diff --git a/CHANGELOG.md b/CHANGELOG.md index 663d73c5..86ef0a4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ To know more about breaking changes, see the [Migration Guide][]. *None.* +## 3.6.1 + +### Fixes + +- Do not throw when querying not existing assets in bulk on Android. + ## 3.6.0 ### Features diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt index 5900002d..268e451d 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/AndroidQDBUtils.kt @@ -163,7 +163,7 @@ object AndroidQDBUtils : IDBUtils { ) cursor.use { cursorWithRange(it, page * size, size) { cursor -> - cursor.toAssetEntity(context).apply { + cursor.toAssetEntity(context, throwIfNotExists = false)?.apply { list.add(this) } } @@ -203,7 +203,7 @@ object AndroidQDBUtils : IDBUtils { ) cursor.use { cursorWithRange(it, start, pageSize) { cursor -> - cursor.toAssetEntity(context).apply { + cursor.toAssetEntity(context, throwIfNotExists = false)?.apply { list.add(this) } } diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt index 27cb68ad..2b610402 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/DBUtils.kt @@ -160,7 +160,7 @@ object DBUtils : IDBUtils { ) cursor.use { while (it.moveToNext()) { - it.toAssetEntity(context).apply { + it.toAssetEntity(context, throwIfNotExists = false)?.apply { list.add(this) } } @@ -201,7 +201,7 @@ object DBUtils : IDBUtils { ) cursor.use { while (it.moveToNext()) { - it.toAssetEntity(context).apply { + it.toAssetEntity(context, throwIfNotExists = false)?.apply { list.add(this) } } diff --git a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt index ba9875e6..4e299563 100644 --- a/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt +++ b/android/src/main/kotlin/com/fluttercandies/photo_manager/core/utils/IDBUtils.kt @@ -169,11 +169,18 @@ interface IDBUtils { return getDouble(getColumnIndex(columnName)) } - fun Cursor.toAssetEntity(context: Context, checkIfExists: Boolean = true): AssetEntity { + fun Cursor.toAssetEntity( + context: Context, + checkIfExists: Boolean = true, + throwIfNotExists: Boolean = true, + ): AssetEntity? { val id = getLong(_ID) val path = getString(DATA) if (checkIfExists && path.isNotBlank() && !File(path).exists()) { - throwMsg("Asset ($id) does not exists at its path ($path).") + if (throwIfNotExists) { + throwMsg("Asset ($id) does not exists at its path ($path).") + } + return null } val date = if (isAboveAndroidQ) { @@ -699,7 +706,7 @@ interface IDBUtils { val result = ArrayList() it.moveToPosition(start - 1) while (it.moveToNext()) { - val asset = it.toAssetEntity(context, false) + val asset = it.toAssetEntity(context, false) ?: continue result.add(asset) if (result.count() == end - start) { break diff --git a/lib/src/internal/plugin.dart b/lib/src/internal/plugin.dart index 76499740..91b2a071 100644 --- a/lib/src/internal/plugin.dart +++ b/lib/src/internal/plugin.dart @@ -183,7 +183,10 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin, OhosPlugin { return result; } - /// Use pagination to get album content. + /// Obtain assets with the pagination. + /// + /// The length of returned assets might be less than requested. + /// Not existing assets will be excluded from the result. Future> getAssetListPaged( String id, { required PMFilter optionGroup, @@ -204,7 +207,10 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin, OhosPlugin { return ConvertUtils.convertToAssetList(result.cast()); } - /// Asset in the specified range. + /// Obtain assets in the specified range. + /// + /// The length of returned assets might be less than requested. + /// Not existing assets will be excluded from the result. Future> getAssetListRange( String id, { required RequestType type, diff --git a/lib/src/types/entity.dart b/lib/src/types/entity.dart index bc019b46..8162bcb4 100644 --- a/lib/src/types/entity.dart +++ b/lib/src/types/entity.dart @@ -188,6 +188,9 @@ class AssetPathEntity { /// /// [page] should starts with and greater than 0. /// [size] is item count of current [page]. + /// + /// The length of returned assets might be less than requested. + /// Not existing assets will be excluded from the result. Future> getAssetListPaged({ required int page, required int size, @@ -206,8 +209,11 @@ class AssetPathEntity { /// Getting assets in range using [start] and [end]. /// /// The [start] and [end] are similar to [String.substring], but it'll return - /// the maxmium assets if the total count of assets is fewer than the range, + /// the maximum assets if the total count of assets is fewer than the range, /// instead of throwing a [RangeError] like [String.substring]. + /// + /// The length of returned assets might be less than requested. + /// Not existing assets will be excluded from the result. Future> getAssetListRange({ required int start, required int end, diff --git a/pubspec.yaml b/pubspec.yaml index dafdc526..7c630d88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: photo_manager description: A Flutter plugin that provides album assets abstraction management APIs on Android, iOS, macOS, and OpenHarmony. repository: https://github.com/fluttercandies/flutter_photo_manager -version: 3.6.0 +version: 3.6.1 environment: sdk: ">=2.13.0 <4.0.0"