Skip to content

Commit

Permalink
Improve UI, code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
raythx98 committed Sep 4, 2020
1 parent 2831af3 commit 465f5e5
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 130 deletions.
11 changes: 5 additions & 6 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
T|1|something
T|0|this|2020-12-31|2021
D|1|that|2020-11-30|2011
E|1|lol|2020-10-20|2000
T|0|something|2020-12-31|2021
T|0|even more homework omg
T|0|something
D|1|that|2020-01-30|20:11
E|1|lol|2020-10-20|20:00
T|1|something|2020-12-31|20:21
T|1|even more homework omg
T|1|something
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException
throw new DukeException("Invalid Description");
}
tasks.addTask(task);
ui.addShowOnScreen("Got it, here yur task bij\n" + task.toString()
ui.addShowOnScreen("Got it, here yur task bij\n " + task.toString()
+ "\nNow you have " + tasks.getSize() + " tasks in the list.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException
throw new DukeException("Invalid Description");
}
tasks.addTask(task);
ui.addShowOnScreen("Got it, here yur task bij\n" + task.toString()
ui.addShowOnScreen("Got it, here yur task bij\n " + task.toString()
+ "\nNow you have " + tasks.getSize() + " tasks in the list.");
}
}
10 changes: 5 additions & 5 deletions src/main/java/raythx98/grandma/command/AddTodoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import raythx98.grandma.storage.Storage;
import raythx98.grandma.task.Task;
import raythx98.grandma.task.TaskList;
import raythx98.grandma.task.ToDos;
import raythx98.grandma.task.ToDo;
import raythx98.grandma.ui.Ui;

public class AddTodoCommand extends AddCommand {
Expand All @@ -17,14 +17,14 @@ public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException
String[] descriptionSplit = taskDescriptionDeadline.split(" /by ", 2);
Task task;
if (descriptionSplit.length == 1) {
task = new ToDos(descriptionSplit[0]);
task = new ToDo(descriptionSplit[0]);
} else if (descriptionSplit.length == 2) {
task = new ToDos(descriptionSplit[0], descriptionSplit[1]);
task = new ToDo(descriptionSplit[0], descriptionSplit[1]);
} else {
throw new DukeException("Invalid Description");
}
tasks.addTask(task);
ui.addShowOnScreen("Got it, here yur task bij\n" + task.toString()
+ "\nNow you have " + tasks.getSize() + " tasks in the list.");
ui.addShowOnScreen("Got it, here yur task bij\n " + task.toString()
+ "\nNow you have " + tasks.getSize() + "tasks in the list.");
}
}
2 changes: 1 addition & 1 deletion src/main/java/raythx98/grandma/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DeleteCommand (int deleteIndex) {

@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
ui.addShowOnScreen("okcan done:\n" + tasks.removeTask(deleteIndex)
ui.addShowOnScreen("okcan deleted:\n " + tasks.removeTask(deleteIndex)
+ "\nNow you have " + tasks.getSize() + " tasks in the list.");
}
}
2 changes: 1 addition & 1 deletion src/main/java/raythx98/grandma/command/DoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DoneCommand (int doneIndex) {

@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
ui.addShowOnScreen("okcan done:\n" + tasks.getTask(doneIndex).markAsDone()
ui.addShowOnScreen("okcan mark completed:\n " + tasks.getTask(doneIndex).markAsDone()
+ "\nNow you have " + tasks.getSize() + " tasks in the list.");
}
}
2 changes: 1 addition & 1 deletion src/main/java/raythx98/grandma/command/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public FindCommand (String keyWord) {

@Override
public void execute(TaskList tasks, Ui ui, Storage storage) throws DukeException {
ui.addShowOnScreen(tasks.findTask(keyWord));
ui.addShowOnScreen("Got it, here yur search results bij: \n" + tasks.findTask(keyWord));
}
}
15 changes: 10 additions & 5 deletions src/main/java/raythx98/grandma/storage/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import raythx98.grandma.exception.UnknownCommandException;
import raythx98.grandma.task.Deadline;
import raythx98.grandma.task.Event;
import raythx98.grandma.task.ToDos;
import raythx98.grandma.task.TaskList;
import raythx98.grandma.task.ToDo;

/**
* Deals with the manipulation of loading and saving data.
Expand Down Expand Up @@ -38,9 +38,14 @@ public Storage(String filepath) {
*/
public void save() {
if (tasks.getSize() > 0) {
Writer.overwrite(filepath, tasks.getTask(0).toPrint());
for (int i = 1; i < tasks.getSize(); i++) {
Writer.writeOn(filepath, "\n" + tasks.getTask(i).toPrint());
try {
Writer.overwrite(filepath, tasks.getTask(0).toPrint());
for (int i = 1; i < tasks.getSize(); i++) {
Writer.writeOn(filepath, "\n" + tasks.getTask(i).toPrint());
}
} catch (DukeException e) {
//Find a way to send error message
System.out.println(e.getMessage());
}
}
}
Expand All @@ -59,7 +64,7 @@ public TaskList load() {
String[] dataSplit = data.split("\\|");
switch (dataSplit[0]) {
case TODO:
tasks.addTask(new ToDos(dataSplit));
tasks.addTask(new ToDo(dataSplit));
break;
case DEADLINE:
tasks.addTask(new Deadline(dataSplit));
Expand Down
49 changes: 19 additions & 30 deletions src/main/java/raythx98/grandma/task/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package raythx98.grandma.task;

import raythx98.grandma.exception.DukeException;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;

import raythx98.grandma.exception.DukeException;

/**
* Represents a specific task which has a deadline.
*/
public class Deadline extends Task {

protected LocalDate date = null;
protected String by = null;
protected LocalTime by = null;

/**
* Something.
Expand All @@ -23,11 +22,11 @@ public class Deadline extends Task {
*/
public Deadline(String description, String by) {
super(description);
tag = "D";
tag = DEADLINE_TAG;
String[] bySplit = by.split(" ", 2);
date = LocalDate.parse(bySplit[0]);
date = LocalDate.parse(bySplit[0], DateTimeFormatter.ofPattern(DATE_FORMAT));
if (bySplit.length > 1) {
this.by = bySplit[1];
this.by = LocalTime.parse(bySplit[1], DateTimeFormatter.ofPattern(TIME_FORMAT));
}
}

Expand All @@ -38,7 +37,7 @@ public Deadline(String description, String by) {
*/
public Deadline(String description) {
super(description);
tag = "D";
tag = DEADLINE_TAG;
}

/**
Expand All @@ -49,52 +48,42 @@ public Deadline(String description) {
*/
public Deadline(String ... taskDescriptions) throws DukeException {
super(taskDescriptions[2]);
tag = "D";
tag = DEADLINE_TAG;
if (taskDescriptions.length == 3) {
} else if (taskDescriptions.length == 5) {
this.date = LocalDate.parse(taskDescriptions[3]);
this.by = taskDescriptions[4];
this.by = LocalTime.parse(taskDescriptions[4]);
} else {
throw new DukeException("Task loading error...");
}
if (taskDescriptions[1].equals("1")) {
if (taskDescriptions[1].equals(TICK_BINARY)) {
this.markAsDone();
}
}

@Override
public String getTaskType() {
return tag;
}

/**
* Something.
*
* @return
*/
public String toPrint() {
if (date == null) {
public String toPrint() throws DukeException {
if (date == null && by == null) {
return super.toPrint();
} else {
} else if (date != null && by != null) {
return super.toPrint() + "|" + date + "|" + by;
} else {
throw new DukeException("DateTime Error la oi...");
}
}

@Override
public String toString() {
if (by == null) {
return "[D]" + super.toString();
return "[" + tag + "] " + super.toString();
} else {
String now = "AM";
LocalTime localTime = LocalTime.parse(by, DateTimeFormatter.ofPattern("HHmm"));
int hour = localTime.get(ChronoField.CLOCK_HOUR_OF_DAY);
int minute = localTime.get(ChronoField.MINUTE_OF_HOUR);
if (hour > 12) {
now = "PM";
hour -= 12;
}
return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy"))
+ ", " + hour + ":" + minute + now + ")";
return "[" + tag + "] " + super.toString() + "\n (by: "
+ date.format(DateTimeFormatter.ofPattern(OUTPUT_DATE_FORMAT))
+ ", " + by.format(DateTimeFormatter.ofPattern(OUTPUT_TIME_FORMAT)) + ")";
}
}
}
54 changes: 21 additions & 33 deletions src/main/java/raythx98/grandma/task/Event.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package raythx98.grandma.task;

import raythx98.grandma.exception.DukeException;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;

import raythx98.grandma.exception.DukeException;

/**
* Represents a specific task which is an event.
*/
public class Event extends Task {

protected LocalDate date = null;
protected String at = null;
protected LocalTime at = null;

/**
* Something.
Expand All @@ -23,12 +22,11 @@ public class Event extends Task {
*/
public Event(String description, String at) {
super(description);
this.at = at;
tag = "E";
String[] bySplit = at.split(" ", 2);
date = LocalDate.parse(bySplit[0]);
if (bySplit.length > 1) {
this.at = bySplit[1];
tag = EVENT_TAG;
String[] atSplit = at.split(" ", 2);
date = LocalDate.parse(atSplit[0], DateTimeFormatter.ofPattern(DATE_FORMAT));
if (atSplit.length > 1) {
this.at = LocalTime.parse(atSplit[1], DateTimeFormatter.ofPattern(TIME_FORMAT));
}
}

Expand All @@ -39,7 +37,7 @@ public Event(String description, String at) {
*/
public Event(String description) {
super(description);
tag = "E";
tag = EVENT_TAG;
}

/**
Expand All @@ -50,52 +48,42 @@ public Event(String description) {
*/
public Event(String ... taskDescriptions) throws DukeException {
super(taskDescriptions[2]);
tag = "E";
tag = EVENT_TAG;
if (taskDescriptions.length == 3) {
} else if (taskDescriptions.length == 5) {
this.date = LocalDate.parse(taskDescriptions[3]);
this.at = taskDescriptions[4];
this.at = LocalTime.parse(taskDescriptions[4]);
} else {
throw new DukeException("Task loading error...");
}
if (taskDescriptions[1].equals("1")) {
if (taskDescriptions[1].equals(TICK_BINARY)) {
this.markAsDone();
}
}

@Override
public String getTaskType() {
return tag;
}

/**
* Something.
*
* @return
*/
public String toPrint() {
if (date == null) {
public String toPrint() throws DukeException {
if (date == null && at == null) {
return super.toPrint();
} else {
} else if (date != null && at != null) {
return super.toPrint() + "|" + date + "|" + at;
} else {
throw new DukeException("DateTime Error la oi...");
}
}

@Override
public String toString() {
if (at == null) {
return "[E]" + super.toString();
return "[" + tag + "] " + super.toString();
} else {
String now = "AM";
LocalTime localTime = LocalTime.parse(at, DateTimeFormatter.ofPattern("HHmm"));
int hour = localTime.get(ChronoField.CLOCK_HOUR_OF_DAY);
int minute = localTime.get(ChronoField.MINUTE_OF_HOUR);
if (hour > 12) {
now = "PM";
hour -= 12;
}
return "[E]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM dd yyyy"))
+ ", " + hour + ":" + minute + now + ")";
return "[" + tag + "] " + super.toString() + "\n (by: "
+ date.format(DateTimeFormatter.ofPattern(OUTPUT_DATE_FORMAT))
+ ", " + at.format(DateTimeFormatter.ofPattern(OUTPUT_TIME_FORMAT)) + ")";
}
}
}

0 comments on commit 465f5e5

Please sign in to comment.