From e3e45292a858e88568da4f76ff0ea8f5e5a18193 Mon Sep 17 00:00:00 2001 From: jubb Date: Thu, 25 Mar 2021 16:40:15 +1100 Subject: [PATCH] fix: unclosed cursor error message --- .../securesms/MediaPreviewActivity.java | 34 +++++++++++-------- .../mediapreview/MediaPreviewViewModel.java | 13 ++++--- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index 6399dbc022..60b5cbeb25 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -18,9 +18,6 @@ package org.thoughtcrime.securesms; import android.annotation.SuppressLint; import android.annotation.TargetApi; - -import androidx.appcompat.app.ActionBar; -import androidx.lifecycle.ViewModelProvider; import android.content.Context; import android.content.Intent; import android.database.Cursor; @@ -30,16 +27,6 @@ import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.loader.app.LoaderManager; -import androidx.loader.content.Loader; -import androidx.core.util.Pair; -import androidx.viewpager.widget.PagerAdapter; -import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.app.AlertDialog; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.view.GestureDetector; import android.view.LayoutInflater; import android.view.Menu; @@ -53,16 +40,28 @@ import android.widget.FrameLayout; import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; +import androidx.core.util.Pair; +import androidx.lifecycle.ViewModelProvider; +import androidx.loader.app.LoaderManager; +import androidx.loader.content.Loader; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; + import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment; import org.session.libsession.messaging.threads.Address; import org.session.libsession.messaging.threads.recipients.Recipient; import org.session.libsession.messaging.threads.recipients.RecipientModifiedListener; import org.session.libsession.utilities.Util; - +import org.session.libsignal.utilities.logging.Log; import org.thoughtcrime.securesms.components.MediaView; import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord; import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader; -import org.session.libsignal.utilities.logging.Log; import org.thoughtcrime.securesms.mediapreview.MediaPreviewViewModel; import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter; import org.thoughtcrime.securesms.mms.GlideApp; @@ -312,6 +311,11 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private int cleanupMedia() { int restartItem = mediaPager.getCurrentItem(); + PagerAdapter adapter = mediaPager.getAdapter(); + if (adapter instanceof CursorPagerAdapter) { + ((CursorPagerAdapter)adapter).cursor.close(); + } + mediaPager.removeAllViews(); mediaPager.setAdapter(null); diff --git a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaPreviewViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaPreviewViewModel.java index 261d9856d8..0babefc0e5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaPreviewViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/mediapreview/MediaPreviewViewModel.java @@ -1,17 +1,18 @@ package org.thoughtcrime.securesms.mediapreview; -import androidx.lifecycle.LiveData; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; import android.content.Context; import android.database.Cursor; import android.net.Uri; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; +import org.session.libsignal.libsignal.util.guava.Optional; import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord; import org.thoughtcrime.securesms.mediasend.Media; -import org.session.libsignal.libsignal.util.guava.Optional; import java.util.Collections; import java.util.LinkedList; @@ -27,7 +28,9 @@ public class MediaPreviewViewModel extends ViewModel { public void setCursor(@NonNull Context context, @Nullable Cursor cursor, boolean leftIsRecent) { boolean firstLoad = (this.cursor == null) && (cursor != null); - + if (this.cursor != null) { + this.cursor.close(); + } this.cursor = cursor; this.leftIsRecent = leftIsRecent;