diff --git a/notifications.txt b/notifications.txt
index 1785b59c5..dc100ade6 100644
--- a/notifications.txt
+++ b/notifications.txt
@@ -1,2 +1,71 @@
-
-
\ No newline at end of file
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 15:06:25.299
+Message:Backup requested
+-
+-
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 15:09:10.673
+Message:Backup requested
+-
+-
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 15:12:45.753
+Message:Backup requested
+-
+-
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 15:37:56.323
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 15:38:03.65
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 16:04:13.287
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 16:04:17.549
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 16:04:43.17
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
+> START OF MESSAGE <
+Read status:false
+Priority:HIGH
+Timestamp:2018-10-04 16:05:10.314
+Message:Backup requested
+-
+Location:-6.206968,106.751365
+> END OF MESSAGE <
diff --git a/src/seedu/addressbook/inbox/Inbox.java b/src/seedu/addressbook/inbox/Inbox.java
index 000e8cd38..44df03fcd 100644
--- a/src/seedu/addressbook/inbox/Inbox.java
+++ b/src/seedu/addressbook/inbox/Inbox.java
@@ -17,17 +17,18 @@ public class Inbox {
public static int unreadMsgs = 0;
private Msg message;
private static ReadNotification nw = new ReadNotification(MESSAGE_STORAGE_FILEPATH);
- WriteNotification myMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH, true);
+ static WriteNotification myMessages = new WriteNotification(MESSAGE_STORAGE_FILEPATH, true);
- protected HashMap, Triplet> notificationsToPrint = new HashMap<>();
+ protected static HashMap, Triplet> notificationsToPrint = new HashMap<>();
public Inbox(){
Inbox inbox = new Inbox();
}
- public void loadMessages() throws IOException {
+ public static void loadMsgs() throws IOException {
notificationsToPrint = nw.ReadFromFile();
+ unreadMsgs = nw.getUnreadMsgs();
}
/** Prints out all unread notifications ordered by priority, then timestamp (earlier first).
@@ -35,8 +36,27 @@ public void loadMessages() throws IOException {
* @return messages to be printed out on the main window.
*/
- /*public String printMsg(){
- //for (String s : messages)
- return
- }*/
+ public int checkNumUnreadMessages(HashMap notificationsToPrint){
+
+ return unreadMsgs;
+ }
+
+ public static void printMsg(){
+ if(unreadMsgs > 0)
+ System.out.println("You have " + unreadMsgs + " unread message" + ((unreadMsgs == 1) ? "." : "s."));
+ else System.out.println(unreadMsgs);
+
+ }
+
+ public static void main(String[] args) throws IOException {
+ /*Msg newMsg = new Msg();
+ Location location = new Location(-6.206968,106.751365);
+ newMsg.addMsg("Backup requested");
+ newMsg.setLocation(location);
+ newMsg.setPriority(Msg.Priority.HIGH);
+ newMsg.setTime();
+ myMessages.writeToFile(newMsg);*/
+ loadMsgs();
+ printMsg();
+ }
}
\ No newline at end of file
diff --git a/src/seedu/addressbook/inbox/Msg.java b/src/seedu/addressbook/inbox/Msg.java
index ca0348950..31f3c8156 100644
--- a/src/seedu/addressbook/inbox/Msg.java
+++ b/src/seedu/addressbook/inbox/Msg.java
@@ -25,8 +25,7 @@ public enum Priority {
LOW // Messages that are FYI (e.g. Notifications to admin that details of subjects have changed
}
- public Msg(){
- Msg message = new Msg();
+ public Msg(){ // Create overloading constructors.
isLocationAvailable = false;
isRead = false;
}
@@ -47,8 +46,7 @@ public String getMsg(){
}
public void setLocation(Location place){
- location.setLongitude(place.getLongitude());
- location.setLatitude(place.getLatitude());
+ this.location = place;
isLocationAvailable = true;
}
diff --git a/src/seedu/addressbook/inbox/ReadNotification.java b/src/seedu/addressbook/inbox/ReadNotification.java
index 8dd725b51..7e8f7a972 100644
--- a/src/seedu/addressbook/inbox/ReadNotification.java
+++ b/src/seedu/addressbook/inbox/ReadNotification.java
@@ -13,57 +13,68 @@
import java.util.HashMap;
public class ReadNotification {
- private String path;
- private Msg returnMsg;
- protected HashMap, Triplet> allMsg = new HashMap<>();
+ private static String path;
+ private static Msg returnMsg;
+ private static int unreadMsgs = 0;
+ protected static HashMap, Triplet> allMsg = new HashMap<>();
public ReadNotification(String filePath) {
path = filePath;
}
- public HashMap, Triplet>
+ public static HashMap, Triplet>
ReadFromFile() throws IOException { // If no new notifications and 'inbox' command invoked, show past 10 notifications
String line;
BufferedReader br = new BufferedReader(new FileReader(path));
while ((line = br.readLine()) != null) {
- if (line == "> START OF MESSAGE <")
+ if (line.equals("> START OF MESSAGE <")) {
returnMsg = new Msg();
- else if (line == "> END OF MESSAGE <") // End of message entry, store into hashmap
+ }
+ else if (line.equals("> END OF MESSAGE <")) // End of message entry, store into hashmap
allMsg.put(new Triplet<>(returnMsg.isRead, returnMsg.getPriority(), returnMsg.getTime()),
new Triplet<>(returnMsg.getMsg(), returnMsg.getEta(), returnMsg.getLocation()));
else {
String[] parts = line.split(":", 2);
String msgType = parts[0];
if (parts.length == 2) {
- if (msgType == "Read status") {
+ if (msgType.equals("Read status")) {
returnMsg.isRead = Boolean.parseBoolean(parts[1]);
- } else if (msgType == "Priority") {
+ if (!returnMsg.isRead)
+ unreadMsgs += 1;
+ }
+ else if (msgType.equals("Priority")) {
Msg.Priority msgPriority;
- if (parts[1] == "HIGH")
+ if (parts[1].equals("HIGH"))
msgPriority = Msg.Priority.HIGH;
- else if (parts[1] == "MED")
+ else if (parts[1].equals("MED"))
msgPriority = Msg.Priority.MED;
else
msgPriority = Msg.Priority.LOW;
returnMsg.setPriority(msgPriority);
- } else if (msgType == "Timestamp") {
- SimpleDateFormat timeFormatted = new SimpleDateFormat("dd.MM.YYYY.HH.MM.ss");
+ }
+ else if (msgType.equals("Timestamp")) {
+ //SimpleDateFormat timeFormatted = new SimpleDateFormat("dd.MM.YYYY.HH.MM.ss");
+ SimpleDateFormat timeFormatted = new SimpleDateFormat("YYYY-MM-dd HH:MM:ss.SSS");
Date parsedTimeStamp;
try {
- parsedTimeStamp = timeFormatted.parse(line);
+ parsedTimeStamp = timeFormatted.parse(parts[1]);
} catch (ParseException e) {
continue; // Find a way to debug this if time format is invalid.
}
Timestamp msgTime = new Timestamp(parsedTimeStamp.getTime());
returnMsg.setTime(msgTime);
- } else if (msgType == "Message") {
+ }
+ else if (msgType.equals("Message")) {
returnMsg.addMsg(parts[1]); // Multiple lines of message required or not?
- } else if (msgType == "ETA") {
+ }
+ else if (msgType.equals("ETA")) {
returnMsg.setEta(Integer.parseInt(parts[1]));
- } else if (msgType == "Location") {
+ }
+ else if (msgType.equals("Location")) {
String[] coordinates = parts[1].split(",", 2);
- returnMsg.setLongitude(Double.parseDouble(coordinates[0]));
- returnMsg.setLatitude(Double.parseDouble(coordinates[1]));
+ Location myLocation = new Location(Double.parseDouble(coordinates[0]),
+ Double.parseDouble(coordinates[1]));
+ returnMsg.setLocation(myLocation);
}
}
@@ -71,4 +82,18 @@ else if (parts[1] == "MED")
}
return allMsg;
}
+
+ public int getUnreadMsgs(){
+ return this.unreadMsgs;
+ }
+
+ public void resetUnreadMsgs(){
+ this.unreadMsgs = 0;
+ }
+ /*public static void main(String[] args) throws IOException {
+ ReadNotification myFile = new ReadNotification("notifications.txt");
+ allMsg = ReadFromFile();
+ System.out.println(unreadMsgs);
+ System.out.println(allMsg.size());
+ }*/
}
diff --git a/src/seedu/addressbook/inbox/WriteNotification.java b/src/seedu/addressbook/inbox/WriteNotification.java
index a91bca929..cc5204f7b 100644
--- a/src/seedu/addressbook/inbox/WriteNotification.java
+++ b/src/seedu/addressbook/inbox/WriteNotification.java
@@ -43,7 +43,7 @@ public void writeToFile(Msg message) throws IOException{
myPrinter.println("Location:" + message.getLatitude() + "," + message.getLongitude());
}
else myPrinter.println('-');
- //myPrinter.println("> END OF MESSAGE <"); // Notate the end of 1 message entry with "---"
+ myPrinter.println("> END OF MESSAGE <"); // Notate the end of 1 message entry with "---"
myPrinter.close();
}