|
|
@ -9,8 +9,8 @@ import io.legado.app.base.BaseViewModel |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
|
|
|
|
import io.legado.app.model.localBook.LocalBook |
|
|
|
import io.legado.app.model.localBook.LocalBook |
|
|
|
|
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
|
import io.legado.app.service.help.ReadBook |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
|
|
|
|
|
|
|
@ -49,15 +49,15 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun loadBookInfo( |
|
|
|
fun loadBookInfo( |
|
|
|
book: Book, |
|
|
|
book: Book, canReName: Boolean = true, |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null |
|
|
|
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null, |
|
|
|
) { |
|
|
|
) { |
|
|
|
execute { |
|
|
|
execute { |
|
|
|
if (book.isLocalBook()) { |
|
|
|
if (book.isLocalBook()) { |
|
|
|
loadChapter(book, changeDruChapterIndex) |
|
|
|
loadChapter(book, changeDruChapterIndex) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> |
|
|
|
WebBook(bookSource).getBookInfo(book, this) |
|
|
|
WebBook(bookSource).getBookInfo(book, this, canReName = canReName) |
|
|
|
.onSuccess(IO) { |
|
|
|
.onSuccess(IO) { |
|
|
|
bookData.postValue(book) |
|
|
|
bookData.postValue(book) |
|
|
|
if (inBookshelf) { |
|
|
|
if (inBookshelf) { |
|
|
@ -138,7 +138,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
} |
|
|
|
} |
|
|
|
bookData.postValue(newBook) |
|
|
|
bookData.postValue(newBook) |
|
|
|
if (newBook.tocUrl.isEmpty()) { |
|
|
|
if (newBook.tocUrl.isEmpty()) { |
|
|
|
loadBookInfo(newBook) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
loadBookInfo(newBook, false) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
loadChapter(newBook) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
loadChapter(newBook) { upChangeDurChapterIndex(newBook, it) } |
|
|
|
} |
|
|
|
} |
|
|
|