split DlgDelegate interface in three

replace dlgButtonClicked() with separate methods for positive and
negative buttons and alert dismissal. I was making too many mistakes
because the old method was getting called twice (e.g. for negative and
then dismissal) and I hadn't needed to differentiate until adding that
new Action. There should be no behavior change with this, but it's
pervasive and replaces some spaghetti.
This commit is contained in:
Eric House 2017-01-06 07:07:17 -08:00
parent dc7ed9bfb2
commit 86e7142687
15 changed files with 473 additions and 475 deletions

View file

@ -168,16 +168,14 @@ public class BTInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
switch( action ) { switch( action ) {
case OPEN_BT_PREFS_ACTION: case OPEN_BT_PREFS_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == which ) { BTService.openBTSettings( m_activity );
BTService.openBTSettings( m_activity );
}
break; break;
default: default:
super.dlgButtonClicked( action, which, params ); super.onPosButton( action, params );
} }
} }
} }

View file

@ -909,7 +909,7 @@ public class BoardDelegate extends DelegateBase
Action.COMMIT_ACTION ) Action.COMMIT_ACTION )
.show(); .show();
} else { } else {
dlgButtonClicked( Action.COMMIT_ACTION, AlertDialog.BUTTON_POSITIVE, null ); onPosButton( Action.COMMIT_ACTION, null );
} }
break; break;
@ -1026,128 +1026,133 @@ public class BoardDelegate extends DelegateBase
////////////////////////////////////////////////// //////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override
public void dlgButtonClicked( Action action, int which,
final Object[] params )
{
boolean handled = false;
boolean positive = AlertDialog.BUTTON_POSITIVE == which;
DbgUtils.logd( TAG, "BoardDelegate.dlgButtonClicked(%s, %b)",
action.toString(), positive );
if ( Action.ENABLE_RELAY_DO_OR == action ) { @Override
handled = true; public void onPosButton( Action action, final Object[] params )
if ( positive ) { {
RelayService.setEnabled( m_activity, true ); JNICmd cmd = JNICmd.CMD_NONE;
} else if ( AlertDialog.BUTTON_NEGATIVE == which ) { switch ( action ) {
m_dropOnDismiss = true; case ENABLE_RELAY_DO_OR:
} else if ( DlgDelegate.DISMISS_BUTTON == which && m_dropOnDismiss ) { RelayService.setEnabled( m_activity, true );
break;
case RETRY_PHONE_STATE_ACTION:
Action stateAction = (Action)params[0];
DBUtils.SentInvitesInfo info = (DBUtils.SentInvitesInfo)params[1];
callInviteChoices( stateAction, info, false );
break;
case UNDO_LAST_ACTION:
cmd = JNICmd.CMD_UNDO_LAST;
break;
case SYNC_ACTION:
doSyncMenuitem();
break;
case SMS_CONFIG_ACTION:
Utils.launchSettings( m_activity );
break;
case COMMIT_ACTION:
cmd = JNICmd.CMD_COMMIT;
break;
case SHOW_EXPL_ACTION:
showToast( m_toastStr );
m_toastStr = null;
break;
case BUTTON_BROWSEALL_ACTION:
case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() );
View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT );
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
DictsDelegate.handleDictsPopup( getDelegator(), button,
curDict, m_gi.dictLang ) ){
break;
}
DictBrowseDelegate.launch( getDelegator(), curDict );
break;
case PREV_HINT_ACTION:
cmd = JNICmd.CMD_PREV_HINT;
break;
case NEXT_HINT_ACTION:
cmd = JNICmd.CMD_NEXT_HINT;
break;
case JUGGLE_ACTION:
cmd = JNICmd.CMD_JUGGLE;
break;
case FLIP_ACTION:
cmd = JNICmd.CMD_FLIP;
break;
case UNDO_ACTION:
cmd = JNICmd.CMD_UNDO_CUR;
break;
case VALUES_ACTION:
cmd = JNICmd.CMD_VALUES;
break;
case CHAT_ACTION:
startChatActivity();
break;
case START_TRADE_ACTION:
showToast( R.string.entering_trade );
cmd = JNICmd.CMD_TRADE;
break;
case LOOKUP_ACTION:
launchLookup( m_words, m_gi.dictLang );
break;
case NFC_TO_SELF:
GamesListDelegate.sendNFCToSelf( m_activity, makeNFCMessage() );
break;
case DROP_RELAY_ACTION:
dropConViaAndRestart(CommsConnType.COMMS_CONN_RELAY);
break;
case DROP_SMS_ACTION:
dropConViaAndRestart(CommsConnType.COMMS_CONN_SMS);
break;
case DELETE_AND_EXIT:
deleteAndClose();
break;
case ENABLE_SMS_DO:
post( new Runnable() {
public void run() {
retrySMSInvites( params );
}
} );
// FALLTHRU: so super gets called, before
default:
super.onPosButton( action, params );
}
if ( JNICmd.CMD_NONE != cmd ) {
handleViaThread( cmd );
}
}
@Override
public void onNegButton( Action action, Object[] params )
{
switch ( action ) {
case ENABLE_RELAY_DO_OR:
m_dropOnDismiss = true;
break;
default:
super.onNegButton( action, params );
}
}
@Override
public void onDismissed( Action action, Object[] params )
{
switch ( action ) {
case ENABLE_RELAY_DO_OR:
if ( m_dropOnDismiss ) {
postDelayed( new Runnable() { postDelayed( new Runnable() {
public void run() { public void run() {
askDropRelay(); askDropRelay();
} }
}, 10 ); }, 10 );
} }
} else if ( Action.RETRY_PHONE_STATE_ACTION == action ) { break;
Action stateAction = (Action)params[0];
DBUtils.SentInvitesInfo info = (DBUtils.SentInvitesInfo)params[1];
callInviteChoices( stateAction, info, false );
} else if ( positive ) {
handled = true;
JNICmd cmd = JNICmd.CMD_NONE;
switch ( action ) {
case UNDO_LAST_ACTION:
cmd = JNICmd.CMD_UNDO_LAST;
break;
case SYNC_ACTION:
doSyncMenuitem();
break;
case SMS_CONFIG_ACTION:
Utils.launchSettings( m_activity );
break;
case COMMIT_ACTION:
cmd = JNICmd.CMD_COMMIT;
break;
case SHOW_EXPL_ACTION:
showToast( m_toastStr );
m_toastStr = null;
break;
case BUTTON_BROWSEALL_ACTION:
case BUTTON_BROWSE_ACTION:
String curDict = m_gi.dictName( m_view.getCurPlayer() );
View button = m_toolbar.getButtonFor( Buttons.BUTTON_BROWSE_DICT );
if ( Action.BUTTON_BROWSEALL_ACTION == action &&
DictsDelegate.handleDictsPopup( getDelegator(), button,
curDict, m_gi.dictLang ) ){
break;
}
DictBrowseDelegate.launch( getDelegator(), curDict );
break;
case PREV_HINT_ACTION:
cmd = JNICmd.CMD_PREV_HINT;
break;
case NEXT_HINT_ACTION:
cmd = JNICmd.CMD_NEXT_HINT;
break;
case JUGGLE_ACTION:
cmd = JNICmd.CMD_JUGGLE;
break;
case FLIP_ACTION:
cmd = JNICmd.CMD_FLIP;
break;
case UNDO_ACTION:
cmd = JNICmd.CMD_UNDO_CUR;
break;
case VALUES_ACTION:
cmd = JNICmd.CMD_VALUES;
break;
case CHAT_ACTION:
startChatActivity();
break;
case START_TRADE_ACTION:
showToast( R.string.entering_trade );
cmd = JNICmd.CMD_TRADE;
break;
case LOOKUP_ACTION:
launchLookup( m_words, m_gi.dictLang );
break;
case NFC_TO_SELF:
GamesListDelegate.sendNFCToSelf( m_activity, makeNFCMessage() );
break;
case DROP_RELAY_ACTION:
dropConViaAndRestart(CommsConnType.COMMS_CONN_RELAY);
break;
case DROP_SMS_ACTION:
dropConViaAndRestart(CommsConnType.COMMS_CONN_SMS);
break;
case DELETE_AND_EXIT:
deleteAndClose();
break;
case ENABLE_SMS_DO:
handled = false; // so super gets called, before
// retrySMSInvites
post( new Runnable() {
public void run() {
retrySMSInvites( params );
}
} );
break;
default:
handled = false;
}
if ( JNICmd.CMD_NONE != cmd ) {
handleViaThread( cmd );
}
} }
}
if ( !handled ) {
super.dlgButtonClicked( action, which, params );
}
} // dlgButtonClicked
public void inviteChoiceMade( Action action, InviteMeans means, public void inviteChoiceMade( Action action, InviteMeans means,
Object[] params ) Object[] params )
@ -1628,8 +1633,7 @@ public class BoardDelegate extends DelegateBase
DbgUtils.logi( TAG, "handleConndMessage(): toastStr: %s", toastStr ); DbgUtils.logi( TAG, "handleConndMessage(): toastStr: %s", toastStr );
m_toastStr = toastStr; m_toastStr = toastStr;
if ( naMsg == 0 ) { if ( naMsg == 0 ) {
dlgButtonClicked( Action.SHOW_EXPL_ACTION, onPosButton( Action.SHOW_EXPL_ACTION, null );
AlertDialog.BUTTON_POSITIVE, null );
} else { } else {
makeNotAgainBuilder( naMsg, naKey, Action.SHOW_EXPL_ACTION ) makeNotAgainBuilder( naMsg, naKey, Action.SHOW_EXPL_ACTION )
.show(); .show();

View file

@ -226,19 +226,17 @@ public class ChatDelegate extends DelegateBase {
} }
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
switch ( action ) { switch ( action ) {
case CLEAR_ACTION: case CLEAR_ACTION:
if ( AlertDialog.BUTTON_POSITIVE == which ) { DBUtils.clearChatHistory( m_activity, m_rowid );
DBUtils.clearChatHistory( m_activity, m_rowid ); TableLayout layout =
TableLayout layout = (TableLayout)findViewById( R.id.chat_history );
(TableLayout)findViewById( R.id.chat_history ); layout.removeAllViews();
layout.removeAllViews();
}
break; break;
default: default:
super.dlgButtonClicked( action, which, params ); super.onPosButton( action, params );
} }
} }

View file

@ -636,59 +636,53 @@ public class DelegateBase implements DlgClickNotify,
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
public void dlgButtonClicked( Action action, int button, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
boolean handled = false; DbgUtils.logd( TAG, "%s.posButtonClicked(%s)", getClass().getSimpleName(),
if ( Action.PERMS_QUERY == action ) { action.toString() );
Perms23.onGotPermsAction( button, params ); switch( action ) {
handled = true; case ENABLE_SMS_ASK:
} else if ( AlertDialog.BUTTON_POSITIVE == button ) { showSMSEnableDialog( Action.ENABLE_SMS_DO, params );
switch( action ) { break;
case ENABLE_SMS_ASK: case ENABLE_SMS_DO:
showSMSEnableDialog( Action.ENABLE_SMS_DO, params ); XWPrefs.setSMSEnabled( m_activity, true );
handled = true; break;
break; case ENABLE_BT_DO:
case ENABLE_SMS_DO: BTService.enable();
XWPrefs.setSMSEnabled( m_activity, true ); break;
break; case ENABLE_RELAY_DO:
case ENABLE_BT_DO: RelayService.setEnabled( m_activity, true );
BTService.enable(); break;
break; case PERMS_QUERY:
case ENABLE_RELAY_DO: Perms23.onGotPermsAction( true, params );
RelayService.setEnabled( m_activity, true ); break;
handled = true; default:
break; DbgUtils.logd( TAG, "unhandled action %s", action.toString() );
default: Assert.fail();
DbgUtils.logd( TAG, "unhandled action %s", action.toString() ); break;
Assert.fail();
break;
}
} }
}
if ( !handled && BuildConfig.DEBUG ) { public void onNegButton( Action action, Object[] params )
String buttonName = null; {
switch( button ) { // DbgUtils.logd( TAG, "%s.negButtonClicked(%s)", getClass().getSimpleName(),
case AlertDialog.BUTTON_POSITIVE: // action.toString() );
buttonName = "positive"; switch ( action ) {
break; case PERMS_QUERY:
case AlertDialog.BUTTON_NEGATIVE: Perms23.onGotPermsAction( false, params );
buttonName = "negative"; break;
break; default:
case AlertDialog.BUTTON_NEUTRAL: DbgUtils.logd( TAG, "onNegButton: unhandled action %s", action.toString() );
buttonName = "neutral"; break;
break;
case DlgDelegate.DISMISS_BUTTON:
buttonName = "dismiss";
break;
default:
Assert.fail();
break;
}
DbgUtils.logi( TAG, "dlgButtonClicked(action=%s button=%s): UNHANDLED",
action.toString(), buttonName );
} }
} }
public void onDismissed( Action action, Object[] params )
{
DbgUtils.logd( TAG, "%s.dlgDismissed(%s)", getClass().getSimpleName(),
action.toString() );
}
public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object[] params ) public void inviteChoiceMade( Action action, DlgClickNotify.InviteMeans means, Object[] params )
{ {
Assert.fail(); Assert.fail();

View file

@ -300,9 +300,9 @@ public class DictBrowseDelegate extends DelegateBase
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
Assert.assertTrue( Action.FINISH_ACTION == action ); Assert.assertTrue( !BuildConfig.DEBUG || Action.FINISH_ACTION==action );
finish(); finish();
} }

View file

@ -901,50 +901,41 @@ public class DictsDelegate extends ListDelegateBase
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
public void dlgButtonClicked( Action action, int which, Object[] params ) @Override
public void onPosButton( Action action, Object[] params )
{ {
DbgUtils.logd( TAG, "dlgButtonClicked(%s)", action.toString() );
boolean positive = DialogInterface.BUTTON_POSITIVE == which;
switch( action ) { switch( action ) {
case DELETE_DICT_ACTION: case DELETE_DICT_ACTION:
if ( positive ) { XWListItem[] items = (XWListItem[])params[0];
XWListItem[] items = (XWListItem[])params[0]; for ( XWListItem item : items ) {
for ( XWListItem item : items ) { String name = item.getText();
String name = item.getText(); DictLoc loc = (DictLoc)item.getCached();
DictLoc loc = (DictLoc)item.getCached(); deleteDict( name, loc );
deleteDict( name, loc );
}
clearSelections();
mkListAdapter();
} }
clearSelections();
mkListAdapter();
break; break;
case UPDATE_DICTS_ACTION: case UPDATE_DICTS_ACTION:
if ( positive ) { Uri[] uris = new Uri[m_needUpdates.size()];
Uri[] uris = new Uri[m_needUpdates.size()]; String[] names = new String[uris.length];
String[] names = new String[uris.length]; int count = 0;
int count = 0; for ( Iterator<String> iter = m_needUpdates.keySet().iterator();
for ( Iterator<String> iter = m_needUpdates.keySet().iterator(); iter.hasNext(); ) {
iter.hasNext(); ) { String name = iter.next();
String name = iter.next(); names[count] = name;
names[count] = name; uris[count] = m_needUpdates.get( name );
uris[count] = m_needUpdates.get( name ); ++count;
++count;
}
DwnldDelegate.downloadDictsInBack( m_activity, uris, names, this );
} }
DwnldDelegate.downloadDictsInBack( m_activity, uris, names, this );
break; break;
case MOVE_CONFIRMED: case MOVE_CONFIRMED:
if ( positive ) { moveDictsWithPermission( params );
moveDictsWithPermission( params );
}
break; break;
case STORAGE_CONFIRMED: case STORAGE_CONFIRMED:
if ( positive ) { mkListAdapter();
mkListAdapter();
}
break; break;
default: default:
super.dlgButtonClicked( action, which, params ); super.onPosButton( action, params );
} }
} }

View file

@ -308,7 +308,10 @@ public class DlgDelegate {
public static enum InviteMeans { public static enum InviteMeans {
SMS, EMAIL, NFC, BLUETOOTH, CLIPBOARD, RELAY, WIFIDIRECT, SMS, EMAIL, NFC, BLUETOOTH, CLIPBOARD, RELAY, WIFIDIRECT,
}; };
void dlgButtonClicked( Action action, int button, Object[] params ); void onPosButton( Action action, Object[] params );
void onNegButton( Action action, Object[] params );
void onDismissed( Action action, Object[] params );
void inviteChoiceMade( Action action, InviteMeans means, Object[] params ); void inviteChoiceMade( Action action, InviteMeans means, Object[] params );
} }
public interface HasDlgDelegate { public interface HasDlgDelegate {
@ -446,7 +449,7 @@ public class DlgDelegate {
} }
// Puts up alert asking to choose a reason to enable SMS, and on dismiss // Puts up alert asking to choose a reason to enable SMS, and on dismiss
// calls dlgButtonClicked with the action and in params a Boolean // calls onPosButton/onNegButton with the action and in params a Boolean
// indicating whether enabling is now ok. // indicating whether enabling is now ok.
public void showSMSEnableDialog( Action action, Object... params ) public void showSMSEnableDialog( Action action, Object... params )
{ {
@ -468,9 +471,7 @@ public class DlgDelegate {
post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
m_clickCallback m_clickCallback
.dlgButtonClicked( action, .onPosButton( action, params );
AlertDialog.BUTTON_POSITIVE,
params );
} }
}); });
} }
@ -702,10 +703,7 @@ public class DlgDelegate {
OnClickListener lstnr = new OnClickListener() { OnClickListener lstnr = new OnClickListener() {
public void onClick( DialogInterface dlg, int item ) { public void onClick( DialogInterface dlg, int item ) {
checkNotAgainCheck( state, naView ); checkNotAgainCheck( state, naView );
m_clickCallback. m_clickCallback.onPosButton( more.action, more.params );
dlgButtonClicked( more.action,
AlertDialog.BUTTON_POSITIVE,
more.params );
} }
}; };
builder.setNegativeButton( more.buttonStr, lstnr ); builder.setNegativeButton( more.buttonStr, lstnr );
@ -866,9 +864,7 @@ public class DlgDelegate {
layout.findViewById( R.id.confirm_sms_reasons ); layout.findViewById( R.id.confirm_sms_reasons );
boolean enabled = 0 < reasons.getSelectedItemPosition(); boolean enabled = 0 < reasons.getSelectedItemPosition();
Assert.assertTrue( enabled ); Assert.assertTrue( enabled );
m_clickCallback.dlgButtonClicked( state.m_action, m_clickCallback.onPosButton( state.m_action, state.m_params );
AlertDialog.BUTTON_POSITIVE,
state.m_params );
} }
}; };
@ -917,9 +913,21 @@ public class DlgDelegate {
checkNotAgainCheck( state, naView ); checkNotAgainCheck( state, naView );
if ( Action.SKIP_CALLBACK != state.m_action ) { if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.dlgButtonClicked( state.m_action, switch ( button ) {
button, case AlertDialog.BUTTON_POSITIVE:
state.m_params ); m_clickCallback.onPosButton( state.m_action,
state.m_params );
break;
case AlertDialog.BUTTON_NEGATIVE:
m_clickCallback.onNegButton( state.m_action,
state.m_params );
break;
default:
DbgUtils.loge( TAG, "unexpected button %d",
button );
// ignore on release builds
Assert.assertFalse( BuildConfig.DEBUG );
}
} }
} }
}; };
@ -948,9 +956,8 @@ public class DlgDelegate {
public void onDismiss( DialogInterface di ) { public void onDismiss( DialogInterface di ) {
dropState( state ); dropState( state );
if ( Action.SKIP_CALLBACK != state.m_action ) { if ( Action.SKIP_CALLBACK != state.m_action ) {
m_clickCallback.dlgButtonClicked( state.m_action, m_clickCallback.onDismissed( state.m_action,
DISMISS_BUTTON, state.m_params );
state.m_params );
} }
m_activity.removeDialog( id ); m_activity.removeDialog( id );
} }

View file

@ -346,16 +346,26 @@ public class DwnldDelegate extends ListDelegateBase {
} }
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
if ( Action.STORAGE_CONFIRMED == action ) { switch ( action ) {
if ( AlertDialog.BUTTON_POSITIVE == which ) { case STORAGE_CONFIRMED:
doWithPermissions( (Uri[])params[0] ); doWithPermissions( (Uri[])params[0] );
} else if ( AlertDialog.BUTTON_NEGATIVE == which ) { break;
finish(); default:
} super.onPosButton( action, params );
} else { }
super.dlgButtonClicked( action, which, params ); }
@Override
public void onNegButton( Action action, Object[] params )
{
switch ( action ) {
case STORAGE_CONFIRMED:
finish();
break;
default:
super.onPosButton( action, params );
} }
} }

View file

@ -684,48 +684,42 @@ public class GameConfigDelegate extends DelegateBase
} }
@Override @Override
public void dlgButtonClicked( Action action, int button, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
boolean callSuper = false;
Assert.assertTrue( curThis() == this ); Assert.assertTrue( curThis() == this );
switch( action ) {
if ( AlertDialog.BUTTON_POSITIVE == button ) { case LOCKED_CHANGE_ACTION:
switch( action ) { handleLockedChange();
case LOCKED_CHANGE_ACTION: break;
handleLockedChange(); case SMS_CONFIG_ACTION:
break; Utils.launchSettings( m_activity );
case SMS_CONFIG_ACTION: break;
Utils.launchSettings( m_activity ); case DELETE_AND_EXIT:
break; if ( m_isNewGame ) {
case DELETE_AND_EXIT: deleteGame();
if ( m_isNewGame ) {
deleteGame();
}
closeNoSave();
break;
case SET_ENABLE_PUBLIC:
XWPrefs.setPrefsBoolean( m_activity, R.string.key_enable_pubroom,
true );
setupRelayStuffIf( true );
break;
default:
callSuper = true;
} }
} else if ( AlertDialog.BUTTON_NEGATIVE == button ) { closeNoSave();
switch ( action ) { break;
case DELETE_AND_EXIT: case SET_ENABLE_PUBLIC:
showDialog( DlgID.CHANGE_CONN ); XWPrefs.setPrefsBoolean( m_activity, R.string.key_enable_pubroom,
break; true );
default: setupRelayStuffIf( true );
callSuper = true; break;
break; default:
} super.onPosButton( action, params );
} else {
callSuper = true;
} }
}
if ( callSuper ) { @Override
super.dlgButtonClicked( action, button, params ); public void onNegButton( Action action, Object[] params )
{
switch ( action ) {
case DELETE_AND_EXIT:
showDialog( DlgID.CHANGE_CONN );
break;
default:
super.onNegButton( action, params );
break;
} }
} }

View file

@ -1234,116 +1234,125 @@ public class GamesListDelegate extends ListDelegateBase
} }
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
public void dlgButtonClicked( Action action, int which, Object[] params ) @Override
public void onPosButton( Action action, Object[] params )
{ {
if ( AlertDialog.BUTTON_POSITIVE == which ) { switch( action ) {
switch( action ) { case NEW_NET_GAME:
case NEW_NET_GAME: m_netLaunchInfo = (NetLaunchInfo)params[0];
m_netLaunchInfo = (NetLaunchInfo)params[0]; if ( checkWarnNoDict( m_netLaunchInfo ) ) {
if ( checkWarnNoDict( m_netLaunchInfo ) ) { makeNewNetGameIf();
makeNewNetGameIf(); }
} break;
break; case RESET_GAMES:
case RESET_GAMES: long[] rowids = (long[])params[0];
long[] rowids = (long[])params[0]; boolean changed = false;
boolean changed = false; for ( long rowid : rowids ) {
for ( long rowid : rowids ) { changed = GameUtils.resetGame( m_activity, rowid ) || changed;
changed = GameUtils.resetGame( m_activity, rowid ) || changed; }
} if ( changed ) {
if ( changed ) { mkListAdapter(); // required because position may change
mkListAdapter(); // required because position may change }
} break;
break; case SYNC_MENU:
case SYNC_MENU: doSyncMenuitem();
doSyncMenuitem(); break;
break; case NEW_FROM:
case NEW_FROM: long curID = (Long)params[0];
long curID = (Long)params[0]; long newid = GameUtils.dupeGame( m_activity, curID );
long newid = GameUtils.dupeGame( m_activity, curID ); if ( DBUtils.ROWID_NOTFOUND != newid ) {
if ( DBUtils.ROWID_NOTFOUND != newid ) { m_selGames.add( newid );
m_selGames.add( newid ); reloadGame( newid );
reloadGame( newid ); }
} break;
break;
case SET_HIDE_NEWGAME_BUTTONS: case SET_HIDE_NEWGAME_BUTTONS:
XWPrefs.setHideNewgameButtons(m_activity, true); XWPrefs.setHideNewgameButtons(m_activity, true);
setupButtons(); setupButtons();
// FALLTHRU // FALLTHRU
case NEW_GAME_PRESSED: case NEW_GAME_PRESSED:
handleNewGame( m_nextIsSolo ); handleNewGame( m_nextIsSolo );
break; break;
case DELETE_GROUPS: case DELETE_GROUPS:
long[] groupIDs = (long[])params[0]; long[] groupIDs = (long[])params[0];
for ( long groupID : groupIDs ) { for ( long groupID : groupIDs ) {
GameUtils.deleteGroup( m_activity, groupID ); GameUtils.deleteGroup( m_activity, groupID );
} }
clearSelections(); clearSelections();
mkListAdapter(); mkListAdapter();
break; break;
case DELETE_GAMES: case DELETE_GAMES:
deleteGames( (long[])params[0] ); deleteGames( (long[])params[0] );
break; break;
case OPEN_GAME: case OPEN_GAME:
doOpenGame( params ); doOpenGame( params );
break; break;
case ENABLE_DUALPANE: case ENABLE_DUALPANE:
makeOkOnlyBuilder( R.string.dualpane_exit_now) makeOkOnlyBuilder( R.string.dualpane_exit_now)
.setAction( Action.ENABLE_DUALPANE_EXIT ) .setAction( Action.ENABLE_DUALPANE_EXIT )
.show(); .show();
break; break;
case CLEAR_SELS: case CLEAR_SELS:
clearSelections(); clearSelections();
break; break;
case DWNLD_LOC_DICT: case DWNLD_LOC_DICT:
String lang = (String)params[0]; String lang = (String)params[0];
String name = (String)params[1]; String name = (String)params[1];
DownloadFinishedListener lstnr = new DownloadFinishedListener() { DownloadFinishedListener lstnr = new DownloadFinishedListener() {
public void downloadFinished( String lang, String name, boolean success ) public void downloadFinished( String lang, String name, boolean success )
{ {
if ( success ) { if ( success ) {
XWPrefs.setPrefsString( m_activity, XWPrefs.setPrefsString( m_activity,
R.string.key_default_language, R.string.key_default_language,
lang ); lang );
name = DictUtils.removeDictExtn( name ); name = DictUtils.removeDictExtn( name );
int[] ids = { R.string.key_default_dict, int[] ids = { R.string.key_default_dict,
R.string.key_default_robodict }; R.string.key_default_robodict };
for ( int id : ids ) { for ( int id : ids ) {
XWPrefs.setPrefsString( m_activity, id, name ); XWPrefs.setPrefsString( m_activity, id, name );
}
XWPrefs.setPrefsBoolean( m_activity,
R.string.key_got_langdict,
true );
} }
XWPrefs.setPrefsBoolean( m_activity,
R.string.key_got_langdict,
true );
} }
}; }
DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr ); };
break; DwnldDelegate.downloadDictInBack( m_activity, lang, name, lstnr );
case NEW_GAME_DFLT_NAME: break;
m_newGameParams = params; case NEW_GAME_DFLT_NAME:
askDefaultName(); m_newGameParams = params;
break; askDefaultName();
break;
case RETRY_REMATCH: case RETRY_REMATCH:
startRematchWithName( (String)params[0], false ); startRematchWithName( (String)params[0], false );
break; break;
default: default:
Assert.fail(); Assert.fail();
} }
} else if ( AlertDialog.BUTTON_NEGATIVE == which ) { }
if ( Action.NEW_GAME_DFLT_NAME == action ) {
m_newGameParams = params; @Override
makeThenLaunchOrConfigure(); public void onNegButton( Action action, Object[] params )
} {
} else if ( DlgDelegate.DISMISS_BUTTON == which ) { if ( Action.NEW_GAME_DFLT_NAME == action ) {
switch( action ) { m_newGameParams = params;
case ENABLE_DUALPANE_EXIT: makeThenLaunchOrConfigure();
setDualpaneAndFinish( true ); }
break; }
}
@Override
public void onDismissed( Action action, Object[] params )
{
switch( action ) {
case ENABLE_DUALPANE_EXIT:
setDualpaneAndFinish( true );
break;
default:
super.onDismissed( action, params );
} }
} }

View file

@ -178,30 +178,25 @@ public class Perms23 {
} }
builder.asyncQuery( m_delegate.getActivity(), new PermCbck() { builder.asyncQuery( m_delegate.getActivity(), new PermCbck() {
public void onPermissionResult( Map<Perm, Boolean> perms ) { public void onPermissionResult( Map<Perm, Boolean> perms ) {
int button = perms.get( m_perm ) if ( perms.get( m_perm ) ) {
? AlertDialog.BUTTON_POSITIVE m_cbck.onPosButton( m_action, m_params );
: AlertDialog.BUTTON_NEGATIVE; } else {
// DbgUtils.logd( TAG, "doIt() calling dlgButtonClicked(%s)", m_cbck.onNegButton( m_action, m_params );
// m_action.toString() ); }
m_cbck.dlgButtonClicked( m_action, button, m_params );
} }
} ); } );
} }
// Post this in case we're called from inside dialog dismiss // Post this in case we're called from inside dialog dismiss
// code. Better to unwind the stack... // code. Better to unwind the stack...
private void handleButton( final int button ) private void handleButton( final boolean positive )
{ {
m_delegate.post( new Runnable() { m_delegate.post( new Runnable() {
public void run() { public void run() {
if ( AlertDialog.BUTTON_POSITIVE == button ) { if ( positive ) {
doIt( false ); doIt( false );
} else if ( AlertDialog.BUTTON_NEGATIVE == button ) { } else {
// DbgUtils.logd( TAG, "handleButton calling dlgButtonClicked(%s)", m_cbck.onNegButton( m_action, m_params );
// m_action.toString() );
m_cbck.dlgButtonClicked( m_action,
AlertDialog.BUTTON_NEGATIVE,
m_params );
} }
} }
} ); } );
@ -221,11 +216,11 @@ public class Perms23 {
.doIt( true ); .doIt( true );
} }
public static void onGotPermsAction( int button, Object[] params ) public static void onGotPermsAction( boolean positive, Object[] params )
{ {
// DbgUtils.logd( TAG, "onGotPermsAction(button=%d)", button ); // DbgUtils.logd( TAG, "onGotPermsAction(button=%d)", button );
QueryInfo info = (QueryInfo)params[0]; QueryInfo info = (QueryInfo)params[0];
info.handleButton( button ); info.handleButton( positive );
} }
private static Map<Integer, PermCbck> s_map = new HashMap<Integer, PermCbck>(); private static Map<Integer, PermCbck> s_map = new HashMap<Integer, PermCbck>();

View file

@ -242,26 +242,19 @@ public class PrefsDelegate extends DelegateBase
} }
@Override @Override
public void dlgButtonClicked( Action action, int button, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
boolean handled = AlertDialog.BUTTON_POSITIVE == button; switch ( action ) {
if ( handled ) { case ENABLE_SMS_DO:
switch ( action ) { XWPrefs.setSMSEnabled( m_activity, true );
case ENABLE_SMS_DO: SMSCheckBoxPreference.setChecked();
XWPrefs.setSMSEnabled( m_activity, true ); break;
SMSCheckBoxPreference.setChecked(); case DISABLE_RELAY_DO:
break; RelayService.setEnabled( m_activity, false );
case DISABLE_RELAY_DO: RelayCheckBoxPreference.setChecked();
RelayService.setEnabled( m_activity, false ); break;
RelayCheckBoxPreference.setChecked(); default:
break; super.onPosButton( action, params );
default:
handled = false;
}
}
if ( !handled ) {
super.dlgButtonClicked( action, button, params );
} }
} }

View file

@ -278,27 +278,29 @@ public class RelayInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
switch( which ) { switch( action ) {
case AlertDialog.BUTTON_POSITIVE: case CLEAR_ACTION:
switch( action ) { clearSelectedImpl();
case CLEAR_ACTION:
clearSelectedImpl();
break;
case USE_IMMOBILE_ACTION:
m_immobileConfirmed = true;
break;
}
break; break;
case DlgDelegate.DISMISS_BUTTON: case USE_IMMOBILE_ACTION:
if ( Action.USE_IMMOBILE_ACTION == action && m_immobileConfirmed ) { m_immobileConfirmed = true;
makeConfirmThenBuilder( R.string.warn_unlimited,
Action.POST_WARNING_ACTION )
.setPosButton( R.string.button_yes )
.show();
}
break; break;
default:
super.onPosButton( action, params );
break;
}
}
@Override
public void onDismissed( Action action, Object[] params )
{
if ( Action.USE_IMMOBILE_ACTION == action && m_immobileConfirmed ) {
makeConfirmThenBuilder( R.string.warn_unlimited,
Action.POST_WARNING_ACTION )
.setPosButton( R.string.button_yes )
.show();
} }
} }

View file

@ -187,34 +187,37 @@ public class SMSInviteDelegate extends InviteDelegate {
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
@Override @Override
public void dlgButtonClicked( Action action, int which, public void onPosButton( Action action, Object[] params )
final Object[] params )
{ {
boolean isPositive = AlertDialog.BUTTON_POSITIVE == which;
switch ( action ) { switch ( action ) {
case RETRY_CONTACTS_ACTION: case RETRY_CONTACTS_ACTION:
askContactsPermission( false ); askContactsPermission( false );
break; break;
case CLEAR_ACTION: case CLEAR_ACTION:
if ( isPositive) { clearSelectedImpl();
clearSelectedImpl();
}
break;
case POST_WARNING_ACTION:
if ( isPositive ) { // ???
PhoneRec rec = new PhoneRec( (String)params[1],
(String)params[0] );
m_phoneRecs.add( rec );
clearChecked();
onItemChecked( rec, true );
saveAndRebuild();
}
break; break;
case USE_IMMOBILE_ACTION: case USE_IMMOBILE_ACTION:
if ( isPositive ) { m_immobileConfirmed = true;
m_immobileConfirmed = true; break;
} else if ( m_immobileConfirmed ) { case POST_WARNING_ACTION:
PhoneRec rec = new PhoneRec( (String)params[1],
(String)params[0] );
m_phoneRecs.add( rec );
clearChecked();
onItemChecked( rec, true );
saveAndRebuild();
break;
default:
super.onPosButton( action, params );
}
}
@Override
public void onNegButton( Action action, final Object[] params )
{
switch ( action ) {
case USE_IMMOBILE_ACTION:
if ( m_immobileConfirmed ) {
// Putting up a new alert from inside another's handler // Putting up a new alert from inside another's handler
// confuses things. So post instead. // confuses things. So post instead.
post( new Runnable() { post( new Runnable() {
@ -229,6 +232,8 @@ public class SMSInviteDelegate extends InviteDelegate {
} ); } );
} }
break; break;
default:
super.onNegButton( action, params );
} }
} }

View file

@ -153,33 +153,31 @@ public class StudyListDelegate extends ListDelegateBase
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void onPosButton( Action action, Object[] params )
{ {
if ( AlertDialog.BUTTON_POSITIVE == which ) { switch ( action ) {
switch ( action ) { case SL_CLEAR_ACTION:
case SL_CLEAR_ACTION: String[] selWords = getSelWords();
String[] selWords = getSelWords(); if ( selWords.length == m_words.length ) {
if ( selWords.length == m_words.length ) { selWords = null; // all: easier on DB :-)
selWords = null; // all: easier on DB :-)
}
DBUtils.studyListClear( m_activity, m_langCodes[m_langPosition],
selWords );
initOrFinish( null );
break;
case SL_COPY_ACTION:
selWords = getSelWords();
ClipboardManager clipboard = (ClipboardManager)
getSystemService( Context.CLIPBOARD_SERVICE );
clipboard.setText( TextUtils.join( "\n", selWords ) );
String msg = getQuantityString( R.plurals.paste_done_fmt,
selWords.length, selWords.length );
showToast( msg );
break;
default:
Assert.fail();
break;
} }
DBUtils.studyListClear( m_activity, m_langCodes[m_langPosition],
selWords );
initOrFinish( null );
break;
case SL_COPY_ACTION:
selWords = getSelWords();
ClipboardManager clipboard = (ClipboardManager)
getSystemService( Context.CLIPBOARD_SERVICE );
clipboard.setText( TextUtils.join( "\n", selWords ) );
String msg = getQuantityString( R.plurals.paste_done_fmt,
selWords.length, selWords.length );
showToast( msg );
break;
default:
Assert.fail();
break;
} }
} }