refactor: Pages folder structure
This commit is contained in:
parent
5fe495db94
commit
1abb7310f3
88 changed files with 188 additions and 250 deletions
115
lib/pages/settings_notifications/settings_notifications.dart
Normal file
115
lib/pages/settings_notifications/settings_notifications.dart
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:open_noti_settings/open_noti_settings.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_notifications_view.dart';
|
||||
|
||||
class NotificationSettingsItem {
|
||||
final PushRuleKind type;
|
||||
final String key;
|
||||
final String Function(BuildContext) title;
|
||||
const NotificationSettingsItem(this.type, this.key, this.title);
|
||||
static List<NotificationSettingsItem> items = [
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.underride,
|
||||
'.m.rule.room_one_to_one',
|
||||
(c) => L10n.of(c).directChats,
|
||||
),
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.override,
|
||||
'.m.rule.contains_display_name',
|
||||
(c) => L10n.of(c).containsDisplayName,
|
||||
),
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.content,
|
||||
'.m.rule.contains_user_name',
|
||||
(c) => L10n.of(c).containsUserName,
|
||||
),
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.override,
|
||||
'.m.rule.invite_for_me',
|
||||
(c) => L10n.of(c).inviteForMe,
|
||||
),
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.override,
|
||||
'.m.rule.member_event',
|
||||
(c) => L10n.of(c).memberChanges,
|
||||
),
|
||||
NotificationSettingsItem(
|
||||
PushRuleKind.override,
|
||||
'.m.rule.suppress_notices',
|
||||
(c) => L10n.of(c).botMessages,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class SettingsNotifications extends StatefulWidget {
|
||||
const SettingsNotifications({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
SettingsNotificationsController createState() =>
|
||||
SettingsNotificationsController();
|
||||
}
|
||||
|
||||
class SettingsNotificationsController extends State<SettingsNotifications> {
|
||||
void openAndroidNotificationSettingsAction() async {
|
||||
await NotificationSetting.configureChannel(
|
||||
const NotificationDetails(
|
||||
android: AndroidNotificationDetails(
|
||||
AppConfig.pushNotificationsChannelId,
|
||||
AppConfig.pushNotificationsChannelName,
|
||||
AppConfig.pushNotificationsChannelDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
return NotificationSetting.open();
|
||||
}
|
||||
|
||||
bool getNotificationSetting(NotificationSettingsItem item) {
|
||||
final pushRules = Matrix.of(context).client.globalPushRules;
|
||||
switch (item.type) {
|
||||
case PushRuleKind.content:
|
||||
return pushRules.content
|
||||
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
|
||||
?.enabled;
|
||||
case PushRuleKind.override:
|
||||
return pushRules.override
|
||||
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
|
||||
?.enabled;
|
||||
case PushRuleKind.room:
|
||||
return pushRules.room
|
||||
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
|
||||
?.enabled;
|
||||
case PushRuleKind.sender:
|
||||
return pushRules.sender
|
||||
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
|
||||
?.enabled;
|
||||
case PushRuleKind.underride:
|
||||
return pushRules.underride
|
||||
?.singleWhere((r) => r.ruleId == item.key, orElse: () => null)
|
||||
?.enabled;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void setNotificationSetting(NotificationSettingsItem item, bool enabled) {
|
||||
showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).client.setPushRuleEnabled(
|
||||
'global',
|
||||
item.type,
|
||||
item.key,
|
||||
enabled,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SettingsNotificationsView(this);
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
import '../../widgets/matrix.dart';
|
||||
import 'settings_notifications.dart';
|
||||
|
||||
class SettingsNotificationsView extends StatelessWidget {
|
||||
final SettingsNotificationsController controller;
|
||||
|
||||
const SettingsNotificationsView(this.controller, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: const BackButton(),
|
||||
title: Text(L10n.of(context).notifications),
|
||||
),
|
||||
body: MaxWidthBody(
|
||||
withScrolling: true,
|
||||
child: StreamBuilder(
|
||||
stream: Matrix.of(context)
|
||||
.client
|
||||
.onAccountData
|
||||
.stream
|
||||
.where((event) => event.type == 'm.push_rules'),
|
||||
builder: (BuildContext context, _) {
|
||||
return Column(
|
||||
children: [
|
||||
SwitchListTile(
|
||||
value: !Matrix.of(context).client.allPushNotificationsMuted,
|
||||
title: Text(
|
||||
L10n.of(context).notificationsEnabledForThisAccount),
|
||||
onChanged: (_) => showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () =>
|
||||
Matrix.of(context).client.setMuteAllPushNotifications(
|
||||
!Matrix.of(context)
|
||||
.client
|
||||
.allPushNotificationsMuted,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!Matrix.of(context).client.allPushNotificationsMuted) ...{
|
||||
if (!kIsWeb && Platform.isAndroid)
|
||||
ListTile(
|
||||
title: Text(L10n.of(context).soundVibrationLedColor),
|
||||
trailing: CircleAvatar(
|
||||
backgroundColor:
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
foregroundColor: Colors.grey,
|
||||
child: const Icon(Icons.edit_outlined),
|
||||
),
|
||||
onTap: controller.openAndroidNotificationSettingsAction,
|
||||
),
|
||||
const Divider(thickness: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).pushRules,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
for (var item in NotificationSettingsItem.items)
|
||||
SwitchListTile(
|
||||
value: controller.getNotificationSetting(item) ?? true,
|
||||
title: Text(item.title(context)),
|
||||
onChanged: (bool enabled) =>
|
||||
controller.setNotificationSetting(item, enabled),
|
||||
),
|
||||
},
|
||||
const Divider(thickness: 1),
|
||||
ListTile(
|
||||
title: Text(
|
||||
L10n.of(context).devices,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
FutureBuilder<List<Pusher>>(
|
||||
future: Matrix.of(context).client.getPushers(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
Center(
|
||||
child: Text(
|
||||
snapshot.error.toLocalizedString(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (snapshot.connectionState != ConnectionState.done) {
|
||||
const Center(
|
||||
child: CircularProgressIndicator.adaptive(
|
||||
strokeWidth: 2));
|
||||
}
|
||||
final pushers = snapshot.data ?? [];
|
||||
return ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: pushers.length,
|
||||
itemBuilder: (_, i) => ListTile(
|
||||
title: Text(
|
||||
'${pushers[i].appDisplayName} - ${pushers[i].appId}'),
|
||||
subtitle: Text(pushers[i].data.url.toString()),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue