Skip to content

Commit

Permalink
Merge pull request #100 from ParkSangGwon/feature/fix-media-util-path
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkSangGwon authored Jan 19, 2022
2 parents d8280ae + 8f12b37 commit 8d2ad18
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 5 additions & 1 deletion tedimagepicker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="gun0912.tedimagepicker">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
tools:ignore="ScopedStorage" />

<queries>
<intent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Build
import android.os.Parcelable
import androidx.annotation.AnimRes
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.gun0912.tedpermission.TedPermissionResult
import com.gun0912.tedpermission.rx2.TedPermission
import com.tedpark.tedonactivityresult.rx2.TedRxOnActivityResult
import gun0912.tedimagepicker.R
Expand All @@ -25,6 +27,7 @@ import gun0912.tedimagepicker.builder.type.ButtonGravity
import gun0912.tedimagepicker.builder.type.MediaType
import gun0912.tedimagepicker.builder.type.SelectType
import gun0912.tedimagepicker.util.ToastUtil
import io.reactivex.Single
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize

Expand Down Expand Up @@ -102,9 +105,19 @@ open class TedImagePickerBaseBuilder<out B : TedImagePickerBaseBuilder<B>>(
}, { throwable -> onErrorListener?.onError(throwable) })
}

private fun checkPermission(context: Context) = TedPermission.create()
.setPermissions(Manifest.permission.READ_EXTERNAL_STORAGE)
.request()
private fun checkPermission(context: Context): Single<TedPermissionResult> {
val permissions = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
)
} else {
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE)
}
return TedPermission.create()
.setPermissions(*permissions)
.request()
}

private fun startActivity(context: Context) {
TedImagePickerActivity.getIntent(context, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ internal class GalleryUtil {
}

val sortOrder = "$INDEX_DATE_ADDED DESC"
val projection =
arrayOf(INDEX_MEDIA_ID, INDEX_MEDIA_URI, albumName, INDEX_DATE_ADDED)
val selection = MediaStore.Images.Media.SIZE + " > 0"

val projection = arrayOf(
INDEX_MEDIA_ID,
INDEX_MEDIA_URI,
albumName,
INDEX_DATE_ADDED
)
val selection = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaStore.Images.Media.SIZE + " > 0"
} else {
null
}
val cursor =
context.contentResolver.query(uri, projection, selection, null, sortOrder)
val albumList: List<Album> = cursor?.let {
Expand Down

0 comments on commit 8d2ad18

Please sign in to comment.