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