diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java index 2c67c644e..e5a8d0597 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -2679,8 +2679,7 @@ public class BoardDelegate extends DelegateBase CommsConnTypeSet connTypes = summary.conTypes; String newName = summary.getRematchName(); Intent intent = GamesListDelegate - .makeRematchIntent( activity, rowid, gi.dictName, - gi.dictLang, connTypes, btAddr, + .makeRematchIntent( activity, rowid, gi, connTypes, btAddr, phone, relayID, newName ); if ( null != intent ) { activity.startActivity( intent ); 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 b2ba0e4a2..b189f0675 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -470,7 +470,7 @@ public class GameUtils { return makeNewMultiGame( context, sink, util, DBUtils.GROUPID_UNSPEC, addr, new int[] {nli.lang}, - new String[] { nli.dict }, nli.nPlayersT, + new String[] { nli.dict }, null, nli.nPlayersT, nli.nPlayersH, nli.forceChannel, nli.inviteID(), nli.gameID(), nli.gameName, false ); @@ -479,23 +479,24 @@ public class GameUtils { public static long makeNewMultiGame( Context context, long groupID, String gameName ) { - return makeNewMultiGame( context, groupID, null, 0, + return makeNewMultiGame( context, groupID, null, 0, null, (CommsConnTypeSet)null, gameName ); } public static long makeNewMultiGame( Context context, long groupID, - String dict, int lang, + String dict, int lang, String jsonData, CommsConnTypeSet addrSet, String gameName ) { String inviteID = makeRandomID(); return makeNewMultiGame( context, groupID, inviteID, dict, lang, - addrSet, gameName ); + jsonData, addrSet, gameName ); } private static long makeNewMultiGame( Context context, long groupID, String inviteID, String dict, - int lang, CommsConnTypeSet addrSet, + int lang, String jsonData, + CommsConnTypeSet addrSet, String gameName ) { int[] langArray = {lang}; @@ -507,14 +508,16 @@ public class GameUtils { addr.populate( context ); int forceChannel = 0; return makeNewMultiGame( context, (MultiMsgSink)null, (UtilCtxt)null, - groupID, addr, langArray, dictArray, 2, 1, - forceChannel, inviteID, 0, gameName, true ); + groupID, addr, langArray, dictArray, jsonData, + 2, 1, forceChannel, inviteID, 0, gameName, + true ); } private static long makeNewMultiGame( Context context, MultiMsgSink sink, UtilCtxt util, long groupID, CommsAddrRec addr, - int[] lang, String[] dict, + int[] lang, String[] dict, + String jsonData, int nPlayersT, int nPlayersH, int forceChannel, String inviteID, int gameID, String gameName, @@ -524,6 +527,7 @@ public class GameUtils { Assert.assertNotNull( inviteID ); CurGameInfo gi = new CurGameInfo( context, inviteID ); + gi.setFrom( jsonData ); gi.setLang( lang[0], dict[0] ); gi.forceChannel = forceChannel; lang[0] = gi.dictLang; @@ -599,7 +603,7 @@ public class GameUtils { } String inviteID = GameUtils.formatGameID( gameID ); return makeNewMultiGame( context, sink, (UtilCtxt)null, groupID, addr, - langa, dicta, nPlayersT, nPlayersH, + langa, dicta, null, nPlayersT, nPlayersH, forceChannel, inviteID, gameID, gameName, isHost ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java index 8e2863e46..11bcc11e1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -89,6 +89,7 @@ public class GamesListDelegate extends ListDelegateBase private static final String REMATCH_ROWID_EXTRA = "rm_rowid"; private static final String REMATCH_DICT_EXTRA = "rm_dict"; private static final String REMATCH_LANG_EXTRA = "rm_lang"; + private static final String REMATCH_PREFS_EXTRA = "rm_prefs"; private static final String REMATCH_NEWNAME_EXTRA = "rm_nnm"; private static final String REMATCH_ADDRS_EXTRA = "rm_addrs"; private static final String REMATCH_BTADDR_EXTRA = "rm_btaddr"; @@ -2058,6 +2059,7 @@ public class GamesListDelegate extends ListDelegateBase String relayID = intent.getStringExtra( REMATCH_RELAYID_EXTRA ); String dict = intent.getStringExtra( REMATCH_DICT_EXTRA ); int lang = intent.getIntExtra( REMATCH_LANG_EXTRA, -1 ); + String json = intent.getStringExtra( REMATCH_PREFS_EXTRA ); int bits = intent.getIntExtra( REMATCH_ADDRS_EXTRA, -1 ); CommsConnTypeSet addrs = new CommsConnTypeSet( bits ); @@ -2068,7 +2070,7 @@ public class GamesListDelegate extends ListDelegateBase } else { long groupID = DBUtils.getGroupForGame( m_activity, srcRowID ); newid = GameUtils.makeNewMultiGame( m_activity, groupID, dict, - lang, addrs, gameName ); + lang, json, addrs, gameName ); DBUtils.addRematchInfo( m_activity, newid, btAddr, phone, relayID ); } @@ -2508,7 +2510,7 @@ public class GamesListDelegate extends ListDelegateBase } public static Intent makeRematchIntent( Context context, long rowid, - String dict, int lang, + CurGameInfo gi, CommsConnTypeSet addrTypes, String btAddr, String phone, String relayID, String newName ) @@ -2517,8 +2519,9 @@ public class GamesListDelegate extends ListDelegateBase if ( XWApp.REMATCH_SUPPORTED ) { intent = makeSelfIntent( context ); intent.putExtra( REMATCH_ROWID_EXTRA, rowid ); - intent.putExtra( REMATCH_DICT_EXTRA, dict ); - intent.putExtra( REMATCH_LANG_EXTRA, lang ); + intent.putExtra( REMATCH_DICT_EXTRA, gi.dictName ); + intent.putExtra( REMATCH_LANG_EXTRA, gi.dictLang ); + intent.putExtra( REMATCH_PREFS_EXTRA, gi.getJSONData() ); intent.putExtra( REMATCH_NEWNAME_EXTRA, newName ); if ( null != addrTypes ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java index 00a4e55b1..8b5b8a20d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CurGameInfo.java @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Random; import junit.framework.Assert; +import org.json.JSONObject; import org.eehouse.android.xw4.DbgUtils; import org.eehouse.android.xw4.DictUtils; @@ -37,6 +38,12 @@ public class CurGameInfo { public static final int MAX_NUM_PLAYERS = 4; + private static final String BOARD_SIZE = "BOARD_SIZE"; + private static final String NO_HINTS = "NO_HINTS"; + private static final String TIMER = "TIMER"; + private static final String ALLOW_PICK = "ALLOW_PICK"; + private static final String PHONIES = "PHONIES"; + public enum XWPhoniesChoice { PHONIES_IGNORE, PHONIES_WARN, PHONIES_DISALLOW }; public enum DeviceRole { SERVER_STANDALONE, SERVER_ISSERVER, SERVER_ISCLIENT }; @@ -143,6 +150,42 @@ public class CurGameInfo { } } + public String getJSONData() + { + String jsonData = null; + try { + JSONObject obj = new JSONObject() + .put( BOARD_SIZE, boardSize ) + .put( NO_HINTS, hintsNotAllowed ) + .put( TIMER, timerEnabled ) + .put( ALLOW_PICK, allowPickTiles ) + .put( PHONIES, phoniesAction.ordinal() ) + ; + jsonData = obj.toString(); + } catch ( org.json.JSONException jse ) { + DbgUtils.loge( jse ); + } + + return jsonData; + } + + public void setFrom( String jsonData ) + { + if ( null != jsonData ) { + try { + JSONObject obj = new JSONObject( jsonData ); + boardSize = obj.optInt( BOARD_SIZE, boardSize ); + hintsNotAllowed = obj.optBoolean( NO_HINTS, hintsNotAllowed ); + timerEnabled = obj.optBoolean( TIMER, timerEnabled ); + allowPickTiles = obj.optBoolean( ALLOW_PICK, allowPickTiles ); + int tmp = obj.optInt( PHONIES, phoniesAction.ordinal() ); + phoniesAction = XWPhoniesChoice.values()[tmp]; + } catch ( org.json.JSONException jse ) { + DbgUtils.loge( jse ); + } + } + } + public void setServerRole( DeviceRole newRole ) { serverRole = newRole;