|
|
|
@ -2,6 +2,7 @@ package io.legado.app.ui.read |
|
|
|
|
|
|
|
|
|
import android.app.Application |
|
|
|
|
import android.content.Intent |
|
|
|
|
import androidx.lifecycle.MediatorLiveData |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
@ -12,6 +13,7 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
var book: Book? = null |
|
|
|
|
var bookSource: BookSource? = null |
|
|
|
|
var chapterMaxIndex = MediatorLiveData<Int>() |
|
|
|
|
|
|
|
|
|
fun initData(intent: Intent) { |
|
|
|
|
val bookUrl = intent.getStringExtra("bookUrl") |
|
|
|
@ -19,7 +21,8 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
execute { |
|
|
|
|
book = App.db.bookDao().getBook(bookUrl) |
|
|
|
|
book?.let { book -> |
|
|
|
|
if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { |
|
|
|
|
val count = App.db.bookChapterDao().getChapterCount(bookUrl) |
|
|
|
|
if (count == 0) { |
|
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { |
|
|
|
|
WebBook(it).getChapterList(book) |
|
|
|
|
.onSuccess { cList -> |
|
|
|
@ -30,6 +33,8 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
} ?: let { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
chapterMaxIndex.postValue(count) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|