From d60bfcfcfc9995f656852a177887fccada69d619 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 2 Oct 2020 12:02:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E5=87=BB=E5=8F=91=E7=8E=B0=E6=8A=98?= =?UTF-8?q?=E5=8F=A0=E5=8F=91=E7=8E=B0,=E5=86=8D=E6=AC=A1=E5=8F=8C?= =?UTF-8?q?=E5=87=BB=E6=BB=9A=E5=8A=A8=E8=87=B3=E9=A1=B6=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/main/MainActivity.kt | 10 +++++++++- .../legado/app/ui/main/explore/ExploreAdapter.kt | 16 +++++++++++++++- .../app/ui/main/explore/ExploreFragment.kt | 11 +++++++++++ app/src/main/res/menu/main_bnv.xml | 2 +- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 64e005ba2..26879ae87 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -39,6 +39,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), get() = getViewModel(MainViewModel::class.java) private var exitTime: Long = 0 private var bookshelfReselected: Long = 0 + private var exploreReselected: Long = 0 private var pagePosition = 0 private val fragmentMap = hashMapOf() @@ -72,7 +73,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun onNavigationItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_bookshelf -> view_pager_main.setCurrentItem(0, false) - R.id.menu_find_book -> view_pager_main.setCurrentItem(1, false) + R.id.menu_explore -> view_pager_main.setCurrentItem(1, false) R.id.menu_rss -> view_pager_main.setCurrentItem(2, false) R.id.menu_my_config -> view_pager_main.setCurrentItem(3, false) } @@ -88,6 +89,13 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), (fragmentMap[0] as? BookshelfFragment)?.gotoTop() } } + R.id.menu_explore -> { + if (System.currentTimeMillis() - exploreReselected > 300) { + exploreReselected = System.currentTimeMillis() + } else { + (fragmentMap[1] as? ExploreFragment)?.compressExplore() + } + } } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 0fdfa373f..137398b71 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -11,7 +11,10 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.accentColor -import io.legado.app.utils.* +import io.legado.app.utils.ACache +import io.legado.app.utils.dp +import io.legado.app.utils.gone +import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_fillet_text.view.* import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.coroutines.CoroutineScope @@ -97,6 +100,17 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } + fun compressExplore(): Boolean { + return if (exIndex < 0) { + false + } else { + val oldExIndex = exIndex + exIndex = -1 + notifyItemChanged(oldExIndex) + true + } + } + private fun showMenu(view: View, position: Int): Boolean { val source = getItem(position) ?: return true val popupMenu = PopupMenu(context, view) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 6aa870ee7..bceb905d1 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -15,6 +15,7 @@ import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppPattern import io.legado.app.data.entities.BookSource +import io.legado.app.help.AppConfig import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.book.explore.ExploreShowActivity @@ -154,4 +155,14 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ viewModel.topSource(source) } + fun compressExplore() { + if (!adapter.compressExplore()) { + if (AppConfig.isEInkMode) { + rv_find.scrollToPosition(0) + } else { + rv_find.smoothScrollToPosition(0) + } + } + } + } \ No newline at end of file diff --git a/app/src/main/res/menu/main_bnv.xml b/app/src/main/res/menu/main_bnv.xml index 9197bec7b..7fcb272c9 100644 --- a/app/src/main/res/menu/main_bnv.xml +++ b/app/src/main/res/menu/main_bnv.xml @@ -8,7 +8,7 @@ android:icon="@drawable/ic_bottom_books" android:title="@string/bookshelf" />