Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix moved files not being removed from preview in file list #781

Merged
merged 4 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,7 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene
mainViewModel.deleteFile(currentFile).observe(viewLifecycleOwner) { apiResponse ->
onApiResponse()
if (apiResponse.isSuccess()) {
if (previewSliderAdapter.deleteFile(currentFile)) {
findNavController().popBackStack()
} else {
toggleBottomSheet(true)
}
mainViewModel.currentPreviewFileList.remove(currentFile.id)
removeFileInSlider()
showSnackbar(R.string.snackbarLeaveShareConfirmation)
} else {
showSnackbar(apiResponse.translatedError)
Expand Down Expand Up @@ -448,12 +443,7 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene
mainViewModel.deleteFile(currentFile).observe(viewLifecycleOwner) { apiResponse ->
onApiResponse()
if (apiResponse.isSuccess()) {
mainViewModel.currentPreviewFileList.remove(currentFile.id)
if (previewSliderAdapter.deleteFile(currentFile)) {
findNavController().popBackStack()
} else {
toggleBottomSheet(true)
}
removeFileInSlider()
val title = resources.getQuantityString(
R.plurals.snackbarMoveTrashConfirmation,
1,
Expand Down Expand Up @@ -487,6 +477,8 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene
mainViewModel.moveFile(currentFile, destinationFolder)
.observe(viewLifecycleOwner) { apiResponse ->
if (apiResponse.isSuccess()) {
// Because if we are on the favorite view we do not want to remove it for example
if (findNavController().previousBackStackEntry?.destination?.id == R.id.fileListFragment) removeFileInSlider()
mainViewModel.refreshActivities.value = true
showSnackbar(getString(R.string.allFileMove, currentFile.name, destinationFolder.name))
} else {
Expand All @@ -495,6 +487,15 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene
}
}

private fun removeFileInSlider() {
mainViewModel.currentPreviewFileList.remove(currentFile.id)
if (previewSliderAdapter.deleteFile(currentFile)) {
findNavController().popBackStack()
} else {
toggleBottomSheet(true)
}
}

companion object {

fun Fragment.toggleFullscreen() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/infomaniak/drive/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ object Utils {
navController: NavController,
selectedFile: File,
fileList: ArrayList<File>,
isSharedWithMe: Boolean = false
isSharedWithMe: Boolean = false,
) {
mainViewModel.currentPreviewFileList = fileList.associateBy { it.id } as LinkedHashMap<Int, File>
val bundle = PreviewSliderFragmentArgs(
Expand Down