mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +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 org.whispersystems.libaxolotl.util.guava.Optional;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import ws.com.google.android.mms.ContentType;
|
import ws.com.google.android.mms.ContentType;
|
||||||
@ -60,7 +63,8 @@ public class AttachmentManager {
|
|||||||
private final @NonNull AudioView audioView;
|
private final @NonNull AudioView audioView;
|
||||||
private final @NonNull AttachmentListener attachmentListener;
|
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;
|
private @Nullable Uri captureUri;
|
||||||
|
|
||||||
public AttachmentManager(@NonNull Activity activity, @NonNull AttachmentListener listener) {
|
public AttachmentManager(@NonNull Activity activity, @NonNull AttachmentListener listener) {
|
||||||
@ -86,6 +90,8 @@ public class AttachmentManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(ExecutionException e) {}
|
public void onFailure(ExecutionException e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
markGarbage(getSlideUri());
|
||||||
slide = Optional.absent();
|
slide = Optional.absent();
|
||||||
audioView.cleanup();
|
audioView.cleanup();
|
||||||
}
|
}
|
||||||
@ -96,6 +102,13 @@ public class AttachmentManager {
|
|||||||
|
|
||||||
captureUri = null;
|
captureUri = null;
|
||||||
slide = Optional.absent();
|
slide = Optional.absent();
|
||||||
|
|
||||||
|
Iterator<Uri> iterator = garbage.listIterator();
|
||||||
|
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
cleanup(iterator.next());
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanup(final @Nullable Uri uri) {
|
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) {
|
private void setSlide(@NonNull Slide slide) {
|
||||||
if (getSlideUri() != null) cleanup(getSlideUri());
|
if (getSlideUri() != null) cleanup(getSlideUri());
|
||||||
if (captureUri != null && slide.getUri() != captureUri) cleanup(captureUri);
|
if (captureUri != null && slide.getUri() != captureUri) cleanup(captureUri);
|
||||||
|
Loading…
Reference in New Issue
Block a user