Worked on login, improved sdeleni a bit
This commit is contained in:
parent
1b9fef13d6
commit
8e74a0b96e
@ -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();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,8 @@ public class CredentialsInput extends DialogWindow {
|
||||
.addComponent(password)
|
||||
.addTo(mainPanel);
|
||||
|
||||
if(!LocalCredentials.getInstance().checkForExistingCredentials())
|
||||
{
|
||||
Panel rememberPanel = new Panel()
|
||||
.setLayoutManager(new GridLayout(3))
|
||||
.setLayoutData(GridLayout.createLayoutData(
|
||||
@ -112,6 +114,7 @@ public class CredentialsInput extends DialogWindow {
|
||||
rememberPanel.addComponent(new Label("Rembember?"))
|
||||
.addComponent(remember)
|
||||
.addTo(mainPanel);
|
||||
}
|
||||
|
||||
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));
|
||||
|
||||
|
@ -32,8 +32,7 @@ public class LoginController {
|
||||
{
|
||||
credentials = localCredentials.getCredentialsFile();
|
||||
}else{
|
||||
dialog = new CredentialsInput();
|
||||
Triplet<String, String, Boolean> data = dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user
|
||||
Triplet<String, String, Boolean> data = loginUsingGui(); // Failed to get credentials to log in, get them from user
|
||||
credentials = new String[] {data.getValue0(), data.getValue1()};
|
||||
|
||||
if(data.getValue2())
|
||||
@ -45,16 +44,11 @@ public class LoginController {
|
||||
loginUsingCredentials(credentials);
|
||||
}
|
||||
|
||||
public void loginUsingGui()
|
||||
public Triplet<String, String, Boolean> loginUsingGui()
|
||||
{
|
||||
dialog = new CredentialsInput();
|
||||
Triplet<String, String, Boolean> 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)
|
||||
|
@ -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'");
|
||||
|
@ -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()));
|
||||
|
@ -83,7 +83,8 @@ 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)
|
||||
@ -95,7 +96,9 @@ public class Rozvrh extends JecnaScrape {
|
||||
.findFirst()
|
||||
.map(m -> m.group(1))
|
||||
.orElse(e.text());
|
||||
timetableOptions.addOption(new Option(text, e.attr("value")));
|
||||
|
||||
boolean isDefault = e.hasAttr("selected");
|
||||
timetableOptions.addOption(new Option(text, e.attr("value"), isDefault));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import xyz.thastertyn.Types.Options;
|
||||
|
||||
public class Sdeleni extends JecnaScrape {
|
||||
|
||||
ArrayList<String> sdeleniList = new ArrayList<>();
|
||||
ArrayList<xyz.thastertyn.Types.Sdeleni> 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<String> getSdeleni()
|
||||
public ArrayList<xyz.thastertyn.Types.Sdeleni> 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 {}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
23
src/main/java/xyz/thastertyn/Types/Sdeleni.java
Normal file
23
src/main/java/xyz/thastertyn/Types/Sdeleni.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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{
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<String> sdeleniList = sdeleni.getSdeleni();
|
||||
ArrayList<xyz.thastertyn.Types.Sdeleni> 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)
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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()
|
||||
|
@ -36,6 +36,17 @@ public class OptionsDialog extends DialogWindow {
|
||||
boxs.add(new ComboBox<Option>(o.getOptions()));
|
||||
}
|
||||
|
||||
for(int i = 0; i < options.length; i++)
|
||||
{
|
||||
for(int j = 0; j < options[i].getOptions().size(); j++)
|
||||
{
|
||||
if(options[i].getOptions().get(j).isDefault())
|
||||
{
|
||||
boxs.get(i).setSelectedIndex(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Panel mainPanel = new Panel()
|
||||
.setLayoutManager(new GridLayout(1)
|
||||
.setLeftMarginSize(1)
|
||||
|
@ -0,0 +1,5 @@
|
||||
package xyz.thastertyn.UserInterface.Listeners;
|
||||
|
||||
public interface ContentResetListener {
|
||||
public void reset();
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.UserInterface;
|
||||
package xyz.thastertyn.UserInterface.Listeners;
|
||||
|
||||
public interface UpdateListener {
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package xyz.thastertyn.UserInterface;
|
||||
package xyz.thastertyn.UserInterface.Listeners;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -17,8 +17,6 @@ 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;
|
||||
import com.googlecode.lanterna.screen.Screen;
|
||||
import com.googlecode.lanterna.screen.Screen.RefreshType;
|
||||
|
||||
import xyz.thastertyn.UserInterface.Content.JecnaContent;
|
||||
import xyz.thastertyn.UserInterface.Content.OmluvnyList;
|
||||
@ -27,7 +25,7 @@ import xyz.thastertyn.UserInterface.Content.Sdeleni;
|
||||
import xyz.thastertyn.UserInterface.Content.Znamky;
|
||||
import xyz.thastertyn.UserInterface.Dialogs.EscapeDialog;
|
||||
|
||||
public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
public class WindowSwitchListener implements WindowListener, UpdateListener, ContentResetListener {
|
||||
private WindowBasedTextGUI textGUI;
|
||||
|
||||
private JecnaContent[] contents = {
|
||||
@ -42,14 +40,12 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
private Panel tabsPanel = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
||||
private Panel holderPanel = new Panel();
|
||||
private Screen screen;
|
||||
|
||||
int current = contents.length - 1;
|
||||
|
||||
public WindowSwitchListener(Panel holder, WindowBasedTextGUI textGUI, Screen screen)
|
||||
public WindowSwitchListener(Panel holder, WindowBasedTextGUI textGUI)
|
||||
{
|
||||
this.textGUI = textGUI;
|
||||
this.screen = screen;
|
||||
holder.addComponent(tabsPanel);
|
||||
holder.addComponent(holderPanel.withBorder(Borders.singleLine()));
|
||||
|
||||
@ -94,11 +90,6 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
|
||||
setPanelPreferedSize();
|
||||
updateLabels();
|
||||
try {
|
||||
screen.refresh(RefreshType.COMPLETE);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfDownloaded()
|
||||
@ -182,7 +173,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
}
|
||||
break;
|
||||
case Escape:
|
||||
EscapeDialog dialog = new EscapeDialog();
|
||||
EscapeDialog dialog = new EscapeDialog(textGUI, this);
|
||||
dialog.showDialog(textGUI);
|
||||
break;
|
||||
default:
|
||||
@ -213,4 +204,16 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
holderPanel.addComponent(contents[current].getPanel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
contents = new JecnaContent[] {
|
||||
new Rozvrh(this),
|
||||
new Znamky(this),
|
||||
new Sdeleni(this),
|
||||
new OmluvnyList(this)
|
||||
};
|
||||
loadPanel();
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
|
||||
import com.googlecode.lanterna.terminal.Terminal;
|
||||
|
||||
import xyz.thastertyn.Login.LoginController;
|
||||
import xyz.thastertyn.UserInterface.Listeners.WindowSwitchListener;
|
||||
|
||||
public class MainWindow {
|
||||
|
||||
@ -58,7 +59,7 @@ public class MainWindow {
|
||||
LoginController controller = new LoginController(textGUI);
|
||||
controller.login();
|
||||
|
||||
window.addWindowListener(new WindowSwitchListener(content, textGUI, screen));
|
||||
window.addWindowListener(new WindowSwitchListener(content, textGUI));
|
||||
|
||||
textGUI.addWindowAndWait(window);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user