|
|
@ -1,6 +1,7 @@ |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
package io.legado.app.ui.main.bookshelf |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
import android.app.Application |
|
|
|
|
|
|
|
import androidx.lifecycle.MediatorLiveData |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.constant.BookType |
|
|
|
import io.legado.app.constant.BookType |
|
|
@ -11,7 +12,7 @@ import kotlinx.coroutines.Dispatchers.IO |
|
|
|
class BookshelfViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
class BookshelfViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
|
|
val updateList = arrayListOf<String>() |
|
|
|
val updateList = arrayListOf<String>() |
|
|
|
|
|
|
|
val adapterNotification = MediatorLiveData<String>() |
|
|
|
|
|
|
|
|
|
|
|
fun saveBookGroup(group: String?) { |
|
|
|
fun saveBookGroup(group: String?) { |
|
|
|
if (!group.isNullOrBlank()) { |
|
|
|
if (!group.isNullOrBlank()) { |
|
|
@ -34,13 +35,17 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) |
|
|
|
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
val bookSource = App.db.bookSourceDao().getBookSource(book.origin) |
|
|
|
bookSource?.let { |
|
|
|
bookSource?.let { |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
updateList.add(book.bookUrl) |
|
|
|
|
|
|
|
adapterNotification.postValue(book.bookUrl) |
|
|
|
WebBook(bookSource).getChapterList(book).onSuccess(IO) { |
|
|
|
WebBook(bookSource).getChapterList(book).onSuccess(IO) { |
|
|
|
it?.let { |
|
|
|
it?.let { |
|
|
|
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { |
|
|
|
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
App.db.bookChapterDao().insert(*it.toTypedArray()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}.onFinally { updateList.remove(book.bookUrl) } |
|
|
|
}.onFinally { |
|
|
|
|
|
|
|
updateList.remove(book.bookUrl) |
|
|
|
|
|
|
|
adapterNotification.postValue(book.bookUrl) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|