diff --git a/firka/lib/helpers/settings/setting.dart b/firka/lib/helpers/settings/setting.dart index 770919c..0bfd468 100644 --- a/firka/lib/helpers/settings/setting.dart +++ b/firka/lib/helpers/settings/setting.dart @@ -34,15 +34,15 @@ class SettingsStore { "settings_padding": SettingsPadding(0, 23), "bell_delay": SettingsDouble( - bellRing, null, null, "Csengő eltolódása", 0), + bellRing, null, null, "Csengő eltolódása", 0, 0, 120, 0), "rounding_1": SettingsDouble(rounding1, null, null, - "Alapértelmezett kerekítés 1 -> 2", 0.5), + "Alapértelmezett kerekítés 1 -> 2", 0.1, 0.5, 0.99, 2), "rounding_2": SettingsDouble(rounding2, null, null, - "Alapértelmezett kerekítés 2 -> 3", 0.5), + "Alapértelmezett kerekítés 2 -> 3", 0.1, 0.5, 0.99, 2), "rounding_3": SettingsDouble(rounding3, null, null, - "Alapértelmezett kerekítés 3 -> 4", 0.5), + "Alapértelmezett kerekítés 3 -> 4", 0.1, 0.5, 0.99, 2), "rounding_4": SettingsDouble(rounding4, null, null, - "Alapértelmezett kerekítés 4 -> 5", 0.5), + "Alapértelmezett kerekítés 4 -> 5", 0.1, 0.5, 0.99, 2), "class_avg_on_graph": SettingsBoolean(classAvgOnGraph, null, null, "Osztályátlag a grafikonon", true), "navbar": SettingsSubGroup( @@ -341,10 +341,25 @@ class SettingsDouble implements SettingsItem { Object? iconData; String title; double value = 0; + double minValue = 0.0; double defaultValue; + double maxValue = 0.0; + int precision; - SettingsDouble( - this.key, this.iconType, this.iconData, this.title, this.defaultValue); + SettingsDouble(this.key, this.iconType, this.iconData, this.title, + this.minValue, this.defaultValue, this.maxValue, this.precision); + + double toRoundedDouble() { + return double.parse(toRoundedString()); + } + + String toRoundedString() { + return precision == 0 + ? value.toString().split(".")[0] + : value.toStringAsPrecision(precision) == "0.0" + ? "0" + : value.toStringAsPrecision(precision); + } @override Future load(IsarCollection model) async { diff --git a/firka/lib/ui/phone/screens/settings/settings_screen.dart b/firka/lib/ui/phone/screens/settings/settings_screen.dart index e649246..ae6e9f0 100644 --- a/firka/lib/ui/phone/screens/settings/settings_screen.dart +++ b/firka/lib/ui/phone/screens/settings/settings_screen.dart @@ -97,17 +97,22 @@ class _SettingsScreenState extends State { } if (item is SettingsDouble) { - var v = item.value.toStringAsPrecision(2); + var v = item.toRoundedString(); - widgets.add(FirkaCard(left: [ - Text(item.title, - style: appStyle.fonts.B_16SB - .apply(color: appStyle.colors.textPrimary)) - ], right: [ - Text(v == "0.0" ? "0" : v, - style: appStyle.fonts.B_14R - .apply(color: appStyle.colors.textPrimary)) - ])); + widgets.add(GestureDetector( + child: FirkaCard(left: [ + Text(item.title, + style: appStyle.fonts.B_16SB + .apply(color: appStyle.colors.textPrimary)) + ], right: [ + Text(v == "0.0" ? "0" : v, + style: appStyle.fonts.B_14R + .apply(color: appStyle.colors.textPrimary)) + ]), + onTap: () async { + showSetDoubleSheet(context, item, widget.data, setState); + }, + )); } if (item is SettingsBoolean) { widgets.add(FirkaCard( @@ -225,3 +230,91 @@ class _SettingsScreenState extends State { ); } } + +void showSetDoubleSheet(BuildContext context, SettingsDouble setting, + AppInitialization data, void Function(VoidCallback fn) setStateOuter) { + showModalBottomSheet( + context: context, + elevation: 100, + isScrollControlled: true, + enableDrag: true, + backgroundColor: Colors.transparent, + barrierColor: appStyle.colors.a15p, + constraints: BoxConstraints( + maxHeight: MediaQuery.of(context).size.height * 0.13, + ), + builder: (BuildContext context) { + return StatefulBuilder( + builder: (BuildContext context, setState) => Stack( + children: [ + Positioned.fill( + child: GestureDetector( + onTap: () => Navigator.pop(context), + behavior: HitTestBehavior.opaque, + child: Container(color: Colors.transparent), + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: Container( + decoration: BoxDecoration( + color: appStyle.colors.card, + borderRadius: + BorderRadius.vertical(top: Radius.circular(16)), + ), + child: Padding( + padding: const EdgeInsets.only( + left: 18.0, right: 16.0, bottom: 30.0, top: 20.0), + child: Column( + children: [ + Center( + child: Text( + setting.title, + style: appStyle.fonts.B_14R, + )), + Padding( + padding: const EdgeInsets.symmetric( + vertical: 0, horizontal: 40), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + Expanded( + // TODO: Make a firka slider + child: Slider( + min: setting.minValue, + value: setting.value, + max: setting.maxValue, + thumbColor: appStyle.colors.accent, + activeColor: appStyle.colors.secondary, + inactiveColor: appStyle.colors.a15p, + onChanged: (v) async { + setState(() { + setting.value = v; + setting.value = + setting.toRoundedDouble(); + }); + + await data.isar.writeTxn(() async { + await setting.save( + data.isar.appSettingsModels); + + setStateOuter(() {}); + }); + }), + ), + Text(setting.toRoundedString(), + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textPrimary)) + ], + ), + ), + ], + ), + ), + ), + ), + ], + )); + }, + ); +}