This commit is contained in:
kunfei 2023-07-01 20:23:24 +08:00
parent bfd27a2f5f
commit fcc887cb25
8 changed files with 7 additions and 11 deletions

View File

@ -385,9 +385,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
override fun getItemPosition(any: Any): Int {
val position = (any as MainFragmentInterface).position
if (position < 0) {
return POSITION_NONE
}
?: return POSITION_NONE
val fragmentId = getId(position)
if ((fragmentId == idBookshelf1 && any is BookshelfFragment1)
|| (fragmentId == idBookshelf2 && any is BookshelfFragment2)

View File

@ -2,6 +2,6 @@ package io.legado.app.ui.main
interface MainFragmentInterface {
val position: Int
val position: Int?
}

View File

@ -33,6 +33,8 @@ import io.legado.app.utils.*
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId),
MainFragmentInterface {
override val position: Int? get() = arguments?.getInt("position")
val activityViewModel by activityViewModels<MainViewModel>()
override val viewModel by viewModels<BookshelfViewModel>()

View File

@ -40,8 +40,6 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
arguments = bundle
}
override val position: Int get() = arguments?.getInt("position") ?: -1
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
private val tabLayout: TabLayout by lazy {

View File

@ -52,8 +52,6 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
arguments = bundle
}
override val position: Int get() = arguments?.getInt("position") ?: -1
private val binding by viewBinding(FragmentBookshelf2Binding::bind)
private val bookshelfLayout by lazy {
getPrefInt(PreferKey.bookshelfLayout)

View File

@ -54,7 +54,7 @@ class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_exp
arguments = bundle
}
override val position: Int get() = arguments?.getInt("position") ?: -1
override val position: Int? get() = arguments?.getInt("position")
override val viewModel by viewModels<ExploreViewModel>()
private val binding by viewBinding(FragmentExploreBinding::bind)

View File

@ -52,7 +52,7 @@ class MyFragment() : BaseFragment(R.layout.fragment_my_config), MainFragmentInte
arguments = bundle
}
override val position: Int get() = arguments?.getInt("position") ?: -1
override val position: Int? get() = arguments?.getInt("position")
private val binding by viewBinding(FragmentMyConfigBinding::bind)

View File

@ -52,7 +52,7 @@ class RssFragment() : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
arguments = bundle
}
override val position: Int get() = arguments?.getInt("position") ?: -1
override val position: Int? get() = arguments?.getInt("position")
private val binding by viewBinding(FragmentRssBinding::bind)
override val viewModel by viewModels<RssSourceViewModel>()