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 427aa3913..42be6050a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DBUtils.java @@ -26,6 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.Cursor; import java.util.StringTokenizer; import android.content.ContentValues; +import java.util.ArrayList; import junit.framework.Assert; import org.eehouse.android.xw4.jni.*; @@ -45,7 +46,7 @@ public class DBUtils { String[] columns = { DBHelper.NUM_MOVES, DBHelper.GAME_OVER, DBHelper.CONTYPE, DBHelper.ROOMNAME, DBHelper.RELAYID, DBHelper.SMSPHONE, - DBHelper.SCORES + DBHelper.SCORES, DBHelper.HASMSGS }; String selection = DBHelper.FILE_NAME + "=\"" + file + "\""; @@ -89,6 +90,11 @@ public class DBUtils { summary.smsPhone = cursor.getString( col ); } } + + col = cursor.getColumnIndex( DBHelper.HASMSGS ); + if ( col >= 0 ) { + summary.msgsPending = 0 != cursor.getInt( col ); + } } cursor.close(); db.close(); @@ -138,6 +144,69 @@ public class DBUtils { } } + public static void setHasMsgs( String relayID ) + { + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getWritableDatabase(); + + String cmd = String.format( "UPDATE %s SET %s = 1 WHERE %s = '%s'", + DBHelper.TABLE_NAME, DBHelper.HASMSGS, + DBHelper.RELAYID, relayID ); + db.execSQL( cmd ); + db.close(); + } + } + + public static String getPathFor( Context context, String relayID ) + { + String result = null; + initDB( context ); + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + String[] columns = { DBHelper.FILE_NAME }; + String selection = DBHelper.RELAYID + "='" + relayID + "'"; + Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection, + null, null, null, null ); + if ( 1 == cursor.getCount() && cursor.moveToFirst() ) { + result = cursor.getString( cursor + .getColumnIndex(DBHelper.FILE_NAME)); + + } + cursor.close(); + db.close(); + } + return result; + } + + public static String[] getRelayIDNoMsgs( Context context ) + { + initDB( context ); + ArrayList ids = new ArrayList(); + + synchronized( s_dbHelper ) { + SQLiteDatabase db = s_dbHelper.getReadableDatabase(); + String[] columns = { DBHelper.RELAYID }; + String selection = DBHelper.RELAYID + " NOT null AND " + + "NOT " + DBHelper.HASMSGS; + + Cursor cursor = db.query( DBHelper.TABLE_NAME, columns, selection, + null, null, null, null ); + + if ( 0 < cursor.getCount() ) { + cursor.moveToFirst(); + while ( !cursor.isLast() ) { + ids.add( cursor. + getString( cursor. + getColumnIndex(DBHelper.RELAYID)) ); + cursor.moveToNext(); + } + } + cursor.close(); + db.close(); + } + return ids.toArray( new String[ids.size()] ); + } + private static void initDB( Context context ) { if ( null == s_dbHelper ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java index e3200b3f4..4ba5ff970 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/GameSummary.java @@ -33,4 +33,5 @@ public class GameSummary { // relay-related fields public String roomName; public String relayID; + public boolean msgsPending; }