mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
parent
3bf8052811
commit
adcb29616a
@ -45,6 +45,9 @@ import org.thoughtcrime.securesms.util.concurrent.ListenableFuture.Listener;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import ws.com.google.android.mms.ContentType;
|
||||
@ -60,7 +63,8 @@ public class AttachmentManager {
|
||||
private final @NonNull AudioView audioView;
|
||||
private final @NonNull AttachmentListener attachmentListener;
|
||||
|
||||
private @NonNull Optional<Slide> slide = Optional.absent();
|
||||
private @NonNull List<Uri> garbage = new LinkedList<>();
|
||||
private @NonNull Optional<Slide> slide = Optional.absent();
|
||||
private @Nullable Uri captureUri;
|
||||
|
||||
public AttachmentManager(@NonNull Activity activity, @NonNull AttachmentListener listener) {
|
||||
@ -86,6 +90,8 @@ public class AttachmentManager {
|
||||
@Override
|
||||
public void onFailure(ExecutionException e) {}
|
||||
});
|
||||
|
||||
markGarbage(getSlideUri());
|
||||
slide = Optional.absent();
|
||||
audioView.cleanup();
|
||||
}
|
||||
@ -96,6 +102,13 @@ public class AttachmentManager {
|
||||
|
||||
captureUri = null;
|
||||
slide = Optional.absent();
|
||||
|
||||
Iterator<Uri> iterator = garbage.listIterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
cleanup(iterator.next());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanup(final @Nullable Uri uri) {
|
||||
@ -105,6 +118,13 @@ public class AttachmentManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void markGarbage(@Nullable Uri uri) {
|
||||
if (uri != null && PersistentBlobProvider.isAuthority(context, uri)) {
|
||||
Log.w(TAG, "Marking garbage that needs cleaning: " + uri);
|
||||
garbage.add(uri);
|
||||
}
|
||||
}
|
||||
|
||||
private void setSlide(@NonNull Slide slide) {
|
||||
if (getSlideUri() != null) cleanup(getSlideUri());
|
||||
if (captureUri != null && slide.getUri() != captureUri) cleanup(captureUri);
|
||||
|
Loading…
Reference in New Issue
Block a user