mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
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 ExifResponseDto
This commit is contained in:
parent
7bd2455175
commit
0048662182
28 changed files with 626 additions and 504 deletions
41
mobile/lib/shared/services/asset_cache.service.dart
Normal file
41
mobile/lib/shared/services/asset_cache.service.dart
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/shared/models/asset.dart';
|
||||
import 'package:immich_mobile/shared/services/json_cache.dart';
|
||||
|
||||
class AssetCacheService extends JsonCache<List<Asset>> {
|
||||
AssetCacheService() : super("asset_cache");
|
||||
|
||||
static Future<List<Map<String, dynamic>>> _computeSerialize(
|
||||
List<Asset> assets,
|
||||
) async {
|
||||
return assets.map((e) => e.toJson()).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void put(List<Asset> data) async {
|
||||
putRawData(await compute(_computeSerialize, data));
|
||||
}
|
||||
|
||||
static Future<List<Asset>> _computeEncode(List<dynamic> data) async {
|
||||
return data.map((e) => Asset.fromJson(e)).whereNotNull().toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Asset>?> get() async {
|
||||
try {
|
||||
final mapList = await readRawData() as List<dynamic>;
|
||||
final responseData = await compute(_computeEncode, mapList);
|
||||
return responseData;
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
await invalidate();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final assetCacheServiceProvider = Provider(
|
||||
(ref) => AssetCacheService(),
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue