Offer to delete finished games

This commit is contained in:
Eric House 2021-02-25 09:03:32 -08:00
parent 9804594237
commit c22526b1f7
8 changed files with 73 additions and 42 deletions

View file

@ -1107,6 +1107,17 @@ public class BoardDelegate extends DelegateBase
showArchiveNA( false ); showArchiveNA( false );
break; break;
case DELETE_ACTION:
if ( 0 < params.length && (Boolean)params[0] ) {
deleteAndClose();
} else {
makeConfirmThenBuilder( R.string.confirm_delete,
Action.DELETE_ACTION )
.setParams(true)
.show();
}
break;
case LAUNCH_INVITE_ACTION: case LAUNCH_INVITE_ACTION:
for ( Object obj : params ) { for ( Object obj : params ) {
if ( obj instanceof CommsAddrRec ) { if ( obj instanceof CommsAddrRec ) {

View file

@ -83,6 +83,7 @@ public class DlgDelegate {
ARCHIVE_SEL_ACTION, // archive was clicked ARCHIVE_SEL_ACTION, // archive was clicked
ARCHIVE_ACTION, ARCHIVE_ACTION,
REMATCH_ACTION, REMATCH_ACTION,
DELETE_ACTION,
// Dict Browser // Dict Browser
FINISH_ACTION, FINISH_ACTION,

View file

@ -95,8 +95,6 @@ public class EnableSMSAlert extends DlgDelegateAlert {
private void checkEnableButton( AlertDialog dialog ) private void checkEnableButton( AlertDialog dialog )
{ {
boolean enabled = 0 < mSpinner.getSelectedItemPosition(); boolean enabled = 0 < mSpinner.getSelectedItemPosition();
((AlertDialog)dialog) Utils.enableAlertButton( dialog, AlertDialog.BUTTON_POSITIVE, enabled );
.getButton( AlertDialog.BUTTON_POSITIVE )
.setEnabled( enabled );
} }
} }

View file

@ -37,7 +37,7 @@ import org.eehouse.android.xw4.jni.GameSummary;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
public class GameOverAlert extends XWDialogFragment public class GameOverAlert extends XWDialogFragment
implements DialogInterface.OnClickListener implements DialogInterface.OnClickListener, CompoundButton.OnCheckedChangeListener
{ {
private static final String TAG = GameOverAlert.class.getSimpleName(); private static final String TAG = GameOverAlert.class.getSimpleName();
private static final String SUMMARY = "SUMMARY"; private static final String SUMMARY = "SUMMARY";
@ -45,14 +45,13 @@ public class GameOverAlert extends XWDialogFragment
private static final String MSG = "MSG"; private static final String MSG = "MSG";
private static final String IN_ARCH = "IN_ARCH"; private static final String IN_ARCH = "IN_ARCH";
private AlertDialog m_dialog; private AlertDialog mDialog;
private GameSummary mSummary; private GameSummary mSummary;
private int mTitleID; private int mTitleID;
private String mMsg; private String mMsg;
private ViewGroup m_view; private ViewGroup mView;
private boolean mInArchive; private boolean mInArchive;
private CheckBox mArchiveBox; private CheckBox mArchiveBox;
// private boolean mArchiveChecked;
public static GameOverAlert newInstance( GameSummary summary, public static GameOverAlert newInstance( GameSummary summary,
int titleID, String msg, int titleID, String msg,
@ -95,43 +94,53 @@ public class GameOverAlert extends XWDialogFragment
mInArchive = sis.getBoolean( IN_ARCH ); mInArchive = sis.getBoolean( IN_ARCH );
Activity activity = getActivity(); Activity activity = getActivity();
m_view = (ViewGroup)LocUtils.inflate( activity, R.layout.game_over ); mView = (ViewGroup)LocUtils.inflate( activity, R.layout.game_over );
initView(); initView();
AlertDialog.Builder ab = LocUtils.makeAlertBuilder( activity ) AlertDialog.Builder ab = LocUtils.makeAlertBuilder( activity )
.setTitle( mTitleID ) .setTitle( mTitleID )
.setView( m_view ) .setView( mView )
.setPositiveButton( android.R.string.ok, this ) .setPositiveButton( android.R.string.ok, this )
.setNeutralButton( R.string.button_rematch, this ) .setNeutralButton( R.string.button_rematch, this )
.setNegativeButton( R.string.button_delete, this )
; ;
m_dialog = ab.create(); mDialog = ab.create();
Log.d( TAG, "onCreateDialog() => %s", m_dialog ); mDialog.setOnShowListener( new DialogInterface.OnShowListener() {
return m_dialog; @Override
public void onShow( DialogInterface dialog ) {
boolean nowChecked = mArchiveBox.isChecked();
onCheckedChanged( null, nowChecked );
}
});
Log.d( TAG, "onCreateDialog() => %s", mDialog );
return mDialog;
} }
@Override @Override
protected String getFragTag() { return TAG; } protected String getFragTag() { return TAG; }
// @Override
// public void onCheckedChanged( CompoundButton buttonView, boolean isChecked )
// {
// Log.d( TAG, "onCheckedChanged(%b)", isChecked );
// mArchiveChecked = isChecked;
// }
@Override @Override
public void onClick( DialogInterface dialog, int which ) public void onClick( DialogInterface dialog, int which )
{ {
Action action = null; Action action = null;
boolean archiveAfter = boolean archiveAfter =
((CheckBox)m_view.findViewById(R.id.archive_check)) ((CheckBox)mView.findViewById(R.id.archive_check))
.isChecked(); .isChecked();
if ( which == AlertDialog.BUTTON_NEUTRAL ) { switch ( which ) {
case AlertDialog.BUTTON_NEUTRAL:
action = Action.REMATCH_ACTION; action = Action.REMATCH_ACTION;
} else if ( which == AlertDialog.BUTTON_POSITIVE && archiveAfter ) { break;
case AlertDialog.BUTTON_POSITIVE:
if ( archiveAfter ) {
action = Action.ARCHIVE_SEL_ACTION; action = Action.ARCHIVE_SEL_ACTION;
} }
break;
case AlertDialog.BUTTON_NEGATIVE:
action = Action.DELETE_ACTION;
break;
}
if ( null != action ) { if ( null != action ) {
Activity activity = getActivity(); Activity activity = getActivity();
@ -143,16 +152,18 @@ public class GameOverAlert extends XWDialogFragment
} }
} }
// private void trySend( Action action, boolean bool ) @Override
// { public void onCheckedChanged( CompoundButton bv, boolean isChecked )
// Log.d( TAG, "trySend(%s)", action ); {
// } Utils.enableAlertButton( mDialog, AlertDialog.BUTTON_NEGATIVE, !isChecked );
}
private void initView() private void initView()
{ {
((TextView)m_view.findViewById( R.id.msg )).setText( mMsg ); ((TextView)mView.findViewById( R.id.msg )).setText( mMsg );
mArchiveBox = (CheckBox)m_view.findViewById( R.id.archive_check ); mArchiveBox = (CheckBox)mView.findViewById( R.id.archive_check );
mArchiveBox.setOnCheckedChangeListener( this );
if ( mInArchive ) { if ( mInArchive ) {
mArchiveBox.setVisibility( View.GONE ); mArchiveBox.setVisibility( View.GONE );
} }

View file

@ -987,9 +987,8 @@ public class GamesListDelegate extends ListDelegateBase
private void enableMoveGroupButton( DialogInterface dlgi ) private void enableMoveGroupButton( DialogInterface dlgi )
{ {
((AlertDialog)dlgi) Utils.enableAlertButton( (AlertDialog)dlgi, AlertDialog.BUTTON_POSITIVE,
.getButton( AlertDialog.BUTTON_POSITIVE ) 0 <= m_mySIS.groupSelItem );
.setEnabled( 0 <= m_mySIS.groupSelItem );
} }
@Override @Override

View file

@ -23,7 +23,6 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.widget.Button;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -44,8 +43,8 @@ public class InviteChoicesAlert extends DlgDelegateAlert
private static WeakReference<InviteChoicesAlert> sSelf; private static WeakReference<InviteChoicesAlert> sSelf;
private Button mPosButton;
private InviteView mInviteView; private InviteView mInviteView;
private AlertDialog mDialog;
public static InviteChoicesAlert newInstance( DlgState state ) public static InviteChoicesAlert newInstance( DlgState state )
{ {
@ -182,17 +181,15 @@ public class InviteChoicesAlert extends DlgDelegateAlert
@Override @Override
AlertDialog create( AlertDialog.Builder builder ) AlertDialog create( AlertDialog.Builder builder )
{ {
AlertDialog dialog = super.create( builder ); mDialog = super.create( builder );
dialog.setOnShowListener(new DialogInterface.OnShowListener() { mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override @Override
public void onShow( DialogInterface diface ) { public void onShow( DialogInterface diface ) {
mPosButton = ((AlertDialog)diface)
.getButton( AlertDialog.BUTTON_POSITIVE );
enableOkButton(); enableOkButton();
} }
}); });
return dialog; return mDialog;
} }
@Override @Override
@ -251,8 +248,7 @@ public class InviteChoicesAlert extends DlgDelegateAlert
private void enableOkButton() private void enableOkButton()
{ {
if ( null != mPosButton ) { boolean enable = null != mInviteView.getChoice();
mPosButton.setEnabled( null != mInviteView.getChoice() ); Utils.enableAlertButton( mDialog, AlertDialog.BUTTON_POSITIVE, enable );
}
} }
} }

View file

@ -21,6 +21,7 @@
package org.eehouse.android.xw4; package org.eehouse.android.xw4;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -48,6 +49,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -684,6 +686,15 @@ public class Utils {
return result; return result;
} }
static void enableAlertButton( AlertDialog dlg, int which, boolean enable )
{
Button button = dlg.getButton(which);
if ( null != button ) {
button.setEnabled( enable );
}
}
// But see hexArray above // But see hexArray above
private static final String HEX_CHARS = "0123456789ABCDEF"; private static final String HEX_CHARS = "0123456789ABCDEF";
private static char[] HEX_CHARS_ARRAY = HEX_CHARS.toCharArray(); private static char[] HEX_CHARS_ARRAY = HEX_CHARS.toCharArray();

View file

@ -1997,6 +1997,10 @@
<string name="button_archive">Archive\u200C</string> <string name="button_archive">Archive\u200C</string>
<string name="checkbox_archive">Move to Archive</string> <string name="checkbox_archive">Move to Archive</string>
<string name="group_name_archive">Archive</string> <string name="group_name_archive">Archive</string>
<!-- When you choose "delete" from the game-over dialog, you see
this string in a comfirmation dialog -->
<string name="confirm_delete">Are you sure you want to delete the
current game? \n\n(This action cannot be undone.)</string>
<string name="duplicate_group_name_fmt">The group “%1$s” already exists.</string> <string name="duplicate_group_name_fmt">The group “%1$s” already exists.</string>
<string name="button_reconnect">Reconnect</string> <string name="button_reconnect">Reconnect</string>
<string name="square_tiles">Square rack tiles</string> <string name="square_tiles">Square rack tiles</string>