Skip to content

Commit

Permalink
Fix last merge, plus stuff
Browse files Browse the repository at this point in the history
-Layout still weird for main window, have to fix it.
  • Loading branch information
Ljaysoft committed Aug 14, 2016
1 parent 4bc188d commit 908ce0f
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 79 deletions.
68 changes: 47 additions & 21 deletions src/main/resources/layout/MainWindow.fxml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox xmlns:fx="http://javafx.com/fxml/1" prefHeight="487.0" prefWidth="599.0" xmlns="http://javafx.com/javafx/8.0.60"> <VBox xmlns:fx="http://javafx.com/fxml/1" alignment="CENTER" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0"
xmlns="http://javafx.com/javafx/8.0.60">
<children> <children>
<MenuBar prefHeight="25.0" prefWidth="634.0" VBox.vgrow="NEVER"> <MenuBar maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="23.0"
prefWidth="640.0">
<menus> <menus>
<Menu mnemonicParsing="false" text="File"> <Menu mnemonicParsing="false" text="File">
<items> <items>
Expand All @@ -23,12 +26,12 @@
</Menu> </Menu>
</menus> </menus>
</MenuBar> </MenuBar>
<VBox prefHeight="0.0" prefWidth="803.0"> <VBox alignment="CENTER_LEFT" prefHeight="32.0" prefWidth="640.0">
<children> <children>
<HBox fx:id="PlayerInfo"> <HBox fx:id="PlayerInfo" alignment="CENTER_LEFT" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="32.0" prefWidth="640.0">
<children> <children>
<ImageView fx:id="teamIcon" fitHeight="32.0" fitWidth="32.0" pickOnBounds="true" <ImageView fx:id="teamIcon" fitHeight="32.0" fitWidth="32.0" preserveRatio="true"/>
preserveRatio="true"/>
<Separator maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" <Separator maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
orientation="VERTICAL"/> orientation="VERTICAL"/>
<Label fx:id="playerNameLabel" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" <Label fx:id="playerNameLabel" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
Expand Down Expand Up @@ -61,20 +64,43 @@
</HBox> </HBox>
</children> </children>
</VBox> </VBox>
<StackPane prefHeight="430.0" prefWidth="775.0"> <TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
<children> prefHeight="424.0" prefWidth="640.0" tabClosingPolicy="UNAVAILABLE">
<TabPane tabClosingPolicy="UNAVAILABLE"> <tabs>
<tabs> <Tab text="Pokémon">
<Tab text="LuckyEggGrinder"> <content>
<content>
<Button fx:id="openGrinderBtn" prefHeight="25.0" prefWidth="105.0" text="Open"/> </content>
<!-- problem with the embeding atm --> <content>
<!--fx:include fx:id="grinderPane" source="LuckyEggGrinder.fxml" />--> <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
</content> prefHeight="396.0" prefWidth="640.0">
</Tab> <children>
</tabs> <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
</TabPane> minWidth="-Infinity" prefHeight="38.0" prefWidth="640.0"/>
</children> <TreeTableView maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
</StackPane> minWidth="-Infinity" prefHeight="357.0" prefWidth="640.0">
<columns>
<TreeTableColumn prefWidth="75.0" text="#"/>
<TreeTableColumn prefWidth="75.0" text="nickname"/>
</columns>
</TreeTableView>
</children>
</VBox>
</content>
</Tab>
<Tab text="Items">
<content>

</content>
</Tab>
<Tab text="LuckyEggGrinder">
<content>
<Button fx:id="openGrinderBtn" prefHeight="25.0" prefWidth="105.0" text="Open"/>
<!-- problem with the embeding atm -->
<!--fx:include fx:id="grinderPane" source="LuckyEggGrinder.fxml" />-->
</content>
</Tab>
</tabs>
</TabPane>
</children> </children>
</VBox> </VBox>
3 changes: 1 addition & 2 deletions src/me/corriekay/pokegoutil/BlossomsPoGoManager.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import javafx.stage.Stage; import javafx.stage.Stage;
import me.corriekay.pokegoutil.DATA.managers.AccountController; import me.corriekay.pokegoutil.DATA.managers.AccountController;
import me.corriekay.pokegoutil.GUI.controller.ChooseGuiWindowController; import me.corriekay.pokegoutil.GUI.controller.ChooseGuiWindowController;

import me.corriekay.pokegoutil.utils.ConfigKey; import me.corriekay.pokegoutil.utils.ConfigKey;
import me.corriekay.pokegoutil.utils.ConfigNew; import me.corriekay.pokegoutil.utils.ConfigNew;
import me.corriekay.pokegoutil.utils.ui.Console;
import me.corriekay.pokegoutil.utils.helpers.UIHelper; import me.corriekay.pokegoutil.utils.helpers.UIHelper;
import me.corriekay.pokegoutil.utils.ui.Console;


import javax.swing.*; import javax.swing.*;


Expand Down
51 changes: 28 additions & 23 deletions src/me/corriekay/pokegoutil/DATA/managers/AccountController.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import com.pokegoapi.auth.PtcCredentialProvider; import com.pokegoapi.auth.PtcCredentialProvider;
import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException; import com.pokegoapi.exceptions.RemoteServerException;
import me.corriekay.pokegoutil.utils.Config; import me.corriekay.pokegoutil.utils.ConfigKey;
import me.corriekay.pokegoutil.utils.ConfigNew;
import me.corriekay.pokegoutil.utils.helpers.Browser; import me.corriekay.pokegoutil.utils.helpers.Browser;
import me.corriekay.pokegoutil.utils.ui.Console; import me.corriekay.pokegoutil.utils.ui.Console;
import me.corriekay.pokegoutil.windows.PokemonGoMainWindow; import me.corriekay.pokegoutil.windows.PokemonGoMainWindow;
Expand All @@ -28,9 +29,11 @@ public final class AccountController {


private static final AccountController S_INSTANCE = new AccountController(); private static final AccountController S_INSTANCE = new AccountController();
private static boolean sIsInit = false; private static boolean sIsInit = false;
private static Config config = Config.getConfig(); private static ConfigNew config = ConfigNew.getConfig();
protected PokemonGoMainWindow mainWindow = null; protected PokemonGoMainWindow mainWindow = null;
protected PokemonGo go = null; protected PokemonGo go = null;
protected OkHttpClient http;
protected CredentialProvider cp;
private Console console; private Console console;
private boolean logged = false; private boolean logged = false;


Expand Down Expand Up @@ -64,8 +67,8 @@ public static void logOn() {
cp = null; cp = null;
http = new OkHttpClient(); http = new OkHttpClient();


JTextField username = new JTextField(config.getString("login.PTCUsername", null)); JTextField username = new JTextField(config.getString(ConfigKey.LOGIN_PTC_USERNAME));
JTextField password = new JPasswordField(config.getString("login.PTCPassword", null)); JTextField password = new JPasswordField(config.getString(ConfigKey.LOGIN_PTC_PASSWORD));


boolean directLoginWithSavedCredentials = checkForSavedCredentials(); boolean directLoginWithSavedCredentials = checkForSavedCredentials();


Expand Down Expand Up @@ -108,10 +111,10 @@ public static void logOn() {
deleteLoginData(LoginType.GOOGLE, true); deleteLoginData(LoginType.GOOGLE, true);
try { try {
cp = new PtcCredentialProvider(http, username.getText(), password.getText()); cp = new PtcCredentialProvider(http, username.getText(), password.getText());
config.setString("login.PTCUsername", username.getText()); config.setString(ConfigKey.LOGIN_PTC_USERNAME, username.getText());
if (config.getBool("login.SaveAuth", false) || checkSaveAuth()) { if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH) || checkSaveAuth()) {
config.setString("login.PTCPassword", password.getText()); config.setString(ConfigKey.LOGIN_PTC_PASSWORD, password.getText());
config.setBool("login.SaveAuth", true); config.setBool(ConfigKey.LOGIN_SAVE_AUTH, true);
} else { } else {
deleteLoginData(LoginType.PTC); deleteLoginData(LoginType.PTC);
} }
Expand All @@ -123,7 +126,7 @@ public static void logOn() {
} else if (response == JOptionPane.NO_OPTION) { } else if (response == JOptionPane.NO_OPTION) {
//Using Google, remove PTC infos //Using Google, remove PTC infos
deleteLoginData(LoginType.PTC, true); deleteLoginData(LoginType.PTC, true);
String authCode = config.getString("login.GoogleAuthToken", null); String authCode = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN, null);
boolean refresh = false; boolean refresh = false;
if (authCode == null) { if (authCode == null) {
//We need to get the auth code, as we do not have it yet. //We need to get the auth code, as we do not have it yet.
Expand Down Expand Up @@ -153,10 +156,10 @@ public static void logOn() {
if (refresh) provider.refreshToken(authCode); if (refresh) provider.refreshToken(authCode);
else provider.login(authCode); else provider.login(authCode);
cp = provider; cp = provider;
if (config.getBool("login.SaveAuth", false) || checkSaveAuth()) { if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH) || checkSaveAuth()) {
if (!refresh) if (!refresh)
config.setString("login.GoogleAuthToken", provider.getRefreshToken()); config.setString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN, provider.getRefreshToken());
config.setBool("login.SaveAuth", true); config.setBool(ConfigKey.LOGIN_SAVE_AUTH, true);
} else { } else {
deleteLoginData(LoginType.GOOGLE); deleteLoginData(LoginType.GOOGLE);
} }
Expand Down Expand Up @@ -208,7 +211,7 @@ private static boolean checkSaveAuth() {
} }


private static LoginType checkSavedConfig() { private static LoginType checkSavedConfig() {
if (!config.getBool("login.SaveAuth", false)) { if (!config.getBool(ConfigKey.LOGIN_SAVE_AUTH)) {
return LoginType.NONE; return LoginType.NONE;
} else { } else {
if (getLoginData(LoginType.GOOGLE) != null) return LoginType.GOOGLE; if (getLoginData(LoginType.GOOGLE) != null) return LoginType.GOOGLE;
Expand All @@ -220,11 +223,11 @@ private static LoginType checkSavedConfig() {
private static List<String> getLoginData(LoginType type) { private static List<String> getLoginData(LoginType type) {
switch (type) { switch (type) {
case GOOGLE: case GOOGLE:
String token = config.getString("login.GoogleAuthToken", null); String token = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
return (token != null) ? Collections.singletonList(token) : null; return (token != null) ? Collections.singletonList(token) : null;
case PTC: case PTC:
String username = config.getString("login.PTCUsername", null); String username = config.getString(ConfigKey.LOGIN_PTC_USERNAME);
String password = config.getString("login.PTCPassword", null); String password = config.getString(ConfigKey.LOGIN_PTC_PASSWORD);
return (username != null && password != null) ? Arrays.asList(username, password) : null; return (username != null && password != null) ? Arrays.asList(username, password) : null;
default: default:
return null; return null;
Expand All @@ -237,18 +240,20 @@ private static void deleteLoginData(LoginType type) {
} }


private static void deleteLoginData(LoginType type, boolean justCleanup) { private static void deleteLoginData(LoginType type, boolean justCleanup) {
if (!justCleanup) config.delete("login.SaveAuth"); if (!justCleanup) config.delete(ConfigKey.LOGIN_SAVE_AUTH);
switch (type) { switch (type) {
case BOTH: case BOTH:
config.delete("login.GoogleAuthToken"); config.delete(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
config.delete("login.PTCUsername"); config.delete(ConfigKey.LOGIN_PTC_USERNAME);
config.delete("login.PTCPassword"); config.delete(ConfigKey.LOGIN_PTC_PASSWORD);
case GOOGLE: case GOOGLE:
config.delete("login.GoogleAuthToken"); config.delete(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
case PTC: case PTC:
config.delete("login.PTCUsername"); config.delete(ConfigKey.LOGIN_PTC_USERNAME);
config.delete("login.PTCPassword"); config.delete(ConfigKey.LOGIN_PTC_PASSWORD);
default: default:


} }
} }


Expand Down
42 changes: 21 additions & 21 deletions src/me/corriekay/pokegoutil/DATA/managers/AccountManager.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void initialize() {
sIsInit = true; sIsInit = true;
} }


public static void login(List<Pair> loginData, LoginType loginType) throws Exception{ public static void login(List<Pair> loginData, LoginType loginType) throws Exception {
loginData.forEach(pair -> { loginData.forEach(pair -> {
switch (pair.getKey().toString()) { switch (pair.getKey().toString()) {
case "username": case "username":
Expand All @@ -64,7 +64,7 @@ public static void login(List<Pair> loginData, LoginType loginType) throws Excep
} }
} }


private static void logOnPTC(String username, String password) throws Exception{ private static void logOnPTC(String username, String password) throws Exception {
if (!sIsInit) { if (!sIsInit) {
throw new ExceptionInInitializerError("AccountController needs to be initialized before logging on"); throw new ExceptionInInitializerError("AccountController needs to be initialized before logging on");
} }
Expand All @@ -76,7 +76,7 @@ private static void logOnPTC(String username, String password) throws Exception{
try { try {
cp = new PtcCredentialProvider(http, username, password); cp = new PtcCredentialProvider(http, username, password);
config.setString(ConfigKey.LOGIN_PTC_USERNAME, username); config.setString(ConfigKey.LOGIN_PTC_USERNAME, username);
if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH, false)) { if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH)) {
config.setString(ConfigKey.LOGIN_PTC_PASSWORD, password); config.setString(ConfigKey.LOGIN_PTC_PASSWORD, password);
} else { } else {
deleteLoginData(LoginType.PTC); deleteLoginData(LoginType.PTC);
Expand Down Expand Up @@ -114,9 +114,9 @@ private static void logOnGoogleAuth(String authCode) {
http = new OkHttpClient(); http = new OkHttpClient();


boolean refresh = false; boolean refresh = false;
if (authCode.equals("Using Previous Token") && config.getBool(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN, false)) { if (authCode.equals("Using Previous Token") && config.getBool(ConfigKey.LOGIN_SAVE_AUTH)) {
// Get credentials // Get credentials
authCode = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN, null); authCode = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
refresh = true; refresh = true;
} }


Expand All @@ -130,7 +130,7 @@ private static void logOnGoogleAuth(String authCode) {
throw new LoginFailedException(); throw new LoginFailedException();


cp = provider; cp = provider;
if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH, false)) { if (config.getBool(ConfigKey.LOGIN_SAVE_AUTH)) {
if (!refresh) if (!refresh)
config.setString(ConfigKey.LOGIN_SAVE_AUTH, provider.getRefreshToken()); config.setString(ConfigKey.LOGIN_SAVE_AUTH, provider.getRefreshToken());
} else { } else {
Expand Down Expand Up @@ -164,7 +164,7 @@ private static void initOtherControllers(PokemonGo go) {
ProfileManager.initialize(go); ProfileManager.initialize(go);
} }


private static void alertFailedLogin(String message) { public static void alertFailedLogin(String message) {
Alert alert = new Alert(Alert.AlertType.ERROR); Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Error Login"); alert.setTitle("Error Login");
alert.setHeaderText("Unfortunately, your login has failed"); alert.setHeaderText("Unfortunately, your login has failed");
Expand All @@ -175,18 +175,18 @@ private static void alertFailedLogin(String message) {
public static List<Pair> getLoginData(LoginType type) { public static List<Pair> getLoginData(LoginType type) {
switch (type) { switch (type) {
case GOOGLE: case GOOGLE:
String token = config.getString("login.GoogleAuthToken", null); String token = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
return (token != null) ? Collections.singletonList( return (token != null) ? Collections.singletonList(
new Pair<>("token", token)) : null; new Pair<>("token", token)) : null;
case PTC: case PTC:
String username = config.getString(ConfigKey.LOGIN_PTC_USERNAME, null); String username = config.getString(ConfigKey.LOGIN_PTC_USERNAME);
String password = config.getString(ConfigKey.LOGIN_PTC_PASSWORD, null); String password = config.getString(ConfigKey.LOGIN_PTC_PASSWORD);
return (username != null && password != null) ? Arrays.asList( return (username != null && password != null) ? Arrays.asList(
new Pair<>("username", username), new Pair<>("password", password)) : null; new Pair<>("username", username), new Pair<>("password", password)) : null;
case BOTH: case BOTH:
String token2 = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN, null); String token2 = config.getString(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
String username2 = config.getString(ConfigKey.LOGIN_PTC_USERNAME, null); String username2 = config.getString(ConfigKey.LOGIN_PTC_USERNAME);
String password2 = config.getString("login.PTCPassword", null); String password2 = config.getString(ConfigKey.LOGIN_PTC_PASSWORD);
return (username2 != null && password2 != null && token2 != null) ? Arrays.asList( return (username2 != null && password2 != null && token2 != null) ? Arrays.asList(
new Pair<>("username", username2), new Pair<>("password", password2), new Pair<>("token", token2)) : null; new Pair<>("username", username2), new Pair<>("password", password2), new Pair<>("token", token2)) : null;
default: default:
Expand All @@ -199,19 +199,19 @@ private static void deleteLoginData(LoginType type) {
} }


private static void deleteLoginData(LoginType type, boolean justCleanup) { private static void deleteLoginData(LoginType type, boolean justCleanup) {
if (!justCleanup) config.delete("login.SaveAuth"); if (!justCleanup) config.delete(ConfigKey.LOGIN_SAVE_AUTH);
switch (type) { switch (type) {
case BOTH: case BOTH:
config.delete("login.GoogleAuthToken"); config.delete(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
config.delete("login.PTCUsername"); config.delete(ConfigKey.LOGIN_PTC_USERNAME);
config.delete("login.PTCPassword"); config.delete(ConfigKey.LOGIN_PTC_PASSWORD);
break; break;
case GOOGLE: case GOOGLE:
config.delete("login.GoogleAuthToken"); config.delete(ConfigKey.LOGIN_GOOGLE_AUTH_TOKEN);
break; break;
case PTC: case PTC:
config.delete("login.PTCUsername"); config.delete(ConfigKey.LOGIN_PTC_USERNAME);
config.delete("login.PTCPassword"); config.delete(ConfigKey.LOGIN_PTC_PASSWORD);
break; break;
default: default:
} }
Expand Down Expand Up @@ -250,7 +250,7 @@ public static boolean isLoggedIn() {
} }


public static void setSaveLogin(boolean save){ public static void setSaveLogin(boolean save){
config.setBool("login.SaveAuth", save); config.setBool(ConfigKey.LOGIN_SAVE_AUTH, save);
} }


public enum LoginType { public enum LoginType {
Expand Down
14 changes: 11 additions & 3 deletions src/me/corriekay/pokegoutil/GUI/controller/LoginController.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ private void toggleFields(boolean save){


@FXML @FXML
void onGoogleAuthBtnClicked(ActionEvent event) { void onGoogleAuthBtnClicked(ActionEvent event) {
AccountManager.login(Collections.singletonList(new Pair<>("token", tokenField.getText())), LoginType.GOOGLE); try {
AccountManager.login(Collections.singletonList(new Pair<>("token", tokenField.getText())), LoginType.GOOGLE);
} catch (Exception e) {
AccountManager.alertFailedLogin(e.toString());
}
if (AccountManager.isLoggedIn()) { if (AccountManager.isLoggedIn()) {
rootScene.getWindow().hide(); rootScene.getWindow().hide();
openMainWindow(); openMainWindow();
Expand All @@ -145,8 +149,12 @@ void onGoogleAuthBtnClicked(ActionEvent event) {


@FXML @FXML
void onPTCLoginBtnClicked(ActionEvent event) { void onPTCLoginBtnClicked(ActionEvent event) {
AccountManager.login(Arrays.asList(new Pair<>("username", usernameField.getText()), try {
new Pair<>("password", passwordField.getText())), LoginType.PTC); AccountManager.login(Arrays.asList(new Pair<>("username", usernameField.getText()),
new Pair<>("password", passwordField.getText())), LoginType.PTC);
} catch (Exception e) {
AccountManager.alertFailedLogin(e.getMessage());
}
if (AccountManager.isLoggedIn()) { if (AccountManager.isLoggedIn()) {
rootScene.getWindow().hide(); rootScene.getWindow().hide();
openMainWindow(); openMainWindow();
Expand Down
Loading

0 comments on commit 908ce0f

Please sign in to comment.