From 5ab04dd0c23c5ae8ec7724783d0394aeed39b97d Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 16 Jun 2020 20:43:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=B7=E6=96=B0=E6=97=B6=E5=8F=AA?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=BD=93=E5=89=8D=E4=B9=A6=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/main/bookshelf/BookshelfFragment.kt | 13 +++++++++++-- .../app/ui/main/bookshelf/books/BooksFragment.kt | 8 ++++++-- app/src/main/res/menu/main_bookshelf.xml | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) 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" /> + +