Skip to content

Commit

Permalink
Prohibit creating nested roots: #68
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancoltech committed Nov 11, 2024
1 parent ddf7c31 commit a445b7b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ open class ArkFilePickerFragment :
FilePickerSideEffect.CannotPinFile -> {
activity?.toast(R.string.ark_file_picker_pin_folder_only)
}

FilePickerSideEffect.NestedRootProhibited -> {
activity?.toast(R.string.ark_file_nested_root_inside)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ internal sealed class FilePickerSideEffect {
data object AlreadyFavorite : FilePickerSideEffect()
data object PinAsFirstRoot : FilePickerSideEffect()
data object CannotPinFile : FilePickerSideEffect()
data object NestedRootProhibited : FilePickerSideEffect()

}

Expand Down Expand Up @@ -190,6 +191,17 @@ internal class ArkFilePickerViewModel(
val roots = rootsWithFavorites.keys
val root = roots.find { root -> file.startsWith(root) }
val favorites = rootsWithFavorites[root]?.flatten()

val hasNestedRoot = roots.contains(file)
|| (roots.indexOfFirst { path ->
val index = path.toString().indexOf(file.toString())
(index >= 0) && (path.toString()[index] == '/') } >= 0)

if (hasNestedRoot) {
postSideEffect(FilePickerSideEffect.NestedRootProhibited)
return@intent
}

val haveRoot = haveRoot()

root?.let {
Expand Down
1 change: 1 addition & 0 deletions filepicker/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="ark_file_picker_already_a_favorite">Already be a Favorite folder!</string>
<string name="ark_file_picker_already_be_a_root">Already be a Root folder!</string>
<string name="ark_file_picker_pin_folder_only">Only folder can be pinned.</string>
<string name="ark_file_nested_root_inside">There\'s already nested root(s) inside.</string>
<string name="ark_file_picker_pin">Pin</string>
<plurals name="ark_file_picker_items">
<item quantity="one">%d item</item>
Expand Down

0 comments on commit a445b7b

Please sign in to comment.