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 <string name="bt_bad_proto_fmt">Crosswords on %1$s wrong version for
Bluetooth play.</string> 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> <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 <string name="bt_bad_proto_fmt">Sdrowssorc no %1$s gnorw noisrev rof
Htooteulb yalp.</string> 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> <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 <string name="bt_bad_proto_fmt">CROSSWORDS ON %1$s WRONG VERSION FOR
BLUETOOTH PLAY.</string> 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> <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. * rights reserved.
* *
* This program is free software; you can redistribute it and/or * 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.MultiService.MultiEvent;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.LastMoveInfo;
import org.eehouse.android.xw4.loc.LocUtils; import org.eehouse.android.xw4.loc.LocUtils;
import junit.framework.Assert; import junit.framework.Assert;
@ -483,16 +484,19 @@ public class BTService extends XWService {
host.getAddress() ); host.getAddress() );
for ( long rowid : rowids ) { for ( long rowid : rowids ) {
if ( BoardDelegate.feedMessage( gameID, buffer, addr ) ) { boolean consumed =
// do nothing BoardDelegate.feedMessage( gameID, buffer, addr );
} else if ( haveGame && if ( !consumed && haveGame ) {
GameUtils.feedMessage( BTService.this, rowid, LastMoveInfo lmi = new LastMoveInfo();
buffer, addr, if ( GameUtils.feedMessage( BTService.this, rowid,
m_btMsgSink, null ) ) { buffer, addr,
postNotification( gameID, R.string.new_btmove_title, m_btMsgSink, lmi ) ) {
R.string.new_move_body, rowid ); consumed = true;
// do nothing GameUtils.postMoveNotification( BTService.this,
} else { rowid, lmi );
}
}
if ( !consumed ) {
DbgUtils.logf( "nobody took msg for gameID %X", DbgUtils.logf( "nobody took msg for gameID %X",
gameID ); gameID );
} }
@ -962,12 +966,6 @@ public class BTService extends XWService {
return dos; 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, private void postNotification( int gameID, int title, String body,
long rowid ) long rowid )
{ {

View file

@ -952,6 +952,19 @@ public class GameUtils {
return rint; 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, private static void tellDied( Context context, GameLock lock,
boolean informNow ) boolean informNow )
{ {

View file

@ -374,24 +374,12 @@ public class RelayService extends XWService
long[] rowids = DBUtils.getRowIDsFor( this, relayID ); long[] rowids = DBUtils.getRowIDsFor( this, relayID );
if ( null != rowids ) { if ( null != rowids ) {
for ( long rowid : 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() private boolean startFetchThreadIf()
{ {
// DbgUtils.logf( "startFetchThreadIf()" ); // DbgUtils.logf( "startFetchThreadIf()" );
@ -870,7 +858,7 @@ public class RelayService extends XWService
LastMoveInfo lmi = new LastMoveInfo(); LastMoveInfo lmi = new LastMoveInfo();
if ( GameUtils.feedMessage( this, rowid, msg, null, if ( GameUtils.feedMessage( this, rowid, msg, null,
sink, lmi ) ) { sink, lmi ) ) {
setupNotification( rowid, lmi ); GameUtils.postMoveNotification( this, rowid, lmi );
} else { } else {
DbgUtils.logf( "feedMessage(): background dropped it" ); DbgUtils.logf( "feedMessage(): background dropped it" );
} }