解决从仓库切换到排行榜崩溃的问题。

This commit is contained in:
Cold-Mint 2023-08-19 16:52:33 +08:00
parent af32d1e970
commit 99ddec7c4b

View File

@ -30,12 +30,11 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
var webModAdapter: WebModAdapter? = null var webModAdapter: WebModAdapter? = null
var lastOffset = 0 var lastOffset = 0
var lastPosition = 0 var lastPosition = 0
val linearLayoutManager by lazy { var linearLayoutManager: StableLinearLayoutManager? = null
StableLinearLayoutManager(requireContext())
}
private var sortMode: WebMod.SortMode = WebMod.SortMode.Download_Number private var sortMode: WebMod.SortMode = WebMod.SortMode.Download_Number
override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) { override fun whenViewCreated(inflater: LayoutInflater, savedInstanceState: Bundle?) {
linearLayoutManager = StableLinearLayoutManager(requireContext())
viewBinding.recyclerView.layoutManager = linearLayoutManager viewBinding.recyclerView.layoutManager = linearLayoutManager
viewBinding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { viewBinding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
@ -100,7 +99,7 @@ class RankingFragment : BaseFragment<FragmentRankingBinding>() {
viewBinding.swipeRefreshLayout.isVisible = true viewBinding.swipeRefreshLayout.isVisible = true
val adapter = createAdapter(list) val adapter = createAdapter(list)
viewBinding.recyclerView.adapter = adapter viewBinding.recyclerView.adapter = adapter
linearLayoutManager.scrollToPositionWithOffset( linearLayoutManager?.scrollToPositionWithOffset(
lastPosition, lastPosition,
lastOffset lastOffset
) )