Worked on login, improved sdeleni a bit

This commit is contained in:
Thastertyn 2023-05-12 16:56:45 +02:00
parent 1b9fef13d6
commit 8e74a0b96e
21 changed files with 157 additions and 111 deletions

View File

@ -12,30 +12,5 @@ public class App {
MainWindow window = new MainWindow(); MainWindow window = new MainWindow();
window.run(); 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();
}*/
} }
} }

View File

@ -101,17 +101,20 @@ public class CredentialsInput extends DialogWindow {
.addComponent(password) .addComponent(password)
.addTo(mainPanel); .addTo(mainPanel);
Panel rememberPanel = new Panel() if(!LocalCredentials.getInstance().checkForExistingCredentials())
.setLayoutManager(new GridLayout(3)) {
.setLayoutData(GridLayout.createLayoutData( Panel rememberPanel = new Panel()
GridLayout.Alignment.FILL, .setLayoutManager(new GridLayout(3))
Alignment.CENTER, .setLayoutData(GridLayout.createLayoutData(
true, GridLayout.Alignment.FILL,
false)); Alignment.CENTER,
true,
false));
rememberPanel.addComponent(new Label("Rembember?")) rememberPanel.addComponent(new Label("Rembember?"))
.addComponent(remember) .addComponent(remember)
.addTo(mainPanel); .addTo(mainPanel);
}
mainPanel.addComponent(new EmptySpace(TerminalSize.ONE)); mainPanel.addComponent(new EmptySpace(TerminalSize.ONE));

View File

@ -32,29 +32,23 @@ public class LoginController {
{ {
credentials = localCredentials.getCredentialsFile(); credentials = localCredentials.getCredentialsFile();
}else{ }else{
dialog = new CredentialsInput(); Triplet<String, String, Boolean> data = loginUsingGui(); // 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 credentials = new String[] {data.getValue0(), data.getValue1()};
credentials = new String[] {data.getValue0(), data.getValue1()};
if(data.getValue2()) if(data.getValue2())
{ {
localCredentials.saveCredentials(credentials); localCredentials.saveCredentials(credentials);
} }
} }
loginUsingCredentials(credentials); loginUsingCredentials(credentials);
} }
public void loginUsingGui() public Triplet<String, String, Boolean> loginUsingGui()
{ {
dialog = new CredentialsInput(); 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()) return dialog.showDialog(textGUI); // Failed to get credentials to log in, get them from user
{
localCredentials.saveCredentials(credentials);
}
} }
private void loginUsingCredentials(String[] credentials) private void loginUsingCredentials(String[] credentials)

View File

@ -7,6 +7,30 @@ import xyz.thastertyn.Types.Options;
public class Jidelna extends JecnaScrape { 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 @Override
public Options[] getOptions() { public Options[] getOptions() {
throw new UnsupportedOperationException("Unimplemented method 'getOptions'"); throw new UnsupportedOperationException("Unimplemented method 'getOptions'");

View File

@ -61,7 +61,8 @@ public class OmluvnyList extends JecnaScrape {
for(Element e : options) 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())); currentChoice = new Choice(Arrays.asList(schoolYearOptions.getOptions().get(0).getValue()));

View File

@ -83,19 +83,22 @@ public class Rozvrh extends JecnaScrape {
for(Element e : schoolYear) 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) for(Element e : timetableId)
{ {
String text = Pattern String text = Pattern
.compile("(Od .* do .*)") .compile("(Od .* do .*)")
.matcher(e.text()) .matcher(e.text())
.results() .results()
.findFirst() .findFirst()
.map(m -> m.group(1)) .map(m -> m.group(1))
.orElse(e.text()); .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));
} }
} }

View File

@ -13,7 +13,7 @@ import xyz.thastertyn.Types.Options;
public class Sdeleni extends JecnaScrape { public class Sdeleni extends JecnaScrape {
ArrayList<String> sdeleniList = new ArrayList<>(); ArrayList<xyz.thastertyn.Types.Sdeleni> sdeleniList = new ArrayList<>();
public void download() throws UnknownHostException, IOException public void download() throws UnknownHostException, IOException
{ {
@ -31,18 +31,11 @@ public class Sdeleni extends JecnaScrape {
isPositive = spans.get(0).hasClass("sprite-icon-tick-16"); isPositive = spans.get(0).hasClass("sprite-icon-tick-16");
label = spans.get(1).text(); label = spans.get(1).text();
if(isPositive) sdeleniList.add(new xyz.thastertyn.Types.Sdeleni(label, isPositive));
{
label = "" + "\u00a0" + label;
}else{
label = "" + "\u00a0" + label;
}
sdeleniList.add(label);
} }
} }
public ArrayList<String> getSdeleni() public ArrayList<xyz.thastertyn.Types.Sdeleni> getSdeleni()
{ {
return sdeleniList; return sdeleniList;
} }
@ -53,6 +46,5 @@ public class Sdeleni extends JecnaScrape {
} }
@Override @Override
public void download(Choice choice) throws IOException { public void download(Choice choice) throws IOException {}
}
} }

View File

@ -106,12 +106,14 @@ public class Znamky extends JecnaScrape {
for(Element e : skolniRoky) 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) 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; wasDownloaded = true;

View File

@ -4,22 +4,21 @@ public class Option {
private String text; private String text;
private String value; private String value;
public Option(String text, String value) { private boolean isDefault;
public Option(String text, String value, boolean isDefault) {
this.text = text; this.text = text;
this.value = value; this.value = value;
this.isDefault = isDefault;
}
public boolean isDefault() {
return isDefault;
} }
public String getText() { public String getText() {
return text; return text;
} }
public void setText(String text) {
this.text = text;
}
public String getValue() { public String getValue() {
return value; return value;
} }
public void setValue(String value) {
this.value = value;
}
@Override @Override
public String toString() { public String toString() {
return text; return text;

View 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;
}
}

View File

@ -8,8 +8,8 @@ import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
import xyz.thastertyn.Scrape.JecnaScrape; import xyz.thastertyn.Scrape.JecnaScrape;
import xyz.thastertyn.Types.Choice; import xyz.thastertyn.Types.Choice;
import xyz.thastertyn.UserInterface.UpdateListener;
import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog; import xyz.thastertyn.UserInterface.Dialogs.OptionsDialog;
import xyz.thastertyn.UserInterface.Listeners.UpdateListener;
/** /**

View File

@ -8,7 +8,7 @@ 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 xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Listeners.UpdateListener;
public class OmluvnyList extends JecnaContent{ public class OmluvnyList extends JecnaContent{

View File

@ -8,7 +8,7 @@ import com.googlecode.lanterna.gui2.Panel;
import com.googlecode.lanterna.gui2.table.Table; import com.googlecode.lanterna.gui2.table.Table;
import xyz.thastertyn.Types.Timetable; import xyz.thastertyn.Types.Timetable;
import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Listeners.UpdateListener;
public class Rozvrh extends JecnaContent { public class Rozvrh extends JecnaContent {

View File

@ -9,7 +9,7 @@ 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 xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Listeners.UpdateListener;
public class Sdeleni extends JecnaContent { public class Sdeleni extends JecnaContent {
@ -30,22 +30,23 @@ public class Sdeleni extends JecnaContent {
{ {
mainPanel.removeAllComponents(); 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)); Panel row = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
String[] split = sdeleni.split("\u00a0");
Label check = new Label(split[0]); Label check = new Label("");
Label text = new Label(split[1]); Label text = new Label(sdeleni.getText());
if(split[0].equals("")) if(sdeleni.isPositive())
{ {
check.setForegroundColor(ANSI.GREEN); check.setForegroundColor(ANSI.GREEN);
check.setText("");
}else{ }else{
check.setForegroundColor(ANSI.RED); check.setForegroundColor(ANSI.RED);
check.setText("");
} }
row.addComponent(check) row.addComponent(check)

View File

@ -15,7 +15,7 @@ import com.googlecode.lanterna.gui2.Panel;
import xyz.thastertyn.Types.Predmet; import xyz.thastertyn.Types.Predmet;
import xyz.thastertyn.Types.Znamka; import xyz.thastertyn.Types.Znamka;
import xyz.thastertyn.UserInterface.UpdateListener; import xyz.thastertyn.UserInterface.Listeners.UpdateListener;
public class Znamky extends JecnaContent { public class Znamky extends JecnaContent {

View File

@ -13,12 +13,18 @@ import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
import xyz.thastertyn.Login.LocalCredentials; import xyz.thastertyn.Login.LocalCredentials;
import xyz.thastertyn.Login.LoginController; import xyz.thastertyn.Login.LoginController;
import xyz.thastertyn.UserInterface.Listeners.ContentResetListener;
public class EscapeDialog extends DialogWindow { public class EscapeDialog extends DialogWindow {
public EscapeDialog() private WindowBasedTextGUI textGUI;
private ContentResetListener listener;
public EscapeDialog(WindowBasedTextGUI textGUI, ContentResetListener listener)
{ {
super("Escape Menu"); super("Escape Menu");
this.textGUI = textGUI;
this.listener = listener;
Panel mainPanel = new Panel() Panel mainPanel = new Panel()
.setLayoutManager(new GridLayout(1) .setLayoutManager(new GridLayout(1)
@ -45,16 +51,19 @@ public class EscapeDialog extends DialogWindow {
public void onDeleteLogin() public void onDeleteLogin()
{ {
close();
LocalCredentials.getInstance().deleteCredentials(); LocalCredentials.getInstance().deleteCredentials();
LoginController controller = new LoginController(getTextGUI()); LoginController controller = new LoginController(textGUI);
controller.loginUsingGui(); controller.loginUsingGui();
listener.reset();
} }
public void onLogout() public void onLogout()
{ {
close(); close();
LoginController controller = new LoginController(getTextGUI()); LoginController controller = new LoginController(textGUI);
controller.loginUsingGui(); controller.loginUsingGui();
listener.reset();
} }
public void onExit() public void onExit()

View File

@ -36,6 +36,17 @@ public class OptionsDialog extends DialogWindow {
boxs.add(new ComboBox<Option>(o.getOptions())); 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() Panel mainPanel = new Panel()
.setLayoutManager(new GridLayout(1) .setLayoutManager(new GridLayout(1)
.setLeftMarginSize(1) .setLeftMarginSize(1)

View File

@ -0,0 +1,5 @@
package xyz.thastertyn.UserInterface.Listeners;
public interface ContentResetListener {
public void reset();
}

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.UserInterface; package xyz.thastertyn.UserInterface.Listeners;
public interface UpdateListener { public interface UpdateListener {
/** /**

View File

@ -1,4 +1,4 @@
package xyz.thastertyn.UserInterface; package xyz.thastertyn.UserInterface.Listeners;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; 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.gui2.dialogs.MessageDialogButton;
import com.googlecode.lanterna.input.KeyStroke; import com.googlecode.lanterna.input.KeyStroke;
import com.googlecode.lanterna.input.KeyType; 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.JecnaContent;
import xyz.thastertyn.UserInterface.Content.OmluvnyList; 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.Content.Znamky;
import xyz.thastertyn.UserInterface.Dialogs.EscapeDialog; import xyz.thastertyn.UserInterface.Dialogs.EscapeDialog;
public class WindowSwitchListener implements WindowListener, UpdateListener { public class WindowSwitchListener implements WindowListener, UpdateListener, ContentResetListener {
private WindowBasedTextGUI textGUI; private WindowBasedTextGUI textGUI;
private JecnaContent[] contents = { private JecnaContent[] contents = {
@ -42,14 +40,12 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
private Panel tabsPanel = new Panel() private Panel tabsPanel = new Panel()
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); .setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
private Panel holderPanel = new Panel(); private Panel holderPanel = new Panel();
private Screen screen;
int current = contents.length - 1; int current = contents.length - 1;
public WindowSwitchListener(Panel holder, WindowBasedTextGUI textGUI, Screen screen) public WindowSwitchListener(Panel holder, WindowBasedTextGUI textGUI)
{ {
this.textGUI = textGUI; this.textGUI = textGUI;
this.screen = screen;
holder.addComponent(tabsPanel); holder.addComponent(tabsPanel);
holder.addComponent(holderPanel.withBorder(Borders.singleLine())); holder.addComponent(holderPanel.withBorder(Borders.singleLine()));
@ -94,11 +90,6 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
setPanelPreferedSize(); setPanelPreferedSize();
updateLabels(); updateLabels();
try {
screen.refresh(RefreshType.COMPLETE);
} catch (IOException e) {
e.printStackTrace();
}
} }
private void checkIfDownloaded() private void checkIfDownloaded()
@ -182,7 +173,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
} }
break; break;
case Escape: case Escape:
EscapeDialog dialog = new EscapeDialog(); EscapeDialog dialog = new EscapeDialog(textGUI, this);
dialog.showDialog(textGUI); dialog.showDialog(textGUI);
break; break;
default: default:
@ -213,4 +204,16 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
holderPanel.addComponent(contents[current].getPanel()); 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();
}
} }

View File

@ -19,6 +19,7 @@ import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
import com.googlecode.lanterna.terminal.Terminal; import com.googlecode.lanterna.terminal.Terminal;
import xyz.thastertyn.Login.LoginController; import xyz.thastertyn.Login.LoginController;
import xyz.thastertyn.UserInterface.Listeners.WindowSwitchListener;
public class MainWindow { public class MainWindow {
@ -58,7 +59,7 @@ public class MainWindow {
LoginController controller = new LoginController(textGUI); LoginController controller = new LoginController(textGUI);
controller.login(); controller.login();
window.addWindowListener(new WindowSwitchListener(content, textGUI, screen)); window.addWindowListener(new WindowSwitchListener(content, textGUI));
textGUI.addWindowAndWait(window); textGUI.addWindowAndWait(window);