mirror of
https://github.com/immich-app/immich.git
synced 2026-03-12 04:41:06 -04:00
* feat: add playbackStyle to local asset entity and related database schema * implement conversion function for playbackStyle in local sync service * implement conversion function for playbackStyle in local sync service * refactor: remove deducedPlaybackStyle from TrashedLocalAssetEntityData * add playbackStyle column to trashed local asset entity * make playbackStyle non-nullable across the mobile codebase * Streamline playbackStyle backfill: - only backfill local assets playbackStyle in flutter/dart code - only update trashed local assets in db migration * bump target database version to 23 and update migration logic for playbackStyle * set playback_style to 0 in merged_asset.drift as its a getter in base asset * run make pigeon * Populate playbackStyle for trashed assets during native migration
122 lines
3.1 KiB
Dart
122 lines
3.1 KiB
Dart
part 'local_asset.model.dart';
|
|
part 'remote_asset.model.dart';
|
|
|
|
enum AssetType {
|
|
// do not change this order!
|
|
other,
|
|
image,
|
|
video,
|
|
audio,
|
|
}
|
|
|
|
enum AssetState { local, remote, merged }
|
|
|
|
// do not change!
|
|
// keep in sync with PlatformAssetPlaybackStyle
|
|
enum AssetPlaybackStyle { unknown, image, video, imageAnimated, livePhoto, videoLooping }
|
|
|
|
sealed class BaseAsset {
|
|
final String name;
|
|
final String? checksum;
|
|
final AssetType type;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final int? width;
|
|
final int? height;
|
|
final int? durationInSeconds;
|
|
final bool isFavorite;
|
|
final String? livePhotoVideoId;
|
|
final bool isEdited;
|
|
|
|
const BaseAsset({
|
|
required this.name,
|
|
required this.checksum,
|
|
required this.type,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
this.width,
|
|
this.height,
|
|
this.durationInSeconds,
|
|
this.isFavorite = false,
|
|
this.livePhotoVideoId,
|
|
required this.isEdited,
|
|
});
|
|
|
|
bool get isImage => type == AssetType.image;
|
|
bool get isVideo => type == AssetType.video;
|
|
|
|
bool get isMotionPhoto => livePhotoVideoId != null;
|
|
|
|
AssetPlaybackStyle get playbackStyle {
|
|
if (isVideo) return AssetPlaybackStyle.video;
|
|
if (isMotionPhoto) return AssetPlaybackStyle.livePhoto;
|
|
if (isImage && durationInSeconds != null && durationInSeconds! > 0) return AssetPlaybackStyle.imageAnimated;
|
|
if (isImage) return AssetPlaybackStyle.image;
|
|
return AssetPlaybackStyle.unknown;
|
|
}
|
|
|
|
Duration get duration {
|
|
final durationInSeconds = this.durationInSeconds;
|
|
if (durationInSeconds != null) {
|
|
return Duration(seconds: durationInSeconds);
|
|
}
|
|
return const Duration();
|
|
}
|
|
|
|
bool get hasRemote => storage == AssetState.remote || storage == AssetState.merged;
|
|
bool get hasLocal => storage == AssetState.local || storage == AssetState.merged;
|
|
bool get isLocalOnly => storage == AssetState.local;
|
|
bool get isRemoteOnly => storage == AssetState.remote;
|
|
|
|
// Overridden in subclasses
|
|
AssetState get storage;
|
|
String? get localId;
|
|
String? get remoteId;
|
|
String get heroTag;
|
|
|
|
@override
|
|
String toString() {
|
|
return '''BaseAsset {
|
|
name: $name,
|
|
type: $type,
|
|
createdAt: $createdAt,
|
|
updatedAt: $updatedAt,
|
|
width: ${width ?? "<NA>"},
|
|
height: ${height ?? "<NA>"},
|
|
durationInSeconds: ${durationInSeconds ?? "<NA>"},
|
|
isFavorite: $isFavorite,
|
|
isEdited: $isEdited,
|
|
}''';
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) return true;
|
|
if (other is BaseAsset) {
|
|
return name == other.name &&
|
|
type == other.type &&
|
|
createdAt == other.createdAt &&
|
|
updatedAt == other.updatedAt &&
|
|
width == other.width &&
|
|
height == other.height &&
|
|
durationInSeconds == other.durationInSeconds &&
|
|
isFavorite == other.isFavorite &&
|
|
isEdited == other.isEdited;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@override
|
|
int get hashCode {
|
|
return name.hashCode ^
|
|
type.hashCode ^
|
|
createdAt.hashCode ^
|
|
updatedAt.hashCode ^
|
|
width.hashCode ^
|
|
height.hashCode ^
|
|
durationInSeconds.hashCode ^
|
|
isFavorite.hashCode ^
|
|
isEdited.hashCode;
|
|
}
|
|
}
|