Taby, Downloader se nyni pouziva

This commit is contained in:
Thastertyn 2023-04-03 12:56:06 +02:00
parent c650fc5247
commit 43b2701151
19 changed files with 276 additions and 230 deletions

BIN
jecnak-tui.jar Normal file

Binary file not shown.

View File

@ -1,9 +1,8 @@
package xyz.thastertyn.ContentDisplay.Content; package xyz.thastertyn.ContentDisplay.Content;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Component;
import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.Label;
/** /**
* Wrapper to include all classes that deal with content in some way * Wrapper to include all classes that deal with content in some way
@ -11,9 +10,9 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
public abstract class JecnaContent { public abstract class JecnaContent {
public abstract Panel getPanel(); public abstract Panel getPanel();
public abstract void download(final String JsessionId); public abstract void download();
public abstract boolean hasStarted(); public abstract boolean hasStarted();
public abstract Border getLabel(); public abstract Label getLabel();
public abstract void specify(final int y, final int hy); public abstract void specify(final int y, final int hy);
public abstract void getOptions(final WindowBasedTextGUI textGUI); public abstract void getOptions(final WindowBasedTextGUI textGUI);
} }

View File

@ -4,26 +4,24 @@ import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.Component;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class OmluvnyList extends JecnaContent{ public class OmluvnyList extends JecnaContent{
private Panel omluvnyPanel = new Panel(); private Panel omluvnyPanel = new Panel();
private Label borderLabel = new Label("Omluvny L.");
private xyz.thastertyn.JecnaParse.OmluvnyList omluvnyList = new xyz.thastertyn.JecnaParse.OmluvnyList(); private xyz.thastertyn.JecnaParse.OmluvnyList omluvnyList = new xyz.thastertyn.JecnaParse.OmluvnyList();
private boolean hasStarted = false; private boolean hasStarted = false;
@Override @Override
public void download(final String JsessionId) { public void download() {
try{ try{
omluvnyList.downloadOmluvnyList(JsessionId); omluvnyList.downloadOmluvnyList();
ArrayList<Pair<String, String>> a = omluvnyList.getData(); ArrayList<Pair<String, String>> a = omluvnyList.getData();
@ -51,8 +49,8 @@ public class OmluvnyList extends JecnaContent{
} }
@Override @Override
public Border getLabel() { public Label getLabel() {
return new Label("Omluvny L.").withBorder(Borders.singleLine()); return borderLabel;
} }
@Override @Override

View File

@ -3,9 +3,6 @@ package xyz.thastertyn.ContentDisplay.Content;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.Component;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
@ -14,11 +11,11 @@ import com.googlecode.lanterna.gui2.table.Table;
public class Rozvrh extends JecnaContent { public class Rozvrh extends JecnaContent {
private Panel rozvrhPanel = new Panel(); private Panel rozvrhPanel = new Panel();
private Label borderLabel = new Label("Rozvrh");
private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh();
private boolean hasStarted = false; private boolean hasStarted = false;
private xyz.thastertyn.JecnaParse.Rozvrh rozvrh = new xyz.thastertyn.JecnaParse.Rozvrh();
private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"}; private String[] labels = {"Den", "7:30-8:15", "8:25-9:10", "9:20-10:05", "10:20-11:05", "11:15-12:00", "12:10-12:55", "13:05-13:50", "14:00-14:45", "14:55-15:40", "15:50-16:35"};
//private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."}; //private String[] labels = {"Den", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "10."};
@ -27,10 +24,10 @@ public class Rozvrh extends JecnaContent {
Table<String> t = new Table<>(labels); Table<String> t = new Table<>(labels);
@Override @Override
public void download(String Jsessionid) public void download()
{ {
try{ try{
rozvrh.downloadRozvrh(Jsessionid); rozvrh.downloadRozvrh();
String[][] rozvrhArray = rozvrh.getRozvrh(); String[][] rozvrhArray = rozvrh.getRozvrh();
@ -70,9 +67,9 @@ public class Rozvrh extends JecnaContent {
} }
@Override @Override
public Border getLabel() public Label getLabel()
{ {
return new Label("Rozvrh").withBorder(Borders.doubleLine()); return borderLabel;
} }
@Override @Override

View File

@ -5,26 +5,25 @@ import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.Component;
import com.googlecode.lanterna.gui2.GridLayout; import com.googlecode.lanterna.gui2.GridLayout;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class Sdeleni extends JecnaContent { public class Sdeleni extends JecnaContent {
private Panel sdeleniPanel = new Panel(); private Panel sdeleniPanel = new Panel();
private Label borderLabel = new Label("Sdeleni R.");
private boolean hasStarted = false;
private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni(); private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni();
private boolean hasStarted = false;
@Override @Override
public void download(String JsessionId) public void download()
{ {
if(!hasStarted) if(!hasStarted)
{ {
@ -34,7 +33,7 @@ public class Sdeleni extends JecnaContent {
.setLeftMarginSize(1) .setLeftMarginSize(1)
.setRightMarginSize(1)); .setRightMarginSize(1));
sdeleni.downloadSdeleni(JsessionId); sdeleni.downloadSdeleni();
ArrayList<Pair<String, Boolean>> sdeleniList = sdeleni.getSdeleni(); ArrayList<Pair<String, Boolean>> sdeleniList = sdeleni.getSdeleni();
@ -65,8 +64,8 @@ public class Sdeleni extends JecnaContent {
} }
@Override @Override
public Border getLabel() { public Label getLabel() {
return new Label("Sdeleni R.").withBorder(Borders.singleLine()); return borderLabel;
} }
@Override @Override

View File

@ -5,34 +5,54 @@ import java.util.ArrayList;
import com.googlecode.lanterna.TextColor; import com.googlecode.lanterna.TextColor;
import com.googlecode.lanterna.graphics.SimpleTheme; import com.googlecode.lanterna.graphics.SimpleTheme;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.Component;
import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Direction;
import com.googlecode.lanterna.gui2.GridLayout;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI; import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class Znamky extends JecnaContent { public class Znamky extends JecnaContent {
private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); private Panel mainPanel = new Panel()
.setLayoutManager(new GridLayout(3));
private Label borderLabel = new Label("Znamky");
private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky(); private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky();
private boolean hasStarted = false; private boolean hasStarted = false;
@Override @Override
public void download(String JsessionId) public void download()
{ {
try{ try{
znamky.downloadZnamky(JsessionId); znamky.downloadZnamky();
Panel predmetyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); Panel predmetyPanel = new Panel()
Panel znamkyP = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); .setLayoutManager(new LinearLayout(Direction.VERTICAL))
Panel vyslPanel = new Panel().setLayoutManager(new LinearLayout(Direction.VERTICAL)); .setLayoutData(GridLayout.createLayoutData(
GridLayout.Alignment.BEGINNING,
GridLayout.Alignment.BEGINNING,
false,
false));
Panel znamkyPanel = new Panel()
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
.setLayoutData(GridLayout.createLayoutData(
GridLayout.Alignment.BEGINNING,
GridLayout.Alignment.BEGINNING,
false,
false));
Panel vyslednaZnamkaPanel = new Panel().
setLayoutManager(new LinearLayout(Direction.VERTICAL))
.setLayoutData(GridLayout.createLayoutData(
GridLayout.Alignment.END,
GridLayout.Alignment.BEGINNING,
true,
false));
ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = znamky.getGrades(); ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = znamky.getGrades();
@ -44,18 +64,16 @@ public class Znamky extends JecnaContent {
for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> predmet : grades) for(Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>> predmet : grades)
{ {
predmetyPanel.addComponent(new Label(predmet.getValue0()));
Panel znamkyZPredmetu = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); Panel jednotliveZnamky = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
if(predmet.getValue1().getValue0().isEmpty()) if(predmet.getValue1().getValue0().isEmpty())
{ {
znamkyZPredmetu.addComponent(new Label("")); jednotliveZnamky.addComponent(new Label(""));
} }
for(Pair<Integer, Double> znamka : predmet.getValue1().getValue0()) for(Pair<Integer, Double> znamka : predmet.getValue1().getValue0())
{ {
// TODO pridat predmet.getValue0() ktery premeni znamky na jmeno predmetu jako funkci (not a bug, its a feature)
Label znamkaLabel = new Label(znamka.getValue0() + ""); Label znamkaLabel = new Label(znamka.getValue0() + "");
switch(znamka.getValue0()) switch(znamka.getValue0())
{ {
@ -80,11 +98,9 @@ public class Znamky extends JecnaContent {
break; break;
} }
znamkyZPredmetu.addComponent(znamkaLabel); jednotliveZnamky.addComponent(znamkaLabel);
} }
znamkyP.addComponent(znamkyZPredmetu);
double prumer = predmet.getValue1().getValue1(); double prumer = predmet.getValue1().getValue1();
Label vysl = new Label(String.format("%.2f", prumer)); Label vysl = new Label(String.format("%.2f", prumer));
@ -108,24 +124,26 @@ public class Znamky extends JecnaContent {
vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny)); vysl.setTheme(new SimpleTheme(TextColor.ANSI.BLACK, nedostatecny));
} }
vyslPanel.addComponent(vysl); znamkyPanel.addComponent(jednotliveZnamky);
predmetyPanel.addComponent(new Label(predmet.getValue0()));
vyslednaZnamkaPanel.addComponent(vysl);
} }
znamkyPanel.addComponent(predmetyPanel); mainPanel.addComponent(predmetyPanel);
znamkyPanel.addComponent(znamkyP); mainPanel.addComponent(znamkyPanel);
znamkyPanel.addComponent(vyslPanel); mainPanel.addComponent(vyslednaZnamkaPanel);
hasStarted = true; hasStarted = true;
}catch(IOException e) }catch(IOException e)
{ {
znamkyPanel.addComponent(new Label("An error has occured")); mainPanel.addComponent(new Label("An error has occured"));
} }
} }
@Override @Override
public Panel getPanel() public Panel getPanel()
{ {
return znamkyPanel; return mainPanel;
} }
@Override @Override
@ -135,9 +153,9 @@ public class Znamky extends JecnaContent {
} }
@Override @Override
public Border getLabel() public Label getLabel()
{ {
return new Label("Znamky").withBorder(Borders.singleLine()); return borderLabel;
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.Button; import com.googlecode.lanterna.gui2.Button;
import com.googlecode.lanterna.gui2.CheckBox;
import com.googlecode.lanterna.gui2.EmptySpace; import com.googlecode.lanterna.gui2.EmptySpace;
import com.googlecode.lanterna.gui2.GridLayout; import com.googlecode.lanterna.gui2.GridLayout;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
@ -17,7 +18,7 @@ import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Triplet;
public class CredentialsInput extends DialogWindow { public class CredentialsInput extends DialogWindow {
@ -26,7 +27,7 @@ public class CredentialsInput extends DialogWindow {
private String user; private String user;
private String pass; private String pass;
//private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login(); private CheckBox remember;
CredentialsInput() CredentialsInput()
{ {
@ -35,6 +36,7 @@ public class CredentialsInput extends DialogWindow {
this.pass = null; this.pass = null;
this.username = new TextBox(); this.username = new TextBox();
this.password = new TextBox().setMask('*'); this.password = new TextBox().setMask('*');
this.remember = new CheckBox();
Panel buttonPanel = new Panel(); Panel buttonPanel = new Panel();
buttonPanel buttonPanel
@ -99,6 +101,18 @@ public class CredentialsInput extends DialogWindow {
.addComponent(password) .addComponent(password)
.addTo(mainPanel); .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);
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
buttonPanel.setLayoutData( buttonPanel.setLayoutData(
@ -132,8 +146,8 @@ public class CredentialsInput extends DialogWindow {
} }
@Override @Override
public Pair<String, String> showDialog(WindowBasedTextGUI textGUI) { public Triplet<String, String, Boolean> showDialog(WindowBasedTextGUI textGUI) {
super.showDialog(textGUI); super.showDialog(textGUI);
return new Pair<String, String>(user, pass); return new Triplet<String,String,Boolean>(user, pass, remember.isChecked());
} }
} }

View File

@ -14,7 +14,7 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog; import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton; import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Triplet;
public class LoginController { public class LoginController {
@ -31,13 +31,16 @@ public class LoginController {
public void login() public void login()
{ {
if(checkForCredentials()) // Credentials exist if(checkForCredentials()) // Credentials exist
{
if(loginUsingCredentials()) // They are accessible and can read them if(loginUsingCredentials()) // They are accessible and can read them
{
return; return;
}
}
try try
{ {
Pair<String, String> data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user Triplet<String, String, Boolean> data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user
login.loginJecna(data.getValue0(), data.getValue1()); login.loginJecna(data.getValue0(), data.getValue1());
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
MessageDialog.showMessageDialog(textGUI, "No Internet connection", MessageDialog.showMessageDialog(textGUI, "No Internet connection",
@ -54,10 +57,9 @@ public class LoginController {
{ {
MessageDialog.showMessageDialog(textGUI, "There was an error", MessageDialog.showMessageDialog(textGUI, "There was an error",
"Maybe try again and it will go away", "Maybe try again and it will go away",
MessageDialogButton.OK); MessageDialogButton.Retry);
return; return;
} }
} }
/** /**
@ -182,9 +184,4 @@ public class LoginController {
return true; return true;
} }
public String getJSessesionId()
{
return login.getJSESSIONID();
}
} }

View File

@ -9,7 +9,6 @@ import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.DefaultWindowManager; import com.googlecode.lanterna.gui2.DefaultWindowManager;
import com.googlecode.lanterna.gui2.Direction; import com.googlecode.lanterna.gui2.Direction;
import com.googlecode.lanterna.gui2.EmptySpace; import com.googlecode.lanterna.gui2.EmptySpace;
import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout; import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.MultiWindowTextGUI; import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
@ -51,11 +50,6 @@ public class MainWindow {
window.setComponent(mainPanel); window.setComponent(mainPanel);
Panel tabs = new Panel()
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
mainPanel.addComponent(tabs);
String title = "Jecnak"; String title = "Jecnak";
Panel content = new Panel(); Panel content = new Panel();
@ -64,7 +58,7 @@ public class MainWindow {
LoginController controller = new LoginController(textGUI); LoginController controller = new LoginController(textGUI);
controller.login(); controller.login();
window.addWindowListener(new WindowSwitchListener(content, controller.getJSessesionId(), tabs, title)); window.addWindowListener(new WindowSwitchListener(content, title));
textGUI.addWindowAndWait(window); textGUI.addWindowAndWait(window);

View File

@ -4,12 +4,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
import com.googlecode.lanterna.TerminalPosition; import com.googlecode.lanterna.TerminalPosition;
import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.Border;
import com.googlecode.lanterna.gui2.Borders; import com.googlecode.lanterna.gui2.Borders;
import com.googlecode.lanterna.gui2.Direction;
import com.googlecode.lanterna.gui2.Label; import com.googlecode.lanterna.gui2.Label;
import com.googlecode.lanterna.gui2.LinearLayout;
import com.googlecode.lanterna.gui2.Panel; import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.gui2.Window;
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import com.googlecode.lanterna.gui2.WindowListener; import com.googlecode.lanterna.gui2.WindowListener;
import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyStroke;
import com.googlecode.lanterna.input.KeyType; import com.googlecode.lanterna.input.KeyType;
@ -22,38 +22,32 @@ import xyz.thastertyn.ContentDisplay.Content.Znamky;
public class WindowSwitchListener implements WindowListener { public class WindowSwitchListener implements WindowListener {
WindowBasedTextGUI gui;
private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni(), new OmluvnyList()}; private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni(), new OmluvnyList()};
private Border[] tabs = new Border[contents.length]; private Label[] tabs = new Label[contents.length];
private Panel tabsPanel; private Panel tabsPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
private Panel content; private Panel content = new Panel();
private String JsessionId; private Panel errorPanel = new Panel().addComponent(new Label("Something went wrong"));
int current = 0; int current = contents.length - 1;
public WindowSwitchListener(Panel holder, String JsessionId, Panel tabs, String title) public WindowSwitchListener(Panel holder, String title)
{ {
this.content = holder; holder.addComponent(tabsPanel);
this.tabsPanel = tabs; holder.addComponent(content.withBorder(Borders.singleLine()));
this.JsessionId = JsessionId;
addTabs(); for(int i = 0; i < contents.length; i++)
defaultPanel(); {
this.tabs[i] = contents[i].getLabel();
tabsPanel.addComponent(this.tabs[i]);
}
next();
} }
private void defaultPanel() private void next()
{ {
contents[0].download(JsessionId);
content.removeAllComponents();
content.addComponent(contents[0].getPanel());
}
public void next()
{
// tabs.getChildrenList().get(current).withBorder(Borders.singleLine());
if(current + 1 == contents.length) if(current + 1 == contents.length)
{ {
current = 0; current = 0;
@ -63,39 +57,37 @@ public class WindowSwitchListener implements WindowListener {
if(!contents[current].hasStarted()) if(!contents[current].hasStarted())
{ {
contents[current].download(JsessionId); contents[current].download();
} }
// tabs[current].getComponent().withBorder(Borders.doubleLine());
content.removeAllComponents(); content.removeAllComponents();
content.addComponent(contents[current].getPanel()); tabsPanel.removeAllComponents();
} if(contents[current].hasStarted())
public void previous()
{
if(current - 1 == -1)
{ {
current = contents.length - 1; int tabColumns = tabsPanel.getSize().getColumns();
if(contents[current].getPanel().getSize().getColumns() < tabColumns)
{
content.addComponent(
contents[current].getPanel().setPreferredSize(new TerminalSize(tabColumns,
contents[current].getPanel().getPreferredSize().getRows())));
}else{
content.addComponent(contents[current].getPanel());
}
}else{ }else{
current--; content.addComponent(errorPanel);
} }
if(!contents[current].hasStarted()) for(int i = 0; i < tabs.length; i++)
{ {
contents[current].download(JsessionId); if(i == current)
} {
content.removeAllComponents(); tabsPanel.addComponent(tabs[i].withBorder(Borders.doubleLine()));
content.addComponent(contents[current].getPanel()); }else{
} tabsPanel.addComponent(tabs[i].withBorder(Borders.singleLine()));
}
private void addTabs()
{
for(int i = 0; i < contents.length; i++)
{
tabs[i] = contents[i].getLabel();
tabsPanel.addComponent(tabs[i]);
} }
} }
@ -106,12 +98,7 @@ public class WindowSwitchListener implements WindowListener {
switch(type) switch(type)
{ {
case Tab: case Tab:
if(!keyStroke.isShiftDown()) next();
{
next();
}else{
previous();
}
break; break;
default: default:
break; break;

View File

@ -1,32 +0,0 @@
package xyz.thastertyn.JecnaParse;
import java.io.IOException;
import java.util.HashMap;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import xyz.thastertyn.Tuple.Pair;
public class Dochazka {
private HashMap<String, Pair<String, String>> absence = new HashMap<>();
public byte downloadAbsence(String JSESSIOND)
{
Document absenceDoc;
try {
// absence-list
absenceDoc = Jsoup.connect("https://www.spsejecna.cz" + "/absence/passing-student")
.cookie("JSESSIOND", JSESSIOND)
.cookie("role", "student")
.header("Connection", "keep-alive")
.get();
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
}

View File

@ -5,11 +5,19 @@ import org.jsoup.Jsoup;
public class Downloader { public class Downloader {
public static Connection download(String url, String Jsessionid) private static String JsessionId;
public static Connection download(String url)
{ {
return Jsoup.connect(url) Connection c = Jsoup.connect(url)
.header("Connection", "keep-alive") .header("Connection", "keep-alive")
.cookie("role", "student") .cookie("role", "student")
.cookie("JSESSIONID", Jsessionid); .cookie("JSESSIONID", JsessionId);
return c;
}
public static void setJSessionId(String JsId)
{
JsessionId = JsId;
} }
} }

View File

@ -18,12 +18,6 @@ public class Login {
private long start; private long start;
private long lastCheck; private long lastCheck;
public String getJSESSIONID()
{
return Jsessionid;
}
public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException public void loginJecna(String user, String pass) throws UnknownHostException, IOException, CredentialException
{ {
//#region JSESSIONID //#region JSESSIONID
@ -33,6 +27,7 @@ public class Login {
.execute(); .execute();
Jsessionid = response.cookie("JSESSIONID"); Jsessionid = response.cookie("JSESSIONID");
Downloader.setJSessionId(Jsessionid);
//#endregion //#endregion
//#region Token3 //#region Token3

View File

@ -8,7 +8,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class OmluvnyList { public class OmluvnyList {
@ -16,9 +16,9 @@ public class OmluvnyList {
private boolean wasDownloaded = false; private boolean wasDownloaded = false;
public void downloadOmluvnyList(final String JsessionId) throws UnknownHostException, IOException public void downloadOmluvnyList() throws UnknownHostException, IOException
{ {
Document doc = Downloader.download("https://www.spsejecna.cz/absence/student", JsessionId).get(); Document doc = Downloader.download("https://www.spsejecna.cz/absence/student").get();
Elements omluv = doc.select("table.absence-list").select("tr"); Elements omluv = doc.select("table.absence-list").select("tr");

View File

@ -50,9 +50,9 @@ public class Rozvrh {
* @throws UnknownHostException kdyz neni pripojeni k internetu * @throws UnknownHostException kdyz neni pripojeni k internetu
* @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom * @throws IOException ostatni exceptiony nejsou dulezite, tak jsou zahrnuty v jednom
*/ */
public void downloadRozvrh(final String Jsessionid) throws UnknownHostException, IOException public void downloadRozvrh() throws UnknownHostException, IOException
{ {
Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class", Jsessionid).get(); Document rozvrhDoc = Downloader.download("https://www.spsejecna.cz" + "/timetable/class").get();
Elements rozvrhTable = rozvrhDoc.select("table.timetable").select("tr"); Elements rozvrhTable = rozvrhDoc.select("table.timetable").select("tr");
Elements[] rozvrhDny = new Elements[rozvrhTable.size()]; Elements[] rozvrhDny = new Elements[rozvrhTable.size()];

View File

@ -8,15 +8,15 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class Sdeleni { public class Sdeleni {
ArrayList<Pair<String, Boolean>> sdeleniList = new ArrayList<>(); ArrayList<Pair<String, Boolean>> sdeleniList = new ArrayList<>();
public void downloadSdeleni(final String JsessionId) throws UnknownHostException, IOException public void downloadSdeleni() throws UnknownHostException, IOException
{ {
Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list", JsessionId).get(); Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list").get();
Elements sdeleni = sdeleniDoc.select("ul.list li"); Elements sdeleni = sdeleniDoc.select("ul.list li");

View File

@ -10,7 +10,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import xyz.thastertyn.Tuple.Pair; import xyz.thastertyn.Tuples.Pair;
public class Znamky { public class Znamky {
@ -21,50 +21,10 @@ public class Znamky {
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti // Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
private ArrayList<Pair<Integer, Boolean>> options = new ArrayList<>(); private ArrayList<Pair<Integer, Boolean>> options = new ArrayList<>();
private void addGrade(int index, String subject, int grade, double weight) public void downloadZnamky(/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
{ {
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
grades.get(index).getValue1().getValue0().add(znamka);
}
private void addSubject(String subject)
{
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
grades.add(new Pair<>(subject, p));
}
private double getAverage(ArrayList<Pair<Integer, Double>> a)
{
try{
double divident = 0;
double divisor = 0;
for(Pair<Integer, Double> p : a)
{
if(p.getValue0() == -1)
{
continue;
}
divident += p.getValue0() * p.getValue1();
divisor += p.getValue1();
}
double prumer = (double) divident / divisor;
return (double) Math.round(prumer * 100) / 100;
}catch(ArithmeticException e)
{
return 0;
}
}
public void downloadZnamky(final String Jsessionid/*, int schoolYearId, int schoolYearHalfId*/) throws UnknownHostException, IOException
{
wasDownloaded = true;
//String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId); //String url = String.format("https://www.spsejecna.cz/score/student?schoolYearId=%d&schoolYearHalfId=%d", schoolYearId, schoolYearHalfId);
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student", Jsessionid).get(); Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student").get();
Elements rows = znamkyDoc.select("table.score").select("tr"); Elements rows = znamkyDoc.select("table.score").select("tr");
@ -114,6 +74,8 @@ public class Znamky {
grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0())); grades.get(subj).getValue1().setValue1(getAverage(grades.get(subj).getValue1().getValue0()));
subj++; subj++;
} }
/* /*
Elements roky = znamkyDoc.select("select[name=schoolYearId]"); Elements roky = znamkyDoc.select("select[name=schoolYearId]");
Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]"); Elements pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]");
@ -131,8 +93,51 @@ public class Znamky {
options.add(new Pair<Integer, Boolean>(rok, jeCelyRok)); options.add(new Pair<Integer, Boolean>(rok, jeCelyRok));
}*/ }*/
wasDownloaded = true;
} }
private void addGrade(int index, String subject, int grade, double weight)
{
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
grades.get(index).getValue1().getValue0().add(znamka);
}
private void addSubject(String subject)
{
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
grades.add(new Pair<>(subject, p));
}
private double getAverage(ArrayList<Pair<Integer, Double>> a)
{
try{
double divident = 0;
double divisor = 0;
for(Pair<Integer, Double> p : a)
{
if(p.getValue0() == -1)
{
continue;
}
divident += p.getValue0() * p.getValue1();
divisor += p.getValue1();
}
double prumer = (double) divident / divisor;
return (double) Math.round(prumer * 100) / 100;
}catch(ArithmeticException e)
{
return 0;
}
}
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades() public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
{ {
return grades; return grades;

View File

@ -1,10 +1,11 @@
package xyz.thastertyn.Tuple; package xyz.thastertyn.Tuples;
/** /**
* Ekvitalent Tuplu, ktery neni zabudovan v jave * Ekvitalent Tuplu, ktery neni zabudovan v jave
*/ */
public class Pair<T1, T2> { public class Pair<T1, T2> {
private T1 value0; private T1 value0;
private T2 value1; private T2 value1;

View File

@ -0,0 +1,66 @@
package xyz.thastertyn.Tuples;
/**
* Ekvitalent Tuplu, ktery neni zabudovan v jave
*/
public class Triplet<T1, T2, T3> {
private T1 value0;
private T2 value1;
private T3 value2;
public Triplet(T1 value0, T2 value1, T3 value2)
{
this.value0 = value0;
this.value1 = value1;
this.value2 = value2;
}
public Triplet()
{
}
public void put(T1 value0, T2 value1, T3 value2)
{
this.value0 = value0;
this.value1 = value1;
this.value2 = value2;
}
public T1 getValue0()
{
return value0;
}
public T2 getValue1()
{
return value1;
}
public T3 getValue2()
{
return value2;
}
public void setValue0(T1 value0)
{
this.value0 = value0;
}
public void setValue1(T2 value1)
{
this.value1 = value1;
}
public void setValue2(T3 value2)
{
this.value2 = value2;
}
@Override
public String toString()
{
return "[" + value0 + ", " + value1 + "]";
}
}