give user a chance to turn on play-via-SMS when sending an SMS

invitation (which will otherwise fail silently). Required a hack
passing params from one dialog to another, but I like that better
(today) than creating new single-purpose iVars in BoardDelegate.
This commit is contained in:
Eric House 2016-01-20 07:58:01 -08:00
parent f65d42732b
commit eb08e8e78d
3 changed files with 75 additions and 18 deletions

View file

@ -992,7 +992,8 @@ public class BoardDelegate extends DelegateBase
// DlgDelegate.DlgClickNotify interface // DlgDelegate.DlgClickNotify interface
////////////////////////////////////////////////// //////////////////////////////////////////////////
@Override @Override
public void dlgButtonClicked( Action action, int which, Object[] params ) public void dlgButtonClicked( Action action, int which,
final Object[] params )
{ {
boolean handled = false; boolean handled = false;
if ( AlertDialog.BUTTON_POSITIVE == which ) { if ( AlertDialog.BUTTON_POSITIVE == which ) {
@ -1066,6 +1067,17 @@ public class BoardDelegate extends DelegateBase
case DELETE_AND_EXIT: case DELETE_AND_EXIT:
deleteAndClose(); deleteAndClose();
break; break;
case ENABLE_SMS_DO:
handled = false; // so super gets called, before
// retrySMSInvites
post( new Runnable() {
public void run() {
retrySMSInvites( params );
}
} );
break;
default: default:
handled = false; handled = false;
} }
@ -2451,7 +2463,8 @@ public class BoardDelegate extends DelegateBase
BTService.inviteRemote( m_activity, dev, nli ); BTService.inviteRemote( m_activity, dev, nli );
break; break;
case SMS: case SMS:
SMSService.inviteRemote( m_activity, dev, nli ); sendSMSInviteIf( dev, nli, true );
dev = null; // don't record send a second time
break; break;
case RELAY: case RELAY:
try { try {
@ -2464,7 +2477,9 @@ public class BoardDelegate extends DelegateBase
break; break;
} }
recordInviteSent( m_missingMeans, dev ); if ( null != dev ) {
recordInviteSent( m_missingMeans, dev );
}
} }
m_missingDevs = null; m_missingDevs = null;
m_missingCounts = null; m_missingCounts = null;
@ -2713,8 +2728,7 @@ public class BoardDelegate extends DelegateBase
String value; String value;
value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_PHONE ); value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_PHONE );
if ( null != value ) { if ( null != value ) {
SMSService.inviteRemote( m_activity, value, nli ); sendSMSInviteIf( value, nli, true );
recordInviteSent( InviteMeans.SMS, value );
} }
value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_BTADDR ); value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_BTADDR );
if ( null != value ) { if ( null != value ) {
@ -2732,6 +2746,32 @@ public class BoardDelegate extends DelegateBase
} }
} }
private void sendSMSInviteIf( String phone, NetLaunchInfo nli,
boolean askOk )
{
if ( XWPrefs.getSMSEnabled( m_activity ) ) {
SMSService.inviteRemote( m_activity, phone, nli );
recordInviteSent( InviteMeans.SMS, phone );
} else if ( askOk ) {
showConfirmThen( R.string.warn_sms_disabled,
R.string.button_enable_sms,
R.string.button_later,
Action.ENABLE_SMS_ASK, nli, phone );
}
}
private void retrySMSInvites( Object[] params )
{
if ( null != params && 2 == params.length
&& params[0] instanceof NetLaunchInfo
&& params[1] instanceof String ) {
sendSMSInviteIf( (String)params[1], (NetLaunchInfo)params[0],
false );
} else {
DbgUtils.logf( "retrySMSInvites: tests failed" );
}
}
private void recordInviteSent( InviteMeans means, String dev ) private void recordInviteSent( InviteMeans means, String dev )
{ {
DBUtils.recordInviteSent( m_activity, m_rowid, means, dev ); DBUtils.recordInviteSent( m_activity, m_rowid, means, dev );

View file

@ -426,6 +426,12 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.showConfirmThen( msg, posButton, negButton, action ); m_dlgDelegate.showConfirmThen( msg, posButton, negButton, action );
} }
protected void showConfirmThen( int msg, int posButton, int negButton,
Action action, Object... params )
{
m_dlgDelegate.showConfirmThen( msg, posButton, negButton, action, params );
}
protected void showConfirmThen( int msg, int posButton, Action action, protected void showConfirmThen( int msg, int posButton, Action action,
Object... params ) Object... params )
{ {
@ -513,9 +519,9 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.showDictGoneFinish(); m_dlgDelegate.showDictGoneFinish();
} }
protected void showSMSEnableDialog( Action action ) protected void showSMSEnableDialog( Action action, Object... params )
{ {
m_dlgDelegate.showSMSEnableDialog( action ); m_dlgDelegate.showSMSEnableDialog( action, params );
} }
////////////////////////////////////////////////// //////////////////////////////////////////////////
@ -566,14 +572,11 @@ public class DelegateBase implements DlgClickNotify,
if ( AlertDialog.BUTTON_POSITIVE == button ) { if ( AlertDialog.BUTTON_POSITIVE == button ) {
switch( action ) { switch( action ) {
case ENABLE_SMS_ASK: case ENABLE_SMS_ASK:
showSMSEnableDialog( Action.ENABLE_SMS_DO ); showSMSEnableDialog( Action.ENABLE_SMS_DO, params );
handled = true; handled = true;
break; break;
case ENABLE_SMS_DO: case ENABLE_SMS_DO:
boolean enabled = (Boolean)params[0]; XWPrefs.setSMSEnabled( m_activity, true );
if ( enabled ) {
XWPrefs.setSMSEnabled( m_activity, true );
}
break; break;
case ENABLE_BT_DO: case ENABLE_BT_DO:
BTService.enable(); BTService.enable();

View file

@ -283,9 +283,9 @@ 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 dlgButtonClicked 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 ) public void showSMSEnableDialog( Action action, Object... params )
{ {
DlgState state = new DlgState( DlgID.DIALOG_ENABLESMS, action ); DlgState state = new DlgState( DlgID.DIALOG_ENABLESMS, action, params );
addState( state ); addState( state );
showDialog( DlgID.DIALOG_ENABLESMS ); showDialog( DlgID.DIALOG_ENABLESMS );
} }
@ -369,6 +369,12 @@ public class DlgDelegate {
showConfirmThen( null, getString(msg), posButton, negButton, action, null ); showConfirmThen( null, getString(msg), posButton, negButton, action, null );
} }
public void showConfirmThen( int msg, int posButton, int negButton, Action action,
Object... params )
{
showConfirmThen( null, getString(msg), posButton, negButton, action, params );
}
public void showConfirmThen( int msg, int posButton, Action action, public void showConfirmThen( int msg, int posButton, Action action,
Object[] params ) Object[] params )
{ {
@ -643,7 +649,6 @@ public class DlgDelegate {
items.add( getString( R.string.invite_choice_relay ) ); items.add( getString( R.string.invite_choice_relay ) );
means.add( DlgClickNotify.InviteMeans.RELAY ); means.add( DlgClickNotify.InviteMeans.RELAY );
} }
final int clipPos = means.size();
items.add( getString( R.string.slmenu_copy_sel ) ); items.add( getString( R.string.slmenu_copy_sel ) );
means.add( DlgClickNotify.InviteMeans.CLIPBOARD ); means.add( DlgClickNotify.InviteMeans.CLIPBOARD );
@ -660,11 +665,21 @@ public class DlgDelegate {
OnClickListener selChanged = new OnClickListener() { OnClickListener selChanged = new OnClickListener() {
public void onClick( DialogInterface dlg, int view ) { public void onClick( DialogInterface dlg, int view ) {
sel[0] = view; sel[0] = view;
if ( view == clipPos ) { switch ( means.get(view) ) {
case CLIPBOARD:
String msg = String msg =
getString( R.string.not_again_clip_expl_fmt, getString( R.string.not_again_clip_expl_fmt,
getString(R.string.slmenu_copy_sel) ); getString(R.string.slmenu_copy_sel) );
showNotAgainDlgThen( msg, R.string.key_na_clip_expl ); showNotAgainDlgThen( msg, R.string.key_na_clip_expl );
break;
case SMS:
if ( ! XWPrefs.getSMSEnabled( m_activity ) ) {
showConfirmThen( R.string.warn_sms_disabled,
R.string.button_enable_sms,
R.string.button_later,
Action.ENABLE_SMS_ASK );
}
break;
} }
Button button = ((AlertDialog)dlg) Button button = ((AlertDialog)dlg)
.getButton( AlertDialog.BUTTON_POSITIVE ); .getButton( AlertDialog.BUTTON_POSITIVE );
@ -731,10 +746,9 @@ 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 );
Object[] params = { new Boolean(enabled), };
m_clickCallback.dlgButtonClicked( state.m_action, m_clickCallback.dlgButtonClicked( state.m_action,
AlertDialog.BUTTON_POSITIVE, AlertDialog.BUTTON_POSITIVE,
params ); state.m_params );
} }
}; };