diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e6d462a..c61eb0ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.5.0-dev.1 +Feature: + +- Add `orientation` for `AssetEntity`. + Update - **Breaking change**, Split video filter and image filter diff --git a/android/src/main/kotlin/top/kikt/imagescanner/core/entity/AssetEntity.kt b/android/src/main/kotlin/top/kikt/imagescanner/core/entity/AssetEntity.kt index 8a9c6ccb..8a4962cf 100644 --- a/android/src/main/kotlin/top/kikt/imagescanner/core/entity/AssetEntity.kt +++ b/android/src/main/kotlin/top/kikt/imagescanner/core/entity/AssetEntity.kt @@ -12,7 +12,8 @@ data class AssetEntity( val height: Int, val type: Int, val displayName: String, - val modifiedDate: Long + val modifiedDate: Long, + val orientation:Int ) { var lat: Double? = null var lng: Double? = null diff --git a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/AndroidQDBUtils.kt b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/AndroidQDBUtils.kt index c73efcfc..66f82f45 100644 --- a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/AndroidQDBUtils.kt +++ b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/AndroidQDBUtils.kt @@ -122,8 +122,8 @@ object AndroidQDBUtils : IDBUtils { val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT) val displayName = cursor.getString(MediaStore.Images.Media.DISPLAY_NAME) val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED) - - val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val orientation: Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) + val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation) list.add(asset) cache.putAsset(asset) } @@ -176,8 +176,9 @@ object AndroidQDBUtils : IDBUtils { val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT) val displayName = cursor.getString(MediaStore.Images.Media.DISPLAY_NAME) val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED) - - val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) + + val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation) list.add(asset) cache.putAsset(asset) } @@ -212,8 +213,9 @@ object AndroidQDBUtils : IDBUtils { val height = cursor.getInt(MediaStore.MediaColumns.HEIGHT) val displayName = cursor.getString(MediaStore.MediaColumns.DISPLAY_NAME) val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED) - - val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) + + val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation) cacheContainer.putAsset(dbAsset) cursor.close() diff --git a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/ConvertUtils.kt b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/ConvertUtils.kt index 88b9357b..d40a3245 100644 --- a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/ConvertUtils.kt +++ b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/ConvertUtils.kt @@ -1,7 +1,10 @@ package top.kikt.imagescanner.core.utils import top.kikt.imagescanner.AssetType -import top.kikt.imagescanner.core.entity.* +import top.kikt.imagescanner.core.entity.AssetEntity +import top.kikt.imagescanner.core.entity.FilterCond +import top.kikt.imagescanner.core.entity.FilterOption +import top.kikt.imagescanner.core.entity.GalleryEntity /// create 2019-09-05 by cai @@ -39,6 +42,7 @@ object ConvertUtils { "createDt" to entity.createDt / 1000, "width" to entity.width, "height" to entity.height, + "orientation" to entity.orientation, "modifiedDt" to entity.modifiedDate, "lat" to entity.lat, "lng" to entity.lng, diff --git a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/DBUtils.kt b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/DBUtils.kt index 79c53e86..ac1d2386 100644 --- a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/DBUtils.kt +++ b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/DBUtils.kt @@ -168,8 +168,9 @@ object DBUtils : IDBUtils { val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE) val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE) + val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) - val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate,orientation) if (lat != 0.0) { asset.lat = lat @@ -232,8 +233,9 @@ object DBUtils : IDBUtils { val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE) val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE) + val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) - val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val asset = AssetEntity(id, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation) if (lat != 0.0) { asset.lat = lat @@ -279,8 +281,9 @@ object DBUtils : IDBUtils { val modifiedDate = cursor.getLong(MediaStore.MediaColumns.DATE_MODIFIED) val lat = cursor.getDouble(MediaStore.Images.ImageColumns.LATITUDE) val lng = cursor.getDouble(MediaStore.Images.ImageColumns.LONGITUDE) + val orientation:Int = cursor.getInt(MediaStore.MediaColumns.ORIENTATION) - val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate) + val dbAsset = AssetEntity(databaseId, path, duration, date, width, height, getMediaType(type), displayName, modifiedDate, orientation) if (lat != 0.0) { dbAsset.lat = lat diff --git a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/IDBUtils.kt b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/IDBUtils.kt index 99813ca4..b46fc97e 100644 --- a/android/src/main/kotlin/top/kikt/imagescanner/core/utils/IDBUtils.kt +++ b/android/src/main/kotlin/top/kikt/imagescanner/core/utils/IDBUtils.kt @@ -33,6 +33,7 @@ interface IDBUtils { MediaStore.MediaColumns.BUCKET_DISPLAY_NAME, // dir name 目录名字 MediaStore.MediaColumns.WIDTH, // 宽 MediaStore.MediaColumns.HEIGHT, // 高 + MediaStore.MediaColumns.ORIENTATION, // 角度 MediaStore.MediaColumns.DATE_MODIFIED, // 修改时间 MediaStore.MediaColumns.MIME_TYPE, // 高 MediaStore.MediaColumns.DATE_TAKEN //日期 @@ -48,6 +49,7 @@ interface IDBUtils { MediaStore.MediaColumns.DATE_TAKEN, //日期 MediaStore.MediaColumns.WIDTH, // 宽 MediaStore.MediaColumns.HEIGHT, // 高 + MediaStore.MediaColumns.ORIENTATION, // 角度 MediaStore.MediaColumns.DATE_MODIFIED, // 修改时间 MediaStore.MediaColumns.MIME_TYPE, // 高 MediaStore.MediaColumns.DURATION //时长 diff --git a/example/lib/page/detail_page.dart b/example/lib/page/detail_page.dart index 0b6487bc..3e014338 100644 --- a/example/lib/page/detail_page.dart +++ b/example/lib/page/detail_page.dart @@ -7,8 +7,13 @@ import 'package:photo_manager/photo_manager.dart'; class DetailPage extends StatefulWidget { final File file; final AssetEntity entity; -final String mediaUrl; - const DetailPage({Key key, this.file, this.entity,this.mediaUrl, }) : super(key: key); + final String mediaUrl; + const DetailPage({ + Key key, + this.file, + this.entity, + this.mediaUrl, + }) : super(key: key); @override _DetailPageState createState() => _DetailPageState(); @@ -78,6 +83,7 @@ class _DetailPageState extends State { buildInfoItem("create", entity.createDateTime.toString()), buildInfoItem("modified", entity.modifiedDateTime.toString()), buildInfoItem("size", entity.size.toString()), + buildInfoItem("orientation", entity.orientation.toString()), buildInfoItem("duration", entity.videoDuration.toString()), buildInfoItemAsync("title", entity.titleAsync), buildInfoItem("lat", lat?.toString() ?? "null"), diff --git a/example/lib/widget/image_item_widget.dart b/example/lib/widget/image_item_widget.dart index 4103de8c..89170594 100644 --- a/example/lib/widget/image_item_widget.dart +++ b/example/lib/widget/image_item_widget.dart @@ -26,12 +26,7 @@ class _ImageItemWidgetState extends State { Widget image; if (u8List != null) { - return Image.memory( - u8List, - width: size.toDouble(), - height: size.toDouble(), - fit: BoxFit.cover, - ); + return _buildImageWidget(item, u8List, size); } else { image = FutureBuilder( future: item.thumbDataWithSize(size, size), @@ -44,12 +39,7 @@ class _ImageItemWidgetState extends State { } if (snapshot.hasData) { ImageLruCache.setData(item, size, snapshot.data); - w = FittedBox( - fit: BoxFit.cover, - child: Image.memory( - snapshot.data, - ), - ); + w = _buildImageWidget(item, snapshot.data, size); } else { w = Center( child: loadWidget, @@ -64,6 +54,15 @@ class _ImageItemWidgetState extends State { return image; } + Widget _buildImageWidget(AssetEntity entity, Uint8List uint8list, num size) { + return Image.memory( + uint8list, + width: size.toDouble(), + height: size.toDouble(), + fit: BoxFit.cover, + ); + } + @override void didUpdateWidget(ImageItemWidget oldWidget) { super.didUpdateWidget(oldWidget); diff --git a/ios/Classes/PHAsset+PHAsset_checkType.m b/ios/Classes/PHAsset+PHAsset_checkType.m index c2d3dd8f..ea4aa40b 100644 --- a/ios/Classes/PHAsset+PHAsset_checkType.m +++ b/ios/Classes/PHAsset+PHAsset_checkType.m @@ -17,6 +17,10 @@ -(bool)isVideo{ return [self mediaType] == PHAssetMediaTypeVideo; } +-(bool)isAudio{ + return [self mediaType] == PHAssetMediaTypeAudio; +} + -(bool)isImageOrVideo{ return [self isVideo] || [self isImage]; } diff --git a/lib/src/entity.dart b/lib/src/entity.dart index 0e85416b..24d461fc 100644 --- a/lib/src/entity.dart +++ b/lib/src/entity.dart @@ -263,11 +263,11 @@ class AssetEntity { Future get exists => PhotoManager._assetExistsWithId(id); /// The url is provided to some video player. Such as [flutter_ijkplayer](https://pub.dev/packages/flutter_ijkplayer) - /// + /// /// It is such as `file:///var/mobile/Media/DCIM/118APPLE/IMG_8371.MOV` in iOS. - /// + /// /// Android28 or lower: `file:///storage/emulated/0/DCIM/Camera/20201020_202020.MP4` - /// + /// /// AndroidQ or higher: `content://media/external/video/media/894857` Future getMediaUrl() { if (type == AssetType.video) { @@ -276,6 +276,12 @@ class AssetEntity { return null; } + /// Orientation of android MediaStore. See [ORIENTATION](https://developer.android.com/reference/android/provider/MediaStore.MediaColumns#ORIENTATION) + /// Example values for android: 0 90 180 270 + /// + /// The value always 0 in iOS. + int orientation; + @override int get hashCode { return id.hashCode; diff --git a/lib/src/utils/convert_utils.dart b/lib/src/utils/convert_utils.dart index 499eb7c1..47182d51 100644 --- a/lib/src/utils/convert_utils.dart +++ b/lib/src/utils/convert_utils.dart @@ -36,6 +36,7 @@ class ConvertUtils { ..createDtSecond = item["createDt"] ..width = item["width"] ..height = item["height"] + ..orientation = (item["orientation"] ?? 0) ..duration = item["duration"] ..modifiedDateSecond = item["modifiedDt"] ..typeInt = item["type"]