Search in sources :

Example 1 with ThumbnailData

use of org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData in project Signal-Android by signalapp.

the class AttachmentDatabase method insertAttachment.

private AttachmentId insertAttachment(long mmsId, Attachment attachment) throws MmsException {
    Log.w(TAG, "Inserting attachment for mms id: " + mmsId);
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    DataInfo dataInfo = null;
    long uniqueId = System.currentTimeMillis();
    if (attachment.getDataUri() != null) {
        dataInfo = setAttachmentData(attachment.getDataUri());
        Log.w(TAG, "Wrote part to file: " + dataInfo.file.getAbsolutePath());
    }
    ContentValues contentValues = new ContentValues();
    contentValues.put(MMS_ID, mmsId);
    contentValues.put(CONTENT_TYPE, attachment.getContentType());
    contentValues.put(TRANSFER_STATE, attachment.getTransferState());
    contentValues.put(UNIQUE_ID, uniqueId);
    contentValues.put(CONTENT_LOCATION, attachment.getLocation());
    contentValues.put(DIGEST, attachment.getDigest());
    contentValues.put(CONTENT_DISPOSITION, attachment.getKey());
    contentValues.put(NAME, attachment.getRelay());
    contentValues.put(FILE_NAME, StorageUtil.getCleanFileName(attachment.getFileName()));
    contentValues.put(SIZE, attachment.getSize());
    contentValues.put(FAST_PREFLIGHT_ID, attachment.getFastPreflightId());
    contentValues.put(VOICE_NOTE, attachment.isVoiceNote() ? 1 : 0);
    if (dataInfo != null) {
        contentValues.put(DATA, dataInfo.file.getAbsolutePath());
        contentValues.put(SIZE, dataInfo.length);
        contentValues.put(DATA_RANDOM, dataInfo.random);
    }
    long rowId = database.insert(TABLE_NAME, null, contentValues);
    AttachmentId attachmentId = new AttachmentId(rowId, uniqueId);
    if (dataInfo != null) {
        if (MediaUtil.hasVideoThumbnail(attachment.getDataUri())) {
            Bitmap bitmap = MediaUtil.getVideoThumbnail(context, attachment.getDataUri());
            if (bitmap != null) {
                ThumbnailData thumbnailData = new ThumbnailData(bitmap);
                updateAttachmentThumbnail(attachmentId, thumbnailData.toDataStream(), thumbnailData.getAspectRatio());
            } else {
                Log.w(TAG, "Retrieving video thumbnail failed, submitting thumbnail generation job...");
                thumbnailExecutor.submit(new ThumbnailFetchCallable(attachmentId));
            }
        } else {
            Log.w(TAG, "Submitting thumbnail generation job...");
            thumbnailExecutor.submit(new ThumbnailFetchCallable(attachmentId));
        }
    }
    return attachmentId;
}
Also used : ContentValues(android.content.ContentValues) Bitmap(android.graphics.Bitmap) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) ThumbnailData(org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId)

Aggregations

ContentValues (android.content.ContentValues)1 Bitmap (android.graphics.Bitmap)1 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)1 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)1 ThumbnailData (org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData)1