新增长按TABS设置为默认页功能

pull/75/head
Administrator 5 years ago
parent 445c108450
commit e672e82c21
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  3. 18
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  4. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -20,4 +20,5 @@ object Bus {
const val SHOW_RSS = "showRss"
const val WEB_SERVICE_STOP = "webServiceStop"
const val UP_DOWNLOAD = "upDownload"
const val UP_TABS = "upTabs"
}

@ -14,6 +14,7 @@ object PreferKey {
const val processText = "process_text"
const val cleanCache = "cleanCache"
const val lastGroup = "lastGroup"
const val saveTabPosition = "saveTabPosition"
const val pageAnim = "pageAnim"
const val readBookFont = "readBookFont"
const val fontFolder = "fontFolder"

@ -13,22 +13,23 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey
import io.legado.app.constant.PreferKey.saveTabPosition
import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.download.DownloadActivity
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getViewModel
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.startActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_tab_layout.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onLongClick
import org.jetbrains.anko.startActivity
class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_bookshelf),
SearchView.OnQueryTextListener,
GroupManageDialog.CallBack,
@ -82,7 +83,16 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
view_pager_bookshelf.adapter = BookshelfAdapter(this, this)
TabLayoutMediator(tab_layout, view_pager_bookshelf) { tab, position ->
tab.text = bookGroups[position].groupName
tab.view?.onLongClick {
tab.select()
putPrefInt(saveTabPosition, position)
toast("该分组<" + bookGroups[position].groupName + ">已成为默认页。")
true
}
}.attach()
observeEvent<Int>(Bus.UP_TABS) {
tab_layout.getTabAt(it)?.select()
}
}
private fun initBookGroupData() {

@ -24,6 +24,7 @@ import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.observeEvent
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.fragment_books.*
import org.jetbrains.anko.startActivity
@ -56,6 +57,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
observeEvent<String>(Bus.UP_BOOK) {
booksAdapter.notification(it)
}
postEvent(Bus.UP_TABS, getPrefInt(PreferKey.saveTabPosition, 0))
}
private fun initRecyclerView() {

Loading…
Cancel
Save