add optional "hideIfEmpty" parameter in "listAlbums" API to show empty albums, only available on iOS platform
This commit is contained in:
parent
270432154d
commit
ea75f18cfe
@ -15,7 +15,8 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
if(call.method == "listAlbums") {
|
if(call.method == "listAlbums") {
|
||||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||||
let mediumType = arguments["mediumType"] as! String
|
let mediumType = arguments["mediumType"] as! String
|
||||||
result(listAlbums(mediumType: mediumType))
|
let hideIfEmpty = arguments["hideIfEmpty"] as? Bool
|
||||||
|
result(listAlbums(mediumType: mediumType, hideIfEmpty: hideIfEmpty))
|
||||||
}
|
}
|
||||||
else if(call.method == "listMedia") {
|
else if(call.method == "listMedia") {
|
||||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||||
@ -89,7 +90,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
|
|
||||||
private var assetCollections : [PHAssetCollection] = []
|
private var assetCollections : [PHAssetCollection] = []
|
||||||
|
|
||||||
private func listAlbums(mediumType: String) -> [NSDictionary] {
|
private func listAlbums(mediumType: String, hideIfEmpty: Bool? = true) -> [NSDictionary] {
|
||||||
self.assetCollections = []
|
self.assetCollections = []
|
||||||
let fetchOptions = PHFetchOptions()
|
let fetchOptions = PHFetchOptions()
|
||||||
var total = 0
|
var total = 0
|
||||||
@ -142,13 +143,13 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
// Smart Albums.
|
// Smart Albums.
|
||||||
processPHAssetCollections(
|
processPHAssetCollections(
|
||||||
fetchResult: PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions),
|
fetchResult: PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions),
|
||||||
hideIfEmpty: true
|
hideIfEmpty: hideIfEmpty ?? true
|
||||||
)
|
)
|
||||||
|
|
||||||
// User-created collections.
|
// User-created collections.
|
||||||
processPHCollections(
|
processPHCollections(
|
||||||
fetchResult: PHAssetCollection.fetchTopLevelUserCollections(with: fetchOptions),
|
fetchResult: PHAssetCollection.fetchTopLevelUserCollections(with: fetchOptions),
|
||||||
hideIfEmpty: true
|
hideIfEmpty: hideIfEmpty ?? true
|
||||||
)
|
)
|
||||||
|
|
||||||
albums.insert([
|
albums.insert([
|
||||||
|
@ -25,9 +25,11 @@ class PhotoGallery {
|
|||||||
/// List all available gallery albums and counts number of items of [MediumType].
|
/// List all available gallery albums and counts number of items of [MediumType].
|
||||||
static Future<List<Album>> listAlbums({
|
static Future<List<Album>> listAlbums({
|
||||||
required MediumType mediumType,
|
required MediumType mediumType,
|
||||||
|
bool? hideIfEmpty = true,
|
||||||
}) async {
|
}) async {
|
||||||
final json = await _channel.invokeMethod('listAlbums', {
|
final json = await _channel.invokeMethod('listAlbums', {
|
||||||
'mediumType': mediumTypeToJson(mediumType),
|
'mediumType': mediumTypeToJson(mediumType),
|
||||||
|
'hideIfEmpty': hideIfEmpty
|
||||||
});
|
});
|
||||||
return json.map<Album>((x) => Album.fromJson(x)).toList();
|
return json.map<Album>((x) => Album.fromJson(x)).toList();
|
||||||
}
|
}
|
||||||
@ -78,6 +80,7 @@ class PhotoGallery {
|
|||||||
'height': height,
|
'height': height,
|
||||||
'highQuality': highQuality,
|
'highQuality': highQuality,
|
||||||
});
|
});
|
||||||
|
if (bytes == null) throw "Failed to fetch thumbnail of medium $mediumId";
|
||||||
return new List<int>.from(bytes);
|
return new List<int>.from(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +99,7 @@ class PhotoGallery {
|
|||||||
'height': height,
|
'height': height,
|
||||||
'highQuality': highQuality,
|
'highQuality': highQuality,
|
||||||
});
|
});
|
||||||
|
if (bytes == null) throw "Failed to fetch thumbnail of album $albumId";
|
||||||
return new List<int>.from(bytes);
|
return new List<int>.from(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user