mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user