|
|
|
@ -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<String>() |
|
|
|
|
|
|
|
|
|
val adapterNotification = MediatorLiveData<String>() |
|
|
|
|
|
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|