Skip to content

Commit 41d6c60

Browse files
committed
android api 30 pageable
1 parent 58246d2 commit 41d6c60

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

android/src/main/kotlin/top/kikt/imagescanner/core/utils/Android30DbUtils.kt

+24-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ object Android30DbUtils : IDBUtils {
125125
return "$DATE_ADDED $asc"
126126
}
127127

128+
129+
private fun cursorWithRange(cursor: Cursor, start: Int, pageSize: Int, block: (cursor: Cursor) -> Unit) {
130+
cursor.moveToPosition(start - 1)
131+
132+
for (i in 0 until pageSize) {
133+
if (cursor.moveToNext()) {
134+
block(cursor)
135+
}
136+
}
137+
}
138+
128139
@SuppressLint("Recycle")
129140
override fun getAssetFromGalleryId(context: Context, galleryId: String, page: Int, pageSize: Int, requestType: Int, timeStamp: Long, option: FilterOption, cacheContainer: CacheContainer?): List<AssetEntity> {
130141

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

159-
while (cursor.moveToNext()) {
170+
cursorWithRange(cursor, page * pageSize, pageSize) {
160171
val asset = convertCursorToAssetEntity(cursor)
161172
list.add(asset)
162173
}
163174

175+
// while (cursor.moveToNext()) {
176+
// val asset = convertCursorToAssetEntity(cursor)
177+
// list.add(asset)
178+
// }
179+
164180
cursor.close()
165181

166182
return list
167183

168184
}
169185

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

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

199-
while (cursor.moveToNext()) {
216+
cursorWithRange(cursor, start, pageSize) {
200217
val asset = convertCursorToAssetEntity(cursor)
201218
list.add(asset)
202219
}
203220

221+
// while (cursor.moveToNext()) {
222+
// val asset = convertCursorToAssetEntity(cursor)
223+
// list.add(asset)
224+
// }
225+
204226
cursor.close()
205227

206228
return list

example/lib/model/photo_provider.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class PhotoProvider extends ChangeNotifier {
6868
String maxWidth = "10000";
6969
String minHeight = "0";
7070
String maxHeight = "10000";
71-
bool _ignoreSize = false;
71+
bool _ignoreSize = true;
7272

7373
bool get ignoreSize => _ignoreSize;
7474

@@ -240,7 +240,7 @@ class AssetPathProvider extends ChangeNotifier {
240240
}
241241

242242
Future<void> onLoadMore() async {
243-
if (showItemCount > path.assetCount) {
243+
if (showItemCount >= path.assetCount) {
244244
print("already max");
245245
return;
246246
}

log/android/android-30.info.log

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
2020-09-23 13:56:03.749 9627-9689/top.kikt.imagescannerexample D/PhotoManagerPluginLogger:
2+
id: 540528482
3+
|--instance_id : null
4+
|--compilation : null
5+
|--disc_number : null
6+
|--duration : null
7+
|--album_artist : null
8+
|--resolution : 4032×3024
9+
|--orientation : 90
10+
|--artist : null
11+
|--author : null
12+
|--format : 14336
13+
|--height : 3024
14+
|--is_drm : 0
15+
|--bucket_display_name : Download
16+
|--owner_package_name : null
17+
|--parent : 11
18+
|--volume_name : external_primary
19+
|--date_modified : 1592527158
20+
|--writer : null
21+
|--date_expires : null
22+
|--composer : null
23+
|--_display_name : 73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
24+
|--datetaken : 1541819329175
25+
|--mime_type : image/heic
26+
|--bitrate : null
27+
|--cd_track_number : null
28+
|--_id : 42
29+
|--xmp : blob(0)
30+
|--year : null
31+
|--_data : /storage/emulated/0/Download/73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
32+
|--_size : 1016658
33+
|--album : null
34+
|--genre : null
35+
|--title : 73646391-2EFE-420E-9B04-6BE5A974F6FD
36+
|--width : 4032
37+
|--is_favorite : 0
38+
|--is_trashed : 0
39+
|--group_id : null
40+
|--document_id : null
41+
|--generation_added : 141
42+
|--is_download : 1
43+
|--generation_modified : 141
44+
|--is_pending : 0
45+
|--date_added : 1600839153
46+
|--capture_framerate : null
47+
|--num_tracks : null
48+
|--original_document_id : null
49+
|--media_type : 1
50+
2020-09-23 13:56:03.749 9627-9689/top.kikt.imagescannerexample D/PhotoManagerPluginLogger: id: 540528482
51+
|--instance_id : null
52+
|--compilation : null
53+
|--disc_number : null
54+
|--duration : null
55+
|--album_artist : null
56+
|--resolution : 4032×3024
57+
|--orientation : 90
58+
|--artist : null
59+
|--author : null
60+
|--format : 14336
61+
|--height : 3024
62+
|--is_drm : 0
63+
|--bucket_display_name : Download
64+
|--owner_package_name : null
65+
|--parent : 11
66+
|--volume_name : external_primary
67+
|--date_modified : 1592527158
68+
|--writer : null
69+
|--date_expires : null
70+
|--composer : null
71+
|--_display_name : 73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
72+
|--datetaken : 1541819329175
73+
|--mime_type : image/heic
74+
|--bitrate : null
75+
|--cd_track_number : null
76+
|--_id : 42
77+
|--xmp : blob(0)
78+
|--year : null
79+
|--_data : /storage/emulated/0/Download/73646391-2EFE-420E-9B04-6BE5A974F6FD.heic
80+
|--_size : 1016658
81+
|--album : null
82+
|--genre : null
83+
|--title : 73646391-2EFE-420E-9B04-6BE5A974F6FD
84+
|--width : 4032
85+
|--is_favorite : 0
86+
|--is_trashed : 0
87+
|--group_id : null
88+
|--document_id : null
89+
|--generation_added : 141
90+
|--is_download : 1
91+
|--generation_modified : 141
92+
|--is_pending : 0
93+
|--date_added : 1600839153
94+
|--capture_framerate : null
95+
|--num_tracks : null
96+
|--original_document_id : null
97+
|--media_type : 1
98+
|--relative_path : Download/

0 commit comments

Comments
 (0)