diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index f51bdc0a6..9c657dd99 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(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>? = null private var noGroupLiveData: LiveData? = null private val bookGroups = mutableListOf() - private val fragmentMap = hashMapOf() + private val fragmentMap = hashMapOf() private var showGroupNone = false override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { @@ -73,6 +75,13 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b super.onCompatOptionsItemSelected(item) when (item.itemId) { R.id.menu_search -> startActivity() + 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") diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index f9346c7ef..c7395c4dd 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -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>? = 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 { + return booksAdapter.getItems() + } + override fun open(book: Book) { when (book.type) { BookType.audio -> diff --git a/app/src/main/res/menu/main_bookshelf.xml b/app/src/main/res/menu/main_bookshelf.xml index 1c63a7629..628026f7c 100644 --- a/app/src/main/res/menu/main_bookshelf.xml +++ b/app/src/main/res/menu/main_bookshelf.xml @@ -8,6 +8,12 @@ android:title="@string/search" app:showAsAction="ifRoom" /> + +