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

Loading…
Cancel
Save