|
|
@ -19,6 +19,7 @@ import 'package:neon/src/settings/widgets/settings_list.dart'; |
|
|
|
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
|
|
|
import 'package:neon/src/settings/widgets/settings_tile.dart'; |
|
|
|
import 'package:neon/src/settings/widgets/text_settings_tile.dart'; |
|
|
|
import 'package:neon/src/settings/widgets/text_settings_tile.dart'; |
|
|
|
import 'package:neon/src/theme/branding.dart'; |
|
|
|
import 'package:neon/src/theme/branding.dart'; |
|
|
|
|
|
|
|
import 'package:neon/src/theme/dialog.dart'; |
|
|
|
import 'package:neon/src/utils/confirmation_dialog.dart'; |
|
|
|
import 'package:neon/src/utils/confirmation_dialog.dart'; |
|
|
|
import 'package:neon/src/utils/global_options.dart'; |
|
|
|
import 'package:neon/src/utils/global_options.dart'; |
|
|
|
import 'package:neon/src/utils/save_file.dart'; |
|
|
|
import 'package:neon/src/utils/save_file.dart'; |
|
|
@ -27,11 +28,25 @@ import 'package:neon/src/widgets/exception.dart'; |
|
|
|
import 'package:package_info_plus/package_info_plus.dart'; |
|
|
|
import 'package:package_info_plus/package_info_plus.dart'; |
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
import 'package:provider/provider.dart'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum SettingsCageories { |
|
|
|
|
|
|
|
apps, |
|
|
|
|
|
|
|
theme, |
|
|
|
|
|
|
|
navigation, |
|
|
|
|
|
|
|
pushNotifications, |
|
|
|
|
|
|
|
startup, |
|
|
|
|
|
|
|
systemTray, |
|
|
|
|
|
|
|
accounts, |
|
|
|
|
|
|
|
other, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class SettingsPage extends StatefulWidget { |
|
|
|
class SettingsPage extends StatefulWidget { |
|
|
|
const SettingsPage({ |
|
|
|
const SettingsPage({ |
|
|
|
|
|
|
|
this.initialCategory, |
|
|
|
super.key, |
|
|
|
super.key, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final SettingsCageories? initialCategory; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
State<SettingsPage> createState() => _SettingsPageState(); |
|
|
|
State<SettingsPage> createState() => _SettingsPageState(); |
|
|
|
} |
|
|
|
} |
|
|
@ -42,271 +57,289 @@ class _SettingsPageState extends State<SettingsPage> { |
|
|
|
final globalOptions = Provider.of<GlobalOptions>(context); |
|
|
|
final globalOptions = Provider.of<GlobalOptions>(context); |
|
|
|
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false); |
|
|
|
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false); |
|
|
|
final appImplementations = Provider.of<Iterable<AppImplementation>>(context); |
|
|
|
final appImplementations = Provider.of<Iterable<AppImplementation>>(context); |
|
|
|
return Scaffold( |
|
|
|
|
|
|
|
resizeToAvoidBottomInset: false, |
|
|
|
|
|
|
|
appBar: AppBar( |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).settings), |
|
|
|
|
|
|
|
actions: [ |
|
|
|
|
|
|
|
IconButton( |
|
|
|
|
|
|
|
onPressed: () async { |
|
|
|
|
|
|
|
if (await showConfirmationDialog(context, AppLocalizations.of(context).settingsResetAllConfirmation)) { |
|
|
|
|
|
|
|
await globalOptions.reset(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (final appImplementation in appImplementations) { |
|
|
|
final appBar = AppBar( |
|
|
|
await appImplementation.options.reset(); |
|
|
|
title: Text(AppLocalizations.of(context).settings), |
|
|
|
} |
|
|
|
actions: [ |
|
|
|
|
|
|
|
IconButton( |
|
|
|
|
|
|
|
onPressed: () async { |
|
|
|
|
|
|
|
if (await showConfirmationDialog(context, AppLocalizations.of(context).settingsResetAllConfirmation)) { |
|
|
|
|
|
|
|
await globalOptions.reset(); |
|
|
|
|
|
|
|
|
|
|
|
for (final account in accountsBloc.accounts.value) { |
|
|
|
for (final appImplementation in appImplementations) { |
|
|
|
await accountsBloc.getOptionsFor(account).reset(); |
|
|
|
await appImplementation.options.reset(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
tooltip: AppLocalizations.of(context).settingsResetAll, |
|
|
|
for (final account in accountsBloc.accounts.value) { |
|
|
|
icon: Icon(MdiIcons.cogRefresh), |
|
|
|
await accountsBloc.getOptionsFor(account).reset(); |
|
|
|
), |
|
|
|
} |
|
|
|
], |
|
|
|
} |
|
|
|
), |
|
|
|
}, |
|
|
|
body: StreamBuilder<List<Account>>( |
|
|
|
tooltip: AppLocalizations.of(context).settingsResetAll, |
|
|
|
stream: accountsBloc.accounts, |
|
|
|
icon: Icon(MdiIcons.cogRefresh), |
|
|
|
builder: ( |
|
|
|
), |
|
|
|
final context, |
|
|
|
], |
|
|
|
final accountsSnapshot, |
|
|
|
); |
|
|
|
) { |
|
|
|
final body = StreamBuilder<List<Account>>( |
|
|
|
final settingsExportHelper = SettingsExportHelper( |
|
|
|
stream: accountsBloc.accounts, |
|
|
|
globalOptions: globalOptions, |
|
|
|
initialData: accountsBloc.accounts.valueOrNull, |
|
|
|
appImplementations: appImplementations, |
|
|
|
builder: ( |
|
|
|
accountSpecificOptions: { |
|
|
|
final context, |
|
|
|
if (accountsSnapshot.hasData) ...{ |
|
|
|
final accountsSnapshot, |
|
|
|
for (final account in accountsSnapshot.requireData) ...{ |
|
|
|
) { |
|
|
|
account: accountsBloc.getOptionsFor(account).options, |
|
|
|
final platform = Provider.of<NeonPlatform>(context, listen: false); |
|
|
|
}, |
|
|
|
return StreamBuilder<bool>( |
|
|
|
}, |
|
|
|
stream: globalOptions.pushNotificationsEnabled.enabled, |
|
|
|
}, |
|
|
|
initialData: globalOptions.pushNotificationsEnabled.enabled.valueOrNull, |
|
|
|
); |
|
|
|
builder: ( |
|
|
|
final platform = Provider.of<NeonPlatform>(context, listen: false); |
|
|
|
final context, |
|
|
|
return StreamBuilder<Account?>( |
|
|
|
final pushNotificationsEnabledEnabledSnapshot, |
|
|
|
stream: accountsBloc.activeAccount, |
|
|
|
) => |
|
|
|
builder: ( |
|
|
|
SettingsList( |
|
|
|
final context, |
|
|
|
initialCategory: widget.initialCategory?.name, |
|
|
|
final activeAccountSnapshot, |
|
|
|
categories: [ |
|
|
|
) => |
|
|
|
SettingsCategory( |
|
|
|
StreamBuilder<bool>( |
|
|
|
title: Text(AppLocalizations.of(context).settingsApps), |
|
|
|
stream: globalOptions.pushNotificationsEnabled.enabled, |
|
|
|
key: ValueKey(SettingsCageories.apps.name), |
|
|
|
builder: ( |
|
|
|
tiles: <SettingsTile>[ |
|
|
|
final context, |
|
|
|
for (final appImplementation in appImplementations) ...[ |
|
|
|
final pushNotificationsEnabledEnabledSnapshot, |
|
|
|
if (appImplementation.options.options.isNotEmpty) ...[ |
|
|
|
) => |
|
|
|
CustomSettingsTile( |
|
|
|
SettingsList( |
|
|
|
leading: appImplementation.buildIcon(), |
|
|
|
categories: [ |
|
|
|
title: Text(appImplementation.name(context)), |
|
|
|
SettingsCategory( |
|
|
|
onTap: () { |
|
|
|
title: Text(AppLocalizations.of(context).settingsApps), |
|
|
|
NextcloudAppSettingsRoute(appid: appImplementation.id).go(context); |
|
|
|
tiles: <SettingsTile>[ |
|
|
|
}, |
|
|
|
for (final appImplementation in appImplementations) ...[ |
|
|
|
|
|
|
|
if (appImplementation.options.options.isNotEmpty) ...[ |
|
|
|
|
|
|
|
CustomSettingsTile( |
|
|
|
|
|
|
|
leading: appImplementation.buildIcon(), |
|
|
|
|
|
|
|
title: Text(appImplementation.name(context)), |
|
|
|
|
|
|
|
onTap: () { |
|
|
|
|
|
|
|
NextcloudAppSettingsRoute(appid: appImplementation.id).go(context); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
SettingsCategory( |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryTheme), |
|
|
|
|
|
|
|
tiles: [ |
|
|
|
|
|
|
|
DropdownButtonSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.themeMode, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CheckBoxSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.themeOLEDAsDark, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CheckBoxSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.themeKeepOriginalAccentColor, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
SettingsCategory( |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryTheme), |
|
|
|
|
|
|
|
key: ValueKey(SettingsCageories.theme.name), |
|
|
|
|
|
|
|
tiles: [ |
|
|
|
|
|
|
|
DropdownButtonSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.themeMode, |
|
|
|
), |
|
|
|
), |
|
|
|
SettingsCategory( |
|
|
|
CheckBoxSettingsTile( |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryNavigation), |
|
|
|
option: globalOptions.themeOLEDAsDark, |
|
|
|
tiles: [ |
|
|
|
|
|
|
|
DropdownButtonSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.navigationMode, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
if (platform.canUsePushNotifications) ...[ |
|
|
|
CheckBoxSettingsTile( |
|
|
|
SettingsCategory( |
|
|
|
option: globalOptions.themeKeepOriginalAccentColor, |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryPushNotifications), |
|
|
|
), |
|
|
|
tiles: [ |
|
|
|
], |
|
|
|
if (pushNotificationsEnabledEnabledSnapshot.hasData && |
|
|
|
), |
|
|
|
!pushNotificationsEnabledEnabledSnapshot.requireData) ...[ |
|
|
|
SettingsCategory( |
|
|
|
TextSettingsTile( |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryNavigation), |
|
|
|
text: AppLocalizations.of(context).globalOptionsPushNotificationsEnabledDisabledNotice, |
|
|
|
key: ValueKey(SettingsCageories.navigation.name), |
|
|
|
style: TextStyle( |
|
|
|
tiles: [ |
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
DropdownButtonSettingsTile( |
|
|
|
fontStyle: FontStyle.italic, |
|
|
|
option: globalOptions.navigationMode, |
|
|
|
color: Theme.of(context).colorScheme.error, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
if (platform.canUsePushNotifications) ...[ |
|
|
|
CheckBoxSettingsTile( |
|
|
|
SettingsCategory( |
|
|
|
option: globalOptions.pushNotificationsEnabled, |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryPushNotifications), |
|
|
|
), |
|
|
|
key: ValueKey(SettingsCageories.pushNotifications.name), |
|
|
|
DropdownButtonSettingsTile( |
|
|
|
tiles: [ |
|
|
|
option: globalOptions.pushNotificationsDistributor, |
|
|
|
if (pushNotificationsEnabledEnabledSnapshot.hasData && |
|
|
|
|
|
|
|
!pushNotificationsEnabledEnabledSnapshot.requireData) ...[ |
|
|
|
|
|
|
|
TextSettingsTile( |
|
|
|
|
|
|
|
text: AppLocalizations.of(context).globalOptionsPushNotificationsEnabledDisabledNotice, |
|
|
|
|
|
|
|
style: TextStyle( |
|
|
|
|
|
|
|
fontWeight: FontWeight.w600, |
|
|
|
|
|
|
|
fontStyle: FontStyle.italic, |
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.error, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
CheckBoxSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.pushNotificationsEnabled, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
DropdownButtonSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.pushNotificationsDistributor, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
if (platform.canUseWindowManager) ...[ |
|
|
|
), |
|
|
|
SettingsCategory( |
|
|
|
], |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryStartup), |
|
|
|
if (platform.canUseWindowManager) ...[ |
|
|
|
tiles: [ |
|
|
|
SettingsCategory( |
|
|
|
CheckBoxSettingsTile( |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryStartup), |
|
|
|
option: globalOptions.startupMinimized, |
|
|
|
key: ValueKey(SettingsCageories.startup.name), |
|
|
|
), |
|
|
|
tiles: [ |
|
|
|
CheckBoxSettingsTile( |
|
|
|
CheckBoxSettingsTile( |
|
|
|
option: globalOptions.startupMinimizeInsteadOfExit, |
|
|
|
option: globalOptions.startupMinimized, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
CheckBoxSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.startupMinimizeInsteadOfExit, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
if (platform.canUseWindowManager && platform.canUseSystemTray) ...[ |
|
|
|
), |
|
|
|
SettingsCategory( |
|
|
|
], |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategorySystemTray), |
|
|
|
if (platform.canUseWindowManager && platform.canUseSystemTray) ...[ |
|
|
|
tiles: [ |
|
|
|
SettingsCategory( |
|
|
|
CheckBoxSettingsTile( |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategorySystemTray), |
|
|
|
option: globalOptions.systemTrayEnabled, |
|
|
|
key: ValueKey(SettingsCageories.systemTray.name), |
|
|
|
), |
|
|
|
tiles: [ |
|
|
|
CheckBoxSettingsTile( |
|
|
|
CheckBoxSettingsTile( |
|
|
|
option: globalOptions.systemTrayHideToTrayWhenMinimized, |
|
|
|
option: globalOptions.systemTrayEnabled, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
CheckBoxSettingsTile( |
|
|
|
|
|
|
|
option: globalOptions.systemTrayHideToTrayWhenMinimized, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
if (accountsSnapshot.hasData) ...[ |
|
|
|
), |
|
|
|
SettingsCategory( |
|
|
|
], |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryAccounts), |
|
|
|
SettingsCategory( |
|
|
|
tiles: [ |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryAccounts), |
|
|
|
if (accountsSnapshot.requireData.length > 1) ...[ |
|
|
|
key: ValueKey(SettingsCageories.accounts.name), |
|
|
|
CheckBoxSettingsTile( |
|
|
|
tiles: [ |
|
|
|
option: globalOptions.rememberLastUsedAccount, |
|
|
|
if (accountsSnapshot.requireData.length > 1) ...[ |
|
|
|
), |
|
|
|
CheckBoxSettingsTile( |
|
|
|
DropdownButtonSettingsTile( |
|
|
|
option: globalOptions.rememberLastUsedAccount, |
|
|
|
option: globalOptions.initialAccount, |
|
|
|
), |
|
|
|
), |
|
|
|
DropdownButtonSettingsTile( |
|
|
|
], |
|
|
|
option: globalOptions.initialAccount, |
|
|
|
for (final account in accountsSnapshot.requireData) ...[ |
|
|
|
|
|
|
|
AccountSettingsTile( |
|
|
|
|
|
|
|
account: account, |
|
|
|
|
|
|
|
onTap: () { |
|
|
|
|
|
|
|
AccountSettingsRoute(accountid: account.id).go(context); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
CustomSettingsTile( |
|
|
|
|
|
|
|
title: ElevatedButton.icon( |
|
|
|
|
|
|
|
onPressed: () async => const LoginRoute().push(context), |
|
|
|
|
|
|
|
icon: Icon(MdiIcons.accountPlus), |
|
|
|
|
|
|
|
label: Text(AppLocalizations.of(context).globalOptionsAccountsAdd), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
SettingsCategory( |
|
|
|
for (final account in accountsSnapshot.requireData) ...[ |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryOther), |
|
|
|
AccountSettingsTile( |
|
|
|
tiles: <SettingsTile>[ |
|
|
|
account: account, |
|
|
|
CustomSettingsTile( |
|
|
|
onTap: () { |
|
|
|
leading: Icon( |
|
|
|
AccountSettingsRoute(accountid: account.id).go(context); |
|
|
|
MdiIcons.scriptText, |
|
|
|
}, |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
title: Text(AppLocalizations.of(context).licenses), |
|
|
|
CustomSettingsTile( |
|
|
|
onTap: () async { |
|
|
|
title: ElevatedButton.icon( |
|
|
|
final branding = Branding.of(context); |
|
|
|
onPressed: () async => const LoginRoute().push(context), |
|
|
|
showLicensePage( |
|
|
|
icon: Icon(MdiIcons.accountPlus), |
|
|
|
context: context, |
|
|
|
label: Text(AppLocalizations.of(context).globalOptionsAccountsAdd), |
|
|
|
applicationName: branding.name, |
|
|
|
), |
|
|
|
applicationIcon: branding.logo, |
|
|
|
) |
|
|
|
applicationLegalese: branding.legalese, |
|
|
|
], |
|
|
|
applicationVersion: Provider.of<PackageInfo>(context, listen: false).version, |
|
|
|
), |
|
|
|
); |
|
|
|
SettingsCategory( |
|
|
|
}, |
|
|
|
title: Text(AppLocalizations.of(context).optionsCategoryOther), |
|
|
|
), |
|
|
|
key: ValueKey(SettingsCageories.other.name), |
|
|
|
CustomSettingsTile( |
|
|
|
tiles: <SettingsTile>[ |
|
|
|
leading: Icon( |
|
|
|
CustomSettingsTile( |
|
|
|
MdiIcons.export, |
|
|
|
leading: Icon( |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
MdiIcons.scriptText, |
|
|
|
), |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
title: Text(AppLocalizations.of(context).settingsExport), |
|
|
|
), |
|
|
|
onTap: () async { |
|
|
|
title: Text(AppLocalizations.of(context).licenses), |
|
|
|
try { |
|
|
|
onTap: () async { |
|
|
|
final fileName = |
|
|
|
final branding = Branding.of(context); |
|
|
|
'nextcloud-neon-settings-${DateTime.now().millisecondsSinceEpoch ~/ 1000}.json.base64'; |
|
|
|
showLicensePage( |
|
|
|
final data = base64.encode( |
|
|
|
context: context, |
|
|
|
utf8.encode( |
|
|
|
applicationName: branding.name, |
|
|
|
json.encode( |
|
|
|
applicationIcon: branding.logo, |
|
|
|
settingsExportHelper.toJsonExport(), |
|
|
|
applicationLegalese: branding.legalese, |
|
|
|
), |
|
|
|
applicationVersion: Provider.of<PackageInfo>(context, listen: false).version, |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
await saveFileWithPickDialog(fileName, Uint8List.fromList(utf8.encode(data))); |
|
|
|
), |
|
|
|
} catch (e, s) { |
|
|
|
CustomSettingsTile( |
|
|
|
debugPrint(e.toString()); |
|
|
|
leading: Icon( |
|
|
|
debugPrint(s.toString()); |
|
|
|
MdiIcons.export, |
|
|
|
NeonException.showSnackbar(context, e); |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
} |
|
|
|
), |
|
|
|
}, |
|
|
|
title: Text(AppLocalizations.of(context).settingsExport), |
|
|
|
), |
|
|
|
onTap: () async { |
|
|
|
CustomSettingsTile( |
|
|
|
final settingsExportHelper = _buildSettingsExportHelper(context); |
|
|
|
leading: Icon( |
|
|
|
|
|
|
|
MdiIcons.import, |
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).settingsImport), |
|
|
|
|
|
|
|
onTap: () async { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
final result = await FilePicker.platform.pickFiles( |
|
|
|
|
|
|
|
withData: true, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result == null) { |
|
|
|
try { |
|
|
|
return; |
|
|
|
final fileName = |
|
|
|
} |
|
|
|
'nextcloud-neon-settings-${DateTime.now().millisecondsSinceEpoch ~/ 1000}.json.base64'; |
|
|
|
|
|
|
|
final data = base64.encode( |
|
|
|
|
|
|
|
utf8.encode( |
|
|
|
|
|
|
|
json.encode( |
|
|
|
|
|
|
|
settingsExportHelper.toJsonExport(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await saveFileWithPickDialog(fileName, Uint8List.fromList(utf8.encode(data))); |
|
|
|
|
|
|
|
} catch (e, s) { |
|
|
|
|
|
|
|
debugPrint(e.toString()); |
|
|
|
|
|
|
|
debugPrint(s.toString()); |
|
|
|
|
|
|
|
NeonException.showSnackbar(context, e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
CustomSettingsTile( |
|
|
|
|
|
|
|
leading: Icon( |
|
|
|
|
|
|
|
MdiIcons.import, |
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
title: Text(AppLocalizations.of(context).settingsImport), |
|
|
|
|
|
|
|
onTap: () async { |
|
|
|
|
|
|
|
final settingsExportHelper = _buildSettingsExportHelper(context); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
final result = await FilePicker.platform.pickFiles( |
|
|
|
|
|
|
|
withData: true, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!result.files.single.path!.endsWith('.json.base64')) { |
|
|
|
if (result == null) { |
|
|
|
if (mounted) { |
|
|
|
return; |
|
|
|
NeonException.showSnackbar( |
|
|
|
} |
|
|
|
context, |
|
|
|
|
|
|
|
AppLocalizations.of(context).settingsImportWrongFileExtension, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final data = |
|
|
|
if (!result.files.single.path!.endsWith('.json.base64')) { |
|
|
|
json.decode(utf8.decode(base64.decode(utf8.decode(result.files.single.bytes!)))); |
|
|
|
if (mounted) { |
|
|
|
await settingsExportHelper.applyFromJson(data as Map<String, dynamic>); |
|
|
|
NeonException.showSnackbar( |
|
|
|
} catch (e, s) { |
|
|
|
context, |
|
|
|
debugPrint(e.toString()); |
|
|
|
AppLocalizations.of(context).settingsImportWrongFileExtension, |
|
|
|
debugPrint(s.toString()); |
|
|
|
); |
|
|
|
NeonException.showSnackbar(context, e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
return; |
|
|
|
), |
|
|
|
} |
|
|
|
], |
|
|
|
|
|
|
|
|
|
|
|
final data = json.decode(utf8.decode(base64.decode(utf8.decode(result.files.single.bytes!)))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await settingsExportHelper.applyFromJson(data as Map<String, dynamic>); |
|
|
|
|
|
|
|
} catch (e, s) { |
|
|
|
|
|
|
|
debugPrint(e.toString()); |
|
|
|
|
|
|
|
debugPrint(s.toString()); |
|
|
|
|
|
|
|
NeonException.showSnackbar(context, e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
); |
|
|
|
), |
|
|
|
}, |
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Scaffold( |
|
|
|
|
|
|
|
resizeToAvoidBottomInset: false, |
|
|
|
|
|
|
|
appBar: appBar, |
|
|
|
|
|
|
|
body: Center( |
|
|
|
|
|
|
|
child: ConstrainedBox( |
|
|
|
|
|
|
|
constraints: NeonDialogTheme.of(context).constraints, |
|
|
|
|
|
|
|
child: body, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SettingsExportHelper _buildSettingsExportHelper(final BuildContext context) { |
|
|
|
|
|
|
|
final globalOptions = Provider.of<GlobalOptions>(context); |
|
|
|
|
|
|
|
final accountsBloc = Provider.of<AccountsBloc>(context, listen: false); |
|
|
|
|
|
|
|
final appImplementations = Provider.of<Iterable<AppImplementation>>(context); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SettingsExportHelper( |
|
|
|
|
|
|
|
globalOptions: globalOptions, |
|
|
|
|
|
|
|
appImplementations: appImplementations, |
|
|
|
|
|
|
|
accountSpecificOptions: accountsBloc.accounts.value.asMap().map( |
|
|
|
|
|
|
|
(final _, final account) => MapEntry(account, accountsBloc.getOptionsFor(account).options), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum SettingsAccountAction { |
|
|
|
enum SettingsAccountAction { |
|
|
|