Renamed a bunch of stuff and hopefully made login a bit more easy to understand
This commit is contained in:
parent
958d50ef99
commit
ae9c652761
@ -1,6 +1,6 @@
|
|||||||
package xyz.thastertyn;
|
package xyz.thastertyn;
|
||||||
|
|
||||||
import xyz.thastertyn.Window.MainWindow;
|
import xyz.thastertyn.ContentDisplay.MainWindow;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hello world!
|
* Hello world!
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package xyz.thastertyn.ContentDisplay.Content;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper to include all classes that deal with content in some way
|
||||||
|
*/
|
||||||
|
public abstract class JecnaContent {
|
||||||
|
|
||||||
|
public abstract Panel getPanel();
|
||||||
|
public abstract void download(String s);
|
||||||
|
public abstract boolean hasStarted();
|
||||||
|
public abstract String getLabel();
|
||||||
|
public abstract void specify(int y, int hy);
|
||||||
|
public abstract void getOptions(WindowBasedTextGUI textGUI);
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package xyz.thastertyn.ContentDisplay.Content;
|
||||||
|
|
||||||
|
public class Jidelna {
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package xyz.thastertyn.Window.Content;
|
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.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.table.Table;
|
import com.googlecode.lanterna.gui2.table.Table;
|
||||||
|
|
||||||
public class Rozvrh extends JecnaContent {
|
public class Rozvrh extends JecnaContent {
|
||||||
@ -13,7 +14,7 @@ public class Rozvrh extends JecnaContent {
|
|||||||
|
|
||||||
private boolean hasStarted = false;
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
private xyz.thastertyn.Jecna.Rozvrh rozvrh = new xyz.thastertyn.Jecna.Rozvrh();
|
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."};
|
||||||
@ -70,4 +71,16 @@ public class Rozvrh extends JecnaContent {
|
|||||||
{
|
{
|
||||||
return "Rozvrh";
|
return "Rozvrh";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specify(int y, int hy) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'specify'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getOptions(WindowBasedTextGUI textGUI) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
package xyz.thastertyn.ContentDisplay.Content;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.GridLayout;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
|
public class Sdeleni extends JecnaContent {
|
||||||
|
|
||||||
|
private Panel sdeleniPanel = new Panel();
|
||||||
|
|
||||||
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
|
private xyz.thastertyn.JecnaParse.Sdeleni sdeleni = new xyz.thastertyn.JecnaParse.Sdeleni();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(String JsessionId)
|
||||||
|
{
|
||||||
|
if(!hasStarted)
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
|
||||||
|
sdeleniPanel.setLayoutManager(new GridLayout(1)
|
||||||
|
.setLeftMarginSize(1)
|
||||||
|
.setRightMarginSize(1));
|
||||||
|
|
||||||
|
sdeleni.downloadSdeleni(JsessionId);
|
||||||
|
|
||||||
|
ArrayList<Pair<String, Boolean>> sdeleniList = sdeleni.getSdeleni();
|
||||||
|
|
||||||
|
for(Pair<String, Boolean> p : sdeleniList)
|
||||||
|
{
|
||||||
|
String label = "";
|
||||||
|
|
||||||
|
if(p.getValue1())
|
||||||
|
{
|
||||||
|
label += "✅";
|
||||||
|
}else{
|
||||||
|
label += "❌";
|
||||||
|
}
|
||||||
|
|
||||||
|
label += " " + p.getValue0();
|
||||||
|
|
||||||
|
sdeleniPanel.addComponent(new Label(label));
|
||||||
|
}
|
||||||
|
hasStarted = true;
|
||||||
|
}catch(UnknownHostException e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}catch(IOException e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel() {
|
||||||
|
return "Sdeleni";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Panel getPanel() {
|
||||||
|
return sdeleniPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasStarted() {
|
||||||
|
return hasStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specify(int y, int hy) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'specify'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getOptions(WindowBasedTextGUI textGUI) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,24 @@
|
|||||||
package xyz.thastertyn.Window.Content;
|
package xyz.thastertyn.ContentDisplay.Content;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import com.googlecode.lanterna.SGR;
|
|
||||||
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.Direction;
|
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.LinearLayout;
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.ActionListDialogBuilder;
|
||||||
|
|
||||||
import xyz.thastertyn.Tuple.Pair;
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
public class Znamky extends JecnaContent {
|
public class Znamky extends JecnaContent {
|
||||||
|
|
||||||
private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
private Panel znamkyPanel = new Panel().setLayoutManager(new LinearLayout(Direction.HORIZONTAL));
|
||||||
|
|
||||||
private xyz.thastertyn.Jecna.Znamky znamky = new xyz.thastertyn.Jecna.Znamky();
|
private xyz.thastertyn.JecnaParse.Znamky znamky = new xyz.thastertyn.JecnaParse.Znamky();
|
||||||
|
|
||||||
private boolean hasStarted = false;
|
private boolean hasStarted = false;
|
||||||
|
|
||||||
@ -130,4 +132,16 @@ public class Znamky extends JecnaContent {
|
|||||||
{
|
{
|
||||||
return "Znamky";
|
return "Znamky";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void specify(int y, int hy) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'specify'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void getOptions(WindowBasedTextGUI textGUI) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,11 +1,7 @@
|
|||||||
package xyz.thastertyn.Window;
|
package xyz.thastertyn.ContentDisplay;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.security.auth.login.CredentialException;
|
|
||||||
|
|
||||||
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.EmptySpace;
|
import com.googlecode.lanterna.gui2.EmptySpace;
|
||||||
@ -21,16 +17,18 @@ 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;
|
||||||
|
|
||||||
public class Login extends DialogWindow {
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
|
public class CredentialsInput extends DialogWindow {
|
||||||
|
|
||||||
private TextBox username;
|
private TextBox username;
|
||||||
private TextBox password;
|
private TextBox password;
|
||||||
private String user;
|
private String user;
|
||||||
private String pass;
|
private String pass;
|
||||||
|
|
||||||
private xyz.thastertyn.Jecna.Login login = new xyz.thastertyn.Jecna.Login();
|
//private xyz.thastertyn.JecnaParse.Login login = new xyz.thastertyn.JecnaParse.Login();
|
||||||
|
|
||||||
Login()
|
CredentialsInput()
|
||||||
{
|
{
|
||||||
super("Login");
|
super("Login");
|
||||||
this.user = null;
|
this.user = null;
|
||||||
@ -126,39 +124,16 @@ public class Login extends DialogWindow {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
login.loginJecna(user, pass);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
MessageDialog.showMessageDialog(getTextGUI(), "No Internet connection",
|
|
||||||
"There seems to be no internet connection, reverting to cached data", MessageDialogButton.OK);
|
|
||||||
return;
|
|
||||||
} catch (CredentialException e)
|
|
||||||
{
|
|
||||||
MessageDialog.showMessageDialog(getTextGUI(), "Incorrect username or password",
|
|
||||||
"The username or password you entered is incorrect", MessageDialogButton.OK);
|
|
||||||
return;
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
MessageDialog.showMessageDialog(getTextGUI(), "There was an error", "Maybe try again and it will go away",
|
|
||||||
MessageDialogButton.OK);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJessionId() {
|
|
||||||
return login.getJSESSIONID();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCancel() {
|
public void onCancel() {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] showDialog(WindowBasedTextGUI textGUI) {
|
public Pair<String, String> showDialog(WindowBasedTextGUI textGUI) {
|
||||||
super.showDialog(textGUI);
|
super.showDialog(textGUI);
|
||||||
return new String[] { user, pass };
|
return new Pair<String, String>(user, pass);
|
||||||
}
|
}
|
||||||
}
|
}
|
190
src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java
Normal file
190
src/main/java/xyz/thastertyn/ContentDisplay/LoginController.java
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
package xyz.thastertyn.ContentDisplay;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
import javax.security.auth.login.CredentialException;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
|
||||||
|
import com.googlecode.lanterna.gui2.dialogs.MessageDialogButton;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
|
public class LoginController {
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
this.textGUI = textGUI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void login()
|
||||||
|
{
|
||||||
|
if(checkForCredentials()) // Credentials exist
|
||||||
|
if(loginUsingCredentials()) // They are accessible and can read them
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Pair<String, String> 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;
|
||||||
|
} catch (CredentialException e)
|
||||||
|
{
|
||||||
|
MessageDialog.showMessageDialog(textGUI, "Incorrect username or password",
|
||||||
|
"The username or password you entered is incorrect",
|
||||||
|
MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
MessageDialog.showMessageDialog(textGUI, "There was an error",
|
||||||
|
"Maybe try again and it will go away",
|
||||||
|
MessageDialogButton.OK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zkontroluje zda jiz neexistuji ulozene udaje na systemu
|
||||||
|
* @return <ul>
|
||||||
|
* <li> {@code true} soubor existuje a neni prazdny </li>
|
||||||
|
* <li> {@code false} neexistuje, nebo je prazdny </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
private boolean checkForCredentials()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
//File credentials = null;
|
||||||
|
|
||||||
|
//if(System.getProperty("os.name").equals("Linux"))
|
||||||
|
//{
|
||||||
|
// credentials = new File("~/.local/share/jecnak/credentials.json");
|
||||||
|
|
||||||
|
//}else if(System.getProperty("os.name").contains("Windows"))
|
||||||
|
//{
|
||||||
|
// credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
||||||
|
//}
|
||||||
|
|
||||||
|
//if(!credentials.exists() || credentials.length() == 0)
|
||||||
|
//{
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
//return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean saveCredentials(String user, String pass)
|
||||||
|
{
|
||||||
|
File credentials;
|
||||||
|
|
||||||
|
if(System.getProperty("os.name").equals("Linux"))
|
||||||
|
{
|
||||||
|
credentials = new File("~/.local/share/jecnak/credentials.json");
|
||||||
|
|
||||||
|
}else if(System.getProperty("os.name").contains("Windows"))
|
||||||
|
{
|
||||||
|
credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedWriter writer = new BufferedWriter(new FileWriter(credentials));
|
||||||
|
writer.append("username=" + user);
|
||||||
|
writer.append("password=" + pass);
|
||||||
|
|
||||||
|
writer.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean loginUsingCredentials()
|
||||||
|
{
|
||||||
|
File credentials;
|
||||||
|
|
||||||
|
if(System.getProperty("os.name").equals("Linux"))
|
||||||
|
{
|
||||||
|
credentials = new File("~/.local/share/jecnak/credentials.json");
|
||||||
|
|
||||||
|
}else if(System.getProperty("os.name").contains("Windows"))
|
||||||
|
{
|
||||||
|
credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!credentials.exists() || credentials.length() == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String user = "";
|
||||||
|
String pass = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
BufferedReader reader = new BufferedReader(new FileReader(credentials));
|
||||||
|
|
||||||
|
String line = "";
|
||||||
|
while((line = reader.readLine()) != null)
|
||||||
|
{
|
||||||
|
if(line.matches("^[a-z]\\=.*$"))
|
||||||
|
{
|
||||||
|
String key = line.split("=")[0];
|
||||||
|
String value = line.split("=")[1];
|
||||||
|
|
||||||
|
switch(key)
|
||||||
|
{
|
||||||
|
case "username":
|
||||||
|
user = value;
|
||||||
|
break;
|
||||||
|
case "password":
|
||||||
|
pass = value;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
login.loginJecna(user, pass);
|
||||||
|
} catch (CredentialException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJSessesionId()
|
||||||
|
{
|
||||||
|
return login.getJSESSIONID();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Window;
|
package xyz.thastertyn.ContentDisplay;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -54,7 +54,8 @@ public class MainWindow {
|
|||||||
Panel tabs = new Panel()
|
Panel tabs = new Panel()
|
||||||
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL))
|
.setLayoutManager(new LinearLayout(Direction.HORIZONTAL))
|
||||||
.addComponent(new Label("Rozvrh").withBorder(Borders.singleLine()))
|
.addComponent(new Label("Rozvrh").withBorder(Borders.singleLine()))
|
||||||
.addComponent(new Label("Znamky").withBorder(Borders.singleLine()));
|
.addComponent(new Label("Znamky").withBorder(Borders.singleLine()))
|
||||||
|
.addComponent(new Label("Sdeleni R.").withBorder(Borders.singleLine()));
|
||||||
|
|
||||||
mainPanel.addComponent(tabs);
|
mainPanel.addComponent(tabs);
|
||||||
|
|
||||||
@ -63,10 +64,10 @@ public class MainWindow {
|
|||||||
Panel content = new Panel();
|
Panel content = new Panel();
|
||||||
mainPanel.addComponent(content.withBorder(Borders.singleLine(title)));
|
mainPanel.addComponent(content.withBorder(Borders.singleLine(title)));
|
||||||
|
|
||||||
Login login = new Login();
|
LoginController controller = new LoginController(textGUI);
|
||||||
login.showDialog(textGUI);
|
controller.login();
|
||||||
|
|
||||||
window.addWindowListener(new WindowSwitchListener(content, login.getJessionId(), tabs, title));
|
window.addWindowListener(new WindowSwitchListener(content, controller.getJSessesionId(), tabs, title));
|
||||||
|
|
||||||
textGUI.addWindowAndWait(window);
|
textGUI.addWindowAndWait(window);
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Window;
|
package xyz.thastertyn.ContentDisplay;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@ -11,20 +11,21 @@ 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;
|
||||||
|
|
||||||
import xyz.thastertyn.Window.Content.JecnaContent;
|
import xyz.thastertyn.ContentDisplay.Content.JecnaContent;
|
||||||
import xyz.thastertyn.Window.Content.Rozvrh;
|
import xyz.thastertyn.ContentDisplay.Content.Rozvrh;
|
||||||
import xyz.thastertyn.Window.Content.Znamky;
|
import xyz.thastertyn.ContentDisplay.Content.Sdeleni;
|
||||||
|
import xyz.thastertyn.ContentDisplay.Content.Znamky;
|
||||||
|
|
||||||
public class WindowSwitchListener implements WindowListener {
|
public class WindowSwitchListener implements WindowListener {
|
||||||
|
|
||||||
WindowBasedTextGUI gui;
|
WindowBasedTextGUI gui;
|
||||||
|
|
||||||
private JecnaContent[] contents = {new Rozvrh(), new Znamky()};
|
private JecnaContent[] contents = {new Rozvrh(), new Znamky(), new Sdeleni()};
|
||||||
|
|
||||||
private String JsessionId;
|
private String JsessionId;
|
||||||
|
|
||||||
Panel content;
|
private Panel content;
|
||||||
Panel tabs;
|
private Panel tabs;
|
||||||
|
|
||||||
String title;
|
String title;
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
|
||||||
|
|
||||||
public class Jidelna {
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
import org.jsoup.Connection;
|
import org.jsoup.Connection;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
5
src/main/java/xyz/thastertyn/JecnaParse/Jidelna.java
Normal file
5
src/main/java/xyz/thastertyn/JecnaParse/Jidelna.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
|
public class Jidelna {
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
@ -19,51 +18,6 @@ public class Login {
|
|||||||
private long start;
|
private long start;
|
||||||
private long lastCheck;
|
private long lastCheck;
|
||||||
|
|
||||||
/**
|
|
||||||
* Zkontroluje zda jiz neexistuji ulozene udaje na systemu
|
|
||||||
* @return <ul>
|
|
||||||
* <li> {@code true} soubor existuje a neni prazdny </li>
|
|
||||||
* <li> {@code false} neexistuje, nebo jsou prazdne </li>
|
|
||||||
* </ul>
|
|
||||||
*/
|
|
||||||
public boolean checkForCredentials()
|
|
||||||
{
|
|
||||||
File credentials = null;
|
|
||||||
|
|
||||||
if(System.getProperty("os.name").equals("Linux"))
|
|
||||||
{
|
|
||||||
credentials = new File("~/.local/share/jecnak/credentials.json");
|
|
||||||
|
|
||||||
}else if(System.getProperty("os.name").contains("Windows"))
|
|
||||||
{
|
|
||||||
credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!credentials.exists() || credentials.length() == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveCredentials(String user, String pass)
|
|
||||||
{
|
|
||||||
File credentials = null;
|
|
||||||
|
|
||||||
if(System.getProperty("os.name").equals("Linux"))
|
|
||||||
{
|
|
||||||
credentials = new File("~/.local/share/jecnak/credentials.json");
|
|
||||||
|
|
||||||
}else if(System.getProperty("os.name").contains("Windows"))
|
|
||||||
{
|
|
||||||
credentials = new File(System.getenv("APPDATA\\jecnak\\"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!credentials.exists())
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getJSESSIONID()
|
public String getJSESSIONID()
|
||||||
{
|
{
|
||||||
@ -94,7 +48,6 @@ public class Login {
|
|||||||
Jsoup.connect("https://www.spsejecna.cz/user/login")
|
Jsoup.connect("https://www.spsejecna.cz/user/login")
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
//.header("Content-Length", "71") Adds 10 seconds to total request time
|
|
||||||
.header("Origin", "https://www.spsejecna.cz")
|
.header("Origin", "https://www.spsejecna.cz")
|
||||||
.header("Connection", "keep-alive")
|
.header("Connection", "keep-alive")
|
||||||
.cookie("JSESSIONID", Jsessionid)
|
.cookie("JSESSIONID", Jsessionid)
|
||||||
@ -122,7 +75,7 @@ public class Login {
|
|||||||
lastCheck = start;
|
lastCheck = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loginJidelna() throws UnknownHostException, IOException
|
/*public void loginJidelna() throws UnknownHostException, IOException
|
||||||
{
|
{
|
||||||
//#region JSESSIONID
|
//#region JSESSIONID
|
||||||
Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/")
|
Connection.Response jidelna = Jsoup.connect("https://objednavky.jidelnasokolska.cz/")
|
||||||
@ -165,5 +118,5 @@ public class Login {
|
|||||||
.method(Method.POST)
|
.method(Method.POST)
|
||||||
.execute();
|
.execute();
|
||||||
//#endregion
|
//#endregion
|
||||||
}
|
}*/
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
48
src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java
Normal file
48
src/main/java/xyz/thastertyn/JecnaParse/Sdeleni.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
|
import xyz.thastertyn.Tuple.Pair;
|
||||||
|
|
||||||
|
public class Sdeleni {
|
||||||
|
|
||||||
|
ArrayList<Pair<String, Boolean>> sdeleniList = new ArrayList<>();
|
||||||
|
|
||||||
|
public void downloadSdeleni(final String JsessionId) throws UnknownHostException, IOException
|
||||||
|
{
|
||||||
|
Document sdeleniDoc = Downloader.download("https://www.spsejecna.cz/user-student/record-list", JsessionId).get();
|
||||||
|
|
||||||
|
Elements sdeleni = sdeleniDoc.select("ul.list li");
|
||||||
|
|
||||||
|
for(Element e : sdeleni)
|
||||||
|
{
|
||||||
|
boolean isPositive = false;
|
||||||
|
String label = "";
|
||||||
|
|
||||||
|
Elements spans = e.select("li").select("a.item").select("span");
|
||||||
|
|
||||||
|
isPositive = spans.get(0).hasClass("sprite-icon-tick-16");
|
||||||
|
label = spans.get(1).text();
|
||||||
|
|
||||||
|
//if(!label.startsWith(" "))
|
||||||
|
//{
|
||||||
|
// label = " " + label;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//label = label.replaceAll("\\s+$", "");
|
||||||
|
|
||||||
|
sdeleniList.add(new Pair<String, Boolean>(label, isPositive));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pair<String, Boolean>> getSdeleni()
|
||||||
|
{
|
||||||
|
return sdeleniList;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.thastertyn.Jecna;
|
package xyz.thastertyn.JecnaParse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -18,14 +18,17 @@ public class Znamky {
|
|||||||
|
|
||||||
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
private ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> grades = new ArrayList<>();
|
||||||
|
|
||||||
public void addGrade(int index, String subject, int grade, double weight)
|
// Integer znaci id roku, boolean jestli je jen prvni nebo i druhe pololeti
|
||||||
|
private ArrayList<Pair<Integer, Boolean>> options = new ArrayList<>();
|
||||||
|
|
||||||
|
private void addGrade(int index, String subject, int grade, double weight)
|
||||||
{
|
{
|
||||||
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
|
Pair<Integer, Double> znamka = new Pair<>(grade, weight);
|
||||||
|
|
||||||
grades.get(index).getValue1().getValue0().add(znamka);
|
grades.get(index).getValue1().getValue0().add(znamka);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSubject(String subject)
|
private void addSubject(String subject)
|
||||||
{
|
{
|
||||||
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
|
Pair<ArrayList<Pair<Integer, Double>>, Double> p = new Pair<>(new ArrayList<Pair<Integer, Double>>(), 0.0);
|
||||||
|
|
||||||
@ -61,7 +64,7 @@ public class Znamky {
|
|||||||
{
|
{
|
||||||
wasDownloaded = true;
|
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?schoolYearId=14&schoolYearHalfId=21", Jsessionid).get();
|
Document znamkyDoc = Downloader.download("https://www.spsejecna.cz/score/student", Jsessionid).get();
|
||||||
|
|
||||||
Elements rows = znamkyDoc.select("table.score").select("tr");
|
Elements rows = znamkyDoc.select("table.score").select("tr");
|
||||||
|
|
||||||
@ -111,6 +114,23 @@ 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 pololetiSelect = znamkyDoc.select("select[name=schoolYearHalfId]");
|
||||||
|
|
||||||
|
for(Element e : roky)
|
||||||
|
{
|
||||||
|
boolean jeCelyRok = false;
|
||||||
|
|
||||||
|
if(pololetiSelect.size() == 2)
|
||||||
|
{
|
||||||
|
jeCelyRok = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rok = Integer.parseInt(e.attr("value"));
|
||||||
|
|
||||||
|
options.add(new Pair<Integer, Boolean>(rok, jeCelyRok));
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
|
public ArrayList<Pair<String, Pair<ArrayList<Pair<Integer, Double>>,Double>>> getGrades()
|
||||||
@ -118,6 +138,11 @@ public class Znamky {
|
|||||||
return grades;
|
return grades;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pair<Integer, Boolean>> getOptions()
|
||||||
|
{
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@ -133,6 +158,5 @@ public class Znamky {
|
|||||||
}else{
|
}else{
|
||||||
return "Nothing was downloaded";
|
return "Nothing was downloaded";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,39 +0,0 @@
|
|||||||
package xyz.thastertyn.Window.Content;
|
|
||||||
|
|
||||||
import com.googlecode.lanterna.gui2.Panel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrapper to include all classes that deal with content in some way
|
|
||||||
*/
|
|
||||||
public class JecnaContent {
|
|
||||||
|
|
||||||
public Panel getPanel()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void download(String s)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasStarted()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel()
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void specify(int y, int hy)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getOptions()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package xyz.thastertyn.Window.Content;
|
|
||||||
|
|
||||||
public class Jidelna {
|
|
||||||
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
target/classes/xyz/thastertyn/JecnaParse/Jidelna.class
Normal file
BIN
target/classes/xyz/thastertyn/JecnaParse/Jidelna.class
Normal file
Binary file not shown.
BIN
target/classes/xyz/thastertyn/JecnaParse/Login.class
Normal file
BIN
target/classes/xyz/thastertyn/JecnaParse/Login.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
target/classes/xyz/thastertyn/JecnaParse/Sdeleni.class
Normal file
BIN
target/classes/xyz/thastertyn/JecnaParse/Sdeleni.class
Normal file
Binary file not shown.
BIN
target/classes/xyz/thastertyn/JecnaParse/Znamky.class
Normal file
BIN
target/classes/xyz/thastertyn/JecnaParse/Znamky.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user