kunfei 3 éve
szülő
commit
eedc8be4c6

+ 1 - 3
app/src/main/java/io/legado/app/ui/main/MainActivity.kt

@@ -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)

+ 1 - 1
app/src/main/java/io/legado/app/ui/main/MainFragmentInterface.kt

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

+ 2 - 0
app/src/main/java/io/legado/app/ui/main/bookshelf/BaseBookshelfFragment.kt

@@ -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>()
 

+ 0 - 2
app/src/main/java/io/legado/app/ui/main/bookshelf/style1/BookshelfFragment1.kt

@@ -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 {

+ 0 - 2
app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt

@@ -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)

+ 1 - 1
app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt

@@ -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)

+ 1 - 1
app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt

@@ -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)
 

+ 1 - 1
app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt

@@ -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>()