Skip to content

Commit

Permalink
fix: Files persist in the gallery when deleted in the preview
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyDL-Infomaniak committed Nov 11, 2024
1 parent c7a31e8 commit e8e80e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class MainViewModel(
private var syncOfflineFilesJob = Job()
private var setCurrentFolderJob = Job()

val deleteFilesFromGallery = SingleLiveEvent<List<Int>>()

private fun getContext() = getApplication<MainApplication>()

fun setCurrentFolder(folder: File?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/infomaniak/drive/ui/menu/GalleryFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -85,6 +86,10 @@ class GalleryFragment : MultiSelectFragment(MATOMO_CATEGORY), NoItemsLayoutView.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

getBackNavigationResult<Int>(DELETE_FILE_KEY) { fileId ->
galleryAdapter.deleteByFileId(fileId)
}

setupPagination()

val isCurrentlyInGallery = menuGalleryBinding != null
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
}
}

0 comments on commit e8e80e0

Please sign in to comment.