From 37094b72f3f24146676d7775089546a542a05451 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 23 Sep 2015 19:11:43 -0700 Subject: [PATCH] fix crash, and clean up rematch game naming code. Deals with solo games too though not used. --- .../eehouse/android/xw4/BoardDelegate.java | 3 +- .../org/eehouse/android/xw4/GameUtils.java | 2 +- .../android/xw4/GamesListDelegate.java | 30 +++++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) 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 690650ff0..c55f0a896 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardDelegate.java @@ -2585,10 +2585,11 @@ public class BoardDelegate extends DelegateBase if ( doIt ) { String[] opponents = m_gi.getRemoteNames(); + String opponent = (0 == opponents.length) ? null : opponents[0]; Intent intent = GamesListDelegate .makeRematchIntent( m_activity, m_rowid, m_gi.dictName, m_gi.dictLang, m_connTypes, btAddr, - phone, relayID, opponents[0] ); + phone, relayID, opponent ); if ( null != intent ) { startActivity( intent ); finish(); 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 362196f93..8ed4853e9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -260,7 +260,7 @@ public class GameUtils { return result; } - public static String makeDefaultName( Context context, boolean isSolo ) + public static String makeDefaultName( Context context ) { int count = DBUtils.getIncrementIntFor( context, DBUtils.KEY_NEWGAMECOUNT, 0, 1 ); return LocUtils.getString( context, R.string.game_fmt, count ); 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 db172b59b..8d9fe9c89 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesListDelegate.java @@ -851,7 +851,7 @@ public class GamesListDelegate extends ListDelegateBase dialog = makeAlertBuilder() .setView( view ) .setTitle( R.string.button_rematch ) - .setIcon( R.drawable.multigame__gen ) + .setIcon( R.drawable.sologame__gen ) .setPositiveButton( android.R.string.ok, new OnClickListener() { public void onClick( DialogInterface dlg, int item ) { EditText edit = (EditText)((Dialog)dlg) @@ -883,29 +883,33 @@ public class GamesListDelegate extends ListDelegateBase ad.getButton( AlertDialog.BUTTON_NEGATIVE ) .setVisibility( canDoDefaults ? View.VISIBLE : View.GONE ); + ad.setIcon( m_nextIsSolo ? R.drawable.sologame__gen + : R.drawable.multigame__gen ); + ad.setTitle( m_nextIsSolo ? R.string.new_game + : R.string.new_game_networked); + String msg = getString( canDoDefaults ? R.string.new_game_message : R.string.new_game_message_nodflt ); - if ( m_nextIsSolo ) { - ad.setTitle( R.string.new_game ); - ad.setIcon( R.drawable.sologame__gen ); - } else { - ad.setTitle( R.string.new_game_networked ); - ad.setIcon( R.drawable.multigame__gen ); - + if ( !m_nextIsSolo ) { msg += "\n\n" + getString( R.string.new_game_message_net ); } TextView edit = (TextView)dialog.findViewById( R.id.msg ); edit.setText( msg ); edit = (TextView)dialog.findViewById( R.id.edit ); - edit.setText( GameUtils.makeDefaultName( m_activity, m_nextIsSolo ) ); + edit.setText( GameUtils.makeDefaultName( m_activity ) ); edit.setVisibility( View.VISIBLE ); break; case GAMES_LIST_NAME_REMATCH: edit = (TextView)dialog.findViewById( R.id.edit ); - String name = getString( R.string.rematch_name_fmt, - m_rematchOpponent ); + boolean solo = m_rematchOpponent == null; + String name = solo + ? GameUtils.makeDefaultName( m_activity ) + : getString( R.string.rematch_name_fmt, m_rematchOpponent ); edit.setText( name ); + int icon = solo + ? R.drawable.sologame__gen : R.drawable.multigame__gen; + ad.setIcon( icon ); ((TextView)dialog.findViewById( R.id.msg )) .setVisibility( View.GONE ); break; @@ -2316,7 +2320,9 @@ public class GamesListDelegate extends ListDelegateBase intent.putExtra( REMATCH_ROWID_EXTRA, rowid ); intent.putExtra( REMATCH_DICT_EXTRA, dict ); intent.putExtra( REMATCH_LANG_EXTRA, lang ); - intent.putExtra( REMATCH_OPPONENT_EXTRA, opponent ); + if ( null != opponent ) { + intent.putExtra( REMATCH_OPPONENT_EXTRA, opponent ); + } if ( null != addrTypes ) { intent.putExtra( REMATCH_ADDRS_EXTRA, addrTypes.toInt() ); // here if ( null != btAddr ) {