diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java index 504aa4e92..83a6d3a5e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DBUtils.java @@ -1460,9 +1460,15 @@ public class DBUtils { m_lastMoveTime = 0; m_count = count; } + + @Override + public String toString() + { + return String.format( "GameGroupInfo: {name: %s}", m_name ); + } } - private static HashMap s_groupsCache = null; + private static Map s_groupsCache = null; private static void invalGroupsCache() { @@ -1513,11 +1519,10 @@ public class DBUtils { } // Map of groups rowid (= summaries.groupid) to group info record - protected static HashMap getGroups( Context context ) + protected static Map getGroups( Context context ) { if ( null == s_groupsCache ) { - HashMap result = - new HashMap(); + Map result = new HashMap<>(); // Select all groups. For each group get the number of games in // that group. There should be a way to do that with one query @@ -1556,27 +1561,10 @@ public class DBUtils { } s_groupsCache = result; } + Log.d( TAG, "getGroups() => %s", s_groupsCache ); return s_groupsCache; } // getGroups - // public static void unhideTo( Context context, long groupID ) - // { - // Assert.assertTrue( GROUPID_UNSPEC != groupID ); - // initDB( context ); - // synchronized( s_dbHelper ) { - // SQLiteDatabase db = s_dbHelper.getWritableDatabase(); - // ContentValues values = new ContentValues(); - // values.put( DBHelper.GROUPID, groupID ); - // String selection = String.format( "%s = %d", DBHelper.GROUPID, - // GROUPID_UNSPEC ); - // long result = db.update( DBHelper.TABLE_NAME_SUM, - // values, selection, null ); - // db.close(); - - // notifyListeners( ROWID_NOTFOUND, true ); - // } - // } - private static void readTurnInfo( SQLiteDatabase db, long groupID, GameGroupInfo ggi ) { @@ -1725,7 +1713,7 @@ public class DBUtils { public static long getAnyGroup( Context context ) { long result = GROUPID_UNSPEC; - HashMap groups = getGroups( context ); + Map groups = getGroups( context ); Iterator iter = groups.keySet().iterator(); if ( iter.hasNext() ) { result = iter.next(); @@ -1754,6 +1742,7 @@ public class DBUtils { } cursor.close(); } + Log.d( TAG, "getGroup(%s) => %d", name, result ); return result; } @@ -1761,8 +1750,7 @@ public class DBUtils { { long rowid = GROUPID_UNSPEC; if ( null != name && 0 < name.length() ) { - HashMap gameInfo = getGroups( context ); - if ( null == gameInfo.get( name ) ) { + if ( null == getGroups( context ).get( name ) ) { ContentValues values = new ContentValues(); values.put( DBHelper.GROUPNAME, name ); values.put( DBHelper.EXPANDED, 1 ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java index b42e2234e..653d3dafa 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GamesListDelegate.java @@ -43,6 +43,7 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; +import android.text.TextUtils; import org.eehouse.android.xw4.DBUtils.GameChangeType; import org.eehouse.android.xw4.DBUtils.GameGroupInfo; @@ -137,7 +138,7 @@ public class GamesListDelegate extends ListDelegateBase GameListAdapter() { super( new Class[] { GroupRec.class, GameRec.class } ); - m_groupPositions = checkPositions(); + m_groupPositions = checkGroupPositions(); } protected Object[] makeListData() @@ -310,7 +311,7 @@ public class GamesListDelegate extends ListDelegateBase if ( null == m_groupPositions || m_groupPositions.length != keys.size() ) { - HashSet unused = new HashSet( keys ); + HashSet unused = new HashSet<>( keys ); long[] newArray = new long[unused.size()]; // First copy the existing values, in order @@ -342,6 +343,7 @@ public class GamesListDelegate extends ListDelegateBase void moveGroup( long groupID, boolean moveUp ) { + Log.d( TAG, "moveGroup(up=%b)", moveUp ); int src = getGroupPosition( groupID ); int dest = src + (moveUp ? -1 : 1); @@ -538,14 +540,14 @@ public class GamesListDelegate extends ListDelegateBase return result; } - private long[] checkPositions() + private long[] checkGroupPositions() { long[] result = XWPrefs.getGroupPositions( m_activity ); if ( null != result ) { - final Map gameInfo = + final Map groups = DBUtils.getGroups( m_activity ); - Set posns = gameInfo.keySet(); + Set posns = groups.keySet(); if ( result.length != posns.size() ) { result = null; } else { @@ -557,6 +559,14 @@ public class GamesListDelegate extends ListDelegateBase } } } + + if ( BuildConfig.DEBUG && null != result ) { + List list = new ArrayList<>(); + for ( long ll : result ) { + list.add( ll ); + } + Log.d( TAG, "checkGroupPositions() => %s", TextUtils.join(",", list )); + } return result; } } // class GameListAdapter