From fa90137e397b0da412a390df723af6d82f69354a Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 30 Jun 2024 11:12:21 +0000 Subject: [PATCH] Merge branch 'order-improvements' --- .../app/comp/store/StoreEntryWrapper.java | 1 - .../xpipe/app/comp/store/StoreSortMode.java | 32 ++++++++++++++++--- .../xpipe/app/comp/store/StoreViewState.java | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java index b521b05c4..da7a84e00 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java @@ -45,7 +45,6 @@ public class StoreEntryWrapper { this.entry = entry; this.name = new SimpleStringProperty(entry.getName()); this.lastAccess = new SimpleObjectProperty<>(entry.getLastAccess().minus(Duration.ofMillis(500))); - this.lastAccessApplied.setValue(lastAccess.getValue()); ActionProvider.ALL.stream() .filter(dataStoreActionProvider -> { return !entry.isDisabled() diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreSortMode.java b/app/src/main/java/io/xpipe/app/comp/store/StoreSortMode.java index e5791c388..a6fc27434 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreSortMode.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreSortMode.java @@ -1,5 +1,7 @@ package io.xpipe.app.comp.store; +import io.xpipe.core.store.FixedChildStore; + import java.time.Instant; import java.util.Comparator; import java.util.List; @@ -45,6 +47,17 @@ public interface StoreSortMode { } }; StoreSortMode DATE_DESC = new StoreSortMode() { + + private Instant date(StoreSection s) { + var la = s.getWrapper().getLastAccessApplied().getValue(); + if (la == null) { + return s.getWrapper().getEntry().getStore() instanceof FixedChildStore ? + Instant.MIN : s.getWrapper().getEntry().getLastAccess(); + } + + return la; + } + @Override public StoreSection representative(StoreSection s) { return Stream.concat( @@ -55,8 +68,8 @@ public interface StoreSortMode { .isUsable()) .map(this::representative), Stream.of(s)) - .max(Comparator.comparing(section -> - section.getWrapper().getLastAccessApplied().getValue())) + .max(Comparator.comparing( + section -> date(section))) .orElseThrow(); } @@ -68,11 +81,22 @@ public interface StoreSortMode { @Override public Comparator comparator() { return Comparator.comparing(e -> { - return e.getWrapper().getLastAccessApplied().getValue(); + return date(e); }); } }; StoreSortMode DATE_ASC = new StoreSortMode() { + + private Instant date(StoreSection s) { + var la = s.getWrapper().getLastAccessApplied().getValue(); + if (la == null) { + return s.getWrapper().getEntry().getStore() instanceof FixedChildStore ? + Instant.MAX : s.getWrapper().getEntry().getLastAccess(); + } + + return la; + } + @Override public StoreSection representative(StoreSection s) { return Stream.concat( @@ -96,7 +120,7 @@ public interface StoreSortMode { @Override public Comparator comparator() { return Comparator.comparing(e -> { - return e.getWrapper().getLastAccessApplied().getValue(); + return date(e); }) .reversed(); } diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java index 110cc51ca..69506d85b 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java @@ -100,6 +100,7 @@ public class StoreViewState { .setAll(FXCollections.observableArrayList(DataStorage.get().getStoreEntries().stream() .map(StoreEntryWrapper::new) .toList())); + allEntries.getList().forEach(e -> e.applyLastAccess()); categories .getList() .setAll(FXCollections.observableArrayList(DataStorage.get().getStoreCategories().stream()