1
0
Fork 0

Prevent favicons from flashing when items are selected in History (#9233)

master
David Walsh 2020-04-01 17:43:21 -05:00 committed by GitHub
parent b94ac93ce9
commit 26137f63a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 26 deletions

View File

@ -8,7 +8,6 @@ import android.content.Context
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.R
@ -22,27 +21,23 @@ open class LibraryPageView(
protected val activity = context.asActivity()
protected fun setUiForNormalMode(
title: String?,
libraryItemsList: RecyclerView
title: String?
) {
updateToolbar(
title = title,
foregroundColor = context.getColorFromAttr(R.attr.primaryText),
backgroundColor = context.getColorFromAttr(R.attr.foundation)
)
libraryItemsList.adapter?.notifyDataSetChanged()
}
protected fun setUiForSelectingMode(
title: String?,
libraryItemsList: RecyclerView
title: String?
) {
updateToolbar(
title = title,
foregroundColor = ContextCompat.getColor(context, R.color.white_color),
backgroundColor = context.getColorFromAttr(R.attr.accent)
)
libraryItemsList.adapter?.notifyDataSetChanged()
}
private fun updateToolbar(title: String?, foregroundColor: Int, backgroundColor: Int) {

View File

@ -127,8 +127,7 @@ class BookmarkView(
setUiForNormalMode(state.tree)
is BookmarkFragmentState.Mode.Selecting ->
setUiForSelectingMode(
context.getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size),
view.bookmark_list
context.getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size)
)
}
view.bookmarks_progress_bar.isVisible = state.isLoading
@ -150,8 +149,7 @@ class BookmarkView(
private fun setUiForNormalMode(root: BookmarkNode?) {
super.setUiForNormalMode(
if (BookmarkRoot.Mobile.id == root?.guid) context.getString(R.string.library_bookmarks) else root?.title,
view.bookmark_list
if (BookmarkRoot.Mobile.id == root?.guid) context.getString(R.string.library_bookmarks) else root?.title
)
}

View File

@ -106,14 +106,13 @@ class HistoryView(
items = state.items
mode = state.mode
if (state.mode != oldMode) {
interactor.onModeSwitched()
historyAdapter.updateMode(state.mode)
historyAdapter.updateMode(state.mode)
val first = layoutManager.findFirstVisibleItemPosition()
val last = layoutManager.findLastVisibleItemPosition() + 1
historyAdapter.notifyItemRangeChanged(first, last - first)
// Deselect all the previously selected items
oldMode.selectedItems.forEach {
historyAdapter.notifyItemChanged(it.id)
}
if (state.mode::class != oldMode::class) {
interactor.onModeSwitched()
}
if (state.mode is HistoryFragmentState.Mode.Editing) {
@ -127,12 +126,10 @@ class HistoryView(
when (val mode = state.mode) {
is HistoryFragmentState.Mode.Normal ->
setUiForNormalMode(
context.getString(R.string.library_history),
view.history_list)
context.getString(R.string.library_history))
is HistoryFragmentState.Mode.Editing ->
setUiForSelectingMode(
context.getString(R.string.history_multi_select_title, mode.selectedItems.size),
view.history_list)
context.getString(R.string.history_multi_select_title, mode.selectedItems.size))
}
}

View File

@ -46,8 +46,6 @@ class HistoryListItemViewHolder(
showDeleteButton: Boolean,
mode: HistoryFragmentState.Mode
) {
this.item = item
itemView.history_layout.titleView.text = item.title
itemView.history_layout.urlView.text = item.url
@ -58,12 +56,18 @@ 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) {
if (this.item?.url != item.url) {
itemView.history_layout.loadFavicon(item.url)
}
if (item !in selectionHolder.selectedItems) {
itemView.overflow_menu.showAndEnable()
} else {
itemView.overflow_menu.hideAndDisable()
}
this.item = item
}
private fun toggleHeader(headerText: String?) {