Search in sources :

Example 6 with MessageRecord

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;
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord)

Example 7 with 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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) ProgressDialogAsyncTask(org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)

Example 8 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationFragment method handleCopyMessage.

private void handleCopyMessage(final Set<MessageRecord> messageRecords) {
    List<MessageRecord> messageList = new LinkedList<>(messageRecords);
    Collections.sort(messageList, new Comparator<MessageRecord>() {

        @Override
        public int compare(MessageRecord lhs, MessageRecord rhs) {
            if (lhs.getDateReceived() < rhs.getDateReceived())
                return -1;
            else if (lhs.getDateReceived() == rhs.getDateReceived())
                return 0;
            else
                return 1;
        }
    });
    StringBuilder bodyBuilder = new StringBuilder();
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    boolean first = true;
    for (MessageRecord messageRecord : messageList) {
        String body = messageRecord.getDisplayBody().toString();
        if (body != null) {
            if (!first)
                bodyBuilder.append('\n');
            bodyBuilder.append(body);
            first = false;
        }
    }
    String result = bodyBuilder.toString();
    if (!TextUtils.isEmpty(result))
        clipboard.setText(result);
}
Also used : ClipboardManager(android.text.ClipboardManager) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) LinkedList(java.util.LinkedList)

Example 9 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationFragment method setCorrectMenuVisibility.

private void setCorrectMenuVisibility(Menu menu) {
    Set<MessageRecord> messageRecords = getListAdapter().getSelectedItems();
    boolean actionMessage = false;
    if (actionMode != null && messageRecords.size() == 0) {
        actionMode.finish();
        return;
    }
    for (MessageRecord messageRecord : messageRecords) {
        if (messageRecord.isGroupAction() || messageRecord.isCallLog() || messageRecord.isJoined() || messageRecord.isExpirationTimerUpdate() || messageRecord.isEndSession() || messageRecord.isIdentityUpdate()) {
            actionMessage = true;
            break;
        }
    }
    if (messageRecords.size() > 1) {
        menu.findItem(R.id.menu_context_forward).setVisible(false);
        menu.findItem(R.id.menu_context_details).setVisible(false);
        menu.findItem(R.id.menu_context_save_attachment).setVisible(false);
        menu.findItem(R.id.menu_context_resend).setVisible(false);
        menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage);
    } else {
        MessageRecord messageRecord = messageRecords.iterator().next();
        menu.findItem(R.id.menu_context_resend).setVisible(messageRecord.isFailed());
        menu.findItem(R.id.menu_context_save_attachment).setVisible(!actionMessage && messageRecord.isMms() && !messageRecord.isMmsNotification() && ((MediaMmsMessageRecord) messageRecord).containsMediaSlide());
        menu.findItem(R.id.menu_context_forward).setVisible(!actionMessage);
        menu.findItem(R.id.menu_context_details).setVisible(!actionMessage);
        menu.findItem(R.id.menu_context_copy).setVisible(!actionMessage);
    }
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)

Example 10 with MessageRecord

use of org.thoughtcrime.securesms.database.model.MessageRecord in project Signal-Android by WhisperSystems.

the class ConversationAdapter method onBindItemViewHolder.

@Override
public void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor) {
    long start = System.currentTimeMillis();
    MessageRecord messageRecord = getMessageRecord(cursor);
    viewHolder.getView().bind(masterSecret, messageRecord, locale, batchSelected, recipients);
    Log.w(TAG, "Bind time: " + (System.currentTimeMillis() - start));
}
Also used : MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord)

Aggregations

MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)12 MediaMmsMessageRecord (org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)6 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)5 Cursor (android.database.Cursor)3 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 ClipboardManager (android.text.ClipboardManager)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)1 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)1 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 Recipients (org.thoughtcrime.securesms.recipients.Recipients)1 ProgressDialogAsyncTask (org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask)1