Skip to content

Commit

Permalink
Merge pull request #6 from Codebugged-Research/feature/reminder
Browse files Browse the repository at this point in the history
Feature/reminder
  • Loading branch information
sambitraze authored Jun 6, 2021
2 parents 6663539 + 8020af0 commit 4236f03
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 85 deletions.
1 change: 0 additions & 1 deletion android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
35 changes: 28 additions & 7 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
compileSdkVersion 30

Expand All @@ -43,13 +49,28 @@ android {
multiDexEnabled true
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
// buildTypes {
// release {
// // TODO: Add your own signing config for the release build.
// // Signing with the debug keys for now, so `flutter run --release` works.
// signingConfig signingConfigs.debug
// }
// }

signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}

}

flutter {
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<application
android:label="propview"
android:label="PropView"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_launcher">
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
Expand Down
Binary file modified android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions android/key.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
storePassword=$PropDial235#
keyPassword=$PropDial235#
keyAlias=upload
storeFile=../upload-keystore.jks
Binary file added android/upload-keystore.jks
Binary file not shown.
73 changes: 67 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,75 @@ import 'package:propview/services/reminderService.dart';
import 'package:propview/utils/theme.dart';
import 'package:propview/views/splashScreen.dart';

ReminderService reminderService;

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();

AndroidInitializationSettings androidInitializationSettings =
AndroidInitializationSettings("logo");

IOSInitializationSettings iosInitializationSettings =
IOSInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true);

final InitializationSettings initializationSettings = InitializationSettings(
android: androidInitializationSettings, iOS: iosInitializationSettings);

await _flutterLocalNotificationsPlugin.initialize(initializationSettings);

await Firebase.initializeApp();
//
// if (message.data != null) {
// ReminderService reminderService;
// reminderService.sheduledNotification(
// message.data['startTime'], message.data['endTime']);
// }
if (message.data != null) {
scheduleIncoming(_flutterLocalNotificationsPlugin, message);
scheduleOutgoing(_flutterLocalNotificationsPlugin, message);
}
}

scheduleIncoming(
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin,
RemoteMessage message) async {
var scheduledNotificationStartTime =
determineScheduledTime(message.data['startTime']);
var android = AndroidNotificationDetails("id", "channel", "description");
var ios = IOSNotificationDetails();
var platform = new NotificationDetails(android: android, iOS: ios);
// ignore: deprecated_member_use
await _flutterLocalNotificationsPlugin.schedule(
0,
"Scheduled Task",
"Your scehduled task will about to start within 15 minutes",
scheduledNotificationStartTime,
platform);
}

scheduleOutgoing(
FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin,
RemoteMessage message) async {
var scheduledNotificationEndTime =
determineScheduledTime(message.data['endTime']);

var android = AndroidNotificationDetails("id", "channel", "description");

var ios = IOSNotificationDetails();

var platform = new NotificationDetails(android: android, iOS: ios);
// ignore: deprecated_member_use
await _flutterLocalNotificationsPlugin.schedule(
0,
"Scheduled Task",
"Your scehduled task will about to end within 15 minutes",
scheduledNotificationEndTime,
platform);
}

DateTime determineScheduledTime(String time) {
DateTime start = DateTime.parse(time);
DateTime scheduledTime = start.subtract(Duration(minutes: 15));
print(scheduledTime);
return scheduledTime;
}

const AndroidNotificationChannel channel = AndroidNotificationChannel(
Expand Down
29 changes: 22 additions & 7 deletions lib/services/NotificationService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class NotificationService {
SharedPreferences pref = await SharedPreferences.getInstance();
String id = await messaging.getToken();
pref.setString("deviceToken", id);
print(id);
//TODO: update user device token upon login
// UserService.updateUser(jsonEncode({"deviceToken": id}));
return id;
}

Expand All @@ -23,10 +20,28 @@ class NotificationService {
"title": title,
"message": message,
"deviceToken": deviceToken,
"data": {
"startTime": DateTime.now().toString(),
"endTime": DateTime.now().add(Duration(seconds: 10)).toString()
}
},
);
http.Response response = await http.post(
Uri.parse("http://68.183.247.233/api/notification/one"),
headers: headers,
body: body);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
}

static Future<bool> sendPushToOneWithTime(String title, String message,
deviceToken, String startTime, String endTime) async {
final Map<String, String> headers = {"Content-Type": "application/json"};
var body = jsonEncode(
{
"title": title,
"message": message,
"deviceToken": deviceToken,
"data": {"startTime": startTime, "endTime": endTime}
},
);
http.Response response = await http.post(
Expand Down
12 changes: 6 additions & 6 deletions lib/services/reminderService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ class ReminderService extends ChangeNotifier {
//Sheduled Notification

Future sheduledNotification(String startTime, String endTime) async {
var scheduledNotificationStartTime =
determineScheduledTime(startTime);
var scheduledNotificationEndTime =
determineScheduledTime(endTime);
print("Hello");
var scheduledNotificationStartTime = determineScheduledTime(startTime);
var scheduledNotificationEndTime = determineScheduledTime(endTime);
var bigPicture = BigPictureStyleInformation(
DrawableResourceAndroidBitmap("logo"),
largeIcon: DrawableResourceAndroidBitmap("logo"),
Expand All @@ -102,14 +101,15 @@ class ReminderService extends ChangeNotifier {

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

// ignore: deprecated_member_use
await _flutterLocalNotificationsPlugin.schedule(
0,
"Scheduled Task",
"Your scehduled task will about to start within 15 minutes",
scheduledNotificationStartTime,
platform);

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

DateTime determineScheduledTime(String time) {
DateTime start = DateTime.parse(time);
DateTime scheduledTime = start.subtract(Duration(minutes: 15));
DateTime scheduledTime = start.subtract(Duration(minutes: 1));
return scheduledTime;
}
}
4 changes: 2 additions & 2 deletions lib/services/userService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class UserService extends AuthService {

static Future<String> getDeviceToken(String id) async {
final Map<String, String> headers = {"Content-Type": "application/json"};
http.Response response = await http.post(
http.Response response = await http.get(
Uri.parse("http://68.183.247.233/api/user/deviceToken/$id"),
headers: headers,
);
var decodedMsg = await jsonDecode(response.body);
if (response.statusCode == 200) {
var decodedMsg = json.decode(response.body);
return decodedMsg["device_token"];
} else {
return "";
Expand Down
7 changes: 5 additions & 2 deletions lib/views/Admin/Profile/ProfileScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
Icons.call, () {}),
profileInfo(
'Email', '${user.officialEmail}', Icons.mail, () {}),
profileInfo('Access Level', '${user.userType}',
Icons.security, () {}),
profileInfo(
'Access Level',
'${user.userType.replaceFirst(user.userType.substring(0, 1), user.userType.substring(0, 1).toUpperCase())}',
Icons.security,
() {}),
profileInfo('Logout', '', Icons.exit_to_app_rounded, () {
AuthService.clearAuth();
Navigator.of(context).pushReplacement(
Expand Down
16 changes: 9 additions & 7 deletions lib/views/Admin/TaskManager/CreateTaskScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:propview/models/Property.dart';
import 'package:propview/models/PropertyOwner.dart';
import 'package:propview/models/TaskCategory.dart';
import 'package:propview/models/User.dart';
import 'package:propview/services/NotificationService.dart';
import 'package:propview/services/notificationService.dart';
import 'package:propview/services/propertyOwnerService.dart';
import 'package:propview/services/propertyService.dart';
import 'package:propview/services/taskCategoryService.dart';
Expand Down Expand Up @@ -509,12 +509,14 @@ class _CreateTaskScreenState extends State<CreateTaskScreen> {
load = false;
});
if (response) {
NotificationService.sendPushToOne(
"New Task Assigned",
"A new task Has been Assigned : ${_taskName.text}",
_selectedUser.deviceToken,
);
var managerToken = await UserService.getDeviceToken(_selectedUser.parentId);
NotificationService.sendPushToOneWithTime(
"New Task Assigned",
"A new task Has been Assigned : ${_taskName.text}",
_selectedUser.deviceToken,
_taskStartDateTime.text,
_taskEndDateTime.text);
var managerToken = await UserService.getDeviceToken(
_selectedUser.parentId);
NotificationService.sendPushToOne(
"New Task Assigned",
"A new task Has been Assigned to your employee : ${_taskName.text}",
Expand Down
Loading

0 comments on commit 4236f03

Please sign in to comment.