Skip to content

Commit

Permalink
android api 30 pageable
Browse files Browse the repository at this point in the history
  • Loading branch information
CaiJingLong committed Sep 23, 2020
1 parent 58246d2 commit 41d6c60
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 4 deletions.
Expand Up @@ -125,6 +125,17 @@ object Android30DbUtils : IDBUtils {
return "$DATE_ADDED $asc"
}


private fun cursorWithRange(cursor: Cursor, start: Int, pageSize: Int, block: (cursor: Cursor) -> Unit) {
cursor.moveToPosition(start - 1)

for (i in 0 until pageSize) {
if (cursor.moveToNext()) {
block(cursor)
}
}
}

@SuppressLint("Recycle")
override fun getAssetFromGalleryId(context: Context, galleryId: String, page: Int, pageSize: Int, requestType: Int, timeStamp: Long, option: FilterOption, cacheContainer: CacheContainer?): List<AssetEntity> {

Expand Down Expand Up @@ -156,17 +167,23 @@ object Android30DbUtils : IDBUtils {
val cursor = context.contentResolver.query(uri, keys, selection, args.toTypedArray(), sortOrder)
?: return emptyList()

while (cursor.moveToNext()) {
cursorWithRange(cursor, page * pageSize, pageSize) {
val asset = convertCursorToAssetEntity(cursor)
list.add(asset)
}

// while (cursor.moveToNext()) {
// val asset = convertCursorToAssetEntity(cursor)
// list.add(asset)
// }

cursor.close()

return list

}


override fun getAssetFromGalleryIdRange(context: Context, gId: String, start: Int, end: Int, requestType: Int, timestamp: Long, option: FilterOption): List<AssetEntity> {
val isAll = gId.isEmpty()

Expand Down Expand Up @@ -196,11 +213,16 @@ object Android30DbUtils : IDBUtils {
val cursor = context.contentResolver.query(uri, keys, selection, args.toTypedArray(), sortOrder)
?: return emptyList()

while (cursor.moveToNext()) {
cursorWithRange(cursor, start, pageSize) {
val asset = convertCursorToAssetEntity(cursor)
list.add(asset)
}

// while (cursor.moveToNext()) {
// val asset = convertCursorToAssetEntity(cursor)
// list.add(asset)
// }

cursor.close()

return list
Expand Down
4 changes: 2 additions & 2 deletions example/lib/model/photo_provider.dart
Expand Up @@ -68,7 +68,7 @@ class PhotoProvider extends ChangeNotifier {
String maxWidth = "10000";
String minHeight = "0";
String maxHeight = "10000";
bool _ignoreSize = false;
bool _ignoreSize = true;

bool get ignoreSize => _ignoreSize;

Expand Down Expand Up @@ -240,7 +240,7 @@ class AssetPathProvider extends ChangeNotifier {
}

Future<void> onLoadMore() async {
if (showItemCount > path.assetCount) {
if (showItemCount >= path.assetCount) {
print("already max");
return;
}
Expand Down
98 changes: 98 additions & 0 deletions log/android/android-30.info.log
@@ -0,0 +1,98 @@
2020-09-23 13:56:03.749 9627-9689/top.kikt.imagescannerexample D/PhotoManagerPluginLogger:
id: 540528482
|--instance_id : null
|--compilation : null
|--disc_number : null
|--duration : null
|--album_artist : null
|--resolution : 4032×3024
|--orientation : 90
|--artist : null
|--author : null
|--format : 14336
|--height : 3024
|--is_drm : 0
|--bucket_display_name : Download
|--owner_package_name : null
|--parent : 11
|--volume_name : external_primary
|--date_modified : 1592527158
|--writer : null
|--date_expires : null
|--composer : null
|--_display_name : 73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
|--datetaken : 1541819329175
|--mime_type : image/heic
|--bitrate : null
|--cd_track_number : null
|--_id : 42
|--xmp : blob(0)
|--year : null
|--_data : /storage/emulated/0/Download/73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
|--_size : 1016658
|--album : null
|--genre : null
|--title : 73646391-2EFE-420E-9B04-6BE5A974F6FD
|--width : 4032
|--is_favorite : 0
|--is_trashed : 0
|--group_id : null
|--document_id : null
|--generation_added : 141
|--is_download : 1
|--generation_modified : 141
|--is_pending : 0
|--date_added : 1600839153
|--capture_framerate : null
|--num_tracks : null
|--original_document_id : null
|--media_type : 1
2020-09-23 13:56:03.749 9627-9689/top.kikt.imagescannerexample D/PhotoManagerPluginLogger: id: 540528482
|--instance_id : null
|--compilation : null
|--disc_number : null
|--duration : null
|--album_artist : null
|--resolution : 4032×3024
|--orientation : 90
|--artist : null
|--author : null
|--format : 14336
|--height : 3024
|--is_drm : 0
|--bucket_display_name : Download
|--owner_package_name : null
|--parent : 11
|--volume_name : external_primary
|--date_modified : 1592527158
|--writer : null
|--date_expires : null
|--composer : null
|--_display_name : 73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
|--datetaken : 1541819329175
|--mime_type : image/heic
|--bitrate : null
|--cd_track_number : null
|--_id : 42
|--xmp : blob(0)
|--year : null
|--_data : /storage/emulated/0/Download/73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
|--_size : 1016658
|--album : null
|--genre : null
|--title : 73646391-2EFE-420E-9B04-6BE5A974F6FD
|--width : 4032
|--is_favorite : 0
|--is_trashed : 0
|--group_id : null
|--document_id : null
|--generation_added : 141
|--is_download : 1
|--generation_modified : 141
|--is_pending : 0
|--date_added : 1600839153
|--capture_framerate : null
|--num_tracks : null
|--original_document_id : null
|--media_type : 1
|--relative_path : Download/

0 comments on commit 41d6c60

Please sign in to comment.