|
|
|
@ -1,18 +1,18 @@ |
|
|
|
|
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 |
|
|
|
|
import io.legado.app.constant.Bus |
|
|
|
|
import io.legado.app.data.entities.BookGroup |
|
|
|
|
import io.legado.app.model.WebBook |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
|
|
class BookshelfViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
val updateList = arrayListOf<String>() |
|
|
|
|
val adapterNotification = MediatorLiveData<String>() |
|
|
|
|
|
|
|
|
|
fun saveBookGroup(group: String?) { |
|
|
|
|
if (!group.isNullOrBlank()) { |
|
|
|
@ -35,7 +35,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) |
|
|
|
|
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
|
bookSource?.let { |
|
|
|
|
updateList.add(book.bookUrl) |
|
|
|
|
adapterNotification.postValue(book.bookUrl) |
|
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
WebBook(bookSource).getChapterList(book).onSuccess(IO) { |
|
|
|
|
it?.let { |
|
|
|
|
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { |
|
|
|
@ -44,7 +44,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) |
|
|
|
|
} |
|
|
|
|
}.onFinally { |
|
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
|
adapterNotification.postValue(book.bookUrl) |
|
|
|
|
postEvent(Bus.UP_BOOK, book.bookUrl) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|