104 lines
4.0 KiB
Dart
104 lines
4.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import '../../../../push/push_registration.dart';
|
|
import '../../../../routing/app_routes.dart';
|
|
import '../../../../state/app/modules/settings/bloc/settings_cubit.dart';
|
|
import '../../../../utils/haptics.dart';
|
|
import '../../../../widget/centered_leading.dart';
|
|
import '../widgets/push_status_sheet.dart';
|
|
|
|
class TalkSection extends StatelessWidget {
|
|
const TalkSection({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final settings = context.watch<SettingsCubit>();
|
|
final talkSettings = settings.val().talkSettings;
|
|
final notificationSettings = settings.val().notificationSettings;
|
|
return Column(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.star_border),
|
|
title: const Text('Favoriten im Talk nach oben sortieren'),
|
|
trailing: Checkbox(
|
|
value: talkSettings.sortFavoritesToTop,
|
|
onChanged: (e) {
|
|
Haptics.selection();
|
|
settings.val(write: true).talkSettings.sortFavoritesToTop = e!;
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.mark_email_unread_outlined),
|
|
title: const Text('Ungelesene Chats nach oben sortieren'),
|
|
trailing: Checkbox(
|
|
value: talkSettings.sortUnreadToTop,
|
|
onChanged: (e) {
|
|
Haptics.selection();
|
|
settings.val(write: true).talkSettings.sortUnreadToTop = e!;
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.wallpaper_outlined),
|
|
title: const Text('Chat-Hintergrund'),
|
|
subtitle: const Text('Bild, Farbe und Darstellung anpassen'),
|
|
trailing: const Icon(Icons.arrow_right),
|
|
onTap: () => AppRoutes.openChatBackgroundSettings(context),
|
|
),
|
|
ListTile(
|
|
leading: const CenteredLeading(
|
|
Icon(Icons.notifications_active_outlined),
|
|
),
|
|
title: const Text('Push-Benachrichtigungen'),
|
|
subtitle: const Text(
|
|
'Benachrichtigungen bei neuen Talk-Nachrichten erhalten',
|
|
),
|
|
trailing: Checkbox(
|
|
value: notificationSettings.enabled,
|
|
onChanged: (e) {
|
|
Haptics.selection();
|
|
final enabled = e ?? false;
|
|
settings.val(write: true).notificationSettings.enabled = enabled;
|
|
// Turning off does NOT unregister: the device stays subscribed so
|
|
// silent sync pushes keep arriving; the message handler and iOS
|
|
// NSE suppress only the visible notification (via the mirrored
|
|
// flag). Enabling (re-)registers and ensures the OS permission.
|
|
if (enabled) {
|
|
final messenger = ScaffoldMessenger.of(context);
|
|
unawaited(() async {
|
|
// Only register when the OS permission isn't explicitly
|
|
// denied — otherwise NC + proxy would push into the void.
|
|
if (await PushRegistration.requestOsPermission()) {
|
|
await PushRegistration().register();
|
|
} else {
|
|
messenger.showSnackBar(
|
|
const SnackBar(
|
|
content: Text(
|
|
'Die Benachrichtigungsberechtigung wurde in den '
|
|
'Systemeinstellungen deaktiviert. Bitte aktiviere '
|
|
'sie dort, um Push-Benachrichtigungen zu erhalten.',
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}());
|
|
}
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
leading: const CenteredLeading(Icon(Icons.monitor_heart_outlined)),
|
|
title: const Text('Push-Status'),
|
|
subtitle: const Text('Registrierung und Zustellung im Detail'),
|
|
trailing: const Icon(Icons.arrow_right),
|
|
onTap: () => showPushStatusSheet(context),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|