mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
cleanup (and use factored-out updateRow a couple of additional places)
This commit is contained in:
parent
795e05f544
commit
0394579b7c
3 changed files with 35 additions and 64 deletions
|
@ -554,10 +554,9 @@ public class DBUtils {
|
|||
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
|
||||
selection, null, null, null,
|
||||
DBHelper.CREATE_TIME + " DESC" ); // order by
|
||||
while ( cursor.moveToNext() ) {
|
||||
if ( cursor.moveToNext() ) {
|
||||
int indx = cursor.getColumnIndex( DBHelper.CREATE_TIME );
|
||||
result = new Date( cursor.getLong( indx ) );
|
||||
break;
|
||||
}
|
||||
cursor.close();
|
||||
db.close();
|
||||
|
@ -710,34 +709,20 @@ public class DBUtils {
|
|||
{
|
||||
Assert.assertTrue( lock.canWrite() );
|
||||
long rowid = lock.getRowid();
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.SNAPSHOT, bytes );
|
||||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.SNAPSHOT, bytes );
|
||||
|
||||
long timestamp = new Date().getTime();
|
||||
if ( setCreate ) {
|
||||
values.put( DBHelper.CREATE_TIME, timestamp );
|
||||
}
|
||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
if ( 0 == result ) {
|
||||
Assert.fail();
|
||||
// values.put( DBHelper.FILE_NAME, path );
|
||||
// rowid = db.insert( DBHelper.TABLE_NAME_SUM, null, values );
|
||||
// DbgUtils.logf( "insert=>%d", rowid );
|
||||
// Assert.assertTrue( row >= 0 );
|
||||
}
|
||||
db.close();
|
||||
long timestamp = new Date().getTime();
|
||||
if ( setCreate ) {
|
||||
values.put( DBHelper.CREATE_TIME, timestamp );
|
||||
}
|
||||
setCached( rowid, null ); // force reread
|
||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||
|
||||
if ( -1 != rowid ) {
|
||||
updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values );
|
||||
|
||||
setCached( rowid, null ); // force reread
|
||||
if ( -1 != rowid ) { // Is this possible? PENDING
|
||||
notifyListeners( rowid );
|
||||
}
|
||||
return rowid;
|
||||
|
@ -861,23 +846,6 @@ public class DBUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static void updateRow( Context context, String table,
|
||||
long rowid, ContentValues values )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
|
||||
int result = db.update( table, values, selection, null );
|
||||
db.close();
|
||||
if ( 0 == result ) {
|
||||
DbgUtils.logf( "updateRow failed" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getChatHistoryStr( Context context, long rowid )
|
||||
{
|
||||
String result = null;
|
||||
|
@ -1200,25 +1168,14 @@ public class DBUtils {
|
|||
private static void saveChatHistory( Context context, long rowid,
|
||||
String history )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
ContentValues values = new ContentValues();
|
||||
if ( null != history ) {
|
||||
values.put( DBHelper.CHAT_HISTORY, history );
|
||||
} else {
|
||||
values.putNull( DBHelper.CHAT_HISTORY );
|
||||
}
|
||||
|
||||
long timestamp = new Date().getTime();
|
||||
values.put( DBHelper.LASTPLAY_TIME, timestamp );
|
||||
|
||||
int result = db.update( DBHelper.TABLE_NAME_SUM,
|
||||
values, selection, null );
|
||||
db.close();
|
||||
ContentValues values = new ContentValues();
|
||||
if ( null != history ) {
|
||||
values.put( DBHelper.CHAT_HISTORY, history );
|
||||
} else {
|
||||
values.putNull( DBHelper.CHAT_HISTORY );
|
||||
}
|
||||
values.put( DBHelper.LASTPLAY_TIME, new Date().getTime() );
|
||||
updateRow( context, DBHelper.TABLE_NAME_SUM, rowid, values );
|
||||
}
|
||||
|
||||
private static void initDB( Context context )
|
||||
|
@ -1231,6 +1188,23 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static void updateRow( Context context, String table,
|
||||
long rowid, ContentValues values )
|
||||
{
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getWritableDatabase();
|
||||
|
||||
String selection = String.format( ROW_ID_FMT, rowid );
|
||||
|
||||
int result = db.update( table, values, selection, null );
|
||||
db.close();
|
||||
if ( 0 == result ) {
|
||||
DbgUtils.logf( "updateRow failed" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyListeners( long rowid )
|
||||
{
|
||||
synchronized( s_listeners ) {
|
||||
|
|
|
@ -112,9 +112,7 @@ public class RelayService extends Service {
|
|||
if ( 0 < idsWMsgs.size() ) {
|
||||
String[] relayIDs = new String[idsWMsgs.size()];
|
||||
idsWMsgs.toArray( relayIDs );
|
||||
// if ( !DispatchNotify.tryHandle( relayIDs ) ) {
|
||||
setupNotification( relayIDs );
|
||||
// }
|
||||
}
|
||||
sink.send( this );
|
||||
}
|
||||
|
|
|
@ -444,7 +444,6 @@ public class Utils {
|
|||
pm.queryIntentActivities( intent,
|
||||
PackageManager.MATCH_DEFAULT_ONLY );
|
||||
result = 0 < doers.size();
|
||||
DbgUtils.logf( "canInstall()=>%b", result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue