From 095377267339af97f9392a72f8b27aa52a1d23b5 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 6 Jan 2019 16:58:30 -0800 Subject: [PATCH] cleanup: don't need wrapper around a List<> --- .../eehouse/android/xw4/BTInviteDelegate.java | 19 ++++++------ .../eehouse/android/xw4/InviteDelegate.java | 29 ++++--------------- .../android/xw4/WiDirInviteDelegate.java | 4 +-- 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java index 80f9f13cf..56bfc204e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BTInviteDelegate.java @@ -34,6 +34,7 @@ import org.eehouse.android.xw4.DBUtils.SentInvitesInfo; import org.eehouse.android.xw4.DlgDelegate.Action; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -55,12 +56,12 @@ public class BTInviteDelegate extends InviteDelegate { // HashMap: m_stamps is serialized, so can't be abstract type HashMap stamps = new HashMap<>(); - void add( BluetoothDevice dev ) { - String devName = dev.getName(); - Log.d( TAG, "add(%s)", devName ); + void add( String devAddress, String devName ) { // If it's already there, update it. Otherwise create new boolean alreadyHave = false; - if ( null != pairs ) { + if ( null == pairs ) { + pairs = new ArrayList<>(); + } else { for ( TwoStringPair pair : pairs ) { alreadyHave = pair.str2.equals(devName); if ( alreadyHave ) { @@ -68,8 +69,9 @@ public class BTInviteDelegate extends InviteDelegate { } } } + if ( !alreadyHave ) { - pairs = TwoStringPair.add( pairs, dev.getAddress(), devName ); + pairs.add( new TwoStringPair( devAddress, devName ) ); } stamps.put( devName, System.currentTimeMillis() ); sort(); @@ -80,7 +82,7 @@ public class BTInviteDelegate extends InviteDelegate { for ( InviterItem item : checked ) { TwoStringPair pair = (TwoStringPair)item; stamps.remove( pair.str2 ); - TwoStringPair.remove( pairs, pair ); + pairs.remove( pair ); } } @@ -102,8 +104,7 @@ public class BTInviteDelegate extends InviteDelegate { { String name = "Faker"; if ( !stamps.containsKey(name) ) { - pairs = TwoStringPair.add( pairs, "00:00:00:00:00:00", name ); - stamps.put( name, System.currentTimeMillis() ); + add( "00:00:00:00:00:00", name ); } } } @@ -247,7 +248,7 @@ public class BTInviteDelegate extends InviteDelegate { { DbgUtils.assertOnUIThread(); - mPersisted.add( dev ); + mPersisted.add( dev.getAddress(), dev.getName() ); store(); updateListAdapter( mPersisted.pairs ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java index 36a322027..deabdb008 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteDelegate.java @@ -58,41 +58,24 @@ abstract class InviteDelegate extends ListDelegateBase } protected static class TwoStringPair implements InviterItem, Serializable { - public String str1; + private String mDev; public String str2; - public TwoStringPair( String str1, String str2 ) { - this.str1 = str1; this.str2 = str2; + public TwoStringPair( String dev, String str2 ) { + mDev = dev; this.str2 = str2; } - public static List add( List pairs, String name, - String addr ) - { - if ( null == pairs ) { - pairs = new ArrayList<>(); - } - - pairs.add( new TwoStringPair( name, addr ) ); - - return pairs; - } - - public static void remove( List pairs, InviterItem dead ) - { - pairs.remove(dead); - } - - public String getDev() { return str1; } + public String getDev() { return mDev; } public boolean equals( InviterItem item ) { boolean result = false; if ( null != item ) { TwoStringPair pair = (TwoStringPair)item; - result = str1.equals( pair.str1 ) + result = mDev.equals( pair.mDev ) && ((null == str2 && null == pair.str2) || str2.equals( pair.str2 ) ); - Log.d( TAG, "%s.equals(%s) => %b", str1, pair.str1, result ); + Log.d( TAG, "%s.equals(%s) => %b", mDev, pair.mDev, result ); } return result; } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java index 7628604f8..eaff78b08 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/WiDirInviteDelegate.java @@ -81,7 +81,7 @@ public class WiDirInviteDelegate extends InviteDelegate protected void onChildAdded( View child, InviterItem data ) { TwoStringPair pair = (TwoStringPair)data; - ((TwoStrsItem)child).setStrings( pair.str2, pair.str1 ); + ((TwoStrsItem)child).setStrings( pair.str2, pair.getDev() ); } @Override @@ -89,7 +89,7 @@ public class WiDirInviteDelegate extends InviteDelegate { for ( int ii = 0; ii < selected.length; ++ii ) { TwoStringPair pair = (TwoStringPair)selected[ii]; - devs[ii] = pair.str1; + devs[ii] = pair.getDev(); } }