Setting to disable memories notifications
This commit is contained in:
@@ -92,6 +92,17 @@ class MemoriesCacheService {
|
||||
Bus.instance.fire(MemoriesSettingChanged());
|
||||
}
|
||||
|
||||
Future<void> toggleOnThisDayNotifications() async {
|
||||
final oldValue = localSettings.isOnThisDayNotificationsEnabled;
|
||||
await localSettings.setOnThisDayNotificationsEnabled(!oldValue);
|
||||
_logger.info("Turning onThisDayNotifications ${oldValue ? "off" : "on"}");
|
||||
if (oldValue) {
|
||||
await _clearAllScheduledOnThisDayNotifications();
|
||||
} else {
|
||||
queueUpdateCache();
|
||||
}
|
||||
}
|
||||
|
||||
bool get enableSmartMemories =>
|
||||
flagService.hasGrantedMLConsent &&
|
||||
localSettings.isMLLocalIndexingEnabled &&
|
||||
@@ -238,11 +249,20 @@ class MemoriesCacheService {
|
||||
return newCache;
|
||||
}
|
||||
|
||||
Future<void> _clearAllScheduledOnThisDayNotifications() async {
|
||||
await NotificationService.instance
|
||||
.clearAllScheduledNotifications(containingPayload: "onThisDay");
|
||||
}
|
||||
|
||||
Future<void> _scheduleOnThisDayNotifications(
|
||||
List<SmartMemory> allMemories,
|
||||
) async {
|
||||
await NotificationService.instance
|
||||
.clearAllScheduledNotifications(containingPayload: "onThisDay");
|
||||
if (!localSettings.isOnThisDayNotificationsEnabled) {
|
||||
_logger
|
||||
.info("On this day notifications are disabled, skipping scheduling");
|
||||
return;
|
||||
}
|
||||
await _clearAllScheduledOnThisDayNotifications();
|
||||
final scheduledDates = <DateTime>{};
|
||||
for (final memory in allMemories) {
|
||||
if (memory.type != MemoryType.onThisDay) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import "package:photos/generated/l10n.dart";
|
||||
import "package:photos/service_locator.dart";
|
||||
import "package:photos/services/notification_service.dart";
|
||||
import 'package:photos/theme/ente_theme.dart';
|
||||
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
|
||||
@@ -9,6 +10,7 @@ import 'package:photos/ui/components/menu_section_description_widget.dart';
|
||||
import 'package:photos/ui/components/title_bar_title_widget.dart';
|
||||
import 'package:photos/ui/components/title_bar_widget.dart';
|
||||
import 'package:photos/ui/components/toggle_switch_widget.dart';
|
||||
import "package:photos/ui/settings/common_settings.dart";
|
||||
|
||||
class NotificationSettingsScreen extends StatelessWidget {
|
||||
const NotificationSettingsScreen({super.key});
|
||||
@@ -77,6 +79,33 @@ class NotificationSettingsScreen extends StatelessWidget {
|
||||
.of(context)
|
||||
.sharedPhotoNotificationsExplanation,
|
||||
),
|
||||
sectionOptionSpacing,
|
||||
MenuItemWidget(
|
||||
captionedTextWidget: CaptionedTextWidget(
|
||||
title: S.of(context).onThisDayMemories,
|
||||
),
|
||||
menuItemColor: colorScheme.fillFaint,
|
||||
trailingWidget: ToggleSwitchWidget(
|
||||
value: () =>
|
||||
NotificationService.instance
|
||||
.hasGrantedPermissions() &&
|
||||
localSettings
|
||||
.isOnThisDayNotificationsEnabled,
|
||||
onChanged: () async {
|
||||
await NotificationService.instance
|
||||
.requestPermissions();
|
||||
await memoriesCacheService
|
||||
.toggleOnThisDayNotifications();
|
||||
},
|
||||
),
|
||||
singleBorderRadius: 8,
|
||||
alignCaptionedTextToLeft: true,
|
||||
isGestureDetectorDisabled: true,
|
||||
),
|
||||
const MenuSectionDescriptionWidget(
|
||||
content:
|
||||
"Receive reminders about memories from this day in previous years.",
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -26,6 +26,8 @@ class LocalSettings {
|
||||
static const kRateUsShownCount = "rate_us_shown_count";
|
||||
static const kEnableMultiplePart = "ls.enable_multiple_part";
|
||||
static const kCuratedMemoriesEnabled = "ls.curated_memories_enabled";
|
||||
static const kOnThisDayNotificationsEnabled =
|
||||
"ls.on_this_day_notifications_enabled";
|
||||
static const kRateUsPromptThreshold = 2;
|
||||
static const shouldLoopVideoKey = "video.should_loop";
|
||||
static const onGuestViewKey = "on_guest_view";
|
||||
@@ -119,6 +121,14 @@ class LocalSettings {
|
||||
return value;
|
||||
}
|
||||
|
||||
bool get isOnThisDayNotificationsEnabled =>
|
||||
_prefs.getBool(kOnThisDayNotificationsEnabled) ?? true;
|
||||
|
||||
Future<bool> setOnThisDayNotificationsEnabled(bool value) async {
|
||||
await _prefs.setBool(kOnThisDayNotificationsEnabled, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
bool get userEnabledMultiplePart =>
|
||||
_prefs.getBool(kEnableMultiplePart) ?? false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user