mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-02 20:46:15 +01:00
cleanup: don't need wrapper around a List<>
This commit is contained in:
parent
2a845da9b6
commit
0953772673
3 changed files with 18 additions and 34 deletions
|
@ -34,6 +34,7 @@ import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
|
||||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
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: m_stamps is serialized, so can't be abstract type
|
||||||
HashMap<String, Long> stamps = new HashMap<>();
|
HashMap<String, Long> stamps = new HashMap<>();
|
||||||
|
|
||||||
void add( BluetoothDevice dev ) {
|
void add( String devAddress, String devName ) {
|
||||||
String devName = dev.getName();
|
|
||||||
Log.d( TAG, "add(%s)", devName );
|
|
||||||
// If it's already there, update it. Otherwise create new
|
// If it's already there, update it. Otherwise create new
|
||||||
boolean alreadyHave = false;
|
boolean alreadyHave = false;
|
||||||
if ( null != pairs ) {
|
if ( null == pairs ) {
|
||||||
|
pairs = new ArrayList<>();
|
||||||
|
} else {
|
||||||
for ( TwoStringPair pair : pairs ) {
|
for ( TwoStringPair pair : pairs ) {
|
||||||
alreadyHave = pair.str2.equals(devName);
|
alreadyHave = pair.str2.equals(devName);
|
||||||
if ( alreadyHave ) {
|
if ( alreadyHave ) {
|
||||||
|
@ -68,8 +69,9 @@ public class BTInviteDelegate extends InviteDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !alreadyHave ) {
|
if ( !alreadyHave ) {
|
||||||
pairs = TwoStringPair.add( pairs, dev.getAddress(), devName );
|
pairs.add( new TwoStringPair( devAddress, devName ) );
|
||||||
}
|
}
|
||||||
stamps.put( devName, System.currentTimeMillis() );
|
stamps.put( devName, System.currentTimeMillis() );
|
||||||
sort();
|
sort();
|
||||||
|
@ -80,7 +82,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
||||||
for ( InviterItem item : checked ) {
|
for ( InviterItem item : checked ) {
|
||||||
TwoStringPair pair = (TwoStringPair)item;
|
TwoStringPair pair = (TwoStringPair)item;
|
||||||
stamps.remove( pair.str2 );
|
stamps.remove( pair.str2 );
|
||||||
TwoStringPair.remove( pairs, pair );
|
pairs.remove( pair );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,8 +104,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
||||||
{
|
{
|
||||||
String name = "Faker";
|
String name = "Faker";
|
||||||
if ( !stamps.containsKey(name) ) {
|
if ( !stamps.containsKey(name) ) {
|
||||||
pairs = TwoStringPair.add( pairs, "00:00:00:00:00:00", name );
|
add( "00:00:00:00:00:00", name );
|
||||||
stamps.put( name, System.currentTimeMillis() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +248,7 @@ public class BTInviteDelegate extends InviteDelegate {
|
||||||
{
|
{
|
||||||
DbgUtils.assertOnUIThread();
|
DbgUtils.assertOnUIThread();
|
||||||
|
|
||||||
mPersisted.add( dev );
|
mPersisted.add( dev.getAddress(), dev.getName() );
|
||||||
store();
|
store();
|
||||||
|
|
||||||
updateListAdapter( mPersisted.pairs );
|
updateListAdapter( mPersisted.pairs );
|
||||||
|
|
|
@ -58,41 +58,24 @@ abstract class InviteDelegate extends ListDelegateBase
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class TwoStringPair implements InviterItem, Serializable {
|
protected static class TwoStringPair implements InviterItem, Serializable {
|
||||||
public String str1;
|
private String mDev;
|
||||||
public String str2;
|
public String str2;
|
||||||
|
|
||||||
public TwoStringPair( String str1, String str2 ) {
|
public TwoStringPair( String dev, String str2 ) {
|
||||||
this.str1 = str1; this.str2 = str2;
|
mDev = dev; this.str2 = str2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<TwoStringPair> add( List<TwoStringPair> pairs, String name,
|
public String getDev() { return mDev; }
|
||||||
String addr )
|
|
||||||
{
|
|
||||||
if ( null == pairs ) {
|
|
||||||
pairs = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
pairs.add( new TwoStringPair( name, addr ) );
|
|
||||||
|
|
||||||
return pairs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void remove( List<TwoStringPair> pairs, InviterItem dead )
|
|
||||||
{
|
|
||||||
pairs.remove(dead);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDev() { return str1; }
|
|
||||||
|
|
||||||
public boolean equals( InviterItem item )
|
public boolean equals( InviterItem item )
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if ( null != item ) {
|
if ( null != item ) {
|
||||||
TwoStringPair pair = (TwoStringPair)item;
|
TwoStringPair pair = (TwoStringPair)item;
|
||||||
result = str1.equals( pair.str1 )
|
result = mDev.equals( pair.mDev )
|
||||||
&& ((null == str2 && null == pair.str2)
|
&& ((null == str2 && null == pair.str2)
|
||||||
|| str2.equals( 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class WiDirInviteDelegate extends InviteDelegate
|
||||||
protected void onChildAdded( View child, InviterItem data )
|
protected void onChildAdded( View child, InviterItem data )
|
||||||
{
|
{
|
||||||
TwoStringPair pair = (TwoStringPair)data;
|
TwoStringPair pair = (TwoStringPair)data;
|
||||||
((TwoStrsItem)child).setStrings( pair.str2, pair.str1 );
|
((TwoStrsItem)child).setStrings( pair.str2, pair.getDev() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -89,7 +89,7 @@ public class WiDirInviteDelegate extends InviteDelegate
|
||||||
{
|
{
|
||||||
for ( int ii = 0; ii < selected.length; ++ii ) {
|
for ( int ii = 0; ii < selected.length; ++ii ) {
|
||||||
TwoStringPair pair = (TwoStringPair)selected[ii];
|
TwoStringPair pair = (TwoStringPair)selected[ii];
|
||||||
devs[ii] = pair.str1;
|
devs[ii] = pair.getDev();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue