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. 75
      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.widget.SeekBar
import androidx.lifecycle.Observer
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.ImageLoader
import io.legado.app.service.help.AudioPlay
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent
@ -24,6 +27,8 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
viewModel.callBack = this
viewModel.bookData.observe(this, Observer { upView(it) })
viewModel.initData(intent)
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) {
AudioPlay.play(
this,

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

@ -17,49 +17,50 @@ class BooksAdapter(context: Context, private val callBack: CallBack) :
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) {
if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
tv_read.text = item.durChapterTitle
tv_last.text = item.latestChapterTitle
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)
true
}
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
tv_read.text = item.durChapterTitle
tv_last.text = item.latestChapterTitle
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.setAsDrawable(iv_cover)
}
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)
true
}
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
}
}
}
}
}
}
fun notification(bookUrl: String) {
for (i in 0 until itemCount) {

Loading…
Cancel
Save