From 2656bc2e1eba91fff42f5d4decfa46ebd3fa44ed Mon Sep 17 00:00:00 2001 From: Tuan Nguyen Date: Sat, 16 Mar 2024 15:38:43 +0700 Subject: [PATCH] #76: Disallow File pinning (#82) --- .../components/filepicker/ArkFilePickerFragment.kt | 4 ++++ .../components/filepicker/ArkFilePickerViewModel.kt | 6 ++++++ filepicker/src/main/res/values/strings.xml | 1 + 3 files changed, 11 insertions(+) diff --git a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt index 3929c72..ac21c3f 100644 --- a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt +++ b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt @@ -302,6 +302,10 @@ open class ArkFilePickerFragment : pagesAdapter.set(getPages()) activity?.toast(R.string.ark_file_picker_pinned_as_root) } + + FilePickerSideEffect.CannotPinFile -> { + activity?.toast(R.string.ark_file_picker_pin_folder_only) + } } diff --git a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt index 27c2abb..19d4b1b 100644 --- a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt +++ b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt @@ -43,6 +43,7 @@ internal sealed class FilePickerSideEffect { data object PinAsFavorite : FilePickerSideEffect() data object AlreadyFavorite : FilePickerSideEffect() data object PinAsFirstRoot : FilePickerSideEffect() + data object CannotPinFile : FilePickerSideEffect() } @@ -180,6 +181,11 @@ internal class ArkFilePickerViewModel( } fun pinFile(file: Path) = intent { + if (!file.isDirectory()) { + postSideEffect(FilePickerSideEffect.CannotPinFile) + return@intent + } + val rootsWithFavorites = container.stateFlow.value.rootsWithFavs val roots = rootsWithFavorites.keys val root = roots.find { root -> file.startsWith(root) } diff --git a/filepicker/src/main/res/values/strings.xml b/filepicker/src/main/res/values/strings.xml index c3d9f22..e7f016e 100644 --- a/filepicker/src/main/res/values/strings.xml +++ b/filepicker/src/main/res/values/strings.xml @@ -15,6 +15,7 @@ Pinned as a Root folder! Already be a Favorite folder! Already be a Root folder! + Only folder can be pinned. Pin %d item