diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java index e23ec75..e5744ea 100644 --- a/src/main/java/xyz/thastertyn/App.java +++ b/src/main/java/xyz/thastertyn/App.java @@ -12,30 +12,5 @@ public class App { MainWindow window = new MainWindow(); window.run(); - - /* - try { - - - - - - Document obedy = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/secured/month.jsp?terminal=false&keyboard=&printer=") - .header("Connection", "keep-alive") - .cookie("XSRF-TOKEN", XSRF_TOKEN) - .cookie("JSESSIONID", jidelnaJSESSIONID) - .get(); - - System.out.println(obedy.toString()); - - //#endregion - - } catch (IOException e) { - // TO DO Auto-generated catch block - e.printStackTrace(); - } catch (SecurityException e) - { - e.printStackTrace(); - }*/ } } diff --git a/src/main/java/xyz/thastertyn/Login/CredentialsInput.java b/src/main/java/xyz/thastertyn/Login/CredentialsInput.java index 6b7a078..a70ff32 100644 --- a/src/main/java/xyz/thastertyn/Login/CredentialsInput.java +++ b/src/main/java/xyz/thastertyn/Login/CredentialsInput.java @@ -101,18 +101,21 @@ public class CredentialsInput extends DialogWindow { .addComponent(password) .addTo(mainPanel); - Panel rememberPanel = new Panel() - .setLayoutManager(new GridLayout(3)) - .setLayoutData(GridLayout.createLayoutData( - GridLayout.Alignment.FILL, - Alignment.CENTER, - true, - false)); - - rememberPanel.addComponent(new Label("Rembember?")) - .addComponent(remember) - .addTo(mainPanel); - + if(!LocalCredentials.getInstance().checkForExistingCredentials()) + { + Panel rememberPanel = new Panel() + .setLayoutManager(new GridLayout(3)) + .setLayoutData(GridLayout.createLayoutData( + GridLayout.Alignment.FILL, + Alignment.CENTER, + true, + false)); + + rememberPanel.addComponent(new Label("Rembember?")) + .addComponent(remember) + .addTo(mainPanel); + } + mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); buttonPanel.setLayoutData( diff --git a/src/main/java/xyz/thastertyn/Login/LoginController.java b/src/main/java/xyz/thastertyn/Login/LoginController.java index 6a32de8..4a45ad7 100644 --- a/src/main/java/xyz/thastertyn/Login/LoginController.java +++ b/src/main/java/xyz/thastertyn/Login/LoginController.java @@ -32,29 +32,23 @@ public class LoginController { { credentials = localCredentials.getCredentialsFile(); }else{ - dialog = new CredentialsInput(); - Triplet data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user - credentials = new String[] {data.getValue0(), data.getValue1()}; + Triplet data = loginUsingGui(); // Failed to get credentials to log in, get them from user + credentials = new String[] {data.getValue0(), data.getValue1()}; - if(data.getValue2()) - { - localCredentials.saveCredentials(credentials); - } + if(data.getValue2()) + { + localCredentials.saveCredentials(credentials); + } } loginUsingCredentials(credentials); } - public void loginUsingGui() + public Triplet loginUsingGui() { dialog = new CredentialsInput(); - Triplet data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user - String[] credentials = new String[] {data.getValue0(), data.getValue1()}; - - if(data.getValue2()) - { - localCredentials.saveCredentials(credentials); - } + + return dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user } private void loginUsingCredentials(String[] credentials) diff --git a/src/main/java/xyz/thastertyn/Scrape/Jidelna.java b/src/main/java/xyz/thastertyn/Scrape/Jidelna.java index 2a754e8..9a9afbb 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Jidelna.java +++ b/src/main/java/xyz/thastertyn/Scrape/Jidelna.java @@ -7,6 +7,30 @@ import xyz.thastertyn.Types.Options; public class Jidelna extends JecnaScrape { + try { + + + + + + Document obedy = Jsoup.connect("https://objednavky.jidelnasokolska.cz/faces/secured/month.jsp?terminal=false&keyboard=&printer=") + .header("Connection", "keep-alive") + .cookie("XSRF-TOKEN", XSRF_TOKEN) + .cookie("JSESSIONID", jidelnaJSESSIONID) + .get(); + + System.out.println(obedy.toString()); + + //#endregion + + } catch (IOException e) { + // TO DO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) + { + e.printStackTrace(); + } + @Override public Options[] getOptions() { throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); diff --git a/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java b/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java index 846dd9b..b89de51 100644 --- a/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/Scrape/OmluvnyList.java @@ -61,7 +61,8 @@ public class OmluvnyList extends JecnaScrape { for(Element e : options) { - schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); + boolean isDefault = e.hasAttr("selected"); + schoolYearOptions.addOption(new Option(e.text(), e.attr("value"), isDefault)); } currentChoice = new Choice(Arrays.asList(schoolYearOptions.getOptions().get(0).getValue())); diff --git a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java index b9744dc..1ff1437 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/Scrape/Rozvrh.java @@ -83,19 +83,22 @@ public class Rozvrh extends JecnaScrape { for(Element e : schoolYear) { - schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); + boolean isDefault = e.hasAttr("selected"); + schoolYearOptions.addOption(new Option(e.text(), e.attr("value"), isDefault)); } for(Element e : timetableId) { String text = Pattern - .compile("(Od .* do .*)") - .matcher(e.text()) - .results() - .findFirst() - .map(m -> m.group(1)) - .orElse(e.text()); - timetableOptions.addOption(new Option(text, e.attr("value"))); + .compile("(Od .* do .*)") + .matcher(e.text()) + .results() + .findFirst() + .map(m -> m.group(1)) + .orElse(e.text()); + + boolean isDefault = e.hasAttr("selected"); + timetableOptions.addOption(new Option(text, e.attr("value"), isDefault)); } } diff --git a/src/main/java/xyz/thastertyn/Scrape/Sdeleni.java b/src/main/java/xyz/thastertyn/Scrape/Sdeleni.java index 4f50ab4..6f4c9d9 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/Scrape/Sdeleni.java @@ -13,7 +13,7 @@ import xyz.thastertyn.Types.Options; public class Sdeleni extends JecnaScrape { - ArrayList sdeleniList = new ArrayList<>(); + ArrayList sdeleniList = new ArrayList<>(); public void download() throws UnknownHostException, IOException { @@ -31,18 +31,11 @@ public class Sdeleni extends JecnaScrape { isPositive = spans.get(0).hasClass("sprite-icon-tick-16"); label = spans.get(1).text(); - if(isPositive) - { - label = "✓" + "\u00a0" + label; - }else{ - label = "✗" + "\u00a0" + label; - } - - sdeleniList.add(label); + sdeleniList.add(new xyz.thastertyn.Types.Sdeleni(label, isPositive)); } } - public ArrayList getSdeleni() + public ArrayList getSdeleni() { return sdeleniList; } @@ -53,6 +46,5 @@ public class Sdeleni extends JecnaScrape { } @Override - public void download(Choice choice) throws IOException { - } + public void download(Choice choice) throws IOException {} } diff --git a/src/main/java/xyz/thastertyn/Scrape/Znamky.java b/src/main/java/xyz/thastertyn/Scrape/Znamky.java index 63eff0f..fc47c0b 100644 --- a/src/main/java/xyz/thastertyn/Scrape/Znamky.java +++ b/src/main/java/xyz/thastertyn/Scrape/Znamky.java @@ -106,12 +106,14 @@ public class Znamky extends JecnaScrape { for(Element e : skolniRoky) { - schoolYearOptions.addOption(new Option(e.text(), e.attr("value"))); + boolean isDefault = e.hasAttr("selected"); + schoolYearOptions.addOption(new Option(e.text(), e.attr("value"), isDefault)); } for(Element e : pololeti) { - schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value"))); + boolean isDefault = e.hasAttr("selected"); + schoolHalfYearOptions.addOption(new Option(e.text(), e.attr("value"), isDefault)); } wasDownloaded = true; diff --git a/src/main/java/xyz/thastertyn/Types/Option.java b/src/main/java/xyz/thastertyn/Types/Option.java index 3b369d4..f87561d 100644 --- a/src/main/java/xyz/thastertyn/Types/Option.java +++ b/src/main/java/xyz/thastertyn/Types/Option.java @@ -4,22 +4,21 @@ public class Option { private String text; private String value; - public Option(String text, String value) { + private boolean isDefault; + public Option(String text, String value, boolean isDefault) { this.text = text; this.value = value; + this.isDefault = isDefault; + } + public boolean isDefault() { + return isDefault; } public String getText() { return text; } - public void setText(String text) { - this.text = text; - } public String getValue() { return value; } - public void setValue(String value) { - this.value = value; - } @Override public String toString() { return text; diff --git a/src/main/java/xyz/thastertyn/Types/Sdeleni.java b/src/main/java/xyz/thastertyn/Types/Sdeleni.java new file mode 100644 index 0000000..cc9cfc1 --- /dev/null +++ b/src/main/java/xyz/thastertyn/Types/Sdeleni.java @@ -0,0 +1,23 @@ +package xyz.thastertyn.Types; + +public class Sdeleni { + + private String text; + private boolean isPositive; + + public Sdeleni(String text, boolean isPositive) + { + this.text = text; + this.isPositive = isPositive; + } + + public boolean isPositive() + { + return isPositive; + } + + public String getText() + { + return text; + } +} diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java index 7418b86..ceb51dd 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/JecnaContent.java @@ -8,8 +8,8 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import xyz.thastertyn.Scrape.JecnaScrape; import xyz.thastertyn.Types.Choice; -import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog; +import xyz.thastertyn.UserInterface.Listeners.UpdateListener; /** diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java index 238644e..a78423d 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/OmluvnyList.java @@ -8,7 +8,7 @@ import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.Panel; -import xyz.thastertyn.UserInterface.UpdateListener; +import xyz.thastertyn.UserInterface.Listeners.UpdateListener; public class OmluvnyList extends JecnaContent{ diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java index fe5b46d..5d9005a 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Rozvrh.java @@ -8,7 +8,7 @@ import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.table.Table; import xyz.thastertyn.Types.Timetable; -import xyz.thastertyn.UserInterface.UpdateListener; +import xyz.thastertyn.UserInterface.Listeners.UpdateListener; public class Rozvrh extends JecnaContent { diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java index 595d7ff..a59fa19 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Sdeleni.java @@ -9,7 +9,7 @@ import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.Panel; -import xyz.thastertyn.UserInterface.UpdateListener; +import xyz.thastertyn.UserInterface.Listeners.UpdateListener; public class Sdeleni extends JecnaContent { @@ -30,22 +30,23 @@ public class Sdeleni extends JecnaContent { { mainPanel.removeAllComponents(); - ArrayList sdeleniList = sdeleni.getSdeleni(); + ArrayList sdeleniList = sdeleni.getSdeleni(); - for(String sdeleni : sdeleniList) + for(xyz.thastertyn.Types.Sdeleni sdeleni : sdeleniList) { Panel row = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); - String[] split = sdeleni.split("\u00a0"); - Label check = new Label(split[0]); - Label text = new Label(split[1]); + Label check = new Label(""); + Label text = new Label(sdeleni.getText()); - if(split[0].equals("✓")) + if(sdeleni.isPositive()) { check.setForegroundColor(ANSI.GREEN); + check.setText("✓"); }else{ check.setForegroundColor(ANSI.RED); + check.setText("✗"); } row.addComponent(check) diff --git a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java index aef3a48..f82f44b 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Content/Znamky.java @@ -15,7 +15,7 @@ import com.googlecode.lanterna.gui2.Panel; import xyz.thastertyn.Types.Predmet; import xyz.thastertyn.Types.Znamka; -import xyz.thastertyn.UserInterface.UpdateListener; +import xyz.thastertyn.UserInterface.Listeners.UpdateListener; public class Znamky extends JecnaContent { diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java index 0ccd1dc..a211193 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/EscapeDialog.java @@ -13,12 +13,18 @@ import com.googlecode.lanterna.gui2.dialogs.DialogWindow; import xyz.thastertyn.Login.LocalCredentials; import xyz.thastertyn.Login.LoginController; +import xyz.thastertyn.UserInterface.Listeners.ContentResetListener; public class EscapeDialog extends DialogWindow { - public EscapeDialog() + private WindowBasedTextGUI textGUI; + private ContentResetListener listener; + + public EscapeDialog(WindowBasedTextGUI textGUI, ContentResetListener listener) { super("Escape Menu"); + this.textGUI = textGUI; + this.listener = listener; Panel mainPanel = new Panel() .setLayoutManager(new GridLayout(1) @@ -45,16 +51,19 @@ public class EscapeDialog extends DialogWindow { public void onDeleteLogin() { + close(); LocalCredentials.getInstance().deleteCredentials(); - LoginController controller = new LoginController(getTextGUI()); + LoginController controller = new LoginController(textGUI); controller.loginUsingGui(); + listener.reset(); } public void onLogout() { close(); - LoginController controller = new LoginController(getTextGUI()); + LoginController controller = new LoginController(textGUI); controller.loginUsingGui(); + listener.reset(); } public void onExit() diff --git a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java index 41b2056..4aebbec 100644 --- a/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java +++ b/src/main/java/xyz/thastertyn/UserInterface/Dialogs/OptionsDialog.java @@ -36,6 +36,17 @@ public class OptionsDialog extends DialogWindow { boxs.add(new ComboBox