Favourites
This commit is contained in:
parent
6a84a9bef0
commit
1747ab0245
23 changed files with 469 additions and 67 deletions
|
@ -2,19 +2,24 @@ import 'dart:ui';
|
|||
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
import 'package:mc_gallery/features/core/services/app_lifecycle_service.dart';
|
||||
import 'package:mc_gallery/features/core/services/local_storage_service.dart';
|
||||
import 'package:mc_gallery/features/core/services/logging_service.dart';
|
||||
import 'package:mc_gallery/locator.dart';
|
||||
|
||||
class ImageCacheManagerService with LoggingService {
|
||||
ImageCacheManagerService({
|
||||
required AppLifecycleService appLifecycleService,
|
||||
}) : _appLifecycleService = appLifecycleService {
|
||||
ImageCacheManagerService(
|
||||
{required AppLifecycleService appLifecycleService,
|
||||
required LocalStorageService localStorageService})
|
||||
: _appLifecycleService = appLifecycleService,
|
||||
_localStorageService = localStorageService {
|
||||
_init();
|
||||
}
|
||||
|
||||
final AppLifecycleService _appLifecycleService;
|
||||
final LocalStorageService _localStorageService;
|
||||
final _cacheManager = DefaultCacheManager();
|
||||
|
||||
Future<void> emptyCache() async => await DefaultCacheManager().emptyCache();
|
||||
Future<void> emptyCache() async => await _cacheManager.emptyCache();
|
||||
|
||||
Future<void> _init() async {
|
||||
_appLifecycleService.addListener(
|
||||
|
@ -27,7 +32,8 @@ class ImageCacheManagerService with LoggingService {
|
|||
case AppLifecycleState.paused:
|
||||
case AppLifecycleState.detached:
|
||||
info('Discarding cached images');
|
||||
await DefaultCacheManager().emptyCache();
|
||||
await _cacheManager.emptyCache();
|
||||
_localStorageService.resetFavourites();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue