Browse Source

Changed textfield to only accept Integers, Using scheduled Executor as Timer

Martin Beyer 4 years ago
parent
commit
92de05b3db

+ 4 - 11
main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java

@@ -11,14 +11,7 @@ import com.google.common.io.BaseEncoding;
 import javafx.beans.Observable;
 import javafx.beans.binding.Bindings;
 import javafx.beans.binding.StringBinding;
-import javafx.beans.property.BooleanProperty;
-import javafx.beans.property.IntegerProperty;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleBooleanProperty;
-import javafx.beans.property.SimpleIntegerProperty;
-import javafx.beans.property.SimpleObjectProperty;
-import javafx.beans.property.SimpleStringProperty;
-import javafx.beans.property.StringProperty;
+import javafx.beans.property.*;
 
 import java.nio.file.Path;
 import java.util.Objects;
@@ -38,7 +31,7 @@ public class VaultSettings {
 	public static final int DEFAULT_FILENAME_LENGTH_LIMIT = -1;
 	public static final WhenUnlocked DEFAULT_ACTION_AFTER_UNLOCK = WhenUnlocked.ASK;
 	public static final boolean DEFAULT_LOCK_AFTER_TIME = false;
-	public static final String DEFAULT_LOCK_TIME_IN_MINUTES = "30";
+	public static final int DEFAULT_LOCK_TIME_IN_MINUTES = 30;
 
 	private static final Random RNG = new Random();
 
@@ -55,7 +48,7 @@ public class VaultSettings {
 	private final IntegerProperty filenameLengthLimit = new SimpleIntegerProperty(DEFAULT_FILENAME_LENGTH_LIMIT);
 	private final ObjectProperty<WhenUnlocked> actionAfterUnlock = new SimpleObjectProperty<>(DEFAULT_ACTION_AFTER_UNLOCK);
 	private final BooleanProperty lockAfterTime = new SimpleBooleanProperty(DEFAULT_LOCK_AFTER_TIME);
-	private final StringProperty lockTimeInMinutes = new SimpleStringProperty(DEFAULT_LOCK_TIME_IN_MINUTES);
+	private final IntegerProperty lockTimeInMinutes = new SimpleIntegerProperty(DEFAULT_LOCK_TIME_IN_MINUTES);
 	private final StringBinding mountName;
 
 	public VaultSettings(String id) {
@@ -169,7 +162,7 @@ public class VaultSettings {
 		return lockAfterTime;
 	}
 
-	public StringProperty lockTimeInMinutes() {
+	public IntegerProperty lockTimeInMinutes() {
 		return lockTimeInMinutes;
 	}
 

+ 2 - 2
main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java

@@ -51,7 +51,7 @@ class VaultSettingsJsonAdapter {
 		int filenameLengthLimit = VaultSettings.DEFAULT_FILENAME_LENGTH_LIMIT;
 		WhenUnlocked actionAfterUnlock = VaultSettings.DEFAULT_ACTION_AFTER_UNLOCK;
 		boolean lockAfterTime = VaultSettings.DEFAULT_LOCK_AFTER_TIME;
-		String lockTimeInMinutes = VaultSettings.DEFAULT_LOCK_TIME_IN_MINUTES;
+		int lockTimeInMinutes = VaultSettings.DEFAULT_LOCK_TIME_IN_MINUTES;
 
 		in.beginObject();
 		while (in.hasNext()) {
@@ -71,7 +71,7 @@ class VaultSettingsJsonAdapter {
 				case "filenameLengthLimit" -> filenameLengthLimit = in.nextInt();
 				case "actionAfterUnlock" -> actionAfterUnlock = parseActionAfterUnlock(in.nextString());
 				case "lockAfterTime" -> lockAfterTime = in.nextBoolean();
-				case "lockTimeInMinutes" -> lockTimeInMinutes = in.nextString();
+				case "lockTimeInMinutes" -> lockTimeInMinutes = in.nextInt();
 				default -> {
 					LOG.warn("Unsupported vault setting found in JSON: " + name);
 					in.skipValue();

File diff suppressed because it is too large
+ 10 - 15
main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java


+ 4 - 3
main/ui/src/main/java/org/cryptomator/ui/vaultoptions/AutoLockVaultOptionsController.java

@@ -5,12 +5,14 @@ import org.cryptomator.ui.common.FxController;
 
 import javax.inject.Inject;
 
+import javafx.beans.binding.Bindings;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.fxml.FXML;
 import javafx.scene.control.CheckBox;
 import javafx.scene.control.TextField;
 import javafx.stage.Stage;
+import javafx.util.converter.NumberStringConverter;
 
 import java.util.ResourceBundle;
 
@@ -31,12 +33,11 @@ public class AutoLockVaultOptionsController implements FxController {
 	@FXML
 	public void initialize() {
 		lockAfterTimeCheckbox.selectedProperty().bindBidirectional(vault.getVaultSettings().lockAfterTime());
-		lockTimeInMinutesTextField.textProperty().bindBidirectional(vault.getVaultSettings().lockTimeInMinutes());
-		//force the field to be a double with the correct decimal point
+		Bindings.bindBidirectional(lockTimeInMinutesTextField.textProperty(), vault.getVaultSettings().lockTimeInMinutes(), new NumberStringConverter());
 		lockTimeInMinutesTextField.textProperty().addListener(new ChangeListener<String>() {
 			@Override
 			public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
-				if (!newValue.matches("\\d{0,9}([\\.]\\d{0,9})?")) {
+				if (!newValue.matches("\\d{0,9}")) {
 					lockTimeInMinutesTextField.setText(newValue.replaceAll("[^\\d]", ""));
 				}
 			}

+ 0 - 3
main/ui/src/main/resources/i18n/strings.properties

@@ -294,9 +294,6 @@ vaultOptions.masterkey.showRecoveryKeyBtn=Display Recovery Key
 vaultOptions.masterkey.recoverPasswordBtn=Recover Password
 ## Auto Lock
 vaultOptions.autoLock=Auto-Lock
-vaultOptions.autoLock.lockOnSleep=Lock on sleep
-vaultOptions.autoLock.lockAfterIdleTimePart1=Lock after computer is idle for
-vaultOptions.autoLock.lockAfterIdleTimePart2=minutes.
 vaultOptions.autoLock.lockAfterTimePart1=Lock after
 vaultOptions.autoLock.lockAfterTimePart2=minutes.