From ec5a990dd7170eb30302d6d2cd22c69fc78c320f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 14 Aug 2019 10:27:24 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt | 8 ++++++++ .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 5 +++++ .../io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index 9f533e2c8..120f4e383 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -65,6 +65,13 @@ class BookshelfAdapter : PagedListAdapter(D callBack?.openBookInfo(book) true } + callBack?.let { + if (book.bookUrl in it.updateList()) { + rl_loading.show() + } else { + rl_loading.hide() + } + } ?: rl_loading.hide() } } @@ -72,5 +79,6 @@ class BookshelfAdapter : PagedListAdapter(D fun open(book: Book) fun openBookInfo(book: Book) fun search() + fun updateList(): List } } \ No newline at end of file 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 2cba38d6d..74576b5ed 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 @@ -73,6 +73,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b refresh_layout.setColorSchemeColors(accentColor) refresh_layout.setOnRefreshListener { refresh_layout.isRefreshing = false + viewModel.upChapterList() } tv_recent_reading.textColor = accentColor rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) @@ -117,6 +118,10 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } + override fun updateList(): List { + return viewModel.updateList + } + override fun onQueryTextSubmit(query: String?): Boolean { context?.startActivity(Pair("key", query)) return false diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 148c20b6a..639910953 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -10,6 +10,9 @@ import kotlinx.coroutines.Dispatchers.IO class BookshelfViewModel(application: Application) : BaseViewModel(application) { + val updateList = arrayListOf() + + fun saveBookGroup(group: String?) { if (!group.isNullOrBlank()) { execute { @@ -30,13 +33,14 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) if (book.origin != BookType.local) { val bookSource = App.db.bookSourceDao().getBookSource(book.origin) bookSource?.let { + updateList.add(book.bookUrl) WebBook(bookSource).getChapterList(book).onSuccess(IO) { it?.let { if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { - + App.db.bookChapterDao().insert(*it.toTypedArray()) } } - } + }.onFinally { updateList.remove(book.bookUrl) } } } }