Fix date ordering

This commit is contained in:
crschnick 2024-03-22 09:03:01 +00:00
parent 474b529050
commit 67dafeabf7
5 changed files with 37 additions and 67 deletions

View file

@ -199,7 +199,7 @@ public class StoreEntryWrapper {
}
var found = getDefaultActionProvider().getValue();
entry.updateLastUsed();
entry.notifyUpdate(true, false);
if (found != null) {
found.createAction(entry.ref()).execute();
} else {

View file

@ -49,15 +49,8 @@ public interface StoreSortMode {
StoreSortMode DATE_DESC = new StoreSortMode() {
@Override
public StoreSection representative(StoreSection s) {
var c = comparator();
return Stream.of(
s.getShownChildren().stream()
.max((o1, o2) -> {
return c.compare(representative(o1), representative(o2));
})
.orElse(s),
s)
.max(c)
return Stream.concat(s.getShownChildren().stream().map(this::representative), Stream.of(s))
.max(Comparator.comparing(section -> section.getWrapper().getEntry().getLastAccess()))
.orElseThrow();
}
@ -69,25 +62,15 @@ public interface StoreSortMode {
@Override
public Comparator<StoreSection> comparator() {
return Comparator.comparing(e -> {
return flatten(e)
.map(entry -> entry.getLastAccess())
.max(Comparator.naturalOrder())
.orElseThrow();
return e.getWrapper().getEntry().getLastAccess();
});
}
};
StoreSortMode DATE_ASC = new StoreSortMode() {
@Override
public StoreSection representative(StoreSection s) {
var c = comparator();
return Stream.of(
s.getShownChildren().stream()
.min((o1, o2) -> {
return c.compare(representative(o1), representative(o2));
})
.orElse(s),
s)
.min(c)
return Stream.concat(s.getShownChildren().stream().map(this::representative), Stream.of(s))
.max(Comparator.comparing(section -> section.getWrapper().getEntry().getLastAccess()))
.orElseThrow();
}
@ -99,10 +82,7 @@ public interface StoreSortMode {
@Override
public Comparator<StoreSection> comparator() {
return Comparator.<StoreSection, Instant>comparing(e -> {
return flatten(e)
.map(entry -> entry.getLastAccess())
.max(Comparator.naturalOrder())
.orElseThrow();
return e.getWrapper().getEntry().getLastAccess();
})
.reversed();
}

View file

@ -116,8 +116,7 @@ public class DataStoreCategory extends StorageElement {
var changed = this.sortMode != sortMode;
if (changed) {
this.sortMode = sortMode;
this.dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
}
@ -125,15 +124,13 @@ public class DataStoreCategory extends StorageElement {
var changed = share != newShare;
if (changed) {
this.share = newShare;
this.dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
}
public void setParentCategory(UUID parentCategory) {
this.parentCategory = parentCategory;
this.dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
public boolean canShare() {

View file

@ -214,11 +214,11 @@ public class DataStoreEntry extends StorageElement {
var lastUsed = Optional.ofNullable(stateJson.get("lastUsed"))
.map(jsonNode -> jsonNode.textValue())
.map(Instant::parse)
.orElse(Instant.now());
.orElse(Instant.EPOCH);
var lastModified = Optional.ofNullable(stateJson.get("lastModified"))
.map(jsonNode -> jsonNode.textValue())
.map(Instant::parse)
.orElse(Instant.now());
.orElse(Instant.EPOCH);
var configuration = Optional.ofNullable(json.get("configuration"))
.map(node -> {
try {
@ -281,7 +281,7 @@ public class DataStoreEntry extends StorageElement {
var changed = inRefresh != newRefresh;
if (changed) {
this.inRefresh = newRefresh;
notifyUpdate();
notifyUpdate(false, false);
}
}
@ -291,7 +291,7 @@ public class DataStoreEntry extends StorageElement {
public void setStoreCache(String key, Object value) {
if (!Objects.equals(storeCache.put(key, value), value)) {
notifyUpdate();
notifyUpdate(false, false);
}
}
@ -321,21 +321,18 @@ public class DataStoreEntry extends StorageElement {
this.storePersistentState = value;
this.storePersistentStateNode = JacksonMapper.getDefault().valueToTree(value);
if (changed) {
this.dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
}
public void setConfiguration(Configuration configuration) {
this.configuration = configuration;
this.dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
public void setCategoryUuid(UUID categoryUuid) {
this.dirty = true;
this.categoryUuid = categoryUuid;
notifyUpdate();
notifyUpdate(false, true);
}
@Override
@ -376,8 +373,7 @@ public class DataStoreEntry extends StorageElement {
var changed = expanded != this.expanded;
this.expanded = expanded;
if (changed) {
dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
}
@ -385,8 +381,7 @@ public class DataStoreEntry extends StorageElement {
var changed = !Objects.equals(color, newColor);
this.color = newColor;
if (changed) {
dirty = true;
notifyUpdate();
notifyUpdate(false, true);
}
}
@ -399,14 +394,12 @@ public class DataStoreEntry extends StorageElement {
storeNode = e.storeNode;
store = e.store;
validity = e.validity;
lastModified = Instant.now();
dirty = true;
provider = e.provider;
childrenCache = null;
validity = store == null ? Validity.LOAD_FAILED : store.isComplete() ? Validity.COMPLETE : Validity.INCOMPLETE;
storePersistentState = e.storePersistentState;
storePersistentStateNode = e.storePersistentStateNode;
notifyUpdate();
notifyUpdate(false, true);
}
public void setStoreInternal(DataStore store, boolean updateTime) {
@ -475,7 +468,8 @@ public class DataStoreEntry extends StorageElement {
}
validity = Validity.COMPLETE;
notifyUpdate();
// Don't count this as modification as this is done always
notifyUpdate(false, false);
return true;
}
@ -500,7 +494,7 @@ public class DataStoreEntry extends StorageElement {
}
validity = Validity.INCOMPLETE;
notifyUpdate();
notifyUpdate(false, false);
return true;
}
@ -509,14 +503,14 @@ public class DataStoreEntry extends StorageElement {
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
try {
inRefresh = true;
notifyUpdate();
notifyUpdate(false, false);
lifecycleStore.initializeValidate();
inRefresh = false;
} catch (Exception e) {
inRefresh = false;
ErrorEvent.fromThrowable(e).handle();
} finally {
notifyUpdate();
notifyUpdate(false, false);
}
}
}
@ -526,12 +520,12 @@ public class DataStoreEntry extends StorageElement {
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
try {
inRefresh = true;
notifyUpdate();
notifyUpdate(false, false);
lifecycleStore.finalizeValidate();
} catch (Exception e) {
ErrorEvent.fromThrowable(e).handle();
} finally {
notifyUpdate();
notifyUpdate(false, false);
}
}
}

View file

@ -47,14 +47,15 @@ public abstract class StorageElement {
public abstract Path[] getShareableFiles();
public void updateLastUsed() {
this.lastUsed = Instant.now();
this.dirty = true;
notifyUpdate();
}
protected void notifyUpdate() {
lastModified = Instant.now();
public void notifyUpdate(boolean used, boolean modified) {
if (used) {
lastUsed = Instant.now();
dirty = true;
}
if (modified) {
lastModified = Instant.now();
dirty = true;
}
listeners.forEach(l -> l.onUpdate());
}
@ -86,9 +87,7 @@ public abstract class StorageElement {
}
this.name = name;
this.dirty = true;
this.lastModified = Instant.now();
notifyUpdate();
notifyUpdate(false, true);
}
public interface Listener {