mirror of https://github.com/immich-app/immich.git
refactor(mobile): reworked Asset, store all required fields from local & remote (#1539)
replace usage of AssetResponseDto with Asset Add new class ExifInfo to store data from ExifResponseDtopull/1501/head
parent
7bd2455175
commit
0048662182
@ -1,76 +0,0 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:openapi/api.dart';
|
|
||||||
|
|
||||||
class ImmichAssetGroupByDate {
|
|
||||||
final String date;
|
|
||||||
List<AssetResponseDto> assets;
|
|
||||||
ImmichAssetGroupByDate({
|
|
||||||
required this.date,
|
|
||||||
required this.assets,
|
|
||||||
});
|
|
||||||
|
|
||||||
ImmichAssetGroupByDate copyWith({
|
|
||||||
String? date,
|
|
||||||
List<AssetResponseDto>? assets,
|
|
||||||
}) {
|
|
||||||
return ImmichAssetGroupByDate(
|
|
||||||
date: date ?? this.date,
|
|
||||||
assets: assets ?? this.assets,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() => 'ImmichAssetGroupByDate(date: $date, assets: $assets)';
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (identical(this, other)) return true;
|
|
||||||
|
|
||||||
return other is ImmichAssetGroupByDate &&
|
|
||||||
other.date == date &&
|
|
||||||
listEquals(other.assets, assets);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => date.hashCode ^ assets.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
class GetAllAssetResponse {
|
|
||||||
final int count;
|
|
||||||
final List<ImmichAssetGroupByDate> data;
|
|
||||||
final String nextPageKey;
|
|
||||||
GetAllAssetResponse({
|
|
||||||
required this.count,
|
|
||||||
required this.data,
|
|
||||||
required this.nextPageKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
GetAllAssetResponse copyWith({
|
|
||||||
int? count,
|
|
||||||
List<ImmichAssetGroupByDate>? data,
|
|
||||||
String? nextPageKey,
|
|
||||||
}) {
|
|
||||||
return GetAllAssetResponse(
|
|
||||||
count: count ?? this.count,
|
|
||||||
data: data ?? this.data,
|
|
||||||
nextPageKey: nextPageKey ?? this.nextPageKey,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() =>
|
|
||||||
'GetAllAssetResponse(count: $count, data: $data, nextPageKey: $nextPageKey)';
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool operator ==(Object other) {
|
|
||||||
if (identical(this, other)) return true;
|
|
||||||
|
|
||||||
return other is GetAllAssetResponse &&
|
|
||||||
other.count == count &&
|
|
||||||
listEquals(other.data, data) &&
|
|
||||||
other.nextPageKey == nextPageKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode => count.hashCode ^ data.hashCode ^ nextPageKey.hashCode;
|
|
||||||
}
|
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
import 'package:openapi/api.dart';
|
||||||
|
import 'package:immich_mobile/utils/builtin_extensions.dart';
|
||||||
|
|
||||||
|
class ExifInfo {
|
||||||
|
int? fileSize;
|
||||||
|
String? make;
|
||||||
|
String? model;
|
||||||
|
String? orientation;
|
||||||
|
String? lensModel;
|
||||||
|
double? fNumber;
|
||||||
|
double? focalLength;
|
||||||
|
int? iso;
|
||||||
|
double? exposureTime;
|
||||||
|
String? city;
|
||||||
|
String? state;
|
||||||
|
String? country;
|
||||||
|
|
||||||
|
ExifInfo.fromDto(ExifResponseDto dto)
|
||||||
|
: fileSize = dto.fileSizeInByte,
|
||||||
|
make = dto.make,
|
||||||
|
model = dto.model,
|
||||||
|
orientation = dto.orientation,
|
||||||
|
lensModel = dto.lensModel,
|
||||||
|
fNumber = dto.fNumber?.toDouble(),
|
||||||
|
focalLength = dto.focalLength?.toDouble(),
|
||||||
|
iso = dto.iso?.toInt(),
|
||||||
|
exposureTime = dto.exposureTime?.toDouble(),
|
||||||
|
city = dto.city,
|
||||||
|
state = dto.state,
|
||||||
|
country = dto.country;
|
||||||
|
|
||||||
|
// stuff below is only required for caching as JSON
|
||||||
|
|
||||||
|
ExifInfo(
|
||||||
|
this.fileSize,
|
||||||
|
this.make,
|
||||||
|
this.model,
|
||||||
|
this.orientation,
|
||||||
|
this.lensModel,
|
||||||
|
this.fNumber,
|
||||||
|
this.focalLength,
|
||||||
|
this.iso,
|
||||||
|
this.exposureTime,
|
||||||
|
this.city,
|
||||||
|
this.state,
|
||||||
|
this.country,
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final json = <String, dynamic>{};
|
||||||
|
json["fileSize"] = fileSize;
|
||||||
|
json["make"] = make;
|
||||||
|
json["model"] = model;
|
||||||
|
json["orientation"] = orientation;
|
||||||
|
json["lensModel"] = lensModel;
|
||||||
|
json["fNumber"] = fNumber;
|
||||||
|
json["focalLength"] = focalLength;
|
||||||
|
json["iso"] = iso;
|
||||||
|
json["exposureTime"] = exposureTime;
|
||||||
|
json["city"] = city;
|
||||||
|
json["state"] = state;
|
||||||
|
json["country"] = country;
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ExifInfo? fromJson(dynamic value) {
|
||||||
|
if (value is Map) {
|
||||||
|
final json = value.cast<String, dynamic>();
|
||||||
|
return ExifInfo(
|
||||||
|
json["fileSize"],
|
||||||
|
json["make"],
|
||||||
|
json["model"],
|
||||||
|
json["orientation"],
|
||||||
|
json["lensModel"],
|
||||||
|
json["fNumber"],
|
||||||
|
json["focalLength"],
|
||||||
|
json["iso"],
|
||||||
|
json["exposureTime"],
|
||||||
|
json["city"],
|
||||||
|
json["state"],
|
||||||
|
json["country"],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
extension DurationExtension on String {
|
||||||
|
Duration toDuration() {
|
||||||
|
final parts =
|
||||||
|
split(':').map((e) => double.parse(e).toInt()).toList(growable: false);
|
||||||
|
return Duration(hours: parts[0], minutes: parts[1], seconds: parts[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
double? toDouble() {
|
||||||
|
return double.tryParse(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue