From df093e1c109c2e1f82ee3f1e3097899cd2bc4a10 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 17 Oct 2014 07:55:04 -0700 Subject: [PATCH] preexisting db field now a set, so treat it that way in the other place it's read --- .../src/org/eehouse/android/xw4/DBUtils.java | 14 ++++++++++---- .../src/org/eehouse/android/xw4/GameUtils.java | 15 ++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 790ddd621..96884daaa 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -522,10 +522,10 @@ public class DBUtils { return result; } - public static HashMap + public static HashMap getGamesWithSendsPending( Context context ) { - HashMap result = new HashMap(); + HashMap result = new HashMap(); String[] columns = { ROW_ID, DBHelper.CONTYPE }; String selection = String.format( "%s > 0", DBHelper.NPACKETSPENDING ); initDB( context ); @@ -537,8 +537,10 @@ public class DBUtils { int indx2 = cursor.getColumnIndex( DBHelper.CONTYPE ); for ( int ii = 0; cursor.moveToNext(); ++ii ) { long rowid = cursor.getLong( indx1 ); - CommsConnType typ = CommsConnType.values()[cursor.getInt(indx2)]; - result.put( rowid, typ ); + CommsConnTypeSet typs = intToConnTypeSet( cursor.getInt(indx2) ); + // Better have an address if has pending sends + Assert.assertTrue( 0 < typs.size() ); + result.put( rowid, typs ); } cursor.close(); db.close(); @@ -2134,6 +2136,7 @@ public class DBUtils { private static final int BIT_VECTOR_MASK = 0x8000; private static CommsConnTypeSet intToConnTypeSet( int asInt ) { + DbgUtils.logf( "intToConnTypeSet(in: %s)", asInt ); CommsConnTypeSet result = new CommsConnTypeSet(); boolean isVector = 0 != (BIT_VECTOR_MASK & asInt); asInt &= ~BIT_VECTOR_MASK; @@ -2142,6 +2145,7 @@ public class DBUtils { for ( CommsConnType value : values ) { int ord = value.ordinal(); if ( 0 != (asInt & (1 << (ord - 1)))) { + DbgUtils.logf( "intToConnTypeSet: adding %s", value.toString() ); result.add( value ); } } @@ -2153,9 +2157,11 @@ public class DBUtils { private static int connTypeSetToInt( CommsConnTypeSet set ) { + DbgUtils.logf( "connTypeSetToInt(setSize: %d)", set.size() ); int result = BIT_VECTOR_MASK; for ( Iterator iter = set.iterator(); iter.hasNext(); ) { CommsConnType typ = iter.next(); + DbgUtils.logf( "connTypeSetToInt: adding %s", typ.toString() ); result |= 1 << (typ.ordinal() - 1); } return result; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index d189a5de0..da4aee6eb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -46,6 +46,7 @@ import junit.framework.Assert; import org.eehouse.android.xw4.jni.*; import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; +import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet; import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole; import org.eehouse.android.xw4.jni.LastMoveInfo; @@ -391,7 +392,8 @@ public class GameUtils { } if ( force ) { - HashMap games = DBUtils.getGamesWithSendsPending( context ); + HashMap games = + DBUtils.getGamesWithSendsPending( context ); if ( 0 < games.size() ) { new ResendTask( context, games, filter, showUI ).execute(); } @@ -1076,12 +1078,12 @@ public class GameUtils { private static class ResendTask extends AsyncTask { private Context m_context; - private HashMap m_games; + private HashMap m_games; private boolean m_showUI; private CommsConnType m_filter; private int m_nSent = 0; - public ResendTask( Context context, HashMap games, + public ResendTask( Context context, HashMap games, CommsConnType filter, boolean showUI ) { m_context = context; @@ -1096,8 +1098,11 @@ public class GameUtils { Iterator iter = m_games.keySet().iterator(); while ( iter.hasNext() ) { long rowid = iter.next(); - if ( null != m_filter && m_filter != m_games.get( rowid ) ) { - continue; + if ( null != m_filter ) { + CommsConnTypeSet gameSet = m_games.get( rowid ); + if ( gameSet != null && ! gameSet.contains( m_filter ) ) { + continue; + } } GameLock lock = new GameLock( rowid, false );