|
|
|
@ -5,13 +5,11 @@ import android.content.Intent |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
import io.legado.app.help.BookHelp |
|
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
|
import io.legado.app.service.help.AudioPlay |
|
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
|
|
class AudioPlayViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
@ -32,25 +30,17 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) |
|
|
|
|
coverData.postValue(book.getDisplayCover()) |
|
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
|
durChapterPos = book.durChapterPos |
|
|
|
|
App.db.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let { |
|
|
|
|
postEvent(EventBus.AUDIO_SUB_TITLE, it.title) |
|
|
|
|
} |
|
|
|
|
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex) |
|
|
|
|
upDurChapter(book) |
|
|
|
|
App.db.bookSourceDao.getBookSource(book.origin)?.let { |
|
|
|
|
webBook = WebBook(it) |
|
|
|
|
} |
|
|
|
|
val count = App.db.bookChapterDao.getChapterCount(book.bookUrl) |
|
|
|
|
if (count == 0) { |
|
|
|
|
if (durChapter == null) { |
|
|
|
|
if (book.tocUrl.isEmpty()) { |
|
|
|
|
loadBookInfo(book) |
|
|
|
|
} else { |
|
|
|
|
loadChapterList(book) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (durChapterIndex > count - 1) { |
|
|
|
|
durChapterIndex = count - 1 |
|
|
|
|
} |
|
|
|
|
durChapter = App.db.bookChapterDao.getChapter(book.bookUrl, durChapterIndex) |
|
|
|
|
upDurChapter(book) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
saveRead() |
|
|
|
|