Search in sources :

Example 1 with PreUploadResult

use of org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult in project Signal-Android by signalapp.

the class MediaUploadRepository method uploadMediaInternal.

@WorkerThread
private void uploadMediaInternal(@NonNull Media media, @Nullable Recipient recipient) {
    Attachment attachment = asAttachment(context, media);
    PreUploadResult result = MessageSender.preUploadPushAttachment(context, attachment, recipient);
    if (result != null) {
        uploadResults.put(media, result);
    } else {
        Log.w(TAG, "Failed to upload media with URI: " + media.getUri());
    }
}
Also used : Attachment(org.thoughtcrime.securesms.attachments.Attachment) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with PreUploadResult

use of org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult in project Signal-Android by signalapp.

the class MediaUploadRepository method updateDisplayOrderInternal.

@WorkerThread
private void updateDisplayOrderInternal(@NonNull List<Media> mediaInOrder) {
    Map<AttachmentId, Integer> orderMap = new HashMap<>();
    Map<Media, PreUploadResult> orderedUploadResults = new LinkedHashMap<>();
    for (int i = 0; i < mediaInOrder.size(); i++) {
        Media media = mediaInOrder.get(i);
        PreUploadResult result = uploadResults.get(media);
        if (result != null) {
            orderMap.put(result.getAttachmentId(), i);
            orderedUploadResults.put(media, result);
        } else {
            Log.w(TAG, "When updating display order, no pre-upload result could be found for media with URI: " + media.getUri());
        }
    }
    SignalDatabase.attachments().updateDisplayOrder(orderMap);
    if (orderedUploadResults.size() == uploadResults.size()) {
        uploadResults.clear();
        uploadResults.putAll(orderedUploadResults);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) LinkedHashMap(java.util.LinkedHashMap) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with PreUploadResult

use of org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult in project Signal-Android by WhisperSystems.

the class MediaUploadRepository method updateDisplayOrderInternal.

@WorkerThread
private void updateDisplayOrderInternal(@NonNull List<Media> mediaInOrder) {
    Map<AttachmentId, Integer> orderMap = new HashMap<>();
    Map<Media, PreUploadResult> orderedUploadResults = new LinkedHashMap<>();
    for (int i = 0; i < mediaInOrder.size(); i++) {
        Media media = mediaInOrder.get(i);
        PreUploadResult result = uploadResults.get(media);
        if (result != null) {
            orderMap.put(result.getAttachmentId(), i);
            orderedUploadResults.put(media, result);
        } else {
            Log.w(TAG, "When updating display order, no pre-upload result could be found for media with URI: " + media.getUri());
        }
    }
    SignalDatabase.attachments().updateDisplayOrder(orderMap);
    if (orderedUploadResults.size() == uploadResults.size()) {
        uploadResults.clear();
        uploadResults.putAll(orderedUploadResults);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) LinkedHashMap(java.util.LinkedHashMap) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with PreUploadResult

use of org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult in project Signal-Android by WhisperSystems.

the class MediaUploadRepository method cancelUploadInternal.

private void cancelUploadInternal(@NonNull Media media) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    PreUploadResult result = uploadResults.get(media);
    if (result != null) {
        Stream.of(result.getJobIds()).forEach(jobManager::cancel);
        uploadResults.remove(media);
    }
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult)

Example 5 with PreUploadResult

use of org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult in project Signal-Android by WhisperSystems.

the class MediaUploadRepository method uploadMediaInternal.

@WorkerThread
private void uploadMediaInternal(@NonNull Media media, @Nullable Recipient recipient) {
    Attachment attachment = asAttachment(context, media);
    PreUploadResult result = MessageSender.preUploadPushAttachment(context, attachment, recipient);
    if (result != null) {
        uploadResults.put(media, result);
    } else {
        Log.w(TAG, "Failed to upload media with URI: " + media.getUri());
    }
}
Also used : Attachment(org.thoughtcrime.securesms.attachments.Attachment) PreUploadResult(org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

PreUploadResult (org.thoughtcrime.securesms.sms.MessageSender.PreUploadResult)6 WorkerThread (androidx.annotation.WorkerThread)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)2 JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)2