Show specific notification on receipt of chat, not rehash of last move

played.

Conflicts:
	xwords4/android/XWords4/archive/R.java
	xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java
This commit is contained in:
Eric House 2015-08-11 06:50:16 -07:00
parent 00e6a80fb0
commit 4a28da1348
7 changed files with 59 additions and 32 deletions

View file

@ -1462,6 +1462,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_chat_title_fmt">Chat message in game %1$s</string>
<!--
############################################################

View file

@ -1255,6 +1255,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_chat_title_fmt">Tahc egassem ni emag %1$s</string>
<!--
############################################################
# Dialogs

View file

@ -1255,6 +1255,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_chat_title_fmt">CHAT MESSAGE IN GAME %1$s</string>
<!--
############################################################
# Dialogs

View file

@ -590,13 +590,14 @@ public class BTService extends XWService {
boolean consumed =
BoardDelegate.feedMessage( rowid, buffer, addr );
if ( !consumed && haveGame ) {
LastMoveInfo lmi = new LastMoveInfo();
GameUtils.BackMoveResult bmr =
new GameUtils.BackMoveResult();
if ( GameUtils.feedMessage( BTService.this, rowid,
buffer, addr,
m_btMsgSink, lmi ) ) {
m_btMsgSink, bmr ) ) {
consumed = true;
GameUtils.postMoveNotification( BTService.this,
rowid, lmi );
rowid, bmr );
}
}
if ( !consumed ) {

View file

@ -70,6 +70,11 @@ public class GameUtils {
}
}
public static class BackMoveResult {
LastMoveInfo m_lmi; // instantiated on demand
String m_chat;
}
private static Object s_syncObj = new Object();
public static byte[] savedGame( Context context, long rowid )
@ -811,6 +816,7 @@ public class GameUtils {
private static class FeedUtilsImpl extends UtilCtxtImpl {
private Context m_context;
private long m_rowid;
public String m_chat;
public boolean m_gotMsg;
public boolean m_gotChat;
public boolean m_gameOver;
@ -827,6 +833,7 @@ public class GameUtils {
{
DBUtils.appendChatHistory( m_context, m_rowid, msg, false );
m_gotChat = true;
m_chat = msg;
}
public void turnChanged( int newTurn )
{
@ -841,7 +848,7 @@ public class GameUtils {
public static boolean feedMessages( Context context, long rowid,
byte[][] msgs, CommsAddrRec ret,
MultiMsgSink sink, LastMoveInfo lmi )
MultiMsgSink sink, BackMoveResult bmr )
{
boolean draw = false;
Assert.assertTrue( -1 != rowid );
@ -874,8 +881,14 @@ public class GameUtils {
DBUtils.saveThumbnail( context, lock, bitmap );
}
if ( null != lmi ) {
XwJNI.model_getPlayersLastScore( gamePtr, -1, lmi );
if ( null != bmr ) {
if ( null != feedImpl.m_chat ) {
bmr.m_chat = feedImpl.m_chat;
} else {
LastMoveInfo lmi = new LastMoveInfo();
XwJNI.model_getPlayersLastScore( gamePtr, -1, lmi );
bmr.m_lmi = lmi;
}
}
saveGame( context, gamePtr, gi, lock, false );
@ -895,12 +908,12 @@ public class GameUtils {
public static boolean feedMessage( Context context, long rowid, byte[] msg,
CommsAddrRec ret, MultiMsgSink sink,
LastMoveInfo lmi )
BackMoveResult bmr )
{
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != rowid );
byte[][] msgs = new byte[1][];
msgs[0] = msg;
return feedMessages( context, rowid, msgs, ret, sink, lmi );
return feedMessages( context, rowid, msgs, ret, sink, bmr );
}
// This *must* involve a reset if the language is changing!!!
@ -1041,18 +1054,25 @@ public class GameUtils {
}
public static void postMoveNotification( Context context, long rowid,
LastMoveInfo lmi )
BackMoveResult bmr )
{
if ( null != lmi ) {
if ( null != bmr ) {
Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
String msg = lmi.format( context );
String title =
LocUtils.getString( context, R.string.notify_title_fmt,
getName( context, rowid ) );
String msg;
int titleID;
if ( null != bmr.m_chat ) {
titleID = R.string.notify_chat_title_fmt;
msg = "\"" + bmr.m_chat + "\"";
} else {
titleID = R.string.notify_title_fmt;
msg = bmr.m_lmi.format( context );
}
String title = LocUtils.getString( context, titleID,
getName( context, rowid ) );
Utils.postNotification( context, intent, title, msg, (int)rowid );
} else {
DbgUtils.logf( "postMoveNotification(): posting nothing for lack"
+ " of lmi" );
DbgUtils.logdf( "postMoveNotification(): posting nothing for lack"
+ " of brm" );
}
}

View file

@ -46,6 +46,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import junit.framework.Assert;
import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.GameUtils.BackMoveResult;
import org.eehouse.android.xw4.jni.CommsAddrRec;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.GameSummary;
@ -384,15 +385,15 @@ public class RelayService extends XWService
startService( this ); // bad name: will *stop* threads too
}
private void setupNotifications( String[] relayIDs, LastMoveInfo[] lmis )
private void setupNotifications( String[] relayIDs, BackMoveResult[] bmrs )
{
for ( int ii = 0; ii < relayIDs.length; ++ii ) {
String relayID = relayIDs[ii];
LastMoveInfo lmi = lmis[ii];
BackMoveResult bmr = bmrs[ii];
long[] rowids = DBUtils.getRowIDsFor( this, relayID );
if ( null != rowids ) {
for ( long rowid : rowids ) {
GameUtils.postMoveNotification( this, rowid, lmi );
GameUtils.postMoveNotification( this, rowid, bmr );
}
}
}
@ -902,10 +903,10 @@ public class RelayService extends XWService
} else {
RelayMsgSink sink = new RelayMsgSink();
sink.setRowID( rowid );
LastMoveInfo lmi = new LastMoveInfo();
BackMoveResult bmr = new BackMoveResult();
if ( GameUtils.feedMessage( this, rowid, msg, s_addr,
sink, lmi ) ) {
GameUtils.postMoveNotification( this, rowid, lmi );
sink, bmr ) ) {
GameUtils.postMoveNotification( this, rowid, bmr );
} else {
DbgUtils.logf( "feedMessage(): background dropped it" );
}
@ -930,21 +931,22 @@ public class RelayService extends XWService
int nameCount = relayIDs.length;
DbgUtils.logf( "RelayService.process(): nameCount: %d", nameCount );
ArrayList<String> idsWMsgs = new ArrayList<String>( nameCount );
ArrayList<LastMoveInfo> lmis = new ArrayList<LastMoveInfo>( nameCount );
ArrayList<BackMoveResult> bmrs =
new ArrayList<BackMoveResult>( nameCount );
for ( int ii = 0; ii < nameCount; ++ii ) {
byte[][] forOne = msgs[ii];
// if game has messages, open it and feed 'em to it.
if ( null != forOne ) {
LastMoveInfo lmi = new LastMoveInfo();
BackMoveResult bmr = new BackMoveResult();
sink.setRowID( rowIDs[ii] );
if ( BoardDelegate.feedMessages( rowIDs[ii], forOne, s_addr )
|| GameUtils.feedMessages( this, rowIDs[ii],
forOne, s_addr,
sink, lmi ) ) {
sink, bmr ) ) {
idsWMsgs.add( relayIDs[ii] );
lmis.add( lmi );
bmrs.add( bmr );
} else {
DbgUtils.logf( "message for %s (rowid %d) not consumed",
relayIDs[ii], rowIDs[ii] );
@ -954,9 +956,9 @@ public class RelayService extends XWService
if ( 0 < idsWMsgs.size() ) {
String[] tmp = new String[idsWMsgs.size()];
idsWMsgs.toArray( tmp );
LastMoveInfo[] lmisa = new LastMoveInfo[lmis.size()];
lmis.toArray( lmisa );
setupNotifications( tmp, lmisa );
BackMoveResult[] bmrsa = new BackMoveResult[bmrs.size()];
bmrs.toArray( bmrsa );
setupNotifications( tmp, bmrsa );
}
sink.send( this );
}

View file

@ -55,6 +55,7 @@ import java.util.Set;
import junit.framework.Assert;
import org.eehouse.android.xw4.GameUtils.BackMoveResult;
import org.eehouse.android.xw4.MultiService.MultiEvent;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec;
@ -734,10 +735,10 @@ public class SMSService extends XWService {
// do nothing
} else {
SMSMsgSink sink = new SMSMsgSink( this );
LastMoveInfo lmi = new LastMoveInfo();
BackMoveResult bmr = new BackMoveResult();
if ( GameUtils.feedMessage( this, rowid, msg, addr,
sink, lmi ) ) {
GameUtils.postMoveNotification( this, rowid, lmi );
sink, bmr ) ) {
GameUtils.postMoveNotification( this, rowid, bmr );
}
}
}