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