diff --git a/src/main/java/org/cryptomator/common/vaults/Vault.java b/src/main/java/org/cryptomator/common/vaults/Vault.java index 4103488f0..2c168ae2d 100644 --- a/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -262,7 +262,7 @@ public class Vault { private void consumeVaultEvent(FilesystemEvent e) { //TODO: here we could implement a buffer to prevent event spam (due to many filesystem requests) - long timestamp = Instant.now().toEpochMilli(); + var timestamp = Instant.now(); Platform.runLater(() -> eventList.addLast(new VaultEvent(timestamp, this, e))); } diff --git a/src/main/java/org/cryptomator/event/VaultEvent.java b/src/main/java/org/cryptomator/event/VaultEvent.java index cd4fc0b52..e42f24339 100644 --- a/src/main/java/org/cryptomator/event/VaultEvent.java +++ b/src/main/java/org/cryptomator/event/VaultEvent.java @@ -5,18 +5,19 @@ import org.cryptomator.cryptofs.event.FilesystemEvent; import java.time.Instant; -public record VaultEvent(long timestamp, Vault v, FilesystemEvent actualEvent) implements Comparable { +public record VaultEvent(Instant timestamp, Vault v, FilesystemEvent actualEvent) implements Comparable { public VaultEvent(Vault v, FilesystemEvent actualEvent) { - this(Instant.now().toEpochMilli(), v, actualEvent); + this(Instant.now(), v, actualEvent); } @Override public int compareTo(VaultEvent other) { - long timeDiff = this.timestamp - other.timestamp; - if (timeDiff != 0) { - return (int) timeDiff; + var timeResult = this.timestamp.compareTo(other.timestamp); + if(timeResult != 0) { + return timeResult; + } else { + return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName()); } - return this.equals(other) ? 0 : this.actualEvent.getClass().getName().compareTo(other.actualEvent.getClass().getName()); } } diff --git a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java index 57e115ff6..f4618182f 100644 --- a/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java +++ b/src/main/java/org/cryptomator/ui/eventview/EventListCellController.java @@ -30,6 +30,9 @@ import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; import javafx.scene.layout.HBox; import java.nio.file.Path; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; import java.util.Optional; import java.util.ResourceBundle; import java.util.function.Function; @@ -37,6 +40,8 @@ import java.util.function.Function; public class EventListCellController implements FxController { private static final Logger LOG = LoggerFactory.getLogger(EventListCellController.class); + private static final DateTimeFormatter LOCAL_DATE_FORMATTER = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); + private static final DateTimeFormatter LOCAL_TIME_FORMATTER = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withZone(ZoneId.systemDefault()); private final ObservableList events; private final Optional revealService; @@ -46,6 +51,8 @@ public class EventListCellController implements FxController { private final StringProperty eventDescription; private final ObjectProperty eventIcon; private final ObservableValue vaultUnlocked; + private final ObservableValue readableTime; + private final ObservableValue readableDate; private final ObservableValue message; private final ObservableValue description; private final ObservableValue icon; @@ -68,6 +75,8 @@ public class EventListCellController implements FxController { this.eventDescription = new SimpleStringProperty(); this.eventIcon = new SimpleObjectProperty<>(); this.vaultUnlocked = ObservableUtil.mapWithDefault(event.flatMap(e -> e.v().unlockedProperty()), Function.identity(), false); + this.readableTime = ObservableUtil.mapWithDefault(event, e -> LOCAL_TIME_FORMATTER.format(e.timestamp()), ""); + this.readableDate = ObservableUtil.mapWithDefault(event, e -> LOCAL_DATE_FORMATTER.format(e.timestamp()), ""); this.message = Bindings.createStringBinding(this::selectMessage, vaultUnlocked, eventMessage); this.description = Bindings.createStringBinding(this::selectDescription, vaultUnlocked, eventDescription); this.icon = Bindings.createObjectBinding(this::selectIcon, vaultUnlocked, eventIcon); @@ -77,7 +86,7 @@ public class EventListCellController implements FxController { @FXML public void initialize() { actionsButtonVisible.bind(Bindings.createBooleanBinding(this::determineActionsButtonVisibility, root.hoverProperty(), eventActionsMenu.showingProperty(), vaultUnlocked)); - vaultUnlocked.addListener((_,_,newValue) -> eventActionsMenu.hide()); + vaultUnlocked.addListener((_, _, newValue) -> eventActionsMenu.hide()); } private boolean determineActionsButtonVisibility() { @@ -222,5 +231,19 @@ public class EventListCellController implements FxController { return actionsButtonVisible.getValue(); } + public ObservableValue eventLocalTimeProperty() { + return readableTime; + } + public String getEventLocalTime() { + return readableTime.getValue(); + } + + public ObservableValue eventLocalDateProperty() { + return readableDate; + } + + public String getEventLocalDate() { + return readableDate.getValue(); + } } diff --git a/src/main/resources/fxml/eventview_cell.fxml b/src/main/resources/fxml/eventview_cell.fxml index a21af9f1d..13f4511d9 100644 --- a/src/main/resources/fxml/eventview_cell.fxml +++ b/src/main/resources/fxml/eventview_cell.fxml @@ -7,7 +7,7 @@ - + + +