소스 검색

fix broken `passwordsMatchAndSufficientProperty` which didn't update more than once

Sebastian Stenzel 3 년 전
부모
커밋
8896723ff2

+ 1 - 1
src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java

@@ -107,7 +107,7 @@ public class CreateNewVaultPasswordController implements FxController {
 
 	@FXML
 	public void initialize() {
-		readyToCreateVault.bind(newPasswordSceneController.passwordsMatchAndSufficientProperty().and(recoveryKeyChoice.selectedToggleProperty().isNotNull()).and(processing.not()));
+		readyToCreateVault.bind(newPasswordSceneController.goodPasswordProperty().and(recoveryKeyChoice.selectedToggleProperty().isNotNull()).and(processing.not()));
 		window.setOnHiding(event -> {
 			newPasswordSceneController.passwordField.wipe();
 			newPasswordSceneController.reenterField.wipe();

+ 1 - 1
src/main/java/org/cryptomator/ui/changepassword/ChangePasswordController.java

@@ -62,7 +62,7 @@ public class ChangePasswordController implements FxController {
 	public void initialize() {
 		BooleanBinding checkboxNotConfirmed = finalConfirmationCheckbox.selectedProperty().not();
 		BooleanBinding oldPasswordFieldEmpty = oldPasswordField.textProperty().isEmpty();
-		finishButton.disableProperty().bind(checkboxNotConfirmed.or(oldPasswordFieldEmpty).or(newPasswordController.passwordsMatchAndSufficientProperty().not()));
+		finishButton.disableProperty().bind(checkboxNotConfirmed.or(oldPasswordFieldEmpty).or(newPasswordController.goodPasswordProperty().not()));
 		window.setOnHiding(event -> {
 			oldPasswordField.wipe();
 			newPasswordController.passwordField.wipe();

+ 15 - 14
src/main/java/org/cryptomator/ui/common/NewPasswordController.java

@@ -4,12 +4,12 @@ import com.tobiasdiez.easybind.EasyBind;
 import org.cryptomator.ui.controls.FontAwesome5IconView;
 import org.cryptomator.ui.controls.NiceSecurePasswordField;
 
-import javafx.beans.Observable;
 import javafx.beans.binding.Bindings;
 import javafx.beans.binding.BooleanBinding;
+import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.IntegerProperty;
 import javafx.beans.property.ReadOnlyBooleanProperty;
-import javafx.beans.property.ReadOnlyBooleanWrapper;
+import javafx.beans.property.SimpleBooleanProperty;
 import javafx.beans.property.SimpleIntegerProperty;
 import javafx.fxml.FXML;
 import javafx.scene.control.Label;
@@ -20,7 +20,7 @@ public class NewPasswordController implements FxController {
 	private final ResourceBundle resourceBundle;
 	private final PasswordStrengthUtil strengthRater;
 	private final IntegerProperty passwordStrength = new SimpleIntegerProperty(-1);
-	private final ReadOnlyBooleanWrapper passwordsMatchAndSufficient = new ReadOnlyBooleanWrapper();
+	private final BooleanProperty goodPassword = new SimpleBooleanProperty();
 
 	public NiceSecurePasswordField passwordField;
 	public NiceSecurePasswordField reenterField;
@@ -50,11 +50,10 @@ public class NewPasswordController implements FxController {
 		passwordMatchLabel.graphicProperty().bind(Bindings.when(passwordsMatch.and(reenterFieldNotEmpty)).then(passwordMatchCheckmark).otherwise(passwordMatchCross));
 		passwordMatchLabel.textProperty().bind(Bindings.when(passwordsMatch.and(reenterFieldNotEmpty)).then(resourceBundle.getString("newPassword.passwordsMatch")).otherwise(resourceBundle.getString("newPassword.passwordsDoNotMatch")));
 
-		passwordField.textProperty().addListener(this::passwordsDidChange);
-		reenterField.textProperty().addListener(this::passwordsDidChange);
+		BooleanBinding sufficientStrength = Bindings.createBooleanBinding(this::sufficientStrength, passwordField.textProperty());
+		goodPassword.bind(passwordsMatch.and(sufficientStrength));
 	}
 
-
 	private FontAwesome5IconView getIconViewForPasswordStrengthLabel() {
 		if (passwordField.getCharacters().length() == 0) {
 			return null;
@@ -67,22 +66,24 @@ public class NewPasswordController implements FxController {
 		}
 	}
 
-	private void passwordsDidChange(@SuppressWarnings("unused") Observable observable) {
-		if (passwordFieldsMatch() && strengthRater.fulfillsMinimumRequirements(passwordField.getCharacters())) {
-			passwordsMatchAndSufficient.setValue(true);
-		}
-	}
-
 	private boolean passwordFieldsMatch() {
 		return CharSequence.compare(passwordField.getCharacters(), reenterField.getCharacters()) == 0;
 	}
 
-	public ReadOnlyBooleanProperty passwordsMatchAndSufficientProperty() {
-		return passwordsMatchAndSufficient.getReadOnlyProperty();
+	private boolean sufficientStrength() {
+		return strengthRater.fulfillsMinimumRequirements(passwordField.getCharacters());
 	}
 
 	/* Getter/Setter */
 
+	public ReadOnlyBooleanProperty goodPasswordProperty() {
+		return goodPassword;
+	}
+
+	public boolean isGoodPassword() {
+		return goodPassword.get();
+	}
+
 	public IntegerProperty passwordStrengthProperty() {
 		return passwordStrength;
 	}

+ 2 - 2
src/main/java/org/cryptomator/ui/recoverykey/RecoveryKeyResetPasswordController.java

@@ -86,11 +86,11 @@ public class RecoveryKeyResetPasswordController implements FxController {
 	/* Getter/Setter */
 
 	public ReadOnlyBooleanProperty validPasswordProperty() {
-		return newPasswordController.passwordsMatchAndSufficientProperty();
+		return newPasswordController.goodPasswordProperty();
 	}
 
 	public boolean isValidPassword() {
-		return newPasswordController.passwordsMatchAndSufficientProperty().get();
+		return newPasswordController.isGoodPassword();
 	}
 
 }