Skip to content

Commit

Permalink
Simplify the usage of ContentResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanCaiCoding committed Oct 10, 2021
1 parent 5990b4a commit ba4d045
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions longan/src/main/java/com/dylanc/longan/ContentResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,6 @@ inline fun <R> ContentResolver.queryMediaImages(
): R? =
query(EXTERNAL_MEDIA_IMAGES_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryFirstMediaImage(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryFirst(EXTERNAL_MEDIA_IMAGES_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryLastMediaImage(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryLast(EXTERNAL_MEDIA_IMAGES_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryMediaVideos(
projection: Array<String>? = null,
selection: String? = null,
Expand All @@ -104,24 +86,6 @@ inline fun <R> ContentResolver.queryMediaVideos(
): R? =
query(EXTERNAL_MEDIA_VIDEO_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryFirstMediaVideo(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryFirst(EXTERNAL_MEDIA_VIDEO_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryLastMediaVideo(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryLast(EXTERNAL_MEDIA_VIDEO_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryMediaAudios(
projection: Array<String>? = null,
selection: String? = null,
Expand All @@ -131,24 +95,6 @@ inline fun <R> ContentResolver.queryMediaAudios(
): R? =
query(EXTERNAL_MEDIA_AUDIO_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryFirstMediaAudio(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryFirst(EXTERNAL_MEDIA_AUDIO_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun <R> ContentResolver.queryLastMediaAudio(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryLast(EXTERNAL_MEDIA_AUDIO_URI, projection, selection, selectionArgs, sortOrder, block)

@RequiresApi(Build.VERSION_CODES.Q)
inline fun <R> ContentResolver.queryMediaDownloads(
projection: Array<String>? = null,
Expand All @@ -159,26 +105,6 @@ inline fun <R> ContentResolver.queryMediaDownloads(
): R? =
query(EXTERNAL_MEDIA_DOWNLOADS_URI, projection, selection, selectionArgs, sortOrder, block)

@RequiresApi(Build.VERSION_CODES.Q)
inline fun <R> ContentResolver.queryFirstMediaDownload(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryFirst(EXTERNAL_MEDIA_DOWNLOADS_URI, projection, selection, selectionArgs, sortOrder, block)

@RequiresApi(Build.VERSION_CODES.Q)
inline fun <R> ContentResolver.queryLastMediaDownload(
projection: Array<String>? = null,
selection: String? = null,
selectionArgs: Array<String>? = null,
sortOrder: String? = null,
block: (Cursor) -> R
): R? =
queryLast(EXTERNAL_MEDIA_DOWNLOADS_URI, projection, selection, selectionArgs, sortOrder, block)

inline fun ContentResolver.insert(uri: Uri, crossinline block: ContentValues.() -> Unit = {}): Uri? =
contentResolver.insert(uri, contentValues(block))

Expand Down

0 comments on commit ba4d045

Please sign in to comment.