Save login
This commit is contained in:
parent
db339eeada
commit
d41abdbad9
@ -1,6 +1,9 @@
|
||||
package main;
|
||||
|
||||
import com.jfoenix.controls.*;
|
||||
import config.Config;
|
||||
import config.ConfigLoader;
|
||||
import container.HttpRequest;
|
||||
import helper.HttpRequestException;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -45,6 +48,7 @@ public class OptionController {
|
||||
private JFXComboBox<String> comboBox;
|
||||
private DataController dataController;
|
||||
private List<User> users;
|
||||
private Config config;
|
||||
|
||||
@FXML
|
||||
public void initialize(){
|
||||
@ -63,6 +67,11 @@ public class OptionController {
|
||||
comboBox.getStyleClass().add("comboBox");
|
||||
mainGrid.add(comboBox, 2,2);
|
||||
|
||||
config = ConfigLoader.load();
|
||||
if(config == null){
|
||||
config = new Config(false, -1, "");
|
||||
}
|
||||
saveLoginTBtn.setSelected(config.isSaveLogin());
|
||||
}
|
||||
|
||||
public void onBackBtnClick(ActionEvent actionEvent) {
|
||||
@ -134,4 +143,16 @@ public class OptionController {
|
||||
EditUserController editUserController = fxmlLoader.getController();
|
||||
editUserController.setCurrentUser(users.get(editIndex));
|
||||
}
|
||||
|
||||
public void toggledBtn(ActionEvent actionEvent) {
|
||||
config.setSaveLogin(saveLoginTBtn.isSelected());
|
||||
if(config.isSaveLogin()){
|
||||
config.setId(DataController.USER_ID);
|
||||
config.setToken(HttpRequest.TOKEN);
|
||||
} else {
|
||||
config.setId(-1);
|
||||
config.setToken("");
|
||||
}
|
||||
ConfigLoader.save(config);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ fx:id="mainGrid">
|
||||
|
||||
<Label styleClass="loginLbl" GridPane.columnIndex="1" GridPane.rowIndex="8"
|
||||
GridPane.halignment="CENTER">Angemeldet bleiben:</Label>
|
||||
<JFXToggleButton fx:id="saveLoginTBtn" GridPane.columnIndex="3" GridPane.rowIndex="8"/>
|
||||
<JFXToggleButton fx:id="saveLoginTBtn" GridPane.columnIndex="3" GridPane.rowIndex="8" onAction="#toggledBtn"/>
|
||||
|
||||
<Label fx:id="labelError" styleClass="errorMessage" GridPane.columnIndex="1" GridPane.rowIndex="9"/>
|
||||
<JFXButton GridPane.columnIndex="4" GridPane.rowIndex="9" onAction="#onBackBtnClick">Zurück</JFXButton>
|
||||
|
@ -17,8 +17,10 @@ public class ConfigLoader {
|
||||
return objectMapper.readValue(jsonString, Config.class);
|
||||
} catch (IOException e) {
|
||||
System.out.println("config.json missing");
|
||||
Config config = new Config(false, -1, "");
|
||||
save(config);
|
||||
return config;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(Config config){
|
||||
|
Loading…
Reference in New Issue
Block a user