mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
bfd27a2f5f
commit
fcc887cb25
@ -385,9 +385,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
|||||||
|
|
||||||
override fun getItemPosition(any: Any): Int {
|
override fun getItemPosition(any: Any): Int {
|
||||||
val position = (any as MainFragmentInterface).position
|
val position = (any as MainFragmentInterface).position
|
||||||
if (position < 0) {
|
?: return POSITION_NONE
|
||||||
return POSITION_NONE
|
|
||||||
}
|
|
||||||
val fragmentId = getId(position)
|
val fragmentId = getId(position)
|
||||||
if ((fragmentId == idBookshelf1 && any is BookshelfFragment1)
|
if ((fragmentId == idBookshelf1 && any is BookshelfFragment1)
|
||||||
|| (fragmentId == idBookshelf2 && any is BookshelfFragment2)
|
|| (fragmentId == idBookshelf2 && any is BookshelfFragment2)
|
||||||
|
@ -2,6 +2,6 @@ package io.legado.app.ui.main
|
|||||||
|
|
||||||
interface MainFragmentInterface {
|
interface MainFragmentInterface {
|
||||||
|
|
||||||
val position: Int
|
val position: Int?
|
||||||
|
|
||||||
}
|
}
|
@ -33,6 +33,8 @@ import io.legado.app.utils.*
|
|||||||
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId),
|
abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfViewModel>(layoutId),
|
||||||
MainFragmentInterface {
|
MainFragmentInterface {
|
||||||
|
|
||||||
|
override val position: Int? get() = arguments?.getInt("position")
|
||||||
|
|
||||||
val activityViewModel by activityViewModels<MainViewModel>()
|
val activityViewModel by activityViewModels<MainViewModel>()
|
||||||
override val viewModel by viewModels<BookshelfViewModel>()
|
override val viewModel by viewModels<BookshelfViewModel>()
|
||||||
|
|
||||||
|
@ -40,8 +40,6 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
|||||||
arguments = bundle
|
arguments = bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
|
||||||
|
|
||||||
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||||
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
private val adapter by lazy { TabFragmentPageAdapter(childFragmentManager) }
|
||||||
private val tabLayout: TabLayout by lazy {
|
private val tabLayout: TabLayout by lazy {
|
||||||
|
@ -52,8 +52,6 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
|||||||
arguments = bundle
|
arguments = bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
override val position: Int get() = arguments?.getInt("position") ?: -1
|
|
||||||
|
|
||||||
private val binding by viewBinding(FragmentBookshelf2Binding::bind)
|
private val binding by viewBinding(FragmentBookshelf2Binding::bind)
|
||||||
private val bookshelfLayout by lazy {
|
private val bookshelfLayout by lazy {
|
||||||
getPrefInt(PreferKey.bookshelfLayout)
|
getPrefInt(PreferKey.bookshelfLayout)
|
||||||
|
@ -54,7 +54,7 @@ class ExploreFragment() : VMBaseFragment<ExploreViewModel>(R.layout.fragment_exp
|
|||||||
arguments = bundle
|
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>()
|
override val viewModel by viewModels<ExploreViewModel>()
|
||||||
private val binding by viewBinding(FragmentExploreBinding::bind)
|
private val binding by viewBinding(FragmentExploreBinding::bind)
|
||||||
|
@ -52,7 +52,7 @@ class MyFragment() : BaseFragment(R.layout.fragment_my_config), MainFragmentInte
|
|||||||
arguments = bundle
|
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)
|
private val binding by viewBinding(FragmentMyConfigBinding::bind)
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class RssFragment() : VMBaseFragment<RssSourceViewModel>(R.layout.fragment_rss),
|
|||||||
arguments = bundle
|
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)
|
private val binding by viewBinding(FragmentRssBinding::bind)
|
||||||
override val viewModel by viewModels<RssSourceViewModel>()
|
override val viewModel by viewModels<RssSourceViewModel>()
|
||||||
|
Loading…
Reference in New Issue
Block a user