@Test public void shouldGetMostRecentTimestamp() throws Exception { assertThat(whassup.getMostRecentTimestamp(true)).isEqualTo(1369589322298L); assertThat(whassup.getMostRecentTimestamp(false)).isEqualTo(1369589322298L); }
public long getMostRecentTimestamp(boolean ignoreGroups) throws IOException { File currentDB = dbProvider.getDBFile(); if (currentDB == null) { return DEFAULT_MOST_RECENT; } else { SQLiteDatabase db = getSqLiteDatabase(decryptDB(currentDB)); Cursor cursor = null; try { String query = "SELECT MAX(" + TIMESTAMP + ") FROM " + WhatsAppMessage.TABLE; if (ignoreGroups) { query += " WHERE " + KEY_REMOTE_JID + " NOT LIKE ?"; } cursor = db.rawQuery( query, ignoreGroups ? new String[]{ "%@" + WhatsAppMessage.GROUP } : null ); if (cursor != null && cursor.moveToNext()) { return cursor.getLong(0); } else { return DEFAULT_MOST_RECENT; } } catch (SQLiteException e) { Log.w(TAG, e); return DEFAULT_MOST_RECENT; } finally { if (cursor != null) cursor.close(); } } }
Whassup { public long getMostRecentTimestamp(boolean ignoreGroups) throws IOException { File currentDB = dbProvider.getDBFile(); if (currentDB == null) { return DEFAULT_MOST_RECENT; } else { SQLiteDatabase db = getSqLiteDatabase(decryptDB(currentDB)); Cursor cursor = null; try { String query = "SELECT MAX(" + TIMESTAMP + ") FROM " + WhatsAppMessage.TABLE; if (ignoreGroups) { query += " WHERE " + KEY_REMOTE_JID + " NOT LIKE ?"; } cursor = db.rawQuery( query, ignoreGroups ? new String[]{ "%@" + WhatsAppMessage.GROUP } : null ); if (cursor != null && cursor.moveToNext()) { return cursor.getLong(0); } else { return DEFAULT_MOST_RECENT; } } catch (SQLiteException e) { Log.w(TAG, e); return DEFAULT_MOST_RECENT; } finally { if (cursor != null) cursor.close(); } } } }
Whassup { public long getMostRecentTimestamp(boolean ignoreGroups) throws IOException { File currentDB = dbProvider.getDBFile(); if (currentDB == null) { return DEFAULT_MOST_RECENT; } else { SQLiteDatabase db = getSqLiteDatabase(decryptDB(currentDB)); Cursor cursor = null; try { String query = "SELECT MAX(" + TIMESTAMP + ") FROM " + WhatsAppMessage.TABLE; if (ignoreGroups) { query += " WHERE " + KEY_REMOTE_JID + " NOT LIKE ?"; } cursor = db.rawQuery( query, ignoreGroups ? new String[]{ "%@" + WhatsAppMessage.GROUP } : null ); if (cursor != null && cursor.moveToNext()) { return cursor.getLong(0); } else { return DEFAULT_MOST_RECENT; } } catch (SQLiteException e) { Log.w(TAG, e); return DEFAULT_MOST_RECENT; } finally { if (cursor != null) cursor.close(); } } } Whassup(Context context);   Whassup(DecryptorFactory decryptorFactory, DBProvider dbProvider, DBOpener dbOpener); }
Whassup { public long getMostRecentTimestamp(boolean ignoreGroups) throws IOException { File currentDB = dbProvider.getDBFile(); if (currentDB == null) { return DEFAULT_MOST_RECENT; } else { SQLiteDatabase db = getSqLiteDatabase(decryptDB(currentDB)); Cursor cursor = null; try { String query = "SELECT MAX(" + TIMESTAMP + ") FROM " + WhatsAppMessage.TABLE; if (ignoreGroups) { query += " WHERE " + KEY_REMOTE_JID + " NOT LIKE ?"; } cursor = db.rawQuery( query, ignoreGroups ? new String[]{ "%@" + WhatsAppMessage.GROUP } : null ); if (cursor != null && cursor.moveToNext()) { return cursor.getLong(0); } else { return DEFAULT_MOST_RECENT; } } catch (SQLiteException e) { Log.w(TAG, e); return DEFAULT_MOST_RECENT; } finally { if (cursor != null) cursor.close(); } } } Whassup(Context context);   Whassup(DecryptorFactory decryptorFactory, DBProvider dbProvider, DBOpener dbOpener); Cursor queryMessages(); Cursor queryMessages(long timestamp, int max); long getMostRecentTimestamp(boolean ignoreGroups); List<WhatsAppMessage> getMessages(long timestamp, int max); List<WhatsAppMessage> getMessages(); boolean hasBackupDB(); }
Whassup { public long getMostRecentTimestamp(boolean ignoreGroups) throws IOException { File currentDB = dbProvider.getDBFile(); if (currentDB == null) { return DEFAULT_MOST_RECENT; } else { SQLiteDatabase db = getSqLiteDatabase(decryptDB(currentDB)); Cursor cursor = null; try { String query = "SELECT MAX(" + TIMESTAMP + ") FROM " + WhatsAppMessage.TABLE; if (ignoreGroups) { query += " WHERE " + KEY_REMOTE_JID + " NOT LIKE ?"; } cursor = db.rawQuery( query, ignoreGroups ? new String[]{ "%@" + WhatsAppMessage.GROUP } : null ); if (cursor != null && cursor.moveToNext()) { return cursor.getLong(0); } else { return DEFAULT_MOST_RECENT; } } catch (SQLiteException e) { Log.w(TAG, e); return DEFAULT_MOST_RECENT; } finally { if (cursor != null) cursor.close(); } } } Whassup(Context context);   Whassup(DecryptorFactory decryptorFactory, DBProvider dbProvider, DBOpener dbOpener); Cursor queryMessages(); Cursor queryMessages(long timestamp, int max); long getMostRecentTimestamp(boolean ignoreGroups); List<WhatsAppMessage> getMessages(long timestamp, int max); List<WhatsAppMessage> getMessages(); boolean hasBackupDB();  }