For #18672 - Renaming a TopSite changes just the title

Previously renaming a TopSite would bind that as a new item and in such update
the entire list. This could potentially leading changes in the list and then
it's ViewPager parent's layout.

This patch switches the code to use the existing TopSitePayload and so do a
partial update of an on-screen TopSite instead of rebind it as a new item.

If a layout is requested while showing <=4 TopSites on the second page, by
having "offscreenPageLimit = 1" the biggest height of ViewPager pages is used
preventing an edgecase where the ViewPager would hide half of the items from
the first page.
upstream-sync
Mugurell 3 years ago
parent 9e30833506
commit 551031eee3

@ -45,6 +45,10 @@ class TopSitePagerViewHolder(
view.top_sites_pager.apply { view.top_sites_pager.apply {
adapter = topSitesPagerAdapter adapter = topSitesPagerAdapter
registerOnPageChangeCallback(topSitesPageChangeCallback) registerOnPageChangeCallback(topSitesPageChangeCallback)
// Retain one more TopSites pages to ensure a new layout request will measure the first page also.
// Otherwise the second page with 3 TopSites will have the entire ViewPager only show
// the first row of TopSites, hiding half of those shown on the first page.
offscreenPageLimit = 1
} }
} }

@ -11,6 +11,7 @@ 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
@ -92,6 +93,11 @@ 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,

@ -40,7 +40,7 @@ class TopSitesAdapter(
holder.bind((payloads[0] as TopSite)) holder.bind((payloads[0] as TopSite))
} }
is TopSitePayload -> { is TopSitePayload -> {
holder.itemView.top_site_title.text = (payloads[0] as TopSitePayload).newTitle holder.bind(payloads[0] as TopSitePayload)
} }
} }
} }

@ -37,7 +37,10 @@ class TopSitesPagerAdapter(
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 AdapterItem.TopSitePagerPayload
for (item in payload.changed) { for (item in payload.changed) {
adapter.notifyItemChanged(item.first % TOP_SITES_PER_PAGE, item.second) adapter.notifyItemChanged(
item.first % TOP_SITES_PER_PAGE,
TopSitesAdapter.TopSitePayload(item.second.title)
)
} }
} }
} }

Loading…
Cancel
Save