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

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

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

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

Loading…
Cancel
Save