diff --git a/.gitignore b/.gitignore
index 5241a72..02fc84b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-*.class
\ No newline at end of file
+*.class
+jecnak-tui.jar
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 42ea84b..de2a843 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,3 +1,3 @@
{
- "java.configuration.updateBuildConfiguration": "interactive"
+ "java.configuration.updateBuildConfiguration": "automatic"
}
\ No newline at end of file
diff --git a/jecnak-tui.jar b/jecnak-tui.jar
deleted file mode 100644
index b6b25ca..0000000
Binary files a/jecnak-tui.jar and /dev/null differ
diff --git a/pom.xml b/pom.xml
index ceeb515..01a0c0e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,8 +14,8 @@
UTF-8
- 1.8
- 1.8
+ 11
+ 11
@@ -26,14 +26,6 @@
1.15.3
-
-
- com.google.code.gson
- gson
- 2.10.1
-
-
-
com.googlecode.lanterna
lanterna
diff --git a/src/main/java/xyz/thastertyn/App.java b/src/main/java/xyz/thastertyn/App.java
index 3dd77f6..0eca844 100644
--- a/src/main/java/xyz/thastertyn/App.java
+++ b/src/main/java/xyz/thastertyn/App.java
@@ -13,7 +13,6 @@ public class App {
MainWindow window = new MainWindow();
window.run();
-
/*
try {
@@ -32,7 +31,7 @@ public class App {
//#endregion
} catch (IOException e) {
- // TODO Auto-generated catch block
+ // TO DO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e)
{
diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java
index 9987659..5f9e323 100644
--- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java
+++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/OmluvnyList.java
@@ -29,12 +29,13 @@ public class OmluvnyList extends JecnaContent{
{
omluvnyPanel.addComponent(new Label(p.getValue0() + " - " + p.getValue1()));
}
+ hasStarted = true;
}catch(UnknownHostException e)
{
- omluvnyPanel.addComponent(new Label("A connection error occurred"));
+ // omluvnyPanel.addComponent(new Label("A connection error occurred"));
}catch(IOException e)
{
- omluvnyPanel.addComponent(new Label("An error occurred"));
+ // omluvnyPanel.addComponent(new Label("An error occurred"));
}
}
diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java
index b47e785..2df15a5 100644
--- a/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java
+++ b/src/main/java/xyz/thastertyn/ContentDisplay/Content/Sdeleni.java
@@ -10,8 +10,6 @@ import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
-import xyz.thastertyn.Tuples.Pair;
-
public class Sdeleni extends JecnaContent {
private Panel sdeleniPanel = new Panel();
@@ -28,29 +26,17 @@ public class Sdeleni extends JecnaContent {
if(!hasStarted)
{
try{
-
sdeleniPanel.setLayoutManager(new GridLayout(1)
.setLeftMarginSize(1)
.setRightMarginSize(1));
sdeleni.downloadSdeleni();
- ArrayList> sdeleniList = sdeleni.getSdeleni();
+ ArrayList sdeleniList = sdeleni.getSdeleni();
- for(Pair p : sdeleniList)
+ for(String s : sdeleniList)
{
- String label = "";
-
- if(p.getValue1())
- {
- label += "✅";
- }else{
- label += "❌";
- }
-
- label += " " + p.getValue0();
-
- sdeleniPanel.addComponent(new Label(label));
+ sdeleniPanel.addComponent(new Label(s));
}
hasStarted = true;
}catch(UnknownHostException e)
diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java
index 9128738..10c445f 100644
--- a/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java
+++ b/src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java
@@ -18,10 +18,9 @@ import xyz.thastertyn.Tuples.Triplet;
public class LoginController {
+ private WindowBasedTextGUI textGUI;
+ private xyz.thastertyn.ContentDisplay.CredentialsInput dialog;
private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login();
- private xyz.thastertyn.ContentDisplay.CredentialsInput dialog = new CredentialsInput();
-
- private WindowBasedTextGUI textGUI = null;
public LoginController(WindowBasedTextGUI textGUI)
{
@@ -30,6 +29,7 @@ public class LoginController {
public void login()
{
+ dialog = new CredentialsInput();
if(checkForCredentials()) // Credentials exist
{
if(loginUsingCredentials()) // They are accessible and can read them
@@ -38,27 +38,27 @@ public class LoginController {
}
}
+ Triplet data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user
try
{
- Triplet data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user
login.loginJecna(data.getValue0(), data.getValue1());
} catch (UnknownHostException e) {
MessageDialog.showMessageDialog(textGUI, "No Internet connection",
"There seems to be no internet connection, reverting to cached data",
MessageDialogButton.OK);
- return;
+ login();
} catch (CredentialException e)
{
MessageDialog.showMessageDialog(textGUI, "Incorrect username or password",
"The username or password you entered is incorrect",
MessageDialogButton.OK);
- return;
+ login();
} catch (IOException e)
{
MessageDialog.showMessageDialog(textGUI, "There was an error",
"Maybe try again and it will go away",
MessageDialogButton.Retry);
- return;
+ login();
}
}
diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java
index cd7ead7..a68649b 100644
--- a/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java
+++ b/src/main/java/xyz/thastertyn/ContentDisplay/MainWindow.java
@@ -58,7 +58,7 @@ public class MainWindow {
LoginController controller = new LoginController(textGUI);
controller.login();
- window.addWindowListener(new WindowSwitchListener(content, title));
+ window.addWindowListener(new WindowSwitchListener(content, title, textGUI));
textGUI.addWindowAndWait(window);
diff --git a/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java
index f581ca6..f42fcfb 100644
--- a/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java
+++ b/src/main/java/xyz/thastertyn/ContentDisplay/WindowSwitchListener.java
@@ -10,7 +10,10 @@ import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.Window;
+import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.WindowListener;
+import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
+import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
import com.googlecode.lanterna.input.KeyStroke;
import com.googlecode.lanterna.input.KeyType;
@@ -22,20 +25,29 @@ import xyz.thastertyn.ContentDisplay.Content.Znamky;
public class WindowSwitchListener implements WindowListener {
- private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni(), new OmluvnyList()};
+ private WindowBasedTextGUI textGUI;
+
+ private JecnaContent[] contents = {
+ new Rozvrh(),
+ new Znamky(),
+ new Sdeleni(),
+ new OmluvnyList()
+ };
+
private Label[] tabs = new Label[contents.length];
private Panel tabsPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
- private Panel content = new Panel();
+ private Panel holderPanel = new Panel();
private Panel errorPanel = new Panel().addComponent(new Label("Something went wrong"));
int current = contents.length - 1;
- public WindowSwitchListener(Panel holder, String title)
+ public WindowSwitchListener(Panel holder, String title, WindowBasedTextGUI textGUI)
{
+ this.textGUI = textGUI;
holder.addComponent(tabsPanel);
- holder.addComponent(content.withBorder(Borders.singleLine()));
+ holder.addComponent(holderPanel.withBorder(Borders.singleLine()));
for(int i = 0; i < contents.length; i++)
{
@@ -60,7 +72,7 @@ public class WindowSwitchListener implements WindowListener {
contents[current].download();
}
- content.removeAllComponents();
+ holderPanel.removeAllComponents();
tabsPanel.removeAllComponents();
if(contents[current].hasStarted())
@@ -69,15 +81,15 @@ public class WindowSwitchListener implements WindowListener {
if(contents[current].getPanel().getSize().getColumns() < tabColumns)
{
- content.addComponent(
+ holderPanel.addComponent(
contents[current].getPanel().setPreferredSize(new TerminalSize(tabColumns,
contents[current].getPanel().getPreferredSize().getRows())));
}else{
- content.addComponent(contents[current].getPanel());
+ holderPanel.addComponent(contents[current].getPanel());
}
}else{
- content.addComponent(errorPanel);
+ holderPanel.addComponent(errorPanel);
}
for(int i = 0; i < tabs.length; i++)
@@ -100,6 +112,15 @@ public class WindowSwitchListener implements WindowListener {
case Tab:
next();
break;
+ case Character:
+ if(keyStroke.getCharacter() == ' ')
+ {
+ MessageDialog.showMessageDialog(textGUI, "Space pressed", "Good job", MessageDialogButton.OK);
+ }
+ break;
+ case Escape:
+ MessageDialog.showMessageDialog(textGUI, "Options", "Loging out and some other stuff soon", MessageDialogButton.OK);
+ break;
default:
break;
}
diff --git a/src/main/java/xyz/thastertyn/JecnaParse/JecnaParser.java b/src/main/java/xyz/thastertyn/JecnaParse/JecnaParser.java
new file mode 100644
index 0000000..85f9bf2
--- /dev/null
+++ b/src/main/java/xyz/thastertyn/JecnaParse/JecnaParser.java
@@ -0,0 +1,5 @@
+package xyz.thastertyn.JecnaParse;
+
+public class JecnaParser {
+
+}
diff --git a/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java b/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java
index b558dbc..04a5d91 100644
--- a/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java
+++ b/src/main/java/xyz/thastertyn/JecnaParse/OmluvnyList.java
@@ -14,8 +14,6 @@ public class OmluvnyList {
private ArrayList> data = new ArrayList<>();
- private boolean wasDownloaded = false;
-
public void downloadOmluvnyList() throws UnknownHostException, IOException
{
Document doc = Downloader.download("https://www.spsejecna.cz/absence/student").get();
@@ -29,12 +27,16 @@ public class OmluvnyList {
data.add(new Pair(date, text));
}
-
- wasDownloaded = true;
}
public ArrayList> getData()
{
return data;
}
+
+ @Override
+ public String toString()
+ {
+ return (!data.isEmpty()) ? data.toString() : null;
+ }
}
diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java
index 340e237..67a00e0 100644
--- a/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java
+++ b/src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java
@@ -8,11 +8,9 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
-import xyz.thastertyn.Tuples.Pair;
-
public class Sdeleni {
- ArrayList> sdeleniList = new ArrayList<>();
+ ArrayList sdeleniList = new ArrayList<>();
public void downloadSdeleni() throws UnknownHostException, IOException
{
@@ -29,19 +27,19 @@ public class Sdeleni {
isPositive = spans.get(0).hasClass("sprite-icon-tick-16");
label = spans.get(1).text();
-
- //if(!label.startsWith(" "))
- //{
- // label = " " + label;
- //}
- //label = label.replaceAll("\\s+$", "");
+ if(isPositive)
+ {
+ label = "✅" + " " + label;
+ }else{
+ label = "❌" + " " + label;
+ }
- sdeleniList.add(new Pair(label, isPositive));
+ sdeleniList.add(label);
}
}
- public ArrayList> getSdeleni()
+ public ArrayList getSdeleni()
{
return sdeleniList;
}
diff --git a/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java
index 33253b3..6ad9fe0 100644
--- a/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java
+++ b/src/main/java/xyz/thastertyn/JecnaParse/Znamky.java
@@ -19,7 +19,7 @@ public class Znamky {
private ArrayList>,Double>>> grades = new ArrayList<>();
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
- private ArrayList> options = new ArrayList<>();
+ private Pair, ArrayList> options = new Pair<>();
public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
{
@@ -75,24 +75,28 @@ public class Znamky {
subj++;
}
+ Element optionsPanel = znamkyDoc.selectFirst("form.listConfigure");
-/*
- Elements roky = znamkyDoc.select("select[name=schoolYearId]");
- Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]");
+ Elements schoolYear = optionsPanel.select("select[id=schoolYearId]").select("option");
+ Elements schoolYearId = optionsPanel.select("select[id=schoolYearHalfId]").select("option");
- for(Element e : roky)
- {
- boolean jeCelyRok = false;
-
- if(pololetiSelect.size() == 2)
+ /*
+ Elements roky = znamkyDoc.select("select[name=schoolYearId]");
+ Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]");
+
+ for(Element e : roky)
{
- jeCelyRok = true;
- }
+ boolean jeCelyRok = false;
+
+ if(pololetiSelect.size() == 2)
+ {
+ jeCelyRok = true;
+ }
- int rok = Integer.parseInt(e.attr("value"));
+ int rok = Integer.parseInt(e.attr("value"));
- options.add(new Pair(rok, jeCelyRok));
- }*/
+ options.add(new Pair(rok, jeCelyRok));
+ }*/
wasDownloaded = true;
@@ -143,11 +147,6 @@ public class Znamky {
return grades;
}
- public ArrayList> getOptions()
- {
- return options;
- }
-
@Override
public String toString()
{
diff --git a/src/test/java/xyz/thastertyn/AppTest.java b/src/test/java/xyz/thastertyn/AppTest.java
index cf34326..46059fa 100644
--- a/src/test/java/xyz/thastertyn/AppTest.java
+++ b/src/test/java/xyz/thastertyn/AppTest.java
@@ -17,4 +17,23 @@ public class AppTest
{
assertTrue( true );
}
+
+ @Test
+ public void hasJavaAbove11()
+ {
+ // https://stackoverflow.com/questions/2591083/getting-java-version-at-runtime#2591122
+ String version = System.getProperty("java.version");
+ int v;
+
+ if(version.startsWith("1."))
+ {
+ version = version.substring(2, 3);
+ }else {
+ int dot = version.indexOf(".");
+ if(dot != -1) { version = version.substring(0, dot); }
+ }
+ v = Integer.parseInt(version);
+
+ assertTrue("Java >= 11 is required", (v >= 11));
+ }
}