do a builder for okonly alerts too

Might be getting carried away with this, but I like having all common
dialogs built the same way.
This commit is contained in:
Eric House 2016-08-15 13:55:11 -07:00
parent 1a56854d41
commit 232f5e1a15
12 changed files with 63 additions and 55 deletions

View file

@ -413,8 +413,9 @@ public class BoardDelegate extends DelegateBase
public void onClick( DialogInterface dialog, public void onClick( DialogInterface dialog,
int item ) { int item ) {
BoardDelegate self = curThis(); BoardDelegate self = curThis();
self.showOKOnlyDialog( self.m_sentInfo String msg = self.m_sentInfo
.getAsText( self.m_activity ) ); .getAsText( self.m_activity );
self.makeOkOnlyBuilder( msg ).show();
} }
}; };
@ -926,7 +927,7 @@ public class BoardDelegate extends DelegateBase
break; break;
case R.id.board_menu_game_invites: case R.id.board_menu_game_invites:
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( m_activity, m_rowid ); SentInvitesInfo sentInfo = DBUtils.getInvitesFor( m_activity, m_rowid );
showOKOnlyDialog( sentInfo.getAsText( m_activity ) ); makeOkOnlyBuilder( sentInfo.getAsText( m_activity ) ).show();
break; break;
case R.id.board_menu_undo_current: case R.id.board_menu_undo_current:
cmd = JNICmd.CMD_UNDO_CUR; cmd = JNICmd.CMD_UNDO_CUR;
@ -1119,7 +1120,7 @@ public class BoardDelegate extends DelegateBase
} else if ( ! NFCUtils.nfcAvail( m_activity )[1] ) { } else if ( ! NFCUtils.nfcAvail( m_activity )[1] ) {
showDialog( DlgID.ENABLE_NFC ); showDialog( DlgID.ENABLE_NFC );
} else { } else {
showOKOnlyDialog( R.string.nfc_just_tap ); makeOkOnlyBuilder( R.string.nfc_just_tap ).show();
} }
break; break;
case BLUETOOTH: case BLUETOOTH:
@ -1211,7 +1212,7 @@ public class BoardDelegate extends DelegateBase
getString( R.string.err_dup_invite_fmt, (String)args[0] ); getString( R.string.err_dup_invite_fmt, (String)args[0] );
post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
showOKOnlyDialog( msg ); makeOkOnlyBuilder( msg ).show();
} }
} ); } );
break; break;

View file

@ -46,6 +46,7 @@ import org.eehouse.android.xw4.DlgDelegate.ActionPair;
import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder; import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify; import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify;
import org.eehouse.android.xw4.DlgDelegate.NotAgainBuilder; import org.eehouse.android.xw4.DlgDelegate.NotAgainBuilder;
import org.eehouse.android.xw4.DlgDelegate.OkOnlyBuilder;
import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
@ -501,16 +502,6 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.showAboutDialog(); m_dlgDelegate.showAboutDialog();
} }
public void showOKOnlyDialog( int msgID )
{
m_dlgDelegate.showOKOnlyDialog( msgID );
}
public void showOKOnlyDialog( String msg )
{
m_dlgDelegate.showOKOnlyDialog( msg );
}
public ConfirmThenBuilder makeConfirmThenBuilder( String msg, Action action ) { public ConfirmThenBuilder makeConfirmThenBuilder( String msg, Action action ) {
return m_dlgDelegate.makeConfirmThenBuilder( msg, action ); return m_dlgDelegate.makeConfirmThenBuilder( msg, action );
} }
@ -546,9 +537,14 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.showInviteChoicesThen( action, info ); m_dlgDelegate.showInviteChoicesThen( action, info );
} }
protected void showOKOnlyDialogThen( String msg, Action action ) public OkOnlyBuilder makeOkOnlyBuilder( int msgId )
{ {
m_dlgDelegate.showOKOnlyDialogThen( msg, action ); return m_dlgDelegate.makeOkOnlyBuilder( msgId );
}
public OkOnlyBuilder makeOkOnlyBuilder( String msg )
{
return m_dlgDelegate.makeOkOnlyBuilder( msg );
} }
protected void startProgress( int titleID, int msgID ) protected void startProgress( int titleID, int msgID )
@ -640,7 +636,7 @@ public class DelegateBase implements DlgClickNotify,
final String msg = getString( fmtId, (String)args[0] ); final String msg = getString( fmtId, (String)args[0] );
runOnUiThread( new Runnable() { runOnUiThread( new Runnable() {
public void run() { public void run() {
showOKOnlyDialog( msg ); makeOkOnlyBuilder( msg ).show();
} }
}); });
} }

View file

@ -195,7 +195,7 @@ public class DictBrowseDelegate extends ListDelegateBase
// be -- then use an empty list elem and disable // be -- then use an empty list elem and disable
// search/minmax stuff. // search/minmax stuff.
String msg = getString( R.string.alert_empty_dict_fmt, name ); String msg = getString( R.string.alert_empty_dict_fmt, name );
showOKOnlyDialogThen( msg, Action.FINISH_ACTION ); makeOkOnlyBuilder(msg).setAction(Action.FINISH_ACTION).show();
} else { } else {
figureMinMax( m_browseState.m_counts ); figureMinMax( m_browseState.m_counts );
if ( newState ) { if ( newState ) {

View file

@ -1322,7 +1322,7 @@ public class DictsDelegate extends ListDelegateBase
.show(); .show();
} }
} else { } else {
showOKOnlyDialog( R.string.remote_no_net ); makeOkOnlyBuilder( R.string.remote_no_net ).show();
m_checkbox.setChecked( false ); m_checkbox.setChecked( false );
} }
stopProgress(); stopProgress();

View file

@ -185,6 +185,20 @@ public class DlgDelegate {
abstract void show(); abstract void show();
} }
public class OkOnlyBuilder extends DlgDelegateBuilder {
public OkOnlyBuilder(String msg) { super( msg, Action.SKIP_CALLBACK ); }
public OkOnlyBuilder(int msgId) { super( msgId, Action.SKIP_CALLBACK ); }
public OkOnlyBuilder setAction( Action action )
{ m_action = action; return this; }
@Override
public void show()
{
showOKOnlyDialogThen( m_msgString, m_action );
}
}
public class ConfirmThenBuilder extends DlgDelegateBuilder { public class ConfirmThenBuilder extends DlgDelegateBuilder {
public ConfirmThenBuilder(String msg, Action action) {super(msg, action);} public ConfirmThenBuilder(String msg, Action action) {super(msg, action);}
public ConfirmThenBuilder(int msgId, Action action) {super(msgId, action);} public ConfirmThenBuilder(int msgId, Action action) {super(msgId, action);}
@ -225,6 +239,15 @@ public class DlgDelegate {
} }
} }
public OkOnlyBuilder makeOkOnlyBuilder( String msg )
{
return new OkOnlyBuilder( msg );
}
public OkOnlyBuilder makeOkOnlyBuilder( int msgId )
{
return new OkOnlyBuilder( msgId );
}
public ConfirmThenBuilder makeConfirmThenBuilder( String msg, Action action ) public ConfirmThenBuilder makeConfirmThenBuilder( String msg, Action action )
{ {
return new ConfirmThenBuilder( msg, action ); return new ConfirmThenBuilder( msg, action );
@ -273,8 +296,8 @@ public class DlgDelegate {
void inviteChoiceMade( Action action, InviteMeans means, Object[] params ); void inviteChoiceMade( Action action, InviteMeans means, Object[] params );
} }
public interface HasDlgDelegate { public interface HasDlgDelegate {
void showOKOnlyDialog( int msgID ); OkOnlyBuilder makeOkOnlyBuilder( int msgID );
void showOKOnlyDialog( String msg ); OkOnlyBuilder makeOkOnlyBuilder( String msg );
NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey, NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey,
Action action ); Action action );
NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey ); NotAgainBuilder makeNotAgainBuilder( int msgID, int prefsKey );
@ -383,7 +406,7 @@ public class DlgDelegate {
} }
} }
public void showOKOnlyDialogThen( String msg, Action action ) private void showOKOnlyDialogThen( String msg, Action action )
{ {
// Assert.assertNull( m_dlgStates ); // Assert.assertNull( m_dlgStates );
DlgState state = new DlgState( DlgID.DIALOG_OKONLY ).setMsg( msg ) DlgState state = new DlgState( DlgID.DIALOG_OKONLY ).setMsg( msg )
@ -392,16 +415,6 @@ public class DlgDelegate {
showDialog( DlgID.DIALOG_OKONLY ); showDialog( DlgID.DIALOG_OKONLY );
} }
public void showOKOnlyDialog( String msg )
{
showOKOnlyDialogThen( msg, Action.SKIP_CALLBACK );
}
public void showOKOnlyDialog( int msgID )
{
showOKOnlyDialogThen( getString( msgID ), Action.SKIP_CALLBACK );
}
public void showDictGoneFinish() public void showDictGoneFinish()
{ {
showDialog( DlgID.DLG_DICTGONE ); showDialog( DlgID.DLG_DICTGONE );
@ -495,7 +508,7 @@ public class DlgDelegate {
public void doSyncMenuitem() public void doSyncMenuitem()
{ {
if ( null == DBUtils.getRelayIDs( m_activity, null ) ) { if ( null == DBUtils.getRelayIDs( m_activity, null ) ) {
showOKOnlyDialog( R.string.no_games_to_refresh ); makeOkOnlyBuilder( R.string.no_games_to_refresh ).show();
} else { } else {
RelayService.timerFired( m_activity ); RelayService.timerFired( m_activity );
Utils.showToast( m_activity, R.string.msgs_progress ); Utils.showToast( m_activity, R.string.msgs_progress );
@ -578,7 +591,7 @@ public class DlgDelegate {
post( new Runnable() { post( new Runnable() {
public void run() { public void run() {
if ( asDlg ) { if ( asDlg ) {
showOKOnlyDialog( fmsg ); makeOkOnlyBuilder( fmsg ).show();
} else { } else {
DbgUtils.showf( m_activity, fmsg ); DbgUtils.showf( m_activity, fmsg );
} }

View file

@ -1238,7 +1238,7 @@ public class GameConfigDelegate extends DelegateBase
{ {
if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY ) if ( m_conTypes.contains( CommsConnType.COMMS_CONN_RELAY )
&& 0 == m_car.ip_relay_invite.length() ) { && 0 == m_car.ip_relay_invite.length() ) {
showOKOnlyDialog( R.string.no_empty_rooms ); makeOkOnlyBuilder( R.string.no_empty_rooms ).show();
} else { } else {
saveAndClose( forceNew ); saveAndClose( forceNew );
} }

View file

@ -1535,7 +1535,7 @@ public class GamesListDelegate extends ListDelegateBase
try { try {
startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse( str ) ) ); startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse( str ) ) );
} catch ( android.content.ActivityNotFoundException anf ) { } catch ( android.content.ActivityNotFoundException anf ) {
showOKOnlyDialog( R.string.no_market ); makeOkOnlyBuilder( R.string.no_market ).show();
} }
break; break;
@ -1761,7 +1761,7 @@ public class GamesListDelegate extends ListDelegateBase
final GameSummary smry = GameUtils.getSummary( m_activity, final GameSummary smry = GameUtils.getSummary( m_activity,
selRowIDs[0] ); selRowIDs[0] );
if ( smry.inRelayGame() ) { if ( smry.inRelayGame() ) {
showOKOnlyDialog( R.string.no_copy_network ); makeOkOnlyBuilder( R.string.no_copy_network ).show();
} else { } else {
dropSels = true; // will select the new game instead dropSels = true; // will select the new game instead
post( new Runnable() { post( new Runnable() {
@ -1802,7 +1802,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( null != info ) { if ( null != info ) {
msg += "\n\n" + info.getAsText( m_activity ); msg += "\n\n" + info.getAsText( m_activity );
} }
showOKOnlyDialog( msg ); makeOkOnlyBuilder( msg ).show();
break; break;
default: default:
@ -1828,7 +1828,7 @@ public class GamesListDelegate extends ListDelegateBase
if ( m_selGroupIDs.contains( dftGroup ) ) { if ( m_selGroupIDs.contains( dftGroup ) ) {
msg = getString( R.string.cannot_delete_default_group_fmt, msg = getString( R.string.cannot_delete_default_group_fmt,
m_adapter.groupName( dftGroup ) ); m_adapter.groupName( dftGroup ) );
showOKOnlyDialog( msg ); makeOkOnlyBuilder( msg ).show();
} else { } else {
Assert.assertTrue( 0 < groupIDs.length ); Assert.assertTrue( 0 < groupIDs.length );
msg = getQuantityString( R.plurals.groups_confirm_del_fmt, msg = getQuantityString( R.plurals.groups_confirm_del_fmt,
@ -2084,7 +2084,7 @@ public class GamesListDelegate extends ListDelegateBase
.setParams( nli ) .setParams( nli )
.show(); .show();
} else { } else {
showOKOnlyDialog( R.string.dropped_dupe ); makeOkOnlyBuilder( R.string.dropped_dupe ).show();
} }
} // startNewNetGame } // startNewNetGame
@ -2167,7 +2167,7 @@ public class GamesListDelegate extends ListDelegateBase
{ {
String msg = intent.getStringExtra( ALERT_MSG ); String msg = intent.getStringExtra( ALERT_MSG );
if ( null != msg ) { if ( null != msg ) {
showOKOnlyDialog( msg ); makeOkOnlyBuilder( msg ).show();
} }
} }
@ -2238,11 +2238,6 @@ public class GamesListDelegate extends ListDelegateBase
} }
} }
private void showGotDictForLang( String lang )
{
showOKOnlyDialog( String.format( "got dict for %s", lang ) );
}
private void updateField() private void updateField()
{ {
String newField = CommonPrefs.getSummaryField( m_activity ); String newField = CommonPrefs.getSummaryField( m_activity );

View file

@ -30,6 +30,7 @@ import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action; import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder; import org.eehouse.android.xw4.DlgDelegate.ConfirmThenBuilder;
import org.eehouse.android.xw4.DlgDelegate.NotAgainBuilder; import org.eehouse.android.xw4.DlgDelegate.NotAgainBuilder;
import org.eehouse.android.xw4.DlgDelegate.OkOnlyBuilder;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
public class PrefsActivity extends PreferenceActivity public class PrefsActivity extends PreferenceActivity
@ -100,14 +101,14 @@ public class PrefsActivity extends PreferenceActivity
m_dlgt.prepareDialog( DlgID.values()[id], dialog ); m_dlgt.prepareDialog( DlgID.values()[id], dialog );
} }
public void showOKOnlyDialog( int msgID ) public OkOnlyBuilder makeOkOnlyBuilder( int msgId )
{ {
m_dlgt.showOKOnlyDialog( msgID ); return m_dlgt.makeOkOnlyBuilder( msgId );
} }
public void showOKOnlyDialog( String msg ) public OkOnlyBuilder makeOkOnlyBuilder( String msg )
{ {
m_dlgt.showOKOnlyDialog( msg ); return m_dlgt.makeOkOnlyBuilder( msg );
} }
public NotAgainBuilder makeNotAgainBuilder(int msgId, int key, Action action) public NotAgainBuilder makeNotAgainBuilder(int msgId, int key, Action action)

View file

@ -232,7 +232,7 @@ public class PrefsDelegate extends DelegateBase
RelayService.enabledChanged( m_activity ); RelayService.enabledChanged( m_activity );
break; break;
case R.string.key_enable_dualpane: case R.string.key_enable_dualpane:
showOKOnlyDialog( R.string.after_restart ); makeOkOnlyBuilder( R.string.after_restart ).show();
break; break;
default: default:
Assert.fail(); Assert.fail();

View file

@ -372,7 +372,7 @@ public class StudyListDelegate extends ListDelegateBase
} }
if ( null != msg ) { if ( null != msg ) {
dlg.showOKOnlyDialog( msg ); dlg.makeOkOnlyBuilder( msg ).show();
} }
} }

View file

@ -101,7 +101,9 @@ public class XWConnAddrPreference extends DialogPreference {
new ConnViaViewLayout.SetEmptyWarner() { new ConnViaViewLayout.SetEmptyWarner() {
public void typeSetEmpty() { public void typeSetEmpty() {
PrefsActivity activity = (PrefsActivity)m_context; PrefsActivity activity = (PrefsActivity)m_context;
activity.showOKOnlyDialog( R.string.warn_no_comms ); activity
.makeOkOnlyBuilder( R.string.warn_no_comms )
.show();
} }
}, activity ); }, activity );
} }

View file

@ -161,7 +161,7 @@ public class LocItemEditDelegate extends DelegateBase implements TextWatcher {
ok = m_keyFmts.equals( getFmtSet( cs.toString(), null ) ); ok = m_keyFmts.equals( getFmtSet( cs.toString(), null ) );
if ( !ok ) { if ( !ok ) {
showOKOnlyDialog( R.string.loc_fmts_mismatch ); makeOkOnlyBuilder( R.string.loc_fmts_mismatch ).show();
} }
} }
return ok; return ok;