add optional mediumType parameter of getAlbumThumbnail api method to display video thumbnail correctly
This commit is contained in:
parent
c70dd411dc
commit
ce9184372b
@ -122,10 +122,11 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
}
|
||||
"getAlbumThumbnail" -> {
|
||||
val albumId = call.argument<String>("albumId")
|
||||
val mediumType = call.argument<String>("mediumType")
|
||||
val width = call.argument<Int>("width")
|
||||
val height = call.argument<Int>("height")
|
||||
BackgroundAsyncTask({
|
||||
getAlbumThumbnail(albumId!!, width, height)
|
||||
getAlbumThumbnail(albumId!!, mediumType, width, height)
|
||||
}, { v ->
|
||||
result.success(v)
|
||||
})
|
||||
@ -461,7 +462,22 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
return byteArray
|
||||
}
|
||||
|
||||
private fun getAlbumThumbnail(albumId: String, width: Int?, height: Int?): ByteArray? {
|
||||
private fun getAlbumThumbnail(albumId: String, mediumType: String?, width: Int?, height: Int?): ByteArray? {
|
||||
return when (mediumType) {
|
||||
imageType -> {
|
||||
getImageAlbumThubnail(albumId, width, height)
|
||||
}
|
||||
videoType -> {
|
||||
getVideoAlbumThubnail(albumId, width, height)
|
||||
}
|
||||
else -> {
|
||||
getImageAlbumThubnail(albumId, width, height)
|
||||
?: getVideoAlbumThubnail(albumId, width, height)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getImageAlbumThubnail(albumId: String, width: Int?, height: Int?): ByteArray? {
|
||||
return this.context?.run {
|
||||
val imageCursor = this.contentResolver.query(
|
||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||
@ -478,6 +494,12 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
private fun getVideoAlbumThubnail(albumId: String, width: Int?, height: Int?): ByteArray? {
|
||||
return this.context?.run {
|
||||
val videoCursor = this.contentResolver.query(
|
||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||
arrayOf(MediaStore.Video.Media._ID),
|
||||
@ -493,7 +515,7 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
||||
}
|
||||
}
|
||||
|
||||
return@run null
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,11 +52,13 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
else if(call.method == "getAlbumThumbnail") {
|
||||
let arguments = call.arguments as! Dictionary<String, AnyObject>
|
||||
let albumId = arguments["albumId"] as! String
|
||||
let mediumType = arguments["mediumType"] as? String
|
||||
let width = arguments["width"] as? Int
|
||||
let height = arguments["height"] as? Int
|
||||
let highQuality = arguments["highQuality"] as? Bool
|
||||
getAlbumThumbnail(
|
||||
albumId: albumId,
|
||||
mediumType: mediumType,
|
||||
width: width,
|
||||
height: height,
|
||||
highQuality: highQuality,
|
||||
@ -251,6 +253,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
|
||||
private func getAlbumThumbnail(
|
||||
albumId: String,
|
||||
mediumType: String?,
|
||||
width: Int?,
|
||||
height: Int?,
|
||||
highQuality: Bool?,
|
||||
@ -258,6 +261,9 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
||||
) {
|
||||
let manager = PHImageManager.default()
|
||||
let fetchOptions = PHFetchOptions()
|
||||
if (mediumType != nil) {
|
||||
fetchOptions.predicate = self.predicateFromMediumType(mediumType: mediumType!)
|
||||
}
|
||||
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
|
||||
if #available(iOS 9, *) {
|
||||
fetchOptions.fetchLimit = 1
|
||||
|
@ -85,6 +85,7 @@ class PhotoGallery {
|
||||
/// Get album thumbnail by album id
|
||||
static Future<List<dynamic>> getAlbumThumbnail({
|
||||
@required String albumId,
|
||||
MediumType mediumType,
|
||||
int width,
|
||||
int height,
|
||||
bool highQuality,
|
||||
@ -92,6 +93,7 @@ class PhotoGallery {
|
||||
assert(albumId != null);
|
||||
final bytes = await _channel.invokeMethod('getAlbumThumbnail', {
|
||||
'albumId': albumId,
|
||||
'mediumType': mediumTypeToJson(mediumType),
|
||||
'width': width,
|
||||
'height': height,
|
||||
'highQuality': highQuality,
|
||||
|
@ -4,12 +4,14 @@ part of photogallery;
|
||||
class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
||||
const AlbumThumbnailProvider({
|
||||
@required this.albumId,
|
||||
this.mediumType,
|
||||
this.height,
|
||||
this.width,
|
||||
this.highQuality = false,
|
||||
}) : assert(albumId != null);
|
||||
|
||||
final String albumId;
|
||||
final MediumType mediumType;
|
||||
final int height;
|
||||
final int width;
|
||||
final bool highQuality;
|
||||
@ -30,6 +32,7 @@ class AlbumThumbnailProvider extends ImageProvider<AlbumThumbnailProvider> {
|
||||
assert(key == this);
|
||||
final bytes = await PhotoGallery.getAlbumThumbnail(
|
||||
albumId: albumId,
|
||||
mediumType: mediumType,
|
||||
height: height,
|
||||
width: width,
|
||||
highQuality: highQuality,
|
||||
|
@ -51,6 +51,7 @@ class Album {
|
||||
}) {
|
||||
return PhotoGallery.getAlbumThumbnail(
|
||||
albumId: id,
|
||||
mediumType: this.mediumType,
|
||||
width: width,
|
||||
height: height,
|
||||
highQuality: highQuality,
|
||||
|
Loading…
x
Reference in New Issue
Block a user