Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements about recent issues #1186

Merged
merged 19 commits into from
Sep 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🚀 Expose withSubtype for isLocallyAvailable
  • Loading branch information
AlexV525 committed Sep 21, 2024
commit cf643bfab703a9de7a7497c0fa15a4aafd590133
3 changes: 2 additions & 1 deletion ios/Classes/PMPlugin.m
Original file line number Diff line number Diff line change
@@ -486,7 +486,8 @@ - (void)handleMethodResultHandler:(ResultHandler *)handler manager:(PMManager *)
} else if ([call.method isEqualToString:@"isLocallyAvailable"]) {
NSString *assetId = call.arguments[@"id"];
BOOL isOrigin = [call.arguments[@"isOrigin"] boolValue];
BOOL exists = [manager entityIsLocallyAvailable:assetId resource:nil isOrigin:isOrigin];
int subtype = [call.arguments[@"subtype"] intValue];
BOOL exists = [manager entityIsLocallyAvailable:assetId resource:nil isOrigin:isOrigin subtype:subtype];
[handler reply:@(exists)];
} else if ([call.method isEqualToString:@"getTitleAsync"]) {
NSString *assetId = call.arguments[@"id"];
2 changes: 1 addition & 1 deletion ios/Classes/core/PMManager.h
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ typedef void (^AssetBlockResult)(PMAssetEntity *, NSObject *);

- (BOOL)existsWithId:(NSString *)assetId;

- (BOOL)entityIsLocallyAvailable:(NSString *)assetId resource:(PHAssetResource *)resource isOrigin:(BOOL)isOrigin;
- (BOOL)entityIsLocallyAvailable:(NSString *)assetId resource:(PHAssetResource *)resource isOrigin:(BOOL)isOrigin subtype:(int)subtype;

- (NSString*)getTitleAsyncWithAssetId:(NSString *)assetId subtype:(int)subtype;

12 changes: 11 additions & 1 deletion ios/Classes/core/PMManager.m
Original file line number Diff line number Diff line change
@@ -152,13 +152,23 @@ - (BOOL)existsWithId:(NSString *)assetId {
return result && result.count > 0;
}

- (BOOL)entityIsLocallyAvailable:(NSString *)assetId resource:(PHAssetResource *)resource isOrigin:(BOOL)isOrigin {
- (BOOL)entityIsLocallyAvailable:(NSString *)assetId resource:(PHAssetResource *)resource isOrigin:(BOOL)isOrigin subtype:(int)subtype {
PHFetchResult<PHAsset *> *result =
[PHAsset fetchAssetsWithLocalIdentifiers:@[assetId] options:[PHFetchOptions new]];
if (!result) {
return NO;
}
PHAsset *asset = result.firstObject;
if (@available(iOS 9.1, *)) {
if ((subtype & PHAssetMediaSubtypePhotoLive) == PHAssetMediaSubtypePhotoLive) {
resource = [asset getLivePhotosResource];
}
}
if (@available(macOS 14.0, *)) {
if ((subtype & PHAssetMediaSubtypePhotoLive) == PHAssetMediaSubtypePhotoLive) {
resource = [asset getLivePhotosResource];
}
}
NSFileManager *fileManager = NSFileManager.defaultManager;
NSString *path = [self makeAssetOutputPath:asset resource:nil isOrigin:isOrigin manager:fileManager];
BOOL isExist = [fileManager fileExistsAtPath:path];
12 changes: 10 additions & 2 deletions lib/src/internal/plugin.dart
Original file line number Diff line number Diff line change
@@ -645,11 +645,19 @@ class PhotoManagerPlugin with BasePlugin, IosPlugin, AndroidPlugin, OhosPlugin {
});
}

Future<bool> isLocallyAvailable(String id, {bool isOrigin = false}) async {
Future<bool> isLocallyAvailable(
String id, {
bool isOrigin = false,
int subtype = 0,
}) async {
if (Platform.isIOS || Platform.isMacOS) {
final bool result = await _channel.invokeMethod<bool>(
PMConstants.mIsLocallyAvailable,
<String, dynamic>{'id': id, 'isOrigin': isOrigin},
<String, dynamic>{
'id': id,
'isOrigin': isOrigin,
'subtype': subtype,
},
) as bool;
return result;
}
11 changes: 9 additions & 2 deletions lib/src/types/entity.dart
Original file line number Diff line number Diff line change
@@ -495,8 +495,15 @@ class AssetEntity {
/// * Android: Always true.
/// * iOS/macOS: Whether the asset has been uploaded to iCloud
/// and locally exist (including cached or not).
Future<bool> isLocallyAvailable({bool isOrigin = false}) {
return plugin.isLocallyAvailable(id, isOrigin: isOrigin);
Future<bool> isLocallyAvailable({
bool isOrigin = false,
bool withSubtype = false,
}) {
return plugin.isLocallyAvailable(
id,
isOrigin: isOrigin,
subtype: withSubtype ? subtype : 0,
);
}

/// Obtain latitude and longitude.