Skip to content

Commit

Permalink
✨ Added reminder notification and hidden graph when there aren't columns
Browse files Browse the repository at this point in the history
  • Loading branch information
GiorgioBertolotti committed Oct 14, 2019
1 parent 3ce0375 commit e3946c4
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pro_time/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zem.protime.pro_time">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="ProTime"
Expand All @@ -19,5 +21,11 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
</application>
</manifest>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 62 additions & 2 deletions pro_time/lib/ui/project_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:math';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:hive/hive.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:pro_time/main.dart';
import 'package:pro_time/model/project.dart';
import 'package:pro_time/resources/application_state.dart';
import 'package:pro_time/resources/controls.dart';
import 'package:pro_time/ui/home.dart';
import 'package:provider/provider.dart';

class ProjectPage extends StatefulWidget {
Expand All @@ -34,6 +36,8 @@ class _ProjectPageState extends State<ProjectPage>
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
StreamController<BarTouchResponse> barTouchedResultStreamController;
int touchedIndex;
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

@override
void initState() {
Expand All @@ -59,7 +63,13 @@ class _ProjectPageState extends State<ProjectPage>
}
});
});

var initializationSettingsAndroid =
AndroidInitializationSettings('ic_notification');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
super.initState();
}

Expand Down Expand Up @@ -211,7 +221,9 @@ class _ProjectPageState extends State<ProjectPage>
],
),
),
(_project.activities != null && _project.activities.length > 0)
(_project.activities != null &&
_project.activities.length > 0 &&
_isThereAnyHour())
? _buildDaysChart()
: Container(),
(_project.activities != null && _project.activities.length > 0)
Expand Down Expand Up @@ -241,6 +253,45 @@ class _ProjectPageState extends State<ProjectPage>
);
}

Future onSelectNotification(String id) async {
for (Project project
in Hive.box('projects').values.toList().cast<Project>()) {
if (project.id == id) {
await Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
break;
}
}
}

_showNotification(Project project) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'protime',
'ProTime',
'This channel is used by ProTime to send timer reminders.',
importance: Importance.Max,
priority: Priority.High,
ticker: 'ticker',
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
0,
'Tracking reminder',
'Don\'t forget to stop your tracking of ' + project.name + "!",
DateTime.now().add(Duration(
minutes: (project.getAverageTime().inMinutes * 1.3).toInt())),
platformChannelSpecifics,
payload: project.id);
}

_cancelNotifications() async {
await flutterLocalNotificationsPlugin.cancelAll();
}

_startTimer() {
ApplicationState appState = Provider.of<ApplicationState>(context);
setState(() {
Expand All @@ -251,6 +302,7 @@ class _ProjectPageState extends State<ProjectPage>
_startBlink();
_updateProject();
});
_showNotification(_project);
}

_pauseTimer() {
Expand All @@ -269,6 +321,7 @@ class _ProjectPageState extends State<ProjectPage>
_stopBlink();
_updateProject();
});
_cancelNotifications();
}

_startBlink() {
Expand Down Expand Up @@ -462,6 +515,13 @@ class _ProjectPageState extends State<ProjectPage>
}
});

bool _isThereAnyHour() {
return List.generate(7, (i) {
return _getHoursForDay(i);
}).reduce(max) !=
0.0;
}

double _getHoursForDay(int dayIndex) {
int toReturn = 0;
for (Activity activity in _project.activities) {
Expand Down
9 changes: 8 additions & 1 deletion pro_time/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.3"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.4"
flutter_picker:
dependency: "direct main"
description:
Expand Down Expand Up @@ -578,4 +585,4 @@ packages:
version: "2.2.0"
sdks:
dart: ">=2.4.0 <3.0.0"
flutter: ">=0.1.4 <2.0.0"
flutter: ">=1.5.0 <2.0.0"
1 change: 1 addition & 0 deletions pro_time/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
auto_size_text: ^2.1.0
flutter_picker: ^1.0.15
fl_chart: ^0.3.3
flutter_local_notifications: ^0.8.4

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit e3946c4

Please sign in to comment.