Skip to content

Commit

Permalink
More refactoring of duplicate use
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptically committed Aug 14, 2016
1 parent a31b69a commit bb722cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java
Expand Up @@ -21,6 +21,7 @@ public class PokeHandler {
public static final int MAX_NICKNAME_LENGTH = 12;

private ArrayList<Pokemon> mons;
private Config config = Config.getConfig();

public PokeHandler(Pokemon pokemon) {
this(new Pokemon[]{pokemon});
Expand Down Expand Up @@ -114,7 +115,7 @@ private static NicknamePokemonResponse.Result renWPattern(String pattern, Pokemo
*/
public static String getLocalPokeName(int id) {
// TODO: change call to getConfigItem to config class once implemented
String lang = Config.getConfig().getString("options.lang", "en");
String lang = config.getString("options.lang", "en");

Locale locale;
String[] langar = lang.split("_");
Expand Down
30 changes: 16 additions & 14 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Expand Up @@ -47,6 +47,8 @@ public class PokemonTab extends JPanel {
private final PokemonTable pt = new PokemonTable();
private final JTextField searchBar = new JTextField("");
private final JTextField ivTransfer = new JTextField("", 20);

private Config config = Config.getConfig();

public PokemonTab(PokemonGo go) {
setLayout(new BorderLayout());
Expand Down Expand Up @@ -164,7 +166,7 @@ protected Void doInBackground() throws Exception {
// pokemon name language drop down
String[] locales = {"en", "de", "fr", "ru", "zh_CN", "zh_HK"};
JComboBox<String> pokelang = new JComboBox<>(locales);
String locale = Config.getConfig().getString("options.lang", "en");
String locale = config.getString("options.lang", "en");
pokelang.setSelectedItem(locale);
pokelang.addActionListener(e -> new SwingWorker<Void, Void>() {
protected Void doInBackground() throws Exception {
Expand Down Expand Up @@ -194,7 +196,7 @@ protected Void doInBackground() throws Exception {
JComboBox<String> source = (JComboBox<String>) e.getSource();
String size = source.getSelectedItem().toString();
pt.setFont(pt.getFont().deriveFont(Float.parseFloat(size)));
Config.getConfig().setInt("options.fontsize", Integer.parseInt(size));
config.setInt("options.fontsize", Integer.parseInt(size));
return null;
}
}.execute());
Expand All @@ -210,7 +212,7 @@ protected Void doInBackground() throws Exception {
}

private void changeLanguage(String langCode) {
Config.getConfig().setString("options.lang", langCode);
config.setString("options.lang", langCode);
refreshPkmn();
}

Expand All @@ -231,7 +233,7 @@ private void showFinishedText(String message, int size, MutableInt success, Muta
(skipped.getValue() > 0 ? "\nSkipped: " + skipped.getValue() : "") +
(err.getValue() > 0 ? "\nErrors: " + err.getValue() : "");

if (Config.getConfig().getBool("popup.afterBulk", true)) {
if (config.getBool("popup.afterBulk", true)) {
JOptionPane.showMessageDialog(null, finishText);
} else {
System.out.println(finishText);
Expand Down Expand Up @@ -269,8 +271,8 @@ private void renameSelected() {

// If not last element and API was queried, sleep until the next one
if (!selection.get(selection.size() - 1).equals(pokemon)) {
int sleepMin = Config.getConfig().getInt("delay.rename.min", 1000);
int sleepMax = Config.getConfig().getInt("delay.rename.max", 5000);
int sleepMin = config.getInt("delay.rename.min", 1000);
int sleepMax = config.getInt("delay.rename.max", 5000);
Utilities.sleepRandom(sleepMin, sleepMax);
}
};
Expand Down Expand Up @@ -322,8 +324,8 @@ private void transferSelected() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = Config.getConfig().getInt("delay.transfer.min", 1000);
int sleepMax = Config.getConfig().getInt("delay.transfer.max", 5000);
int sleepMin = config.getInt("delay.transfer.min", 1000);
int sleepMax = config.getInt("delay.transfer.max", 5000);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down Expand Up @@ -368,7 +370,7 @@ private void evolveSelected() {
int newHp = newPoke.getStamina();
System.out.println(
"Evolving " + PokeHandler.getLocalPokeName(poke) + ". Evolve result: Success!");
if (Config.getConfig().getBool("transfer.afterEvolve", false)) {
if (config.getBool("transfer.afterEvolve", false)) {
ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result result = newPoke.transferPokemon();
System.out.println("Transferring " + StringUtils.capitalize(newPoke.getPokemonId().toString().toLowerCase()) + ", Result: " + result);
System.out.println("Stat changes: (Candies: " + newCandies + "[" + candies + "-" + candiesToEvolve + "]");
Expand Down Expand Up @@ -400,7 +402,7 @@ private void evolveSelected() {
}
SwingUtilities.invokeLater(this::refreshList);
showFinishedText("Pokémon batch evolve"
+ ((Config.getConfig().getBool("transfer.afterEvolve", false)) ? "/transfer" : "")
+ ((config.getBool("transfer.afterEvolve", false)) ? "/transfer" : "")
+ " complete!", selection.size(), success, skipped, err);
}
}
Expand Down Expand Up @@ -444,8 +446,8 @@ private void powerUpSelected() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = Config.getConfig().getInt("delay.powerUp.min", 1000);
int sleepMax = Config.getConfig().getInt("delay.powerUp.max", 5000);
int sleepMin = config.getInt("delay.powerUp.min", 1000);
int sleepMax = config.getInt("delay.powerUp.max", 5000);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down Expand Up @@ -491,8 +493,8 @@ private void toggleFavorite() {

// If not last element, sleep until the next one
if (!selection.get(selection.size() - 1).equals(poke)) {
int sleepMin = Config.getConfig().getInt("delay.favorite.min", 1000);
int sleepMax = Config.getConfig().getInt("delay.favorite.max", 3000);
int sleepMin = config.getInt("delay.favorite.min", 1000);
int sleepMax = config.getInt("delay.favorite.max", 3000);
Utilities.sleepRandom(sleepMin, sleepMax);
}
} catch (Exception e) {
Expand Down

0 comments on commit bb722cf

Please sign in to comment.