修复rss切换样式bug

pull/951/head
gedoor 4 years ago
parent e034c4c8f0
commit d2eab14cef
  1. 22
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt

@ -20,7 +20,7 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
override val viewModel: RssSortViewModel override val viewModel: RssSortViewModel
by viewModels() by viewModels()
private val fragments = linkedMapOf<String, RssArticlesFragment>() private var sorts = linkedMapOf<String, String>()
private lateinit var adapter: TabFragmentPageAdapter private lateinit var adapter: TabFragmentPageAdapter
private val upSourceResult = registerForActivityResult( private val upSourceResult = registerForActivityResult(
ActivityResultContracts.StartActivityForResult() ActivityResultContracts.StartActivityForResult()
@ -40,7 +40,7 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
adapter = TabFragmentPageAdapter() adapter = TabFragmentPageAdapter()
binding.viewPager.adapter = adapter binding.viewPager.adapter = adapter
TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position -> TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
tab.text = fragments.keys.elementAt(position) tab.text = sorts.keys.elementAt(position)
}.attach() }.attach()
viewModel.titleLiveData.observe(this, { viewModel.titleLiveData.observe(this, {
binding.titleBar.title = it binding.titleBar.title = it
@ -77,11 +77,10 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
} }
private fun upFragments() { private fun upFragments() {
fragments.clear() viewModel.rssSource?.sortUrls()?.let {
viewModel.rssSource?.sortUrls()?.forEach { sorts = it
fragments[it.key] = RssArticlesFragment.create(it.key, it.value)
} }
if (fragments.size == 1) { if (sorts.size == 1) {
binding.tabLayout.gone() binding.tabLayout.gone()
} else { } else {
binding.tabLayout.visible() binding.tabLayout.visible()
@ -92,11 +91,18 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
private inner class TabFragmentPageAdapter : FragmentStateAdapter(this) { private inner class TabFragmentPageAdapter : FragmentStateAdapter(this) {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return fragments.size return sorts.size
}
override fun getItemId(position: Int): Long {
return position + (viewModel.rssSource?.articleStyle ?: 0).toLong() * 100
} }
override fun createFragment(position: Int): Fragment { override fun createFragment(position: Int): Fragment {
return fragments.values.elementAt(position) return RssArticlesFragment.create(
sorts.keys.elementAt(position),
sorts.values.elementAt(position)
)
} }
} }

Loading…
Cancel
Save