Skip to content

Commit

Permalink
Show notification experimental warning
Browse files Browse the repository at this point in the history
  • Loading branch information
micahmo committed Jan 7, 2024
1 parent 185ac27 commit 9f31e34
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
"@dimReadPosts": {
"description": "Description of the effect on read posts."
},
"disable": "Disable",
"@disable": {
"description": "Action for disabling something"
},
"dismissRead": "Dismiss Read",
"@dismissRead": {},
"displayUserScore": "Display User Scores (Karma).",
Expand Down Expand Up @@ -321,7 +325,7 @@
"@enableFeedFab": {
"description": "Enable the Floating Action Button for the feed"
},
"enableInboxNotifications": "Enable Inbox Notifications",
"enableInboxNotifications": "Enable Inbox Notifications (Experimental)",
"@enableInboxNotifications": {
"description": "Setting name for inbox notifications"
},
Expand Down Expand Up @@ -599,6 +603,10 @@
"@notificationsNotAllowed": {
"description": "Description for when notifications are now allowed for app"
},
"notificationsWarningDialog": "Notifications are an experimental feature which may not function correctly on all devices.\n\n· Checks will occur every ~15 minutes and will consume additional battery.\n\n· Disable battery optimizations for a higher likelihood of successful notifications.\n\nSee the following page for more information.",
"@notificationsWarningDialog": {
"description": "The content of the warning dialog for the notifications feature"
},
"off": "off",
"@off": {},
"ok": "OK",
Expand Down Expand Up @@ -977,6 +985,10 @@
"@unblockInstance": {
"description": "Tooltip for unblocking an instance"
},
"understandEnable": "I Understand, Enable",
"@understandEnable": {
"description": "Action for acknowledging and enabling something"
},
"unexpectedError": "Unexpected Error",
"@unexpectedError": {},
"unsubscribe": "Unsubscribe",
Expand Down Expand Up @@ -1029,6 +1041,10 @@
"@visitInstance": {},
"visitUserProfile": "Visit User Profile",
"@visitUserProfile": {},
"warning": "Warning",
"@warning": {
"description": "Heading for warning dialogs"
},
"xDownvotes": "{x} downvotes",
"@xDownvotes": {},
"xScore": "{x} score",
Expand Down
42 changes: 41 additions & 1 deletion lib/settings/pages/general_settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:go_router/go_router.dart';

import 'package:lemmy_api_client/v3.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -18,11 +19,13 @@ import 'package:thunder/settings/widgets/list_option.dart';
import 'package:thunder/settings/widgets/settings_list_tile.dart';
import 'package:thunder/settings/widgets/toggle_option.dart';
import 'package:thunder/shared/comment_sort_picker.dart';
import 'package:thunder/shared/dialogs.dart';
import 'package:thunder/shared/sort_picker.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';
import 'package:thunder/utils/bottom_sheet_list_picker.dart';
import 'package:thunder/utils/constants.dart';
import 'package:thunder/utils/language/language.dart';
import 'package:thunder/utils/links.dart';

class GeneralSettingsPage extends StatefulWidget {
const GeneralSettingsPage({super.key});
Expand Down Expand Up @@ -633,6 +636,43 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
iconEnabled: Icons.notifications_on_rounded,
iconDisabled: Icons.notifications_off_rounded,
onToggle: (bool value) async {
// Show a warning message about the experimental nature of this feature.
// This message is specific to Android.
if (!kIsWeb && Platform.isAndroid && value) {
bool res = false;
await showThunderDialog(
context: context,
title: l10n.warning,
contentWidgetBuilder: (_) => Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(l10n.notificationsWarningDialog),
const SizedBox(height: 10),
Align(
alignment: Alignment.centerLeft,
child: GestureDetector(
onTap: () => handleLink(context, url: 'https://dontkillmyapp.com/'),
child: Text(
'https://dontkillmyapp.com/',
style: theme.textTheme.bodyMedium?.copyWith(color: Colors.blue),
),
),
),
],
),
primaryButtonText: l10n.understandEnable,
onPrimaryButtonPressed: (dialogContext, _) {
res = true;
dialogContext.pop();
},
secondaryButtonText: l10n.disable,
onSecondaryButtonPressed: (dialogContext) => dialogContext.pop(),
);

// The user chose not to enable the feature
if (!res) return;
}

setPreferences(LocalSettings.enableInboxNotifications, value);

if (!kIsWeb && Platform.isAndroid && value) {
Expand Down Expand Up @@ -662,7 +702,7 @@ class _GeneralSettingsPageState extends State<GeneralSettingsPage> with SingleTi
},
subtitle: enableInboxNotifications
? !kIsWeb && Platform.isAndroid && areAndroidNotificationsAllowed == true
? l10n.backgroundCheckWarning
? null
: l10n.notificationsNotAllowed
: null,
),
Expand Down

0 comments on commit 9f31e34

Please sign in to comment.