Skip to content

Commit

Permalink
[App] add EventPage; [Event] move subTitle calc to Event; [EventPage]…
Browse files Browse the repository at this point in the history
… implemented;
  • Loading branch information
tastelessjolt committed Dec 19, 2018
1 parent a48ca6e commit b681dd5
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 58 deletions.
36 changes: 30 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:InstiApp/src/routes/eventpage.dart';
import 'package:InstiApp/src/routes/feedpage.dart';
import 'package:InstiApp/src/routes/trainingblogpage.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -39,14 +40,37 @@ class MyAppState extends State<MyApp> {
fontFamily: "SourceSansPro",
primarySwatch: Colors.deepPurple,
),
routes: {
"/": (_) => LoginPage(),
"/mess": (_) => MessPage(),
"/placeblog": (_) => PlacementBlogPage(),
"/trainblog": (_) => TrainingBlogPage(),
"/feed": (_) => FeedPage(),
// routes: {
// "/": (_) => LoginPage(),
// "/mess": (_) => MessPage(),
// "/placeblog": (_) => PlacementBlogPage(),
// "/trainblog": (_) => TrainingBlogPage(),
// "/feed": (_) => FeedPage(),
// "/event": (_) => EventPage(),
// },
onGenerateRoute: (RouteSettings settings) {
if (settings.name.startsWith("/event/") ) {
return _buildRoute(settings, EventPage(_bloc.getEvent(settings.name.split("/event/")[1])));
}
else {
switch (settings.name) {
case "/": return _buildRoute(settings, LoginPage());
case "/mess": return _buildRoute(settings, MessPage());
case "/placeblog": return _buildRoute(settings, PlacementBlogPage());
case "/trainblog": return _buildRoute(settings, TrainingBlogPage());
case "/feed": return _buildRoute(settings, FeedPage());
}
}
return _buildRoute(settings, MessPage());
},
),
);
}

MaterialPageRoute _buildRoute(RouteSettings settings, Widget builder){
return new MaterialPageRoute(
settings: settings,
builder: (BuildContext context) => builder,
);
}
}
41 changes: 41 additions & 0 deletions lib/src/api/model/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:InstiApp/src/api/model/body.dart';
import 'package:InstiApp/src/api/model/user.dart';
import 'package:InstiApp/src/api/model/venue.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';
import 'package:date_format/date_format.dart';

part 'event.jser.dart';

Expand Down Expand Up @@ -55,6 +56,46 @@ class Event {
int eventUserUes;

bool eventBigImage = false;

String getSubTitle() {
String subtitle = "";

DateTime startTime = DateTime.parse(eventStartTime);
DateTime endTime = DateTime.parse(eventEndTime);
DateTime timeNow = DateTime.now();
bool eventStarted = timeNow.compareTo(startTime) > 0;
bool eventEnded = timeNow.compareTo(endTime) > 0;

if (eventEnded)
subtitle += "Ended | ";
else if (eventStarted) {
int difference =
endTime.millisecondsSinceEpoch - timeNow.millisecondsSinceEpoch;
int minutes = difference ~/ (60 * 1000) % 60;
int hours = difference ~/ (60 * 60 * 1000) % 24;
int days = difference ~/ (24 * 60 * 60 * 1000);
String timeDiff = "";
if (days > 0) timeDiff += "${days}D ";
if (hours > 0) timeDiff += "${hours}H ";

timeDiff += "${minutes}M";

subtitle += "Ends in $timeDiff | ";
}

if (startTime != null) {
subtitle += formatDate(startTime.toLocal(), [dd, " ", M, " | ", HH, ":", nn]);
}
String eventVenueName = "";
for (var venue in eventVenues) {
eventVenueName += ", ${venue.venueShortName}";
}
if (eventVenueName != "") {
subtitle += " | ${eventVenueName.substring(2)}";
}

return subtitle;
}
}

@GenSerializer()
Expand Down
26 changes: 26 additions & 0 deletions lib/src/blocs/ia_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,38 @@ class InstiAppBloc {
_eventsSubject.add(UnmodifiableListView(_events));
}

Event getEvent(String uuid) {
return _events?.firstWhere((event) => event.eventID == uuid);
}

void updateSession(Session sess) {
currSession = sess;
_sessionSubject.add(sess);
_persistSession(sess);
}

Future<void> updateUesEvent(Event e, int ues) async {
try {
print("updating Ues from ${e.eventUserUes} to $ues");
await client.updateUserEventStatus(getSessionIdHeader(), e.eventID, ues);
if (e.eventUserUes == 2) {
e.eventGoingCount--;
}
if (e.eventUserUes == 1) {
e.eventInterestedCount--;
}
if (ues == 1) {
e.eventInterestedCount++;
} else if (ues == 2) {
e.eventGoingCount++;
}
e.eventUserUes = ues;
print("updated Ues from ${e.eventUserUes} to $ues");
} catch (ex) {
print(ex);
}
}

void _persistSession(Session sess) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString("session", standardSerializers.encode(sess));
Expand Down
138 changes: 138 additions & 0 deletions lib/src/routes/eventpage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import 'package:InstiApp/src/api/model/event.dart';
import 'package:InstiApp/src/bloc_provider.dart';
import 'package:InstiApp/src/blocs/ia_bloc.dart';
import 'package:InstiApp/src/drawer.dart';
import 'package:flutter/material.dart';
import 'package:outline_material_icons/outline_material_icons.dart';

class EventPage extends StatefulWidget {
final Event event;

EventPage(this.event);

@override
_EventPageState createState() => _EventPageState();
}

class _EventPageState extends State<EventPage> {
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
int loadingUes = 0;

@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
var bloc = BlocProvider.of(context).bloc;

return Scaffold(
key: _scaffoldKey,
drawer: DrawerOnly(),
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
leading: Container(
decoration: ShapeDecoration(
shape: BeveledRectangleBorder(
borderRadius:
BorderRadius.only(bottomRight: Radius.circular(15))),
color: theme.accentColor),
child: IconButton(
icon: Icon(
OMIcons.menu,
color: Colors.white,
),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
},
),
),
expandedHeight: 300,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Container(
width: MediaQuery.of(context).size.width * 0.65,
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
color: Color.fromRGBO(0, 0, 0, 0.2),
child: Text(
widget.event?.eventName,
)),
background: Image.network(
widget.event?.eventImageURL ??
widget.event?.eventBodies[0].imageUrl,
fit: BoxFit.fitWidth),
),
),
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ButtonBar(
mainAxisSize: MainAxisSize.max,
alignment: MainAxisAlignment.center,
children: <Widget>[
buildUserStatusButton("Going", 2, theme, bloc),
buildUserStatusButton("Interested", 1, theme, bloc),
],
),
SizedBox(height: 16.0,),

],
),
)
],
),
);
}

RaisedButton buildUserStatusButton(String name, int id, ThemeData theme, InstiAppBloc bloc) {
return RaisedButton(
color: widget.event?.eventUserUes == id ? theme.accentColor : Colors.white,
textColor: widget.event?.eventUserUes == id ? Colors.white : null,
shape: RoundedRectangleBorder(
side: BorderSide(
color: theme.accentColor,
),
borderRadius: BorderRadius.all(Radius.circular(4))),
child: Row(children: () {
var rowChildren = <Widget>[
Text(name),
SizedBox(
width: 8.0,
),
Text("${id == 1 ? widget.event?.eventInterestedCount : widget.event?.eventGoingCount}"),
];
if (loadingUes == id) {
rowChildren.insertAll(0, [
SizedBox(
height: 18,
width: 18,
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
widget.event?.eventUserUes == id
? Colors.white
: theme.accentColor),
strokeWidth: 2,
)),
SizedBox(
width: 8.0,
)
]);
}
return rowChildren;
}()),
onPressed: () async {
setState(() {
loadingUes = id;
});
await bloc.updateUesEvent(
widget.event, widget.event.eventUserUes == id ? 0 : id);
setState(() {
loadingUes = 0;
// event has changes
});
},
);
}
}
70 changes: 18 additions & 52 deletions lib/src/routes/feedpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,64 +87,24 @@ class _FeedPageState extends State<FeedPage> {
);
}

String _formSubTitle(Event event) {
String subtitle = "";

DateTime startTime = DateTime.parse(event.eventStartTime);
DateTime endTime = DateTime.parse(event.eventEndTime);
DateTime timeNow = DateTime.now();
bool eventStarted = timeNow.compareTo(startTime) > 0;
bool eventEnded = timeNow.compareTo(endTime) > 0;

if (eventEnded)
subtitle += "Ended | ";
else if (eventStarted) {
int difference =
endTime.millisecondsSinceEpoch - timeNow.millisecondsSinceEpoch;
int minutes = difference ~/ (60 * 1000) % 60;
int hours = difference ~/ (60 * 60 * 1000) % 24;
int days = difference ~/ (24 * 60 * 60 * 1000);
String timeDiff = "";
if (days > 0) timeDiff += "${days}D ";
if (hours > 0) timeDiff += "${hours}H ";

timeDiff += "${minutes}M";

subtitle += "Ends in $timeDiff | ";
}

if (startTime != null) {
// TODO: Time Date Formatting
subtitle += startTime.toIso8601String();
// SimpleDateFormat simpleDateFormatDate = new SimpleDateFormat("dd MMM");
// SimpleDateFormat simpleDateFormatTime = new SimpleDateFormat("HH:mm");

// subtitle += simpleDateFormatDate.format(DateTime) + " | " + simpleDateFormatTime.format(DateTime);
}
String eventVenueName = "";
for (var venue in event.eventVenues) {
eventVenueName += ", ${venue.venueShortName}";
}
if (eventVenueName != "") {
subtitle += " | ${eventVenueName.substring(2)}";
}

return subtitle;
}

Widget _buildEvent(Event event) {
var theme = Theme.of(context);

if (event.eventBigImage ?? false) {
return InkWell(
onTap: () {},
onTap: () {
_openEventPage(event);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Image.network(
event.eventImageURL ?? event.eventBodies[0].imageUrl,
fit: BoxFit.cover,
Ink.image(
child: Container(),
image: NetworkImage(
event.eventImageURL ?? event.eventBodies[0].imageUrl,
),
height: 200,
fit: BoxFit.cover,
),
ListTile(
contentPadding:
Expand All @@ -154,7 +114,7 @@ class _FeedPageState extends State<FeedPage> {
style: theme.textTheme.title,
),
enabled: true,
subtitle: Text(_formSubTitle(event)),
subtitle: Text(event.getSubTitle()),
)
],
),
Expand All @@ -171,9 +131,15 @@ class _FeedPageState extends State<FeedPage> {
backgroundImage: NetworkImage(
event.eventImageURL ?? event.eventBodies[0].imageUrl),
),
subtitle: Text(_formSubTitle(event)),
onTap: () {},
subtitle: Text(event.getSubTitle()),
onTap: () {
_openEventPage(event);
},
);
}
}

_openEventPage(Event event) {
Navigator.of(context).pushNamed("/event/${event.eventID}");
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
flutter_html: ^0.8.2
markdown: ^2.0.2
shared_preferences: ^0.4.3
date_format: ^1.0.5

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit b681dd5

Please sign in to comment.