From c22526b1f763d8e77c5523c390b46999fed8ca48 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 25 Feb 2021 09:03:32 -0800 Subject: [PATCH] Offer to delete finished games --- .../eehouse/android/xw4/BoardDelegate.java | 11 ++++ .../org/eehouse/android/xw4/DlgDelegate.java | 1 + .../eehouse/android/xw4/EnableSMSAlert.java | 4 +- .../eehouse/android/xw4/GameOverAlert.java | 63 +++++++++++-------- .../android/xw4/GamesListDelegate.java | 5 +- .../android/xw4/InviteChoicesAlert.java | 16 ++--- .../java/org/eehouse/android/xw4/Utils.java | 11 ++++ .../app/src/main/res/values/strings.xml | 4 ++ 8 files changed, 73 insertions(+), 42 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java index 301e9db50..37a3aa413 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/BoardDelegate.java @@ -1107,6 +1107,17 @@ public class BoardDelegate extends DelegateBase showArchiveNA( false ); 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: for ( Object obj : params ) { if ( obj instanceof CommsAddrRec ) { diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java index 55bc82b0e..72d131ef6 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/DlgDelegate.java @@ -83,6 +83,7 @@ public class DlgDelegate { ARCHIVE_SEL_ACTION, // archive was clicked ARCHIVE_ACTION, REMATCH_ACTION, + DELETE_ACTION, // Dict Browser FINISH_ACTION, diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java index 4b1f8b237..bdaf8a5bd 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/EnableSMSAlert.java @@ -95,8 +95,6 @@ public class EnableSMSAlert extends DlgDelegateAlert { private void checkEnableButton( AlertDialog dialog ) { boolean enabled = 0 < mSpinner.getSelectedItemPosition(); - ((AlertDialog)dialog) - .getButton( AlertDialog.BUTTON_POSITIVE ) - .setEnabled( enabled ); + Utils.enableAlertButton( dialog, AlertDialog.BUTTON_POSITIVE, enabled ); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameOverAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameOverAlert.java index 334ecb73c..0b4bec60c 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameOverAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameOverAlert.java @@ -37,7 +37,7 @@ import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.loc.LocUtils; 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 SUMMARY = "SUMMARY"; @@ -45,14 +45,13 @@ public class GameOverAlert extends XWDialogFragment private static final String MSG = "MSG"; private static final String IN_ARCH = "IN_ARCH"; - private AlertDialog m_dialog; + private AlertDialog mDialog; private GameSummary mSummary; private int mTitleID; private String mMsg; - private ViewGroup m_view; + private ViewGroup mView; private boolean mInArchive; private CheckBox mArchiveBox; - // private boolean mArchiveChecked; public static GameOverAlert newInstance( GameSummary summary, int titleID, String msg, @@ -95,42 +94,52 @@ public class GameOverAlert extends XWDialogFragment mInArchive = sis.getBoolean( IN_ARCH ); Activity activity = getActivity(); - m_view = (ViewGroup)LocUtils.inflate( activity, R.layout.game_over ); + mView = (ViewGroup)LocUtils.inflate( activity, R.layout.game_over ); initView(); AlertDialog.Builder ab = LocUtils.makeAlertBuilder( activity ) .setTitle( mTitleID ) - .setView( m_view ) + .setView( mView ) .setPositiveButton( android.R.string.ok, this ) .setNeutralButton( R.string.button_rematch, this ) + .setNegativeButton( R.string.button_delete, this ) ; - m_dialog = ab.create(); - Log.d( TAG, "onCreateDialog() => %s", m_dialog ); - return m_dialog; + mDialog = ab.create(); + mDialog.setOnShowListener( new DialogInterface.OnShowListener() { + @Override + public void onShow( DialogInterface dialog ) { + boolean nowChecked = mArchiveBox.isChecked(); + onCheckedChanged( null, nowChecked ); + } + }); + + Log.d( TAG, "onCreateDialog() => %s", mDialog ); + return mDialog; } @Override protected String getFragTag() { return TAG; } - // @Override - // public void onCheckedChanged( CompoundButton buttonView, boolean isChecked ) - // { - // Log.d( TAG, "onCheckedChanged(%b)", isChecked ); - // mArchiveChecked = isChecked; - // } - @Override public void onClick( DialogInterface dialog, int which ) { Action action = null; boolean archiveAfter = - ((CheckBox)m_view.findViewById(R.id.archive_check)) + ((CheckBox)mView.findViewById(R.id.archive_check)) .isChecked(); - if ( which == AlertDialog.BUTTON_NEUTRAL ) { + switch ( which ) { + case AlertDialog.BUTTON_NEUTRAL: action = Action.REMATCH_ACTION; - } else if ( which == AlertDialog.BUTTON_POSITIVE && archiveAfter ) { - action = Action.ARCHIVE_SEL_ACTION; + break; + case AlertDialog.BUTTON_POSITIVE: + if ( archiveAfter ) { + action = Action.ARCHIVE_SEL_ACTION; + } + break; + case AlertDialog.BUTTON_NEGATIVE: + action = Action.DELETE_ACTION; + break; } if ( null != action ) { @@ -143,16 +152,18 @@ public class GameOverAlert extends XWDialogFragment } } - // private void trySend( Action action, boolean bool ) - // { - // Log.d( TAG, "trySend(%s)", action ); - // } + @Override + public void onCheckedChanged( CompoundButton bv, boolean isChecked ) + { + Utils.enableAlertButton( mDialog, AlertDialog.BUTTON_NEGATIVE, !isChecked ); + } 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 ) { mArchiveBox.setVisibility( View.GONE ); } 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 83ec6388b..dea70d82a 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 @@ -987,9 +987,8 @@ public class GamesListDelegate extends ListDelegateBase private void enableMoveGroupButton( DialogInterface dlgi ) { - ((AlertDialog)dlgi) - .getButton( AlertDialog.BUTTON_POSITIVE ) - .setEnabled( 0 <= m_mySIS.groupSelItem ); + Utils.enableAlertButton( (AlertDialog)dlgi, AlertDialog.BUTTON_POSITIVE, + 0 <= m_mySIS.groupSelItem ); } @Override diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java index ab844d3a1..27c92c61f 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/InviteChoicesAlert.java @@ -23,7 +23,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface; -import android.widget.Button; import android.widget.RadioGroup; import java.lang.ref.WeakReference; @@ -44,8 +43,8 @@ public class InviteChoicesAlert extends DlgDelegateAlert private static WeakReference sSelf; - private Button mPosButton; private InviteView mInviteView; + private AlertDialog mDialog; public static InviteChoicesAlert newInstance( DlgState state ) { @@ -182,17 +181,15 @@ public class InviteChoicesAlert extends DlgDelegateAlert @Override AlertDialog create( AlertDialog.Builder builder ) { - AlertDialog dialog = super.create( builder ); - dialog.setOnShowListener(new DialogInterface.OnShowListener() { + mDialog = super.create( builder ); + mDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow( DialogInterface diface ) { - mPosButton = ((AlertDialog)diface) - .getButton( AlertDialog.BUTTON_POSITIVE ); enableOkButton(); } }); - return dialog; + return mDialog; } @Override @@ -251,8 +248,7 @@ public class InviteChoicesAlert extends DlgDelegateAlert private void enableOkButton() { - if ( null != mPosButton ) { - mPosButton.setEnabled( null != mInviteView.getChoice() ); - } + boolean enable = null != mInviteView.getChoice(); + Utils.enableAlertButton( mDialog, AlertDialog.BUTTON_POSITIVE, enable ); } } diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index f9095e2ac..d07057430 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -21,6 +21,7 @@ package org.eehouse.android.xw4; import android.app.Activity; +import android.app.AlertDialog; import android.app.Dialog; import android.app.Notification; import android.app.NotificationManager; @@ -48,6 +49,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; @@ -684,6 +686,15 @@ public class Utils { 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 private static final String HEX_CHARS = "0123456789ABCDEF"; private static char[] HEX_CHARS_ARRAY = HEX_CHARS.toCharArray(); diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index 660a33dd0..54a630edc 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -1997,6 +1997,10 @@ Archive\u200C Move to Archive Archive + + Are you sure you want to delete the + current game? \n\n(This action cannot be undone.) The group ā€œ%1$sā€ already exists. Reconnect Square rack tiles