feat: 刷新时只刷新当前书架

pull/248/head
gedoor 5 years ago
parent b136828093
commit 5ab04dd0c2
  1. 13
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  2. 8
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt
  3. 6
      app/src/main/res/menu/main_bookshelf.xml

@ -31,6 +31,7 @@ import io.legado.app.ui.book.download.DownloadActivity
import io.legado.app.ui.book.group.GroupManageDialog
import io.legado.app.ui.book.local.ImportBookActivity
import io.legado.app.ui.book.search.SearchActivity
import io.legado.app.ui.main.MainViewModel
import io.legado.app.ui.main.bookshelf.books.BooksFragment
import io.legado.app.ui.widget.text.AutoCompleteTextView
import io.legado.app.utils.*
@ -52,11 +53,12 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override val viewModel: BookshelfViewModel
get() = getViewModel(BookshelfViewModel::class.java)
private val activityViewModel: MainViewModel
get() = getViewModelOfActivity(MainViewModel::class.java)
private var bookGroupLiveData: LiveData<List<BookGroup>>? = null
private var noGroupLiveData: LiveData<Int>? = null
private val bookGroups = mutableListOf<BookGroup>()
private val fragmentMap = hashMapOf<Int, Fragment>()
private val fragmentMap = hashMapOf<Int, BooksFragment>()
private var showGroupNone = false
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
@ -73,6 +75,13 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
super.onCompatOptionsItemSelected(item)
when (item.itemId) {
R.id.menu_search -> startActivity<SearchActivity>()
R.id.menu_update_toc -> {
val group = bookGroups[tab_layout.selectedTabPosition]
val fragment = fragmentMap[group.groupId]
fragment?.getBooks()?.let {
activityViewModel.upChapterList(it)
}
}
R.id.menu_bookshelf_layout -> configBookshelf()
R.id.menu_group_manage -> GroupManageDialog()
.show(childFragmentManager, "groupManageDialog")

@ -46,14 +46,14 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
}
}
private lateinit var activityViewModel: MainViewModel
private val activityViewModel: MainViewModel
get() = getViewModelOfActivity(MainViewModel::class.java)
private lateinit var booksAdapter: BaseBooksAdapter
private var bookshelfLiveData: LiveData<List<Book>>? = null
private var position = 0
private var groupId = -1
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
activityViewModel = getViewModelOfActivity(MainViewModel::class.java)
arguments?.let {
position = it.getInt("position", 0)
groupId = it.getInt("groupId", -1)
@ -120,6 +120,10 @@ class BooksFragment : BaseFragment(R.layout.fragment_books),
})
}
fun getBooks(): List<Book> {
return booksAdapter.getItems()
}
override fun open(book: Book) {
when (book.type) {
BookType.audio ->

@ -8,6 +8,12 @@
android:title="@string/search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_update_toc"
android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/update_toc"
app:showAsAction="never" />
<item
android:id="@+id/menu_add_local"
android:icon="@drawable/ic_add"

Loading…
Cancel
Save