mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
Show specific notification on receipt of chat, not rehash of last move
played.
This commit is contained in:
parent
265ac48b88
commit
5853b0c5c6
8 changed files with 776 additions and 723 deletions
File diff suppressed because it is too large
Load diff
|
@ -1463,6 +1463,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>
|
||||
|
||||
<!--
|
||||
############################################################
|
||||
|
|
|
@ -1256,6 +1256,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
|
||||
|
|
|
@ -1256,6 +1256,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
|
||||
|
|
|
@ -603,13 +603,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 ) {
|
||||
|
|
|
@ -69,6 +69,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 )
|
||||
|
@ -846,6 +851,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;
|
||||
|
@ -862,6 +868,7 @@ public class GameUtils {
|
|||
{
|
||||
DBUtils.appendChatHistory( m_context, m_rowid, msg, false );
|
||||
m_gotChat = true;
|
||||
m_chat = msg;
|
||||
}
|
||||
public void turnChanged( int newTurn )
|
||||
{
|
||||
|
@ -876,7 +883,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 );
|
||||
|
@ -909,8 +916,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 );
|
||||
|
@ -930,12 +943,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!!!
|
||||
|
@ -1079,18 +1092,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" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import junit.framework.Assert;
|
|||
|
||||
import org.eehouse.android.xw4.MultiService.DictFetchOwner;
|
||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||
import org.eehouse.android.xw4.GameUtils.BackMoveResult;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
import org.eehouse.android.xw4.jni.GameSummary;
|
||||
|
@ -451,15 +452,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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -991,10 +992,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.logdf( "feedMessage(): background dropped it" );
|
||||
}
|
||||
|
@ -1017,21 +1018,22 @@ public class RelayService extends XWService
|
|||
RelayMsgSink sink = new RelayMsgSink();
|
||||
int nameCount = relayIDs.length;
|
||||
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( "RelayService.process(): message for %s (rowid %d)"
|
||||
+ " not consumed", relayIDs[ii], rowIDs[ii] );
|
||||
|
@ -1041,9 +1043,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 );
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -731,10 +732,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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue