|
| 1 | +//@@ kherlenbayasgalan & jingxizhu |
| 2 | + |
1 | 3 | package seedu.duke.calendar;
|
2 | 4 |
|
| 5 | +import seedu.duke.calendar.command.EventCommand; |
| 6 | +import seedu.duke.calendar.command.UnknownCommand; |
| 7 | +import seedu.duke.calendar.Event; |
| 8 | +import seedu.duke.flashcard.FlashcardStorage; |
| 9 | + |
| 10 | +import java.io.FileNotFoundException; |
| 11 | +import java.util.ArrayList; |
| 12 | +import java.util.Scanner; |
| 13 | + |
3 | 14 | public class CalendarManager {
|
4 | 15 | Calendar calendar;
|
5 | 16 | CalendarUi calendarUi;
|
| 17 | + EventList eventList; |
6 | 18 | CalendarCommandParser calendarCommandParser;
|
| 19 | + Scanner scanner; |
| 20 | + |
| 21 | + private EventStorage storage; |
| 22 | + |
| 23 | + public CalendarManager(ArrayList<Event> events) { |
| 24 | + |
| 25 | + EventDirectory eventdirectory = new EventDirectory(); |
| 26 | + eventdirectory.listEventFiles(); |
| 27 | + |
| 28 | + storage = new EventStorage("./data/events/event.txt"); |
| 29 | + |
| 30 | + try{ |
| 31 | + eventList = storage.loadEvents(); |
| 32 | + } catch (FileNotFoundException e){ |
| 33 | + System.out.println("Making new file for Events"); |
| 34 | + eventList = new EventList(events); |
| 35 | + } |
7 | 36 |
|
8 |
| - public CalendarManager() { |
9 | 37 | calendar = new Calendar();
|
10 |
| - calendarUi = new CalendarUi(); |
| 38 | + calendarUi = new CalendarUi(eventList); |
11 | 39 | calendarCommandParser = new CalendarCommandParser();
|
| 40 | + scanner = new Scanner(System.in); |
| 41 | + |
12 | 42 | }
|
13 | 43 |
|
14 |
| - public void start() { |
| 44 | + public EventStorage getStorage(){ |
| 45 | + return this.storage; |
| 46 | + } |
| 47 | + |
| 48 | + public boolean validCommand(String input) { |
| 49 | + EventCommand command = calendarCommandParser.parseInput(input); |
| 50 | + |
| 51 | + return !(command instanceof UnknownCommand); |
| 52 | + } |
| 53 | + |
| 54 | + public boolean isResponsible(String input) { |
| 55 | + return validCommand(input); |
| 56 | + } |
| 57 | + |
| 58 | + public void processInput(String input) { |
| 59 | + startCalendar(input); |
| 60 | + |
| 61 | + storage.saveEvents(eventList.getEvent()); |
| 62 | + } |
15 | 63 |
|
| 64 | + public void startCalendar(String input) { |
| 65 | + EventCommand command = calendarCommandParser.parseInput(input); |
| 66 | + assert !(command instanceof seedu.duke.calendar.command.UnknownCommand) : |
| 67 | + "Command cannot be " + "unknown"; |
| 68 | + calendarUi.executeCommand(command); |
| 69 | + //calendarCommandParser.parseInput(command); |
16 | 70 | }
|
17 | 71 |
|
18 | 72 | }
|
0 commit comments