diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSortMode.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSortMode.java index a1f49e797..e600cfbd0 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSortMode.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreSortMode.java @@ -1,10 +1,13 @@ package io.xpipe.app.comp.storage.store; +import io.xpipe.app.storage.DataStoreEntry; + import java.time.Instant; import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Optional; +import java.util.stream.Stream; public interface StoreSortMode { @@ -17,7 +20,7 @@ public String getId() { @Override public Comparator comparator() { return Comparator.comparing( - e -> e.getWrapper().getName().toLowerCase(Locale.ROOT)); + e -> e.getWrapper().getName().toLowerCase(Locale.ROOT)); } }; @@ -30,7 +33,7 @@ public String getId() { @Override public Comparator comparator() { return Comparator.comparing( - e -> e.getWrapper().getName().toLowerCase(Locale.ROOT)) + e -> e.getWrapper().getName().toLowerCase(Locale.ROOT)) .reversed(); } }; @@ -43,8 +46,12 @@ public String getId() { @Override public Comparator comparator() { - return Comparator.comparing( - e -> e.getWrapper().getLastAccess()); + return Comparator.comparing(e -> { + return flatten(e) + .map(entry -> entry.getLastAccess()) + .max(Comparator.naturalOrder()) + .orElseThrow(); + }); } }; @@ -56,16 +63,29 @@ public String getId() { @Override public Comparator comparator() { - return Comparator.comparing(e -> e.getWrapper().getLastAccess()) - .reversed(); + return Comparator.comparing(e -> { + return flatten(e) + .map(entry -> entry.getLastAccess()) + .max(Comparator.naturalOrder()) + .orElseThrow(); + }).reversed(); } }; + static Stream flatten(StoreSection section) { + return Stream.concat( + Stream.of(section.getWrapper().getEntry()), + section.getChildren().stream().flatMap(section1 -> flatten(section1))); + } + static List ALL = List.of(ALPHABETICAL_DESC, ALPHABETICAL_ASC, DATE_DESC, DATE_ASC); static Optional fromId(String id) { - return ALL.stream().filter(storeSortMode -> storeSortMode.getId().equals(id)).findFirst(); + return ALL.stream() + .filter(storeSortMode -> storeSortMode.getId().equals(id)) + .findFirst(); } + String getId(); Comparator comparator(); diff --git a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreViewState.java b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreViewState.java index f8d39ba32..441b1ddaa 100644 --- a/app/src/main/java/io/xpipe/app/comp/storage/store/StoreViewState.java +++ b/app/src/main/java/io/xpipe/app/comp/storage/store/StoreViewState.java @@ -37,7 +37,7 @@ public class StoreViewState { private StoreViewState() { var val = AppCache.getIfPresent("sortMode", String.class) .flatMap(StoreSortMode::fromId) - .orElse(StoreSortMode.ALPHABETICAL_DESC); + .orElse(StoreSortMode.DATE_ASC); this.sortMode = new SimpleObjectProperty<>(val); this.sortMode.addListener((observable, oldValue, newValue) -> { AppCache.update("sortMode", newValue.getId()); diff --git a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java index bb26be3a0..27a559bee 100644 --- a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java +++ b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java @@ -115,13 +115,13 @@ public static T unreportableIfContains(T t, String... s) { public static T unreportableIf(T t, boolean b) { if (b) { - // EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).unreportable()); + EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).unreportable()); } return t; } public static T unreportable(T t) { - // EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).unreportable()); + EVENT_BASES.put(t, ErrorEvent.fromThrowable(t).unreportable()); return t; } }