Skip to content

Commit

Permalink
feat(neon,neon_news,neon_files,neon_notes,neon_notifications): make d…
Browse files Browse the repository at this point in the history
…ialog adaptive

Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Nov 13, 2023
1 parent be85303 commit 9c9ea70
Show file tree
Hide file tree
Showing 42 changed files with 1,438 additions and 771 deletions.
6 changes: 6 additions & 0 deletions packages/neon/neon/lib/l10n/en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@
}
}
},
"errorDialog": "An error has occurred",
"actionYes": "Yes",
"actionNo": "No",
"actionClose": "Close",
"actionRetry": "Retry",
"actionShowSlashHide": "Show/Hide",
"actionExit": "Exit",
"actionContinue": "Continue",
"actionCancel": "Cancel",
"firstLaunchGoToSettingsToEnablePushNotifications": "Go to the settings to enable push notifications",
"nextPushSupported": "NextPush is supported!",
"nextPushSupportedText": "NextPush is a FOSS way of receiving push notifications using the UnifiedPush protocol via a Nextcloud instance.\nYou can install NextPush from the F-Droid app store.",
Expand All @@ -97,9 +99,11 @@
"settingsAccountManage": "Manage accounts",
"settingsExport": "Export settings",
"settingsImport": "Import settings",
"settingsReset": "Reset settings?",
"settingsImportWrongFileExtension": "Settings import has wrong file extension (has to be .json.base64)",
"settingsResetAll": "Reset all settings",
"settingsResetAllConfirmation": "Do you want to reset all settings?",
"settingsResetAllExplanation": "This will reset all preferences back to their default settings.",
"settingsResetFor": "Reset all settings for {name}",
"@settingsResetFor": {
"placeholders": {
Expand All @@ -108,6 +112,8 @@
}
}
},
"settingsResetForExplanation": "This will reset your account preferences back to their default settings.",
"settingsResetForClientExplanation": "This will reset all preferences for the app back to their default settings.",
"settingsResetForConfirmation": "Do you want to reset all settings for {name}?",
"@settingsResetForConfirmation": {
"placeholders": {
Expand Down
36 changes: 36 additions & 0 deletions packages/neon/neon/lib/l10n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ abstract class NeonLocalizations {
/// **'Route not found: {route}'**
String errorRouteNotFound(String route);

/// No description provided for @errorDialog.
///
/// In en, this message translates to:
/// **'An error has occurred'**
String get errorDialog;

/// No description provided for @actionYes.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -311,6 +317,12 @@ abstract class NeonLocalizations {
/// **'Continue'**
String get actionContinue;

/// No description provided for @actionCancel.
///
/// In en, this message translates to:
/// **'Cancel'**
String get actionCancel;

/// No description provided for @firstLaunchGoToSettingsToEnablePushNotifications.
///
/// In en, this message translates to:
Expand Down Expand Up @@ -389,6 +401,12 @@ abstract class NeonLocalizations {
/// **'Import settings'**
String get settingsImport;

/// No description provided for @settingsReset.
///
/// In en, this message translates to:
/// **'Reset settings?'**
String get settingsReset;

/// No description provided for @settingsImportWrongFileExtension.
///
/// In en, this message translates to:
Expand All @@ -407,12 +425,30 @@ abstract class NeonLocalizations {
/// **'Do you want to reset all settings?'**
String get settingsResetAllConfirmation;

/// No description provided for @settingsResetAllExplanation.
///
/// In en, this message translates to:
/// **'This will reset all preferences back to their default settings.'**
String get settingsResetAllExplanation;

/// No description provided for @settingsResetFor.
///
/// In en, this message translates to:
/// **'Reset all settings for {name}'**
String settingsResetFor(String name);

/// No description provided for @settingsResetForExplanation.
///
/// In en, this message translates to:
/// **'This will reset your account preferences back to their default settings.'**
String get settingsResetForExplanation;

/// No description provided for @settingsResetForClientExplanation.
///
/// In en, this message translates to:
/// **'This will reset all preferences for the app back to their default settings.'**
String get settingsResetForClientExplanation;

/// No description provided for @settingsResetForConfirmation.
///
/// In en, this message translates to:
Expand Down
19 changes: 19 additions & 0 deletions packages/neon/neon/lib/l10n/localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class NeonLocalizationsEn extends NeonLocalizations {
return 'Route not found: $route';
}

@override
String get errorDialog => 'An error has occurred';

@override
String get actionYes => 'Yes';

Expand All @@ -147,6 +150,9 @@ class NeonLocalizationsEn extends NeonLocalizations {
@override
String get actionContinue => 'Continue';

@override
String get actionCancel => 'Cancel';

@override
String get firstLaunchGoToSettingsToEnablePushNotifications => 'Go to the settings to enable push notifications';

Expand Down Expand Up @@ -187,6 +193,9 @@ class NeonLocalizationsEn extends NeonLocalizations {
@override
String get settingsImport => 'Import settings';

@override
String get settingsReset => 'Reset settings?';

@override
String get settingsImportWrongFileExtension => 'Settings import has wrong file extension (has to be .json.base64)';

Expand All @@ -196,11 +205,21 @@ class NeonLocalizationsEn extends NeonLocalizations {
@override
String get settingsResetAllConfirmation => 'Do you want to reset all settings?';

@override
String get settingsResetAllExplanation => 'This will reset all preferences back to their default settings.';

@override
String settingsResetFor(String name) {
return 'Reset all settings for $name';
}

@override
String get settingsResetForExplanation => 'This will reset your account preferences back to their default settings.';

@override
String get settingsResetForClientExplanation =>
'This will reset all preferences for the app back to their default settings.';

@override
String settingsResetForConfirmation(String name) {
return 'Do you want to reset all settings for $name?';
Expand Down
36 changes: 26 additions & 10 deletions packages/neon/neon/lib/src/pages/account_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:neon/src/settings/widgets/settings_category.dart';
import 'package:neon/src/settings/widgets/settings_list.dart';
import 'package:neon/src/theme/dialog.dart';
import 'package:neon/src/utils/adaptive.dart';
import 'package:neon/src/utils/dialog.dart';
import 'package:neon/src/widgets/dialog.dart';
import 'package:neon/src/widgets/error.dart';
import 'package:nextcloud/provisioning_api.dart' as provisioning_api;

Expand Down Expand Up @@ -46,15 +46,23 @@ class AccountSettingsPage extends StatelessWidget {
actions: [
IconButton(
onPressed: () async {
if (await showConfirmationDialog(
context,
NeonLocalizations.of(context).accountOptionsRemoveConfirm(account.humanReadableID),
)) {
final decision = await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
icon: const Icon(Icons.logout),
title: NeonLocalizations.of(context).accountOptionsRemove,
content: Text(
NeonLocalizations.of(context).accountOptionsRemoveConfirm(account.humanReadableID),
),
),
);

if (decision ?? false) {
final isActive = bloc.activeAccount.valueOrNull == account;

options.reset();
bloc.removeAccount(account);

// ignore: use_build_context_synchronously
if (!context.mounted) {
return;
}
Expand All @@ -71,10 +79,18 @@ class AccountSettingsPage extends StatelessWidget {
),
IconButton(
onPressed: () async {
if (await showConfirmationDialog(
context,
NeonLocalizations.of(context).settingsResetForConfirmation(name),
)) {
final content =
'${NeonLocalizations.of(context).settingsResetForConfirmation(name)} ${NeonLocalizations.of(context).settingsResetForExplanation}';
final decision = await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
icon: const Icon(Icons.restart_alt),
title: NeonLocalizations.of(context).settingsReset,
content: Text(content),
),
);

if (decision ?? false) {
options.reset();
}
},
Expand Down
34 changes: 5 additions & 29 deletions packages/neon/neon/lib/src/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';

import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/result.dart';
import 'package:neon/src/blocs/accounts.dart';
import 'package:neon/src/blocs/apps.dart';
Expand All @@ -11,11 +10,11 @@ import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:neon/src/utils/global_options.dart' as global_options;
import 'package:neon/src/utils/global_popups.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/widgets/app_bar.dart';
import 'package:neon/src/widgets/drawer.dart';
import 'package:neon/src/widgets/error.dart';
import 'package:neon/src/widgets/unified_search_results.dart';
import 'package:neon/utils.dart';
import 'package:nextcloud/core.dart' as core;
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -68,7 +67,7 @@ class _HomePageState extends State<HomePage> {
}

final message = l10n.errorUnsupportedAppVersions(buffer.toString());
unawaited(_showProblem(message));
unawaited(showErrorDialog(context: context, message: message));
});

GlobalPopups().register(context);
Expand All @@ -86,10 +85,10 @@ class _HomePageState extends State<HomePage> {
Future<void> _checkMaintenanceMode() async {
try {
final status = await _account.client.core.getStatus();

if (status.body.maintenance && mounted) {
await _showProblem(
NeonLocalizations.of(context).errorServerInMaintenanceMode,
);
final message = NeonLocalizations.of(context).errorServerInMaintenanceMode;
await showErrorDialog(context: context, message: message);
}
} catch (e, s) {
debugPrint(e.toString());
Expand All @@ -100,29 +99,6 @@ class _HomePageState extends State<HomePage> {
}
}

Future<void> _showProblem(final String title) async {
final colorScheme = Theme.of(context).colorScheme;

await showDialog<void>(
context: context,
builder: (final context) => AlertDialog(
title: Text(title),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: colorScheme.error,
foregroundColor: colorScheme.onError,
),
onPressed: () {
Navigator.of(context).pop();
},
child: Text(NeonLocalizations.of(context).actionClose),
),
],
),
);
}

@override
Widget build(final BuildContext context) {
const drawer = NeonDrawer();
Expand Down
19 changes: 14 additions & 5 deletions packages/neon/neon/lib/src/pages/nextcloud_app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:neon/src/settings/widgets/option_settings_tile.dart';
import 'package:neon/src/settings/widgets/settings_category.dart';
import 'package:neon/src/settings/widgets/settings_list.dart';
import 'package:neon/src/theme/dialog.dart';
import 'package:neon/src/utils/dialog.dart';
import 'package:neon/src/widgets/dialog.dart';

@internal
class NextcloudAppSettingsPage extends StatelessWidget {
Expand All @@ -25,10 +25,19 @@ class NextcloudAppSettingsPage extends StatelessWidget {
actions: [
IconButton(
onPressed: () async {
if (await showConfirmationDialog(
context,
NeonLocalizations.of(context).settingsResetForConfirmation(appImplementation.name(context)),
)) {
final content =
'${NeonLocalizations.of(context).settingsResetForConfirmation(appImplementation.name(context))} ${NeonLocalizations.of(context).settingsResetForClientExplanation}';

final decision = await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
icon: const Icon(Icons.restart_alt),
title: NeonLocalizations.of(context).settingsReset,
content: Text(content),
),
);

if (decision ?? false) {
appImplementation.options.reset();
}
},
Expand Down
15 changes: 13 additions & 2 deletions packages/neon/neon/lib/src/pages/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import 'package:neon/src/settings/widgets/text_settings_tile.dart';
import 'package:neon/src/theme/branding.dart';
import 'package:neon/src/theme/dialog.dart';
import 'package:neon/src/utils/adaptive.dart';
import 'package:neon/src/utils/dialog.dart';
import 'package:neon/src/utils/global_options.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/utils/save_file.dart';
import 'package:neon/src/widgets/dialog.dart';
import 'package:neon/src/widgets/error.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
Expand Down Expand Up @@ -96,7 +96,18 @@ class _SettingsPageState extends State<SettingsPage> {
actions: [
IconButton(
onPressed: () async {
if (await showConfirmationDialog(context, NeonLocalizations.of(context).settingsResetAllConfirmation)) {
final content =
'${NeonLocalizations.of(context).settingsResetAllConfirmation} ${NeonLocalizations.of(context).settingsResetAllExplanation}';
final decision = await showAdaptiveDialog<bool>(
context: context,
builder: (final context) => NeonConfirmationDialog(
icon: const Icon(Icons.restart_alt),
title: NeonLocalizations.of(context).settingsReset,
content: Text(content),
),
);

if (decision ?? false) {
globalOptions.reset();

for (final appImplementation in appImplementations) {
Expand Down
Loading

0 comments on commit 9c9ea70

Please sign in to comment.