2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/19131 - Fixes top sites refresh and interactability

This commit is contained in:
codrut.topliceanu 2021-06-14 15:13:48 +03:00 committed by mergify[bot]
parent a2c509b9af
commit 58657ebdef
5 changed files with 26 additions and 29 deletions

View File

@ -53,9 +53,9 @@ class TopSitePagerViewHolder(
} }
fun update(payload: AdapterItem.TopSitePagerPayload) { fun update(payload: AdapterItem.TopSitePagerPayload) {
for (item in payload.changed) { // Due to offscreenPageLimit = 1 we need to update both pages manually here
topSitesPagerAdapter.notifyItemChanged(currentPage, payload) topSitesPagerAdapter.notifyItemChanged(0, payload)
} topSitesPagerAdapter.notifyItemChanged(1, payload)
} }
fun bind(topSites: List<TopSite>) { fun bind(topSites: List<TopSite>) {

View File

@ -11,7 +11,6 @@ import android.view.View
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.appcompat.content.res.AppCompatResources.getDrawable import androidx.appcompat.content.res.AppCompatResources.getDrawable
import kotlinx.android.synthetic.main.top_site_item.* import kotlinx.android.synthetic.main.top_site_item.*
import kotlinx.android.synthetic.main.top_site_item.view.*
import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSite
@ -93,11 +92,6 @@ class TopSiteItemViewHolder(
this.topSite = topSite this.topSite = topSite
} }
fun bind(topSitePayload: TopSitesAdapter.TopSitePayload) {
itemView.top_site_title.text = topSitePayload.newTitle
topSite = topSite.copy(title = topSitePayload.newTitle)
}
private fun onTouchEvent( private fun onTouchEvent(
v: View, v: View,
event: MotionEvent, event: MotionEvent,

View File

@ -8,7 +8,6 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import kotlinx.android.synthetic.main.top_site_item.view.*
import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
import org.mozilla.fenix.perf.StartupTimeline import org.mozilla.fenix.perf.StartupTimeline
@ -39,17 +38,10 @@ class TopSitesAdapter(
is TopSite -> { is TopSite -> {
holder.bind((payloads[0] as TopSite)) holder.bind((payloads[0] as TopSite))
} }
is TopSitePayload -> {
holder.bind(payloads[0] as TopSitePayload)
}
} }
} }
} }
data class TopSitePayload(
val newTitle: String?
)
internal object TopSitesDiffCallback : DiffUtil.ItemCallback<TopSite>() { internal object TopSitesDiffCallback : DiffUtil.ItemCallback<TopSite>() {
override fun areItemsTheSame(oldItem: TopSite, newItem: TopSite) = oldItem.id == newItem.id override fun areItemsTheSame(oldItem: TopSite, newItem: TopSite) = oldItem.id == newItem.id
@ -58,7 +50,7 @@ class TopSitesAdapter(
override fun getChangePayload(oldItem: TopSite, newItem: TopSite): Any? { override fun getChangePayload(oldItem: TopSite, newItem: TopSite): Any? {
return if (oldItem.id == newItem.id && oldItem.url == newItem.url && oldItem.title != newItem.title) { return if (oldItem.id == newItem.id && oldItem.url == newItem.url && oldItem.title != newItem.title) {
TopSitePayload(newItem.title) newItem
} else null } else null
} }
} }

View File

@ -10,7 +10,7 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import kotlinx.android.synthetic.main.component_top_sites.view.* import kotlinx.android.synthetic.main.component_top_sites.view.*
import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.home.sessioncontrol.AdapterItem import org.mozilla.fenix.home.sessioncontrol.AdapterItem.TopSitePagerPayload
import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor import org.mozilla.fenix.home.sessioncontrol.TopSiteInteractor
import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSitePagerViewHolder.Companion.TOP_SITES_PER_PAGE import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSitePagerViewHolder.Companion.TOP_SITES_PER_PAGE
import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSiteViewHolder import org.mozilla.fenix.home.sessioncontrol.viewholders.TopSiteViewHolder
@ -33,15 +33,26 @@ class TopSitesPagerAdapter(
if (payloads.isNullOrEmpty()) { if (payloads.isNullOrEmpty()) {
onBindViewHolder(holder, position) onBindViewHolder(holder, position)
} else { } else {
if (payloads[0] is AdapterItem.TopSitePagerPayload) { if (payloads[0] is TopSitePagerPayload) {
val adapter = holder.itemView.top_sites_list.adapter as TopSitesAdapter val adapter = holder.itemView.top_sites_list.adapter as TopSitesAdapter
val payload = payloads[0] as AdapterItem.TopSitePagerPayload val payload = payloads[0] as TopSitePagerPayload
for (item in payload.changed) {
adapter.notifyItemChanged( update(payload, position, adapter)
item.first % TOP_SITES_PER_PAGE, }
TopSitesAdapter.TopSitePayload(item.second.title) }
) }
}
private fun update(
payload: TopSitePagerPayload,
position: Int,
adapter: TopSitesAdapter
) {
// Only currently selected page items need to be updated.
for (item in payload.changed) {
if (item.first < TOP_SITES_PER_PAGE && position == 0) {
adapter.notifyItemChanged(item.first, item.second)
} else if (item.first >= TOP_SITES_PER_PAGE && position == 1) {
adapter.notifyItemChanged(item.first - TOP_SITES_PER_PAGE, item.second)
} }
} }
} }
@ -67,7 +78,7 @@ class TopSitesPagerAdapter(
changed.add(Pair(index, item)) changed.add(Pair(index, item))
} }
} }
return if (changed.isNotEmpty()) AdapterItem.TopSitePagerPayload(changed) else null return if (changed.isNotEmpty()) TopSitePagerPayload(changed) else null
} }
} }
} }

View File

@ -29,7 +29,7 @@ class TopSitesAdapterTest {
assertEquals( assertEquals(
TopSitesAdapter.TopSitesDiffCallback.getChangePayload(topSite, topSite2), TopSitesAdapter.TopSitesDiffCallback.getChangePayload(topSite, topSite2),
TopSitesAdapter.TopSitePayload("Title2") topSite.copy(title = "Title2")
) )
val topSite3 = TopSite( val topSite3 = TopSite(