diff --git a/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageFragment.kt b/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageFragment.kt index be2b286c60..8533bf6511 100644 --- a/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageFragment.kt +++ b/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageFragment.kt @@ -247,7 +247,12 @@ class CustomPageFragment : LazyFragment(), ISmartRefreshContent, IScrollable, IB }) dataList.observe(viewLifecycleOwner) { - adapter.submitList(it) + adapter.submitList(it) { + if (shouldScrollToTop) { + shouldScrollToTop = false + binding.gameList.scrollToPosition(0) + } + } } loadStatus.observe(viewLifecycleOwner) { (status, isPullToRefresh) -> diff --git a/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageViewModel.kt b/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageViewModel.kt index da941d4a97..3a94124f9d 100644 --- a/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/home/custom/CustomPageViewModel.kt @@ -132,6 +132,8 @@ class CustomPageViewModel(application: Application) : AndroidViewModel(applicati val pkVoteResultLiveData = MutableLiveData>>() + var shouldScrollToTop: Boolean = false + fun init( pageConfigure: PageConfigure, searchToolbarTabWrapperViewModel: SearchToolbarTabWrapperViewModel?, @@ -582,6 +584,11 @@ class CustomPageViewModel(application: Application) : AndroidViewModel(applicati subjectItem.data ) if (customPageItemList.isEmpty()) return + + if (index == 0) { + shouldScrollToTop = true + } + newData[index] = customPageItemList[0] newData.addAll(index + 1, customPageItemList.subList(1, customPageItemList.size)) newData.forEachIndexed { pos, customPageItem -> @@ -619,6 +626,10 @@ class CustomPageViewModel(application: Application) : AndroidViewModel(applicati subjectItem.data ) if (customPageItemList.isEmpty()) return + + if (index == 0) { + shouldScrollToTop = true + } newData[index] = customPageItemList[0] newData.addAll(index + 1, customPageItemList.subList(1, customPageItemList.size)) newData.forEachIndexed { pos, customPageItem -> diff --git a/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomPageAdapter.kt b/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomPageAdapter.kt index 5cd8c164f2..974d4daf15 100644 --- a/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomPageAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/home/custom/adapter/CustomPageAdapter.kt @@ -84,13 +84,13 @@ class CustomPageAdapter( } val firstShowPosition: LiveData = _firstShowPosition - override fun submitList(list: List?) { + override fun submitList(list: List?, commitCallback: Runnable?) { val dataWithFooter = if (list.isNullOrEmpty()) { ArrayList(list) } else { list + CustomFooterItem } - super.submitList(dataWithFooter) + super.submitList(dataWithFooter, commitCallback) } /**