Skip to content

Commit

Permalink
[App] add NotificationsPage; add notifs to bloc and cache; fix Camera…
Browse files Browse the repository at this point in the history
…, Gallery perm on iOS; fix Navigator from `MyApp`; [NavDrawer] add notif indicator; [BlogPage, ExplorePage] search button/bar moved to top; [MessPage] fix no messmenu bug; [UserPage] not show n/a while guest; [LoginPage] fix notch overlay; fix brightness compare
  • Loading branch information
tastelessjolt committed Jan 28, 2019
1 parent bde563b commit e951d89
Show file tree
Hide file tree
Showing 23 changed files with 989 additions and 346 deletions.
10 changes: 10 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ allprojects {
google()
jcenter()
}
// subprojects {
// project.configurations.all {
// resolutionStrategy.eachDependency { details ->
// if (details.requested.group == 'com.android.support'
// && !details.requested.name.contains('multidex') ) {
// details.useVersion "27.1."
// }
// }
// }
// }
}

rootProject.buildDir = '../build'
Expand Down
2 changes: 1 addition & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../.symlinks/flutter/ios/Flutter.framework",
"${PODS_ROOT}/../.symlinks/flutter/ios-release/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
Expand Down
6 changes: 6 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@
<string></string>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>To upload photo from the gallery</string>
<key>NSCameraUsageDescription</key>
<string>To upload photo from the camera</string>
<key>NSMicrophoneUsageDescription</key>
<string></string>
</dict>
</plist>
16 changes: 10 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:InstiApp/src/routes/feedpage.dart';
import 'package:InstiApp/src/routes/mappage.dart';
import 'package:InstiApp/src/routes/newcomplaintpage.dart';
import 'package:InstiApp/src/routes/newspage.dart';
import 'package:InstiApp/src/routes/notificationspage.dart';
import 'package:InstiApp/src/routes/putentitypage.dart';
import 'package:InstiApp/src/routes/quicklinkspage.dart';
import 'package:InstiApp/src/routes/settingspage.dart';
Expand Down Expand Up @@ -60,6 +61,8 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
new FlutterLocalNotificationsPlugin();

GlobalKey<NavigatorState> _navigatorKey = GlobalKey<NavigatorState>();

void setTheme(VoidCallback a) {
setState(a);
}
Expand Down Expand Up @@ -93,7 +96,8 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
systemNavigationBarIconBrightness: Brightness.values[1 -
ThemeData.estimateBrightnessForColor(widget.bloc.primaryColor).index],
statusBarColor: Colors.transparent, //or set color with: Color(0xFF0000FF)
statusBarIconBrightness: Brightness.values[1 - widget.bloc.brightness.toBrightness().index],
statusBarIconBrightness:
Brightness.values[1 - widget.bloc.brightness.toBrightness().index],
));

return BlocProvider(
Expand Down Expand Up @@ -219,6 +223,8 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
return _buildRoute(settings, MapPage());
case "/settings":
return _buildRoute(settings, SettingsPage());
case "/notifications":
return _buildRoute(settings, NotificationsPage());
}
}
return _buildRoute(settings, MessPage());
Expand Down Expand Up @@ -349,7 +355,7 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {

Future navigateFromNotification(RichNotification fromMap) async {
// TODO: Navigate to correct page
// Navigator.of(context).push(route)
// _navigatorKey.currentState.push(route)
var page = {
"blogentry": fromMap.notificationExtra?.contains("/trainingblog") ?? false
? "/trainblog"
Expand All @@ -362,9 +368,7 @@ class MyAppState extends State<MyApp> with WidgetsBindingObserver {
debugPrint(fromMap.toString());
var routeName =
"$page${fromMap.notificationType != "blogentry" ? fromMap.notificationID ?? "" : ""}";
print(Navigator.of(context));
var t = await Navigator.of(context).push(
new MaterialPageRoute(builder: (context) => new TrainingBlogPage()));
print(t);
print(_navigatorKey.currentState);
_navigatorKey.currentState.pushNamed(routeName);
}
}
3 changes: 3 additions & 0 deletions lib/src/api/apiclient.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class InstiAppApi extends _$InstiAppApiClient implements ApiClient {
@GetReq(path: "/notifications/read/:notificationID")
Future<void> markNotificationRead(@Header("Cookie") String sessionID, @PathParam() String notificationID);

@GetReq(path: "/notifications/read")
Future<void> markAllNotificationsRead(@Header("Cookie") String sessionID);

@GetReq(path: "/logout")
Future<void> logout(@Header("Cookie") String sessionID);

Expand Down
8 changes: 8 additions & 0 deletions lib/src/api/apiclient.jretro.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 63 additions & 1 deletion lib/src/api/model/notification.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import 'package:InstiApp/src/api/model/event.dart';
import 'package:InstiApp/src/api/model/post.dart';
import 'package:InstiApp/src/api/model/serializers.dart';
import 'package:jaguar_serializer/jaguar_serializer.dart';

part 'notification.jser.dart';

final String TYPE_EVENT = "event";
final String TYPE_NEWSENTRY = "newsentry";
final String TYPE_BLOG = "blogentry";

class Notification {
@Alias("id")
int notificationId;
Expand All @@ -17,7 +24,62 @@ class Notification {

@Alias("actor")
Object notificationActor;

String getTitle() {
if (isEvent) {
return getEvent().eventName;
} else if (isNews) {
return getNews().title;
} else if (isBlogPost) {
return getBlogPost().title;
}
return "Notification";
}

String getSubtitle() {
return notificationVerb;
}

String getAvatarUrl() {
if (isEvent) {
var ev = getEvent();
return ev.eventImageURL ?? ev.eventBodies[0].bodyImageURL;
} else if (isNews) {
return getNews().body.bodyImageURL;
}
return null;
}

bool get isEvent => notificationActorType.contains(TYPE_EVENT);

bool get isNews => notificationActorType.contains(TYPE_NEWSENTRY);

bool get isBlogPost => notificationActorType.contains(TYPE_BLOG);

Event getEvent() {
return standardSerializers.oneFrom<Event>(notificationActor);
}

NewsArticle getNews() {
return standardSerializers.oneFrom<NewsArticle>(notificationActor);
}

Post getBlogPost() {
return standardSerializers.oneFrom<Post>(notificationActor);
}

String getID() {
if (isEvent) {
return getEvent().eventID;
} else if (isNews) {
return getNews().postID;
} else if (isBlogPost) {
return getBlogPost().postID;
}
return "";
}
}

@GenSerializer()
class NotificationSerializer extends Serializer<Notification> with _$NotificationSerializer {}
class NotificationSerializer extends Serializer<Notification>
with _$NotificationSerializer {}
3 changes: 3 additions & 0 deletions lib/src/api/model/notification.jser.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/src/api/model/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class NewsArticle extends Post {
@GenSerializer()
class NewsArticleSerializer extends Serializer<NewsArticle> with _$NewsArticleSerializer {}

@GenSerializer()
class PostSerializer extends Serializer<Post> with _$PostSerializer {}

@GenSerializer()
class PlacementBlogPostSerializer extends Serializer<PlacementBlogPost> with _$PlacementBlogPostSerializer {}

Expand Down
26 changes: 26 additions & 0 deletions lib/src/api/model/post.jser.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/api/model/serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ JsonRepo standardSerializers = JsonRepo(serializers: [
DateTimeSerializer(),

// Blog
PostSerializer(),
PlacementBlogPostSerializer(),
TrainingBlogPostSerializer(),

Expand Down
2 changes: 2 additions & 0 deletions lib/src/blocs/drawer_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class DrawerBloc {
String currentRoute;
int _highlightPageIndex;

bool reloadNotifications = true;

DrawerBloc(this.currentRoute, {int highlightPageIndexVal = 0}) {
setPageIndex(highlightPageIndexVal);
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/blocs/explore_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ExploreBloc {
}
}

Future<void> refresh() async {
Future refresh() async {
if ((query ?? "") == "") {
if (allBodies?.isEmpty ?? true) {
allBodies = await bloc.client.getAllBodies(bloc.getSessionIdHeader());
Expand All @@ -55,6 +55,5 @@ class ExploreBloc {
} else {
_push(await bloc.client.search(bloc.getSessionIdHeader(), query));
}
return Future.delayed(Duration(milliseconds: 300));
}
}
44 changes: 44 additions & 0 deletions lib/src/blocs/ia_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:rxdart/rxdart.dart';
import 'package:http/io_client.dart';
import 'package:jaguar_retrofit/jaguar_retrofit.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:InstiApp/src/api/model/notification.dart' as ntf;

/// Describes the contrast needs of a color.
class AppBrightness {
Expand Down Expand Up @@ -58,6 +59,8 @@ class InstiAppBloc {
static String eventStorageID = "events";
// Mess StorageID
static String messStorageID = "mess";
// Notifications StorageID
static String notificationsStorageID = "notifications";

// FCM handle
final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
Expand All @@ -72,6 +75,11 @@ class InstiAppBloc {
Stream<UnmodifiableListView<Event>> get events => _eventsSubject.stream;
final _eventsSubject = BehaviorSubject<UnmodifiableListView<Event>>();

Stream<UnmodifiableListView<ntf.Notification>> get notifications =>
_notificationsSubject.stream;
final _notificationsSubject =
BehaviorSubject<UnmodifiableListView<ntf.Notification>>();

// Sub Blocs
PostBloc placementBloc;
PostBloc trainingBloc;
Expand All @@ -85,6 +93,7 @@ class InstiAppBloc {
Session currSession;
var _hostels = <Hostel>[];
var _events = <Event>[];
var _notifications = <ntf.Notification>[];

// api functions
final client = InstiAppApi();
Expand Down Expand Up @@ -195,6 +204,31 @@ class InstiAppBloc {
_eventsSubject.add(UnmodifiableListView(_events));
}

// Notifications bloc
Future<void> updateNotifications() async {
var notifs = await client.getNotifications(getSessionIdHeader());
_notifications = notifs;
_notificationsSubject.add(UnmodifiableListView(_notifications));
}

Future clearAllNotifications() async {
await client.markAllNotificationsRead(getSessionIdHeader());
_notifications = [];
_notificationsSubject.add(UnmodifiableListView(_notifications));
}

Future clearNotification(ntf.Notification notification) async {
await client.markNotificationRead(
getSessionIdHeader(), "${notification.notificationId}");
var idx = _notifications
.indexWhere((n) => n.notificationId == notification.notificationId);
print(idx);
if (idx != -1) {
_notifications.removeAt(idx);
_notificationsSubject.add(UnmodifiableListView(_notifications));
}
}

// Section
// Navigator helper
Future<Event> getEvent(String uuid) async {
Expand Down Expand Up @@ -343,6 +377,10 @@ class InstiAppBloc {
if (_events?.isNotEmpty ?? false) {
prefs.setString(eventStorageID, standardSerializers.encode(_events));
}
if (_notifications?.isNotEmpty ?? false) {
prefs.setString(
notificationsStorageID, standardSerializers.encode(_notifications));
}

exploreBloc?.saveToCache(sharedPrefs: prefs);
complaintsBloc?.saveToCache(sharedPrefs: prefs);
Expand All @@ -366,6 +404,12 @@ class InstiAppBloc {
_eventsSubject.add(UnmodifiableListView(_events));
}

if (prefs.getKeys().contains(notificationsStorageID)) {
_notifications = standardSerializers.decodeList<ntf.Notification>(
prefs.getString(notificationsStorageID));
_notificationsSubject.add(UnmodifiableListView(_notifications));
}

exploreBloc?.restoreFromCache(sharedPrefs: prefs);
complaintsBloc?.restoreFromCache(sharedPrefs: prefs);
calendarBloc?.restoreFromCache(sharedPrefs: prefs);
Expand Down
Loading

0 comments on commit e951d89

Please sign in to comment.