use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.
the class AttachmentDatabase method getPendingAttachments.
@NonNull
public List<DatabaseAttachment> getPendingAttachments() {
final SQLiteDatabase database = databaseHelper.getReadableDatabase();
final List<DatabaseAttachment> attachments = new LinkedList<>();
Cursor cursor = null;
try {
cursor = database.query(TABLE_NAME, PROJECTION, TRANSFER_STATE + " = ?", new String[] { String.valueOf(TRANSFER_PROGRESS_STARTED) }, null, null, null);
while (cursor != null && cursor.moveToNext()) {
attachments.add(getAttachment(cursor));
}
} finally {
if (cursor != null)
cursor.close();
}
return attachments;
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.
the class AttachmentDatabase method updateAttachmentData.
@NonNull
public Attachment updateAttachmentData(@NonNull Attachment attachment, @NonNull MediaStream mediaStream) throws MmsException {
SQLiteDatabase database = databaseHelper.getWritableDatabase();
DatabaseAttachment databaseAttachment = (DatabaseAttachment) attachment;
DataInfo dataInfo = getAttachmentDataFileInfo(databaseAttachment.getAttachmentId(), DATA);
if (dataInfo == null) {
throw new MmsException("No attachment data found!");
}
dataInfo = setAttachmentData(dataInfo.file, mediaStream.getStream());
ContentValues contentValues = new ContentValues();
contentValues.put(SIZE, dataInfo.length);
contentValues.put(CONTENT_TYPE, mediaStream.getMimeType());
contentValues.put(DATA_RANDOM, dataInfo.random);
database.update(TABLE_NAME, contentValues, PART_ID_WHERE, databaseAttachment.getAttachmentId().toStrings());
return new DatabaseAttachment(databaseAttachment.getAttachmentId(), databaseAttachment.getMmsId(), databaseAttachment.hasData(), databaseAttachment.hasThumbnail(), mediaStream.getMimeType(), databaseAttachment.getTransferState(), dataInfo.length, databaseAttachment.getFileName(), databaseAttachment.getLocation(), databaseAttachment.getKey(), databaseAttachment.getRelay(), databaseAttachment.getDigest(), databaseAttachment.getFastPreflightId(), databaseAttachment.isVoiceNote());
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.
the class AttachmentDatabase method markAttachmentUploaded.
public void markAttachmentUploaded(long messageId, Attachment attachment) {
ContentValues values = new ContentValues(1);
SQLiteDatabase database = databaseHelper.getWritableDatabase();
values.put(TRANSFER_STATE, TRANSFER_PROGRESS_DONE);
database.update(TABLE_NAME, values, PART_ID_WHERE, ((DatabaseAttachment) attachment).getAttachmentId().toStrings());
notifyConversationListeners(DatabaseFactory.getMmsDatabase(context).getThreadIdForMessage(messageId));
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.
the class PartProvider method getType.
@Override
public String getType(@NonNull Uri uri) {
Log.w(TAG, "getType() called: " + uri);
switch(uriMatcher.match(uri)) {
case SINGLE_ROW:
PartUriParser partUriParser = new PartUriParser(uri);
DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachment(partUriParser.getPartId());
if (attachment != null) {
return attachment.getContentType();
}
}
return null;
}
use of org.thoughtcrime.securesms.attachments.DatabaseAttachment in project Signal-Android by signalapp.
the class PartProvider method query.
@Override
public Cursor query(@NonNull Uri url, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
Log.w(TAG, "query() called: " + url);
if (projection == null || projection.length <= 0)
return null;
switch(uriMatcher.match(url)) {
case SINGLE_ROW:
PartUriParser partUri = new PartUriParser(url);
DatabaseAttachment attachment = DatabaseFactory.getAttachmentDatabase(getContext()).getAttachment(partUri.getPartId());
if (attachment == null)
return null;
MatrixCursor matrixCursor = new MatrixCursor(projection, 1);
Object[] resultRow = new Object[projection.length];
for (int i = 0; i < projection.length; i++) {
if (OpenableColumns.DISPLAY_NAME.equals(projection[i])) {
resultRow[i] = attachment.getFileName();
}
}
matrixCursor.addRow(resultRow);
return matrixCursor;
}
return null;
}
Aggregations