From 04d839868d46c0e4a9aaa8867e8222defa908c3a Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 20 Nov 2012 06:24:23 -0800 Subject: [PATCH] on launch to handle an invite for a game that seems to already exist, instead launch that game -- for better feedback. --- .../src/org/eehouse/android/xw4/DBUtils.java | 18 ++++++++++++------ .../eehouse/android/xw4/DispatchNotify.java | 12 +++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java index 48055402f..8403f65e5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -551,10 +551,12 @@ public class DBUtils { synchronized( s_dbHelper ) { SQLiteDatabase db = s_dbHelper.getReadableDatabase(); String[] columns = { ROW_ID }; - String selection = DBHelper.ROOMNAME + "='" + nli.room + "' AND " - + DBHelper.INVITEID + "='" + nli.inviteID + "' AND " - + DBHelper.DICTLANG + "=" + nli.lang + " AND " - + DBHelper.NUM_PLAYERS + "=" + nli.nPlayers; + String selection = + String.format( "%s='%s' AND %s='%s' AND %s=%d AND %s=%d", + DBHelper.ROOMNAME, nli.room, + DBHelper.INVITEID, nli.inviteID, + DBHelper.DICTLANG, nli.lang, + DBHelper.NUM_PLAYERS, nli.nPlayers ); Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns, selection, null, null, null, null ); if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { @@ -566,10 +568,14 @@ public class DBUtils { return result; } - public static boolean isNewInvite( Context context, Uri data ) + public static long getRowIDForOpen( Context context, Uri data ) { + long rowid = ROWID_NOTFOUND; NetLaunchInfo nli = new NetLaunchInfo( data ); - return null != nli && -1 == getRowIDForOpen( context, nli ); + if ( null != nli ) { + rowid = getRowIDForOpen( context, nli ); + } + return rowid; } public static String[] getRelayIDs( Context context, boolean noMsgs ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java index ab9231174..a82d1addc 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java @@ -29,6 +29,8 @@ import android.os.Bundle; import java.util.HashSet; import junit.framework.Assert; +import org.eehouse.android.xw4.jni.GameSummary; + public class DispatchNotify extends Activity { public static final String RELAYIDS_EXTRA = "relayids"; @@ -63,12 +65,20 @@ public class DispatchNotify extends Activity { mustLaunch = true; } } else if ( null != data ) { - if ( DBUtils.isNewInvite( this, data ) ) { + long rowid = DBUtils.getRowIDForOpen( this, data ); + if ( DBUtils.ROWID_NOTFOUND == rowid ) { if ( !tryHandle( data ) ) { mustLaunch = true; } } else { DbgUtils.logf( "DispatchNotify: dropping duplicate invite" ); + GameSummary summary = DBUtils.getSummary( this, rowid ); + if ( null != summary ) { + gameID = summary.gameID; + if ( !tryHandle( gameID ) ) { + mustLaunch = true; + } + } } }