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
@@ -23,6 +23,7 @@ import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.activity import io.legado.app.utils.activity
import io.legado.app.utils.dpToPx import io.legado.app.utils.dpToPx
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.removeLastElement
import io.legado.app.utils.showDialogFragment import io.legado.app.utils.showDialogFragment
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.visible import io.legado.app.utils.visible
@@ -118,9 +119,7 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
return if (recycler.isEmpty()) { return if (recycler.isEmpty()) {
ItemFilletTextBinding.inflate(inflater, flexbox, false).root ItemFilletTextBinding.inflate(inflater, flexbox, false).root
} else { } else {
recycler.last().also { recycler.removeLastElement() as TextView
recycler.removeLast()
} as TextView
} }
} }
@@ -174,11 +173,13 @@ class ExploreAdapter(context: Context, val callBack: CallBack) :
putExtra("type", "bookSource") putExtra("type", "bookSource")
putExtra("key", source.bookSourceUrl) putExtra("key", source.bookSourceUrl)
} }
R.id.menu_refresh -> Coroutine.async(callBack.scope) { R.id.menu_refresh -> Coroutine.async(callBack.scope) {
source.clearExploreKindsCache() source.clearExploreKindsCache()
}.onSuccess { }.onSuccess {
notifyItemChanged(position) notifyItemChanged(position)
} }
R.id.menu_del -> callBack.deleteSource(source) R.id.menu_del -> callBack.deleteSource(source)
} }
true true
@@ -14,9 +14,16 @@ inline fun <T> List<T>.fastBinarySearch(
comparison: (T) -> Int comparison: (T) -> Int
): Int { ): Int {
when { when {
fromIndex > toIndex -> throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex).") fromIndex > toIndex ->
fromIndex < 0 -> throw IndexOutOfBoundsException("fromIndex ($fromIndex) is less than zero.") throw IllegalArgumentException(
toIndex > size -> throw IndexOutOfBoundsException("toIndex ($toIndex) is greater than size ($size).") "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 var low = fromIndex
@@ -43,3 +50,11 @@ inline fun <T, K : Comparable<K>> List<T>.fastBinarySearchBy(
toIndex: Int = size, toIndex: Int = size,
crossinline selector: (T) -> K? crossinline selector: (T) -> K?
): Int = fastBinarySearch(fromIndex, toIndex) { compareValues(selector(it), key) } ): 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)
}
}