|
@@ -15,18 +15,20 @@ import javafx.beans.property.BooleanProperty;
|
|
|
import javafx.beans.property.ObjectProperty;
|
|
|
import javafx.beans.property.ReadOnlyStringProperty;
|
|
|
import javafx.beans.property.SimpleBooleanProperty;
|
|
|
+import javafx.beans.value.ObservableValue;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.scene.control.CheckBox;
|
|
|
import javafx.scene.control.ContentDisplay;
|
|
|
import javafx.scene.control.Label;
|
|
|
import javafx.scene.layout.HBox;
|
|
|
-import javafx.util.Duration;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.time.format.FormatStyle;
|
|
|
-import java.util.Date;
|
|
|
import java.util.Locale;
|
|
|
+import java.util.ResourceBundle;
|
|
|
|
|
|
|
|
|
@PreferencesScoped
|
|
@@ -36,12 +38,13 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
|
|
|
private final Application application;
|
|
|
private final Environment environment;
|
|
|
+ private final ResourceBundle resourceBundle;
|
|
|
private final Settings settings;
|
|
|
private final UpdateChecker updateChecker;
|
|
|
private final ObjectBinding<ContentDisplay> checkForUpdatesButtonState;
|
|
|
private final ReadOnlyStringProperty latestVersion;
|
|
|
- private final ObjectProperty<Date> lastSuccessfulUpdateCheck;
|
|
|
- private final ReadOnlyStringProperty timeDifferenceMessage;
|
|
|
+ private final ObservableValue<Instant> lastSuccessfulUpdateCheck;
|
|
|
+ private final ObservableValue<String> timeDifferenceMessage;
|
|
|
private final String currentVersion;
|
|
|
private final BooleanBinding updateAvailable;
|
|
|
private final BooleanProperty upToDateLabelVisible = new SimpleBooleanProperty(false);
|
|
@@ -53,15 +56,16 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
public Label upToDateLabel;
|
|
|
|
|
|
@Inject
|
|
|
- UpdatesPreferencesController(Application application, Environment environment, Settings settings, UpdateChecker updateChecker) {
|
|
|
+ UpdatesPreferencesController(Application application, Environment environment, ResourceBundle resourceBundle, Settings settings, UpdateChecker updateChecker) {
|
|
|
this.application = application;
|
|
|
this.environment = environment;
|
|
|
+ this.resourceBundle = resourceBundle;
|
|
|
this.settings = settings;
|
|
|
this.updateChecker = updateChecker;
|
|
|
this.checkForUpdatesButtonState = Bindings.when(updateChecker.checkingForUpdatesProperty()).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
|
|
|
this.latestVersion = updateChecker.latestVersionProperty();
|
|
|
this.lastSuccessfulUpdateCheck = updateChecker.lastSuccessfulUpdateCheckProperty();
|
|
|
- this.timeDifferenceMessage = updateChecker.timeDifferenceMessageProperty();
|
|
|
+ this.timeDifferenceMessage = lastSuccessfulUpdateCheck.map(this::updateTimeDifferenceMessage);
|
|
|
this.currentVersion = updateChecker.getCurrentVersion();
|
|
|
this.updateAvailable = updateChecker.updateAvailableProperty();
|
|
|
this.updateCheckState = updateChecker.updateCheckStateProperty();
|
|
@@ -75,7 +79,7 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
updateCheckState.addListener((_, _, _) -> {
|
|
|
if (isUpdateSuccessfulAndCurrent.get()) {
|
|
|
upToDateLabelVisible.set(true);
|
|
|
- PauseTransition delay = new PauseTransition(Duration.seconds(5));
|
|
|
+ PauseTransition delay = new PauseTransition(javafx.util.Duration.seconds(5));
|
|
|
delay.setOnFinished(_ -> upToDateLabelVisible.set(false));
|
|
|
delay.play();
|
|
|
}
|
|
@@ -119,27 +123,43 @@ public class UpdatesPreferencesController implements FxController {
|
|
|
return currentVersion;
|
|
|
}
|
|
|
|
|
|
- public ObjectProperty<Date> lastSuccessfulUpdateCheckProperty() {
|
|
|
+ public ObservableValue<Instant> lastSuccessfulUpdateCheckProperty() {
|
|
|
return lastSuccessfulUpdateCheck;
|
|
|
}
|
|
|
|
|
|
public String getLastSuccessfulUpdateCheck() {
|
|
|
- Date date = lastSuccessfulUpdateCheck.get();
|
|
|
- if (date != null && !date.equals(Settings.DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK)) {
|
|
|
- LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ Instant lastCheck = lastSuccessfulUpdateCheck.getValue();
|
|
|
+ if (lastCheck != null && !lastCheck.equals(Settings.DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK)) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.getDefault());
|
|
|
- return formatter.format(localDateTime);
|
|
|
+ return formatter.format(LocalDateTime.ofInstant(lastCheck, ZoneId.systemDefault()));
|
|
|
} else {
|
|
|
return "-";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public ReadOnlyStringProperty timeDifferenceMessageProperty(){
|
|
|
+ private String updateTimeDifferenceMessage(Instant lastSuccessCheck) {
|
|
|
+ if (lastSuccessCheck.equals(Settings.DEFAULT_LAST_SUCCESSFUL_UPDATE_CHECK)) {
|
|
|
+ return resourceBundle.getString("preferences.updates.lastUpdateCheck.never");
|
|
|
+ }
|
|
|
+
|
|
|
+ var duration = Duration.between(lastSuccessCheck, Instant.now());
|
|
|
+ var hours = duration.toHours();
|
|
|
+ if (hours < 1) {
|
|
|
+ return resourceBundle.getString("preferences.updates.lastUpdateCheck.recently");
|
|
|
+ } else if (hours < 24) {
|
|
|
+ return String.format(resourceBundle.getString("preferences.updates.lastUpdateCheck.hoursAgo"), hours);
|
|
|
+ } else {
|
|
|
+ return String.format(resourceBundle.getString("preferences.updates.lastUpdateCheck.daysAgo"), duration.toDays());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public ObservableValue<String> timeDifferenceMessageProperty() {
|
|
|
return timeDifferenceMessage;
|
|
|
}
|
|
|
|
|
|
public String getTimeDifferenceMessage() {
|
|
|
- return timeDifferenceMessage.get();
|
|
|
+ return timeDifferenceMessage.getValue();
|
|
|
}
|
|
|
|
|
|
public BooleanProperty upToDateLabelVisibleProperty() {
|