finished notification fix

This commit is contained in:
hihihaha
2024-03-10 17:38:22 +01:00
parent f6ff98c5ed
commit b8e4c4ea3a
13 changed files with 306 additions and 177 deletions

View File

@@ -2,6 +2,8 @@ import 'package:refilc/api/providers/update_provider.dart';
import 'package:refilc/helpers/quick_actions.dart';
import 'package:refilc/models/settings.dart';
import 'package:refilc/theme/observer.dart';
import 'package:refilc/utils/navigation_service.dart';
import 'package:refilc/utils/service_locator.dart';
import 'package:refilc_kreta_api/client/client.dart';
import 'package:refilc_kreta_api/providers/grade_provider.dart';
import 'package:refilc_mobile_ui/common/system_chrome.dart';
@@ -42,7 +44,7 @@ class NavigationScreenState extends State<NavigationScreen>
with WidgetsBindingObserver {
late NavigationRoute selected;
List<String> initializers = [];
final _navigatorState = GlobalKey<NavigatorState>();
final _navigatorState = locator<NavigationService>().navigatorKey;
late SettingsProvider settings;
late NewsProvider newsProvider;

View File

@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:refilc/api/providers/database_provider.dart';
import 'package:refilc/api/providers/user_provider.dart';
import 'package:refilc/helpers/notification_helper.dart';
@@ -5,12 +6,12 @@ import 'package:refilc/models/settings.dart';
import 'package:refilc/models/user.dart';
import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_mobile_ui/common/beta_chip.dart';
import 'package:refilc_mobile_ui/common/panel/panel.dart';
import 'package:refilc_mobile_ui/common/panel/panel_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:provider/provider.dart';
import 'package:refilc_mobile_ui/common/splitted_panel/splitted_panel.dart';
import 'notifications_screen.i18n.dart';
class MenuNotifications extends StatelessWidget {
@@ -57,13 +58,15 @@ class MenuNotifications extends StatelessWidget {
class NotificationsScreen extends StatelessWidget {
const NotificationsScreen({super.key});
void setAllAsSeen(BuildContext context) {
// Set all notification categories as seen to avoid spamming the user with notifications when they turn on notifications
DatabaseProvider database = Provider.of<DatabaseProvider>(context, listen: false);
// Set all notification categories as seen to avoid spamming the user with notifications when they turn on notifications
void setAll(BuildContext context, DateTime date) {
DatabaseProvider database =
Provider.of<DatabaseProvider>(context, listen: false);
User? user = Provider.of<UserProvider>(context, listen: false).user;
if(user != null) {
for(LastSeenCategory category in LastSeenCategory.values) {
database.userStore.storeLastSeen(DateTime.now(), userId: user.id, category: category);
if (user != null) {
for (LastSeenCategory category in LastSeenCategory.values) {
database.userStore
.storeLastSeen(date, userId: user.id, category: category);
}
}
}
@@ -84,159 +87,188 @@ class NotificationsScreen extends StatelessWidget {
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
child: Panel(
child: Column(
children: [
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsGradesEnabled,
onChanged: (v) {
settings.update(notificationsGradesEnabled: v);
setAllAsSeen(context);
child: Column(
children: [
SplittedPanel(
padding: const EdgeInsets.only(top: 8.0),
cardPadding: const EdgeInsets.all(4.0),
isSeparated: true,
children: [
PanelButton(
padding: const EdgeInsets.only(left: 14.0, right: 6.0),
onPressed: () {
settings.update(
notificationsEnabled:
!settings.notificationsGradesEnabled);
setAll(context, DateTime.now());
},
title: Row(
children: [
Icon(
FeatherIcons.bookmark,
color: settings.notificationsGradesEnabled
? Theme.of(context).colorScheme.secondary
: AppColors.of(context).text.withOpacity(.25),
),
const SizedBox(width: 14.0),
Expanded(
child: Text(
"grades".i18n,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsGradesEnabled
? 1.0
: .5,
),
),
),
),
],
title: Text(
"grades".i18n,
style: TextStyle(
color: AppColors.of(context).text.withOpacity(
settings.notificationsGradesEnabled ? .95 : .25),
),
),
leading: Icon(
FeatherIcons.bookmark,
size: 22.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsGradesEnabled ? .95 : .25),
),
trailing: Switch(
onChanged: (v) =>
settings.update(notificationsGradesEnabled: v),
value: settings.notificationsGradesEnabled,
activeColor: Theme.of(context).colorScheme.secondary,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
bottom: Radius.circular(12.0),
),
),
),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsAbsencesEnabled,
onChanged: (v) {
settings.update(notificationsAbsencesEnabled: v);
setAllAsSeen(context);
],
),
SplittedPanel(
padding: const EdgeInsets.only(top: 8.0),
cardPadding: const EdgeInsets.all(4.0),
isSeparated: true,
children: [
PanelButton(
padding: const EdgeInsets.only(left: 14.0, right: 6.0),
onPressed: () {
settings.update(
notificationsEnabled:
!settings.notificationsAbsencesEnabled);
setAll(context, DateTime.now());
},
title: Row(
children: [
Icon(
FeatherIcons.clock,
color: settings.notificationsAbsencesEnabled
? Theme.of(context).colorScheme.secondary
: AppColors.of(context).text.withOpacity(.25),
),
const SizedBox(width: 14.0),
Expanded(
child: Text(
"absences".i18n,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsAbsencesEnabled
? 1.0
: .5,
),
),
),
),
],
title: Text(
"absences".i18n,
style: TextStyle(
color: AppColors.of(context).text.withOpacity(
settings.notificationsAbsencesEnabled ? .95 : .25),
),
),
leading: Icon(
FeatherIcons.clock,
size: 22.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsAbsencesEnabled ? .95 : .25),
),
trailing: Switch(
onChanged: (v) =>
settings.update(notificationsAbsencesEnabled: v),
value: settings.notificationsAbsencesEnabled,
activeColor: Theme.of(context).colorScheme.secondary,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
bottom: Radius.circular(12.0),
),
),
),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsMessagesEnabled,
onChanged: (v) {
settings.update(notificationsMessagesEnabled: v);
setAllAsSeen(context);
],
),
SplittedPanel(
padding: const EdgeInsets.only(top: 8.0),
cardPadding: const EdgeInsets.all(4.0),
isSeparated: true,
children: [
PanelButton(
padding: const EdgeInsets.only(left: 14.0, right: 6.0),
onPressed: () {
settings.update(
notificationsEnabled:
!settings.notificationsMessagesEnabled);
setAll(context, DateTime.now());
},
title: Row(
children: [
Icon(
FeatherIcons.messageSquare,
color: settings.notificationsMessagesEnabled
? Theme.of(context).colorScheme.secondary
: AppColors.of(context).text.withOpacity(.25),
),
const SizedBox(width: 14.0),
Expanded(
child: Text(
"messages".i18n,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsMessagesEnabled
? 1.0
: .5,
),
),
),
),
],
title: Text(
"messages".i18n,
style: TextStyle(
color: AppColors.of(context).text.withOpacity(
settings.notificationsMessagesEnabled ? .95 : .25),
),
),
leading: Icon(
FeatherIcons.messageSquare,
size: 22.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsMessagesEnabled ? .95 : .25),
),
trailing: Switch(
onChanged: (v) =>
settings.update(notificationsMessagesEnabled: v),
value: settings.notificationsMessagesEnabled,
activeColor: Theme.of(context).colorScheme.secondary,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
bottom: Radius.circular(12.0),
),
),
),
Material(
type: MaterialType.transparency,
child: SwitchListTile(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0)),
value: settings.notificationsLessonsEnabled,
onChanged: (v) {
settings.update(notificationsLessonsEnabled: v);
setAllAsSeen(context);
],
),
SplittedPanel(
padding: const EdgeInsets.only(top: 8.0),
cardPadding: const EdgeInsets.all(4.0),
isSeparated: true,
children: [
PanelButton(
padding: const EdgeInsets.only(left: 14.0, right: 6.0),
onPressed: () {
settings.update(
notificationsEnabled:
!settings.notificationsLessonsEnabled);
setAll(context, DateTime.now());
},
title: Row(
children: [
Icon(
FeatherIcons.calendar,
color: settings.notificationsLessonsEnabled
? Theme.of(context).colorScheme.secondary
: AppColors.of(context).text.withOpacity(.25),
),
const SizedBox(width: 14.0),
Expanded(
child: Text(
"lessons".i18n,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 16.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsLessonsEnabled
? 1.0
: .5,
),
),
),
),
],
title: Text(
"lessons".i18n,
style: TextStyle(
color: AppColors.of(context).text.withOpacity(
settings.notificationsLessonsEnabled ? .95 : .25),
),
),
leading: Icon(
FeatherIcons.bookmark,
size: 22.0,
color: AppColors.of(context).text.withOpacity(
settings.notificationsLessonsEnabled ? .95 : .25),
),
trailing: Switch(
onChanged: (v) =>
settings.update(notificationsLessonsEnabled: v),
value: settings.notificationsLessonsEnabled,
activeColor: Theme.of(context).colorScheme.secondary,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
bottom: Radius.circular(12.0),
),
),
),
],
),
],
),
// only used for debugging, pressing **will** cause notification spam
kDebugMode
? SplittedPanel(
padding: const EdgeInsets.only(top: 9.0),
cardPadding: const EdgeInsets.all(4.0),
isSeparated: true,
children: [
PanelButton(
onPressed: () => setAll(
context, DateTime(1970, 1, 1, 0, 0, 0, 0, 0)),
title: Text("set_all_as_unseen".i18n),
leading: Icon(
FeatherIcons.mail,
size: 22.0,
color: AppColors.of(context).text.withOpacity(0.95),
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12.0),
bottom: Radius.circular(4.0)),
)
],
)
: const SizedBox.shrink(),
],
),
),
),

View File

@@ -8,7 +8,8 @@ extension SettingsLocalization on String {
"grades": "Grades",
"absences": "Absences",
"messages": "Messages",
"lessons": "Lessons"
"lessons": "Lessons",
"set_all_as_unseen": "Set all as unseen",
},
"hu_hu": {
@@ -16,14 +17,16 @@ extension SettingsLocalization on String {
"grades": "Jegyek",
"absences": "Hiányzások",
"messages": "Üzenetek",
"lessons": "Órák"
"lessons": "Órák",
"set_all_as_unseen": "Összes kategória beállítása olvasatlannak",
},
"de_de": {
"notifications_screen": "Mitteilung",
"grades": "Noten",
"absences": "Fehlen",
"messages": "Nachrichten",
"lessons": "Unterricht"
"lessons": "Unterricht",
"set_all_as_unseen": "Alle als ungelesen einstellen",
},
};

View File

@@ -67,9 +67,10 @@ dependencies:
flutter_stripe: ^10.0.0
flutter_any_logo: ^1.1.1
custom_sliding_segmented_control: ^1.8.1
get_it: ^7.6.7
dev_dependencies:
flutter_lints: ^3.0.1
flutter:
uses-material-design: true
uses-material-design: true