修复听书从后台打开时不对的bug

pull/1072/head
gedoor 3 years ago
parent 0390bd397f
commit f9a5c9ee63
  1. 1
      app/src/main/assets/updateLog.md
  2. 22
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  4. 10
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt

@ -11,6 +11,7 @@
**2021/06/22**
* 修复隐藏未读设置不生效的bug
* 修复系统字体大小选择大时导入界面按钮显示不全的bug
* 修复听书从后台打开时不对的bug
**2021/06/20**
* viewPager2 改回 viewPager

@ -98,9 +98,7 @@ object AudioPlay {
durChapterIndex = index
durChapterPos = 0
durChapter = null
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
saveRead(book)
play(context)
}
}
@ -115,16 +113,13 @@ object AudioPlay {
durChapterIndex--
durChapterPos = 0
durChapter = null
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
saveRead(book)
play(context)
}
}
}
fun next(context: Context) {
Coroutine.async {
book?.let { book ->
if (book.durChapterIndex >= book.totalChapterNum) {
return@let
@ -132,13 +127,10 @@ object AudioPlay {
durChapterIndex++
durChapterPos = 0
durChapter = null
book.durChapterIndex = durChapterIndex
book.durChapterPos = 0
saveRead()
saveRead(book)
play(context)
}
}
}
fun addTimer(context: Context) {
val intent = Intent(context, AudioPlayService::class.java)
@ -146,18 +138,16 @@ object AudioPlay {
context.startService(intent)
}
fun saveRead() {
Coroutine.async {
book?.let { book ->
fun saveRead(book: Book) {
book.lastCheckCount = 0
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = durChapterIndex
book.durChapterPos = durChapterPos
Coroutine.async {
appDb.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title
}
appDb.bookDao.update(book)
}
book.save()
}
}

@ -40,8 +40,7 @@ class AudioPlayActivity :
ChangeSourceDialog.CallBack {
override val binding by viewBinding(ActivityAudioPlayBinding::inflate)
override val viewModel: AudioPlayViewModel
by viewModels()
override val viewModel by viewModels<AudioPlayViewModel>()
private var adjustProgress = false
private val progressTimeFormat by lazy {
@ -61,8 +60,12 @@ class AudioPlayActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) {
binding.titleBar.transparent()
AudioPlay.titleData.observe(this, { binding.titleBar.title = it })
AudioPlay.coverData.observe(this, { upCover(it) })
AudioPlay.titleData.observe(this) {
binding.titleBar.title = it
}
AudioPlay.coverData.observe(this) {
upCover(it)
}
viewModel.initData(intent)
initView()
}

@ -17,14 +17,10 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
fun initData(intent: Intent) = AudioPlay.apply {
execute {
val bookUrl = intent.getStringExtra("bookUrl")
if (book?.bookUrl != bookUrl) {
if (bookUrl != null && bookUrl != book?.bookUrl) {
stop(context)
inBookshelf = intent.getBooleanExtra("inBookshelf", true)
book = if (!bookUrl.isNullOrEmpty()) {
appDb.bookDao.getBook(bookUrl)
} else {
appDb.bookDao.lastReadBook
}
book = appDb.bookDao.getBook(bookUrl)
book?.let { book ->
titleData.postValue(book.name)
coverData.postValue(book.getDisplayCover())
@ -42,8 +38,8 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
loadChapterList(book)
}
}
saveRead(book)
}
saveRead()
}
}
}

Loading…
Cancel
Save