From ece0669f7df2706cfa5138621aee77f05f1e05ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20M=C3=BCller?= Date: Sat, 30 May 2026 13:54:19 +0200 Subject: [PATCH] implemented a central haptic feedback system with configurable levels (off, reduced, full), added a `Haptics` facade providing semantic feedback methods, integrated haptic cues across navigation, settings toggles, and async action results, and updated version to 1.1.0+54 --- lib/app.dart | 12 ++- .../view/loadable_state_consumer.dart | 2 + lib/storage/haptic_settings.dart | 16 +++ lib/storage/haptic_settings.g.dart | 19 ++++ lib/storage/settings.dart | 3 + lib/storage/settings.g.dart | 4 + lib/utils/clipboard_helper.dart | 3 + lib/utils/haptics.dart | 72 +++++++++++++ lib/view/login/login.dart | 2 + .../pages/files/widgets/file_element.dart | 3 + .../pages/settings/data/default_settings.dart | 2 + .../pages/settings/modules_settings_page.dart | 10 +- .../settings/sections/appearance_section.dart | 102 ++++++++++++++---- .../settings/sections/dev_tools_section.dart | 40 +++---- .../settings/sections/files_section.dart | 20 ++-- .../pages/settings/sections/talk_section.dart | 14 ++- .../settings/sections/timetable_section.dart | 14 +-- lib/view/pages/talk/widgets/chat_bubble.dart | 26 +++-- lib/view/pages/talk/widgets/chat_tile.dart | 2 + .../timetable/widgets/calendar/week_grid.dart | 2 +- .../widgets/custom_workweek_calendar.dart | 2 +- lib/widget/async_action_button.dart | 1 + .../async_action_controller.dart | 2 + lib/widget/async_actions/async_mixin.dart | 6 +- lib/widget/confirm_dialog.dart | 2 + pubspec.yaml | 2 +- 26 files changed, 308 insertions(+), 75 deletions(-) create mode 100644 lib/storage/haptic_settings.dart create mode 100644 lib/storage/haptic_settings.g.dart create mode 100644 lib/utils/haptics.dart diff --git a/lib/app.dart b/lib/app.dart index eb3b3eb..e5317a6 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -23,6 +23,7 @@ import 'state/app/modules/timetable/bloc/timetable_bloc.dart'; import 'state/app/modules/timetable/bloc/timetable_state.dart'; import 'storage/settings.dart' as model; import 'utils/debouncer.dart'; +import 'utils/haptics.dart'; import 'view/pages/overhang.dart'; import 'widget/breaker/breaker.dart'; import 'widget_data/widget_navigation.dart'; @@ -42,13 +43,19 @@ class _AppState extends State with WidgetsBindingObserver { StreamSubscription? _onMessageOpenedAppSub; StreamSubscription? _fcmTokenRefreshSub; int _knownTotalTabs = 1; + int _lastTabIndex = 0; bool _userOnLastTab = false; static const Duration _chatListActiveInterval = Duration(seconds: 15); static const Duration _chatListIdleInterval = Duration(seconds: 60); void _onTabControllerChanged() { - _userOnLastTab = Main.bottomNavigator.index == _knownTotalTabs - 1; + final newIndex = Main.bottomNavigator.index; + if (newIndex != _lastTabIndex) { + Haptics.selection(); + _lastTabIndex = newIndex; + } + _userOnLastTab = newIndex == _knownTotalTabs - 1; _syncChatListPolling(); } @@ -107,7 +114,9 @@ class _AppState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); + Haptics.bind(context.read()); Main.bottomNavigator = PersistentTabController(initialIndex: 0); + _lastTabIndex = Main.bottomNavigator.index; Main.bottomNavigator.addListener(_onTabControllerChanged); WidgetsBinding.instance.addObserver(this); @@ -230,6 +239,7 @@ class _AppState extends State with WidgetsBindingObserver { Main.bottomNavigator = PersistentTabController( initialIndex: targetIndex, ); + _lastTabIndex = targetIndex; Main.bottomNavigator.addListener(_onTabControllerChanged); _userOnLastTab = targetIndex == totalTabs - 1; } diff --git a/lib/state/app/infrastructure/loadable_state/view/loadable_state_consumer.dart b/lib/state/app/infrastructure/loadable_state/view/loadable_state_consumer.dart index 75ab76e..2139a70 100644 --- a/lib/state/app/infrastructure/loadable_state/view/loadable_state_consumer.dart +++ b/lib/state/app/infrastructure/loadable_state/view/loadable_state_consumer.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../../../utils/haptics.dart'; import '../../../../../widget/conditional_wrapper.dart'; import '../../utility_widgets/bloc_module.dart'; import '../../utility_widgets/loadable_hydrated_bloc/loadable_hydrated_bloc_event.dart'; @@ -86,6 +87,7 @@ class LoadableStateConsumer< final childWidget = enablePullToRefresh ? RefreshIndicator( onRefresh: () { + Haptics.refresh(); loadableState.reFetch?.call(); return Future.value(); }, diff --git a/lib/storage/haptic_settings.dart b/lib/storage/haptic_settings.dart new file mode 100644 index 0000000..cebc91e --- /dev/null +++ b/lib/storage/haptic_settings.dart @@ -0,0 +1,16 @@ +import 'package:json_annotation/json_annotation.dart'; + +part 'haptic_settings.g.dart'; + +enum HapticLevel { off, reduced, full } + +@JsonSerializable() +class HapticSettings { + HapticLevel level; + + HapticSettings({required this.level}); + + factory HapticSettings.fromJson(Map json) => + _$HapticSettingsFromJson(json); + Map toJson() => _$HapticSettingsToJson(this); +} diff --git a/lib/storage/haptic_settings.g.dart b/lib/storage/haptic_settings.g.dart new file mode 100644 index 0000000..db1f522 --- /dev/null +++ b/lib/storage/haptic_settings.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'haptic_settings.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +HapticSettings _$HapticSettingsFromJson(Map json) => + HapticSettings(level: $enumDecode(_$HapticLevelEnumMap, json['level'])); + +Map _$HapticSettingsToJson(HapticSettings instance) => + {'level': _$HapticLevelEnumMap[instance.level]!}; + +const _$HapticLevelEnumMap = { + HapticLevel.off: 'off', + HapticLevel.reduced: 'reduced', + HapticLevel.full: 'full', +}; diff --git a/lib/storage/settings.dart b/lib/storage/settings.dart index e7fc579..7fa4a18 100644 --- a/lib/storage/settings.dart +++ b/lib/storage/settings.dart @@ -4,6 +4,7 @@ import 'package:json_annotation/json_annotation.dart'; import 'dev_tools_settings.dart'; import 'file_settings.dart'; import 'file_view_settings.dart'; +import 'haptic_settings.dart'; import 'holidays_settings.dart'; import 'modules_settings.dart'; import 'notification_settings.dart'; @@ -26,6 +27,7 @@ class Settings { FileViewSettings fileViewSettings; NotificationSettings notificationSettings; DevToolsSettings devToolsSettings; + HapticSettings hapticSettings; Settings({ required this.appTheme, @@ -38,6 +40,7 @@ class Settings { required this.fileViewSettings, required this.notificationSettings, required this.devToolsSettings, + required this.hapticSettings, }); static String _themeToJson(ThemeMode m) => m.name; diff --git a/lib/storage/settings.g.dart b/lib/storage/settings.g.dart index a3402be..6da7a81 100644 --- a/lib/storage/settings.g.dart +++ b/lib/storage/settings.g.dart @@ -33,6 +33,9 @@ Settings _$SettingsFromJson(Map json) => Settings( devToolsSettings: DevToolsSettings.fromJson( json['devToolsSettings'] as Map, ), + hapticSettings: HapticSettings.fromJson( + json['hapticSettings'] as Map, + ), ); Map _$SettingsToJson(Settings instance) => { @@ -46,4 +49,5 @@ Map _$SettingsToJson(Settings instance) => { 'fileViewSettings': instance.fileViewSettings.toJson(), 'notificationSettings': instance.notificationSettings.toJson(), 'devToolsSettings': instance.devToolsSettings.toJson(), + 'hapticSettings': instance.hapticSettings.toJson(), }; diff --git a/lib/utils/clipboard_helper.dart b/lib/utils/clipboard_helper.dart index 54c56f1..81e915e 100644 --- a/lib/utils/clipboard_helper.dart +++ b/lib/utils/clipboard_helper.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'haptics.dart'; + /// Copies [text] to the system clipboard and shows a SnackBar. Future copyToClipboard( BuildContext context, @@ -8,6 +10,7 @@ Future copyToClipboard( String successMessage = 'In Zwischenablage kopiert', }) async { await Clipboard.setData(ClipboardData(text: text)); + Haptics.selection(); if (!context.mounted) return; ScaffoldMessenger.of(context).showSnackBar( SnackBar( diff --git a/lib/utils/haptics.dart b/lib/utils/haptics.dart new file mode 100644 index 0000000..e668eb1 --- /dev/null +++ b/lib/utils/haptics.dart @@ -0,0 +1,72 @@ +import 'dart:async'; + +import 'package:flutter/services.dart'; + +import '../state/app/modules/settings/bloc/settings_cubit.dart'; +import '../storage/haptic_settings.dart'; +import '../storage/settings.dart'; + +/// App-weite Haptik-Fassade. Liest die aktive Stufe aus einem in-memory Cache, +/// der einmal an den SettingsCubit gebunden wird — damit sind die Aufrufe +/// kontextfrei (egal ob aus Widget oder Util). +/// +/// Semantische Methoden statt roher Impacts, damit Call-Sites die Intention +/// transportieren, nicht die Stärke. +class Haptics { + static HapticLevel _level = HapticLevel.full; + static StreamSubscription? _sub; + + /// Einmal aus App-Root aufrufen, sobald der [SettingsCubit] verfügbar ist. + static void bind(SettingsCubit cubit) { + _level = cubit.state.hapticSettings.level; + _sub?.cancel(); + _sub = cubit.stream.listen((s) => _level = s.hapticSettings.level); + } + + // --- reduced + full --- + + /// Long-Press, der ein Bottom-Sheet / Action-Menü öffnet. + static void longPress() { + if (_level == HapticLevel.off) return; + HapticFeedback.mediumImpact(); + } + + /// Bestätigen eines ConfirmDialogs (nicht das Abbrechen). + static void confirm() { + if (_level == HapticLevel.off) return; + HapticFeedback.mediumImpact(); + } + + /// Fehler einer Async-Aktion / Dialog-Fehler. + static void error() { + if (_level == HapticLevel.off) return; + HapticFeedback.mediumImpact(); + } + + /// Seltener Dopamin-Moment — z.B. erfolgreicher Login. + static void heavyAccent() { + if (_level == HapticLevel.off) return; + HapticFeedback.heavyImpact(); + } + + // --- nur full --- + + /// Erfolg einer Async-Aktion (Senden, Reagieren, Speichern, …). + static void success() { + if (_level != HapticLevel.full) return; + HapticFeedback.lightImpact(); + } + + /// Pull-to-Refresh ausgelöst. + static void refresh() { + if (_level != HapticLevel.full) return; + HapticFeedback.selectionClick(); + } + + /// Tab-Wechsel, Toggle-Switch, Clipboard-Copy — alles, was eine + /// subtile Quittung verdient. + static void selection() { + if (_level != HapticLevel.full) return; + HapticFeedback.selectionClick(); + } +} diff --git a/lib/view/login/login.dart b/lib/view/login/login.dart index 85d1f4c..2d8b966 100644 --- a/lib/view/login/login.dart +++ b/lib/view/login/login.dart @@ -10,6 +10,7 @@ import '../../state/app/modules/settings/bloc/settings_cubit.dart'; import '../../storage/dev_tools_settings.dart'; import '../../storage/settings.dart' as model; import '../../theming/light_app_theme.dart'; +import '../../utils/haptics.dart'; import '../pages/settings/widgets/endpoint_picker.dart'; import 'login_controller.dart'; import 'widgets/login_branding.dart'; @@ -40,6 +41,7 @@ class _LoginState extends State { } void _onLoginSuccess() { + Haptics.heavyAccent(); context.read().setStatus(AccountStatus.loggedIn); // Re-register the periodic refresh (cancelAll runs on logout) and kick // off an immediate one-off so the widget populates within seconds diff --git a/lib/view/pages/files/widgets/file_element.dart b/lib/view/pages/files/widgets/file_element.dart index 6cb91b2..a17d9af 100644 --- a/lib/view/pages/files/widgets/file_element.dart +++ b/lib/view/pages/files/widgets/file_element.dart @@ -10,6 +10,7 @@ import '../../../../routing/app_routes.dart'; import '../../../../share_intent/remote_file_ref.dart'; import '../../../../utils/download_manager.dart'; import '../../../../utils/file_clipboard.dart'; +import '../../../../utils/haptics.dart'; import '../../../../widget/centered_leading.dart'; import '../../../../widget/confirm_dialog.dart'; import '../../../../widget/details_bottom_sheet.dart'; @@ -83,6 +84,7 @@ class _FileElementState extends State { if (job == null) return; final status = job.status.value; if (status is DownloadDone) { + Haptics.success(); DownloadManager.instance.clear(widget.file.path); _detachJob(); AppRoutes.openFileViewer( @@ -288,6 +290,7 @@ class _FileElementState extends State { } void _showActionSheet() { + Haptics.longPress(); showDetailsBottomSheet( context, children: (sheetCtx) => [ diff --git a/lib/view/pages/settings/data/default_settings.dart b/lib/view/pages/settings/data/default_settings.dart index 5191e47..2e92119 100644 --- a/lib/view/pages/settings/data/default_settings.dart +++ b/lib/view/pages/settings/data/default_settings.dart @@ -6,6 +6,7 @@ import '../../../../state/app/modules/app_modules.dart'; import '../../../../storage/dev_tools_settings.dart'; import '../../../../storage/file_settings.dart'; import '../../../../storage/file_view_settings.dart'; +import '../../../../storage/haptic_settings.dart'; import '../../../../storage/holidays_settings.dart'; import '../../../../storage/modules_settings.dart'; import '../../../../storage/notification_settings.dart'; @@ -65,5 +66,6 @@ class DefaultSettings { marianumConnectEndpoint: MarianumConnectEndpoint.live, marianumConnectCustomUrl: '', ), + hapticSettings: HapticSettings(level: HapticLevel.full), ); } diff --git a/lib/view/pages/settings/modules_settings_page.dart b/lib/view/pages/settings/modules_settings_page.dart index 623e9f3..7f7e901 100644 --- a/lib/view/pages/settings/modules_settings_page.dart +++ b/lib/view/pages/settings/modules_settings_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../state/app/modules/app_modules.dart'; import '../../../state/app/modules/settings/bloc/settings_cubit.dart'; import '../../../storage/settings.dart' as model; +import '../../../utils/haptics.dart'; import '../../../widget/confirm_dialog.dart'; import 'data/default_settings.dart'; @@ -23,6 +24,7 @@ class ModuleSortBody extends StatelessWidget { final modulesSettings = settings.val().modulesSettings; void changeVisibility(Modules module) { + Haptics.selection(); var hidden = settings.val(write: true).modulesSettings.hiddenModules; if (hidden.contains(module)) { hidden.remove(module); @@ -48,9 +50,11 @@ class ModuleSortBody extends StatelessWidget { 'Auf größeren Bildschirmen werden mehr Module direkt angezeigt', ), value: modulesSettings.autoFillBottomBar, - onChanged: (value) => - settings.val(write: true).modulesSettings.autoFillBottomBar = - value, + onChanged: (value) { + Haptics.selection(); + settings.val(write: true).modulesSettings.autoFillBottomBar = + value; + }, ), if (!modulesSettings.autoFillBottomBar) ListTile( diff --git a/lib/view/pages/settings/sections/appearance_section.dart b/lib/view/pages/settings/sections/appearance_section.dart index 851c25f..137757b 100644 --- a/lib/view/pages/settings/sections/appearance_section.dart +++ b/lib/view/pages/settings/sections/appearance_section.dart @@ -2,7 +2,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../state/app/modules/settings/bloc/settings_cubit.dart'; +import '../../../../storage/haptic_settings.dart'; import '../../../../theming/app_theme.dart'; +import '../../../../utils/haptics.dart'; class AppearanceSection extends StatelessWidget { const AppearanceSection({super.key}); @@ -10,29 +12,83 @@ class AppearanceSection extends StatelessWidget { @override Widget build(BuildContext context) { final settings = context.watch(); - return ListTile( - leading: const Icon(Icons.dark_mode_outlined), - title: const Text('Farbgebung'), - trailing: DropdownButton( - value: settings.val().appTheme, - icon: const Icon(Icons.arrow_drop_down), - items: ThemeMode.values - .map( - (e) => DropdownMenuItem( - value: e, - enabled: e != settings.val().appTheme, - child: Row( - children: [ - Icon(AppTheme.getDisplayOptions(e).icon), - const SizedBox(width: 10), - Text(AppTheme.getDisplayOptions(e).displayName), - ], - ), - ), - ) - .toList(), - onChanged: (e) => settings.val(write: true).appTheme = e!, - ), + return Column( + children: [ + ListTile( + leading: const Icon(Icons.dark_mode_outlined), + title: const Text('Farbgebung'), + trailing: DropdownButton( + value: settings.val().appTheme, + icon: const Icon(Icons.arrow_drop_down), + items: ThemeMode.values + .map( + (e) => DropdownMenuItem( + value: e, + enabled: e != settings.val().appTheme, + child: Row( + children: [ + Icon(AppTheme.getDisplayOptions(e).icon), + const SizedBox(width: 10), + Text(AppTheme.getDisplayOptions(e).displayName), + ], + ), + ), + ) + .toList(), + onChanged: (e) => settings.val(write: true).appTheme = e!, + ), + ), + ListTile( + leading: const Icon(Icons.vibration_outlined), + title: const Text('Haptisches Feedback'), + trailing: DropdownButton( + value: settings.val().hapticSettings.level, + icon: const Icon(Icons.arrow_drop_down), + items: HapticLevel.values + .map( + (e) => DropdownMenuItem( + value: e, + enabled: e != settings.val().hapticSettings.level, + child: Row( + children: [ + Icon(_hapticIcon(e)), + const SizedBox(width: 10), + Text(_hapticLabel(e)), + ], + ), + ), + ) + .toList(), + onChanged: (e) { + settings.val(write: true).hapticSettings.level = e!; + // Sofortiges Probe-Feedback in der neu gewählten Stufe. + Haptics.longPress(); + }, + ), + ), + ], ); } + + IconData _hapticIcon(HapticLevel level) { + switch (level) { + case HapticLevel.off: + return Icons.notifications_off_outlined; + case HapticLevel.reduced: + return Icons.notifications_paused_outlined; + case HapticLevel.full: + return Icons.notifications_active_outlined; + } + } + + String _hapticLabel(HapticLevel level) { + switch (level) { + case HapticLevel.off: + return 'Aus'; + case HapticLevel.reduced: + return 'Reduziert'; + case HapticLevel.full: + return 'Vollständig'; + } + } } diff --git a/lib/view/pages/settings/sections/dev_tools_section.dart b/lib/view/pages/settings/sections/dev_tools_section.dart index df7fab7..9ed675d 100644 --- a/lib/view/pages/settings/sections/dev_tools_section.dart +++ b/lib/view/pages/settings/sections/dev_tools_section.dart @@ -6,6 +6,7 @@ import 'package:hydrated_bloc/hydrated_bloc.dart'; import '../../../../routing/app_routes.dart'; import '../../../../state/app/modules/settings/bloc/settings_cubit.dart'; import '../../../../storage/settings.dart' as model; +import '../../../../utils/haptics.dart'; import '../../../../widget/centered_leading.dart'; import '../../../../widget/confirm_dialog.dart'; import '../../../../widget/debug/cache_view.dart'; @@ -45,12 +46,13 @@ class _DevToolsSectionState extends State { title: const Text('Performance graph'), trailing: Checkbox( value: dev.showPerformanceOverlay, - onChanged: (e) => - widget.settings - .val(write: true) - .devToolsSettings - .showPerformanceOverlay = - e!, + onChanged: (e) { + Haptics.selection(); + widget.settings + .val(write: true) + .devToolsSettings + .showPerformanceOverlay = e!; + }, ), ), ListTile( @@ -60,12 +62,13 @@ class _DevToolsSectionState extends State { title: const Text('Indicate offscreen layers'), trailing: Checkbox( value: dev.checkerboardOffscreenLayers, - onChanged: (e) => - widget.settings - .val(write: true) - .devToolsSettings - .checkerboardOffscreenLayers = - e!, + onChanged: (e) { + Haptics.selection(); + widget.settings + .val(write: true) + .devToolsSettings + .checkerboardOffscreenLayers = e!; + }, ), ), ListTile( @@ -73,12 +76,13 @@ class _DevToolsSectionState extends State { title: const Text('Indicate raster cache images'), trailing: Checkbox( value: dev.checkerboardRasterCacheImages, - onChanged: (e) => - widget.settings - .val(write: true) - .devToolsSettings - .checkerboardRasterCacheImages = - e!, + onChanged: (e) { + Haptics.selection(); + widget.settings + .val(write: true) + .devToolsSettings + .checkerboardRasterCacheImages = e!; + }, ), ), ], diff --git a/lib/view/pages/settings/sections/files_section.dart b/lib/view/pages/settings/sections/files_section.dart index 1c4a7d1..9853b1f 100644 --- a/lib/view/pages/settings/sections/files_section.dart +++ b/lib/view/pages/settings/sections/files_section.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../state/app/modules/settings/bloc/settings_cubit.dart'; +import '../../../../utils/haptics.dart'; class FilesSection extends StatelessWidget { const FilesSection({super.key}); @@ -16,8 +17,10 @@ class FilesSection extends StatelessWidget { title: const Text('Ordner in Dateien nach oben sortieren'), trailing: Checkbox( value: settings.val().fileSettings.sortFoldersToTop, - onChanged: (e) => - settings.val(write: true).fileSettings.sortFoldersToTop = e!, + onChanged: (e) { + Haptics.selection(); + settings.val(write: true).fileSettings.sortFoldersToTop = e!; + }, ), ), ListTile( @@ -25,12 +28,13 @@ class FilesSection extends StatelessWidget { title: const Text('Dateien immer mit Systemdialog öffnen'), trailing: Checkbox( value: settings.val().fileViewSettings.alwaysOpenExternally, - onChanged: (e) => - settings - .val(write: true) - .fileViewSettings - .alwaysOpenExternally = - e!, + onChanged: (e) { + Haptics.selection(); + settings + .val(write: true) + .fileViewSettings + .alwaysOpenExternally = e!; + }, ), ), ], diff --git a/lib/view/pages/settings/sections/talk_section.dart b/lib/view/pages/settings/sections/talk_section.dart index 2aae4fe..eeac06e 100644 --- a/lib/view/pages/settings/sections/talk_section.dart +++ b/lib/view/pages/settings/sections/talk_section.dart @@ -3,6 +3,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../notification/notify_updater.dart'; import '../../../../state/app/modules/settings/bloc/settings_cubit.dart'; +import '../../../../utils/haptics.dart'; import '../../../../widget/centered_leading.dart'; import '../../../../widget/info_dialog.dart'; @@ -21,8 +22,10 @@ class TalkSection extends StatelessWidget { title: const Text('Favoriten im Talk nach oben sortieren'), trailing: Checkbox( value: talkSettings.sortFavoritesToTop, - onChanged: (e) => - settings.val(write: true).talkSettings.sortFavoritesToTop = e!, + onChanged: (e) { + Haptics.selection(); + settings.val(write: true).talkSettings.sortFavoritesToTop = e!; + }, ), ), ListTile( @@ -30,8 +33,10 @@ class TalkSection extends StatelessWidget { title: const Text('Ungelesene Chats nach oben sortieren'), trailing: Checkbox( value: talkSettings.sortUnreadToTop, - onChanged: (e) => - settings.val(write: true).talkSettings.sortUnreadToTop = e!, + onChanged: (e) { + Haptics.selection(); + settings.val(write: true).talkSettings.sortUnreadToTop = e!; + }, ), ), ListTile( @@ -43,6 +48,7 @@ class TalkSection extends StatelessWidget { trailing: Checkbox( value: notificationSettings.enabled, onChanged: (e) { + Haptics.selection(); if (e!) { NotifyUpdater.enableAfterDisclaimer(settings).asDialog(context); } else { diff --git a/lib/view/pages/settings/sections/timetable_section.dart b/lib/view/pages/settings/sections/timetable_section.dart index 044cca0..e63917b 100644 --- a/lib/view/pages/settings/sections/timetable_section.dart +++ b/lib/view/pages/settings/sections/timetable_section.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import '../../../../state/app/modules/settings/bloc/settings_cubit.dart'; +import '../../../../utils/haptics.dart'; import '../../../../view/pages/timetable/data/timetable_name_mode.dart'; class TimetableSection extends StatelessWidget { @@ -46,12 +47,13 @@ class TimetableSection extends StatelessWidget { title: const Text('Doppelstunden zusammenhängend anzeigen'), trailing: Checkbox( value: timetableSettings.connectDoubleLessons, - onChanged: (e) => - settings - .val(write: true) - .timetableSettings - .connectDoubleLessons = - e!, + onChanged: (e) { + Haptics.selection(); + settings + .val(write: true) + .timetableSettings + .connectDoubleLessons = e!; + }, ), ), ], diff --git a/lib/view/pages/talk/widgets/chat_bubble.dart b/lib/view/pages/talk/widgets/chat_bubble.dart index d026b4d..b630f1f 100644 --- a/lib/view/pages/talk/widgets/chat_bubble.dart +++ b/lib/view/pages/talk/widgets/chat_bubble.dart @@ -9,6 +9,7 @@ import '../../../../routing/app_routes.dart'; import '../../../../share_intent/remote_file_ref.dart'; import '../../../../state/app/modules/chat/bloc/chat_bloc.dart'; import '../../../../utils/download_manager.dart'; +import '../../../../utils/haptics.dart'; import '../../../../widget/confirm_dialog.dart'; import '../../../../widget/info_dialog.dart'; import '../data/chat_bubble_styles.dart'; @@ -63,6 +64,7 @@ class _ChatBubbleState extends State Offset _position = Offset.zero; Offset _dragStartPosition = Offset.zero; + bool _swipeActionArmed = false; @override void initState() { @@ -97,6 +99,7 @@ class _ChatBubbleState extends State if (job == null) return; final status = job.status.value; if (status is DownloadDone) { + Haptics.success(); DownloadManager.instance.clear(job.remotePath); _detachJob(); final talkFile = message.file; @@ -197,13 +200,16 @@ class _ChatBubbleState extends State } } - void _showOptionsDialog() => showChatMessageOptionsDialog( - context, - chatData: widget.chatData, - bubbleData: widget.bubbleData, - isSender: widget.isSender, - onRefetch: widget.refetch, - ); + void _showOptionsDialog() { + Haptics.longPress(); + showChatMessageOptionsDialog( + context, + chatData: widget.chatData, + bubbleData: widget.bubbleData, + isSender: widget.isSender, + onRefetch: widget.refetch, + ); + } /// True only for messages whose body has a meaningful tap action (poll /// dialog or file download/cancel). For plain text messages we leave @@ -302,10 +308,16 @@ class _ChatBubbleState extends State ? Offset(_position.dx, 0) : Offset(_position.dx + dx, 0); }); + // Beim Überqueren der Action-Schwelle einmalig Haptik feuern, + // damit der User physisch spürt: "jetzt löst's beim Loslassen aus". + final isArmed = _position.dx.abs() > 50; + if (isArmed && !_swipeActionArmed) Haptics.longPress(); + _swipeActionArmed = isArmed; }, onHorizontalDragEnd: (_) { final isAction = _position.dx.abs() > 50; setState(() => _position = Offset.zero); + _swipeActionArmed = false; if (widget.bubbleData.isReplyable && isAction) { context.read().setReferenceMessageId( widget.bubbleData.id, diff --git a/lib/view/pages/talk/widgets/chat_tile.dart b/lib/view/pages/talk/widgets/chat_tile.dart index 67a413b..20dd12a 100644 --- a/lib/view/pages/talk/widgets/chat_tile.dart +++ b/lib/view/pages/talk/widgets/chat_tile.dart @@ -13,6 +13,7 @@ import '../../../../notification/notification_tasks.dart'; import '../../../../routing/app_routes.dart'; import '../../../../state/app/modules/chat/bloc/chat_bloc.dart'; import '../../../../state/app/modules/chat_list/bloc/chat_list_bloc.dart'; +import '../../../../utils/haptics.dart'; import '../../../../widget/async_action_button.dart'; import '../../../../widget/confirm_dialog.dart'; import '../../../../widget/debug/debug_tile.dart'; @@ -166,6 +167,7 @@ class _ChatTileState extends State { }, onLongPress: () { if (widget.disableContextActions) return; + Haptics.longPress(); showDetailsBottomSheet( context, children: (sheetCtx) => [ diff --git a/lib/view/pages/timetable/widgets/calendar/week_grid.dart b/lib/view/pages/timetable/widgets/calendar/week_grid.dart index f5a0f65..9c49381 100644 --- a/lib/view/pages/timetable/widgets/calendar/week_grid.dart +++ b/lib/view/pages/timetable/widgets/calendar/week_grid.dart @@ -242,7 +242,7 @@ class _DayColumn extends StatelessWidget { ); if (_overlapsExistingAppointment(start, end, dayAppts)) return; - HapticFeedback.mediumImpact(); + Haptics.longPress(); onCreateEvent!(start, end); } diff --git a/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart b/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart index 867670e..bb8a6be 100644 --- a/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart +++ b/lib/view/pages/timetable/widgets/custom_workweek_calendar.dart @@ -9,11 +9,11 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:intl/intl.dart'; import 'package:syncfusion_flutter_calendar/calendar.dart'; import '../../../../extensions/date_time.dart'; +import '../../../../utils/haptics.dart'; import '../../../../widget/details_bottom_sheet.dart'; import '../data/calendar_layout.dart'; import '../data/calendar_logic.dart'; diff --git a/lib/widget/async_action_button.dart b/lib/widget/async_action_button.dart index 96ef4eb..f99dfd6 100644 --- a/lib/widget/async_action_button.dart +++ b/lib/widget/async_action_button.dart @@ -7,6 +7,7 @@ library; import 'package:flutter/material.dart'; import '../api/errors/error_mapper.dart'; +import '../utils/haptics.dart'; import 'app_progress_indicator.dart'; import 'info_dialog.dart'; diff --git a/lib/widget/async_actions/async_action_controller.dart b/lib/widget/async_actions/async_action_controller.dart index 2046c22..51c385d 100644 --- a/lib/widget/async_actions/async_action_controller.dart +++ b/lib/widget/async_actions/async_action_controller.dart @@ -13,8 +13,10 @@ Future runWithErrorDialog( }) async { try { await action(); + Haptics.success(); return true; } catch (e) { + Haptics.error(); if (!context.mounted) return false; final message = errorBuilder != null ? errorBuilder(e) diff --git a/lib/widget/async_actions/async_mixin.dart b/lib/widget/async_actions/async_mixin.dart index 85d2dc3..c4700f6 100644 --- a/lib/widget/async_actions/async_mixin.dart +++ b/lib/widget/async_actions/async_mixin.dart @@ -66,9 +66,11 @@ class _AsyncMixinState extends State<_AsyncMixin> { ); if (!mounted) return; if (success) { + Haptics.success(); widget.onSuccess?.call(); - } else if (widget.onError != null && _controller.error != null) { - widget.onError!(_controller.error!); + } else if (_controller.error != null) { + Haptics.error(); + widget.onError?.call(_controller.error!); } } diff --git a/lib/widget/confirm_dialog.dart b/lib/widget/confirm_dialog.dart index acdcf65..e7f06e5 100644 --- a/lib/widget/confirm_dialog.dart +++ b/lib/widget/confirm_dialog.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; +import '../utils/haptics.dart'; import 'async_action_button.dart'; class ConfirmDialog extends StatelessWidget { @@ -53,6 +54,7 @@ class ConfirmDialog extends StatelessWidget { ), TextButton( onPressed: () { + Haptics.confirm(); Navigator.of(context).pop(); onConfirm!(); }, diff --git a/pubspec.yaml b/pubspec.yaml index 50be876..8718a7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Mobile client for Webuntis and Nextcloud with Talk integration publish_to: 'none' -version: 1.0.3+52 +version: 1.1.0+54 environment: sdk: ">=3.8.0 <4.0.0"