diff --git a/filepicker/build.gradle.kts b/filepicker/build.gradle.kts index 145a438..c2cf942 100644 --- a/filepicker/build.gradle.kts +++ b/filepicker/build.gradle.kts @@ -73,7 +73,7 @@ dependencies { implementation(libraries.viewbinding.property.delegate) } -val libVersion: String = scmVersion.version +val libVersion: String = /*scmVersion.version*/"0.1.1-SNAPSHOT-04" publishing { publications { @@ -95,5 +95,6 @@ publishing { password = System.getenv("GITHUB_TOKEN") } } + mavenLocal() } } \ No newline at end of file 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 ac21c3f..27166dd 100644 --- a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt +++ b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerFragment.kt @@ -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) + } } 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 19d4b1b..6de5430 100644 --- a/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt +++ b/filepicker/src/main/java/dev/arkbuilders/components/filepicker/ArkFilePickerViewModel.kt @@ -1,5 +1,6 @@ package dev.arkbuilders.components.filepicker +import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope @@ -44,6 +45,7 @@ internal sealed class FilePickerSideEffect { data object AlreadyFavorite : FilePickerSideEffect() data object PinAsFirstRoot : FilePickerSideEffect() data object CannotPinFile : FilePickerSideEffect() + data object NestedRootProhibited : FilePickerSideEffect() } @@ -190,6 +192,24 @@ 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) + + Log.d("tuancoltech", "rootsWithFavorites: " + rootsWithFavorites + + "\nroots: " + roots + + "\nfavorites: " + favorites + + "\nPining file: " + file.toString() + + "\nhasNestedRoot: " + hasNestedRoot) + + if (hasNestedRoot) { + Log.v("tuancoltech", "NestedRootProhibited file: " + file) + postSideEffect(FilePickerSideEffect.NestedRootProhibited) + return@intent + } + val haveRoot = haveRoot() root?.let { @@ -232,4 +252,9 @@ internal class ArkFilePickerViewModelFactory( override fun create(modelClass: Class): T = ArkFilePickerViewModel(deviceStorageUtils, mode, initialPath) as T +} + +fun Path.isChildOf(path: Path): Boolean { + val index = path.toString().indexOf(this.toString()) + return (index >= 0) && (path.toString()[index] == '/') } \ No newline at end of file diff --git a/filepicker/src/main/res/values/strings.xml b/filepicker/src/main/res/values/strings.xml index e7f016e..20116db 100644 --- a/filepicker/src/main/res/values/strings.xml +++ b/filepicker/src/main/res/values/strings.xml @@ -16,6 +16,7 @@ Already be a Favorite folder! Already be a Root folder! Only folder can be pinned. + There\'s already nested root(s) inside. Pin %d item diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 09a3470..d62b267 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ arkComponentUtils = "0.0.9-SNAPSHOT-01" akrComponentFoldersTree = "0.0.9-SNAPSHOT-02" akrComponentTagSelector = "0.0.9-SNAPSHOT-02" akrComponentScoreWidget = "0.0.9-SNAPSHOT-02" -arkComponentFilePicker = "0.1.0-SNAPSHOT" +arkComponentFilePicker = "0.1.1-SNAPSHOT-04" coil = "2.4.0" androidxFragmentKtx = "1.6.1" fastadapter = "5.7.0" diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 8ea98a7..53999fa 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -68,6 +68,12 @@ android { } } +buildscript { + repositories { + mavenLocal() + } +} + dependencies { implementation(libraries.ark.component.filepicker) implementation(libraries.arklib) diff --git a/settings.gradle.kts b/settings.gradle.kts index 265ee03..a970e4d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ pluginManagement { repositories { google() mavenCentral() + mavenLocal() gradlePluginPortal() } } @@ -12,6 +13,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + mavenLocal() maven { url = URI("https://jitpack.io") }