mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 06:19:22 +00:00
145 lines
4.1 KiB
Dart
145 lines
4.1 KiB
Dart
import 'package:comunic/helpers/preferences_helper.dart';
|
|
import 'package:comunic/helpers/server_config_helper.dart';
|
|
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
|
import 'package:comunic/ui/widgets/settings/header_spacer_section.dart';
|
|
import 'package:comunic/utils/flutter_utils.dart';
|
|
import 'package:comunic/utils/intl_utils.dart';
|
|
import 'package:comunic/utils/ui_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:settings_ui/settings_ui.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
/// Application settings
|
|
///
|
|
/// @author Pierre Hubert
|
|
|
|
class ApplicationSettings extends StatefulWidget {
|
|
@override
|
|
_ApplicationSettingsState createState() => _ApplicationSettingsState();
|
|
}
|
|
|
|
class _ApplicationSettingsState extends State<ApplicationSettings> {
|
|
PreferencesHelper _preferencesHelper;
|
|
|
|
Future<void> _refresh() async {
|
|
_preferencesHelper = await PreferencesHelper.getInstance();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => AsyncScreenWidget(
|
|
onReload: _refresh,
|
|
onBuild: _buildSections,
|
|
errorMessage: tr("Could not load settings!"));
|
|
|
|
Widget _buildSections() {
|
|
return SettingsList(
|
|
sections: [
|
|
HeadSpacerSection(),
|
|
_buildAppearanceSection(),
|
|
_buildGeneralSection(),
|
|
_buildDebugSection()
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Appearance section
|
|
SettingsSection _buildAppearanceSection() => SettingsSection(
|
|
title: tr("Appearance"),
|
|
tiles: [
|
|
_PreferencesSettingsTile(
|
|
preferencesKey: PreferencesKeyList.ENABLE_DARK_THEME,
|
|
title: tr("Enable dark theme"),
|
|
subtitle: null,
|
|
onChange: _updatedSettings,
|
|
helper: _preferencesHelper,
|
|
),
|
|
],
|
|
);
|
|
|
|
/// General section
|
|
SettingsSection _buildGeneralSection() => SettingsSection(
|
|
title: tr("General"),
|
|
tiles: [
|
|
SettingsTile(
|
|
title: tr("Privacy policy"),
|
|
onPressed: (c) => launch(srvConfig.privacyPolicyURL),
|
|
),
|
|
SettingsTile(
|
|
title: tr("Terms of Use"),
|
|
onPressed: (c) => launch(srvConfig.termsURL),
|
|
),
|
|
SettingsTile(
|
|
title: tr("About this application"),
|
|
subtitle: isIOS ? null : tr("Learn more about us"),
|
|
onPressed: (_) => showAboutAppDialog(context),
|
|
)
|
|
],
|
|
);
|
|
|
|
/// Debug section
|
|
SettingsSection _buildDebugSection() => SettingsSection(
|
|
title: tr("Debug features"),
|
|
tiles: [
|
|
// Force mobile mode
|
|
_PreferencesSettingsTile(
|
|
preferencesKey: PreferencesKeyList.FORCE_MOBILE_MODE,
|
|
title: tr("Force mobile mode"),
|
|
subtitle: isIOS
|
|
? null
|
|
: tr(
|
|
"Force the smartphone mode of the application to be used, even when tablet mode could be used."),
|
|
onChange: _updatedSettings,
|
|
helper: _preferencesHelper,
|
|
),
|
|
|
|
// Show performances overlay
|
|
_PreferencesSettingsTile(
|
|
preferencesKey: PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY,
|
|
title: tr("Show performances overlay"),
|
|
subtitle: null,
|
|
onChange: _updatedSettings,
|
|
helper: _preferencesHelper,
|
|
),
|
|
],
|
|
);
|
|
|
|
/// Apply new settings
|
|
_updatedSettings() {
|
|
setState(() {});
|
|
applyNewThemeSettings(context);
|
|
}
|
|
}
|
|
|
|
class _PreferencesSettingsTile extends SettingsTile {
|
|
final PreferencesKeyList preferencesKey;
|
|
final String title;
|
|
final String subtitle;
|
|
final Function onChange;
|
|
final PreferencesHelper helper;
|
|
|
|
const _PreferencesSettingsTile({
|
|
@required this.preferencesKey,
|
|
@required this.title,
|
|
@required this.subtitle,
|
|
@required this.onChange,
|
|
@required this.helper,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SettingsTile.switchTile(
|
|
title: title,
|
|
subtitle: subtitle,
|
|
onToggle: _doChange,
|
|
switchValue: helper.getBool(preferencesKey),
|
|
titleMaxLines: 2,
|
|
subtitleMaxLines: 4,
|
|
);
|
|
}
|
|
|
|
void _doChange(bool value) async {
|
|
await helper.setBool(preferencesKey, value);
|
|
onChange();
|
|
}
|
|
}
|