diff --git a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt index 20865cfea5..703a51004d 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt @@ -124,6 +124,8 @@ class MainViewModel( private var syncOfflineFilesJob = Job() private var setCurrentFolderJob = Job() + val deleteFilesFromGallery = SingleLiveEvent>() + private fun getContext() = getApplication() fun setCurrentFolder(folder: File?) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt index dd83c8a45c..8ff62d5860 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt @@ -277,6 +277,9 @@ class PreviewSliderFragment : BasePreviewSliderFragment(), FileInfoActionsView.O removeFileInSlider() showSnackbar(getString(R.string.snackbarMoveTrashConfirmation, currentFile.name)) mainViewModel.deleteFileFromHome.value = true + mainViewModel.deleteFilesFromGallery.postValue( + mainViewModel.deleteFilesFromGallery.value?.plus(currentFile.id) ?: listOf(currentFile.id) + ) } else { showSnackbar(R.string.errorDelete) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/menu/GalleryFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/menu/GalleryFragment.kt index e678455d8e..efbc8dc0b3 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/menu/GalleryFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/menu/GalleryFragment.kt @@ -46,6 +46,7 @@ import com.infomaniak.drive.utils.getAdjustedColumnNumber import com.infomaniak.drive.utils.observeAndDisplayNetworkAvailability import com.infomaniak.drive.views.NoItemsLayoutView import com.infomaniak.lib.core.utils.Utils.createRefreshTimer +import com.infomaniak.lib.core.utils.getBackNavigationResult import com.infomaniak.lib.core.utils.setPagination import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -85,6 +86,10 @@ class GalleryFragment : MultiSelectFragment(MATOMO_CATEGORY), NoItemsLayoutView. override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + getBackNavigationResult(DELETE_FILE_KEY) { fileId -> + galleryAdapter.deleteByFileId(fileId) + } + setupPagination() val isCurrentlyInGallery = menuGalleryBinding != null @@ -148,6 +153,10 @@ class GalleryFragment : MultiSelectFragment(MATOMO_CATEGORY), NoItemsLayoutView. } observeApiResultPagination() + + mainViewModel.deleteFilesFromGallery.observe(viewLifecycleOwner) { filesId -> + filesId.forEach { fileId -> galleryAdapter.deleteByFileId(fileId) } + } } private fun observeApiResultPagination() { @@ -338,5 +347,7 @@ class GalleryFragment : MultiSelectFragment(MATOMO_CATEGORY), NoItemsLayoutView. const val TAG = "GalleryFragment" const val MATOMO_CATEGORY = "picturesFileAction" private const val NUMBER_ITEMS_LOADER = 13 + + const val DELETE_FILE_KEY = "sort_type_option" } }