Fixed Sdeleni bug caused by emoji
This commit is contained in:
parent
88aec67833
commit
1b9fef13d6
@ -17,6 +17,8 @@ public class LocalCredentials {
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
private static LocalCredentials localCredentials = new LocalCredentials();
|
||||
|
||||
private String path;
|
||||
|
||||
private File credentialsFile;
|
||||
@ -109,6 +111,7 @@ public class LocalCredentials {
|
||||
writer.append("user=" + credentials[0]);
|
||||
writer.append("\n");
|
||||
writer.append("pass=" + credentials[1]);
|
||||
writer.append("\n");
|
||||
|
||||
writer.close();
|
||||
} catch (IOException e) {
|
||||
@ -118,5 +121,19 @@ public class LocalCredentials {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean deleteCredentials()
|
||||
{
|
||||
credentialsFile.delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
private LocalCredentials() {}
|
||||
|
||||
public static LocalCredentials getInstance()
|
||||
{
|
||||
return localCredentials;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ public class LoginController {
|
||||
|
||||
private WindowBasedTextGUI textGUI;
|
||||
private xyz.thastertyn.Login.CredentialsInput dialog;
|
||||
private LocalCredentials localCredentials = new LocalCredentials();
|
||||
private LocalCredentials localCredentials = LocalCredentials.getInstance();
|
||||
private xyz.thastertyn.Login.Login login = new xyz.thastertyn.Login.Login();
|
||||
|
||||
public LoginController(WindowBasedTextGUI textGUI)
|
||||
@ -45,6 +45,18 @@ public class LoginController {
|
||||
loginUsingCredentials(credentials);
|
||||
}
|
||||
|
||||
public void 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);
|
||||
}
|
||||
}
|
||||
|
||||
private void loginUsingCredentials(String[] credentials)
|
||||
{
|
||||
try {
|
||||
|
@ -1,20 +1,23 @@
|
||||
package xyz.thastertyn.Scrape;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import xyz.thastertyn.Tuples.Pair;
|
||||
import xyz.thastertyn.Types.Choice;
|
||||
import xyz.thastertyn.Types.Option;
|
||||
import xyz.thastertyn.Types.Options;
|
||||
|
||||
public class OmluvnyList extends JecnaScrape {
|
||||
|
||||
private ArrayList<Pair<String, String>> data;
|
||||
private ArrayList<xyz.thastertyn.Types.OmluvnyList> data;
|
||||
private Choice currentChoice;
|
||||
|
||||
private Options schoolYearOptions;
|
||||
|
||||
@ -26,6 +29,9 @@ public class OmluvnyList extends JecnaScrape {
|
||||
|
||||
@Override
|
||||
public void download(Choice choice) throws IOException {
|
||||
|
||||
currentChoice = choice;
|
||||
|
||||
download(String.format(
|
||||
"https://www.spsejecna.cz/absence/student?schoolYearId=%s",
|
||||
choice.getChoices().get(0)));
|
||||
@ -42,9 +48,13 @@ public class OmluvnyList extends JecnaScrape {
|
||||
for(Element e : omluvneListy)
|
||||
{
|
||||
String date = e.child(0).text();
|
||||
|
||||
|
||||
String text = e.child(1).text();
|
||||
|
||||
data.add(new Pair<String, String>(date, text));
|
||||
data.add(
|
||||
new xyz.thastertyn.Types.OmluvnyList(
|
||||
parseDate(date), text));
|
||||
}
|
||||
|
||||
Elements options = omluvnyListDokumentHTML.select("form.listConfigure").select("select[id=schoolYearId]").select("option");
|
||||
@ -53,6 +63,39 @@ public class OmluvnyList extends JecnaScrape {
|
||||
{
|
||||
schoolYearOptions.addOption(new Option(e.text(), e.attr("value")));
|
||||
}
|
||||
|
||||
currentChoice = new Choice(Arrays.asList(schoolYearOptions.getOptions().get(0).getValue()));
|
||||
}
|
||||
|
||||
private LocalDate parseDate(String text)
|
||||
{
|
||||
int year = 0, month = 0, day = 0;
|
||||
String[] split = text.split("\\.");
|
||||
|
||||
month = Integer.parseInt(split[0]);
|
||||
day = Integer.parseInt(split[1]);
|
||||
|
||||
if(currentChoice == null)
|
||||
{
|
||||
// Pick the current year
|
||||
int currYear = LocalDate.now().getYear();
|
||||
int currMonth = LocalDate.now().getMonthValue();
|
||||
|
||||
if(month > currMonth && currMonth < 8)
|
||||
{
|
||||
year = currYear;
|
||||
}else if(month < currMonth && currMonth > 8)
|
||||
{
|
||||
year = currYear + 1;
|
||||
}else if(month < currMonth && currMonth < 8)
|
||||
{
|
||||
year = currYear;
|
||||
}
|
||||
}else{
|
||||
year = Integer.parseInt(currentChoice.getChoices().get(0));
|
||||
}
|
||||
|
||||
return LocalDate.of(year, Month.of(month), day);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,7 +103,7 @@ public class OmluvnyList extends JecnaScrape {
|
||||
return new Options[] {schoolYearOptions};
|
||||
}
|
||||
|
||||
public ArrayList<Pair<String, String>> getData()
|
||||
public ArrayList<xyz.thastertyn.Types.OmluvnyList> getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ public class Sdeleni extends JecnaScrape {
|
||||
|
||||
if(isPositive)
|
||||
{
|
||||
label = "✅" + " " + label;
|
||||
label = "✓" + "\u00a0" + label;
|
||||
}else{
|
||||
label = "❌" + " " + label;
|
||||
label = "✗" + "\u00a0" + label;
|
||||
}
|
||||
|
||||
sdeleniList.add(label);
|
||||
@ -49,11 +49,10 @@ public class Sdeleni extends JecnaScrape {
|
||||
|
||||
@Override
|
||||
public Options[] getOptions() {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getOptions'");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(Choice choice) throws IOException {
|
||||
throw new UnsupportedOperationException("Unimplemented method 'download'");
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,33 @@
|
||||
package xyz.thastertyn.Types;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class OmluvnyList {
|
||||
|
||||
private String datum;
|
||||
private LocalDate datum;
|
||||
private String popis;
|
||||
|
||||
public OmluvnyList(String datum, String popis)
|
||||
public OmluvnyList(LocalDate datum, String popis)
|
||||
{
|
||||
this.datum = datum;
|
||||
this.popis = popis;
|
||||
}
|
||||
|
||||
public LocalDate getDatum() {
|
||||
return datum;
|
||||
}
|
||||
|
||||
public void setDatum(LocalDate datum) {
|
||||
this.datum = datum;
|
||||
}
|
||||
|
||||
public String getPopis() {
|
||||
return popis;
|
||||
}
|
||||
|
||||
public void setPopis(String popis) {
|
||||
this.popis = popis;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ public abstract class JecnaContent {
|
||||
}else{
|
||||
scraper.download();
|
||||
setGUI();
|
||||
listener.updatePanel();
|
||||
}
|
||||
|
||||
hasStarted = true;
|
||||
@ -52,6 +51,12 @@ public abstract class JecnaContent {
|
||||
}
|
||||
|
||||
public void showOptions(WindowBasedTextGUI textGUI) throws IOException {
|
||||
|
||||
if(scraper.getOptions() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OptionsDialog dialog = new OptionsDialog(scraper.getOptions());
|
||||
|
||||
Choice choice = dialog.showDialog(textGUI);
|
||||
|
@ -8,7 +8,6 @@ import com.googlecode.lanterna.gui2.Label;
|
||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||
import com.googlecode.lanterna.gui2.Panel;
|
||||
|
||||
import xyz.thastertyn.Tuples.Pair;
|
||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||
|
||||
public class OmluvnyList extends JecnaContent{
|
||||
@ -28,15 +27,15 @@ public class OmluvnyList extends JecnaContent{
|
||||
protected void setGUI()
|
||||
{
|
||||
this.mainPanel.removeAllComponents();
|
||||
ArrayList<Pair<String, String>> a = omluvnyList.getData();
|
||||
ArrayList<xyz.thastertyn.Types.OmluvnyList> a = omluvnyList.getData();
|
||||
|
||||
Panel content = new Panel()
|
||||
.setLayoutManager(new LinearLayout(Direction.VERTICAL))
|
||||
.addTo(mainPanel);
|
||||
|
||||
for(Pair<String, String> p : a)
|
||||
for(xyz.thastertyn.Types.OmluvnyList omluvnyList : a)
|
||||
{
|
||||
content.addComponent(new Label(p.getValue0() + " - " + p.getValue1()));
|
||||
content.addComponent(new Label(omluvnyList.getDatum() + " - " + omluvnyList.getPopis()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,11 @@ package xyz.thastertyn.UserInterface.Content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.googlecode.lanterna.TextColor.ANSI;
|
||||
import com.googlecode.lanterna.gui2.Direction;
|
||||
import com.googlecode.lanterna.gui2.GridLayout;
|
||||
import com.googlecode.lanterna.gui2.Label;
|
||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||
import com.googlecode.lanterna.gui2.Panel;
|
||||
|
||||
import xyz.thastertyn.UserInterface.UpdateListener;
|
||||
@ -29,6 +32,25 @@ public class Sdeleni extends JecnaContent {
|
||||
|
||||
ArrayList<String> sdeleniList = sdeleni.getSdeleni();
|
||||
|
||||
sdeleniList.forEach(sdeleni -> mainPanel.addComponent(new Label(sdeleni)));
|
||||
for(String 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]);
|
||||
|
||||
if(split[0].equals("✓"))
|
||||
{
|
||||
check.setForegroundColor(ANSI.GREEN);
|
||||
}else{
|
||||
check.setForegroundColor(ANSI.RED);
|
||||
}
|
||||
|
||||
row.addComponent(check)
|
||||
.addComponent(text)
|
||||
.addTo(mainPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@ import com.googlecode.lanterna.gui2.Window;
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
||||
|
||||
import xyz.thastertyn.Login.LocalCredentials;
|
||||
import xyz.thastertyn.Login.LoginController;
|
||||
|
||||
public class EscapeDialog extends DialogWindow {
|
||||
|
||||
public EscapeDialog()
|
||||
@ -42,16 +45,16 @@ public class EscapeDialog extends DialogWindow {
|
||||
|
||||
public void onDeleteLogin()
|
||||
{
|
||||
close();
|
||||
|
||||
// Call login manager to delete login
|
||||
LocalCredentials.getInstance().deleteCredentials();
|
||||
LoginController controller = new LoginController(getTextGUI());
|
||||
controller.loginUsingGui();
|
||||
}
|
||||
|
||||
public void onLogout()
|
||||
{
|
||||
close();
|
||||
|
||||
// Go back to square one and start logging in again
|
||||
LoginController controller = new LoginController(getTextGUI());
|
||||
controller.loginUsingGui();
|
||||
}
|
||||
|
||||
public void onExit()
|
||||
|
@ -52,14 +52,13 @@ public class MainWindow {
|
||||
|
||||
window.setComponent(mainPanel);
|
||||
|
||||
|
||||
Panel content = new Panel();
|
||||
mainPanel.addComponent(content.withBorder(Borders.singleLine("Jecnak")));
|
||||
|
||||
LoginController controller = new LoginController(textGUI);
|
||||
controller.login();
|
||||
|
||||
window.addWindowListener(new WindowSwitchListener(content, textGUI));
|
||||
window.addWindowListener(new WindowSwitchListener(content, textGUI, screen));
|
||||
|
||||
textGUI.addWindowAndWait(window);
|
||||
|
||||
|
@ -17,6 +17,8 @@ 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;
|
||||
@ -40,12 +42,14 @@ 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)
|
||||
public WindowSwitchListener(Panel holder, WindowBasedTextGUI textGUI, Screen screen)
|
||||
{
|
||||
this.textGUI = textGUI;
|
||||
this.screen = screen;
|
||||
holder.addComponent(tabsPanel);
|
||||
holder.addComponent(holderPanel.withBorder(Borders.singleLine()));
|
||||
|
||||
@ -90,6 +94,11 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
|
||||
setPanelPreferedSize();
|
||||
updateLabels();
|
||||
try {
|
||||
screen.refresh(RefreshType.COMPLETE);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfDownloaded()
|
||||
@ -119,10 +128,11 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
if(currentColumns < tabColumns)
|
||||
{
|
||||
holderPanel.addComponent(
|
||||
contents[current].getPanel()
|
||||
contents[current]
|
||||
.getPanel()
|
||||
.setPreferredSize(
|
||||
new TerminalSize(
|
||||
tabColumns - 2,
|
||||
tabColumns,
|
||||
contents[current].getPanel().getPreferredSize().getRows())));
|
||||
return;
|
||||
}
|
||||
@ -160,12 +170,10 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
switch(type)
|
||||
{
|
||||
case Tab:
|
||||
if(keyStroke.isShiftDown())
|
||||
{
|
||||
previous();
|
||||
}else{
|
||||
next();
|
||||
}
|
||||
break;
|
||||
case ReverseTab:
|
||||
previous();
|
||||
break;
|
||||
case Character:
|
||||
if(keyStroke.getCharacter() == ' ')
|
||||
@ -184,6 +192,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
|
||||
@Override
|
||||
public void onUnhandledInput(Window basePane, KeyStroke keyStroke, AtomicBoolean hasBeenHandled) {
|
||||
hasBeenHandled.set(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,6 +202,7 @@ public class WindowSwitchListener implements WindowListener, UpdateListener {
|
||||
|
||||
@Override
|
||||
public void onMoved(Window window, TerminalPosition oldPosition, TerminalPosition newPosition) {
|
||||
window.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user