From 2cdfab30a651f31bb0d1c8770e1ffa708cbaaedc Mon Sep 17 00:00:00 2001 From: majid Date: Wed, 5 Jul 2023 13:09:45 +0330 Subject: [PATCH 1/2] removed unnecessary maven repositories. --- settings.gradle | 4 ---- 1 file changed, 4 deletions(-) diff --git a/settings.gradle b/settings.gradle index d530fef..7bda480 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,6 @@ pluginManagement { repositories { gradlePluginPortal() - maven { url 'https://gradle.iranrepo.ir' } - maven { url 'https://maven.google.com' } google() mavenCentral() } @@ -11,8 +9,6 @@ dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { gradlePluginPortal() - maven { url 'https://gradle.iranrepo.ir' } - maven { url 'https://maven.google.com' } maven { url 'https://jitpack.io' } google() mavenCentral() From 3500bd3d652f6d6de8a20f4bddfdf1b18b3fa9a3 Mon Sep 17 00:00:00 2001 From: majid Date: Tue, 11 Jul 2023 12:48:32 +0330 Subject: [PATCH 2/2] Close #5 --- app/build.gradle | 4 ++-- file-picker/build.gradle | 6 ++--- file-picker/src/main/AndroidManifest.xml | 11 ++++++++-- .../java/com/github/file_picker/FilePicker.kt | 22 +++++++++++++++++-- .../data/repository/FilesPagingSource.kt | 2 +- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fa31fd0..6a17768 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdk 31 + compileSdk 33 defaultConfig { applicationId "ir.one_developer.filepickerlibrary" minSdk 21 - targetSdk 31 + targetSdk 33 versionCode 1 versionName "1.0" diff --git a/file-picker/build.gradle b/file-picker/build.gradle index b93338e..b056ea4 100644 --- a/file-picker/build.gradle +++ b/file-picker/build.gradle @@ -6,11 +6,11 @@ plugins { } android { - compileSdk 31 + compileSdk 33 defaultConfig { minSdk 21 - targetSdk 31 + targetSdk 33 vectorDrawables.useSupportLibrary = true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -70,7 +70,7 @@ afterEvaluate { from components.release groupId = 'com.github.majidarabi' artifactId = 'file-picker' - version = '0.2.1' + version = '0.2.2' } } } diff --git a/file-picker/src/main/AndroidManifest.xml b/file-picker/src/main/AndroidManifest.xml index 27a5330..c8e1cc9 100644 --- a/file-picker/src/main/AndroidManifest.xml +++ b/file-picker/src/main/AndroidManifest.xml @@ -2,7 +2,14 @@ - - + + + + + + + \ No newline at end of file diff --git a/file-picker/src/main/java/com/github/file_picker/FilePicker.kt b/file-picker/src/main/java/com/github/file_picker/FilePicker.kt index 934ff52..e1cde04 100644 --- a/file-picker/src/main/java/com/github/file_picker/FilePicker.kt +++ b/file-picker/src/main/java/com/github/file_picker/FilePicker.kt @@ -4,6 +4,7 @@ import android.Manifest import android.content.DialogInterface import android.content.res.ColorStateList import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -263,7 +264,8 @@ class FilePicker private constructor( } override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, + inflater: LayoutInflater, + container: ViewGroup?, savedInstanceState: Bundle? ): View { _binding = FilePickerBinding.inflate(inflater, container, false) @@ -278,7 +280,7 @@ class FilePicker private constructor( override fun onStart() { super.onStart() - val readStoragePermission = Manifest.permission.READ_EXTERNAL_STORAGE + val readStoragePermission = getRequiredPermissionByType() if (!hasPermission(readStoragePermission)) { requestPermission(readStoragePermission) return @@ -286,6 +288,22 @@ class FilePicker private constructor( loadFiles() } + /** + * Get required permission by file type + * + * @return the permission + */ + private fun getRequiredPermissionByType() : String { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + return when(fileType) { + FileType.AUDIO -> Manifest.permission.READ_MEDIA_AUDIO + FileType.VIDEO -> Manifest.permission.READ_MEDIA_VIDEO + FileType.IMAGE -> Manifest.permission.READ_MEDIA_IMAGES + } + } + return Manifest.permission.READ_EXTERNAL_STORAGE + } + override fun show(manager: FragmentManager, tag: String?) { if (isShown) return super.show(manager, tag) diff --git a/file-picker/src/main/java/com/github/file_picker/data/repository/FilesPagingSource.kt b/file-picker/src/main/java/com/github/file_picker/data/repository/FilesPagingSource.kt index bf079cc..6385b4a 100644 --- a/file-picker/src/main/java/com/github/file_picker/data/repository/FilesPagingSource.kt +++ b/file-picker/src/main/java/com/github/file_picker/data/repository/FilesPagingSource.kt @@ -13,7 +13,7 @@ internal class FilesPagingSource( ) : PagingSource() { // the initial load size for the first page may be different from the requested size - var initialLoadSize: Int = 0 + private var initialLoadSize: Int = 0 override fun getRefreshKey(state: PagingState): Int? = state.anchorPosition?.let { anchorPosition ->