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) } } } }