Skip to content

Commit 031bf94

Browse files
committed
fix(gallery-fragment): illegal state exception
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 7952523 commit 031bf94

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
6565
private static final int SELECT_LOCATION_REQUEST_CODE = 212;
6666
private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog;
6767

68-
@Inject FileDataStorageManager fileDataStorageManager;
6968
private final static int maxColumnSizeLandscape = 5;
7069
private final static int maxColumnSizePortrait = 2;
7170
private int columnSize;
@@ -119,9 +118,17 @@ public static void setLastMediaItemPosition(Integer position) {
119118

120119
@Override
121120
public void onDestroyView() {
121+
if (photoSearchTask != null) {
122+
photoSearchTask.cancel(true);
123+
photoSearchTask = null;
124+
}
125+
122126
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(refreshSearchEventReceiver);
127+
123128
setLastMediaItemPosition(null);
129+
124130
mAdapter.cleanup();
131+
125132
super.onDestroyView();
126133
}
127134

@@ -264,6 +271,8 @@ private void searchAndDisplay() {
264271
}
265272

266273
public void searchCompleted(boolean emptySearch, long lastTimeStamp) {
274+
if (!isAdded()) return;
275+
267276
this.setPhotoSearchQueryRunning(false);
268277

269278
if (lastTimeStamp > -1) {
@@ -407,7 +416,12 @@ public void showAllGalleryItems() {
407416
}
408417

409418
private void updateSubtitle(GalleryFragmentBottomSheetDialog.MediaState mediaState) {
410-
requireActivity().runOnUiThread(() -> {
419+
final var activity = getActivity();
420+
if (!isAdded() || activity == null) {
421+
return;
422+
}
423+
424+
activity.runOnUiThread(() -> {
411425
if (!isAdded()) {
412426
return;
413427
}
@@ -419,7 +433,7 @@ private void updateSubtitle(GalleryFragmentBottomSheetDialog.MediaState mediaSta
419433
subTitle = getResources().getString(R.string.subtitle_videos_only);
420434
}
421435

422-
if (requireActivity() instanceof ToolbarActivity toolbarActivity) {
436+
if (activity instanceof ToolbarActivity toolbarActivity) {
423437
toolbarActivity.updateToolbarSubtitle(subTitle);
424438
}
425439
});

0 commit comments

Comments
 (0)