Skip to content

Commit

Permalink
Revert "Merge pull request #1962 from UCSD/populate-freefood"
Browse files Browse the repository at this point in the history
This reverts commit 82a0909, reversing
changes made to add4de5.
  • Loading branch information
c3bryant committed Mar 5, 2024
1 parent 00e3d38 commit a9dc674
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 176 deletions.
6 changes: 3 additions & 3 deletions lib/app_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -279,9 +279,9 @@ List<SingleChildWidget> dependentServices = [
return messageDataProvider;
},
),
ChangeNotifierProxyProvider<MessagesDataProvider, IAmGoingProvider>(
ChangeNotifierProxyProvider<MessagesDataProvider, FreeFoodDataProvider>(
create: (_) {
var freefoodDataProvider = IAmGoingProvider();
var freefoodDataProvider = FreeFoodDataProvider();
freefoodDataProvider.loadRegisteredEvents();
return freefoodDataProvider;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> json) => IAmGoingModel(
factory FreeFoodModel.fromJson(Map<String, dynamic> json) => FreeFoodModel(
statusCode: json["statusCode"],
body: Body.fromJson(json["body"]),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -33,7 +33,7 @@ class IAmGoingProvider extends ChangeNotifier {
String? _error;

///MODELS
IAmGoingModel? _freeFoodModel;
FreeFoodModel? _freeFoodModel;
late MessagesDataProvider _messageDataProvider;

///SERVICES
Expand All @@ -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<MessageElement?> 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!);
}
Expand Down Expand Up @@ -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<String>? get registeredEvents => _registeredEvents;

bool isLoading(String? id) => id == _curId;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -8,7 +8,7 @@ class FreeFoodService {
bool _isLoading = false;
DateTime? _lastUpdated;
String? _error;
IAmGoingModel? _data;
FreeFoodModel? _data;

final NetworkHelper _networkHelper = NetworkHelper();
final Map<String, String> headers = {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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<IAmGoingNotification> {
_CheckBoxButtonState(data) {
this.data = data;
class _CheckBoxButtonState extends State<FreeFoodNotification> {
_CheckBoxButtonState(messageId) {
this.messageId = messageId;
}

late IAmGoingProvider _IAmGoingDataProvider;
late MessageElement data;
late FreeFoodDataProvider _freeFoodDataProvider;
String? messageId;

bool _isLoading = false;
bool _isGoing = false;
Expand All @@ -34,9 +32,9 @@ class _CheckBoxButtonState extends State<IAmGoingNotification> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
_IAmGoingDataProvider = Provider.of<IAmGoingProvider>(context);
_isLoading = _IAmGoingDataProvider.isLoading(data.messageId);
_isGoing = _IAmGoingDataProvider.registeredEvents!.contains(data.messageId);
_freeFoodDataProvider = Provider.of<FreeFoodDataProvider>(context);
_isLoading = _freeFoodDataProvider.isLoading(messageId);
_isGoing = _freeFoodDataProvider.registeredEvents!.contains(messageId);
if (_isGoing) {
_buttonColor = Colors.green;
_borderColor = Colors.green;
Expand All @@ -50,33 +48,22 @@ class _CheckBoxButtonState extends State<IAmGoingNotification> {

@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: <Widget>[
Container(
height: 25,
width: 150,
child: AnimatedCrossFade(
duration: Duration(milliseconds: 300),
crossFadeState: isOverCount
Expand All @@ -87,24 +74,12 @@ class _CheckBoxButtonState extends State<IAmGoingNotification> {
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: <Widget>[
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))
],
)),
],
Expand All @@ -117,7 +92,7 @@ class _CheckBoxButtonState extends State<IAmGoingNotification> {
),
),
),
_checkBoxButton(),
_checkBoxButton()
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
));
Expand Down Expand Up @@ -182,12 +157,12 @@ class _CheckBoxButtonState extends State<IAmGoingNotification> {
_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;
});
Expand Down
Loading

0 comments on commit a9dc674

Please sign in to comment.