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
//////////////////////////////////////////////////
@Override
public void dlgButtonClicked( Action action, int which, Object[] params )
public void dlgButtonClicked( Action action, int which,
final Object[] params )
{
boolean handled = false;
if ( AlertDialog.BUTTON_POSITIVE == which ) {
@ -1066,6 +1067,17 @@ public class BoardDelegate extends DelegateBase
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;
}
@ -2451,7 +2463,8 @@ public class BoardDelegate extends DelegateBase
BTService.inviteRemote( m_activity, dev, nli );
break;
case SMS:
SMSService.inviteRemote( m_activity, dev, nli );
sendSMSInviteIf( dev, nli, true );
dev = null; // don't record send a second time
break;
case RELAY:
try {
@ -2464,7 +2477,9 @@ public class BoardDelegate extends DelegateBase
break;
}
recordInviteSent( m_missingMeans, dev );
if ( null != dev ) {
recordInviteSent( m_missingMeans, dev );
}
}
m_missingDevs = null;
m_missingCounts = null;
@ -2713,8 +2728,7 @@ public class BoardDelegate extends DelegateBase
String value;
value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_PHONE );
if ( null != value ) {
SMSService.inviteRemote( m_activity, value, nli );
recordInviteSent( InviteMeans.SMS, value );
sendSMSInviteIf( value, nli, true );
}
value = m_summary.getStringExtra( GameSummary.EXTRA_REMATCH_BTADDR );
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 )
{
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 );
}
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,
Object... params )
{
@ -513,9 +519,9 @@ public class DelegateBase implements DlgClickNotify,
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 ) {
switch( action ) {
case ENABLE_SMS_ASK:
showSMSEnableDialog( Action.ENABLE_SMS_DO );
showSMSEnableDialog( Action.ENABLE_SMS_DO, params );
handled = true;
break;
case ENABLE_SMS_DO:
boolean enabled = (Boolean)params[0];
if ( enabled ) {
XWPrefs.setSMSEnabled( m_activity, true );
}
XWPrefs.setSMSEnabled( m_activity, true );
break;
case ENABLE_BT_DO:
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
// calls dlgButtonClicked with the action and in params a Boolean
// 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 );
showDialog( DlgID.DIALOG_ENABLESMS );
}
@ -369,6 +369,12 @@ public class DlgDelegate {
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,
Object[] params )
{
@ -643,7 +649,6 @@ public class DlgDelegate {
items.add( getString( R.string.invite_choice_relay ) );
means.add( DlgClickNotify.InviteMeans.RELAY );
}
final int clipPos = means.size();
items.add( getString( R.string.slmenu_copy_sel ) );
means.add( DlgClickNotify.InviteMeans.CLIPBOARD );
@ -660,11 +665,21 @@ public class DlgDelegate {
OnClickListener selChanged = new OnClickListener() {
public void onClick( DialogInterface dlg, int view ) {
sel[0] = view;
if ( view == clipPos ) {
switch ( means.get(view) ) {
case CLIPBOARD:
String msg =
getString( R.string.not_again_clip_expl_fmt,
getString(R.string.slmenu_copy_sel) );
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)
.getButton( AlertDialog.BUTTON_POSITIVE );
@ -731,10 +746,9 @@ public class DlgDelegate {
layout.findViewById( R.id.confirm_sms_reasons );
boolean enabled = 0 < reasons.getSelectedItemPosition();
Assert.assertTrue( enabled );
Object[] params = { new Boolean(enabled), };
m_clickCallback.dlgButtonClicked( state.m_action,
AlertDialog.BUTTON_POSITIVE,
params );
state.m_params );
}
};