Skip to content

Commit

Permalink
fix(images): utilize new technique to persistently cache images
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Mar 27, 2023
1 parent c5eace4 commit f1a82c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
37 changes: 22 additions & 15 deletions lib/modules/settings/routes/system/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class _State extends State<SystemRoute> with LunaScrollControllerMixin {

Widget _appBar() {
return LunaAppBar(
title: 'System',
title: 'settings.System'.tr(),
scrollControllers: [scrollController],
);
}
Expand All @@ -48,43 +48,50 @@ class _State extends State<SystemRoute> with LunaScrollControllerMixin {
const SettingsSystemBackupRestoreRestoreTile(),
LunaDivider(),
_logs(),
if (LunaImageCache.isSupported) _clearImageCache(),
_clearImageCache(),
_clearConfiguration(),
],
);
}

Widget _logs() {
return LunaBlock(
title: 'Logs',
body: const [TextSpan(text: 'View, Export, and Clear Logs')],
title: 'settings.Logs'.tr(),
body: [TextSpan(text: 'settings.LogsDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.developer_mode_rounded),
onTap: SettingsRoutes.SYSTEM_LOGS.go,
);
}

Widget _clearImageCache() {
return LunaBlock(
title: 'Clear Image Cache',
body: const [TextSpan(text: 'Clear Cached Images From the Disk')],
title: 'settings.ClearImageCache'.tr(),
body: [TextSpan(text: 'settings.ClearImageCacheDescription'.tr())],
trailing: const LunaIconButton(icon: Icons.image_not_supported_rounded),
onTap: () async {
bool result = await SettingsDialogs().clearImageCache(context);
if (result) {
LunaImageCache().clear();
showLunaSuccessSnackBar(
title: 'Image Cache Cleared',
message: 'Your image cache has been cleared',
);
result = await LunaImageCache().clear();
if (result) {
showLunaSuccessSnackBar(
title: 'settings.ImageCacheCleared'.tr(),
message: 'settings.ImageCacheClearedDescription'.tr(),
);
} else {
showLunaErrorSnackBar(
title: 'settings.FailedToClearImageCache'.tr(),
message: 'settings.FailedToClearImageCacheDescription'.tr(),
);
}
}
},
);
}

Widget _clearConfiguration() {
return LunaBlock(
title: 'Clear Configuration',
body: const [TextSpan(text: 'Clean Slate')],
title: 'settings.ClearConfiguration'.tr(),
body: [TextSpan(text: 'settings.CleanSlate'.tr())],
trailing: const LunaIconButton(icon: Icons.delete_sweep_rounded),
onTap: () async {
bool result = await SettingsDialogs().clearConfiguration(context);
Expand All @@ -93,8 +100,8 @@ class _State extends State<SystemRoute> with LunaScrollControllerMixin {
if (LunaFirebase.isSupported) LunaFirebaseAuth().signOut();
LunaState.reset(context);
showLunaSuccessSnackBar(
title: 'Configuration Cleared',
message: 'Your configuration has been cleared',
title: 'settings.ConfigurationCleared'.tr(),
message: 'settings.ConfigurationClearedDescription'.tr(),
);
}
},
Expand Down
2 changes: 1 addition & 1 deletion lib/system/cache/image/image_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ abstract class LunaImageCache {
factory LunaImageCache() => getImageCache();

void initialize();
Future<void> clear();
Future<bool> clear();
dynamic get instance;
}
10 changes: 7 additions & 3 deletions lib/system/cache/image/platform/image_cache_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class IO implements LunaImageCache {
CacheManager get instance => _cache;

@override
Future<void> clear() async => _cache.emptyCache();
Future<bool> clear() async {
await _cache.emptyCache();
PaintingBinding.instance.imageCache.clear();
return true;
}

@override
void initialize() {
ImageCache().maximumSize = 1000;
ImageCache().maximumSizeBytes = 128 << 20;
PaintingBinding.instance.imageCache.maximumSize = 1000;
PaintingBinding.instance.imageCache.maximumSizeBytes = 128 << 20;
}
}

0 comments on commit f1a82c0

Please sign in to comment.