Skip to content

Commit 4236f03

Browse files
authored
Merge pull request #6 from Codebugged-Research/feature/reminder
Feature/reminder
2 parents 6663539 + 8020af0 commit 4236f03

27 files changed

+391
-85
lines changed

android/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ GeneratedPluginRegistrant.java
88

99
# Remember to never publicly share your keystore.
1010
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11-
key.properties

android/app/build.gradle

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ apply plugin: 'kotlin-android'
2626
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2727
apply plugin: 'com.google.gms.google-services'
2828

29+
def keystoreProperties = new Properties()
30+
def keystorePropertiesFile = rootProject.file('key.properties')
31+
if (keystorePropertiesFile.exists()) {
32+
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
33+
}
34+
2935
android {
3036
compileSdkVersion 30
3137

@@ -43,13 +49,28 @@ android {
4349
multiDexEnabled true
4450
}
4551

46-
buildTypes {
47-
release {
48-
// TODO: Add your own signing config for the release build.
49-
// Signing with the debug keys for now, so `flutter run --release` works.
50-
signingConfig signingConfigs.debug
51-
}
52-
}
52+
// buildTypes {
53+
// release {
54+
// // TODO: Add your own signing config for the release build.
55+
// // Signing with the debug keys for now, so `flutter run --release` works.
56+
// signingConfig signingConfigs.debug
57+
// }
58+
// }
59+
60+
signingConfigs {
61+
release {
62+
keyAlias keystoreProperties['keyAlias']
63+
keyPassword keystoreProperties['keyPassword']
64+
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
65+
storePassword keystoreProperties['storePassword']
66+
}
67+
}
68+
buildTypes {
69+
release {
70+
signingConfig signingConfigs.release
71+
}
72+
}
73+
5374
}
5475

5576
flutter {

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
99
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
1010
<application
11-
android:label="propview"
11+
android:label="PropView"
1212
android:usesCleartextTraffic="true"
1313
android:icon="@mipmap/ic_launcher">
1414
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
Loading
Loading
Loading
Loading
Loading

android/key.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
storePassword=$PropDial235#
2+
keyPassword=$PropDial235#
3+
keyAlias=upload
4+
storeFile=../upload-keystore.jks

android/upload-keystore.jks

2.56 KB
Binary file not shown.

lib/main.dart

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,75 @@ import 'package:propview/services/reminderService.dart';
99
import 'package:propview/utils/theme.dart';
1010
import 'package:propview/views/splashScreen.dart';
1111

12+
ReminderService reminderService;
13+
1214
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
15+
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
16+
FlutterLocalNotificationsPlugin();
17+
18+
AndroidInitializationSettings androidInitializationSettings =
19+
AndroidInitializationSettings("logo");
20+
21+
IOSInitializationSettings iosInitializationSettings =
22+
IOSInitializationSettings(
23+
requestAlertPermission: true,
24+
requestBadgePermission: true,
25+
requestSoundPermission: true);
26+
27+
final InitializationSettings initializationSettings = InitializationSettings(
28+
android: androidInitializationSettings, iOS: iosInitializationSettings);
29+
30+
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
31+
1332
await Firebase.initializeApp();
14-
//
15-
// if (message.data != null) {
16-
// ReminderService reminderService;
17-
// reminderService.sheduledNotification(
18-
// message.data['startTime'], message.data['endTime']);
19-
// }
33+
if (message.data != null) {
34+
scheduleIncoming(_flutterLocalNotificationsPlugin, message);
35+
scheduleOutgoing(_flutterLocalNotificationsPlugin, message);
36+
}
37+
}
38+
39+
scheduleIncoming(
40+
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin,
41+
RemoteMessage message) async {
42+
var scheduledNotificationStartTime =
43+
determineScheduledTime(message.data['startTime']);
44+
var android = AndroidNotificationDetails("id", "channel", "description");
45+
var ios = IOSNotificationDetails();
46+
var platform = new NotificationDetails(android: android, iOS: ios);
47+
// ignore: deprecated_member_use
48+
await _flutterLocalNotificationsPlugin.schedule(
49+
0,
50+
"Scheduled Task",
51+
"Your scehduled task will about to start within 15 minutes",
52+
scheduledNotificationStartTime,
53+
platform);
54+
}
55+
56+
scheduleOutgoing(
57+
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin,
58+
RemoteMessage message) async {
59+
var scheduledNotificationEndTime =
60+
determineScheduledTime(message.data['endTime']);
61+
62+
var android = AndroidNotificationDetails("id", "channel", "description");
63+
64+
var ios = IOSNotificationDetails();
65+
66+
var platform = new NotificationDetails(android: android, iOS: ios);
67+
// ignore: deprecated_member_use
68+
await _flutterLocalNotificationsPlugin.schedule(
69+
0,
70+
"Scheduled Task",
71+
"Your scehduled task will about to end within 15 minutes",
72+
scheduledNotificationEndTime,
73+
platform);
74+
}
75+
76+
DateTime determineScheduledTime(String time) {
77+
DateTime start = DateTime.parse(time);
78+
DateTime scheduledTime = start.subtract(Duration(minutes: 15));
79+
print(scheduledTime);
80+
return scheduledTime;
2081
}
2182

2283
const AndroidNotificationChannel channel = AndroidNotificationChannel(

lib/services/NotificationService.dart

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class NotificationService {
99
SharedPreferences pref = await SharedPreferences.getInstance();
1010
String id = await messaging.getToken();
1111
pref.setString("deviceToken", id);
12-
print(id);
13-
//TODO: update user device token upon login
14-
// UserService.updateUser(jsonEncode({"deviceToken": id}));
1512
return id;
1613
}
1714

@@ -23,10 +20,28 @@ class NotificationService {
2320
"title": title,
2421
"message": message,
2522
"deviceToken": deviceToken,
26-
"data": {
27-
"startTime": DateTime.now().toString(),
28-
"endTime": DateTime.now().add(Duration(seconds: 10)).toString()
29-
}
23+
},
24+
);
25+
http.Response response = await http.post(
26+
Uri.parse("http://68.183.247.233/api/notification/one"),
27+
headers: headers,
28+
body: body);
29+
if (response.statusCode == 200) {
30+
return true;
31+
} else {
32+
return false;
33+
}
34+
}
35+
36+
static Future<bool> sendPushToOneWithTime(String title, String message,
37+
deviceToken, String startTime, String endTime) async {
38+
final Map<String, String> headers = {"Content-Type": "application/json"};
39+
var body = jsonEncode(
40+
{
41+
"title": title,
42+
"message": message,
43+
"deviceToken": deviceToken,
44+
"data": {"startTime": startTime, "endTime": endTime}
3045
},
3146
);
3247
http.Response response = await http.post(

lib/services/reminderService.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ class ReminderService extends ChangeNotifier {
8383
//Sheduled Notification
8484

8585
Future sheduledNotification(String startTime, String endTime) async {
86-
var scheduledNotificationStartTime =
87-
determineScheduledTime(startTime);
88-
var scheduledNotificationEndTime =
89-
determineScheduledTime(endTime);
86+
print("Hello");
87+
var scheduledNotificationStartTime = determineScheduledTime(startTime);
88+
var scheduledNotificationEndTime = determineScheduledTime(endTime);
9089
var bigPicture = BigPictureStyleInformation(
9190
DrawableResourceAndroidBitmap("logo"),
9291
largeIcon: DrawableResourceAndroidBitmap("logo"),
@@ -102,14 +101,15 @@ class ReminderService extends ChangeNotifier {
102101

103102
var platform = new NotificationDetails(android: android, iOS: ios);
104103

104+
// ignore: deprecated_member_use
105105
await _flutterLocalNotificationsPlugin.schedule(
106106
0,
107107
"Scheduled Task",
108108
"Your scehduled task will about to start within 15 minutes",
109109
scheduledNotificationStartTime,
110110
platform);
111111

112-
await _flutterLocalNotificationsPlugin.schedule(
112+
await _flutterLocalNotificationsPlugin.schedule(
113113
0,
114114
"Scheduled Task",
115115
"Your scehduled task will about to end within 15 minutes",
@@ -125,7 +125,7 @@ class ReminderService extends ChangeNotifier {
125125

126126
DateTime determineScheduledTime(String time) {
127127
DateTime start = DateTime.parse(time);
128-
DateTime scheduledTime = start.subtract(Duration(minutes: 15));
128+
DateTime scheduledTime = start.subtract(Duration(minutes: 1));
129129
return scheduledTime;
130130
}
131131
}

lib/services/userService.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class UserService extends AuthService {
6464

6565
static Future<String> getDeviceToken(String id) async {
6666
final Map<String, String> headers = {"Content-Type": "application/json"};
67-
http.Response response = await http.post(
67+
http.Response response = await http.get(
6868
Uri.parse("http://68.183.247.233/api/user/deviceToken/$id"),
6969
headers: headers,
7070
);
71-
var decodedMsg = await jsonDecode(response.body);
7271
if (response.statusCode == 200) {
72+
var decodedMsg = json.decode(response.body);
7373
return decodedMsg["device_token"];
7474
} else {
7575
return "";

lib/views/Admin/Profile/ProfileScreen.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
111111
Icons.call, () {}),
112112
profileInfo(
113113
'Email', '${user.officialEmail}', Icons.mail, () {}),
114-
profileInfo('Access Level', '${user.userType}',
115-
Icons.security, () {}),
114+
profileInfo(
115+
'Access Level',
116+
'${user.userType.replaceFirst(user.userType.substring(0, 1), user.userType.substring(0, 1).toUpperCase())}',
117+
Icons.security,
118+
() {}),
116119
profileInfo('Logout', '', Icons.exit_to_app_rounded, () {
117120
AuthService.clearAuth();
118121
Navigator.of(context).pushReplacement(

lib/views/Admin/TaskManager/CreateTaskScreen.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:propview/models/Property.dart';
88
import 'package:propview/models/PropertyOwner.dart';
99
import 'package:propview/models/TaskCategory.dart';
1010
import 'package:propview/models/User.dart';
11-
import 'package:propview/services/NotificationService.dart';
11+
import 'package:propview/services/notificationService.dart';
1212
import 'package:propview/services/propertyOwnerService.dart';
1313
import 'package:propview/services/propertyService.dart';
1414
import 'package:propview/services/taskCategoryService.dart';
@@ -509,12 +509,14 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
509509
load = false;
510510
});
511511
if (response) {
512-
NotificationService.sendPushToOne(
513-
"New Task Assigned",
514-
"A new task Has been Assigned : ${_taskName.text}",
515-
_selectedUser.deviceToken,
516-
);
517-
var managerToken = await UserService.getDeviceToken(_selectedUser.parentId);
512+
NotificationService.sendPushToOneWithTime(
513+
"New Task Assigned",
514+
"A new task Has been Assigned : ${_taskName.text}",
515+
_selectedUser.deviceToken,
516+
_taskStartDateTime.text,
517+
_taskEndDateTime.text);
518+
var managerToken = await UserService.getDeviceToken(
519+
_selectedUser.parentId);
518520
NotificationService.sendPushToOne(
519521
"New Task Assigned",
520522
"A new task Has been Assigned to your employee : ${_taskName.text}",

0 commit comments

Comments
 (0)