1
0
Fork 0

For #2570: Hide 3-dots menu for all library items when in select mode (#5699)

Removed items from RecyclerView cache to allow setting the new visibility
Disabled hidden buttons, otherwise they could still be clicked
master
Mihai Adrian 2019-10-11 09:02:22 +03:00 committed by Jeff Boek
parent 93a380bff2
commit 167c6dca93
5 changed files with 47 additions and 13 deletions

View File

@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import android.view.View
import android.widget.ImageButton
fun ImageButton.hideAndDisable() {
this.visibility = View.INVISIBLE
this.isEnabled = false
}
fun ImageButton.showAndEnable() {
this.visibility = View.VISIBLE
this.isEnabled = true
}

View File

@ -8,7 +8,6 @@ import android.content.Context
import android.graphics.ColorFilter
import android.graphics.PorterDuff
import android.graphics.PorterDuffColorFilter
import android.view.View
import android.view.ViewGroup
import android.widget.ActionMenuView
import android.widget.ImageButton
@ -21,9 +20,11 @@ import androidx.core.view.forEach
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.library_site_item.view.*
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.asActivity
import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.ext.hideAndDisable
import org.mozilla.fenix.ext.showAndEnable
open class LibraryPageView(
override val containerView: ViewGroup
@ -40,8 +41,9 @@ open class LibraryPageView(
context.getColorFromAttr(R.attr.primaryText),
context.getColorFromAttr(R.attr.foundation)
)
libraryItemsList.children.forEach { item ->
item.overflow_menu.visibility = View.VISIBLE
libraryItemsList.setItemViewCacheSize(0)
libraryItemsList.children.forEach {
item -> item.overflow_menu.showAndEnable()
}
}
@ -54,8 +56,9 @@ open class LibraryPageView(
ContextCompat.getColor(context, R.color.white_color),
context.getColorFromAttr(R.attr.accentHighContrast)
)
libraryItemsList.children.forEach { item ->
item.overflow_menu.visibility = View.INVISIBLE
libraryItemsList.setItemViewCacheSize(0)
libraryItemsList.children.forEach {
item -> item.overflow_menu.hideAndDisable()
}
}

View File

@ -9,6 +9,8 @@ import androidx.core.content.ContextCompat
import mozilla.components.concept.storage.BookmarkNode
import org.jetbrains.anko.image
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.hideAndDisable
import org.mozilla.fenix.ext.showAndEnable
import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.library.SelectionHolder
import org.mozilla.fenix.library.bookmarks.BookmarkViewInteractor
@ -31,9 +33,10 @@ class BookmarkFolderViewHolder(
if (!item.inRoots()) {
setupMenu(item)
containerView.overflowView.visibility = when (selectionHolder.selectedItems.isEmpty()) {
true -> View.VISIBLE
false -> View.INVISIBLE
if (selectionHolder.selectedItems.isEmpty()) {
containerView.overflowView.showAndEnable()
} else {
containerView.overflowView.hideAndDisable()
}
} else {
containerView.overflowView.visibility = View.GONE

View File

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

View File

@ -7,7 +7,10 @@ package org.mozilla.fenix.library.history.viewholders
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.history_list_item.view.*
import kotlinx.android.synthetic.main.library_site_item.view.*
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.hideAndDisable
import org.mozilla.fenix.ext.showAndEnable
import org.mozilla.fenix.library.SelectionHolder
import org.mozilla.fenix.library.history.HistoryInteractor
import org.mozilla.fenix.library.history.HistoryItem
@ -55,6 +58,11 @@ class HistoryListItemViewHolder(
itemView.history_layout.setSelectionInteractor(item, selectionHolder, historyInteractor)
itemView.history_layout.changeSelected(item in selectionHolder.selectedItems)
itemView.history_layout.loadFavicon(item.url)
if (mode === HistoryFragmentState.Mode.Normal) {
itemView.overflow_menu.showAndEnable()
} else {
itemView.overflow_menu.hideAndDisable()
}
}
private fun toggleHeader(headerText: String?) {