when re-inviting, pre-populate BT and SMS invite dialogs from the most

recent invitation of that "means" recorded for that game
This commit is contained in:
Eric House 2016-01-18 07:41:47 -08:00
parent 6c1394a3a5
commit 38898776bd
11 changed files with 97 additions and 39 deletions

View file

@ -586,7 +586,7 @@
<string name="invit_expl_sms_fmt">Invite sent via SMS to phone
number %1$s on %2$s</string>
<string name="invit_expl_bt_fmt">Invite sent via Bluetooth to
paired device %1$s on %2$s</string>
paired device \"%1$s\" on %2$s</string>
<string name="invit_expl_relay_fmt">Invite forwarded by the relay
to another device on %1$s</string>
<string name="invit_expl_notarget_fmt">Invite sent via %1$s on

View file

@ -500,7 +500,7 @@
<string name="invit_expl_sms_fmt">Etivni tnes aiv SMS ot enohp
rebmun %1$s no %2$s</string>
<string name="invit_expl_bt_fmt">Etivni tnes aiv Htooteulb ot
deriap ecived %1$s no %2$s</string>
deriap ecived \"%1$s\" no %2$s</string>
<string name="invit_expl_relay_fmt">Etivni dedrawrof yb eht yaler
ot rehtona ecived no %1$s</string>
<string name="invit_expl_notarget_fmt">Etivni tnes aiv %1$s no

View file

@ -500,7 +500,7 @@
<string name="invit_expl_sms_fmt">INVITE SENT VIA SMS TO PHONE
NUMBER %1$s ON %2$s</string>
<string name="invit_expl_bt_fmt">INVITE SENT VIA BLUETOOTH TO
PAIRED DEVICE %1$s ON %2$s</string>
PAIRED DEVICE \"%1$s\" ON %2$s</string>
<string name="invit_expl_relay_fmt">INVITE FORWARDED BY THE RELAY
TO ANOTHER DEVICE ON %1$s</string>
<string name="invit_expl_notarget_fmt">INVITE SENT VIA %1$s ON

View file

@ -44,6 +44,8 @@ import java.util.Iterator;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
public class BTInviteDelegate extends InviteDelegate {
@ -53,12 +55,17 @@ public class BTInviteDelegate extends InviteDelegate {
private boolean m_setChecked;
private BTDevsAdapter m_adapter;
public static void launchForResult( Activity activity, int nMissing,
public static void launchForResult( Activity activity, int nMissing,
SentInvitesInfo info,
RequestCode requestCode )
{
Assert.assertTrue( 0 < nMissing ); // don't call if nMissing == 0
Intent intent = new Intent( activity, BTInviteActivity.class );
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
if ( null != info ) {
String lastDev = info.getLastDev( InviteMeans.BLUETOOTH );
intent.putExtra( INTENT_KEY_LASTDEV, lastDev );
}
activity.startActivityForResult( intent, requestCode.ordinal() );
}
@ -239,6 +246,9 @@ public class BTInviteDelegate extends InviteDelegate {
if ( m_setChecked || m_checked.contains( btAddr ) ) {
box.setChecked( true );
} else if ( null != m_lastDev && m_lastDev.equals( btAddr ) ) {
m_lastDev = null;
box.setChecked( true );
}
return layout;
}

View file

@ -438,7 +438,8 @@ public class BoardDelegate extends DelegateBase
if ( m_summary.hasRematchInfo() ) {
tryRematchInvites( true );
} else {
showInviteChoicesThen( Action.LAUNCH_INVITE_ACTION );
showInviteChoicesThen( Action.LAUNCH_INVITE_ACTION,
m_sentInfo );
}
} else {
askDropRelay();
@ -1083,6 +1084,8 @@ public class BoardDelegate extends DelegateBase
Object[] params )
{
if ( action == Action.LAUNCH_INVITE_ACTION ) {
SentInvitesInfo info = params[0] instanceof SentInvitesInfo
? (SentInvitesInfo)params[0] : null;
switch( means ) {
case NFC:
if ( XWPrefs.getNFCToSelfEnabled( m_activity ) ) {
@ -1094,11 +1097,11 @@ public class BoardDelegate extends DelegateBase
}
break;
case BLUETOOTH:
BTInviteDelegate.launchForResult( m_activity, m_nMissing,
BTInviteDelegate.launchForResult( m_activity, m_nMissing, info,
RequestCode.BT_INVITE_RESULT );
break;
case SMS:
SMSInviteDelegate.launchForResult( m_activity, m_nMissing,
SMSInviteDelegate.launchForResult( m_activity, m_nMissing, info,
RequestCode.SMS_INVITE_RESULT );
break;
case RELAY:
@ -2422,7 +2425,6 @@ public class BoardDelegate extends DelegateBase
m_invitesPending = m_missingDevs.length;
for ( int ii = 0; ii < m_missingDevs.length; ++ii ) {
String dev = m_missingDevs[ii];
String devName = dev;
int nPlayers = m_missingCounts[ii];
Assert.assertTrue( 0 <= m_nGuestDevs );
int forceChannel = ii + m_nGuestDevs + 1;
@ -2436,8 +2438,7 @@ public class BoardDelegate extends DelegateBase
case BLUETOOTH:
if ( ! m_progressShown ) {
m_progressShown = true;
devName = BTService.nameForAddr( dev );
String progMsg = devName;
String progMsg = BTService.nameForAddr( dev );
progMsg = getString( R.string.invite_progress_fmt, progMsg );
startProgress( R.string.invite_progress_title, progMsg,
new OnCancelListener() {
@ -2463,7 +2464,7 @@ public class BoardDelegate extends DelegateBase
break;
}
recordInviteSent( m_missingMeans, devName );
recordInviteSent( m_missingMeans, dev );
}
m_missingDevs = null;
m_missingCounts = null;

View file

@ -423,25 +423,41 @@ public class DBUtils {
public static class SentInvitesInfo {
public long m_rowid;
private ArrayList<InviteMeans> m_means;
private ArrayList<String> m_target;
private ArrayList<Timestamp> m_timestamp;
private ArrayList<String> m_targets;
private ArrayList<Timestamp> m_timestamps;
private int m_cachedCount = 0;
private SentInvitesInfo( long rowID ) {
m_rowid = rowID;
m_means = new ArrayList<InviteMeans>();
m_target = new ArrayList<String>();
m_timestamp = new ArrayList<Timestamp>();
m_targets = new ArrayList<String>();
m_timestamps = new ArrayList<Timestamp>();
}
private void addEntry( InviteMeans means, String target, Timestamp ts )
{
m_means.add( means );
m_target.add( target );
m_timestamp.add( ts );
m_targets.add( target );
m_timestamps.add( ts );
m_cachedCount = -1;
}
public InviteMeans getLastMeans()
{
return 0 < m_means.size() ? m_means.get(0) : null;
}
public String getLastDev( InviteMeans means )
{
String result = null;
for ( int ii = 0; null == result && ii < m_means.size(); ++ii ) {
if ( means == m_means.get( ii ) ) {
result = m_targets.get( ii );
}
}
return result;
}
// There will be lots of duplicates, but we can't detect them all. BUT
// if means and target are the same it's definitely a dup. So count
// them all and return the largest number we have. 99% of the time we
@ -449,7 +465,7 @@ public class DBUtils {
public int getMinPlayerCount() {
if ( -1 == m_cachedCount ) {
DbgUtils.logf( "getMinPlayerCount(%H)", this );
int count = m_timestamp.size();
int count = m_timestamps.size();
Map<InviteMeans, Set<String>> hashes
= new HashMap<InviteMeans, Set<String>>();
int fakeCount = 0; // make all null-targets count for one
@ -462,7 +478,7 @@ public class DBUtils {
hashes.put( means, devs );
}
devs = hashes.get( means );
String target = m_target.get( ii );
String target = m_targets.get( ii );
if ( null == target ) {
target = String.format( "%d", ++fakeCount );
}
@ -487,12 +503,12 @@ public class DBUtils {
public String getAsText( Context context )
{
int count = m_timestamp.size();
int count = m_timestamps.size();
String[] strs = new String[count];
for ( int ii = 0; ii < count; ++ii ) {
InviteMeans means = m_means.get(ii);
String target = m_target.get(ii);
String timestamp = m_timestamp.get(ii).toString();
String target = m_targets.get(ii);
String timestamp = m_timestamps.get(ii).toString();
String msg;
switch ( means ) {
@ -501,8 +517,9 @@ public class DBUtils {
target, timestamp );
break;
case BLUETOOTH:
String devName = BTService.nameForAddr( target );
msg = LocUtils.getString( context, R.string.invit_expl_bt_fmt,
target, timestamp );
devName, timestamp );
break;
case RELAY:
msg = LocUtils.getString( context, R.string.invit_expl_relay_fmt,

View file

@ -465,9 +465,10 @@ public class DelegateBase implements DlgClickNotify,
m_dlgDelegate.launchLookup( words, lang, !studyOn );
}
protected void showInviteChoicesThen( Action action )
protected void showInviteChoicesThen( Action action,
DBUtils.SentInvitesInfo info )
{
m_dlgDelegate.showInviteChoicesThen( action );
m_dlgDelegate.showInviteChoicesThen( action, info );
}
protected void showOKOnlyDialogThen( String msg, Action action )

View file

@ -47,6 +47,7 @@ import java.util.Iterator;
import junit.framework.Assert;
import org.eehouse.android.xw4.loc.LocUtils;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
public class DlgDelegate {
@ -391,13 +392,14 @@ public class DlgDelegate {
showDialog( DlgID.CONFIRM_THEN );
}
public void showInviteChoicesThen( final Action action )
public void showInviteChoicesThen( final Action action,
SentInvitesInfo info )
{
if ( (XWApp.SMS_INVITE_ENABLED && Utils.deviceSupportsSMS( m_activity ))
|| XWPrefs.getNFCToSelfEnabled( m_activity )
|| NFCUtils.nfcAvail( m_activity )[0]
|| BTService.BTAvailable() ) {
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN, action );
DlgState state = new DlgState( DlgID.INVITE_CHOICES_THEN, action, info );
addState( state );
showDialog( DlgID.INVITE_CHOICES_THEN );
} else {
@ -616,6 +618,12 @@ public class DlgDelegate {
final ArrayList<DlgClickNotify.InviteMeans> means =
new ArrayList<DlgClickNotify.InviteMeans>();
ArrayList<String> items = new ArrayList<String>();
DlgClickNotify.InviteMeans lastMeans = null;
if ( null != state.m_params
&& state.m_params[0] instanceof SentInvitesInfo ) {
lastMeans =((SentInvitesInfo)state.m_params[0]).getLastMeans();
}
if ( XWApp.SMS_INVITE_ENABLED && Utils.deviceSupportsSMS(m_activity) ) {
items.add( getString( R.string.invite_choice_sms ) );
means.add( DlgClickNotify.InviteMeans.SMS );
@ -640,22 +648,27 @@ public class DlgDelegate {
means.add( DlgClickNotify.InviteMeans.CLIPBOARD );
final int[] sel = { -1 };
if ( null != lastMeans ) {
for ( int ii = 0; ii < means.size(); ++ii ) {
if ( lastMeans == means.get(ii) ) {
sel[0] = ii;
break;
}
}
}
OnClickListener selChanged = new OnClickListener() {
public void onClick( DialogInterface dlg, int view ) {
// First time through, enable the button
if ( -1 == sel[0] ) {
((AlertDialog)dlg)
.getButton( AlertDialog.BUTTON_POSITIVE )
.setEnabled( true );
}
sel[0] = view;
if ( view == clipPos ) {
String msg =
getString( R.string.not_again_clip_expl_fmt,
getString(R.string.slmenu_copy_sel) );
showNotAgainDlgThen( msg, R.string.key_na_clip_expl );
}
Button button = ((AlertDialog)dlg)
.getButton( AlertDialog.BUTTON_POSITIVE );
button.setEnabled( true );
}
};
OnClickListener okClicked = new OnClickListener() {
@ -672,7 +685,7 @@ public class DlgDelegate {
AlertDialog.Builder builder = LocUtils.makeAlertBuilder( m_activity )
.setTitle( R.string.invite_choice_title )
.setSingleChoiceItems( items.toArray( new String[items.size()] ),
.setSingleChoiceItems( items.toArray( new String[items.size()] ),
sel[0], selChanged )
.setPositiveButton( android.R.string.ok, okClicked )
.setNegativeButton( android.R.string.cancel, null );
@ -685,7 +698,8 @@ public class DlgDelegate {
AlertDialog ad = (AlertDialog)dialog;
Button button = ad.getButton( AlertDialog.BUTTON_POSITIVE );
if ( null != button ) {
button.setEnabled( false );
long[] ids = ad.getListView().getCheckedItemIds();
button.setEnabled( 1 == ids.length );
}
}

View file

@ -91,6 +91,11 @@ public class DlgState implements Parcelable {
this( dlgID, null, 0, null, 0, params );
}
public DlgState( DlgID dlgID, Action action, Object... params )
{
this( dlgID, null, 0, action, 0, params );
}
public int describeContents() {
return 0;
}

View file

@ -40,8 +40,10 @@ abstract class InviteDelegate extends ListDelegateBase
public static final String DEVS = "DEVS";
public static final String COUNTS = "COUNTS";
protected static final String INTENT_KEY_NMISSING = "NMISSING";
protected static final String INTENT_KEY_LASTDEV = "LDEV";
protected int m_nMissing;
protected String m_lastDev;
protected Button m_okButton;
protected Button m_rescanButton;
protected Button m_clearButton;
@ -56,6 +58,7 @@ abstract class InviteDelegate extends ListDelegateBase
m_activity = delegator.getActivity();
Intent intent = getIntent();
m_nMissing = intent.getIntExtra( INTENT_KEY_NMISSING, -1 );
m_lastDev = intent.getStringExtra( INTENT_KEY_LASTDEV );
}
protected void init( int button_invite, int button_rescan,

View file

@ -49,6 +49,7 @@ import java.util.Map;
import junit.framework.Assert;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
public class SMSInviteDelegate extends InviteDelegate {
@ -63,11 +64,16 @@ public class SMSInviteDelegate extends InviteDelegate {
private boolean m_immobileConfirmed;
private Activity m_activity;
public static void launchForResult( Activity activity, int nMissing,
public static void launchForResult( Activity activity, int nMissing,
SentInvitesInfo info,
RequestCode requestCode )
{
Intent intent = new Intent( activity, SMSInviteActivity.class );
intent.putExtra( INTENT_KEY_NMISSING, nMissing );
if ( null != info ) {
String lastDev = info.getLastDev( InviteMeans.SMS );
intent.putExtra( INTENT_KEY_LASTDEV, lastDev );
}
activity.startActivityForResult( intent, requestCode.ordinal() );
}
@ -327,7 +333,8 @@ public class SMSInviteDelegate extends InviteDelegate {
m_phoneRecs = new ArrayList<PhoneRec>(phones.length);
for ( String phone : phones ) {
PhoneRec rec = new PhoneRec( phone );
boolean matches = phone.equals( m_lastDev );
PhoneRec rec = new PhoneRec( null, phone, matches );
m_phoneRecs.add( rec );
}
}
@ -383,7 +390,7 @@ public class SMSInviteDelegate extends InviteDelegate {
this( null, phone, false );
}
public PhoneRec( String name, String phone, boolean checked )
private PhoneRec( String name, String phone, boolean checked )
{
m_phone = phone;
m_isChecked = checked;