From 3d5d0d24e777fb125285545decbfdf856de7345c Mon Sep 17 00:00:00 2001 From: Mihai Adrian <48995920+mcarare@users.noreply.github.com> Date: Fri, 11 Oct 2019 09:02:22 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/2570: Hide 3-dots menu for all library items when in select mode (https://github.com/mozilla-mobile/fenix/pull/5699) Removed items from RecyclerView cache to allow setting the new visibility Disabled hidden buttons, otherwise they could still be clicked --- .../src/main/java/org/mozilla/fenix/ext/ImageButton.kt | 18 ++++++++++++++++++ .../java/org/mozilla/fenix/library/LibraryPageView.kt | 15 +++++++++------ .../bookmarks/viewholders/BookmarkFolderViewHolder.kt | 9 ++++++--- .../bookmarks/viewholders/BookmarkItemViewHolder.kt | 10 ++++++---- .../history/viewholders/HistoryListItemViewHolder.kt | 8 ++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 mobile/android/fenix/app/src/main/java/org/mozilla/fenix/ext/ImageButton.kt diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/ext/ImageButton.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/ext/ImageButton.kt new file mode 100644 index 000000000000..7c5c6073570b --- /dev/null +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/ext/ImageButton.kt @@ -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 +} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt index dd57f68eb6e1..879aa7dab87d 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/LibraryPageView.kt @@ -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() } } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkFolderViewHolder.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkFolderViewHolder.kt index 2c44f3c33130..bd47afb12abc 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkFolderViewHolder.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkFolderViewHolder.kt @@ -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 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkItemViewHolder.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkItemViewHolder.kt index 9da3893634e8..6d51750bc824 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkItemViewHolder.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/bookmarks/viewholders/BookmarkItemViewHolder.kt @@ -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 diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt index 23234b0924d3..2ad5894aabf1 100644 --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/library/history/viewholders/HistoryListItemViewHolder.kt @@ -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?) { -- 2.11.4.GIT