use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.
the class ConversationAdapter method findLastSeenPosition.
public int findLastSeenPosition(long lastSeen) {
if (lastSeen <= 0)
return -1;
if (!isActiveCursor())
return -1;
int count = getItemCount();
for (int i = 0; i < count; i++) {
Cursor cursor = getCursorAtPositionOrThrow(i);
MessageRecord messageRecord = getMessageRecord(cursor);
if (messageRecord.isOutgoing() || messageRecord.getDateReceived() <= lastSeen) {
return i;
}
}
return -1;
}
use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.
the class ConversationAdapter method getReceivedTimestamp.
public long getReceivedTimestamp(int position) {
if (!isActiveCursor())
return 0;
if (isHeaderPosition(position))
return 0;
if (isFooterPosition(position))
return 0;
if (position >= getItemCount())
return 0;
if (position < 0)
return 0;
Cursor cursor = getCursorAtPositionOrThrow(position);
MessageRecord messageRecord = getMessageRecord(cursor);
if (messageRecord.isOutgoing())
return 0;
else
return messageRecord.getDateReceived();
}
use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.
the class ConversationAdapter method getHeaderId.
@Override
public long getHeaderId(int position) {
if (!isActiveCursor())
return -1;
if (isHeaderPosition(position))
return -1;
if (isFooterPosition(position))
return -1;
if (position >= getItemCount())
return -1;
if (position < 0)
return -1;
Cursor cursor = getCursorAtPositionOrThrow(position);
MessageRecord record = getMessageRecord(cursor);
calendar.setTime(new Date(record.getDateSent()));
return Util.hashCode(calendar.get(Calendar.YEAR), calendar.get(Calendar.DAY_OF_YEAR));
}
use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.
the class ConversationAdapter method getMessageRecord.
private MessageRecord getMessageRecord(Cursor cursor) {
long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.ID));
String type = cursor.getString(cursor.getColumnIndexOrThrow(MmsSmsDatabase.TRANSPORT));
final SoftReference<MessageRecord> reference = messageRecordCache.get(type + messageId);
if (reference != null) {
final MessageRecord record = reference.get();
if (record != null)
return record;
}
final MessageRecord messageRecord = db.readerFor(cursor, masterSecret).getCurrent();
messageRecordCache.put(type + messageId, new SoftReference<>(messageRecord));
return messageRecord;
}
use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.
the class ConversationFragment method handleDeleteMessages.
private void handleDeleteMessages(final Set<MessageRecord> messageRecords) {
int messagesCount = messageRecords.size();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setIconAttribute(R.attr.dialog_alert_icon);
builder.setTitle(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messagesCount, messagesCount));
builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.ConversationFragment_this_will_permanently_delete_all_n_selected_messages, messagesCount, messagesCount));
builder.setCancelable(true);
builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new ProgressDialogAsyncTask<MessageRecord, Void, Void>(getActivity(), R.string.ConversationFragment_deleting, R.string.ConversationFragment_deleting_messages) {
@Override
protected Void doInBackground(MessageRecord... messageRecords) {
for (MessageRecord messageRecord : messageRecords) {
boolean threadDeleted;
if (messageRecord.isMms()) {
threadDeleted = DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId());
} else {
threadDeleted = DatabaseFactory.getSmsDatabase(getActivity()).deleteMessage(messageRecord.getId());
}
if (threadDeleted) {
threadId = -1;
listener.setThreadId(threadId);
}
}
return null;
}
}.execute(messageRecords.toArray(new MessageRecord[messageRecords.size()]));
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
Aggregations