From c2eff7d3f2fdfb067756cc1142259608c42428d7 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 12 Nov 2017 22:31:48 -0800 Subject: [PATCH] add "archive" option to dialog on opening done game Create the group if needed. Name's not user-editable at this point. Should be a preference, and that preference should be changed if user renames it. --- .../eehouse/android/xw4/BoardDelegate.java | 25 +++++++++++++++ .../java/org/eehouse/android/xw4/DBUtils.java | 32 +++++++++++++++++-- .../android/xw4/GamesListDelegate.java | 5 +-- .../app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 59 insertions(+), 5 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 35052ec90..71f60acf4 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -204,6 +204,21 @@ public class BoardDelegate extends DelegateBase } }; ab.setNegativeButton( R.string.button_rematch, lstnr ); + + // If we're not already in the "archive" group, offer to move + final String archiveName = LocUtils + .getString( m_activity, R.string.group_name_archive ); + final long archiveGroup = DBUtils.getGroup( m_activity, archiveName ); + long curGroup = DBUtils.getGroupForGame( m_activity, m_rowid ); + if ( curGroup != archiveGroup ) { + lstnr = new OnClickListener() { + public void onClick( DialogInterface dlg, + int whichButton ) { + archiveAndClose( archiveName, archiveGroup ); + } + }; + ab.setNeutralButton( R.string.button_archive, lstnr ); + } } else if ( DlgID.DLG_CONNSTAT == dlgID && BuildConfig.DEBUG && null != m_connTypes && (m_connTypes.contains( CommsConnType.COMMS_CONN_RELAY ) @@ -2575,6 +2590,16 @@ public class BoardDelegate extends DelegateBase return wordsArray; } + private void archiveAndClose( String archiveName, long groupID ) + { + if ( DBUtils.GROUPID_UNSPEC == groupID ) { + groupID = DBUtils.addGroup( m_activity, archiveName ); + } + DBUtils.moveGame( m_activity, m_rowid, groupID ); + waitCloseGame( false ); + finish(); + } + // For now, supported if standalone or either BT or SMS used for transport private boolean rematchSupported( boolean showMulti ) { 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 ec7782026..9f287b36b 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 @@ -81,7 +81,9 @@ public class DBUtils { private static long s_cachedRowID = ROWID_NOTFOUND; private static byte[] s_cachedBytes = null; - public static enum GameChangeType { GAME_CHANGED, GAME_CREATED, GAME_DELETED }; + public static enum GameChangeType { GAME_CHANGED, GAME_CREATED, + GAME_DELETED, GAME_MOVED, + }; public static interface DBChangeListener { public void gameSaved( long rowid, GameChangeType change ); @@ -1701,6 +1703,29 @@ public class DBUtils { return result; } + public static long getGroup( Context context, String name ) + { + long result = GROUPID_UNSPEC; + String[] columns = { ROW_ID }; + String selection = DBHelper.GROUPNAME + " = ?"; + String[] selArgs = { name }; + + initDB( context ); + synchronized( s_dbHelper ) { + Cursor cursor = s_db.query( DBHelper.TABLE_NAME_GROUPS, columns, + selection, selArgs, + null, // groupBy + null, // having + null // orderby + ); + if ( cursor.moveToNext() ) { + result = cursor.getLong( cursor.getColumnIndex( ROW_ID ) ); + } + cursor.close(); + } + return result; + } + public static long addGroup( Context context, String name ) { long rowid = GROUPID_UNSPEC; @@ -1759,13 +1784,14 @@ public class DBUtils { } // Change group id of a game - public static void moveGame( Context context, long gameid, long groupID ) + public static void moveGame( Context context, long rowid, long groupID ) { Assert.assertTrue( GROUPID_UNSPEC != groupID ); ContentValues values = new ContentValues(); values.put( DBHelper.GROUPID, groupID ); - updateRow( context, DBHelper.TABLE_NAME_SUM, gameid, values ); + updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values ); invalGroupsCache(); + notifyListeners( rowid, GameChangeType.GAME_MOVED ); } private static String getChatHistoryStr( Context context, long rowid ) 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 90a1dc2b1..06300270b 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 @@ -1060,8 +1060,6 @@ public class GamesListDelegate extends ListDelegateBase invalidateOptionsMenuIf(); setTitle(); } - - mkListAdapter(); } public void invalidateOptionsMenuIf() @@ -1133,6 +1131,9 @@ public class GamesListDelegate extends ListDelegateBase mkListAdapter(); setSelGame( rowid ); break; + case GAME_MOVED: + mkListAdapter(); + break; default: Assert.fail(); break; diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 4ba195973..c8342bb3a 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2158,6 +2158,8 @@ game with the same players and parameters as the one that just ended. --> Rematch + Archive\u200C + Archive Reconnect