Skip to content

Commit

Permalink
feat(mobile): clear local storage option (immich-app#4635)
Browse files Browse the repository at this point in the history
* feat(mobile): clear local storage option

* en json
  • Loading branch information
alextran1502 authored Oct 25, 2023
1 parent e47a11b commit aefd052
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 15 deletions.
8 changes: 5 additions & 3 deletions mobile/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@
"version_announcement_overlay_text_3": " and ensure your docker-compose and .env setup is up-to-date to prevent any misconfigurations, especially if you use WatchTower or any mechanism that handles updating your server application automatically.",
"version_announcement_overlay_title": "New Server Version Available \uD83C\uDF89",
"viewer_remove_from_stack": "Remove from Stack",
"viewer_stack_use_as_main_asset": "Use as Main Asset",
"viewer_unstack": "Un-Stack"
}
"viewer_unstack": "Un-Stack",
"cache_settings_tile_title": "Local Storage",
"cache_settings_tile_subtitle": "Control the local storage behaviour",
"viewer_stack_use_as_main_asset": "Use as Main Asset"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart' show useEffect, useState;
import 'package:immich_mobile/modules/backup/models/duplicated_asset.model.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/providers/db.provider.dart';

class LocalStorageSettings extends HookConsumerWidget {
const LocalStorageSettings({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final isarDb = ref.watch(dbProvider);
final cacheItemCount = useState(0);
useEffect(
() {
cacheItemCount.value = isarDb.duplicatedAssets.countSync();
return null;
},
[],
);

void clearCache() {
isarDb.writeTxnSync(() => isarDb.duplicatedAssets.clearSync());
cacheItemCount.value = isarDb.duplicatedAssets.countSync();
}

return ExpansionTile(
textColor: Theme.of(context).primaryColor,
title: const Text(
"cache_settings_tile_title",
style: TextStyle(
fontWeight: FontWeight.bold,
),
).tr(),
subtitle: const Text(
"cache_settings_tile_subtitle",
style: TextStyle(
fontSize: 13,
),
).tr(),
children: [
ListTile(
title: Text(
"Duplicated Assets (${cacheItemCount.value})",
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(fontWeight: FontWeight.bold),
).tr(),
subtitle: const Text(
"Photos and videos that are black listed by the app",
style: TextStyle(
fontSize: 13,
),
).tr(),
trailing: TextButton(
onPressed: cacheItemCount.value > 0 ? clearCache : null,
child: Text(
"CLEAR",
style: TextStyle(
fontSize: 12,
color: cacheItemCount.value > 0 ? Colors.red : Colors.grey,
fontWeight: FontWeight.bold,
),
).tr(),
),
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,33 @@ class NotificationSetting extends HookConsumerWidget {
if (!hasPermission)
ListTile(
leading: const Icon(Icons.notifications_outlined),
title: const Text('notification_permission_list_tile_title').tr(),
title: Text(
'notification_permission_list_tile_title',
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(fontWeight: FontWeight.bold),
).tr(),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('notification_permission_list_tile_content').tr(),
Text(
'notification_permission_list_tile_content',
style: Theme.of(context).textTheme.labelMedium,
).tr(),
const SizedBox(height: 8),
ElevatedButton(
onPressed: ()
=> ref.watch(notificationPermissionProvider.notifier)
.requestNotificationPermission().then((permission) {
if (permission == PermissionStatus.permanentlyDenied) {
showPermissionsDialog();
}
onPressed: () => ref
.watch(notificationPermissionProvider.notifier)
.requestNotificationPermission()
.then((permission) {
if (permission == PermissionStatus.permanentlyDenied) {
showPermissionsDialog();
}
}),
child:
const Text('notification_permission_list_tile_enable_button')
.tr(),
child: const Text(
'notification_permission_list_tile_enable_button',
).tr(),
),
],
),
Expand Down Expand Up @@ -130,7 +140,8 @@ class NotificationSetting extends HookConsumerWidget {
).tr(args: [formattedValue]),
subtitle: Slider(
value: sliderValue.value,
onChanged: !hasPermission ? null : (double v) => sliderValue.value = v,
onChanged:
!hasPermission ? null : (double v) => sliderValue.value = v,
onChangeEnd: (double v) => appSettingService.setSetting(
AppSettingsEnum.uploadErrorNotificationGracePeriod,
v.toInt(),
Expand Down
2 changes: 2 additions & 0 deletions mobile/lib/modules/settings/views/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/modules/settings/ui/advanced_settings/advanced_settings.dart';
import 'package:immich_mobile/modules/settings/ui/asset_list_settings/asset_list_settings.dart';
import 'package:immich_mobile/modules/settings/ui/local_storage_settings/local_storage_settings.dart';
import 'package:immich_mobile/modules/settings/ui/image_viewer_quality_setting/image_viewer_quality_setting.dart';
import 'package:immich_mobile/modules/settings/ui/notification_setting/notification_setting.dart';
import 'package:immich_mobile/modules/settings/ui/theme_setting/theme_setting.dart';
Expand Down Expand Up @@ -42,6 +43,7 @@ class SettingsPage extends HookConsumerWidget {
const AssetListSettings(),
const NotificationSetting(),
// const ExperimentalSettings(),
const LocalStorageSettings(),
const AdvancedSettings(),
],
).toList(),
Expand Down

0 comments on commit aefd052

Please sign in to comment.