双击发现折叠发现,再次双击滚动至顶端

pull/406/head
gedoor 4 years ago
parent 9dd2aa38d6
commit d60bfcfcfc
  1. 10
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  2. 16
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  3. 11
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  4. 2
      app/src/main/res/menu/main_bnv.xml

@ -39,6 +39,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(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<Int, Fragment>()
@ -72,7 +73,7 @@ class MainActivity : VMBaseActivity<MainViewModel>(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<MainViewModel>(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()
}
}
}
}

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

@ -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<ExploreViewModel>(R.layout.fragment_find_
viewModel.topSource(source)
}
fun compressExplore() {
if (!adapter.compressExplore()) {
if (AppConfig.isEInkMode) {
rv_find.scrollToPosition(0)
} else {
rv_find.smoothScrollToPosition(0)
}
}
}
}

@ -8,7 +8,7 @@
android:icon="@drawable/ic_bottom_books"
android:title="@string/bookshelf" />
<item
android:id="@+id/menu_find_book"
android:id="@+id/menu_explore"
android:icon="@drawable/ic_bottom_explore"
android:title="@string/find" />
<item

Loading…
Cancel
Save