pull/46/head
kunfei 5 years ago
parent b54751d042
commit d3297a16a5
  1. 14
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  2. 7
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  3. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt

@ -2,11 +2,14 @@ package io.legado.app.ui.audio
import android.os.Bundle import android.os.Bundle
import android.widget.SeekBar import android.widget.SeekBar
import androidx.lifecycle.Observer
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.Bus import io.legado.app.constant.Bus
import io.legado.app.constant.Status import io.legado.app.constant.Status
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.ImageLoader
import io.legado.app.service.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent import io.legado.app.utils.observeEvent
@ -24,6 +27,8 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
viewModel.callBack = this
viewModel.bookData.observe(this, Observer { upView(it) })
viewModel.initData(intent) viewModel.initData(intent)
initView() initView()
} }
@ -59,6 +64,15 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
}) })
} }
private fun upView(book: Book) {
actionBar?.title = book.name
ImageLoader.load(this, book.getDisplayCover())
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
AudioPlay.play( AudioPlay.play(
this, this,

@ -11,7 +11,6 @@ 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 import io.legado.app.model.WebBook
import io.legado.app.ui.book.read.ReadBookViewModel
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@ -19,7 +18,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
var inBookshelf = false var inBookshelf = false
var bookData = MutableLiveData<Book>() var bookData = MutableLiveData<Book>()
var chapterSize = 0 var chapterSize = 0
var callBack: ReadBookViewModel.CallBack? = null var callBack: CallBack? = null
var durChapterIndex = 0 var durChapterIndex = 0
var durPageIndex = 0 var durPageIndex = 0
var isLocalBook = true var isLocalBook = true
@ -55,7 +54,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
durChapterIndex = count - 1 durChapterIndex = count - 1
} }
chapterSize = count chapterSize = count
callBack?.loadContent()
} }
} }
saveRead(book) saveRead(book)
@ -155,7 +153,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
App.db.bookDao().delete(it.bookUrl) App.db.bookDao().delete(it.bookUrl)
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
callBack?.upContent()
} }
App.db.bookDao().insert(book) App.db.bookDao().insert(book)
bookData.postValue(book) bookData.postValue(book)
@ -182,7 +180,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
App.db.bookDao().update(book) App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray()) App.db.bookChapterDao().insert(*chapters.toTypedArray())
chapterSize = chapters.size chapterSize = chapters.size
callBack?.loadContent()
} }
} }

@ -17,7 +17,7 @@ class BooksAdapter(context: Context, private val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) { SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) = override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) { with(holder.itemView) {
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this) ATH.applyBackgroundTint(this)
@ -60,6 +60,7 @@ class BooksAdapter(context: Context, private val callBack: CallBack) :
} }
} }
} }
}
fun notification(bookUrl: String) { fun notification(bookUrl: String) {
for (i in 0 until itemCount) { for (i in 0 until itemCount) {

Loading…
Cancel
Save