put a different title on notifications when it's now a player's

turn. Probably only matters in three-device games, but I like it.
This commit is contained in:
Eric House 2016-01-14 20:45:58 -08:00
parent 1e50181b12
commit fe0504a308
8 changed files with 460 additions and 432 deletions

File diff suppressed because it is too large Load diff

View file

@ -1496,6 +1496,7 @@
device, and the body that appears when you pull the notifications
down. -->
<string name="notify_title_fmt">Move in game %1$s</string>
<string name="notify_title_turn_fmt">Your turn in game %1$s</string>
<string name="notify_chat_title_fmt">Chat message in game %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
@ -2615,10 +2616,10 @@
<string name="str_no_hint_found">Cannot find any moves</string>
<string name="not_again_rematch_two_only">The Rematch button is
disabled because, for now anyway, rematch is limited to two-person
games. I think it\'s rare that people play with more than two. Let
me know if I\'m wrong and I\'ll try harder to make it work.</string>
<string name="not_again_rematch_two_only">Rematch is limited to
two-person games, at least for now, because it\'s harder with more
devices and I think it\'s rare that people play with more than
two. Let me know if I\'m wrong and I\'ll up the priority.</string>
<string name="enable_relay_toself_title">Enable relay invites to self</string>
<string name="enable_relay_toself_summary">(To aid testing and debugging)</string>

View file

@ -1283,6 +1283,7 @@
device, and the body that appears when you pull the notifications
down. -->
<string name="notify_title_fmt">Evom ni emag %1$s</string>
<string name="notify_title_turn_fmt">Ruoy nrut ni emag %1$s</string>
<string name="notify_chat_title_fmt">Tahc egassem ni emag %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
@ -2237,10 +2238,10 @@
<string name="not_again_comms_bt">Esu Htooteulb ot yalp tsniaga a
ybraen ecived taht\'s \"deriap\" htiw sruoy.</string>
<string name="str_no_hint_found">Tonnac dnif yna sevom</string>
<string name="not_again_rematch_two_only">Eht Hctamer nottub si
delbasid ,esuaceb rof won ,yawyna hctamer si detimil ot nosrep-owt
semag. I kniht ti\'s erar taht elpoep yalp htiw erom naht owt. Tel
em wonk fi I\'m gnorw dna I\'ll yrt redrah ot ekam ti krow.</string>
<string name="not_again_rematch_two_only">Hctamer si detimil ot
nosrep-owt ,semag ta tsael rof ,won esuaceb ti\'s redrah htiw erom
secived dna I kniht ti\'s erar taht elpoep yalp htiw erom naht
owt. Tel em wonk fi I\'m gnorw dna I\'ll pu eht ytiroirp.</string>
<string name="enable_relay_toself_title">Elbane yaler setivni ot fles</string>
<string name="enable_relay_toself_summary">oT( dia gnitset dna )gniggubed</string>
<!-- Shown after "resend messages" menuitem chosen -->

View file

@ -1283,6 +1283,7 @@
device, and the body that appears when you pull the notifications
down. -->
<string name="notify_title_fmt">MOVE IN GAME %1$s</string>
<string name="notify_title_turn_fmt">YOUR TURN IN GAME %1$s</string>
<string name="notify_chat_title_fmt">CHAT MESSAGE IN GAME %1$s</string>
<string name="notify_chat_body_fmt">%1$s: %2$s</string>
<!--
@ -2237,10 +2238,10 @@
<string name="not_again_comms_bt">USE BLUETOOTH TO PLAY AGAINST A
NEARBY DEVICE THAT\'S \"PAIRED\" WITH YOURS.</string>
<string name="str_no_hint_found">CANNOT FIND ANY MOVES</string>
<string name="not_again_rematch_two_only">THE REMATCH BUTTON IS
DISABLED BECAUSE, FOR NOW ANYWAY, REMATCH IS LIMITED TO TWO-PERSON
GAMES. I THINK IT\'S RARE THAT PEOPLE PLAY WITH MORE THAN TWO. LET
ME KNOW IF I\'M WRONG AND I\'LL TRY HARDER TO MAKE IT WORK.</string>
<string name="not_again_rematch_two_only">REMATCH IS LIMITED TO
TWO-PERSON GAMES, AT LEAST FOR NOW, BECAUSE IT\'S HARDER WITH MORE
DEVICES AND I THINK IT\'S RARE THAT PEOPLE PLAY WITH MORE THAN
TWO. LET ME KNOW IF I\'M WRONG AND I\'LL UP THE PRIORITY.</string>
<string name="enable_relay_toself_title">ENABLE RELAY INVITES TO SELF</string>
<string name="enable_relay_toself_summary">(TO AID TESTING AND DEBUGGING)</string>
<!-- Shown after "resend messages" menuitem chosen -->

View file

@ -595,6 +595,7 @@ public class BTService extends XWService {
CommsAddrRec addr = new CommsAddrRec( host.getName(),
host.getAddress() );
boolean[] isLocalP = new boolean[1];
for ( long rowid : rowids ) {
boolean consumed =
BoardDelegate.feedMessage( rowid, buffer, addr );
@ -603,10 +604,12 @@ public class BTService extends XWService {
new GameUtils.BackMoveResult();
if ( GameUtils.feedMessage( BTService.this, rowid,
buffer, addr,
m_btMsgSink, bmr ) ) {
m_btMsgSink, bmr,
isLocalP ) ) {
consumed = true;
GameUtils.postMoveNotification( BTService.this,
rowid, bmr );
rowid, bmr,
isLocalP[0] );
}
}
if ( !consumed ) {

View file

@ -875,7 +875,8 @@ public class GameUtils {
public static boolean feedMessages( Context context, long rowid,
byte[][] msgs, CommsAddrRec ret,
MultiMsgSink sink, BackMoveResult bmr )
MultiMsgSink sink, BackMoveResult bmr,
boolean[] isLocalOut )
{
boolean draw = false;
Assert.assertTrue( -1 != rowid );
@ -920,7 +921,12 @@ public class GameUtils {
}
saveGame( context, gamePtr, gi, lock, false );
summarizeAndClose( context, lock, gamePtr, gi );
GameSummary summary = summarizeAndClose( context, lock,
gamePtr, gi );
if ( null != isLocalOut ) {
isLocalOut[0] = 0 <= summary.turn
&& gi.players[summary.turn].isLocal;
}
int flags = setFromFeedImpl( feedImpl );
if ( GameSummary.MSG_FLAGS_NONE != flags ) {
@ -937,12 +943,12 @@ public class GameUtils {
public static boolean feedMessage( Context context, long rowid, byte[] msg,
CommsAddrRec ret, MultiMsgSink sink,
BackMoveResult bmr )
BackMoveResult bmr, boolean[] isLocalOut )
{
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != rowid );
byte[][] msgs = new byte[1][];
msgs[0] = msg;
return feedMessages( context, rowid, msgs, ret, sink, bmr );
return feedMessages( context, rowid, msgs, ret, sink, bmr, isLocalOut );
}
// This *must* involve a reset if the language is changing!!!
@ -1079,7 +1085,8 @@ public class GameUtils {
}
public static void postMoveNotification( Context context, long rowid,
BackMoveResult bmr )
BackMoveResult bmr,
boolean isTurnNow )
{
if ( null != bmr ) {
Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
@ -1095,8 +1102,12 @@ public class GameUtils {
msg = bmr.m_chat;
}
} else if ( null != bmr.m_lmi ) {
titleID = R.string.notify_title_fmt;
msg = bmr.m_lmi.format( context ); // NPE
if ( isTurnNow ) {
titleID = R.string.notify_title_turn_fmt;
} else {
titleID = R.string.notify_title_fmt;
}
msg = bmr.m_lmi.format( context );
}
if ( 0 != titleID ) {

View file

@ -452,7 +452,8 @@ public class RelayService extends XWService
startService( this ); // bad name: will *stop* threads too
}
private void setupNotifications( String[] relayIDs, BackMoveResult[] bmrs )
private void setupNotifications( String[] relayIDs, BackMoveResult[] bmrs,
ArrayList<Boolean> locals )
{
for ( int ii = 0; ii < relayIDs.length; ++ii ) {
String relayID = relayIDs[ii];
@ -460,7 +461,8 @@ public class RelayService extends XWService
long[] rowids = DBUtils.getRowIDsFor( this, relayID );
if ( null != rowids ) {
for ( long rowid : rowids ) {
GameUtils.postMoveNotification( this, rowid, bmr );
GameUtils.postMoveNotification( this, rowid, bmr,
locals.get(ii) );
}
}
}
@ -993,9 +995,10 @@ public class RelayService extends XWService
RelayMsgSink sink = new RelayMsgSink();
sink.setRowID( rowid );
BackMoveResult bmr = new BackMoveResult();
boolean[] isLocalP = new boolean[1];
if ( GameUtils.feedMessage( this, rowid, msg, s_addr,
sink, bmr ) ) {
GameUtils.postMoveNotification( this, rowid, bmr );
sink, bmr, isLocalP ) ) {
GameUtils.postMoveNotification( this, rowid, bmr, isLocalP[0] );
} else {
DbgUtils.logdf( "feedMessage(): background dropped it" );
}
@ -1018,9 +1021,11 @@ public class RelayService extends XWService
RelayMsgSink sink = new RelayMsgSink();
int nameCount = relayIDs.length;
ArrayList<String> idsWMsgs = new ArrayList<String>( nameCount );
ArrayList<Boolean> isLocals = new ArrayList<Boolean>( nameCount );
ArrayList<BackMoveResult> bmrs =
new ArrayList<BackMoveResult>( nameCount );
boolean[] isLocalP = new boolean[1];
for ( int ii = 0; ii < nameCount; ++ii ) {
byte[][] forOne = msgs[ii];
@ -1028,12 +1033,15 @@ public class RelayService extends XWService
if ( null != forOne ) {
BackMoveResult bmr = new BackMoveResult();
sink.setRowID( rowIDs[ii] );
// since BoardDelegate.feedMessages can't know:
isLocalP[0] = false;
if ( BoardDelegate.feedMessages( rowIDs[ii], forOne, s_addr )
|| GameUtils.feedMessages( this, rowIDs[ii],
forOne, s_addr,
sink, bmr ) ) {
sink, bmr, isLocalP ) ) {
idsWMsgs.add( relayIDs[ii] );
bmrs.add( bmr );
isLocals.add( isLocalP[0] );
} else {
DbgUtils.logf( "RelayService.process(): message for %s (rowid %d)"
+ " not consumed", relayIDs[ii], rowIDs[ii] );
@ -1045,7 +1053,7 @@ public class RelayService extends XWService
idsWMsgs.toArray( tmp );
BackMoveResult[] bmrsa = new BackMoveResult[bmrs.size()];
bmrs.toArray( bmrsa );
setupNotifications( tmp, bmrsa );
setupNotifications( tmp, bmrsa, isLocals );
}
sink.send( this );
}

View file

@ -718,6 +718,7 @@ public class SMSService extends XWService {
if ( null == rowids || 0 == rowids.length ) {
sendDiedPacket( addr.sms_phone, gameID );
} else {
boolean[] isLocalP = new boolean[1];
for ( long rowid : rowids ) {
if ( BoardDelegate.feedMessage( rowid, msg, addr ) ) {
// do nothing
@ -725,8 +726,9 @@ public class SMSService extends XWService {
SMSMsgSink sink = new SMSMsgSink( this );
BackMoveResult bmr = new BackMoveResult();
if ( GameUtils.feedMessage( this, rowid, msg, addr,
sink, bmr ) ) {
GameUtils.postMoveNotification( this, rowid, bmr );
sink, bmr, isLocalP ) ) {
GameUtils.postMoveNotification( this, rowid, bmr,
isLocalP[0] );
}
}
}