diff options
Diffstat (limited to 'ui/src/main/java/com/wireguard/android')
4 files changed, 9 insertions, 30 deletions
diff --git a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt index 87248b57..3460e96e 100644 --- a/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt +++ b/ui/src/main/java/com/wireguard/android/databinding/BindingAdapters.kt @@ -90,7 +90,7 @@ object BindingAdapters { @BindingAdapter(requireAll = false, value = ["items", "layout", "configurationHandler"]) fun <K, E : Keyed<out K>> setItems(view: RecyclerView, oldList: ObservableKeyedArrayList<K, E>?, oldLayoutId: Int, - oldRowConfigurationHandler: RowConfigurationHandler<*, *>?, + @Suppress("UNUSED_PARAMETER") oldRowConfigurationHandler: RowConfigurationHandler<*, *>?, newList: ObservableKeyedArrayList<K, E>?, newLayoutId: Int, newRowConfigurationHandler: RowConfigurationHandler<*, *>?) { if (view.layoutManager == null) @@ -98,7 +98,7 @@ object BindingAdapters { if (oldList === newList && oldLayoutId == newLayoutId) return // The ListAdapter interface is not generic, so this cannot be checked. - var adapter = view.adapter as ObservableKeyedRecyclerViewAdapter<K, E>? + @Suppress("UNCHECKED_CAST") var adapter = view.adapter as? ObservableKeyedRecyclerViewAdapter<K, E>? // If the layout changes, any existing adapter must be replaced. if (adapter != null && oldList != null && oldLayoutId != newLayoutId) { adapter.setList(null) diff --git a/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.kt b/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.kt index 72c2495b..c3bfb3bb 100644 --- a/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.kt +++ b/ui/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.kt @@ -4,6 +4,7 @@ */ package com.wireguard.android.databinding +import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup @@ -55,6 +56,7 @@ class ObservableKeyedRecyclerViewAdapter<K, E : Keyed<out K>> internal construct } fun setRowConfigurationHandler(rowConfigurationHandler: RowConfigurationHandler<*, *>?) { + @Suppress("UNCHECKED_CAST") this.rowConfigurationHandler = rowConfigurationHandler as? RowConfigurationHandler<ViewDataBinding, Any> } diff --git a/ui/src/main/java/com/wireguard/android/databinding/ObservableSortedKeyedArrayList.kt b/ui/src/main/java/com/wireguard/android/databinding/ObservableSortedKeyedArrayList.kt index 9261d202..d00065a1 100644 --- a/ui/src/main/java/com/wireguard/android/databinding/ObservableSortedKeyedArrayList.kt +++ b/ui/src/main/java/com/wireguard/android/databinding/ObservableSortedKeyedArrayList.kt @@ -16,7 +16,7 @@ import java.util.Spliterator * array-based nature of this class, insertion and removal of elements with anything but the largest * key still require O(n) time. */ -class ObservableSortedKeyedArrayList<K, E : Keyed<out K>>(private val comparator: Comparator<in K>?) : ObservableKeyedArrayList<K, E>() { +class ObservableSortedKeyedArrayList<K, E : Keyed<out K>>(private val comparator: Comparator<in K>) : ObservableKeyedArrayList<K, E>() { @Transient private val keyList = KeyList(this) @@ -54,34 +54,15 @@ class ObservableSortedKeyedArrayList<K, E : Keyed<out K>>(private val comparator return true } - private fun getInsertionPoint(e: E): Int { - return if (comparator != null) { - -Collections.binarySearch(keyList, e.key, comparator) - 1 - } else { - val list = keyList as List<Comparable<K>> - -Collections.binarySearch(list, e.key) - 1 - } - } + private fun getInsertionPoint(e: E) = -Collections.binarySearch(keyList, e.key, comparator) - 1 override fun indexOfKey(key: K): Int { - val index: Int - index = if (comparator != null) { - Collections.binarySearch(keyList, key, comparator) - } else { - val list = keyList as List<Comparable<K>> - Collections.binarySearch(list, key) - } + val index = Collections.binarySearch(keyList, key, comparator) return if (index >= 0) index else -1 } override fun set(index: Int, element: E): E { - val order: Int - order = if (comparator != null) { - comparator.compare(element.key, get(index).key) - } else { - val key = element.key as Comparable<K> - key.compareTo(get(index).key) - } + val order = comparator.compare(element.key, get(index).key) if (order != 0) { // Allow replacement if the new key would be inserted adjacent to the replaced element. val insertionPoint = getInsertionPoint(element) @@ -91,10 +72,6 @@ class ObservableSortedKeyedArrayList<K, E : Keyed<out K>>(private val comparator return super.set(index, element) } - fun values(): Collection<E> { - return this - } - private class KeyList<K, E : Keyed<out K>>(private val list: ObservableSortedKeyedArrayList<K, E>) : AbstractList<K>(), Set<K> { override fun get(index: Int): K = list[index].key diff --git a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt index 1762fa58..8e834260 100644 --- a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt @@ -35,7 +35,7 @@ class KernelModuleDisablerPreference(context: Context, attrs: AttributeSet?) : P } Application.getAsyncWorker().runAsync { Application.getTunnelManager().tunnels.thenApply { observableTunnels -> - val downings = observableTunnels.values().map { it.setStateAsync(Tunnel.State.DOWN).toCompletableFuture() }.toTypedArray() + val downings = observableTunnels.map { it.setStateAsync(Tunnel.State.DOWN).toCompletableFuture() }.toTypedArray() CompletableFuture.allOf(*downings).thenRun { val restartIntent = Intent(context, SettingsActivity::class.java) restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) |