Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nukc/qoo
File Scan, Permissions Request, Easier to do things.
https://github.com/nukc/qoo
files imagepicker permission-requests
Last synced: 29 days ago
JSON representation
File Scan, Permissions Request, Easier to do things.
- Host: GitHub
- URL: https://github.com/nukc/qoo
- Owner: nukc
- Created: 2020-08-31T08:18:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T02:17:34.000Z (over 3 years ago)
- Last Synced: 2024-10-14T11:26:17.229Z (3 months ago)
- Topics: files, imagepicker, permission-requests
- Language: Kotlin
- Homepage:
- Size: 1.52 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Qoo
```groovy
implementation 'com.github.nukc.permissionrer:permissionrer:1.0'```
> Scanner
文件扫描,可通过 ``Path`` 或 ``Uri`` 。
主要是通过实现 ``BasePathMatcher`` 或 ``BaseUriMatcher``。
Image Picker Demo:
> PermissionRer
权限请求
```kotlin
PermissionRer.with(activity)
.request(Manifest.permission.READ_EXTERNAL_STORAGE)
.subscribe { granted, permissions ->
if (granted) {
activity.startActivityForResult(
Intent(activity, ImagePickerActivity::class.java),
REQUEST_CODE
)
} else if (permissions[0].shouldShowRequestPermissionRationale) {
Toast.makeText(activity, R.string.tils_select_image_need_read_image_permission, Toast.LENGTH_SHORT).show()
}
}
```#### 用法示例:
```kotlin
viewModelScope.launch {
val fileBox = FileScanner.build(context)
.scan(ImageMatcher())
.scan(ApkMatcher())
.scan(InvalidImageMatcher(), InvalidVideoMatcher())
.setScanListener(..)
.start()
}
```Scan Listener:
```kotlin
interface OnScanListener {
fun onScanStart()fun onScanning(item: BaseItem)
fun onScanEnd()
}
```Matcher eg:
```kotlin
/**
* image matcher, eg: jpg, gif, png
* @author Nukc.
*/
open class ImageMatcher : BaseUriMatcher() {override fun provideUri(): Uri {
return MediaStore.Images.Media.EXTERNAL_CONTENT_URI
}override fun provideProjection(): Array {
return getProjection()
}override fun provideSelection(): String? {
return null
}override fun provideSelectionArgs(): Array? {
return null
}override fun provideSortOrder(): String? {
return "${MediaStore.Files.FileColumns.DATE_ADDED} DESC"
}override fun fill(cur: Cursor): ImageItem {
val id = cur.getLong(cacheColumn[MediaStore.Images.Media._ID]!!)
val contentUri: Uri = ContentUris.withAppendedId(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
id
)
return ImageItem(
id = id,
name = cur.getString(cacheColumn[MediaStore.Images.Media.DISPLAY_NAME]!!),
path = cur.getString(cacheColumn[MediaStore.Images.Media.DATA]!!),
size = cur.getLong(cacheColumn[MediaStore.Images.Media.SIZE]!!),
dateAdded = cur.getLong(cacheColumn[MediaStore.Images.Media.DATE_ADDED]!!),
dateModified = cur.getLong(cacheColumn[MediaStore.Images.Media.DATE_MODIFIED]!!),
mimeType = cur.getString(cacheColumn[MediaStore.Images.Media.MIME_TYPE]!!),
contentUri = contentUri,
bucketName = cur.getString(cacheColumn[MediaStore.Files.FileColumns.BUCKET_DISPLAY_NAME]!!)
)
}private fun getProjection(): Array {
return arrayOf(
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.Images.Media.SIZE,
MediaStore.Images.Media.MIME_TYPE,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.DATE_ADDED,
MediaStore.Images.Media.DATE_MODIFIED,
MediaStore.Files.FileColumns.BUCKET_ID,
MediaStore.Files.FileColumns.BUCKET_DISPLAY_NAME
)
}
}
```### TODO:
* [x] Demo
* [x] Image Picker