From 4f2b6bef84f75bc17101a17c60251fc0df43aae1 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 6 Jan 2018 23:07:17 -0600 Subject: [PATCH] Keyed...: Rename all the things Hooray for diamond interface inheritance. Signed-off-by: Samuel Holland --- .../wireguard/android/QuickTileService.java | 4 ++-- .../android/databinding/BindingAdapters.java | 12 +++++------ ...r.java => ObservableKeyedListAdapter.java} | 20 +++++++++---------- .../android/model/TunnelManager.java | 10 +++++----- ...ist.java => ObservableKeyedArrayList.java} | 4 ++-- ...ableList.java => ObservableKeyedList.java} | 2 +- ...va => ObservableSortedKeyedArrayList.java} | 9 ++++----- .../main/res/layout/tunnel_list_fragment.xml | 2 +- app/src/main/res/layout/tunnel_list_item.xml | 2 +- 9 files changed, 32 insertions(+), 33 deletions(-) rename app/src/main/java/com/wireguard/android/databinding/{KeyedObservableListAdapter.java => ObservableKeyedListAdapter.java} (85%) rename app/src/main/java/com/wireguard/android/util/{KeyedObservableArrayList.java => ObservableKeyedArrayList.java} (95%) rename app/src/main/java/com/wireguard/android/util/{KeyedObservableList.java => ObservableKeyedList.java} (75%) rename app/src/main/java/com/wireguard/android/util/{SortedKeyedObservableArrayList.java => ObservableSortedKeyedArrayList.java} (92%) diff --git a/app/src/main/java/com/wireguard/android/QuickTileService.java b/app/src/main/java/com/wireguard/android/QuickTileService.java index 10563b6e..3b652a5b 100644 --- a/app/src/main/java/com/wireguard/android/QuickTileService.java +++ b/app/src/main/java/com/wireguard/android/QuickTileService.java @@ -21,7 +21,7 @@ import com.wireguard.android.activity.SettingsActivity; import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.TunnelManager; -import com.wireguard.android.util.KeyedObservableList; +import com.wireguard.android.util.ObservableKeyedList; import java.util.Objects; @@ -104,7 +104,7 @@ public class QuickTileService extends TileService implements OnSharedPreferenceC final String currentName = tunnel != null ? tunnel.getName() : null; final String newName = preferences.getString(TunnelManager.KEY_PRIMARY_TUNNEL, null); if (!Objects.equals(currentName, newName)) { - final KeyedObservableList tunnels = tunnelManager.getTunnels(); + final ObservableKeyedList tunnels = tunnelManager.getTunnels(); final Tunnel newTunnel = newName != null ? tunnels.get(newName) : null; if (tunnel != null) tunnel.removeOnPropertyChangedCallback(tunnelCallback); diff --git a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java index f4dd2aff..34ddb010 100644 --- a/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java +++ b/app/src/main/java/com/wireguard/android/databinding/BindingAdapters.java @@ -11,7 +11,7 @@ import android.widget.TextView; import com.wireguard.android.R; import com.wireguard.android.util.Keyed; -import com.wireguard.android.util.KeyedObservableList; +import com.wireguard.android.util.ObservableKeyedList; import com.wireguard.android.widget.ToggleSwitch; import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener; @@ -68,13 +68,13 @@ public final class BindingAdapters { @BindingAdapter({"items", "layout"}) public static > void setItems(final ListView view, - final KeyedObservableList oldList, final int oldLayoutId, - final KeyedObservableList newList, final int newLayoutId) { + final ObservableKeyedList oldList, final int oldLayoutId, + final ObservableKeyedList newList, final int newLayoutId) { if (oldList == newList && oldLayoutId == newLayoutId) return; // The ListAdapter interface is not generic, so this cannot be checked. - @SuppressWarnings("unchecked") KeyedObservableListAdapter adapter = - (KeyedObservableListAdapter) view.getAdapter(); + @SuppressWarnings("unchecked") ObservableKeyedListAdapter adapter = + (ObservableKeyedListAdapter) view.getAdapter(); // If the layout changes, any existing adapter must be replaced. if (adapter != null && oldList != null && oldLayoutId != newLayoutId) { adapter.setList(null); @@ -84,7 +84,7 @@ public final class BindingAdapters { if (newList == null || newLayoutId == 0) return; if (adapter == null) { - adapter = new KeyedObservableListAdapter<>(view.getContext(), newLayoutId, newList); + adapter = new ObservableKeyedListAdapter<>(view.getContext(), newLayoutId, newList); view.setAdapter(adapter); } // Either the list changed, or this is an entirely new listener because the layout changed. diff --git a/app/src/main/java/com/wireguard/android/databinding/KeyedObservableListAdapter.java b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java similarity index 85% rename from app/src/main/java/com/wireguard/android/databinding/KeyedObservableListAdapter.java rename to app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java index d1d377aa..b22c8909 100644 --- a/app/src/main/java/com/wireguard/android/databinding/KeyedObservableListAdapter.java +++ b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedListAdapter.java @@ -11,22 +11,22 @@ import android.widget.BaseAdapter; import com.wireguard.android.BR; import com.wireguard.android.util.Keyed; -import com.wireguard.android.util.KeyedObservableList; +import com.wireguard.android.util.ObservableKeyedList; import java.lang.ref.WeakReference; /** - * A generic {@code ListAdapter} backed by a {@code KeyedObservableList}. + * A generic {@code ListAdapter} backed by a {@code ObservableKeyedList}. */ -class KeyedObservableListAdapter> extends BaseAdapter { +class ObservableKeyedListAdapter> extends BaseAdapter { private final OnListChangedCallback callback = new OnListChangedCallback<>(this); private final int layoutId; private final LayoutInflater layoutInflater; - private KeyedObservableList list; + private ObservableKeyedList list; - KeyedObservableListAdapter(final Context context, final int layoutId, - final KeyedObservableList list) { + ObservableKeyedListAdapter(final Context context, final int layoutId, + final ObservableKeyedList list) { this.layoutId = layoutId; layoutInflater = LayoutInflater.from(context); setList(list); @@ -72,7 +72,7 @@ class KeyedObservableListAdapter> extends BaseAd return true; } - void setList(final KeyedObservableList newList) { + void setList(final ObservableKeyedList newList) { if (list != null) list.removeOnListChangedCallback(callback); list = newList; @@ -85,15 +85,15 @@ class KeyedObservableListAdapter> extends BaseAd private static final class OnListChangedCallback> extends ObservableList.OnListChangedCallback> { - private final WeakReference> weakAdapter; + private final WeakReference> weakAdapter; - private OnListChangedCallback(final KeyedObservableListAdapter adapter) { + private OnListChangedCallback(final ObservableKeyedListAdapter adapter) { weakAdapter = new WeakReference<>(adapter); } @Override public void onChanged(final ObservableList sender) { - final KeyedObservableListAdapter adapter = weakAdapter.get(); + final ObservableKeyedListAdapter adapter = weakAdapter.get(); if (adapter != null) adapter.notifyDataSetChanged(); else diff --git a/app/src/main/java/com/wireguard/android/model/TunnelManager.java b/app/src/main/java/com/wireguard/android/model/TunnelManager.java index 123f5b51..68bb541a 100644 --- a/app/src/main/java/com/wireguard/android/model/TunnelManager.java +++ b/app/src/main/java/com/wireguard/android/model/TunnelManager.java @@ -8,8 +8,8 @@ import com.wireguard.android.configStore.ConfigStore; import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.Tunnel.Statistics; import com.wireguard.android.util.ExceptionLoggers; -import com.wireguard.android.util.KeyedObservableList; -import com.wireguard.android.util.SortedKeyedObservableArrayList; +import com.wireguard.android.util.ObservableKeyedList; +import com.wireguard.android.util.ObservableSortedKeyedArrayList; import com.wireguard.config.Config; import java.util.Collections; @@ -37,8 +37,8 @@ public final class TunnelManager { private final Backend backend; private final ConfigStore configStore; private final SharedPreferences preferences; - private final KeyedObservableList tunnels = - new SortedKeyedObservableArrayList<>(); + private final ObservableKeyedList tunnels = + new ObservableSortedKeyedArrayList<>(); @Inject public TunnelManager(final Backend backend, final ConfigStore configStore, @@ -82,7 +82,7 @@ public final class TunnelManager { return backend.getStatistics(tunnel).thenApply(tunnel::onStatisticsChanged); } - public KeyedObservableList getTunnels() { + public ObservableKeyedList getTunnels() { return tunnels; } diff --git a/app/src/main/java/com/wireguard/android/util/KeyedObservableArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java similarity index 95% rename from app/src/main/java/com/wireguard/android/util/KeyedObservableArrayList.java rename to app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java index 101f0ba7..6ba76207 100644 --- a/app/src/main/java/com/wireguard/android/util/KeyedObservableArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedArrayList.java @@ -14,8 +14,8 @@ import java.util.Objects; * operations, require O(n) time. */ -public class KeyedObservableArrayList> - extends ObservableArrayList implements KeyedObservableList { +public class ObservableKeyedArrayList> + extends ObservableArrayList implements ObservableKeyedList { @Override public boolean add(final E e) { if (e == null) diff --git a/app/src/main/java/com/wireguard/android/util/KeyedObservableList.java b/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java similarity index 75% rename from app/src/main/java/com/wireguard/android/util/KeyedObservableList.java rename to app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java index 15df0bba..af9fd34d 100644 --- a/app/src/main/java/com/wireguard/android/util/KeyedObservableList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableKeyedList.java @@ -6,6 +6,6 @@ import android.databinding.ObservableList; * A list that is both keyed and observable. */ -public interface KeyedObservableList> +public interface ObservableKeyedList> extends KeyedList, ObservableList { } diff --git a/app/src/main/java/com/wireguard/android/util/SortedKeyedObservableArrayList.java b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java similarity index 92% rename from app/src/main/java/com/wireguard/android/util/SortedKeyedObservableArrayList.java rename to app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java index 21fcccd3..9ccc1c10 100644 --- a/app/src/main/java/com/wireguard/android/util/SortedKeyedObservableArrayList.java +++ b/app/src/main/java/com/wireguard/android/util/ObservableSortedKeyedArrayList.java @@ -14,9 +14,8 @@ import java.util.List; * key still require O(n) time. */ -public class SortedKeyedObservableArrayList, - E extends Keyed> extends KeyedObservableArrayList { - +public class ObservableSortedKeyedArrayList, + E extends Keyed> extends ObservableKeyedArrayList { private final transient List keyList = new KeyList<>(this); @Override @@ -87,9 +86,9 @@ public class SortedKeyedObservableArrayList, private static final class KeyList, E extends Keyed> extends AbstractList { - private final SortedKeyedObservableArrayList list; + private final ObservableSortedKeyedArrayList list; - private KeyList(final SortedKeyedObservableArrayList list) { + private KeyList(final ObservableSortedKeyedArrayList list) { this.list = list; } diff --git a/app/src/main/res/layout/tunnel_list_fragment.xml b/app/src/main/res/layout/tunnel_list_fragment.xml index fa489840..ba3728a3 100644 --- a/app/src/main/res/layout/tunnel_list_fragment.xml +++ b/app/src/main/res/layout/tunnel_list_fragment.xml @@ -12,7 +12,7 @@ + type="com.wireguard.android.util.ObservableKeyedList<String, Tunnel>" /> + type="com.wireguard.android.util.ObservableKeyedList<String, Tunnel>" />