From ec55ccde3e0560b5679b6c360e8555a478bb39e1 Mon Sep 17 00:00:00 2001 From: JHubi1 Date: Sat, 8 Jun 2024 18:13:31 +0200 Subject: [PATCH] Resorted settings, toggle's text can change value --- lib/l10n/app_de.arb | 101 +++++++++++++----------- lib/l10n/app_en.arb | 90 ++++++++++----------- lib/screen_settings.dart | 89 ++++++++++++--------- lib/settings/about.dart | 25 +++--- lib/settings/export.dart | 2 +- lib/settings/interface.dart | 151 ++++++++++++++++++------------------ 6 files changed, 244 insertions(+), 214 deletions(-) diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index f841947..08a229d 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -222,6 +222,46 @@ "description": "Text displayed when behavior settings are not updated for older chats", "context": "Visible in the settings view" }, + "settingsShowModelTags": "Model-Tags anzeigen", + "@settingsShowModelTags": { + "description": "Text displayed as description for show model tags toggle", + "context": "Visible in the settings view" + }, + "settingsResetOnModelChange": "Zurücksetzen bei Modelländerung", + "@settingsResetOnModelChange": { + "description": "Text displayed as description for reset on model change toggle", + "context": "Visible in the settings view" + }, + "settingsGenerateTitles": "Titel generieren", + "@settingsGenerateTitles": { + "description": "Text displayed as description for generate titles toggle", + "context": "Visible in the settings view" + }, + "settingsEnableEditing": "Nachrichtenbearbeitung aktivieren", + "@settingsEnableEditing": { + "description": "Text displayed as description for enable editing toggle", + "context": "Visible in the settings view" + }, + "settingsAskBeforeDelete": "Vor Löschung des Chats fragen", + "@settingsAskBeforeDelete": { + "description": "Text displayed as description for ask before deletion toggle", + "context": "Visible in the settings view" + }, + "settingsShowTips": "Tipps in der Seitenleiste anzeigen", + "@settingsShowTips": { + "description": "Text displayed as description for show tips toggle", + "context": "Visible in the settings view" + }, + "settingsRequestTypeStream": "Stream", + "@settingsRequestTypeStream": { + "description": "Text displayed as description for stream request type. Do not translate if not required!", + "context": "Visible in the settings view" + }, + "settingsRequestTypeRequest": "Request", + "@settingsRequestTypeRequest": { + "description": "Text displayed as description for request request type. Do not translate if not required!", + "context": "Visible in the settings view" + }, "settingsBrightnessSystem": "System", "@settingsBrightnessSystem": { "description": "Text displayed as description for system brightness option", @@ -257,46 +297,6 @@ "description": "Text displayed for cancel button, should be capitalized", "context": "Visible in the settings view" }, - "settingsGenerateTitles": "Titel generieren", - "@settingsGenerateTitles": { - "description": "Text displayed as description for generate titles toggle", - "context": "Visible in the settings view" - }, - "settingsAskBeforeDelete": "Vor Löschung des Chats fragen", - "@settingsAskBeforeDelete": { - "description": "Text displayed as description for ask before deletion toggle", - "context": "Visible in the settings view" - }, - "settingsResetOnModelChange": "Zurücksetzen bei Modelländerung", - "@settingsResetOnModelChange": { - "description": "Text displayed as description for reset on model change toggle", - "context": "Visible in the settings view" - }, - "settingsEnableEditing": "Nachrichtenbearbeitung aktivieren", - "@settingsEnableEditing": { - "description": "Text displayed as description for enable editing toggle", - "context": "Visible in the settings view" - }, - "settingsShowTips": "Tipps in der Seitenleiste anzeigen", - "@settingsShowTips": { - "description": "Text displayed as description for show tips toggle", - "context": "Visible in the settings view" - }, - "settingsShowModelTags": "Model-Tags anzeigen", - "@settingsShowModelTags": { - "description": "Text displayed as description for show model tags toggle", - "context": "Visible in the settings view" - }, - "settingsRequestTypeStream": "Stream", - "@settingsRequestTypeStream": { - "description": "Text displayed as description for stream request type. Do not translate if not required!", - "context": "Visible in the settings view" - }, - "settingsRequestTypeRequest": "Request", - "@settingsRequestTypeRequest": { - "description": "Text displayed as description for request request type. Do not translate if not required!", - "context": "Visible in the settings view" - }, "settingsExportChats": "Chats exportieren", "@settingsExportChats": { "description": "Text displayed as description for export chats button", @@ -342,6 +342,11 @@ "description": "Warning displayed for export and import options", "context": "Visible in the settings view" }, + "settingsCheckForUpdates": "Beim Öffnen nach Updates suchen", + "@settingsCheckForUpdates": { + "description": "Text displayed as description for check for updates toggle", + "context": "Visible in the settings view" + }, "settingsUpdateCheck": "Nach Updates suchen", "@settingsUpdateCheck": { "description": "Text displayed as description for check for updates button", @@ -403,11 +408,6 @@ "description": "Text displayed for cancel button, should be capitalized", "context": "Visible in the settings view" }, - "settingsCheckForUpdates": "Nach Updates suchen", - "@settingsCheckForUpdates": { - "description": "Text displayed as description for check for updates toggle", - "context": "Visible in the settings view" - }, "settingsGithub": "GitHub", "@settingsGithub": { "description": "Text displayed as description for GitHub button", @@ -422,5 +422,16 @@ "@settingsMainDeveloper": { "description": "Text displayed as description for main developer button", "context": "Visible in the settings view" + }, + "settingsVersion": "Ollama App v{version}", + "@settingsVersion": { + "description": "Text displayed as description for version", + "context": "Visible in the settings view", + "placeholders": { + "version": { + "type": "String", + "description": "Version number of the app" + } + } } } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4ead0dc..5977de3 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -222,6 +222,46 @@ "description": "Text displayed when behavior settings are not updated for older chats", "context": "Visible in the settings view" }, + "settingsShowModelTags": "Show model tags", + "@settingsShowModelTags": { + "description": "Text displayed as description for show model tags toggle", + "context": "Visible in the settings view" + }, + "settingsResetOnModelChange": "Reset on model change", + "@settingsResetOnModelChange": { + "description": "Text displayed as description for reset on model change toggle", + "context": "Visible in the settings view" + }, + "settingsGenerateTitles": "Generate titles", + "@settingsGenerateTitles": { + "description": "Text displayed as description for generate titles toggle", + "context": "Visible in the settings view" + }, + "settingsEnableEditing": "Enable editing of messages", + "@settingsEnableEditing": { + "description": "Text displayed as description for enable editing toggle", + "context": "Visible in the settings view" + }, + "settingsAskBeforeDelete": "Ask before chat deletion", + "@settingsAskBeforeDelete": { + "description": "Text displayed as description for ask before deletion toggle", + "context": "Visible in the settings view" + }, + "settingsShowTips": "Show tips in sidebar", + "@settingsShowTips": { + "description": "Text displayed as description for show tips toggle", + "context": "Visible in the settings view" + }, + "settingsRequestTypeStream": "Stream", + "@settingsRequestTypeStream": { + "description": "Text displayed as description for stream request type. Do not translate if not required!", + "context": "Visible in the settings view" + }, + "settingsRequestTypeRequest": "Request", + "@settingsRequestTypeRequest": { + "description": "Text displayed as description for request request type. Do not translate if not required!", + "context": "Visible in the settings view" + }, "settingsBrightnessSystem": "System", "@settingsBrightnessSystem": { "description": "Text displayed as description for system brightness option", @@ -257,46 +297,6 @@ "description": "Text displayed for cancel button, should be capitalized", "context": "Visible in the settings view" }, - "settingsGenerateTitles": "Generate titles", - "@settingsGenerateTitles": { - "description": "Text displayed as description for generate titles toggle", - "context": "Visible in the settings view" - }, - "settingsAskBeforeDelete": "Ask before chat deletion", - "@settingsAskBeforeDelete": { - "description": "Text displayed as description for ask before deletion toggle", - "context": "Visible in the settings view" - }, - "settingsResetOnModelChange": "Reset on model change", - "@settingsResetOnModelChange": { - "description": "Text displayed as description for reset on model change toggle", - "context": "Visible in the settings view" - }, - "settingsEnableEditing": "Enable editing of messages", - "@settingsEnableEditing": { - "description": "Text displayed as description for enable editing toggle", - "context": "Visible in the settings view" - }, - "settingsShowTips": "Show tips in sidebar", - "@settingsShowTips": { - "description": "Text displayed as description for show tips toggle", - "context": "Visible in the settings view" - }, - "settingsShowModelTags": "Show model tags", - "@settingsShowModelTags": { - "description": "Text displayed as description for show model tags toggle", - "context": "Visible in the settings view" - }, - "settingsRequestTypeStream": "Stream", - "@settingsRequestTypeStream": { - "description": "Text displayed as description for stream request type. Do not translate if not required!", - "context": "Visible in the settings view" - }, - "settingsRequestTypeRequest": "Request", - "@settingsRequestTypeRequest": { - "description": "Text displayed as description for request request type. Do not translate if not required!", - "context": "Visible in the settings view" - }, "settingsExportChats": "Export chats", "@settingsExportChats": { "description": "Text displayed as description for export chats button", @@ -342,6 +342,11 @@ "description": "Warning displayed for export and import options", "context": "Visible in the settings view" }, + "settingsCheckForUpdates": "Check for updates on open", + "@settingsCheckForUpdates": { + "description": "Text displayed as description for check for updates toggle", + "context": "Visible in the settings view" + }, "settingsUpdateCheck": "Check for updates", "@settingsUpdateCheck": { "description": "Text displayed as description for check for updates button", @@ -403,11 +408,6 @@ "description": "Text displayed for cancel button, should be capitalized", "context": "Visible in the settings view" }, - "settingsCheckForUpdates": "Check for updates", - "@settingsCheckForUpdates": { - "description": "Text displayed as description for check for updates toggle", - "context": "Visible in the settings view" - }, "settingsGithub": "GitHub", "@settingsGithub": { "description": "Text displayed as description for GitHub button", diff --git a/lib/screen_settings.dart b/lib/screen_settings.dart index 7bb8e10..efa6f84 100644 --- a/lib/screen_settings.dart +++ b/lib/screen_settings.dart @@ -21,36 +21,45 @@ Widget toggle(BuildContext context, String text, bool value, Function(bool value) onChanged) { var space = "⁣"; // Invisible character: U+2063 var spacePlus = " $space"; - return Padding( - padding: const EdgeInsets.only(top: 4, bottom: 4), - child: Stack(children: [ - Padding( - padding: const EdgeInsets.only(left: 16, right: 16, top: 12), - child: Divider( + return InkWell( + splashFactory: NoSplash.splashFactory, + highlightColor: Colors.transparent, + hoverColor: Colors.transparent, + onTap: () { + onChanged(!value); + }, + child: Padding( + padding: const EdgeInsets.only(top: 8, bottom: 8), + child: Stack(children: [ + Padding( + padding: const EdgeInsets.only(left: 16, right: 16, top: 12), + child: Divider( + color: (Theme.of(context).brightness == Brightness.light) + ? Colors.grey[300] + : Colors.grey[900])), + Row(mainAxisSize: MainAxisSize.max, children: [ + Expanded( + child: Text(text + spacePlus, + overflow: TextOverflow.ellipsis, + maxLines: 1, + style: TextStyle( + backgroundColor: + (Theme.of(context).brightness == Brightness.light) + ? (theme ?? ThemeData()).colorScheme.surface + : (themeDark ?? ThemeData.dark()) + .colorScheme + .surface))), + Container( + padding: const EdgeInsets.only(left: 16), color: (Theme.of(context).brightness == Brightness.light) - ? Colors.grey[300] - : Colors.grey[900])), - Row(mainAxisSize: MainAxisSize.max, children: [ - Expanded( - child: Text(text + spacePlus, - overflow: TextOverflow.ellipsis, - maxLines: 1, - style: TextStyle( - backgroundColor: - (Theme.of(context).brightness == Brightness.light) - ? (theme ?? ThemeData()).colorScheme.surface - : (themeDark ?? ThemeData.dark()) - .colorScheme - .surface))), - Container( - padding: const EdgeInsets.only(left: 16), - color: (Theme.of(context).brightness == Brightness.light) - ? (theme ?? ThemeData()).colorScheme.surface - : (themeDark ?? ThemeData.dark()).colorScheme.surface, - child: SizedBox( - height: 40, child: Switch(value: value, onChanged: onChanged))) + ? (theme ?? ThemeData()).colorScheme.surface + : (themeDark ?? ThemeData.dark()).colorScheme.surface, + child: SizedBox( + height: 40, + child: Switch(value: value, onChanged: onChanged))) + ]), ]), - ]), + ), ); } @@ -66,6 +75,17 @@ Widget title(String text, {double top = 16, double bottom = 16}) { ])); } +Widget titleDivider({double top = 16, double bottom = 16}) { + return Padding( + padding: EdgeInsets.only(left: 8, right: 8, top: top, bottom: bottom), + child: const Row( + mainAxisSize: MainAxisSize.max, + children: [ + Expanded(child: Divider()), + ], + )); +} + Widget button(String text, IconData icon, void Function()? onPressed, {Color? color}) { return InkWell( @@ -346,15 +366,12 @@ class _ScreenSettingsState extends State { "monospace")) ], )))), - const Padding( - padding: EdgeInsets.only( - left: 8, right: 8, top: 16, bottom: 4), - child: Divider()), + titleDivider(bottom: 4), button( AppLocalizations.of(context)! .settingsTitleBehavior, Icons.psychology_rounded, () { - HapticFeedback.selectionClick(); + HapticFeedback.selectionClick(); Navigator.push( context, MaterialPageRoute( @@ -365,7 +382,7 @@ class _ScreenSettingsState extends State { AppLocalizations.of(context)! .settingsTitleInterface, Icons.web_asset_rounded, () { - HapticFeedback.selectionClick(); + HapticFeedback.selectionClick(); Navigator.push( context, MaterialPageRoute( @@ -375,7 +392,7 @@ class _ScreenSettingsState extends State { button( AppLocalizations.of(context)!.settingsTitleExport, Icons.share_rounded, () { - HapticFeedback.selectionClick(); + HapticFeedback.selectionClick(); Navigator.push( context, MaterialPageRoute( @@ -385,7 +402,7 @@ class _ScreenSettingsState extends State { button( AppLocalizations.of(context)!.settingsTitleAbout, Icons.help_rounded, () { - HapticFeedback.selectionClick(); + HapticFeedback.selectionClick(); Navigator.push( context, MaterialPageRoute( diff --git a/lib/settings/about.dart b/lib/settings/about.dart index 78ec58c..8ac9ece 100644 --- a/lib/settings/about.dart +++ b/lib/settings/about.dart @@ -89,6 +89,18 @@ class _ScreenSettingsAboutState extends State { .settingsVersion(currentVersion ?? "0.0.1"), Icons.verified_rounded, null), + (updateStatus == "notAvailable") + ? const SizedBox.shrink() + : toggle( + context, + AppLocalizations.of(context)! + .settingsCheckForUpdates, + (prefs!.getBool("checkUpdateOnSettingsOpen") ?? + false), (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("checkUpdateOnSettingsOpen", value); + setState(() {}); + }), (updateStatus == "notAvailable") ? const SizedBox.shrink() : button( @@ -132,18 +144,7 @@ class _ScreenSettingsAboutState extends State { return; } }), - (updateStatus == "notAvailable") - ? const SizedBox.shrink() - : toggle( - context, - AppLocalizations.of(context)! - .settingsCheckForUpdates, - (prefs!.getBool("checkUpdateOnSettingsOpen") ?? - false), (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("checkUpdateOnSettingsOpen", value); - setState(() {}); - }), + titleDivider(), button(AppLocalizations.of(context)!.settingsGithub, SimpleIcons.github, () { HapticFeedback.selectionClick(); diff --git a/lib/settings/export.dart b/lib/settings/export.dart index ff4d2d1..d980ac1 100644 --- a/lib/settings/export.dart +++ b/lib/settings/export.dart @@ -72,7 +72,7 @@ class _ScreenSettingsExportState extends State { child: Column(children: [ Expanded( child: ListView(children: [ - const SizedBox(height: 16), + // const SizedBox(height: 16), button(AppLocalizations.of(context)!.settingsExportChats, Icons.upload_rounded, () async { HapticFeedback.selectionClick(); diff --git a/lib/settings/interface.dart b/lib/settings/interface.dart index 0261b98..b3b8d24 100644 --- a/lib/settings/interface.dart +++ b/lib/settings/interface.dart @@ -71,6 +71,82 @@ class _ScreenSettingsInterfaceState extends State { child: Column(children: [ Expanded( child: ListView(children: [ + // const SizedBox(height: 16), + toggle( + context, + AppLocalizations.of(context)!.settingsShowModelTags, + (prefs!.getBool("modelTags") ?? false), (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("modelTags", value); + setState(() {}); + }), + toggle( + context, + AppLocalizations.of(context)! + .settingsResetOnModelChange, + (prefs!.getBool("resetOnModelSelect") ?? true), + (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("resetOnModelSelect", value); + setState(() {}); + }), + titleDivider(), + toggle( + context, + AppLocalizations.of(context)!.settingsGenerateTitles, + (prefs!.getBool("generateTitles") ?? true), (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("generateTitles", value); + setState(() {}); + }), + toggle( + context, + AppLocalizations.of(context)!.settingsEnableEditing, + (prefs!.getBool("enableEditing") ?? true), (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("enableEditing", value); + setState(() {}); + }), + toggle( + context, + AppLocalizations.of(context)!.settingsAskBeforeDelete, + (prefs!.getBool("askBeforeDeletion") ?? false), + (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("askBeforeDeletion", value); + setState(() {}); + }), + toggle( + context, + AppLocalizations.of(context)!.settingsShowTips, + (prefs!.getBool("tips") ?? true), (value) { + HapticFeedback.selectionClick(); + prefs!.setBool("tips", value); + setState(() {}); + }), + titleDivider(bottom: 20), + SegmentedButton( + segments: [ + ButtonSegment( + value: "stream", + label: Text(AppLocalizations.of(context)! + .settingsRequestTypeStream), + icon: const Icon(Icons.stream_rounded)), + ButtonSegment( + value: "request", + label: Text(AppLocalizations.of(context)! + .settingsRequestTypeRequest), + icon: const Icon(Icons.send_rounded)) + ], + selected: { + prefs!.getString("requestType") ?? "stream" + }, + onSelectionChanged: (p0) { + HapticFeedback.selectionClick(); + setState(() { + prefs!.setString("requestType", p0.elementAt(0)); + }); + }), const SizedBox(height: 16), SegmentedButton( segments: [ @@ -151,81 +227,6 @@ class _ScreenSettingsInterfaceState extends State { }); }); }), - const SizedBox(height: 16), - toggle( - context, - AppLocalizations.of(context)!.settingsGenerateTitles, - (prefs!.getBool("generateTitles") ?? true), (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("generateTitles", value); - setState(() {}); - }), - toggle( - context, - AppLocalizations.of(context)!.settingsAskBeforeDelete, - (prefs!.getBool("askBeforeDeletion") ?? false), - (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("askBeforeDeletion", value); - setState(() {}); - }), - toggle( - context, - AppLocalizations.of(context)! - .settingsResetOnModelChange, - (prefs!.getBool("resetOnModelSelect") ?? true), - (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("resetOnModelSelect", value); - setState(() {}); - }), - toggle( - context, - AppLocalizations.of(context)!.settingsEnableEditing, - (prefs!.getBool("enableEditing") ?? true), (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("enableEditing", value); - setState(() {}); - }), - toggle( - context, - AppLocalizations.of(context)!.settingsShowTips, - (prefs!.getBool("tips") ?? true), (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("tips", value); - setState(() {}); - }), - toggle( - context, - AppLocalizations.of(context)!.settingsShowModelTags, - (prefs!.getBool("modelTags") ?? false), (value) { - HapticFeedback.selectionClick(); - prefs!.setBool("modelTags", value); - setState(() {}); - }), - const SizedBox(height: 16), - SegmentedButton( - segments: [ - ButtonSegment( - value: "stream", - label: Text(AppLocalizations.of(context)! - .settingsRequestTypeStream), - icon: const Icon(Icons.stream_rounded)), - ButtonSegment( - value: "request", - label: Text(AppLocalizations.of(context)! - .settingsRequestTypeRequest), - icon: const Icon(Icons.send_rounded)) - ], - selected: { - prefs!.getString("requestType") ?? "stream" - }, - onSelectionChanged: (p0) { - HapticFeedback.selectionClick(); - setState(() { - prefs!.setString("requestType", p0.elementAt(0)); - }); - }) ]), ), const SizedBox(height: 16)