Skip to content

Commit

Permalink
🐛 Correct behaviors when the access is limited (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Dec 9, 2022
1 parent d39d74f commit cd1bbbd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,10 @@ that can be found in the LICENSE file. -->

- Allow overrides `viewAsset` in the `AssetPickerBuilderDelegate`. (#391)

### Fixes

- Correct behaviors when the access is limited on iOS. (#392)

## 8.1.4

### Fixes
Expand Down
40 changes: 27 additions & 13 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Expand Up @@ -800,34 +800,49 @@ class DefaultAssetPickerBuilderDelegate
if (!isPermissionLimited) {
return;
}
final PathWrapper<AssetPathEntity>? currentWrapper = provider.currentPath;
isSwitchingPath.value = false;
if (call.arguments is Map) {
final Map<dynamic, dynamic> arguments =
call.arguments as Map<dynamic, dynamic>;
if (arguments['newCount'] == 0) {
provider
..currentAssets = <AssetEntity>[]
..currentPath = null
..selectedAssets = <AssetEntity>[]
..hasAssetsToDisplay = false
..isAssetsEmpty = true;
..isAssetsEmpty = true
..totalAssetsCount = 0
..paths.clear();
return;
}
if (currentWrapper == null) {
await provider.getPaths();
}
}
await provider.getPaths();
provider.currentPath = provider.paths.first;
final PathWrapper<AssetPathEntity>? currentWrapper = provider.currentPath;
if (currentWrapper != null) {
final AssetPathEntity newPath =
await currentWrapper.path.obtainForNewProperties();
final int assetCount = await newPath.assetCountAsync;
final PathWrapper<AssetPathEntity> newPathWrapper =
PathWrapper<AssetPathEntity>(
path: newPath,
assetCount: assetCount,
);
provider
..currentPath = PathWrapper<AssetPathEntity>(path: newPath)
..currentPath = newPathWrapper
..hasAssetsToDisplay = assetCount != 0
..isAssetsEmpty = assetCount == 0
..totalAssetsCount = assetCount;
isSwitchingPath.value = false;
..totalAssetsCount = assetCount
..getThumbnailFromPath(newPathWrapper);
if (newPath.isAll) {
await provider.getAssetsFromCurrentPath();
final List<AssetEntity> entitiesShouldBeRemoved = <AssetEntity>[];
for (final AssetEntity entity in provider.selectedAssets) {
if (!provider.currentAssets.contains(entity)) {
entitiesShouldBeRemoved.add(entity);
}
}
entitiesShouldBeRemoved.forEach(provider.selectedAssets.remove);
}
}
}
Expand Down Expand Up @@ -1395,7 +1410,7 @@ class DefaultAssetPickerBuilderDelegate

// Return actual length if the current path is all.
// 如果当前目录是全部内容,则返回实际的内容数量。
if (currentPathEntity?.isAll != true) {
if (currentPathEntity?.isAll != true && specialItem == null) {
return length;
}
switch (specialItemPosition) {
Expand Down Expand Up @@ -1706,14 +1721,13 @@ class DefaultAssetPickerBuilderDelegate
return UnconstrainedBox(
child: GestureDetector(
onTap: () {
if (provider.currentPath == null) {
return;
}
Feedback.forTap(context);
if (isPermissionLimited && provider.isAssetsEmpty) {
PhotoManager.presentLimited();
return;
}
if (provider.currentPath == null) {
return;
}
isSwitchingPath.value = !isSwitchingPath.value;
},
child: Container(
Expand Down
27 changes: 9 additions & 18 deletions lib/src/provider/asset_picker_provider.dart
Expand Up @@ -133,7 +133,7 @@ abstract class AssetPickerProvider<Asset, Path> extends ChangeNotifier {
/// for the first asset under the path.
/// 使用 [Map] 来保存路径下第一个资源的缩略图数据
List<PathWrapper<Path>> get paths => _paths;
final List<PathWrapper<Path>> _paths = <PathWrapper<Path>>[];
List<PathWrapper<Path>> _paths = <PathWrapper<Path>>[];

/// Set thumbnail [data] for the specific [path].
/// 为指定的路径设置缩略图数据
Expand Down Expand Up @@ -310,6 +310,8 @@ class DefaultAssetPickerProvider
sizeConstraint: SizeConstraint(ignoreSize: true),
),
containsPathModified: sortPathsByModifiedDate,
createTimeCond: DateTimeCond.def().copyWith(ignore: true),
updateTimeCond: DateTimeCond.def().copyWith(ignore: true),
);

// Merge user's filter option into base options if it's not null.
Expand All @@ -322,19 +324,9 @@ class DefaultAssetPickerProvider
filterOption: options,
);

for (final AssetPathEntity pathEntity in list) {
final int index = _paths.indexWhere(
(PathWrapper<AssetPathEntity> p) => p.path.id == pathEntity.id,
);
final PathWrapper<AssetPathEntity> wrapper = PathWrapper<AssetPathEntity>(
path: pathEntity,
);
if (index == -1) {
_paths.add(wrapper);
} else {
_paths[index] = wrapper;
}
}
_paths = list
.map((AssetPathEntity p) => PathWrapper<AssetPathEntity>(path: p))
.toList();
// Sort path using sort path delegate.
Singleton.sortPathDelegate.sort(_paths);
// Use sync method to avoid unnecessary wait.
Expand All @@ -357,11 +349,10 @@ class DefaultAssetPickerProvider
size: pageSize,
);
if (page == 0) {
_currentAssets = list;
} else {
_currentAssets.addAll(list);
_currentAssets.clear();
}
_hasAssetsToDisplay = currentAssets.isNotEmpty;
_currentAssets.addAll(list);
_hasAssetsToDisplay = _currentAssets.isNotEmpty;
notifyListeners();
}

Expand Down

0 comments on commit cd1bbbd

Please sign in to comment.