add "filename" and "title" property of Medium
This commit is contained in:
parent
330fd1929e
commit
54a5f6bad9
@ -56,6 +56,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
val imageMetadataProjection = arrayOf(
|
val imageMetadataProjection = arrayOf(
|
||||||
MediaStore.Images.Media._ID,
|
MediaStore.Images.Media._ID,
|
||||||
|
MediaStore.Images.Media.DISPLAY_NAME,
|
||||||
|
MediaStore.Images.Media.TITLE,
|
||||||
MediaStore.Images.Media.WIDTH,
|
MediaStore.Images.Media.WIDTH,
|
||||||
MediaStore.Images.Media.HEIGHT,
|
MediaStore.Images.Media.HEIGHT,
|
||||||
MediaStore.Images.Media.ORIENTATION,
|
MediaStore.Images.Media.ORIENTATION,
|
||||||
@ -66,6 +68,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
val videoMetadataProjection = arrayOf(
|
val videoMetadataProjection = arrayOf(
|
||||||
MediaStore.Video.Media._ID,
|
MediaStore.Video.Media._ID,
|
||||||
|
MediaStore.Video.Media.DISPLAY_NAME,
|
||||||
|
MediaStore.Video.Media.TITLE,
|
||||||
MediaStore.Video.Media.WIDTH,
|
MediaStore.Video.Media.WIDTH,
|
||||||
MediaStore.Video.Media.HEIGHT,
|
MediaStore.Video.Media.HEIGHT,
|
||||||
MediaStore.Video.Media.ORIENTATION,
|
MediaStore.Video.Media.ORIENTATION,
|
||||||
@ -797,6 +801,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
private fun getImageMetadata(cursor: Cursor): Map<String, Any?> {
|
private fun getImageMetadata(cursor: Cursor): Map<String, Any?> {
|
||||||
val idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID)
|
val idColumn = cursor.getColumnIndex(MediaStore.Images.Media._ID)
|
||||||
|
val filenameColumn = cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME)
|
||||||
|
val titleColumn = cursor.getColumnIndex(MediaStore.Images.Media.TITLE)
|
||||||
val widthColumn = cursor.getColumnIndex(MediaStore.Images.Media.WIDTH)
|
val widthColumn = cursor.getColumnIndex(MediaStore.Images.Media.WIDTH)
|
||||||
val heightColumn = cursor.getColumnIndex(MediaStore.Images.Media.HEIGHT)
|
val heightColumn = cursor.getColumnIndex(MediaStore.Images.Media.HEIGHT)
|
||||||
val orientationColumn = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION)
|
val orientationColumn = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION)
|
||||||
@ -805,6 +811,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)
|
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Images.Media.DATE_MODIFIED)
|
||||||
|
|
||||||
val id = cursor.getLong(idColumn)
|
val id = cursor.getLong(idColumn)
|
||||||
|
val filename = cursor.getString(filenameColumn)
|
||||||
|
val title = cursor.getString(titleColumn)
|
||||||
val width = cursor.getLong(widthColumn)
|
val width = cursor.getLong(widthColumn)
|
||||||
val height = cursor.getLong(heightColumn)
|
val height = cursor.getLong(heightColumn)
|
||||||
val orientation = cursor.getLong(orientationColumn)
|
val orientation = cursor.getLong(orientationColumn)
|
||||||
@ -820,6 +828,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
return mapOf(
|
return mapOf(
|
||||||
"id" to id.toString(),
|
"id" to id.toString(),
|
||||||
|
"filename" to filename,
|
||||||
|
"title" to title,
|
||||||
"mediumType" to imageType,
|
"mediumType" to imageType,
|
||||||
"width" to width,
|
"width" to width,
|
||||||
"height" to height,
|
"height" to height,
|
||||||
@ -832,6 +842,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
private fun getVideoMetadata(cursor: Cursor): Map<String, Any?> {
|
private fun getVideoMetadata(cursor: Cursor): Map<String, Any?> {
|
||||||
val idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID)
|
val idColumn = cursor.getColumnIndex(MediaStore.Video.Media._ID)
|
||||||
|
val filenameColumn = cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME)
|
||||||
|
val titleColumn = cursor.getColumnIndex(MediaStore.Video.Media.TITLE)
|
||||||
val widthColumn = cursor.getColumnIndex(MediaStore.Video.Media.WIDTH)
|
val widthColumn = cursor.getColumnIndex(MediaStore.Video.Media.WIDTH)
|
||||||
val heightColumn = cursor.getColumnIndex(MediaStore.Video.Media.HEIGHT)
|
val heightColumn = cursor.getColumnIndex(MediaStore.Video.Media.HEIGHT)
|
||||||
val orientationColumn = cursor.getColumnIndex(MediaStore.Video.Media.ORIENTATION)
|
val orientationColumn = cursor.getColumnIndex(MediaStore.Video.Media.ORIENTATION)
|
||||||
@ -841,6 +853,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)
|
val dateModifiedColumn = cursor.getColumnIndex(MediaStore.Video.Media.DATE_MODIFIED)
|
||||||
|
|
||||||
val id = cursor.getLong(idColumn)
|
val id = cursor.getLong(idColumn)
|
||||||
|
val filename = cursor.getString(filenameColumn)
|
||||||
|
val title = cursor.getString(titleColumn)
|
||||||
val width = cursor.getLong(widthColumn)
|
val width = cursor.getLong(widthColumn)
|
||||||
val height = cursor.getLong(heightColumn)
|
val height = cursor.getLong(heightColumn)
|
||||||
val orientation = cursor.getLong(orientationColumn)
|
val orientation = cursor.getLong(orientationColumn)
|
||||||
@ -857,6 +871,8 @@ class PhotoGalleryPlugin : FlutterPlugin, MethodCallHandler {
|
|||||||
|
|
||||||
return mapOf(
|
return mapOf(
|
||||||
"id" to id.toString(),
|
"id" to id.toString(),
|
||||||
|
"filename" to filename,
|
||||||
|
"title" to title,
|
||||||
"mediumType" to videoType,
|
"mediumType" to videoType,
|
||||||
"width" to width,
|
"width" to width,
|
||||||
"orientation" to orientationDegree2Value(orientation),
|
"orientation" to orientationDegree2Value(orientation),
|
||||||
|
@ -416,8 +416,11 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
|
|
||||||
private func getMediumFromAsset(asset: PHAsset) -> [String: Any?] {
|
private func getMediumFromAsset(asset: PHAsset) -> [String: Any?] {
|
||||||
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
||||||
|
let filename = self.extractFilenameFromAsset(asset: asset)
|
||||||
return [
|
return [
|
||||||
"id": asset.localIdentifier,
|
"id": asset.localIdentifier,
|
||||||
|
"filename": filename,
|
||||||
|
"title": self.extractTitleFromFilename(filename: filename),
|
||||||
"mediumType": toDartMediumType(value: asset.mediaType),
|
"mediumType": toDartMediumType(value: asset.mediaType),
|
||||||
"mimeType": mimeType,
|
"mimeType": mimeType,
|
||||||
"height": asset.pixelHeight,
|
"height": asset.pixelHeight,
|
||||||
@ -430,6 +433,7 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
|
|
||||||
private func getMediumFromAssetAsync(asset: PHAsset, completion: @escaping ([String : Any?]?, Error?) -> Void) -> Void {
|
private func getMediumFromAssetAsync(asset: PHAsset, completion: @escaping ([String : Any?]?, Error?) -> Void) -> Void {
|
||||||
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
let mimeType = self.extractMimeTypeFromAsset(asset: asset)
|
||||||
|
let filename = self.extractFilenameFromAsset(asset: asset)
|
||||||
let manager = PHImageManager.default()
|
let manager = PHImageManager.default()
|
||||||
manager.requestImageData(
|
manager.requestImageData(
|
||||||
for: asset,
|
for: asset,
|
||||||
@ -437,6 +441,8 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
resultHandler: { (data: Data?, uti: String?, orientation: UIImage.Orientation, info: ([AnyHashable: Any]?)) -> Void in
|
resultHandler: { (data: Data?, uti: String?, orientation: UIImage.Orientation, info: ([AnyHashable: Any]?)) -> Void in
|
||||||
completion([
|
completion([
|
||||||
"id": asset.localIdentifier,
|
"id": asset.localIdentifier,
|
||||||
|
"filename": filename,
|
||||||
|
"title": self.extractTitleFromFilename(filename: filename),
|
||||||
"mediumType": self.toDartMediumType(value: asset.mediaType),
|
"mediumType": self.toDartMediumType(value: asset.mediaType),
|
||||||
"mimeType": mimeType,
|
"mimeType": mimeType,
|
||||||
"height": asset.pixelHeight,
|
"height": asset.pixelHeight,
|
||||||
@ -551,6 +557,23 @@ public class SwiftPhotoGalleryPlugin: NSObject, FlutterPlugin {
|
|||||||
return self.extractMimeTypeFromUTI(uti: uti)
|
return self.extractMimeTypeFromUTI(uti: uti)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func extractFilenameFromAsset(asset: PHAsset) -> String? {
|
||||||
|
if #available(iOS 9.0, *) {
|
||||||
|
let resources = PHAssetResource.assetResources(for: asset)
|
||||||
|
if let resource = resources.first {
|
||||||
|
return resource.originalFilename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return asset.value(forKey: "filename") as? String
|
||||||
|
}
|
||||||
|
|
||||||
|
private func extractTitleFromFilename(filename: String?) -> String? {
|
||||||
|
if let name = filename {
|
||||||
|
return (name as NSString).deletingPathExtension
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
private func cachePath() -> URL {
|
private func cachePath() -> URL {
|
||||||
let paths = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
|
let paths = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)
|
||||||
let cacheFolder = paths[0].appendingPathComponent("photo_gallery")
|
let cacheFolder = paths[0].appendingPathComponent("photo_gallery")
|
||||||
|
@ -8,6 +8,12 @@ class Medium {
|
|||||||
/// A unique identifier for the medium.
|
/// A unique identifier for the medium.
|
||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
|
/// The medium filename.
|
||||||
|
final String? filename;
|
||||||
|
|
||||||
|
/// The medium title
|
||||||
|
final String? title;
|
||||||
|
|
||||||
/// The medium type.
|
/// The medium type.
|
||||||
final MediumType? mediumType;
|
final MediumType? mediumType;
|
||||||
|
|
||||||
@ -34,6 +40,8 @@ class Medium {
|
|||||||
|
|
||||||
Medium({
|
Medium({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
this.filename,
|
||||||
|
this.title,
|
||||||
this.mediumType,
|
this.mediumType,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
@ -47,6 +55,8 @@ class Medium {
|
|||||||
/// Creates a medium from platform channel protocol.
|
/// Creates a medium from platform channel protocol.
|
||||||
Medium.fromJson(dynamic json)
|
Medium.fromJson(dynamic json)
|
||||||
: id = json["id"],
|
: id = json["id"],
|
||||||
|
filename = json["filename"],
|
||||||
|
title = json["title"],
|
||||||
mediumType = jsonToMediumType(json["mediumType"]),
|
mediumType = jsonToMediumType(json["mediumType"]),
|
||||||
width = json["width"],
|
width = json["width"],
|
||||||
height = json["height"],
|
height = json["height"],
|
||||||
@ -63,6 +73,8 @@ class Medium {
|
|||||||
static Medium fromMap(Map map) {
|
static Medium fromMap(Map map) {
|
||||||
return Medium(
|
return Medium(
|
||||||
id: map['id'],
|
id: map['id'],
|
||||||
|
filename: map['filename'],
|
||||||
|
title: map['title'],
|
||||||
mediumType: jsonToMediumType(map['mediumType']),
|
mediumType: jsonToMediumType(map['mediumType']),
|
||||||
width: map['width'],
|
width: map['width'],
|
||||||
height: map['height'],
|
height: map['height'],
|
||||||
@ -76,6 +88,8 @@ class Medium {
|
|||||||
Map toMap() {
|
Map toMap() {
|
||||||
return {
|
return {
|
||||||
"id": this.id,
|
"id": this.id,
|
||||||
|
"filename": this.filename,
|
||||||
|
"title": this.title,
|
||||||
"mediumType": mediumTypeToJson(this.mediumType),
|
"mediumType": mediumTypeToJson(this.mediumType),
|
||||||
"height": this.height,
|
"height": this.height,
|
||||||
"orientation": this.orientation,
|
"orientation": this.orientation,
|
||||||
@ -115,6 +129,8 @@ class Medium {
|
|||||||
other is Medium &&
|
other is Medium &&
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
id == other.id &&
|
id == other.id &&
|
||||||
|
filename == other.filename &&
|
||||||
|
title == other.title &&
|
||||||
mediumType == other.mediumType &&
|
mediumType == other.mediumType &&
|
||||||
width == other.width &&
|
width == other.width &&
|
||||||
height == other.height &&
|
height == other.height &&
|
||||||
@ -126,6 +142,8 @@ class Medium {
|
|||||||
@override
|
@override
|
||||||
int get hashCode =>
|
int get hashCode =>
|
||||||
id.hashCode ^
|
id.hashCode ^
|
||||||
|
filename.hashCode ^
|
||||||
|
title.hashCode ^
|
||||||
mediumType.hashCode ^
|
mediumType.hashCode ^
|
||||||
width.hashCode ^
|
width.hashCode ^
|
||||||
height.hashCode ^
|
height.hashCode ^
|
||||||
@ -137,6 +155,8 @@ class Medium {
|
|||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Medium{id: $id, '
|
return 'Medium{id: $id, '
|
||||||
|
'filename: $filename, '
|
||||||
|
'title: $title, '
|
||||||
'mediumType: $mediumType, '
|
'mediumType: $mediumType, '
|
||||||
'width: $width, '
|
'width: $width, '
|
||||||
'height: $height, '
|
'height: $height, '
|
||||||
|
Loading…
x
Reference in New Issue
Block a user