Skip to content

Commit 1396e1e

Browse files
committed
Fix manually specifying identifier (#137, #145)
1 parent 949e2b3 commit 1396e1e

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/airsquared/blobsaver/Background.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private static void saveBackgroundBlobs(int preset) {
215215
if (!"none".equals(boardConfig) && !"".equals(boardConfig)) { // needs board config
216216
Collections.addAll(args, "--boardconfig", boardConfig);
217217
}
218-
if (!"".equals(apnonce)) {
218+
if (!Shared.isEmptyOrNull(apnonce)) {
219219
Collections.addAll(args, "--apnonce", apnonce);
220220
}
221221
tsscheckerLog = executeProgram(args.toArray(new String[0]));

src/main/java/com/airsquared/blobsaver/Controller.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class Controller {
8787

8888
static void afterStageShowing() {
8989
for (int i = 0; i < 10; i++) { // sets the names for the presets
90-
if (!"".equals(appPrefs.get("Name Preset" + i, ""))) {
90+
if (!Shared.isEmptyOrNull(appPrefs.get("Name Preset" + i, ""))) {
9191
Button btn = (Button) primaryStage.getScene().lookup("#preset" + i);
9292
btn.setText("Load " + appPrefs.get("Name Preset" + i, ""));
9393
}
@@ -127,12 +127,18 @@ public void initialize() {
127127
deviceTypeChoiceBox.setValue("iPhone");
128128
deviceModelChoiceBox.getSelectionModel().selectedItemProperty().addListener((x, y, newValue) -> {
129129
deviceModelChoiceBox.setEffect(null);
130+
if (Shared.isEmptyOrNull((String) newValue)) {
131+
return;
132+
}
130133
String identifier = Devices.getDeviceModelIdentifiersMap().get(newValue.toString());
131134
requireBoardConfig(identifier);
132135
requireApnonce(identifier);
133136
});
134137
identifierField.textProperty().addListener((x, y, identifier) -> {
135138
identifierField.setEffect(null);
139+
if (Shared.isEmptyOrNull(identifier)) {
140+
return;
141+
}
136142
requireBoardConfig(identifier);
137143
requireApnonce(identifier);
138144
});
@@ -296,7 +302,7 @@ private void loadPreset(int preset) {
296302
return;
297303
}
298304
ecidField.setText(prefs.get("ECID", ""));
299-
if (!"".equals(prefs.get("Path", ""))) {
305+
if (!Shared.isEmptyOrNull(prefs.get("Path", ""))) {
300306
pathField.setText(prefs.get("Path", ""));
301307
}
302308
if ("none".equals(prefs.get("Device Model", ""))) {
@@ -312,7 +318,7 @@ private void loadPreset(int preset) {
312318
if (!"none".equals(prefs.get("Board Config", "")) && getBoardConfig) {
313319
boardConfigField.setText(prefs.get("Board Config", ""));
314320
}
315-
if (!"".equals(prefs.get("Apnonce", ""))) {
321+
if (!Shared.isEmptyOrNull(prefs.get("Apnonce", ""))) {
316322
if (!apnonceCheckBox.isSelected()) {
317323
apnonceCheckBox.fire();
318324
}
@@ -364,7 +370,7 @@ public void presetButtonHandler(ActionEvent evt) {
364370
@SuppressWarnings("Duplicates")
365371
private void savePreset(int preset) {
366372
boolean doReturn = false;
367-
if (!identifierCheckBox.isSelected() && "".equals(deviceModelChoiceBox.getValue())) {
373+
if (!identifierCheckBox.isSelected() && Shared.isEmptyOrNull((String) deviceModelChoiceBox.getValue())) {
368374
deviceModelChoiceBox.setEffect(errorBorder);
369375
doReturn = true;
370376
}
@@ -382,7 +388,7 @@ private void savePreset(int preset) {
382388
textInputDialog.showAndWait();
383389

384390
String result = textInputDialog.getResult();
385-
if (result != null && !"".equals(result)) {
391+
if (Shared.isEmptyOrNull(result)) {
386392
appPrefs.put("Name Preset" + preset, textInputDialog.getResult());
387393
((Button) primaryStage.getScene().lookup("#preset" + preset)).setText("Save in " + textInputDialog.getResult());
388394
} else {
@@ -633,7 +639,6 @@ private void useMacOSMenuBar() {
633639

634640
// needs to be run with Platform.runLater(), otherwise the application menu doesn't show up
635641
Platform.runLater(() -> tk.setGlobalMenuBar(macOSMenuBar));
636-
System.out.println("using macOS menu bar");
637642
}
638643

639644
public void backgroundSettingsHandler() {
@@ -708,7 +713,7 @@ public void chooseTimeToRunHandler() {
708713
hBox.getChildren().addAll(textField, choiceBox);
709714
alert.getDialogPane().setContent(hBox);
710715
alert.showAndWait();
711-
if ((alert.getResult() != null) && !ButtonType.CANCEL.equals(alert.getResult()) && !"".equals(textField.getText()) && (choiceBox.getValue() != null)) {
716+
if ((alert.getResult() != null) && !ButtonType.CANCEL.equals(alert.getResult()) && !Shared.isEmptyOrNull(textField.getText()) && Shared.isEmptyOrNull(choiceBox.getValue())) {
712717
appPrefs.putInt("Time to run", Integer.parseInt(textField.getText()));
713718
appPrefs.put("Time unit for background", choiceBox.getValue());
714719
} else {
@@ -891,11 +896,11 @@ public void readApnonce() {
891896
@SuppressWarnings("Duplicates")
892897
public void goButtonHandler() {
893898
boolean doReturn = false;
894-
if (!identifierCheckBox.isSelected() && (deviceTypeChoiceBox.getValue() == null || "".equals(deviceTypeChoiceBox.getValue()))) {
899+
if (!identifierCheckBox.isSelected() && Shared.isEmptyOrNull((String) deviceTypeChoiceBox.getValue())) {
895900
deviceTypeChoiceBox.setEffect(errorBorder);
896901
doReturn = true;
897902
}
898-
if (!identifierCheckBox.isSelected() && ("".equals(deviceModelChoiceBox.getValue()))) {
903+
if (!identifierCheckBox.isSelected() && Shared.isEmptyOrNull((String) deviceModelChoiceBox.getValue())) {
899904
deviceModelChoiceBox.setEffect(errorBorder);
900905
doReturn = true;
901906
}
@@ -910,7 +915,7 @@ public void goButtonHandler() {
910915
if (doReturn) return;
911916

912917
String deviceModel = (String) deviceModelChoiceBox.getValue();
913-
if ("".equals(deviceModel)) {
918+
if (Shared.isEmptyOrNull(deviceModel)) {
914919
String identifierText = identifierField.getText();
915920
try {
916921
if (identifierText.startsWith("iPad") || identifierText.startsWith("iPod") || identifierText.startsWith("iPhone") || identifierText.startsWith("AppleTV")) {
@@ -952,7 +957,7 @@ private static boolean isTextFieldInvalid(CheckBox checkBox, TextField textField
952957
}
953958

954959
private static boolean isTextFieldInvalid(boolean isTextFieldRequired, TextField textField) {
955-
if (isTextFieldRequired && (textField.getText() == null || "".equals(textField.getText()))) {
960+
if (isTextFieldRequired && Shared.isEmptyOrNull(textField.getText())) {
956961
textField.setEffect(errorBorder);
957962
return true;
958963
}

src/main/java/com/airsquared/blobsaver/Shared.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ static String exceptionToString(Throwable t) {
320320
return writer.toString();
321321
}
322322

323+
static boolean isEmptyOrNull(String s) {
324+
return s == null || s.isEmpty();
325+
}
326+
323327
// temporary until ProGuard is implemented
324328
static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr) {
325329
if (str == null || searchStr == null) {

0 commit comments

Comments
 (0)