@@ -30,7 +30,9 @@ import java.util.concurrent.locks.ReentrantLock
30
30
import kotlin.concurrent.withLock
31
31
32
32
// / create 2019-09-11 by cai
33
+ @Suppress(" DEPRECATION" )
33
34
@RequiresApi(Build .VERSION_CODES .Q )
35
+ @SuppressLint(" Recycle" )
34
36
object AndroidQDBUtils : IDBUtils {
35
37
private const val TAG = " PhotoManagerPlugin"
36
38
@@ -144,7 +146,7 @@ object AndroidQDBUtils : IDBUtils {
144
146
? : return emptyList()
145
147
146
148
while (cursor.moveToNext()) {
147
- val asset = convertCursorToAssetEntity(cursor, requestType )
149
+ val asset = convertCursorToAssetEntity(cursor)
148
150
list.add(asset)
149
151
cache.putAsset(asset)
150
152
}
@@ -187,7 +189,7 @@ object AndroidQDBUtils : IDBUtils {
187
189
? : return emptyList()
188
190
189
191
while (cursor.moveToNext()) {
190
- val asset = convertCursorToAssetEntity(cursor, requestType )
192
+ val asset = convertCursorToAssetEntity(cursor)
191
193
list.add(asset)
192
194
cache.putAsset(asset)
193
195
}
@@ -198,13 +200,13 @@ object AndroidQDBUtils : IDBUtils {
198
200
199
201
}
200
202
201
- private fun convertCursorToAssetEntity (cursor : Cursor , requestType : Int ): AssetEntity {
203
+ private fun convertCursorToAssetEntity (cursor : Cursor ): AssetEntity {
202
204
val id = cursor.getString(MediaStore .MediaColumns ._ID )
203
205
val path = cursor.getString(MediaStore .MediaColumns .DATA )
204
206
val date = cursor.getLong(MediaStore .Images .Media .DATE_TAKEN )
205
207
val type = cursor.getInt(MEDIA_TYPE )
206
208
207
- val duration = if (type == MediaStore . Files . FileColumns . MEDIA_TYPE_IMAGE ) 0 else cursor.getLong(MediaStore .Video .VideoColumns .DURATION )
209
+ val duration = if (type == MEDIA_TYPE_IMAGE ) 0 else cursor.getLong(MediaStore .Video .VideoColumns .DURATION )
208
210
val width = cursor.getInt(MediaStore .MediaColumns .WIDTH )
209
211
val height = cursor.getInt(MediaStore .MediaColumns .HEIGHT )
210
212
val displayName = cursor.getString(MediaStore .Images .Media .DISPLAY_NAME )
@@ -221,21 +223,20 @@ object AndroidQDBUtils : IDBUtils {
221
223
222
224
val keys = (IDBUtils .storeImageKeys + IDBUtils .typeKeys + IDBUtils .storeVideoKeys).distinct().toTypedArray()
223
225
224
- val selection = " ${ MediaStore . Files . FileColumns . _ID } = ?"
226
+ val selection = " $_ID = ?"
225
227
226
228
val args = arrayOf(id)
227
229
228
230
val cursor = context.contentResolver.query(allUri, keys, selection, args, null )
229
231
cursor?.use {
230
- if (cursor.moveToNext()) {
231
- val type = cursor.getInt(MEDIA_TYPE )
232
- val dbAsset = convertCursorToAssetEntity(cursor, type)
232
+ return if (cursor.moveToNext()) {
233
+ val dbAsset = convertCursorToAssetEntity(cursor)
233
234
cacheContainer.putAsset(dbAsset)
234
235
cursor.close()
235
- return dbAsset
236
+ dbAsset
236
237
} else {
237
238
cursor.close()
238
- return null
239
+ null
239
240
}
240
241
}
241
242
return null
@@ -377,7 +378,7 @@ object AndroidQDBUtils : IDBUtils {
377
378
val uri = MediaStore .Images .Media .EXTERNAL_CONTENT_URI
378
379
379
380
val values = ContentValues ().apply {
380
- put(MEDIA_TYPE , MediaStore . Files . FileColumns . MEDIA_TYPE_IMAGE )
381
+ put(MEDIA_TYPE , MEDIA_TYPE_IMAGE )
381
382
382
383
put(MediaStore .MediaColumns .DISPLAY_NAME , title)
383
384
put(MediaStore .Images .ImageColumns .MIME_TYPE , typeFromStream)
@@ -423,7 +424,7 @@ object AndroidQDBUtils : IDBUtils {
423
424
val uri = MediaStore .Images .Media .EXTERNAL_CONTENT_URI
424
425
425
426
val values = ContentValues ().apply {
426
- put(MEDIA_TYPE , MediaStore . Files . FileColumns . MEDIA_TYPE_IMAGE )
427
+ put(MEDIA_TYPE , MEDIA_TYPE_IMAGE )
427
428
428
429
put(MediaStore .MediaColumns .DISPLAY_NAME , title)
429
430
put(MediaStore .Images .ImageColumns .MIME_TYPE , typeFromStream)
@@ -480,7 +481,7 @@ object AndroidQDBUtils : IDBUtils {
480
481
481
482
val mediaType = convertTypeToMediaType(asset.type)
482
483
483
- if (mediaType == MediaStore . Files . FileColumns . MEDIA_TYPE_VIDEO ) {
484
+ if (mediaType == MEDIA_TYPE_VIDEO ) {
484
485
copyKeys.add(MediaStore .Video .VideoColumns .DESCRIPTION )
485
486
}
486
487
@@ -500,7 +501,7 @@ object AndroidQDBUtils : IDBUtils {
500
501
put(key, cursor.getString(key))
501
502
}
502
503
put(MEDIA_TYPE , mediaType)
503
- put(MediaStore . Files . FileColumns . RELATIVE_PATH , relativePath)
504
+ put(RELATIVE_PATH , relativePath)
504
505
}
505
506
506
507
val insertedUri = cr.insert(insertUri, cv) ? : throwMsg(" Cannot insert new asset." )
@@ -592,8 +593,8 @@ object AndroidQDBUtils : IDBUtils {
592
593
Log .i(TAG , " The removeAllExistsAssets was stopped, will be delete ids = $removedList " )
593
594
}
594
595
595
- val idWhere = removedList.map { " ?" }.joinToString( " , " )
596
-
596
+ val idWhere = removedList.joinToString( " , " ) { " ?" }
597
+
597
598
// Remove exists rows.
598
599
val deleteRowCount = cr.delete(allUri, " ${BaseColumns ._ID } in ( $idWhere )" , removedList.toTypedArray())
599
600
Log .i(" PhotoManagerPlugin" , " Delete rows: $deleteRowCount " )
@@ -605,7 +606,7 @@ object AndroidQDBUtils : IDBUtils {
605
606
private fun getRelativePath (context : Context , galleryId : String ): String? {
606
607
val cr = context.contentResolver
607
608
608
- val cursor = cr.query(allUri, arrayOf(MediaStore . Files . FileColumns . BUCKET_ID , MediaStore . Files . FileColumns . RELATIVE_PATH ), " ${ MediaStore . Files . FileColumns . BUCKET_ID } = ?" , arrayOf(galleryId), null )
609
+ val cursor = cr.query(allUri, arrayOf(BUCKET_ID , RELATIVE_PATH ), " $BUCKET_ID = ?" , arrayOf(galleryId), null )
609
610
? : return null
610
611
611
612
cursor.use {
@@ -619,7 +620,7 @@ object AndroidQDBUtils : IDBUtils {
619
620
override fun getSomeInfo (context : Context , assetId : String ): Pair <String , String >? {
620
621
val cr = context.contentResolver
621
622
622
- val cursor = cr.query(allUri, arrayOf(MediaStore . Files . FileColumns . BUCKET_ID , MediaStore . Files . FileColumns . RELATIVE_PATH ), " ${ MediaStore . Files . FileColumns . _ID } = ?" , arrayOf(assetId), null )
623
+ val cursor = cr.query(allUri, arrayOf(BUCKET_ID , RELATIVE_PATH ), " $_ID = ?" , arrayOf(assetId), null )
623
624
? : return null
624
625
625
626
cursor.use {
@@ -646,7 +647,7 @@ object AndroidQDBUtils : IDBUtils {
646
647
val info = VideoUtils .getPropertiesUseMediaPlayer(path)
647
648
648
649
val values = ContentValues ().apply {
649
- put(MEDIA_TYPE , MediaStore . Files . FileColumns . MEDIA_TYPE_VIDEO )
650
+ put(MEDIA_TYPE , MEDIA_TYPE_VIDEO )
650
651
651
652
put(MediaStore .MediaColumns .DISPLAY_NAME , title)
652
653
put(MediaStore .Video .VideoColumns .MIME_TYPE , typeFromStream)
0 commit comments