From 4cd75abaa9c0d55a154d143369d69fd49023a0f1 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 3 Mar 2015 07:03:42 -0800 Subject: [PATCH] Don't unbundle an invalid NLI: use a static factory method rather than a constructor since the factory is allowed to fail. --- .../android/xw4/GamesListDelegate.java | 2 +- .../eehouse/android/xw4/NetLaunchInfo.java | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) 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 4a89f649f..380e58cea 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -968,7 +968,7 @@ public class GamesListDelegate extends ListDelegateBase m_rowid = bundle.getLong( SAVE_ROWID ); m_rowids = bundle.getLongArray( SAVE_ROWIDS ); m_groupid = bundle.getLong( SAVE_GROUPID ); - m_netLaunchInfo = new NetLaunchInfo( bundle ); + m_netLaunchInfo = NetLaunchInfo.makeFrom( bundle ); m_missingDictName = bundle.getString( SAVE_DICTNAMES ); m_nextIsSolo = bundle.getBoolean( SAVE_NEXTSOLO ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 33d89d793..89f1bde22 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -91,21 +91,33 @@ public class NetLaunchInfo { init( context, data ); } - public NetLaunchInfo( Bundle bundle ) + private NetLaunchInfo( Bundle bundle ) { - room = bundle.getString( MultiService.ROOM ); - m_inviteID = bundle.getString( MultiService.INVITEID ); lang = bundle.getInt( MultiService.LANG ); - forceChannel = bundle.getInt( MultiService.FORCECHANNEL ); - dict = bundle.getString( MultiService.DICT ); - gameName = bundle.getString( MultiService.GAMENAME ); - nPlayersT = bundle.getInt( MultiService.NPLAYERST ); - nPlayersH = bundle.getInt( MultiService.NPLAYERSH ); - m_gameID = bundle.getInt( MultiService.GAMEID ); - btName = bundle.getString( MultiService.BT_NAME ); - btAddress = bundle.getString( MultiService.BT_ADDRESS ); + if ( 0 != lang ) { // don't bother if it's invalid + room = bundle.getString( MultiService.ROOM ); + m_inviteID = bundle.getString( MultiService.INVITEID ); + forceChannel = bundle.getInt( MultiService.FORCECHANNEL ); + dict = bundle.getString( MultiService.DICT ); + gameName = bundle.getString( MultiService.GAMENAME ); + nPlayersT = bundle.getInt( MultiService.NPLAYERST ); + nPlayersH = bundle.getInt( MultiService.NPLAYERSH ); + m_gameID = bundle.getInt( MultiService.GAMEID ); + btName = bundle.getString( MultiService.BT_NAME ); + btAddress = bundle.getString( MultiService.BT_ADDRESS ); - m_addrs = new CommsConnTypeSet( bundle.getInt( ADDRS_KEY ) ); + m_addrs = new CommsConnTypeSet( bundle.getInt( ADDRS_KEY ) ); + } + } + + public static NetLaunchInfo makeFrom( Bundle bundle ) + { + NetLaunchInfo nli = new NetLaunchInfo( bundle ); + nli.calcValid(); + if ( !nli.isValid() ) { + nli = null; + } + return nli; } public NetLaunchInfo( Context context, Uri data )