save into DB rather than drop chat messages received in background.

Still need to add UI to let user know a new message is there.
This commit is contained in:
Andy2 2011-02-16 07:37:14 -08:00
parent a954977e56
commit 0c9b053844
2 changed files with 38 additions and 1 deletions

View file

@ -129,6 +129,13 @@ public class GameUtils {
public static void loadMakeGame( Context context, int gamePtr, public static void loadMakeGame( Context context, int gamePtr,
CurGameInfo gi, String path ) CurGameInfo gi, String path )
{
loadMakeGame( context, gamePtr, gi, null, path );
}
public static void loadMakeGame( Context context, int gamePtr,
CurGameInfo gi, UtilCtxt util,
String path )
{ {
byte[] stream = savedGame( context, path ); byte[] stream = savedGame( context, path );
XwJNI.gi_from_stream( gi, stream ); XwJNI.gi_from_stream( gi, stream );
@ -137,6 +144,7 @@ public class GameUtils {
boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream, boolean madeGame = XwJNI.game_makeFromStream( gamePtr, stream,
JNIUtilsImpl.get(), gi, JNIUtilsImpl.get(), gi,
dictBytes, gi.dictName, dictBytes, gi.dictName,
util,
CommonPrefs.get(context)); CommonPrefs.get(context));
if ( !madeGame ) { if ( !madeGame ) {
XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(), XwJNI.game_makeNewGame( gamePtr, gi, JNIUtilsImpl.get(),
@ -361,6 +369,21 @@ public class GameUtils {
activity.finish(); activity.finish();
} }
private static class FeedUtilsImpl extends UtilCtxtImpl {
private Context m_context;
private String m_path;
public FeedUtilsImpl( Context context, String path )
{
m_context = context;
m_path = path;
}
public void showChat( String msg )
{
DBUtils.appendChatHistory( m_context, m_path, msg, false );
}
}
public static boolean feedMessages( Context context, String relayID, public static boolean feedMessages( Context context, String relayID,
byte[][] msgs ) byte[][] msgs )
{ {
@ -369,7 +392,9 @@ public class GameUtils {
if ( null != path ) { if ( null != path ) {
int gamePtr = XwJNI.initJNI(); int gamePtr = XwJNI.initJNI();
CurGameInfo gi = new CurGameInfo( context ); CurGameInfo gi = new CurGameInfo( context );
loadMakeGame( context, gamePtr, gi, path ); loadMakeGame( context, gamePtr, gi,
new FeedUtilsImpl(context, path),
path );
for ( byte[] msg : msgs ) { for ( byte[] msg : msgs ) {
draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw; draw = XwJNI.game_receiveMessage( gamePtr, msg ) || draw;

View file

@ -93,6 +93,18 @@ public class XwJNI {
(TransportProcs)null ); (TransportProcs)null );
} }
public static boolean game_makeFromStream( int gamePtr,
byte[] stream,
JNIUtils jniu,
CurGameInfo gi,
byte[] dict, String dictName,
UtilCtxt util,
CommonPrefs cp ) {
return game_makeFromStream( gamePtr, stream, gi, dict, dictName,
util, jniu, (DrawCtx)null, cp,
(TransportProcs)null );
}
public static native boolean game_receiveMessage( int gamePtr, public static native boolean game_receiveMessage( int gamePtr,
byte[] stream ); byte[] stream );
public static native void game_summarize( int gamePtr, GameSummary summary ); public static native void game_summarize( int gamePtr, GameSummary summary );