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.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewbinding.ViewBinding
|
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 splitties.views.onLongClick
|
||||||
import java.util.*
|
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 itemClickListener: ((holder: ItemViewHolder, item: ITEM) -> Unit)? = null
|
||||||
private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null
|
private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null
|
||||||
|
|
||||||
|
private var diffJob: Coroutine<*>? = null
|
||||||
|
|
||||||
var itemAnimation: ItemAnimation? = null
|
var itemAnimation: ItemAnimation? = null
|
||||||
|
|
||||||
fun setOnItemClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Unit) {
|
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)
|
return itemCallback.getChangePayload(oldItem, newItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val diffResult = DiffUtil.calculateDiff(callback)
|
diffJob?.cancel()
|
||||||
if (this.items.isNotEmpty()) {
|
diffJob = Coroutine.async {
|
||||||
this.items.clear()
|
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 {
|
companion object {
|
||||||
private const val TYPE_HEADER_VIEW = Int.MIN_VALUE
|
private const val TYPE_HEADER_VIEW = Int.MIN_VALUE
|
||||||
private const val TYPE_FOOTER_VIEW = Int.MAX_VALUE - 999
|
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 {
|
execute {
|
||||||
appDb.dictRuleDao.update(*dictRule)
|
appDb.dictRuleDao.update(*dictRule)
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put(it.localizedMessage, it)
|
val msg = "更新字典规则出错\n${it.localizedMessage}"
|
||||||
context.toastOnUi(it.localizedMessage)
|
AppLog.put(msg, it)
|
||||||
|
context.toastOnUi(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,8 +25,9 @@ class DictRuleViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
execute {
|
execute {
|
||||||
appDb.dictRuleDao.delete(*dictRule)
|
appDb.dictRuleDao.delete(*dictRule)
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put(it.localizedMessage, it)
|
val msg = "删除字典规则出错\n${it.localizedMessage}"
|
||||||
context.toastOnUi(it.localizedMessage)
|
AppLog.put(msg, it)
|
||||||
|
context.toastOnUi(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,14 +9,16 @@
|
|||||||
android:id="@+id/tab_layout"
|
android:id="@+id/tab_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="16dp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:ignore="SpeakableTextPresentCheck" />
|
tools:ignore="SpeakableTextPresentCheck" />
|
||||||
|
|
||||||
<TextView
|
<io.legado.app.ui.widget.text.ScrollTextView
|
||||||
android:id="@+id/tv_dict"
|
android:id="@+id/tv_dict"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/tab_layout" />
|
app:layout_constraintTop_toBottomOf="@id/tab_layout" />
|
||||||
|
|
||||||
<io.legado.app.ui.widget.anima.RotateLoading
|
<io.legado.app.ui.widget.anima.RotateLoading
|
||||||
|
Loading…
Reference in New Issue
Block a user