From a9dc6744ae4e5ae16467ec62b76d12dee5a96862 Mon Sep 17 00:00:00 2001 From: "Bryant, Charles" Date: Tue, 5 Mar 2024 10:52:31 -0800 Subject: [PATCH] Revert "Merge pull request #1962 from UCSD/populate-freefood" This reverts commit 82a0909644862ea2f9f2b20bca9c4a05bdd2604d, reversing changes made to add4de5a2e01fd0fced28e0ba3dacf815cc750a4. --- lib/app_provider.dart | 6 +- lib/app_router.dart | 2 +- ...Going.dart => notifications_freefood.dart} | 12 +- ...Going.dart => notifications_freefood.dart} | 21 ++- ...Going.dart => notifications_freefood.dart} | 10 +- ..._settings_view.dart => notifications.dart} | 0 ...Going.dart => notifications_freefood.dart} | 83 ++++------- .../notifications_list_view.dart | 131 ++++++++---------- ..._settings_view.dart => notifications.dart} | 35 +++-- 9 files changed, 124 insertions(+), 176 deletions(-) rename lib/core/models/{notifications_IAmGoing.dart => notifications_freefood.dart} (69%) rename lib/core/providers/{notifications_IAmGoing.dart => notifications_freefood.dart} (92%) rename lib/core/services/{notifications_IAmGoing.dart => notifications_freefood.dart} (94%) rename lib/ui/notifications/{notification_settings_view.dart => notifications.dart} (100%) rename lib/ui/notifications/{notifications_IAmGoing.dart => notifications_freefood.dart} (63%) rename lib/ui/profile/{notification_settings_view.dart => notifications.dart} (79%) diff --git a/lib/app_provider.dart b/lib/app_provider.dart index daefd0b9b..05e8bc18b 100644 --- a/lib/app_provider.dart +++ b/lib/app_provider.dart @@ -13,7 +13,7 @@ import 'package:campus_mobile_experimental/core/providers/messages.dart'; import 'package:campus_mobile_experimental/core/providers/news.dart'; import 'package:campus_mobile_experimental/core/providers/notices.dart'; import 'package:campus_mobile_experimental/core/providers/notifications.dart'; -import 'package:campus_mobile_experimental/core/providers/notifications_IAmGoing.dart'; +import 'package:campus_mobile_experimental/core/providers/notifications_freefood.dart'; import 'package:campus_mobile_experimental/core/providers/parking.dart'; import 'package:campus_mobile_experimental/core/providers/scanner.dart'; import 'package:campus_mobile_experimental/core/providers/scanner_message.dart'; @@ -279,9 +279,9 @@ List dependentServices = [ return messageDataProvider; }, ), - ChangeNotifierProxyProvider( + ChangeNotifierProxyProvider( create: (_) { - var freefoodDataProvider = IAmGoingProvider(); + var freefoodDataProvider = FreeFoodDataProvider(); freefoodDataProvider.loadRegisteredEvents(); return freefoodDataProvider; }, diff --git a/lib/app_router.dart b/lib/app_router.dart index e6dd49cf2..35b41d9e3 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -36,7 +36,7 @@ import 'package:campus_mobile_experimental/ui/parking/parking_lot_view.dart'; import 'package:campus_mobile_experimental/ui/parking/parking_structure_view.dart'; import 'package:campus_mobile_experimental/ui/parking/spot_types_view.dart'; import 'package:campus_mobile_experimental/ui/profile/cards.dart'; -import 'package:campus_mobile_experimental/ui/profile/notification_settings_view.dart'; +import 'package:campus_mobile_experimental/ui/profile/notifications.dart'; import 'package:campus_mobile_experimental/ui/profile/profile.dart'; import 'package:campus_mobile_experimental/ui/scanner/native_scanner_view.dart'; import 'package:campus_mobile_experimental/ui/shuttle/add_shuttle_stops_view.dart'; diff --git a/lib/core/models/notifications_IAmGoing.dart b/lib/core/models/notifications_freefood.dart similarity index 69% rename from lib/core/models/notifications_IAmGoing.dart rename to lib/core/models/notifications_freefood.dart index 5515ff7d6..6216c06a0 100644 --- a/lib/core/models/notifications_IAmGoing.dart +++ b/lib/core/models/notifications_freefood.dart @@ -1,20 +1,20 @@ import 'dart:convert'; -IAmGoingModel IAmGoingModelFromJson(String str) => - IAmGoingModel.fromJson(json.decode(str)); +FreeFoodModel freeFoodModelFromJson(String str) => + FreeFoodModel.fromJson(json.decode(str)); -String freeFoodModelToJson(IAmGoingModel data) => json.encode(data.toJson()); +String freeFoodModelToJson(FreeFoodModel data) => json.encode(data.toJson()); -class IAmGoingModel { +class FreeFoodModel { int? statusCode; Body? body; - IAmGoingModel({ + FreeFoodModel({ this.statusCode, this.body, }); - factory IAmGoingModel.fromJson(Map json) => IAmGoingModel( + factory FreeFoodModel.fromJson(Map json) => FreeFoodModel( statusCode: json["statusCode"], body: Body.fromJson(json["body"]), ); diff --git a/lib/core/providers/notifications_IAmGoing.dart b/lib/core/providers/notifications_freefood.dart similarity index 92% rename from lib/core/providers/notifications_IAmGoing.dart rename to lib/core/providers/notifications_freefood.dart index 9892c19ce..362034d47 100644 --- a/lib/core/providers/notifications_IAmGoing.dart +++ b/lib/core/providers/notifications_freefood.dart @@ -2,20 +2,20 @@ import 'dart:collection'; import 'package:campus_mobile_experimental/app_constants.dart'; import 'package:campus_mobile_experimental/core/models/notifications.dart'; -import 'package:campus_mobile_experimental/core/models/notifications_IAmGoing.dart'; +import 'package:campus_mobile_experimental/core/models/notifications_freefood.dart'; import 'package:campus_mobile_experimental/core/providers/messages.dart'; -import 'package:campus_mobile_experimental/core/services/notifications_IAmGoing.dart'; +import 'package:campus_mobile_experimental/core/services/notifications_freefood.dart'; import 'package:flutter/material.dart'; import 'package:hive/hive.dart'; -class IAmGoingProvider extends ChangeNotifier { - IAmGoingProvider() { +class FreeFoodDataProvider extends ChangeNotifier { + FreeFoodDataProvider() { ///DEFAULT STATES _isLoading = false; ///INITIALIZE SERVICES _freeFoodService = FreeFoodService(); - _freeFoodModel = IAmGoingModel(); + _freeFoodModel = FreeFoodModel(); ///INITIALIZE VALUES initializeValues(); @@ -33,7 +33,7 @@ class IAmGoingProvider extends ChangeNotifier { String? _error; ///MODELS - IAmGoingModel? _freeFoodModel; + FreeFoodModel? _freeFoodModel; late MessagesDataProvider _messageDataProvider; ///SERVICES @@ -51,15 +51,13 @@ class IAmGoingProvider extends ChangeNotifier { _registeredEvents!.remove(id); } - //parses event message topic to determine if it is an IAmGoing event void parseMessages() { // initializeValues(); List messages = _messageDataProvider.messages!; messages.forEach((m) async { if (m!.audience != null && m.audience!.topics != null && - (m.audience!.topics!.contains("freeFood") || - m.audience!.topics!.contains("campusInnovationEvents"))) { + m.audience!.topics!.contains("freeFood")) { fetchCount(m.messageId!); fetchMaxCount(m.messageId!); } @@ -191,11 +189,8 @@ class IAmGoingProvider extends ChangeNotifier { ///SIMPLE GETTERS String? get error => _error; - DateTime? get lastUpdated => _lastUpdated; - - IAmGoingModel? get freeFoodModel => _freeFoodModel; - + FreeFoodModel? get freeFoodModel => _freeFoodModel; List? get registeredEvents => _registeredEvents; bool isLoading(String? id) => id == _curId; diff --git a/lib/core/services/notifications_IAmGoing.dart b/lib/core/services/notifications_freefood.dart similarity index 94% rename from lib/core/services/notifications_IAmGoing.dart rename to lib/core/services/notifications_freefood.dart index 660a2b1e4..f589f228a 100644 --- a/lib/core/services/notifications_IAmGoing.dart +++ b/lib/core/services/notifications_freefood.dart @@ -1,5 +1,5 @@ import 'package:campus_mobile_experimental/app_networking.dart'; -import 'package:campus_mobile_experimental/core/models/notifications_IAmGoing.dart'; +import 'package:campus_mobile_experimental/core/models/notifications_freefood.dart'; class FreeFoodService { final String baseEndpoint = @@ -8,7 +8,7 @@ class FreeFoodService { bool _isLoading = false; DateTime? _lastUpdated; String? _error; - IAmGoingModel? _data; + FreeFoodModel? _data; final NetworkHelper _networkHelper = NetworkHelper(); final Map headers = { @@ -26,7 +26,7 @@ class FreeFoodService { baseEndpoint + 'events/' + id + '/rsvpCount', headers); /// parse data - final data = IAmGoingModelFromJson(_response); + final data = freeFoodModelFromJson(_response); _isLoading = false; _data = data; @@ -56,7 +56,7 @@ class FreeFoodService { var _response = await _networkHelper.authorizedFetch(_url, headers); /// parse data - final data = IAmGoingModelFromJson(_response); + final data = freeFoodModelFromJson(_response); _isLoading = false; _data = data; return true; @@ -125,7 +125,7 @@ class FreeFoodService { // getters String? get error => _error; - IAmGoingModel? get freeFoodModel => _data; + FreeFoodModel? get freeFoodModel => _data; bool get isLoading => _isLoading; DateTime? get lastUpdated => _lastUpdated; } diff --git a/lib/ui/notifications/notification_settings_view.dart b/lib/ui/notifications/notifications.dart similarity index 100% rename from lib/ui/notifications/notification_settings_view.dart rename to lib/ui/notifications/notifications.dart diff --git a/lib/ui/notifications/notifications_IAmGoing.dart b/lib/ui/notifications/notifications_freefood.dart similarity index 63% rename from lib/ui/notifications/notifications_IAmGoing.dart rename to lib/ui/notifications/notifications_freefood.dart index 023b7c638..c4db86880 100644 --- a/lib/ui/notifications/notifications_IAmGoing.dart +++ b/lib/ui/notifications/notifications_freefood.dart @@ -1,29 +1,27 @@ -import 'package:campus_mobile_experimental/core/providers/notifications_IAmGoing.dart'; +import 'package:campus_mobile_experimental/core/providers/notifications_freefood.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import '../../core/models/notifications.dart'; - -class IAmGoingNotification extends StatefulWidget { +class FreeFoodNotification extends StatefulWidget { /// required parameters - final MessageElement data; + final String? messageId; - const IAmGoingNotification({ + const FreeFoodNotification({ Key? key, - required this.data, + required this.messageId, }) : super(key: key); @override - _CheckBoxButtonState createState() => _CheckBoxButtonState(data); + _CheckBoxButtonState createState() => _CheckBoxButtonState(messageId); } -class _CheckBoxButtonState extends State { - _CheckBoxButtonState(data) { - this.data = data; +class _CheckBoxButtonState extends State { + _CheckBoxButtonState(messageId) { + this.messageId = messageId; } - late IAmGoingProvider _IAmGoingDataProvider; - late MessageElement data; + late FreeFoodDataProvider _freeFoodDataProvider; + String? messageId; bool _isLoading = false; bool _isGoing = false; @@ -34,9 +32,9 @@ class _CheckBoxButtonState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _IAmGoingDataProvider = Provider.of(context); - _isLoading = _IAmGoingDataProvider.isLoading(data.messageId); - _isGoing = _IAmGoingDataProvider.registeredEvents!.contains(data.messageId); + _freeFoodDataProvider = Provider.of(context); + _isLoading = _freeFoodDataProvider.isLoading(messageId); + _isGoing = _freeFoodDataProvider.registeredEvents!.contains(messageId); if (_isGoing) { _buttonColor = Colors.green; _borderColor = Colors.green; @@ -50,33 +48,22 @@ class _CheckBoxButtonState extends State { @override Widget build(BuildContext context) { - var isOverCount = _IAmGoingDataProvider.isOverCount(data.messageId); - String messageType = data.audience!.topics![0]; + var isOverCount = _freeFoodDataProvider.isOverCount(messageId); // print('messageId "' + messageId + '" isOverCount: ' + isOverCount.toString()); - var currCount = _IAmGoingDataProvider.count(data.messageId); - String countText; - if (messageType == "campusInnovationEvents") { - if (currCount == 1) { - countText = '$currCount participant is going'; - } else { - countText = '$currCount participants are going'; - } - } else { - // messageType == "freeFood" or anything else - if (currCount == 1) { - countText = '$currCount student is going'; - } else { - countText = '$currCount students are going'; - } - } + var currCount = _freeFoodDataProvider.count(messageId); + var countText = currCount == 1 + ? '$currCount student is going' + : '$currCount students are going'; return Container( - margin: EdgeInsets.only(left: 72.0), + margin: EdgeInsets.only(top: 10.0), child: Row( children: [ Container( + height: 25, + width: 150, child: AnimatedCrossFade( duration: Duration(milliseconds: 300), crossFadeState: isOverCount @@ -87,24 +74,12 @@ class _CheckBoxButtonState extends State { Text(countText, style: TextStyle(fontSize: 10, color: Colors.red)), Container( - margin: EdgeInsets.only(top: 4.0), - width: 200, + margin: EdgeInsets.only(top: 2.0), child: Row( children: [ - Padding( - padding: EdgeInsets.only(right: 4.0), - child: Icon(Icons.report, - color: Colors.grey, size: 10)), - Flexible( - child: Text(() { - if (messageType == "campusInnovationEvents") { - return "The event may not have enough space for all the participants"; - } else { - // messageType == "freeFood" or anything else - return "There may not be enough food"; - } - }(), style: TextStyle(fontSize: 9)), - ) + Icon(Icons.report, color: Colors.grey, size: 10), + Text("There may not be enough food", + style: TextStyle(fontSize: 9)) ], )), ], @@ -117,7 +92,7 @@ class _CheckBoxButtonState extends State { ), ), ), - _checkBoxButton(), + _checkBoxButton() ], mainAxisAlignment: MainAxisAlignment.spaceBetween, )); @@ -182,12 +157,12 @@ class _CheckBoxButtonState extends State { _buttonColor = Colors.white; _borderColor = Color(0xFF034161); _textColor = Color(0xFF034161); - _IAmGoingDataProvider.decrementCount(data.messageId!); + _freeFoodDataProvider.decrementCount(messageId!); } else { _buttonColor = Colors.green; _borderColor = Colors.green; _textColor = Colors.white; - _IAmGoingDataProvider.incrementCount(data.messageId!); + _freeFoodDataProvider.incrementCount(messageId!); } _isGoing = !_isGoing; }); diff --git a/lib/ui/notifications/notifications_list_view.dart b/lib/ui/notifications/notifications_list_view.dart index 4dae75065..12ef1c1e0 100644 --- a/lib/ui/notifications/notifications_list_view.dart +++ b/lib/ui/notifications/notifications_list_view.dart @@ -5,34 +5,15 @@ import 'package:campus_mobile_experimental/core/models/notifications.dart'; import 'package:campus_mobile_experimental/core/providers/bottom_nav.dart'; import 'package:campus_mobile_experimental/core/providers/map.dart'; import 'package:campus_mobile_experimental/core/providers/messages.dart'; -import 'package:campus_mobile_experimental/ui/notifications/notifications_IAmGoing.dart'; -import 'package:campus_mobile_experimental/ui/profile/notification_settings_view.dart'; +import 'package:campus_mobile_experimental/core/providers/notifications_freefood.dart'; +import 'package:campus_mobile_experimental/ui/notifications/notifications_freefood.dart'; import 'package:flutter/material.dart'; import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:provider/provider.dart'; import 'package:uni_links2/uni_links.dart'; import 'package:url_launcher/url_launcher.dart'; -bool hideListView = false; // debug -List eventTypesForIAmGoing = [ - "campusInnovationEvents", - "freeFood", - "testCampusInnovationEvents", - "testFreeFood", -]; // for the "I am Going" feature - -class NotificationsListView extends StatefulWidget { - @override - State createState() => _NotificationsListViewState(); -} - -class _NotificationsListViewState extends State { - @override - initState() { - super.initState(); - hideListView = true; - } - +class NotificationsListView extends StatelessWidget { @override Widget build(BuildContext context) { initUniLinks(context); @@ -128,6 +109,8 @@ class _NotificationsListViewState extends State { Widget _buildMessage(BuildContext context, int index) { MessageElement data = Provider.of(context).messages![index]!; + FreeFoodDataProvider freefoodProvider = + Provider.of(context); String? messageType; if (data.audience!.topics == null) { @@ -135,63 +118,61 @@ class _NotificationsListViewState extends State { } else { messageType = data.audience?.topics![0]; } - return ListView( - shrinkWrap: true, - physics: NeverScrollableScrollPhysics(), - children: [ - ListTile( - leading: Icon(chooseIcon(messageType!), - color: Theme.of(context).colorScheme.secondary, size: 30), - title: Column( - children: [ - Text( - data.message!.title!, - style: TextStyle(fontWeight: FontWeight.bold), - ), - Padding(padding: const EdgeInsets.all(3.5)) - ], - crossAxisAlignment: CrossAxisAlignment.start, + + return ListTile( + leading: Icon(_chooseIcon(messageType!), + color: Theme.of(context).colorScheme.secondary, size: 30), + title: Column( + children: [ + Text( + data.message!.title!, + style: TextStyle(fontWeight: FontWeight.bold), ), - subtitle: Column( - children: [ - Align( - alignment: Alignment.topLeft, - child: Linkify( - text: data.message!.message!, - onOpen: (link) async { - try { - await launch(link.url, forceSafariVC: true); - } catch (e) { - // an error occurred, do nothing - } - }, - options: LinkifyOptions(humanize: false), - style: TextStyle(fontSize: 12.5), - ), - ), - ], + Padding(padding: const EdgeInsets.all(3.5)) + ], + crossAxisAlignment: CrossAxisAlignment.start, + ), + subtitle: Column( + children: [ + Align( + alignment: Alignment.topLeft, + child: Linkify( + text: data.message!.message!, + onOpen: (link) async { + try { + await launch(link.url, forceSafariVC: true); + } catch (e) { + // an error occurred, do nothing + } + }, + options: LinkifyOptions(humanize: false), + style: TextStyle(fontSize: 12.5), + ), ), - trailing: Column(children: [ - Text(_readTimestamp(data.timestamp!), - style: TextStyle(fontSize: 10, color: Colors.grey)), - ])), - // check if the event type needs the "I am going" feature (e.g., "freeFood" events), - // if true, use IAmGoingNotification format - // if false, use regular notification format - needIAmGoingFeature(data.messageId, messageType, eventTypesForIAmGoing) - ? IAmGoingNotification(data: data) - : Container(), - ], - ); + freefoodProvider.isFreeFood(data.messageId) + ? FreeFoodNotification(messageId: data.messageId) + : Container(), + ], + ), + trailing: Column(children: [ + Text(_readTimestamp(data.timestamp!), + style: TextStyle(fontSize: 10, color: Colors.grey)), + ])); } - // this function checks whether the current notification's messageType requires the "I am Going" feature - // this currently only apply to "campusInnovationEvents" and "freeFood" notifications - // a list of event types for "I am Going" feature is defined the eventTypesForIAmGoing variable - bool needIAmGoingFeature( - String? messageId, String? messageType, List eventTypes) { - // print('messageType is: $messageType'); - return eventTypes.contains(messageType); + IconData _chooseIcon(String messageType) { + if (messageType == "studentAnnouncements" || + messageType == "testStudentAnnouncements") { + return Icons.school_outlined; + } else if (messageType == "freeFood") { + return Icons.restaurant_outlined; + } else if (messageType == "campusAnnouncements" || + messageType == "testCampusAnnouncements") { + return Icons.campaign_outlined; + } else if (messageType == "DM") { + return Icons.info_outline; + } + return Icons.info_outline; } String _readTimestamp(int timestamp) { diff --git a/lib/ui/profile/notification_settings_view.dart b/lib/ui/profile/notifications.dart similarity index 79% rename from lib/ui/profile/notification_settings_view.dart rename to lib/ui/profile/notifications.dart index b29b983dc..e102843e0 100644 --- a/lib/ui/profile/notification_settings_view.dart +++ b/lib/ui/profile/notifications.dart @@ -25,7 +25,7 @@ class NotificationsSettingsView extends StatelessWidget { for (String? topic in topicsAvailable) { list.add(ListTile( key: Key(topic!), - leading: Icon(chooseIcon(topic), + leading: Icon(_chooseIcons(topic), color: Theme.of(context).colorScheme.secondary, size: 30), title: Text(getTopicName(context, topic)!), trailing: Switch( @@ -43,6 +43,21 @@ class NotificationsSettingsView extends StatelessWidget { return list; } + IconData _chooseIcons(String messageType) { + if (messageType == "studentAnnouncements" || + messageType == "testStudentAnnouncements") { + return Icons.school_outlined; + } else if (messageType == "freeFood" || messageType == "testFreeFood") { + return Icons.restaurant_outlined; + } else if (messageType == "campusAnnouncements" || + messageType == "testCampusAnnouncements") { + return Icons.campaign_outlined; + } else if (messageType == "DM") { + return Icons.info_outline; + } + return Icons.info_outline; + } + List getTopics(BuildContext context) { UserDataProvider _userDataProvider = Provider.of(context); PushNotificationDataProvider _pushNotificationDataProvider = @@ -64,21 +79,3 @@ class NotificationsSettingsView extends StatelessWidget { .getTopicName(topicId); } } - -IconData chooseIcon(String messageType) { - if (messageType == "studentAnnouncements" || - messageType == "testStudentAnnouncements") { - return Icons.school_outlined; - } else if (messageType == "freeFood" || - messageType == "testFreeFood") { - return Icons.restaurant_outlined; - } else if (messageType == "campusAnnouncements" || - messageType == "testCampusAnnouncements") { - return Icons.campaign_outlined; - } else if (messageType == "campusInnovationEvents" || - messageType == "testCampusInnovationEvents") { - return Icons.event_outlined; - } else { // if messageType == "DM" or anything else - return Icons.info_outline; - } -} \ No newline at end of file