feat: 优化代码

pull/98/head
kunfei 5 years ago
parent eb33ea1e17
commit 2acf5ae253
  1. 13
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  2. 57
      app/src/main/java/io/legado/app/ui/widget/DetailSeekBar.kt
  3. 2
      app/src/main/java/io/legado/app/ui/widget/ViewDetailSeekBar.kt
  4. 4
      app/src/main/res/values/attrs.xml

@ -1,6 +1,7 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import android.os.Bundle
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
@ -15,8 +16,9 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
BaseBooksAdapter(context, R.layout.item_bookshelf_grid) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
val bundle = payloads.getOrNull(0) as? Bundle
with(holder.itemView) {
if (payloads.isEmpty()) {
if (bundle == null) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
bv_author.text = item.author
@ -35,9 +37,12 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bundle.keySet().map {
when (it) {
"name" -> tv_name.text = item.name
"author" -> bv_author.text = item.author
"cover" -> iv_cover.load(item.getDisplayCover(), item.name, item.author)
"refresh" -> if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {

@ -0,0 +1,57 @@
package io.legado.app.ui.widget
import android.content.Context
import android.util.AttributeSet
import android.view.Gravity
import android.view.View
import android.widget.SeekBar
import androidx.appcompat.widget.LinearLayoutCompat
import io.legado.app.R
import io.legado.app.utils.progressAdd
import kotlinx.android.synthetic.main.view_detail_seek_bar.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class DetailSeekBar(context: Context, attrs: AttributeSet?) : LinearLayoutCompat(context, attrs),
SeekBar.OnSeekBarChangeListener {
private var valueFormat: String? = null
private var onChanged: ((progress: Int) -> Unit)? = null
val progress: Int
get() = seek_bar.progress
init {
gravity = Gravity.CENTER_VERTICAL
View.inflate(context, R.layout.view_detail_seek_bar, this)
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.DetailSeekBar)
tv_seek_title.text = typedArray.getText(R.styleable.DetailSeekBar_title)
typedArray.recycle()
iv_seek_add.onClick {
seek_bar.progressAdd(1)
onChanged?.invoke(seek_bar.progress)
}
iv_seek_remove.onClick {
seek_bar.progressAdd(-1)
onChanged?.invoke(seek_bar.progress)
}
seek_bar.setOnSeekBarChangeListener(this)
}
private fun upValue() {
}
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
onChanged?.invoke(seek_bar.progress)
}
}

@ -65,6 +65,10 @@
<attr name="speed" format="dimension"/>
</declare-styleable>
<declare-styleable name="DetailSeekBar">
<attr name="title" format="string" />
</declare-styleable>
<declare-styleable name="SmoothCheckBox">
<attr name="duration" format="integer"/>
<attr name="stroke_width" format="dimension"/>

Loading…
Cancel
Save