mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
优化
This commit is contained in:
parent
52980246e6
commit
9a773381aa
@ -12,6 +12,7 @@ import android.widget.SeekBar
|
|||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
|
import io.legado.app.constant.BookType
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.constant.Status
|
import io.legado.app.constant.Status
|
||||||
import io.legado.app.constant.Theme
|
import io.legado.app.constant.Theme
|
||||||
@ -21,6 +22,7 @@ import io.legado.app.data.entities.BookChapter
|
|||||||
import io.legado.app.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
import io.legado.app.databinding.ActivityAudioPlayBinding
|
import io.legado.app.databinding.ActivityAudioPlayBinding
|
||||||
import io.legado.app.help.book.isAudio
|
import io.legado.app.help.book.isAudio
|
||||||
|
import io.legado.app.help.book.removeType
|
||||||
import io.legado.app.help.config.AppConfig
|
import io.legado.app.help.config.AppConfig
|
||||||
import io.legado.app.lib.dialogs.alert
|
import io.legado.app.lib.dialogs.alert
|
||||||
import io.legado.app.model.AudioPlay
|
import io.legado.app.model.AudioPlay
|
||||||
@ -195,6 +197,8 @@ class AudioPlayActivity :
|
|||||||
launch {
|
launch {
|
||||||
withContext(IO) {
|
withContext(IO) {
|
||||||
AudioPlay.book?.migrateTo(book, toc)
|
AudioPlay.book?.migrateTo(book, toc)
|
||||||
|
book.removeType(BookType.updateError)
|
||||||
|
AudioPlay.book?.delete()
|
||||||
appDb.bookDao.insert(book)
|
appDb.bookDao.insert(book)
|
||||||
}
|
}
|
||||||
startActivity<ReadBookActivity> {
|
startActivity<ReadBookActivity> {
|
||||||
|
@ -4,11 +4,13 @@ import android.app.Application
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
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.BookType
|
||||||
import io.legado.app.constant.EventBus
|
import io.legado.app.constant.EventBus
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
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.data.entities.BookSource
|
import io.legado.app.data.entities.BookSource
|
||||||
|
import io.legado.app.help.book.removeType
|
||||||
import io.legado.app.model.AudioPlay
|
import io.legado.app.model.AudioPlay
|
||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
@ -79,6 +81,8 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
|
|||||||
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
|
fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
|
||||||
execute {
|
execute {
|
||||||
AudioPlay.book?.migrateTo(book, toc)
|
AudioPlay.book?.migrateTo(book, toc)
|
||||||
|
book.removeType(BookType.updateError)
|
||||||
|
AudioPlay.book?.delete()
|
||||||
appDb.bookDao.insert(book)
|
appDb.bookDao.insert(book)
|
||||||
AudioPlay.book = book
|
AudioPlay.book = book
|
||||||
AudioPlay.bookSource = source
|
AudioPlay.bookSource = source
|
||||||
|
@ -237,6 +237,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
bookData.value?.migrateTo(book, toc)
|
bookData.value?.migrateTo(book, toc)
|
||||||
if (inBookshelf) {
|
if (inBookshelf) {
|
||||||
book.removeType(BookType.updateError)
|
book.removeType(BookType.updateError)
|
||||||
|
bookData.value?.delete()
|
||||||
appDb.bookDao.insert(book)
|
appDb.bookDao.insert(book)
|
||||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||||
}
|
}
|
||||||
|
@ -832,13 +832,17 @@ class ReadBookActivity : BaseReadBookActivity(),
|
|||||||
} else {
|
} else {
|
||||||
ReadAloud.stop(this)
|
ReadAloud.stop(this)
|
||||||
launch {
|
launch {
|
||||||
ReadBook.book?.migrateTo(book, toc)
|
withContext(IO) {
|
||||||
appDb.bookDao.insert(book)
|
ReadBook.book?.migrateTo(book, toc)
|
||||||
|
book.removeType(BookType.updateError)
|
||||||
|
ReadBook.book?.delete()
|
||||||
|
appDb.bookDao.insert(book)
|
||||||
|
}
|
||||||
|
startActivity<AudioPlayActivity> {
|
||||||
|
putExtra("bookUrl", book.bookUrl)
|
||||||
|
}
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
startActivity<AudioPlayActivity> {
|
|
||||||
putExtra("bookUrl", book.bookUrl)
|
|
||||||
}
|
|
||||||
finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +216,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
ReadBook.upMsg(context.getString(R.string.loading))
|
ReadBook.upMsg(context.getString(R.string.loading))
|
||||||
ReadBook.book?.migrateTo(book, toc)
|
ReadBook.book?.migrateTo(book, toc)
|
||||||
book.removeType(BookType.updateError)
|
book.removeType(BookType.updateError)
|
||||||
|
ReadBook.book?.delete()
|
||||||
appDb.bookDao.insert(book)
|
appDb.bookDao.insert(book)
|
||||||
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
appDb.bookChapterDao.insert(*toc.toTypedArray())
|
||||||
ReadBook.resetData(book)
|
ReadBook.resetData(book)
|
||||||
|
Loading…
Reference in New Issue
Block a user