Skip to content

Commit

Permalink
showing deleted list will no longer need new command. leave can have …
Browse files Browse the repository at this point in the history
…date updated only on the end date
  • Loading branch information
TehZiHuai committed Nov 7, 2019
1 parent beb2ce3 commit be4ef02
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/main/java/Operations/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public ArrayList<Task> loadFile(String fileName) throws RoomShareException {
Leave leave = new Leave(description, user, from, to);
leave.setPriority(priority);
leave.setRecurrenceSchedule(recurrence);
leave.setDone(done);
taskArrayList.add(leave);
} else {
//Meeting type
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/Operations/TaskCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ public ArrayList<Date> extractDate(String input) throws RoomShareException {
// date of the leave
throw new RoomShareException(ExceptionType.invalidDateRange);
}
dates.add(parser.formatDate(toInput));
}
} else
throw new RoomShareException(ExceptionType.emptyDate);
Expand Down Expand Up @@ -432,7 +431,7 @@ public void updateTask(String input, Task oldTask) throws RoomShareException {
}

if (input.contains("&")) {
ArrayList<Date> dates = this.extractDate(input);
ArrayList<Date> dates = extractDate(input);
if (oldTask instanceof Leave && dates.size() == 2) {
Leave oldLeave = (Leave) oldTask;
Date start = dates.get(0);
Expand All @@ -442,7 +441,12 @@ public void updateTask(String input, Task oldTask) throws RoomShareException {
oldLeave.setEndDate(end);
} else {
Date date = dates.get(0);
oldTask.setDate(date);
if (oldTask instanceof Leave) {
Leave oldLeave = (Leave)oldTask;
oldLeave.setEndDate(date);
} else {
oldTask.setDate(date);
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/Operations/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import Enums.SortType;
import Enums.TimeUnit;
import Model_Classes.Assignment;
import Model_Classes.Leave;
import Model_Classes.Task;

import java.util.ArrayList;
Expand Down Expand Up @@ -375,7 +376,7 @@ public void snooze (int index, int amount, TimeUnit timeUnit) throws RoomShareEx
public int getSize() {
int count =0;
for(Task t : tasks) {
if(!t.getOverdue()) {
if(!t.getOverdue() && !(t instanceof Leave)) {
count += 1;
}
}
Expand All @@ -389,7 +390,9 @@ public int getSize() {
public int getDoneSize(){
int count = 0;
for (Task t: tasks){
if (t.getDone() && !t.getOverdue()) count++;
if (t.getDone() && !t.getOverdue() && !(t instanceof Leave)) {
count++;
}
}
return count;
}
Expand Down Expand Up @@ -446,4 +449,5 @@ public int[] listTagged(String user) throws RoomShareException{
int[] done = {belongCount, doneCount};
return done;
}

}
39 changes: 18 additions & 21 deletions src/main/java/RoomShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void run() throws RoomShareException, IOException, InterruptedException {
try {
String input = parser.getCommandLine();
int index = parser.getIndex(input);
Task oldTask = taskList.get(index);
Task oldTask = TaskList.get(index);
taskCreator.updateTask(input,oldTask);
ui.showUpdated(index+1);
storage.writeFile(TaskList.currentList(), "data.txt");
Expand Down Expand Up @@ -355,26 +355,23 @@ public void run() throws RoomShareException, IOException, InterruptedException {
Ui.clearScreen();
ui.startUp();
String input = parser.getCommandLine();
ui.showTagged(input);
try {
int[] doneArray = taskList.listTagged(input);
ui.showTaggedPercentage(input);
ProgressBar progressBar = new ProgressBar(doneArray[0], doneArray[1]);
ui.showBar(progressBar.showBar());
} catch (RoomShareException e) {
ui.showError(e);
}
listRoutine.list();
break;

case deleted:
Ui.clearScreen();
ui.startUp();
ui.showDeletedList();
try {
tempDeleteList.list();
} catch (RoomShareException e) {
ui.showError(e);
if (input.equals("deleted")) {
ui.showDeletedList();
try {
tempDeleteList.list();
} catch (RoomShareException e) {
ui.showError(e);
}
} else {
ui.showTagged(input);
try {
int[] doneArray = taskList.listTagged(input);
ui.showTaggedPercentage(input);
ProgressBar progressBar = new ProgressBar(doneArray[0], doneArray[1]);
ui.showBar(progressBar.showBar());
} catch (RoomShareException e) {
ui.showError(e);
}
}
listRoutine.list();
break;
Expand Down

0 comments on commit be4ef02

Please sign in to comment.