Fix crash when exiting preview of deleted file

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2023-11-01 11:21:10 +01:00
parent b188af0aca
commit 548977479e
No known key found for this signature in database
GPG key ID: C705C33DC3B9BA5B
2 changed files with 8 additions and 9 deletions

View file

@ -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.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation; import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation;
import com.owncloud.android.lib.resources.files.SearchRemoteOperation; 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.CopyFileOperation;
import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.MoveFileOperation;
@ -1733,8 +1732,9 @@ public class FileDisplayActivity extends FileActivity
boolean fileAvailable = getStorageManager().fileExists(removedFile.getFileId()); boolean fileAvailable = getStorageManager().fileExists(removedFile.getFileId());
if (leftFragment instanceof FileFragment && !fileAvailable && removedFile.equals(((FileFragment) leftFragment).getFile())) { if (leftFragment instanceof FileFragment && !fileAvailable && removedFile.equals(((FileFragment) leftFragment).getFile())) {
if (leftFragment instanceof PreviewMediaFragment) { if (leftFragment instanceof PreviewMediaFragment previewMediaFragment) {
((PreviewMediaFragment) leftFragment).stopPreview(true); previewMediaFragment.stopPreview(true);
onBackPressed();
} }
setFile(getStorageManager().getFileById(removedFile.getParentId())); setFile(getStorageManager().getFileById(removedFile.getParentId()));
resetTitleBarAndScrolling(); resetTitleBarAndScrolling();
@ -1742,8 +1742,8 @@ public class FileDisplayActivity extends FileActivity
OCFile parentFile = getStorageManager().getFileById(removedFile.getParentId()); OCFile parentFile = getStorageManager().getFileById(removedFile.getParentId());
if (parentFile != null && parentFile.equals(getCurrentDir())) { if (parentFile != null && parentFile.equals(getCurrentDir())) {
updateListOfFilesFragment(false); updateListOfFilesFragment(false);
} else if (getLeftFragment() instanceof GalleryFragment) { } else if (getLeftFragment() instanceof GalleryFragment galleryFragment) {
((GalleryFragment) getLeftFragment()).onRefresh(); galleryFragment.onRefresh();
} }
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
} else { } else {

View file

@ -673,10 +673,9 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
} }
public void stopPreview(boolean stopAudio) { public void stopPreview(boolean stopAudio) {
OCFile file = getFile(); if (stopAudio && mediaPlayerServiceConnection != null) {
if (MimeTypeUtil.isAudio(file) && stopAudio) { mediaPlayerServiceConnection.stop();
mediaPlayerServiceConnection.pause(); } else if (exoPlayer != null) {
} else if (MimeTypeUtil.isVideo(file)) {
savedPlaybackPosition = exoPlayer.getCurrentPosition(); savedPlaybackPosition = exoPlayer.getCurrentPosition();
exoPlayer.stop(); exoPlayer.stop();
} }