Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
majid committed Jul 11, 2023
2 parents deb4f92 + 3500bd3 commit 2354205
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 3 additions & 3 deletions file-picker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -70,7 +70,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.majidarabi'
artifactId = 'file-picker'
version = '0.2.1'
version = '0.2.2'
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions file-picker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ir.one_developer.file_picker">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application android:requestLegacyExternalStorage="true"/>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<application android:requestLegacyExternalStorage="true" />

</manifest>
22 changes: 20 additions & 2 deletions file-picker/src/main/java/com/github/file_picker/FilePicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -278,14 +280,30 @@ 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
}
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class FilesPagingSource(
) : PagingSource<Int, Media>() {

// 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, Media>): Int? =
state.anchorPosition?.let { anchorPosition ->
Expand Down

0 comments on commit 2354205

Please sign in to comment.