Keyed...: Rename all the things

Hooray for diamond interface inheritance.

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland 2018-01-06 23:07:17 -06:00
parent 4d38993832
commit 4f2b6bef84
9 changed files with 32 additions and 33 deletions

View File

@ -21,7 +21,7 @@ import com.wireguard.android.activity.SettingsActivity;
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.model.TunnelManager; import com.wireguard.android.model.TunnelManager;
import com.wireguard.android.util.KeyedObservableList; import com.wireguard.android.util.ObservableKeyedList;
import java.util.Objects; 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 currentName = tunnel != null ? tunnel.getName() : null;
final String newName = preferences.getString(TunnelManager.KEY_PRIMARY_TUNNEL, null); final String newName = preferences.getString(TunnelManager.KEY_PRIMARY_TUNNEL, null);
if (!Objects.equals(currentName, newName)) { if (!Objects.equals(currentName, newName)) {
final KeyedObservableList<String, Tunnel> tunnels = tunnelManager.getTunnels(); final ObservableKeyedList<String, Tunnel> tunnels = tunnelManager.getTunnels();
final Tunnel newTunnel = newName != null ? tunnels.get(newName) : null; final Tunnel newTunnel = newName != null ? tunnels.get(newName) : null;
if (tunnel != null) if (tunnel != null)
tunnel.removeOnPropertyChangedCallback(tunnelCallback); tunnel.removeOnPropertyChangedCallback(tunnelCallback);

View File

@ -11,7 +11,7 @@ import android.widget.TextView;
import com.wireguard.android.R; import com.wireguard.android.R;
import com.wireguard.android.util.Keyed; 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;
import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener; import com.wireguard.android.widget.ToggleSwitch.OnBeforeCheckedChangeListener;
@ -68,13 +68,13 @@ public final class BindingAdapters {
@BindingAdapter({"items", "layout"}) @BindingAdapter({"items", "layout"})
public static <K, E extends Keyed<? extends K>> public static <K, E extends Keyed<? extends K>>
void setItems(final ListView view, void setItems(final ListView view,
final KeyedObservableList<K, E> oldList, final int oldLayoutId, final ObservableKeyedList<K, E> oldList, final int oldLayoutId,
final KeyedObservableList<K, E> newList, final int newLayoutId) { final ObservableKeyedList<K, E> newList, final int newLayoutId) {
if (oldList == newList && oldLayoutId == newLayoutId) if (oldList == newList && oldLayoutId == newLayoutId)
return; return;
// The ListAdapter interface is not generic, so this cannot be checked. // The ListAdapter interface is not generic, so this cannot be checked.
@SuppressWarnings("unchecked") KeyedObservableListAdapter<K, E> adapter = @SuppressWarnings("unchecked") ObservableKeyedListAdapter<K, E> adapter =
(KeyedObservableListAdapter<K, E>) view.getAdapter(); (ObservableKeyedListAdapter<K, E>) view.getAdapter();
// If the layout changes, any existing adapter must be replaced. // If the layout changes, any existing adapter must be replaced.
if (adapter != null && oldList != null && oldLayoutId != newLayoutId) { if (adapter != null && oldList != null && oldLayoutId != newLayoutId) {
adapter.setList(null); adapter.setList(null);
@ -84,7 +84,7 @@ public final class BindingAdapters {
if (newList == null || newLayoutId == 0) if (newList == null || newLayoutId == 0)
return; return;
if (adapter == null) { if (adapter == null) {
adapter = new KeyedObservableListAdapter<>(view.getContext(), newLayoutId, newList); adapter = new ObservableKeyedListAdapter<>(view.getContext(), newLayoutId, newList);
view.setAdapter(adapter); view.setAdapter(adapter);
} }
// Either the list changed, or this is an entirely new listener because the layout changed. // Either the list changed, or this is an entirely new listener because the layout changed.

View File

@ -11,22 +11,22 @@ import android.widget.BaseAdapter;
import com.wireguard.android.BR; import com.wireguard.android.BR;
import com.wireguard.android.util.Keyed; import com.wireguard.android.util.Keyed;
import com.wireguard.android.util.KeyedObservableList; import com.wireguard.android.util.ObservableKeyedList;
import java.lang.ref.WeakReference; 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<K, E extends Keyed<? extends K>> extends BaseAdapter { class ObservableKeyedListAdapter<K, E extends Keyed<? extends K>> extends BaseAdapter {
private final OnListChangedCallback<E> callback = new OnListChangedCallback<>(this); private final OnListChangedCallback<E> callback = new OnListChangedCallback<>(this);
private final int layoutId; private final int layoutId;
private final LayoutInflater layoutInflater; private final LayoutInflater layoutInflater;
private KeyedObservableList<K, E> list; private ObservableKeyedList<K, E> list;
KeyedObservableListAdapter(final Context context, final int layoutId, ObservableKeyedListAdapter(final Context context, final int layoutId,
final KeyedObservableList<K, E> list) { final ObservableKeyedList<K, E> list) {
this.layoutId = layoutId; this.layoutId = layoutId;
layoutInflater = LayoutInflater.from(context); layoutInflater = LayoutInflater.from(context);
setList(list); setList(list);
@ -72,7 +72,7 @@ class KeyedObservableListAdapter<K, E extends Keyed<? extends K>> extends BaseAd
return true; return true;
} }
void setList(final KeyedObservableList<K, E> newList) { void setList(final ObservableKeyedList<K, E> newList) {
if (list != null) if (list != null)
list.removeOnListChangedCallback(callback); list.removeOnListChangedCallback(callback);
list = newList; list = newList;
@ -85,15 +85,15 @@ class KeyedObservableListAdapter<K, E extends Keyed<? extends K>> extends BaseAd
private static final class OnListChangedCallback<E extends Keyed<?>> private static final class OnListChangedCallback<E extends Keyed<?>>
extends ObservableList.OnListChangedCallback<ObservableList<E>> { extends ObservableList.OnListChangedCallback<ObservableList<E>> {
private final WeakReference<KeyedObservableListAdapter<?, E>> weakAdapter; private final WeakReference<ObservableKeyedListAdapter<?, E>> weakAdapter;
private OnListChangedCallback(final KeyedObservableListAdapter<?, E> adapter) { private OnListChangedCallback(final ObservableKeyedListAdapter<?, E> adapter) {
weakAdapter = new WeakReference<>(adapter); weakAdapter = new WeakReference<>(adapter);
} }
@Override @Override
public void onChanged(final ObservableList<E> sender) { public void onChanged(final ObservableList<E> sender) {
final KeyedObservableListAdapter adapter = weakAdapter.get(); final ObservableKeyedListAdapter adapter = weakAdapter.get();
if (adapter != null) if (adapter != null)
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
else else

View File

@ -8,8 +8,8 @@ import com.wireguard.android.configStore.ConfigStore;
import com.wireguard.android.model.Tunnel.State; import com.wireguard.android.model.Tunnel.State;
import com.wireguard.android.model.Tunnel.Statistics; import com.wireguard.android.model.Tunnel.Statistics;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.util.KeyedObservableList; import com.wireguard.android.util.ObservableKeyedList;
import com.wireguard.android.util.SortedKeyedObservableArrayList; import com.wireguard.android.util.ObservableSortedKeyedArrayList;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import java.util.Collections; import java.util.Collections;
@ -37,8 +37,8 @@ public final class TunnelManager {
private final Backend backend; private final Backend backend;
private final ConfigStore configStore; private final ConfigStore configStore;
private final SharedPreferences preferences; private final SharedPreferences preferences;
private final KeyedObservableList<String, Tunnel> tunnels = private final ObservableKeyedList<String, Tunnel> tunnels =
new SortedKeyedObservableArrayList<>(); new ObservableSortedKeyedArrayList<>();
@Inject @Inject
public TunnelManager(final Backend backend, final ConfigStore configStore, public TunnelManager(final Backend backend, final ConfigStore configStore,
@ -82,7 +82,7 @@ public final class TunnelManager {
return backend.getStatistics(tunnel).thenApply(tunnel::onStatisticsChanged); return backend.getStatistics(tunnel).thenApply(tunnel::onStatisticsChanged);
} }
public KeyedObservableList<String, Tunnel> getTunnels() { public ObservableKeyedList<String, Tunnel> getTunnels() {
return tunnels; return tunnels;
} }

View File

@ -14,8 +14,8 @@ import java.util.Objects;
* operations, require O(n) time. * operations, require O(n) time.
*/ */
public class KeyedObservableArrayList<K, E extends Keyed<? extends K>> public class ObservableKeyedArrayList<K, E extends Keyed<? extends K>>
extends ObservableArrayList<E> implements KeyedObservableList<K, E> { extends ObservableArrayList<E> implements ObservableKeyedList<K, E> {
@Override @Override
public boolean add(final E e) { public boolean add(final E e) {
if (e == null) if (e == null)

View File

@ -6,6 +6,6 @@ import android.databinding.ObservableList;
* A list that is both keyed and observable. * A list that is both keyed and observable.
*/ */
public interface KeyedObservableList<K, E extends Keyed<? extends K>> public interface ObservableKeyedList<K, E extends Keyed<? extends K>>
extends KeyedList<K, E>, ObservableList<E> { extends KeyedList<K, E>, ObservableList<E> {
} }

View File

@ -14,9 +14,8 @@ import java.util.List;
* key still require O(n) time. * key still require O(n) time.
*/ */
public class SortedKeyedObservableArrayList<K extends Comparable<? super K>, public class ObservableSortedKeyedArrayList<K extends Comparable<? super K>,
E extends Keyed<? extends K>> extends KeyedObservableArrayList<K, E> { E extends Keyed<? extends K>> extends ObservableKeyedArrayList<K, E> {
private final transient List<K> keyList = new KeyList<>(this); private final transient List<K> keyList = new KeyList<>(this);
@Override @Override
@ -87,9 +86,9 @@ public class SortedKeyedObservableArrayList<K extends Comparable<? super K>,
private static final class KeyList<K extends Comparable<? super K>, private static final class KeyList<K extends Comparable<? super K>,
E extends Keyed<? extends K>> extends AbstractList<K> { E extends Keyed<? extends K>> extends AbstractList<K> {
private final SortedKeyedObservableArrayList<K, E> list; private final ObservableSortedKeyedArrayList<K, E> list;
private KeyList(final SortedKeyedObservableArrayList<K, E> list) { private KeyList(final ObservableSortedKeyedArrayList<K, E> list) {
this.list = list; this.list = list;
} }

View File

@ -12,7 +12,7 @@
<variable <variable
name="tunnels" name="tunnels"
type="com.wireguard.android.util.KeyedObservableList&lt;String, Tunnel&gt;" /> type="com.wireguard.android.util.ObservableKeyedList&lt;String, Tunnel&gt;" />
</data> </data>
<com.commonsware.cwac.crossport.design.widget.CoordinatorLayout <com.commonsware.cwac.crossport.design.widget.CoordinatorLayout

View File

@ -10,7 +10,7 @@
<variable <variable
name="collection" name="collection"
type="com.wireguard.android.util.KeyedObservableList&lt;String, Tunnel&gt;" /> type="com.wireguard.android.util.ObservableKeyedList&lt;String, Tunnel&gt;" />
<variable <variable
name="key" name="key"