mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
dabd23d2fd
@ -9,6 +9,9 @@ import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.utils.buildMainHandler
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import splitties.views.onLongClick
|
||||
import java.util.*
|
||||
|
||||
@ -31,6 +34,8 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
||||
private var itemClickListener: ((holder: ItemViewHolder, item: ITEM) -> Unit)? = null
|
||||
private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null
|
||||
|
||||
private var diffJob: Coroutine<*>? = null
|
||||
|
||||
var itemAnimation: ItemAnimation? = null
|
||||
|
||||
fun setOnItemClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Unit) {
|
||||
@ -139,15 +144,21 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
||||
return itemCallback.getChangePayload(oldItem, newItem)
|
||||
}
|
||||
}
|
||||
val diffResult = DiffUtil.calculateDiff(callback)
|
||||
if (this.items.isNotEmpty()) {
|
||||
this.items.clear()
|
||||
diffJob?.cancel()
|
||||
diffJob = Coroutine.async {
|
||||
val diffResult = DiffUtil.calculateDiff(callback)
|
||||
ensureActive()
|
||||
handler.post {
|
||||
if (this@RecyclerAdapter.items.isNotEmpty()) {
|
||||
this@RecyclerAdapter.items.clear()
|
||||
}
|
||||
if (items != null) {
|
||||
this@RecyclerAdapter.items.addAll(items)
|
||||
}
|
||||
diffResult.dispatchUpdatesTo(this@RecyclerAdapter)
|
||||
onCurrentListChanged()
|
||||
}
|
||||
}
|
||||
if (items != null) {
|
||||
this.items.addAll(items)
|
||||
}
|
||||
diffResult.dispatchUpdatesTo(this)
|
||||
onCurrentListChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@ -449,6 +460,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
||||
companion object {
|
||||
private const val TYPE_HEADER_VIEW = Int.MIN_VALUE
|
||||
private const val TYPE_FOOTER_VIEW = Int.MAX_VALUE - 999
|
||||
private val handler by lazy { buildMainHandler() }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,9 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
execute {
|
||||
appDb.dictRuleDao.update(*dictRule)
|
||||
}.onError {
|
||||
AppLog.put(it.localizedMessage, it)
|
||||
context.toastOnUi(it.localizedMessage)
|
||||
val msg = "更新字典规则出错\n${it.localizedMessage}"
|
||||
AppLog.put(msg, it)
|
||||
context.toastOnUi(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,8 +25,9 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
||||
execute {
|
||||
appDb.dictRuleDao.delete(*dictRule)
|
||||
}.onError {
|
||||
AppLog.put(it.localizedMessage, it)
|
||||
context.toastOnUi(it.localizedMessage)
|
||||
val msg = "删除字典规则出错\n${it.localizedMessage}"
|
||||
AppLog.put(msg, it)
|
||||
context.toastOnUi(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,14 +9,16 @@
|
||||
android:id="@+id/tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
|
||||
<TextView
|
||||
<io.legado.app.ui.widget.text.ScrollTextView
|
||||
android:id="@+id/tv_dict"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tab_layout" />
|
||||
|
||||
<io.legado.app.ui.widget.anima.RotateLoading
|
||||
|
Loading…
Reference in New Issue
Block a user