Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make second condition as separate variable?
Second condition is hard to understand, maybe root.startsWith(file) || file.startsWith(root)
startsWith checks if this is child of argument path

@mdrlzy mdrlzy Oct 29, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also extract this check as separate method to the utils module?
We will need this check in Navigator app.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you don't check if selected folder is parent of root.
We can't allow /Internal/Music root and /Internal/Music/A selected folder to pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdrlzy The changes in this PR are doing exactly what you think is missing.
That means, if /Internal/Music/A is root, pinning (in consequence, making root) /Internal/Music is disallowed.


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