include last move summary in BT notifications

This commit is contained in:
Eric House 2014-09-06 06:47:24 -07:00
parent c1ee254c4f
commit c6a9f303f0
6 changed files with 34 additions and 35 deletions

View file

@ -1859,7 +1859,7 @@
<string name="bt_bad_proto_fmt">Crosswords on %1$s wrong version for
Bluetooth play.</string>
<!-- -->
<string name="new_btmove_title">New move via Bluetooth</string>
<string name="new_btmove_title">Message via Bluetooth</string>
<!-- -->
<string name="new_move_body">One or more moves has arrived</string>
<!-- -->

View file

@ -1596,7 +1596,7 @@
<string name="bt_bad_proto_fmt">Sdrowssorc no %1$s gnorw noisrev rof
Htooteulb yalp.</string>
<!-- -->
<string name="new_btmove_title">Wen evom aiv Htooteulb</string>
<string name="new_btmove_title">Egassem aiv Htooteulb</string>
<!-- -->
<string name="new_move_body">Eno ro erom sevom sah devirra</string>
<!-- -->

View file

@ -1596,7 +1596,7 @@
<string name="bt_bad_proto_fmt">CROSSWORDS ON %1$s WRONG VERSION FOR
BLUETOOTH PLAY.</string>
<!-- -->
<string name="new_btmove_title">NEW MOVE VIA BLUETOOTH</string>
<string name="new_btmove_title">MESSAGE VIA BLUETOOTH</string>
<!-- -->
<string name="new_move_body">ONE OR MORE MOVES HAS ARRIVED</string>
<!-- -->

View file

@ -1,6 +1,6 @@
/* -*- compile-command: "find-and-ant.sh debug install"; -*- */
/* -*- compile-command: "find-and-ant.sh -i debug"; -*- */
/*
* Copyright 2010 - 2012 by Eric House (xwords@eehouse.org). All
* Copyright 2010 - 2014 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit;
import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.LastMoveInfo;
import org.eehouse.android.xw4.loc.LocUtils;
import junit.framework.Assert;
@ -483,16 +484,19 @@ public class BTService extends XWService {
host.getAddress() );
for ( long rowid : rowids ) {
if ( BoardDelegate.feedMessage( gameID, buffer, addr ) ) {
// do nothing
} else if ( haveGame &&
GameUtils.feedMessage( BTService.this, rowid,
buffer, addr,
m_btMsgSink, null ) ) {
postNotification( gameID, R.string.new_btmove_title,
R.string.new_move_body, rowid );
// do nothing
} else {
boolean consumed =
BoardDelegate.feedMessage( gameID, buffer, addr );
if ( !consumed && haveGame ) {
LastMoveInfo lmi = new LastMoveInfo();
if ( GameUtils.feedMessage( BTService.this, rowid,
buffer, addr,
m_btMsgSink, lmi ) ) {
consumed = true;
GameUtils.postMoveNotification( BTService.this,
rowid, lmi );
}
}
if ( !consumed ) {
DbgUtils.logf( "nobody took msg for gameID %X",
gameID );
}
@ -962,12 +966,6 @@ public class BTService extends XWService {
return dos;
}
private void postNotification( int gameID, int title, int body, long rowid )
{
String bstr = LocUtils.getString( this, body );
postNotification( gameID, title, bstr, rowid );
}
private void postNotification( int gameID, int title, String body,
long rowid )
{

View file

@ -952,6 +952,19 @@ public class GameUtils {
return rint;
}
public static void postMoveNotification( Context context, long rowid,
LastMoveInfo lmi )
{
Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
String msg = "";
if ( null != lmi ) {
msg = lmi.format( context );
}
String title = LocUtils.getString( context, R.string.notify_title_fmt,
getName( context, rowid ) );
Utils.postNotification( context, intent, title, msg, (int)rowid );
}
private static void tellDied( Context context, GameLock lock,
boolean informNow )
{

View file

@ -374,24 +374,12 @@ public class RelayService extends XWService
long[] rowids = DBUtils.getRowIDsFor( this, relayID );
if ( null != rowids ) {
for ( long rowid : rowids ) {
setupNotification( rowid, lmi );
GameUtils.postMoveNotification( this, rowid, lmi );
}
}
}
}
private void setupNotification( long rowid, LastMoveInfo lmi )
{
Intent intent = GamesListDelegate.makeRowidIntent( this, rowid );
String msg = "";
if ( null != lmi ) {
msg = lmi.format( this );
}
String title = LocUtils.getString( this, R.string.notify_title_fmt,
GameUtils.getName( this, rowid ) );
Utils.postNotification( this, intent, title, msg, (int)rowid );
}
private boolean startFetchThreadIf()
{
// DbgUtils.logf( "startFetchThreadIf()" );
@ -870,7 +858,7 @@ public class RelayService extends XWService
LastMoveInfo lmi = new LastMoveInfo();
if ( GameUtils.feedMessage( this, rowid, msg, null,
sink, lmi ) ) {
setupNotification( rowid, lmi );
GameUtils.postMoveNotification( this, rowid, lmi );
} else {
DbgUtils.logf( "feedMessage(): background dropped it" );
}