This commit is contained in:
Horis
2024-09-01 11:44:10 +08:00
parent dde4af4517
commit 73588feb06
2 changed files with 22 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.activity
import io.legado.app.utils.dpToPx
import io.legado.app.utils.gone
import io.legado.app.utils.removeLastElement
import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.startActivity
import io.legado.app.utils.visible
@@ -118,9 +119,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
return if (recycler.isEmpty()) {
ItemFilletTextBinding.inflate(inflater, flexbox, false).root
} else {
recycler.last().also {
recycler.removeLast()
} as TextView
recycler.removeLastElement() as TextView
}
}
@@ -174,11 +173,13 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
putExtra("type", "bookSource")
putExtra("key", source.bookSourceUrl)
}
R.id.menu_refresh -> Coroutine.async(callBack.scope) {
source.clearExploreKindsCache()
}.onSuccess {
notifyItemChanged(position)
}
R.id.menu_del -> callBack.deleteSource(source)
}
true

View File

@@ -14,9 +14,16 @@ inline fun <T> List<T>.fastBinarySearch(
comparison: (T) -> Int
): Int {
when {
fromIndex > toIndex -> throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex).")
fromIndex < 0 -> throw IndexOutOfBoundsException("fromIndex ($fromIndex) is less than zero.")
toIndex > size -> throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).")
fromIndex > toIndex ->
throw IllegalArgumentException(
"fromIndex ($fromIndex) is greater than toIndex ($toIndex)."
)
fromIndex < 0 ->
throw IndexOutOfBoundsException("fromIndex ($fromIndex) is less than zero.")
toIndex > size ->
throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).")
}
var low = fromIndex
@@ -43,3 +50,11 @@ inline fun <T, K : Comparable<K>> List<T>.fastBinarySearchBy(
toIndex: Int = size,
crossinline selector: (T) -> K?
): Int = fastBinarySearch(fromIndex, toIndex) { compareValues(selector(it), key) }
fun <T> MutableList<T>.removeLastElement(): T {
return if (isEmpty()) {
throw NoSuchElementException("List is empty.")
} else {
removeAt(lastIndex)
}
}