Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
feat: Add restart required note when importing data
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Jul 19, 2023
1 parent c2bf9d7 commit 8a854e8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@
"settingsScreen_import_file": "Import file",
"settingsScreen_import_pickerTitle": "Select the export.locus.json file to import your data",
"settingsScreen_import_transfer": "Transfer from old device",
"settingsScreen_import_confirmation_title": "Are you sure you want to import your data?",
"settingsScreen_import_confirmation_description": "Do you want to import your data? THIS WILL OVERWRITE YOUR CURRENT DATA (SHARES, SETTINGS, ETC.) WITH THE DATA FROM THE IMPORT!",
"settingsScreen_import_confirmation_confirm": "Import",
"settingsScreen_import_restart_title": "Restart Locus",
"settingsScreen_import_restart_description": "Locus needs to be restart to finish the import. Please restart the app now.",
"settingsScreen_version": "Version {version} ({flavor, select, gms{GMS} floss{FLOSS} other{Unknown}})",
"@settingsScreen_version": {
"placeholders": {
Expand Down
30 changes: 29 additions & 1 deletion lib/screens/SettingsScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,35 @@ class _SettingsScreenState extends State<SettingsScreen> {
]);

if (context.mounted) {
Navigator.pop(context, true);
final shouldClose =
await showPlatformDialog(
context: context,
barrierDismissible: !Platform.isAndroid,
builder: (context) => PlatformAlertDialog(
title: Text(l10n
.settingsScreen_import_restart_title),
content: Text(l10n
.settingsScreen_import_restart_description),
actions: [
PlatformDialogAction(
child: Text(l10n.closeApp),
onPressed: () => Navigator.pop(
context, Platform.isAndroid),
),
],
),
);

if (!mounted) {
return;
}

if (shouldClose != true) {
Navigator.pop(context);
return;
}

exit(0);
}
},
),
Expand Down
39 changes: 36 additions & 3 deletions lib/screens/settings_screen_widgets/ImportSheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:locus/services/settings_service.dart';
import 'package:locus/services/task_service.dart';
import 'package:locus/services/view_service.dart';
import 'package:locus/utils/PageRoute.dart';
import 'package:locus/utils/platform.dart';
import 'package:locus/widgets/PlatformFlavorWidget.dart';

import '../../constants/spacing.dart';
import '../../utils/theme.dart';
Expand All @@ -38,9 +40,40 @@ class ImportSheet extends StatefulWidget {
class _ImportSheetState extends State<ImportSheet> {
String errorMessage = "";

void parseRawData(final String rawData) async {
void importRawData(final String rawData) async {
final l10n = AppLocalizations.of(context);

final shouldImport = await showPlatformDialog(
context: context,
builder: (context) => PlatformAlertDialog(
material: (context, __) => MaterialAlertDialogData(
icon: PlatformFlavorWidget(
material: (context, _) => const Icon(Icons.warning_rounded),
cupertino: (context, _) =>
const Icon(CupertinoIcons.exclamationmark_triangle_fill),
),
),
title: Text(l10n.settingsScreen_import_confirmation_title),
content: Text(l10n.settingsScreen_import_confirmation_description),
actions: createCancellableDialogActions(
context,
[
PlatformDialogAction(
material: (context, _) => MaterialDialogActionData(
icon: const Icon(Icons.download_rounded),
),
child: Text(l10n.settingsScreen_import_confirmation_confirm),
onPressed: () => Navigator.pop(context, true),
),
],
),
),
);

if (shouldImport != true || !mounted) {
return;
}

try {
final data = jsonDecode(rawData);
final tasks = TaskService(
Expand Down Expand Up @@ -108,7 +141,7 @@ class _ImportSheetState extends State<ImportSheet> {
final content = String.fromCharCodes(
List<int>.from(result.files[0].bytes!));

parseRawData(content);
importRawData(content);
} catch (_) {
setState(() {
errorMessage = l10n.unknownError;
Expand All @@ -131,7 +164,7 @@ class _ImportSheetState extends State<ImportSheet> {
NativePageRoute(
context: context,
builder: (context) => TransferReceiverScreen(
onContentReceived: parseRawData),
onContentReceived: importRawData),
),
);
},
Expand Down

0 comments on commit 8a854e8

Please sign in to comment.