From 548977479e6cc692a7fb4ede726438853e27df5c Mon Sep 17 00:00:00 2001 From: ZetaTom <70907959+ZetaTom@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:21:10 +0100 Subject: [PATCH] Fix crash when exiting preview of deleted file Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com> --- .../android/ui/activity/FileDisplayActivity.java | 10 +++++----- .../android/ui/preview/PreviewMediaFragment.java | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index b7066e8a45..cb7013cd1c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -90,7 +90,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation; import com.owncloud.android.lib.resources.files.SearchRemoteOperation; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.MoveFileOperation; @@ -1733,8 +1732,9 @@ public class FileDisplayActivity extends FileActivity boolean fileAvailable = getStorageManager().fileExists(removedFile.getFileId()); if (leftFragment instanceof FileFragment && !fileAvailable && removedFile.equals(((FileFragment) leftFragment).getFile())) { - if (leftFragment instanceof PreviewMediaFragment) { - ((PreviewMediaFragment) leftFragment).stopPreview(true); + if (leftFragment instanceof PreviewMediaFragment previewMediaFragment) { + previewMediaFragment.stopPreview(true); + onBackPressed(); } setFile(getStorageManager().getFileById(removedFile.getParentId())); resetTitleBarAndScrolling(); @@ -1742,8 +1742,8 @@ public class FileDisplayActivity extends FileActivity OCFile parentFile = getStorageManager().getFileById(removedFile.getParentId()); if (parentFile != null && parentFile.equals(getCurrentDir())) { updateListOfFilesFragment(false); - } else if (getLeftFragment() instanceof GalleryFragment) { - ((GalleryFragment) getLeftFragment()).onRefresh(); + } else if (getLeftFragment() instanceof GalleryFragment galleryFragment) { + galleryFragment.onRefresh(); } supportInvalidateOptionsMenu(); } else { diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 20d82add5a..7975f46b6a 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -673,10 +673,9 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene } public void stopPreview(boolean stopAudio) { - OCFile file = getFile(); - if (MimeTypeUtil.isAudio(file) && stopAudio) { - mediaPlayerServiceConnection.pause(); - } else if (MimeTypeUtil.isVideo(file)) { + if (stopAudio && mediaPlayerServiceConnection != null) { + mediaPlayerServiceConnection.stop(); + } else if (exoPlayer != null) { savedPlaybackPosition = exoPlayer.getCurrentPosition(); exoPlayer.stop(); }