From f1eea13c5ed07628fa91a80c2168a4085995edb8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 26 Oct 2020 11:02:42 -0700 Subject: [PATCH] remember last invitee and make default next time --- .../org/eehouse/android/xw4/GamesListDelegate.java | 7 +++++-- .../java/org/eehouse/android/xw4/NewWithKnowns.java | 11 ++++++++++- .../app/src/main/res/layout/new_game_with_knowns.xml | 4 ++-- xwords4/android/app/src/main/res/values/strings.xml | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) 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 4e46af8ec..939892a7c 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 @@ -86,6 +86,7 @@ public class GamesListDelegate extends ListDelegateBase private static final String SAVE_NEXTSOLO = "SAVE_NEXTSOLO"; private static final String SAVE_REMATCHEXTRAS = "SAVE_REMATCHEXTRAS"; private static final String SAVE_MYSIS = TAG + "/MYSIS"; + private static final String KP_NAME_KEY = TAG + "/kp_last_name"; private static final String RELAYIDS_EXTRA = "relayids"; private static final String ROWID_EXTRA = "rowid"; @@ -965,10 +966,11 @@ public class GamesListDelegate extends ListDelegateBase private Dialog mkNewWithKnowns() { String[] names = XwJNI.kplr_getPlayers(); - final String[] nameRef = {null}; + final String[] nameRef + = { DBUtils.getStringFor( m_activity, KP_NAME_KEY, null ) }; final NewWithKnowns view = (NewWithKnowns) LocUtils.inflate( m_activity, R.layout.new_game_with_knowns ); - view.setNames( names, GameUtils.makeDefaultName( m_activity ) ); + view.setNames( names, nameRef[0], GameUtils.makeDefaultName( m_activity ) ); AlertDialog.Builder ab = makeAlertBuilder() .setView( view ) .setTitle( R.string.new_game_networked ) @@ -977,6 +979,7 @@ public class GamesListDelegate extends ListDelegateBase @Override public void onClick( DialogInterface dlg, int item ) { Assert.assertTrueNR( null != nameRef[0] ); + DBUtils.setStringFor( m_activity, KP_NAME_KEY, nameRef[0] ); CommsAddrRec addr = XwJNI.kplr_getAddr( nameRef[0] ); if ( null != addr ) { launchLikeRematch( addr, view.gameName() ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java index 25e0aae65..763a1c2b1 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/NewWithKnowns.java @@ -20,6 +20,7 @@ package org.eehouse.android.xw4; import android.content.Context; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; import android.widget.AdapterView.OnItemSelectedListener; @@ -49,7 +50,7 @@ public class NewWithKnowns extends LinearLayout implements OnItemSelectedListene mListener = listener; } - void setNames( String[] knowns, String gameName ) + void setNames( String[] knowns, String dflt, String gameName ) { ArrayAdapter adapter = new ArrayAdapter( getContext(), @@ -60,6 +61,14 @@ public class NewWithKnowns extends LinearLayout implements OnItemSelectedListene Spinner spinner = (Spinner)findViewById( R.id.names ); spinner.setAdapter( adapter ); spinner.setOnItemSelectedListener( this ); + if ( !TextUtils.isEmpty( dflt ) ) { + for ( int ii = 0; ii < knowns.length; ++ii ) { + if ( knowns[ii].equals( dflt ) ) { + spinner.setSelection( ii ); + break; + } + } + } EditText et = (EditText)findViewById( R.id.name_edit ); et.setText( gameName ); diff --git a/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml b/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml index 51313d412..87ecd898a 100644 --- a/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml +++ b/xwords4/android/app/src/main/res/layout/new_game_with_knowns.xml @@ -10,7 +10,7 @@ Unable to change name from “%1$s” to “%2$s”. Is “%2$s” already in use? + + Name your game + + Choose your opponent +