tweak buttons and text of invite dialog

I want to encourage people not to think there's action to be taken
between when they invite and an invitee responds, e.g. to email. So make
the "Close Game" button the "positive" one that case.
This commit is contained in:
Eric House 2021-02-20 20:31:53 -08:00
parent 014cafe67e
commit 4e21e40de5
2 changed files with 90 additions and 81 deletions

View file

@ -140,9 +140,10 @@ class InvitesNeededAlert {
State state = (State)params[0]; State state = (State)params[0];
AlertDialog.Builder ab = mDelegate.makeAlertBuilder(); AlertDialog.Builder ab = mDelegate.makeAlertBuilder();
mAlert = alert; mAlert = alert;
int[] closeLoc = { AlertDialog.BUTTON_NEGATIVE };
if ( state.mIsServer ) { if ( state.mIsServer ) {
makeImplHost( ab, callbacks, alert, state ); makeImplHost( ab, callbacks, alert, state, closeLoc );
} else { } else {
makeImplGuest( ab, state ); makeImplGuest( ab, state );
} }
@ -156,14 +157,22 @@ class InvitesNeededAlert {
} }
} ); } );
OnClickListener onClose = new OnClickListener() {
alert.setNoDismissListenerNeg( ab, R.string.button_close_game, @Override
new OnClickListener() { public void onClick( DialogInterface dlg, int item ) {
@Override callbacks.onCloseClicked();
public void onClick( DialogInterface dlg, int item ) { }
callbacks.onCloseClicked(); };
} switch ( closeLoc[0] ) {
} ); case AlertDialog.BUTTON_NEGATIVE:
alert.setNoDismissListenerNeg( ab, R.string.button_close_game, onClose );
break;
case AlertDialog.BUTTON_POSITIVE:
alert.setNoDismissListenerPos( ab, R.string.button_close_game, onClose );
break;
default:
Assert.failDbg();
}
Dialog result = ab.create(); Dialog result = ab.create();
result.setCanceledOnTouchOutside( false ); result.setCanceledOnTouchOutside( false );
@ -186,13 +195,18 @@ class InvitesNeededAlert {
} }
private void makeImplHost( AlertDialog.Builder ab, final Callbacks callbacks, private void makeImplHost( AlertDialog.Builder ab, final Callbacks callbacks,
DBAlert alert, State state ) DBAlert alert, State state, int[] closeLoc )
{ {
Context context = mDelegate.getActivity(); Context context = mDelegate.getActivity();
String title;
boolean isRematch = state.mIsRematch;
final int nPlayersMissing = state.mNPlayersMissing; final int nPlayersMissing = state.mNPlayersMissing;
long rowid = callbacks.getRowID();
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( context, rowid );
int nSent = sentInfo.getMinPlayerCount();
boolean invitesNeeded = nPlayersMissing > nSent;
String title;
boolean isRematch = state.mIsRematch;
if ( isRematch ) { if ( isRematch ) {
title = LocUtils.getString( context, R.string.waiting_rematch_title ); title = LocUtils.getString( context, R.string.waiting_rematch_title );
} else { } else {
@ -200,43 +214,40 @@ class InvitesNeededAlert {
.getQuantityString( context, R.plurals.waiting_title_fmt, .getQuantityString( context, R.plurals.waiting_title_fmt,
nPlayersMissing, nPlayersMissing ); nPlayersMissing, nPlayersMissing );
} }
ab.setTitle( title );
String message = LocUtils String message;
.getQuantityString( context, R.plurals.invite_msg_fmt, int inviteButtonTxt;
nPlayersMissing, nPlayersMissing ); if ( invitesNeeded ) {
message += "\n\n" Assert.assertTrueNR( !isRematch );
+ LocUtils.getString( context, R.string.invite_msg_extra ); message = LocUtils.getString( context, R.string.invites_unsent );
inviteButtonTxt = R.string.newgame_invite;
if ( isRematch ) { } else {
message += "\n\n" message = LocUtils
+ LocUtils.getString( context, R.string.invite_msg_extra_rematch ); .getQuantityString( context, R.plurals.invite_msg_fmt, // here
} nPlayersMissing, nPlayersMissing );
if ( isRematch ) {
ab.setTitle( title ) message += "\n\n"
.setMessage( message ); + LocUtils.getString( context, R.string.invite_msg_extra_rematch );
alert.setNoDismissListenerPos( ab, R.string.newgame_invite,
new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
callbacks.onInviteClicked();
}
} );
if ( BuildConfig.NON_RELEASE ) {
long rowid = callbacks.getRowID();
SentInvitesInfo sentInfo = DBUtils.getInvitesFor( context, rowid );
int nSent = sentInfo.getMinPlayerCount();
boolean invitesSent = nSent >= nPlayersMissing;
if ( invitesSent ) {
alert.setNoDismissListenerNeut( ab, R.string.newgame_invite_more,
new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
callbacks.onInfoClicked();
}
} );
} }
inviteButtonTxt = R.string.newgame_reinvite;
}
ab.setMessage( message );
// If user needs to act, emphasize that by having the positive button
// be Invite. If not, have the positive button be Close
OnClickListener onInvite = new OnClickListener() {
@Override
public void onClick( DialogInterface dlg, int item ) {
callbacks.onInviteClicked();
}
};
if ( invitesNeeded ) {
alert.setNoDismissListenerPos( ab, inviteButtonTxt, onInvite );
} else {
alert.setNoDismissListenerNeg( ab, inviteButtonTxt, onInvite );
closeLoc[0] = DialogInterface.BUTTON_POSITIVE;
} }
} }
} }

View file

@ -453,51 +453,48 @@
<string name="no_moves_made">(No moves yet)</string> <string name="no_moves_made">(No moves yet)</string>
<!-- If a networked game is opened and is not complete, i.e. if it <!-- If a networked game is opened and is not complete, i.e. if it
is listed as expecting remote players who have not yet shown is listed as expecting remote players who have not yet shown
up, then the most likely explanation is that none has been up, then IF nobody's been invited (the initial case) the user
invited. (It's also possible that an invitation has been needs to invite. But once that's done, there's nothing to do
sent, but I have no way of knowing that.) So every time I until recipients respond. So there are two messages for the
open such a game I give the user a chance to issue an two cases. This is the first-->
invititation while trying to warn him not to send duplicates. <string name="invites_unsent">This game is configured to expect a
The number of players missing is substituted for "%1$d". --> remote player.
\n\nWould you like to invite someone?</string>
<!-- This is the second: invitations have been sent but players
are still missing. -->
<plurals name="invite_msg_fmt"> <plurals name="invite_msg_fmt">
<item quantity="one">This game is waiting for one remote <item quantity="one">This game is waiting for one remote
player to respond to an invitation.</item> player to receive and respond to an invitation.
\n\nYou will see this message until the invited player has
responded. If you suspect the invitation you sent was lost,
theres no harm in sending another.</item>
<item quantity="other">This game is waiting for %1$d remote <item quantity="other">This game is waiting for %1$d remote
players to repond to invitations.</item> players to repond to invitations.
\n\nYou will see this message until all expected players have
responded. If you suspect any invitations you sent were lost,
theres no harm in sending more.</item>
</plurals> </plurals>
<string name="invite_msg_extra">You will see this message until
all expected players have connected. If youve already sent an
invitation and suspect it was lost, theres no harm in sending
another.</string>
<string name="invite_msg_extra_rematch">With rematches, all <string name="invite_msg_extra_rematch">With rematches, all
necessary invitations will have been sent automatically. But you necessary invitations will have been sent automatically. But you
can always send new ones if an invitee is not responding.</string> can always send new ones if an invitee is not responding.</string>
<!-- <plurals name="invite_sent_fmt"> --> <!-- Appended to message above if local device has NFC
<!-- <item quantity="one">You have already invited a remote player to --> available. But not used right now -->
<!-- this game. We are waiting for him/her to respond. Please --> <!--string name="invite_if_nfc">Or just Tap to Invite - if the other
<!-- use the re-invite button if you think the invitation did not go --> device also has Android Beaming and is nearby.</string-->
<!-- out.</item> -->
<!-- <item quantity="other">You have already sent %1$d unique -->
<!-- invitations for this game. We are waiting for %2$d of the -->
<!-- recipients to respond. Please use the re-invite button if you -->
<!-- think the invitations did not go out.</item> -->
<!-- </plurals> -->
<!-- <string name="invited_msg">This game was created from an -->
<!-- invitation you received. As soon as it is able to connect to the -->
<!-- sender and any other invitees have arrived play will -->
<!-- begin.</string> -->
<!-- Appended to message above if local device has NFC available -->
<string name="invite_if_nfc">Or just Tap to Invite -- if the other
device also has Android Beaming and is nearby.</string>
<!-- Most users create games with only two players, which is the <!-- Most users create games with only two players, which is the
default, but CrossWords supports up to four. When I'm using default, but CrossWords supports up to four. When I'm using
the above string to encourage the opener of a game missing the above string to encourage the opener of a game missing
players to invite, IF the number of missing players is players to invite, IF the number of missing players is
greater than one this text is appended to the above. --> greater than one this text is appended to the above. -->
<string name="invite_multiple">\u0020(You are expecting multiple <!-- <string name="invite_multiple">\u0020(You are expecting multiple -->
remote players. You dont have to invite them all at once, but <!-- remote players. You dont have to invite them all at once, but -->
this alert will not be dismissed until everybody has been invited <!-- this alert will not be dismissed until everybody has been invited -->
and all invitations have been accepted.)</string> <!-- and all invitations have been accepted.)</string> -->
<string name="invit_expl_sms_fmt">Invite sent via Data SMS to phone <string name="invit_expl_sms_fmt">Invite sent via Data SMS to phone
number %1$s on %2$s</string> number %1$s on %2$s</string>
<string name="invit_expl_usrsms_fmt">Invite sent via SMS on %1$s</string> <string name="invit_expl_usrsms_fmt">Invite sent via SMS on %1$s</string>
@ -1008,6 +1005,7 @@
it immediately because an email or messaging app will be it immediately because an email or messaging app will be
launched to send your invitation. --> launched to send your invitation. -->
<string name="newgame_invite">Invite now</string> <string name="newgame_invite">Invite now</string>
<string name="newgame_reinvite">Invite again</string>
<!-- Button offering to invite Known Player to a new game --> <!-- Button offering to invite Known Player to a new game -->
<string name="invite_player_fmt">Invite %1$s</string> <string name="invite_player_fmt">Invite %1$s</string>
<string name="newgame_invite_more">History</string> <string name="newgame_invite_more">History</string>