2022-10-17 14:53:27 +02:00
|
|
|
|
|
|
|
import 'package:collection/collection.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/services/asset_cache.service.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
2022-10-18 14:06:35 +02:00
|
|
|
class BaseAlbumCacheService extends JsonCache<List<AlbumResponseDto>> {
|
|
|
|
BaseAlbumCacheService(super.cacheFileName);
|
2022-10-17 14:53:27 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void put(List<AlbumResponseDto> data) {
|
|
|
|
putRawData(data.map((e) => e.toJson()).toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-17 16:40:51 +02:00
|
|
|
Future<List<AlbumResponseDto>> get() async {
|
2022-10-17 14:53:27 +02:00
|
|
|
try {
|
2022-10-17 16:40:51 +02:00
|
|
|
final mapList = await readRawData() as List<dynamic>;
|
2022-10-17 14:53:27 +02:00
|
|
|
|
|
|
|
final responseData = mapList
|
|
|
|
.map((e) => AlbumResponseDto.fromJson(e))
|
|
|
|
.whereNotNull()
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
return responseData;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint(e.toString());
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2022-10-18 14:06:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class AlbumCacheService extends BaseAlbumCacheService {
|
|
|
|
AlbumCacheService() : super("album_cache");
|
|
|
|
}
|
2022-10-17 14:53:27 +02:00
|
|
|
|
2022-10-18 14:06:35 +02:00
|
|
|
class SharedAlbumCacheService extends BaseAlbumCacheService {
|
|
|
|
SharedAlbumCacheService() : super("shared_album_cache");
|
2022-10-17 14:53:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final albumCacheServiceProvider = Provider(
|
|
|
|
(ref) => AlbumCacheService(),
|
|
|
|
);
|
2022-10-18 14:06:35 +02:00
|
|
|
|
|
|
|
final sharedAlbumCacheServiceProvider = Provider(
|
|
|
|
(ref) => SharedAlbumCacheService(),
|
|
|
|
);
|
|
|
|
|