feat(mobile): sync local asset width & height from platform (#18994)

* add width and height to sqlite entities

* sync width & height from platform

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
shenlong 2025-06-09 08:20:54 +05:30 committed by GitHub
parent e376366b7b
commit 75c24f0023
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 47 additions and 8 deletions

View file

@ -85,6 +85,8 @@ data class PlatformAsset (
val type: Long,
val createdAt: Long? = null,
val updatedAt: Long? = null,
val width: Long? = null,
val height: Long? = null,
val durationInSeconds: Long
)
{
@ -95,8 +97,10 @@ data class PlatformAsset (
val type = pigeonVar_list[2] as Long
val createdAt = pigeonVar_list[3] as Long?
val updatedAt = pigeonVar_list[4] as Long?
val durationInSeconds = pigeonVar_list[5] as Long
return PlatformAsset(id, name, type, createdAt, updatedAt, durationInSeconds)
val width = pigeonVar_list[5] as Long?
val height = pigeonVar_list[6] as Long?
val durationInSeconds = pigeonVar_list[7] as Long
return PlatformAsset(id, name, type, createdAt, updatedAt, width, height, durationInSeconds)
}
}
fun toList(): List<Any?> {
@ -106,6 +110,8 @@ data class PlatformAsset (
type,
createdAt,
updatedAt,
width,
height,
durationInSeconds,
)
}

View file

@ -37,6 +37,8 @@ open class NativeSyncApiImplBase(context: Context) {
MediaStore.MediaColumns.DATE_MODIFIED,
MediaStore.Files.FileColumns.MEDIA_TYPE,
MediaStore.MediaColumns.BUCKET_ID,
MediaStore.MediaColumns.WIDTH,
MediaStore.MediaColumns.HEIGHT,
MediaStore.MediaColumns.DURATION
)
@ -68,6 +70,8 @@ open class NativeSyncApiImplBase(context: Context) {
val dateModifiedColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED)
val mediaTypeColumn = c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE)
val bucketIdColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.BUCKET_ID)
val widthColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.WIDTH)
val heightColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.HEIGHT)
val durationColumn = c.getColumnIndexOrThrow(MediaStore.MediaColumns.DURATION)
while (c.moveToNext()) {
@ -86,12 +90,23 @@ open class NativeSyncApiImplBase(context: Context) {
?: c.getLong(dateAddedColumn)
// Date modified is seconds since epoch
val modifiedAt = c.getLong(dateModifiedColumn)
val width = c.getInt(widthColumn).toLong()
val height = c.getInt(heightColumn).toLong()
// Duration is milliseconds
val duration = if (mediaType == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE) 0
else c.getLong(durationColumn) / 1000
val bucketId = c.getString(bucketIdColumn)
val asset = PlatformAsset(id, name, mediaType.toLong(), createdAt, modifiedAt, duration)
val asset = PlatformAsset(
id,
name,
mediaType.toLong(),
createdAt,
modifiedAt,
width,
height,
duration
)
yield(AssetResult.ValidAsset(asset, bucketId))
}
}

Binary file not shown.

View file

@ -135,6 +135,8 @@ struct PlatformAsset: Hashable {
var type: Int64
var createdAt: Int64? = nil
var updatedAt: Int64? = nil
var width: Int64? = nil
var height: Int64? = nil
var durationInSeconds: Int64
@ -145,7 +147,9 @@ struct PlatformAsset: Hashable {
let type = pigeonVar_list[2] as! Int64
let createdAt: Int64? = nilOrValue(pigeonVar_list[3])
let updatedAt: Int64? = nilOrValue(pigeonVar_list[4])
let durationInSeconds = pigeonVar_list[5] as! Int64
let width: Int64? = nilOrValue(pigeonVar_list[5])
let height: Int64? = nilOrValue(pigeonVar_list[6])
let durationInSeconds = pigeonVar_list[7] as! Int64
return PlatformAsset(
id: id,
@ -153,6 +157,8 @@ struct PlatformAsset: Hashable {
type: type,
createdAt: createdAt,
updatedAt: updatedAt,
width: width,
height: height,
durationInSeconds: durationInSeconds
)
}
@ -163,6 +169,8 @@ struct PlatformAsset: Hashable {
type,
createdAt,
updatedAt,
width,
height,
durationInSeconds,
]
}

View file

@ -25,7 +25,9 @@ extension PHAsset {
type: Int64(mediaType.rawValue),
createdAt: creationDate.map { Int64($0.timeIntervalSince1970) },
updatedAt: modificationDate.map { Int64($0.timeIntervalSince1970) },
durationInSeconds: Int64(duration)
width: Int64(pixelWidth),
height: Int64(pixelHeight),
durationInSeconds: Int64(duration),
)
}
}
@ -156,8 +158,6 @@ class NativeSyncApiImpl: NativeSyncApi {
id: asset.localIdentifier,
name: "",
type: 0,
createdAt: nil,
updatedAt: nil,
durationInSeconds: 0
)
if (updatedAssets.contains(AssetWrapper(with: predicate))) {

View file

@ -373,6 +373,8 @@ extension on Iterable<PlatformAsset> {
updatedAt: e.updatedAt == null
? DateTime.now()
: DateTime.fromMillisecondsSinceEpoch(e.updatedAt! * 1000),
width: e.width,
height: e.height,
durationInSeconds: e.durationInSeconds,
),
).toList();

View file

@ -272,7 +272,9 @@ class DriftLocalAlbumRepository extends DriftDatabaseRepository
type: asset.type,
createdAt: Value(asset.createdAt),
updatedAt: Value(asset.updatedAt),
durationInSeconds: Value.absentIfNull(asset.durationInSeconds),
width: Value(asset.width),
height: Value(asset.height),
durationInSeconds: Value(asset.durationInSeconds),
id: asset.id,
checksum: const Value(null),
);

View file

@ -6,5 +6,7 @@ mixin AssetEntityMixin on Table {
IntColumn get type => intEnum<AssetType>()();
DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
IntColumn get width => integer().nullable()();
IntColumn get height => integer().nullable()();
IntColumn get durationInSeconds => integer().nullable()();
}

Binary file not shown.

View file

@ -20,6 +20,8 @@ class PlatformAsset {
// Seconds since epoch
final int? createdAt;
final int? updatedAt;
final int? width;
final int? height;
final int durationInSeconds;
const PlatformAsset({
@ -28,6 +30,8 @@ class PlatformAsset {
required this.type,
this.createdAt,
this.updatedAt,
this.width,
this.height,
this.durationInSeconds = 0,
});
}