diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java index 6a9ebc811..f96c0f89e 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DelegateBase.java @@ -525,7 +525,7 @@ public class DelegateBase implements DlgClickNotify, } } - protected Dialog buildNamerDlg( GameNamer namer, int titleID, + protected Dialog buildNamerDlg( Renamer namer, int titleID, OnClickListener lstnr1, OnClickListener lstnr2, DlgID dlgID ) { 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 358fcf96f..454c92516 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 @@ -730,8 +730,8 @@ public class GamesListDelegate extends ListDelegateBase GameSummary summary = GameUtils.getSummary( m_activity, rowid ); int labelID = (summary.isMultiGame() && !summary.anyMissing()) ? R.string.rename_label_caveat : R.string.rename_label; - final GameNamer namer = - buildNamer(GameUtils.getName( m_activity, rowid ), labelID ); + final Renamer namer = + buildRenamer( GameUtils.getName( m_activity, rowid ), labelID ); lstnr = new OnClickListener() { public void onClick( DialogInterface dlg, int item ) { String name = namer.getName(); @@ -747,8 +747,8 @@ public class GamesListDelegate extends ListDelegateBase case RENAME_GROUP: { final long groupID = (Long)params[0]; - final GameNamer namer = buildNamer( m_adapter.groupName(groupID), - R.string.rename_group_label ); + final Renamer namer = buildRenamer( m_adapter.groupName(groupID), + R.string.rename_group_label ); lstnr = new OnClickListener() { public void onClick( DialogInterface dlg, int item ) { GamesListDelegate self = curThis(); @@ -766,7 +766,7 @@ public class GamesListDelegate extends ListDelegateBase break; case NEW_GROUP: { - final GameNamer namer = buildNamer( "", R.string.newgroup_label ); + final Renamer namer = buildRenamer( "", R.string.newgroup_label ); lstnr = new OnClickListener() { public void onClick( DialogInterface dlg, int item ) { String name = namer.getName(); @@ -2663,12 +2663,13 @@ public class GamesListDelegate extends ListDelegateBase } } - private GameNamer buildNamer( String name, int labelID ) + private Renamer buildRenamer( String name, int labelID ) { - GameNamer namer = (GameNamer)inflate( R.layout.rename_game ); - namer.setName( name ); - namer.setLabel( labelID ); - return namer; + Renamer renamer = ((Renamer)inflate( R.layout.renamer )) + .setName( name ) + .setLabel( labelID ) + ; + return renamer; } private void showNewGroupIf() diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java index 060d538e1..3d1f755e3 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java @@ -87,9 +87,10 @@ public class KnownPlayersDelegate extends DelegateBase { switch ( dlgID ) { case RENAME_PLAYER: final String oldName = (String)params[0]; - final GameNamer namer = (GameNamer)inflate( R.layout.rename_game ); - namer.setName( oldName ); - namer.setLabel( "some label" ); + final Renamer namer = ((Renamer)inflate( R.layout.renamer )) + .setName( oldName ) + .setLabel( "some label" ) + ; OnClickListener lstnr = new OnClickListener() { @Override @@ -135,6 +136,12 @@ public class KnownPlayersDelegate extends DelegateBase { tv.setText( name ); } + private String getName( ViewGroup item ) + { + TextView tv = (TextView)item.findViewById( R.id.player_name ); + return tv.getText().toString(); + } + private void renameInPlace( String oldName, String newName ) { ViewGroup child = mChildren.remove( oldName ); @@ -142,7 +149,7 @@ public class KnownPlayersDelegate extends DelegateBase { mChildren.put( newName, child ); } - private ViewGroup makePlayerElem( final String player ) + private ViewGroup makePlayerElem( String player ) { ViewGroup view = null; CommsAddrRec addr = XwJNI.kplr_getAddr( player ); @@ -173,14 +180,14 @@ public class KnownPlayersDelegate extends DelegateBase { .setOnClickListener( new View.OnClickListener() { @Override public void onClick( View view ) { - showDialogFragment( DlgID.RENAME_PLAYER, player ); + showDialogFragment( DlgID.RENAME_PLAYER, getName(item) ); } } ); item.findViewById( R.id.player_delete ) .setOnClickListener( new View.OnClickListener() { @Override public void onClick( View view ) { - confirmAndDelete( player ); + confirmAndDelete( getName(item) ); } } ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameNamer.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Renamer.java similarity index 85% rename from xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameNamer.java rename to xwords4/android/app/src/main/java/org/eehouse/android/xw4/Renamer.java index cd1c46cf0..6122caf16 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameNamer.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Renamer.java @@ -29,29 +29,32 @@ import android.widget.TextView; import org.eehouse.android.xw4.loc.LocUtils; -public class GameNamer extends LinearLayout { +public class Renamer extends LinearLayout { private Context m_context; - public GameNamer( Context cx, AttributeSet as ) { + public Renamer( Context cx, AttributeSet as ) { super( cx, as ); m_context = cx; } - public void setLabel( String label ) + public Renamer setLabel( String label ) { TextView view = (TextView)findViewById( R.id.name_label ); view.setText( label ); + return this; } - public void setLabel( int id ) + public Renamer setLabel( int id ) { setLabel( LocUtils.getString( getContext(), id ) ); + return this; } - public void setName( String text ) + public Renamer setName( String text ) { getEdit().setText( text ); + return this; } public String getName() diff --git a/xwords4/android/app/src/main/res/layout/rename_game.xml b/xwords4/android/app/src/main/res/layout/renamer.xml similarity index 93% rename from xwords4/android/app/src/main/res/layout/rename_game.xml rename to xwords4/android/app/src/main/res/layout/renamer.xml index bdfef4248..66b4e53de 100644 --- a/xwords4/android/app/src/main/res/layout/rename_game.xml +++ b/xwords4/android/app/src/main/res/layout/renamer.xml @@ -1,6 +1,6 @@ - - +