From 9ff185d55325b094d81ead6ee39b442a0e4a1737 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Sat, 10 Dec 2022 11:44:13 -0500 Subject: [PATCH] Fix favourite spelling on notification enum --- lib/controls/app_bottom_nav_bar.dart | 26 ++++++++++++------- lib/controls/notifications_control.dart | 2 +- lib/models/user_notification.dart | 21 ++++++++++++++- lib/screens/notifications_screen.dart | 5 +++- .../notification_mastodon_extension.dart | 4 +-- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/lib/controls/app_bottom_nav_bar.dart b/lib/controls/app_bottom_nav_bar.dart index 29906f5..799474e 100644 --- a/lib/controls/app_bottom_nav_bar.dart +++ b/lib/controls/app_bottom_nav_bar.dart @@ -1,8 +1,10 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; +import 'package:provider/provider.dart'; import '../routes.dart'; +import '../services/notifications_manager.dart'; enum NavBarButtons { timelines, @@ -19,6 +21,8 @@ class AppBottomNavBar extends StatelessWidget { @override Widget build(BuildContext context) { + final notificationManager = context.watch(); + final hasNotifications = notificationManager.notifications.isNotEmpty; return BottomNavigationBar( onTap: (index) { final newButton = _indexToButton(index); @@ -51,7 +55,7 @@ class AppBottomNavBar extends StatelessWidget { selectedItemColor: Colors.black, unselectedItemColor: Colors.black54, currentIndex: _buttonToIndex(currentButton), - items: _menuItems, + items: _menuItems(hasNotifications), ); } @@ -94,29 +98,33 @@ class AppBottomNavBar extends StatelessWidget { throw ArgumentError('$index has no button type'); } - List get _menuItems { - return const [ - BottomNavigationBarItem( + List _menuItems(bool hasNotifications) { + return [ + const BottomNavigationBarItem( label: 'Timelines', icon: Icon(Icons.home_outlined), activeIcon: Icon(Icons.home_filled), ), BottomNavigationBarItem( label: 'Notifications', - icon: Icon(Icons.notifications_none_outlined), - activeIcon: Icon(Icons.notifications), + icon: Icon(hasNotifications + ? Icons.notifications_active_outlined + : Icons.notifications_none_outlined), + activeIcon: Icon(hasNotifications + ? Icons.notifications_active + : Icons.notifications), ), - BottomNavigationBarItem( + const BottomNavigationBarItem( label: 'Messages', icon: Icon(Icons.messenger_outline), activeIcon: Icon(Icons.messenger), ), - BottomNavigationBarItem( + const BottomNavigationBarItem( label: 'Contacts', icon: Icon(Icons.people_outline), activeIcon: Icon(Icons.people_sharp), ), - BottomNavigationBarItem( + const BottomNavigationBarItem( label: 'Profile', icon: Icon(Icons.person_outline), activeIcon: Icon(Icons.person), diff --git a/lib/controls/notifications_control.dart b/lib/controls/notifications_control.dart index e00fdd6..9a168b5 100644 --- a/lib/controls/notifications_control.dart +++ b/lib/controls/notifications_control.dart @@ -61,7 +61,7 @@ class NotificationControl extends StatelessWidget { case NotificationType.unknown: buildSnackbar(context, 'Unknown message type, nothing to do'); break; - case NotificationType.favorite: + case NotificationType.favourite: case NotificationType.mention: case NotificationType.reshare: case NotificationType.status: diff --git a/lib/models/user_notification.dart b/lib/models/user_notification.dart index efd82f1..2fdb6c8 100644 --- a/lib/models/user_notification.dart +++ b/lib/models/user_notification.dart @@ -1,5 +1,5 @@ enum NotificationType { - favorite, + favourite, follow, follow_request, mention, @@ -7,6 +7,25 @@ enum NotificationType { status, unknown; + String toVerb() { + switch (this) { + case NotificationType.favourite: + return 'favorited'; + case NotificationType.follow: + return 'follows'; + case NotificationType.follow_request: + return 'sent follow request to you'; + case NotificationType.mention: + return 'mentioned you on'; + case NotificationType.reshare: + return 'reshared'; + case NotificationType.status: + return 'updated'; + case NotificationType.unknown: + return 'unknowned'; + } + } + static NotificationType parse(String? text) { if (text == null) { return unknown; diff --git a/lib/screens/notifications_screen.dart b/lib/screens/notifications_screen.dart index 4f1702b..6f3a62b 100644 --- a/lib/screens/notifications_screen.dart +++ b/lib/screens/notifications_screen.dart @@ -37,7 +37,10 @@ class NotificationsScreen extends StatelessWidget { return NotificationControl(notification: notifications[index]); }, separatorBuilder: (context, index) { - return Divider(); + return Divider( + color: Colors.black54, + height: 0.0, + ); }, itemCount: notifications.length); } diff --git a/lib/serializers/mastodon/notification_mastodon_extension.dart b/lib/serializers/mastodon/notification_mastodon_extension.dart index 0d2a5d5..6a46113 100644 --- a/lib/serializers/mastodon/notification_mastodon_extension.dart +++ b/lib/serializers/mastodon/notification_mastodon_extension.dart @@ -38,7 +38,7 @@ extension NotificationMastodonExtension on UserNotification { case NotificationType.unknown: content = '${from.name} has unknown interaction notification'; break; - case NotificationType.favorite: + case NotificationType.favourite: case NotificationType.mention: case NotificationType.reshare: case NotificationType.status: @@ -47,7 +47,7 @@ extension NotificationMastodonExtension on UserNotification { statusLink = status.externalLink; final referenceType = status.parentId.isEmpty ? 'post' : 'comment'; content = - "${from.name} $type on ${status.author}'s $referenceType: ${status.body.truncate()}"; + "${from.name} ${type.toVerb()} ${status.author}'s $referenceType: ${status.body.truncate()}"; break; }