public void trimThread(long threadId, int length) { Log.w("ThreadDatabase", "Trimming thread: " + threadId + " to: " + length); Cursor cursor = null; try { cursor = DatabaseFactory.getMmsSmsDatabase(context).getConversation(threadId); if (cursor != null && length > 0 && cursor.getCount() > length) { Log.w("ThreadDatabase", "Cursor count is greater than length!"); cursor.moveToPosition(length - 1); long lastTweetDate = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.NORMALIZED_DATE_RECEIVED)); Log.w("ThreadDatabase", "Cut off tweet date: " + lastTweetDate); DatabaseFactory.getSmsDatabase(context) .deleteMessagesInThreadBeforeDate(threadId, lastTweetDate); DatabaseFactory.getMmsDatabase(context) .deleteMessagesInThreadBeforeDate(threadId, lastTweetDate); update(threadId, false); notifyConversationListeners(threadId); } } finally { if (cursor != null) cursor.close(); } }
public void updateReadState(long threadId) { int unreadCount = DatabaseFactory.getMmsSmsDatabase(context).getUnreadCount(threadId); ContentValues contentValues = new ContentValues(); contentValues.put(READ, unreadCount == 0); databaseHelper .getWritableDatabase() .update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(threadId)}); notifyConversationListListeners(); }
public boolean update(long threadId, boolean unarchive) { MmsSmsDatabase mmsSmsDatabase = DatabaseFactory.getMmsSmsDatabase(context); long count = mmsSmsDatabase.getConversationCount(threadId); if (count == 0) { deleteThread(threadId); notifyConversationListListeners(); return true; } MmsSmsDatabase.Reader reader = null; try { reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId)); MessageRecord record; if (reader != null && (record = reader.getNext()) != null) { updateThread( threadId, count, record.getBody().getBody(), getAttachmentUriFor(record), record.getTimestamp(), record.getDeliveryStatus(), record.getReceiptCount(), record.getType(), unarchive); notifyConversationListListeners(); return false; } else { deleteThread(threadId); notifyConversationListListeners(); return true; } } finally { if (reader != null) reader.close(); } }