mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 00:37:47 +00:00
Remove some unnecessary intermediate blob creation.
This commit is contained in:
parent
276e867f9a
commit
b572fce658
@ -70,6 +70,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.gms.location.places.ui.PlacePicker;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@ -581,7 +582,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
sendMediaMessage(transport.isSms(), message, slideDeck, Collections.emptyList(), Collections.emptyList(), expiresIn, subscriptionId, initiating);
|
||||
final Context context = ConversationActivity.this.getApplicationContext();
|
||||
|
||||
sendMediaMessage(transport.isSms(), message, slideDeck, Collections.emptyList(), Collections.emptyList(), expiresIn, subscriptionId, initiating).addListener(new AssertedSuccessListener<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
|
||||
Stream.of(slideDeck.getSlides())
|
||||
.map(Slide::getUri)
|
||||
.withoutNulls()
|
||||
.forEach(uri -> PersistentBlobProvider.getInstance(context).delete(context, uri));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
@ -2054,7 +2067,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
throws InvalidMessageException
|
||||
{
|
||||
Log.i(TAG, "Sending media message...");
|
||||
sendMediaMessage(forceSms, getMessage(), attachmentManager.buildSlideDeck(), Collections.emptyList(), linkPreviewViewModel.getPersistedLinkPreviews(this), expiresIn, subscriptionId, initiating);
|
||||
sendMediaMessage(forceSms, getMessage(), attachmentManager.buildSlideDeck(), Collections.emptyList(), linkPreviewViewModel.getActiveLinkPreviews(), expiresIn, subscriptionId, initiating);
|
||||
}
|
||||
|
||||
private ListenableFuture<Void> sendMediaMessage(final boolean forceSms,
|
||||
|
@ -51,37 +51,14 @@ public class LinkPreviewViewModel extends ViewModel {
|
||||
return linkPreviewState.getValue() != null && linkPreviewState.getValue().getLinkPreview().isPresent();
|
||||
}
|
||||
|
||||
public @NonNull List<LinkPreview> getPersistedLinkPreviews(@NonNull Context context) {
|
||||
public @NonNull List<LinkPreview> getActiveLinkPreviews() {
|
||||
final LinkPreviewState state = linkPreviewState.getValue();
|
||||
|
||||
if (state == null || !state.getLinkPreview().isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if (!state.getLinkPreview().get().getThumbnail().isPresent() || state.getLinkPreview().get().getThumbnail().get().getDataUri() == null) {
|
||||
} else {
|
||||
return Collections.singletonList(state.getLinkPreview().get());
|
||||
}
|
||||
|
||||
LinkPreview originalPreview = state.getLinkPreview().get();
|
||||
Attachment originalAttachment = originalPreview.getThumbnail().get();
|
||||
Uri memoryUri = originalAttachment.getDataUri();
|
||||
byte[] imageBlob = MemoryBlobProvider.getInstance().getBlob(memoryUri);
|
||||
Uri diskUri = PersistentBlobProvider.getInstance(context).create(context, imageBlob, MediaUtil.IMAGE_JPEG, null);
|
||||
Attachment newAttachment = new UriAttachment(diskUri,
|
||||
diskUri,
|
||||
originalAttachment.getContentType(),
|
||||
originalAttachment.getTransferState(),
|
||||
originalAttachment.getSize(),
|
||||
originalAttachment.getWidth(),
|
||||
originalAttachment.getHeight(),
|
||||
originalAttachment.getFileName(),
|
||||
originalAttachment.getFastPreflightId(),
|
||||
originalAttachment.isVoiceNote(),
|
||||
originalAttachment.isQuote(),
|
||||
originalAttachment.getCaption());
|
||||
|
||||
MemoryBlobProvider.getInstance().delete(memoryUri);
|
||||
|
||||
return Collections.singletonList(new LinkPreview(originalPreview.getUrl(), originalPreview.getTitle(), Optional.of(newAttachment)));
|
||||
}
|
||||
|
||||
public void onTextChanged(@NonNull Context context, @NonNull String text, int cursorStart, int cursorEnd) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user