mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
add msgsPending field set from new DB column; add methods to set
column and to fetch relayIDs for games where it's not set, and to get path for game based on relayID.
This commit is contained in:
parent
d5eff5af21
commit
6ce5f36133
2 changed files with 71 additions and 1 deletions
|
@ -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<String> ids = new ArrayList<String>();
|
||||
|
||||
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 ) {
|
||||
|
|
|
@ -33,4 +33,5 @@ public class GameSummary {
|
|||
// relay-related fields
|
||||
public String roomName;
|
||||
public String relayID;
|
||||
public boolean msgsPending;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue