2022-10-14 23:57:55 +02:00
|
|
|
import 'package:collection/collection.dart';
|
2022-10-15 23:20:15 +02:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-10-14 23:57:55 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-11-08 19:00:24 +02:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2022-10-19 22:03:54 +02:00
|
|
|
import 'package:immich_mobile/shared/services/json_cache.dart';
|
2022-10-17 18:02:43 +02:00
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
class AssetCacheService extends JsonCache<List<Asset>> {
|
2022-10-17 18:02:43 +02:00
|
|
|
AssetCacheService() : super("asset_cache");
|
2022-10-17 14:53:27 +02:00
|
|
|
|
|
|
|
@override
|
2022-11-08 19:00:24 +02:00
|
|
|
void put(List<Asset> data) {
|
2022-10-17 14:53:27 +02:00
|
|
|
putRawData(data.map((e) => e.toJson()).toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-11-08 19:00:24 +02:00
|
|
|
Future<List<Asset>> get() async {
|
2022-10-15 23:20:15 +02:00
|
|
|
try {
|
2022-10-17 16:40:51 +02:00
|
|
|
final mapList = await readRawData() as List<dynamic>;
|
2022-10-14 23:57:55 +02:00
|
|
|
|
2022-11-08 19:00:24 +02:00
|
|
|
final responseData =
|
|
|
|
mapList.map((e) => Asset.fromJson(e)).whereNotNull().toList();
|
2022-10-14 23:57:55 +02:00
|
|
|
|
2022-10-15 23:20:15 +02:00
|
|
|
return responseData;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint(e.toString());
|
2022-10-14 23:57:55 +02:00
|
|
|
|
2022-10-15 23:20:15 +02:00
|
|
|
return [];
|
|
|
|
}
|
2022-10-14 23:57:55 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-17 14:53:27 +02:00
|
|
|
|
|
|
|
final assetCacheServiceProvider = Provider(
|
2022-11-08 19:00:24 +02:00
|
|
|
(ref) => AssetCacheService(),
|
2022-10-17 14:53:27 +02:00
|
|
|
);
|