Implement settings
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SettingsRootPage extends StatefulWidget {
|
||||
const SettingsRootPage({super.key, required bool isVisiblePage});
|
||||
|
||||
@override
|
||||
State<SettingsRootPage> createState() => _SettingsRootPageState();
|
||||
}
|
||||
|
||||
class _SettingsRootPageState extends State<SettingsRootPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Text('(coming soon...)'), //TODO
|
||||
);
|
||||
}
|
||||
}
|
117
flutter/lib/pages/settings/settings_number_modal.dart
Normal file
117
flutter/lib/pages/settings/settings_number_modal.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class SettingsNumberModal extends StatefulWidget {
|
||||
final String title;
|
||||
final int currentValue;
|
||||
final int minValue;
|
||||
final int maxValue;
|
||||
final ValueChanged<int> onValueChanged;
|
||||
|
||||
const SettingsNumberModal({
|
||||
Key? key,
|
||||
required this.title,
|
||||
required this.currentValue,
|
||||
required this.minValue,
|
||||
required this.maxValue,
|
||||
required this.onValueChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SettingsNumberModal> createState() => _SettingsNumberModalState();
|
||||
|
||||
static Future<void> show(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
required int currentValue,
|
||||
required int minValue,
|
||||
required int maxValue,
|
||||
required ValueChanged<int> onValueChanged,
|
||||
}) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => SettingsNumberModal(
|
||||
title: title,
|
||||
currentValue: currentValue,
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
onValueChanged: onValueChanged,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsNumberModalState extends State<SettingsNumberModal> {
|
||||
late TextEditingController _controller;
|
||||
late int selectedValue;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
selectedValue = widget.currentValue;
|
||||
_controller = TextEditingController(text: widget.currentValue.toString());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(widget.title),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _controller,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Enter a number',
|
||||
errorText: _validateInput(),
|
||||
),
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedValue = int.tryParse(value) ?? widget.currentValue;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _validateInput() == null
|
||||
? () {
|
||||
widget.onValueChanged(selectedValue);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
: null,
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String? _validateInput() {
|
||||
final number = int.tryParse(_controller.text);
|
||||
if (number == null) {
|
||||
return 'Please enter a valid number';
|
||||
}
|
||||
if (number < widget.minValue) {
|
||||
return 'Value must be at least ${widget.minValue}';
|
||||
}
|
||||
if (number > widget.maxValue) {
|
||||
return 'Value must be at most ${widget.maxValue}';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
43
flutter/lib/pages/settings/settings_picker_screen.dart
Normal file
43
flutter/lib/pages/settings/settings_picker_screen.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
|
||||
class SettingsPickerScreen<T> extends StatelessWidget {
|
||||
const SettingsPickerScreen({
|
||||
Key? key,
|
||||
required this.title,
|
||||
required this.initialValue,
|
||||
required this.values,
|
||||
required this.onValueChanged,
|
||||
this.icons,
|
||||
}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
final T initialValue;
|
||||
final List<T> values;
|
||||
final void Function(T value) onValueChanged;
|
||||
final Widget Function(T v)? icons;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SettingsList(
|
||||
platform: PlatformUtils.detectPlatform(context),
|
||||
sections: [
|
||||
SettingsSection(
|
||||
tiles: values.map((e) {
|
||||
return SettingsTile(
|
||||
leading: icons != null ? icons!(e) : null,
|
||||
title: Text(e.toString()),
|
||||
onPressed: (_) {
|
||||
onValueChanged(e);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
245
flutter/lib/pages/settings/settings_view.dart
Normal file
245
flutter/lib/pages/settings/settings_view.dart
Normal file
@@ -0,0 +1,245 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:settings_ui/settings_ui.dart';
|
||||
import 'package:simplecloudnotifier/git_stamp/git_stamp.dart';
|
||||
import 'package:simplecloudnotifier/pages/settings/settings_number_modal.dart';
|
||||
import 'package:simplecloudnotifier/pages/settings/settings_picker_screen.dart';
|
||||
import 'package:simplecloudnotifier/state/app_settings.dart';
|
||||
import 'package:simplecloudnotifier/state/app_auth.dart';
|
||||
import 'package:simplecloudnotifier/state/app_theme.dart';
|
||||
import 'package:simplecloudnotifier/state/globals.dart';
|
||||
import 'package:simplecloudnotifier/utils/navi.dart';
|
||||
import 'package:simplecloudnotifier/utils/toaster.dart';
|
||||
|
||||
class SettingsRootPage extends StatefulWidget {
|
||||
const SettingsRootPage({super.key, required bool isVisiblePage});
|
||||
|
||||
@override
|
||||
State<SettingsRootPage> createState() => _SettingsRootPageState();
|
||||
}
|
||||
|
||||
class _SettingsRootPageState extends State<SettingsRootPage> {
|
||||
int _multiClickCounter = 0;
|
||||
DateTime? _lastClickTime = null;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cfg = Provider.of<AppSettings>(context);
|
||||
final thm = Provider.of<AppTheme>(context);
|
||||
|
||||
return SettingsList(
|
||||
platform: PlatformUtils.detectPlatform(context),
|
||||
contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 24),
|
||||
sections: [
|
||||
SettingsSection(
|
||||
title: Text('General'),
|
||||
tiles: [
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(thm.darkMode ? FontAwesomeIcons.solidMoon : FontAwesomeIcons.solidSun),
|
||||
title: Text('Theme'),
|
||||
value: Text(thm.darkMode ? 'Dark' : 'Light'),
|
||||
onPressed: (_) => thm.switchDarkMode(),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidSquare, color: thm.color.value),
|
||||
title: Text('Color'),
|
||||
value: Text(thm.color.displayStr),
|
||||
onPressed: (_) => Navi.push(
|
||||
context,
|
||||
() => SettingsPickerScreen(
|
||||
title: 'Color',
|
||||
initialValue: thm.color,
|
||||
values: ThemeColor.values,
|
||||
icons: (v) => Icon(FontAwesomeIcons.solidSquare, color: v.value),
|
||||
onValueChanged: (value) => AppTheme().setColor(value),
|
||||
),
|
||||
),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidLineColumns),
|
||||
title: Text('Message Preview Lines'),
|
||||
value: Text("${cfg.messagePreviewLength}"),
|
||||
onPressed: (_) {
|
||||
SettingsNumberModal.show(
|
||||
context,
|
||||
title: 'Message Preview Lines',
|
||||
currentValue: cfg.messagePreviewLength,
|
||||
minValue: 1,
|
||||
maxValue: 32,
|
||||
onValueChanged: (value) => AppSettings().update((p) => p.messagePreviewLength = value),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (Platform.isAndroid)
|
||||
SettingsTile.switchTile(
|
||||
initialValue: cfg.groupNotifications,
|
||||
leading: Icon(FontAwesomeIcons.solidLayerGroup),
|
||||
title: Text('Group notifications together'),
|
||||
onToggle: (value) => AppSettings().update((p) => p.groupNotifications = !p.groupNotifications),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidCalendarDays),
|
||||
title: Text('Date Format'),
|
||||
value: Text(cfg.dateFormat.displayStr),
|
||||
onPressed: (_) => Navi.push(
|
||||
context,
|
||||
() => SettingsPickerScreen(
|
||||
title: 'Date Format',
|
||||
initialValue: cfg.dateFormat,
|
||||
values: AppSettingsDateFormat.values,
|
||||
onValueChanged: (value) => AppSettings().update((p) => p.dateFormat = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsSection(
|
||||
title: Text('Priority 0 (Low)'),
|
||||
tiles: _buildNotificationTiles(context, cfg, 0),
|
||||
),
|
||||
SettingsSection(
|
||||
title: Text('Priority 1 (Normal)'),
|
||||
tiles: _buildNotificationTiles(context, cfg, 1),
|
||||
),
|
||||
SettingsSection(
|
||||
title: Text('Priority 2 (High)'),
|
||||
tiles: _buildNotificationTiles(context, cfg, 2),
|
||||
),
|
||||
SettingsSection(
|
||||
title: Text('Advanced Settings'),
|
||||
tiles: [
|
||||
if (cfg.devMode)
|
||||
SettingsTile.switchTile(
|
||||
initialValue: cfg.showDebugButton,
|
||||
leading: Icon(FontAwesomeIcons.solidSpiderBlackWidow),
|
||||
title: Text('Debug Button anzeigen'),
|
||||
onToggle: (value) => AppSettings().update((p) => p.showDebugButton = !p.showDebugButton),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidList),
|
||||
title: Text('Page Size (Messages)'),
|
||||
value: Text("${cfg.messagePageSize}"),
|
||||
onPressed: (_) {
|
||||
SettingsNumberModal.show(
|
||||
context,
|
||||
title: 'Page Size (Messages)',
|
||||
currentValue: cfg.messagePageSize,
|
||||
minValue: 1,
|
||||
maxValue: 2048,
|
||||
onValueChanged: (value) => AppSettings().update((p) => p.messagePageSize = value),
|
||||
);
|
||||
},
|
||||
),
|
||||
SettingsTile.switchTile(
|
||||
initialValue: cfg.backgroundRefreshMessageListOnPop,
|
||||
leading: Icon(FontAwesomeIcons.solidPageCaretDown),
|
||||
title: Text('Refresh messages on page navigation'),
|
||||
onToggle: (value) => AppSettings().update((p) => p.backgroundRefreshMessageListOnPop = !p.backgroundRefreshMessageListOnPop),
|
||||
),
|
||||
SettingsTile.switchTile(
|
||||
initialValue: cfg.alwaysBackgroundRefreshMessageListOnLifecycleResume,
|
||||
leading: Icon(FontAwesomeIcons.solidRecycle),
|
||||
title: Text('Refresh messages on app resume'),
|
||||
onToggle: (value) => AppSettings().update((p) => p.alwaysBackgroundRefreshMessageListOnLifecycleResume = !p.alwaysBackgroundRefreshMessageListOnLifecycleResume),
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsSection(
|
||||
title: Text('About'),
|
||||
tiles: [
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidCodeCommit),
|
||||
title: Text('Version'),
|
||||
value: Text(Globals().version),
|
||||
onPressed: (cfg.devMode)
|
||||
? null
|
||||
: (context) {
|
||||
if (_lastClickTime == null || DateTime.now().difference(_lastClickTime!).inSeconds > 1) _multiClickCounter = 0;
|
||||
_multiClickCounter++;
|
||||
_lastClickTime = DateTime.now();
|
||||
|
||||
if (_multiClickCounter >= 12) {
|
||||
Toaster.info("Debug", "Developer mode enabled");
|
||||
AppSettings().update((p) {
|
||||
p.devMode = true;
|
||||
p.showDebugButton = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidCodeBranch),
|
||||
title: Text('Build'),
|
||||
value: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(GitStamp.sha.substring(0, 7) + ' +' + Globals().buildNumber),
|
||||
Text("( " + cfg.dateFormat.dateFormat().format(DateTime.parse(GitStamp.buildDateTime).toLocal()) + " )", style: TextStyle(fontStyle: FontStyle.italic)),
|
||||
],
|
||||
),
|
||||
onPressed: (context) => _clipboardCopy(GitStamp.sha),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidBell),
|
||||
title: Text('FCM Token'),
|
||||
value: Text(AppAuth().getToken()),
|
||||
onPressed: (context) => _clipboardCopy(AppAuth().getToken()),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _clipboardCopy(String v) {
|
||||
Clipboard.setData(new ClipboardData(text: v));
|
||||
Toaster.info("Clipboard", 'Copied to Clipboard');
|
||||
print('================= [CLIPBOARD] =================\n${v}\n================= [/CLIPBOARD] =================');
|
||||
}
|
||||
|
||||
List<AbstractSettingsTile> _buildNotificationTiles(BuildContext context, AppSettings cfg, int prio) {
|
||||
final ncf = AppSettings().getNotificationSettings(prio);
|
||||
return [
|
||||
SettingsTile.switchTile(
|
||||
initialValue: ncf.enableLights,
|
||||
leading: Icon(FontAwesomeIcons.solidLightbulb),
|
||||
title: Text('Enable Lights'),
|
||||
onToggle: (value) => AppSettings().updateNotification(prio, (p) => p.withEnableLights(!p.enableLights)),
|
||||
),
|
||||
SettingsTile.switchTile(
|
||||
initialValue: ncf.enableVibration,
|
||||
leading: Icon(FontAwesomeIcons.solidShutters),
|
||||
title: Text('Enable Vibration'),
|
||||
onToggle: (value) => AppSettings().updateNotification(prio, (p) => p.withEnableVibration(!p.enableVibration)),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidWaveform),
|
||||
title: Text('Notification Sound'),
|
||||
value: Text(ncf.sound ?? '(Default)'),
|
||||
onPressed: (context) => {/*TODO*/},
|
||||
),
|
||||
SettingsTile.switchTile(
|
||||
initialValue: ncf.playSound,
|
||||
leading: Icon(FontAwesomeIcons.solidVolume),
|
||||
title: Text('Play Sound'),
|
||||
onToggle: (value) => AppSettings().updateNotification(prio, (p) => p.withPlaySound(!p.playSound)),
|
||||
),
|
||||
SettingsTile.switchTile(
|
||||
initialValue: ncf.silent,
|
||||
leading: Icon(FontAwesomeIcons.solidVolumeSlash),
|
||||
title: Text('Silent'),
|
||||
onToggle: (value) => AppSettings().updateNotification(prio, (p) => p.withSilent(!p.silent)),
|
||||
),
|
||||
SettingsTile.navigation(
|
||||
leading: Icon(FontAwesomeIcons.solidStopwatch20),
|
||||
title: Text('Auto Timeout'),
|
||||
value: Text((ncf.timeoutAfter != null) ? "${ncf.timeoutAfter} sec" : "(None)"),
|
||||
onPressed: (context) => {/*TODO*/},
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user