diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 523aca465..2e30f937d 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -40,7 +40,7 @@ interface BookDao { fun recentRead(): DataSource.Factory @Query("SELECT * FROM books ORDER BY durChapterTime DESC limit 0,10") - fun getRecentRead(): DataSource.Factory + fun getRecentRead(): List @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg book: Book) 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 0f70422e3..b67ad32cf 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 @@ -33,6 +33,17 @@ class BookshelfAdapter : PagedListAdapter(D var callBack: CallBack? = null + fun notification(bookUrl: String) { + for (i in 0..itemCount) { + getItem(i)?.let { + if (it.bookUrl == bookUrl) { + notifyItemChanged(i) + return + } + } + } + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list, parent, false)) } 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 86cb82006..11dec61a1 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 @@ -85,6 +85,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookshelfAdapter = BookshelfAdapter() rv_bookshelf.adapter = bookshelfAdapter bookshelfAdapter.callBack = this + viewModel.adapterNotification.observe(viewLifecycleOwner, Observer { bookshelfAdapter.notification(it) }) } private fun initBookGroupData() { 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 639910953..b4b2a6e21 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 @@ -1,6 +1,7 @@ package io.legado.app.ui.main.bookshelf import android.app.Application +import androidx.lifecycle.MediatorLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.constant.BookType @@ -11,7 +12,7 @@ import kotlinx.coroutines.Dispatchers.IO class BookshelfViewModel(application: Application) : BaseViewModel(application) { val updateList = arrayListOf() - + val adapterNotification = MediatorLiveData() fun saveBookGroup(group: String?) { if (!group.isNullOrBlank()) { @@ -34,13 +35,17 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) val bookSource = App.db.bookSourceDao().getBookSource(book.origin) bookSource?.let { updateList.add(book.bookUrl) + adapterNotification.postValue(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) } + }.onFinally { + updateList.remove(book.bookUrl) + adapterNotification.postValue(book.bookUrl) + } } } }