2024-01-22 23:32:21 +01:00
|
|
|
import 'dart:async';
|
2023-12-25 20:29:51 +01:00
|
|
|
import 'dart:io';
|
|
|
|
|
2023-09-08 11:50:21 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-29 21:39:54 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2024-01-22 23:32:21 +01:00
|
|
|
import 'package:prasule/api/wallet_manager.dart';
|
2023-12-25 20:29:51 +01:00
|
|
|
import 'package:prasule/main.dart';
|
2024-01-22 23:32:21 +01:00
|
|
|
import 'package:prasule/pw/platformbutton.dart';
|
2023-12-25 19:03:52 +01:00
|
|
|
import 'package:prasule/pw/platformroute.dart';
|
2024-01-22 23:32:21 +01:00
|
|
|
import 'package:prasule/util/show_message.dart';
|
2023-12-29 21:39:54 +01:00
|
|
|
import 'package:prasule/views/settings/edit_categories.dart';
|
2023-12-25 19:03:52 +01:00
|
|
|
import 'package:prasule/views/settings/graph_type.dart';
|
2023-09-08 11:50:21 +02:00
|
|
|
import 'package:prasule/views/settings/tessdata_list.dart';
|
|
|
|
import 'package:settings_ui/settings_ui.dart';
|
2023-12-25 20:29:51 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2023-09-08 11:50:21 +02:00
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Shows settings categories
|
2023-09-08 11:50:21 +02:00
|
|
|
class SettingsView extends StatefulWidget {
|
2023-12-29 21:39:54 +01:00
|
|
|
/// Shows settings categories
|
2023-09-08 11:50:21 +02:00
|
|
|
const SettingsView({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<SettingsView> createState() => _SettingsViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsViewState extends State<SettingsView> {
|
2023-12-25 20:29:51 +01:00
|
|
|
var _useMaterialYou = true;
|
|
|
|
final _supportsYou = MyApp.appliedYou;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
SharedPreferences.getInstance().then((s) {
|
|
|
|
_useMaterialYou = s.getBool("useMaterialYou") ?? true;
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-08 11:50:21 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2023-12-25 19:03:52 +01:00
|
|
|
appBar: AppBar(title: Text(AppLocalizations.of(context).settings)),
|
2023-09-08 11:50:21 +02:00
|
|
|
body: SettingsList(
|
2023-10-06 18:37:06 +02:00
|
|
|
applicationType: ApplicationType.both,
|
|
|
|
darkTheme: SettingsThemeData(
|
2024-04-22 17:05:22 +02:00
|
|
|
settingsListBackground: Theme.of(context).colorScheme.surface,
|
2023-12-29 21:39:54 +01:00
|
|
|
titleTextColor: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
sections: [
|
2023-12-29 21:39:54 +01:00
|
|
|
SettingsSection(
|
2023-12-31 12:41:10 +01:00
|
|
|
title: Text(AppLocalizations.of(context).wallet),
|
2023-12-29 21:39:54 +01:00
|
|
|
tiles: [
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).editCategories),
|
|
|
|
description:
|
|
|
|
Text(AppLocalizations.of(context).editCategoriesDesc),
|
|
|
|
trailing: const Icon(Icons.keyboard_arrow_right),
|
|
|
|
onPressed: (context) => Navigator.of(context).push(
|
|
|
|
platformRoute(
|
|
|
|
(c) => const EditCategoriesView(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
SettingsSection(
|
|
|
|
tiles: [
|
|
|
|
SettingsTile.navigation(
|
2023-12-25 19:03:52 +01:00
|
|
|
title: Text(AppLocalizations.of(context).downloadedOcr),
|
2023-10-11 18:37:18 +02:00
|
|
|
description:
|
2023-12-25 19:03:52 +01:00
|
|
|
Text(AppLocalizations.of(context).downloadedOcrDesc),
|
|
|
|
trailing: const Icon(Icons.keyboard_arrow_right),
|
2023-12-29 21:39:54 +01:00
|
|
|
onPressed: (context) => Navigator.of(context).push(
|
|
|
|
platformRoute(
|
|
|
|
(c) => const TessdataListView(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
],
|
2023-12-25 19:03:52 +01:00
|
|
|
title: Text(AppLocalizations.of(context).ocr),
|
2023-09-08 11:50:21 +02:00
|
|
|
),
|
2023-12-25 19:03:52 +01:00
|
|
|
SettingsSection(
|
|
|
|
title: Text(AppLocalizations.of(context).settingsAppearance),
|
|
|
|
tiles: [
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).graphType),
|
|
|
|
description: Text(AppLocalizations.of(context).graphTypeDesc),
|
|
|
|
trailing: const Icon(Icons.keyboard_arrow_right),
|
|
|
|
onPressed: (c) => Navigator.of(c).push(
|
|
|
|
platformRoute(
|
|
|
|
(p0) => const GraphTypeSettingsView(),
|
|
|
|
),
|
|
|
|
),
|
2023-12-25 20:29:51 +01:00
|
|
|
),
|
|
|
|
if (Platform.isAndroid && _supportsYou)
|
|
|
|
SettingsTile.switchTile(
|
|
|
|
initialValue: _useMaterialYou,
|
|
|
|
onToggle: (v) async {
|
2023-12-29 21:39:54 +01:00
|
|
|
final s = await SharedPreferences.getInstance();
|
|
|
|
await s.setBool("useMaterialYou", v);
|
2023-12-25 20:29:51 +01:00
|
|
|
_useMaterialYou = v;
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
title: Text(AppLocalizations.of(context).enableYou),
|
2023-12-29 21:39:54 +01:00
|
|
|
description: Text(
|
|
|
|
AppLocalizations.of(context).enableYouDesc,
|
|
|
|
),
|
|
|
|
),
|
2023-12-25 19:03:52 +01:00
|
|
|
],
|
2023-12-29 21:39:54 +01:00
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
if (!Platform.isIOS)
|
|
|
|
SettingsSection(
|
|
|
|
//! TODO: Find a replacement for iOS
|
|
|
|
title: Text(AppLocalizations.of(context).settingsData),
|
|
|
|
tiles: [
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).exportSingle),
|
|
|
|
description:
|
|
|
|
Text(AppLocalizations.of(context).exportSingleDesc),
|
|
|
|
onPressed: (ctx) async {
|
|
|
|
final all = await WalletManager.listWallets();
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
final w = await showAdaptiveDialog<String>(
|
|
|
|
context: ctx,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context).selectExportWallet,
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
actions: [
|
|
|
|
PlatformButton(
|
|
|
|
text: AppLocalizations.of(context).cancel,
|
|
|
|
onPressed: () => Navigator.of(ctx).pop(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
content: SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width * 0.7,
|
|
|
|
height: MediaQuery.of(context).size.height * 0.3,
|
|
|
|
child: ListView.builder(
|
|
|
|
itemBuilder: (con, i) => InkWell(
|
|
|
|
onTap: () => Navigator.of(ctx).pop(all[i].name),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(
|
|
|
|
all[i].name,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
shrinkWrap: true,
|
|
|
|
itemCount: all.length,
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
);
|
|
|
|
if (w == null) return;
|
|
|
|
try {
|
|
|
|
await WalletManager.exportWallet(name: w);
|
|
|
|
} catch (e) {
|
|
|
|
if (!context.mounted) return;
|
|
|
|
unawaited(
|
|
|
|
showAdaptiveDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context).exportError,
|
|
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Flexible(
|
|
|
|
child: Text(e.toString()),
|
|
|
|
),
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
);
|
|
|
|
logger.e(e);
|
|
|
|
return;
|
|
|
|
}
|
2024-01-22 23:32:21 +01:00
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
2024-01-29 23:51:25 +01:00
|
|
|
showMessage(
|
|
|
|
AppLocalizations.of(ctx).exportCompleted,
|
|
|
|
ctx,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).exportArchive),
|
|
|
|
description:
|
|
|
|
Text(AppLocalizations.of(context).exportArchiveDesc),
|
|
|
|
onPressed: (ctx) async {
|
|
|
|
try {
|
|
|
|
await WalletManager.exportAllWallets();
|
|
|
|
} catch (e) {
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
|
|
|
showAdaptiveDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context).exportError,
|
|
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Flexible(
|
|
|
|
child: Text(e.toString()),
|
|
|
|
),
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
);
|
|
|
|
logger.e(e);
|
|
|
|
return;
|
|
|
|
}
|
2024-01-22 23:32:21 +01:00
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
2024-01-29 23:51:25 +01:00
|
|
|
showMessage(
|
|
|
|
AppLocalizations.of(ctx).exportCompleted,
|
|
|
|
context,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).importSingle),
|
|
|
|
description:
|
|
|
|
Text(AppLocalizations.of(context).importSingleDesc),
|
|
|
|
onPressed: (ctx) async {
|
|
|
|
try {
|
|
|
|
await WalletManager.importWallet();
|
|
|
|
} catch (e) {
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
|
|
|
showAdaptiveDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context).exportError,
|
|
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Flexible(
|
|
|
|
child: Text(e.toString()),
|
|
|
|
),
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
);
|
|
|
|
logger.e(e);
|
|
|
|
return;
|
|
|
|
}
|
2024-01-22 23:32:21 +01:00
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
2024-01-29 23:51:25 +01:00
|
|
|
showMessage(
|
|
|
|
AppLocalizations.of(ctx).importCompleted,
|
|
|
|
context,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
SettingsTile.navigation(
|
|
|
|
title: Text(AppLocalizations.of(context).importArchive),
|
|
|
|
description:
|
|
|
|
Text(AppLocalizations.of(context).importArchiveDesc),
|
|
|
|
onPressed: (ctx) async {
|
|
|
|
try {
|
|
|
|
await WalletManager.importArchive();
|
|
|
|
} catch (e) {
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
|
|
|
showAdaptiveDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog.adaptive(
|
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context).exportError,
|
|
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Flexible(
|
|
|
|
child: Text(e.toString()),
|
|
|
|
),
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-29 23:51:25 +01:00
|
|
|
);
|
|
|
|
logger.e(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ctx.mounted) return;
|
|
|
|
unawaited(
|
|
|
|
showMessage(
|
|
|
|
AppLocalizations.of(ctx).importCompleted,
|
|
|
|
context,
|
2024-01-22 23:32:21 +01:00
|
|
|
),
|
|
|
|
);
|
2024-01-29 23:51:25 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|