mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-02 20:46:15 +01:00
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:
parent
00e6a80fb0
commit
4a28da1348
7 changed files with 59 additions and 32 deletions
|
@ -1462,6 +1462,7 @@
|
||||||
device, and the body that appears when you pull the notifications
|
device, and the body that appears when you pull the notifications
|
||||||
down. -->
|
down. -->
|
||||||
<string name="notify_title_fmt">Move in game %1$s</string>
|
<string name="notify_title_fmt">Move in game %1$s</string>
|
||||||
|
<string name="notify_chat_title_fmt">Chat message in game %1$s</string>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
############################################################
|
############################################################
|
||||||
|
|
|
@ -1255,6 +1255,7 @@
|
||||||
device, and the body that appears when you pull the notifications
|
device, and the body that appears when you pull the notifications
|
||||||
down. -->
|
down. -->
|
||||||
<string name="notify_title_fmt">Evom ni emag %1$s</string>
|
<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
|
# Dialogs
|
||||||
|
|
|
@ -1255,6 +1255,7 @@
|
||||||
device, and the body that appears when you pull the notifications
|
device, and the body that appears when you pull the notifications
|
||||||
down. -->
|
down. -->
|
||||||
<string name="notify_title_fmt">MOVE IN GAME %1$s</string>
|
<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
|
# Dialogs
|
||||||
|
|
|
@ -590,13 +590,14 @@ public class BTService extends XWService {
|
||||||
boolean consumed =
|
boolean consumed =
|
||||||
BoardDelegate.feedMessage( rowid, buffer, addr );
|
BoardDelegate.feedMessage( rowid, buffer, addr );
|
||||||
if ( !consumed && haveGame ) {
|
if ( !consumed && haveGame ) {
|
||||||
LastMoveInfo lmi = new LastMoveInfo();
|
GameUtils.BackMoveResult bmr =
|
||||||
|
new GameUtils.BackMoveResult();
|
||||||
if ( GameUtils.feedMessage( BTService.this, rowid,
|
if ( GameUtils.feedMessage( BTService.this, rowid,
|
||||||
buffer, addr,
|
buffer, addr,
|
||||||
m_btMsgSink, lmi ) ) {
|
m_btMsgSink, bmr ) ) {
|
||||||
consumed = true;
|
consumed = true;
|
||||||
GameUtils.postMoveNotification( BTService.this,
|
GameUtils.postMoveNotification( BTService.this,
|
||||||
rowid, lmi );
|
rowid, bmr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( !consumed ) {
|
if ( !consumed ) {
|
||||||
|
|
|
@ -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();
|
private static Object s_syncObj = new Object();
|
||||||
|
|
||||||
public static byte[] savedGame( Context context, long rowid )
|
public static byte[] savedGame( Context context, long rowid )
|
||||||
|
@ -811,6 +816,7 @@ public class GameUtils {
|
||||||
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
private static class FeedUtilsImpl extends UtilCtxtImpl {
|
||||||
private Context m_context;
|
private Context m_context;
|
||||||
private long m_rowid;
|
private long m_rowid;
|
||||||
|
public String m_chat;
|
||||||
public boolean m_gotMsg;
|
public boolean m_gotMsg;
|
||||||
public boolean m_gotChat;
|
public boolean m_gotChat;
|
||||||
public boolean m_gameOver;
|
public boolean m_gameOver;
|
||||||
|
@ -827,6 +833,7 @@ public class GameUtils {
|
||||||
{
|
{
|
||||||
DBUtils.appendChatHistory( m_context, m_rowid, msg, false );
|
DBUtils.appendChatHistory( m_context, m_rowid, msg, false );
|
||||||
m_gotChat = true;
|
m_gotChat = true;
|
||||||
|
m_chat = msg;
|
||||||
}
|
}
|
||||||
public void turnChanged( int newTurn )
|
public void turnChanged( int newTurn )
|
||||||
{
|
{
|
||||||
|
@ -841,7 +848,7 @@ public class GameUtils {
|
||||||
|
|
||||||
public static boolean feedMessages( Context context, long rowid,
|
public static boolean feedMessages( Context context, long rowid,
|
||||||
byte[][] msgs, CommsAddrRec ret,
|
byte[][] msgs, CommsAddrRec ret,
|
||||||
MultiMsgSink sink, LastMoveInfo lmi )
|
MultiMsgSink sink, BackMoveResult bmr )
|
||||||
{
|
{
|
||||||
boolean draw = false;
|
boolean draw = false;
|
||||||
Assert.assertTrue( -1 != rowid );
|
Assert.assertTrue( -1 != rowid );
|
||||||
|
@ -874,8 +881,14 @@ public class GameUtils {
|
||||||
DBUtils.saveThumbnail( context, lock, bitmap );
|
DBUtils.saveThumbnail( context, lock, bitmap );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( null != 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 );
|
XwJNI.model_getPlayersLastScore( gamePtr, -1, lmi );
|
||||||
|
bmr.m_lmi = lmi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGame( context, gamePtr, gi, lock, false );
|
saveGame( context, gamePtr, gi, lock, false );
|
||||||
|
@ -895,12 +908,12 @@ public class GameUtils {
|
||||||
|
|
||||||
public static boolean feedMessage( Context context, long rowid, byte[] msg,
|
public static boolean feedMessage( Context context, long rowid, byte[] msg,
|
||||||
CommsAddrRec ret, MultiMsgSink sink,
|
CommsAddrRec ret, MultiMsgSink sink,
|
||||||
LastMoveInfo lmi )
|
BackMoveResult bmr )
|
||||||
{
|
{
|
||||||
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != rowid );
|
Assert.assertTrue( DBUtils.ROWID_NOTFOUND != rowid );
|
||||||
byte[][] msgs = new byte[1][];
|
byte[][] msgs = new byte[1][];
|
||||||
msgs[0] = msg;
|
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!!!
|
// 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,
|
public static void postMoveNotification( Context context, long rowid,
|
||||||
LastMoveInfo lmi )
|
BackMoveResult bmr )
|
||||||
{
|
{
|
||||||
if ( null != lmi ) {
|
if ( null != bmr ) {
|
||||||
Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
|
Intent intent = GamesListDelegate.makeRowidIntent( context, rowid );
|
||||||
String msg = lmi.format( context );
|
String msg;
|
||||||
String title =
|
int titleID;
|
||||||
LocUtils.getString( context, R.string.notify_title_fmt,
|
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 ) );
|
getName( context, rowid ) );
|
||||||
Utils.postNotification( context, intent, title, msg, (int)rowid );
|
Utils.postNotification( context, intent, title, msg, (int)rowid );
|
||||||
} else {
|
} else {
|
||||||
DbgUtils.logf( "postMoveNotification(): posting nothing for lack"
|
DbgUtils.logdf( "postMoveNotification(): posting nothing for lack"
|
||||||
+ " of lmi" );
|
+ " of brm" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
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;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.jni.GameSummary;
|
import org.eehouse.android.xw4.jni.GameSummary;
|
||||||
|
@ -384,15 +385,15 @@ public class RelayService extends XWService
|
||||||
startService( this ); // bad name: will *stop* threads too
|
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 ) {
|
for ( int ii = 0; ii < relayIDs.length; ++ii ) {
|
||||||
String relayID = relayIDs[ii];
|
String relayID = relayIDs[ii];
|
||||||
LastMoveInfo lmi = lmis[ii];
|
BackMoveResult bmr = bmrs[ii];
|
||||||
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 ) {
|
||||||
GameUtils.postMoveNotification( this, rowid, lmi );
|
GameUtils.postMoveNotification( this, rowid, bmr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -902,10 +903,10 @@ public class RelayService extends XWService
|
||||||
} else {
|
} else {
|
||||||
RelayMsgSink sink = new RelayMsgSink();
|
RelayMsgSink sink = new RelayMsgSink();
|
||||||
sink.setRowID( rowid );
|
sink.setRowID( rowid );
|
||||||
LastMoveInfo lmi = new LastMoveInfo();
|
BackMoveResult bmr = new BackMoveResult();
|
||||||
if ( GameUtils.feedMessage( this, rowid, msg, s_addr,
|
if ( GameUtils.feedMessage( this, rowid, msg, s_addr,
|
||||||
sink, lmi ) ) {
|
sink, bmr ) ) {
|
||||||
GameUtils.postMoveNotification( this, rowid, lmi );
|
GameUtils.postMoveNotification( this, rowid, bmr );
|
||||||
} else {
|
} else {
|
||||||
DbgUtils.logf( "feedMessage(): background dropped it" );
|
DbgUtils.logf( "feedMessage(): background dropped it" );
|
||||||
}
|
}
|
||||||
|
@ -930,21 +931,22 @@ public class RelayService extends XWService
|
||||||
int nameCount = relayIDs.length;
|
int nameCount = relayIDs.length;
|
||||||
DbgUtils.logf( "RelayService.process(): nameCount: %d", nameCount );
|
DbgUtils.logf( "RelayService.process(): nameCount: %d", nameCount );
|
||||||
ArrayList<String> idsWMsgs = new ArrayList<String>( 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 ) {
|
for ( int ii = 0; ii < nameCount; ++ii ) {
|
||||||
byte[][] forOne = msgs[ii];
|
byte[][] forOne = msgs[ii];
|
||||||
|
|
||||||
// if game has messages, open it and feed 'em to it.
|
// if game has messages, open it and feed 'em to it.
|
||||||
if ( null != forOne ) {
|
if ( null != forOne ) {
|
||||||
LastMoveInfo lmi = new LastMoveInfo();
|
BackMoveResult bmr = new BackMoveResult();
|
||||||
sink.setRowID( rowIDs[ii] );
|
sink.setRowID( rowIDs[ii] );
|
||||||
if ( BoardDelegate.feedMessages( rowIDs[ii], forOne, s_addr )
|
if ( BoardDelegate.feedMessages( rowIDs[ii], forOne, s_addr )
|
||||||
|| GameUtils.feedMessages( this, rowIDs[ii],
|
|| GameUtils.feedMessages( this, rowIDs[ii],
|
||||||
forOne, s_addr,
|
forOne, s_addr,
|
||||||
sink, lmi ) ) {
|
sink, bmr ) ) {
|
||||||
idsWMsgs.add( relayIDs[ii] );
|
idsWMsgs.add( relayIDs[ii] );
|
||||||
lmis.add( lmi );
|
bmrs.add( bmr );
|
||||||
} else {
|
} else {
|
||||||
DbgUtils.logf( "message for %s (rowid %d) not consumed",
|
DbgUtils.logf( "message for %s (rowid %d) not consumed",
|
||||||
relayIDs[ii], rowIDs[ii] );
|
relayIDs[ii], rowIDs[ii] );
|
||||||
|
@ -954,9 +956,9 @@ public class RelayService extends XWService
|
||||||
if ( 0 < idsWMsgs.size() ) {
|
if ( 0 < idsWMsgs.size() ) {
|
||||||
String[] tmp = new String[idsWMsgs.size()];
|
String[] tmp = new String[idsWMsgs.size()];
|
||||||
idsWMsgs.toArray( tmp );
|
idsWMsgs.toArray( tmp );
|
||||||
LastMoveInfo[] lmisa = new LastMoveInfo[lmis.size()];
|
BackMoveResult[] bmrsa = new BackMoveResult[bmrs.size()];
|
||||||
lmis.toArray( lmisa );
|
bmrs.toArray( bmrsa );
|
||||||
setupNotifications( tmp, lmisa );
|
setupNotifications( tmp, bmrsa );
|
||||||
}
|
}
|
||||||
sink.send( this );
|
sink.send( this );
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.GameUtils.BackMoveResult;
|
||||||
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;
|
||||||
|
@ -734,10 +735,10 @@ public class SMSService extends XWService {
|
||||||
// do nothing
|
// do nothing
|
||||||
} else {
|
} else {
|
||||||
SMSMsgSink sink = new SMSMsgSink( this );
|
SMSMsgSink sink = new SMSMsgSink( this );
|
||||||
LastMoveInfo lmi = new LastMoveInfo();
|
BackMoveResult bmr = new BackMoveResult();
|
||||||
if ( GameUtils.feedMessage( this, rowid, msg, addr,
|
if ( GameUtils.feedMessage( this, rowid, msg, addr,
|
||||||
sink, lmi ) ) {
|
sink, bmr ) ) {
|
||||||
GameUtils.postMoveNotification( this, rowid, lmi );
|
GameUtils.postMoveNotification( this, rowid, bmr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue