1
0
Fork 0

For #2570: Hide 3-dots menu when in select mode for bookmarks and history (#5173)

Show or hide overflow menu for entire list is triggered when mode is changed
For bookmarks, due to implementation of selection and diffUtil,
additional check is necessary for current item (last selected) that is redrawn
master
Mihai Adrian 2019-09-12 23:56:39 +03:00 committed by Sawyer Blatz
parent df8aed9158
commit c8bc144114
5 changed files with 39 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import android.content.Context
import android.graphics.ColorFilter import android.graphics.ColorFilter
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter import android.graphics.PorterDuffColorFilter
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ActionMenuView import android.widget.ActionMenuView
import android.widget.ImageButton import android.widget.ImageButton
@ -15,8 +16,11 @@ import androidx.annotation.ColorInt
import androidx.appcompat.view.menu.ActionMenuItemView import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.children
import androidx.core.view.forEach import androidx.core.view.forEach
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.library_site_item.view.*
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.asActivity import org.mozilla.fenix.ext.asActivity
import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.getColorFromAttr
@ -27,20 +31,32 @@ open class LibraryPageView(
protected val context: Context inline get() = containerView.context protected val context: Context inline get() = containerView.context
protected val activity = context.asActivity() protected val activity = context.asActivity()
protected fun setUiForNormalMode(title: String?) { protected fun setUiForNormalMode(
title: String?,
libraryItemsList: RecyclerView
) {
activity?.title = title activity?.title = title
setToolbarColors( setToolbarColors(
context.getColorFromAttr(R.attr.primaryText), context.getColorFromAttr(R.attr.primaryText),
context.getColorFromAttr(R.attr.foundation) context.getColorFromAttr(R.attr.foundation)
) )
libraryItemsList.children.forEach {
item -> item.overflow_menu.visibility = View.VISIBLE
}
} }
protected fun setUiForSelectingMode(title: String?) { protected fun setUiForSelectingMode(
title: String?,
libraryItemsList: RecyclerView
) {
activity?.title = title activity?.title = title
setToolbarColors( setToolbarColors(
ContextCompat.getColor(context, R.color.white_color), ContextCompat.getColor(context, R.color.white_color),
context.getColorFromAttr(R.attr.accentHighContrast) context.getColorFromAttr(R.attr.accentHighContrast)
) )
libraryItemsList.children.forEach {
item -> item.overflow_menu.visibility = View.INVISIBLE
}
} }
/** /**

View File

@ -125,7 +125,10 @@ class BookmarkView(
is BookmarkFragmentState.Mode.Normal -> is BookmarkFragmentState.Mode.Normal ->
setUiForNormalMode(state.tree) setUiForNormalMode(state.tree)
is BookmarkFragmentState.Mode.Selecting -> is BookmarkFragmentState.Mode.Selecting ->
setUiForSelectingMode(context.getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size)) setUiForSelectingMode(
context.getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size),
view.bookmark_list
)
} }
} }
@ -145,7 +148,8 @@ class BookmarkView(
private fun setUiForNormalMode(root: BookmarkNode?) { private fun setUiForNormalMode(root: BookmarkNode?) {
super.setUiForNormalMode( super.setUiForNormalMode(
if (BookmarkRoot.Mobile.matches(root)) context.getString(R.string.library_bookmarks) else root?.title if (BookmarkRoot.Mobile.matches(root)) context.getString(R.string.library_bookmarks) else root?.title,
view.bookmark_list
) )
} }

View File

@ -31,6 +31,10 @@ class BookmarkFolderViewHolder(
if (!item.inRoots()) { if (!item.inRoots()) {
setupMenu(item) setupMenu(item)
containerView.overflowView.visibility = when (selectionHolder.selectedItems.isEmpty()) {
true -> View.VISIBLE
false -> View.INVISIBLE
}
} else { } else {
containerView.overflowView.visibility = View.GONE containerView.overflowView.visibility = View.GONE
} }

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.library.bookmarks.viewholders package org.mozilla.fenix.library.bookmarks.viewholders
import android.view.View
import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNode
import org.mozilla.fenix.library.LibrarySiteItemView import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.library.SelectionHolder import org.mozilla.fenix.library.SelectionHolder
@ -22,6 +23,10 @@ class BookmarkItemViewHolder(
containerView.displayAs(LibrarySiteItemView.ItemType.SITE) containerView.displayAs(LibrarySiteItemView.ItemType.SITE)
containerView.overflowView.visibility = when (selectionHolder.selectedItems.isEmpty()) {
true -> View.VISIBLE
false -> View.INVISIBLE
}
setupMenu(item) setupMenu(item)
containerView.titleView.text = if (item.title.isNullOrBlank()) item.url else item.title containerView.titleView.text = if (item.title.isNullOrBlank()) item.url else item.title
containerView.urlView.text = item.url containerView.urlView.text = item.url

View File

@ -98,9 +98,13 @@ class HistoryView(
when (val mode = state.mode) { when (val mode = state.mode) {
is HistoryFragmentState.Mode.Normal -> is HistoryFragmentState.Mode.Normal ->
setUiForNormalMode(context.getString(R.string.library_history)) setUiForNormalMode(
context.getString(R.string.library_history),
view.history_list)
is HistoryFragmentState.Mode.Editing -> is HistoryFragmentState.Mode.Editing ->
setUiForSelectingMode(context.getString(R.string.history_multi_select_title, mode.selectedItems.size)) setUiForSelectingMode(
context.getString(R.string.history_multi_select_title, mode.selectedItems.size),
view.history_list)
} }
} }