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

View File

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

View File

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

View File

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