mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-02 18:17:27 +13:00
Fix date ordering
This commit is contained in:
parent
474b529050
commit
67dafeabf7
5 changed files with 37 additions and 67 deletions
|
@ -199,7 +199,7 @@ public class StoreEntryWrapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
var found = getDefaultActionProvider().getValue();
|
var found = getDefaultActionProvider().getValue();
|
||||||
entry.updateLastUsed();
|
entry.notifyUpdate(true, false);
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
found.createAction(entry.ref()).execute();
|
found.createAction(entry.ref()).execute();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -49,15 +49,8 @@ public interface StoreSortMode {
|
||||||
StoreSortMode DATE_DESC = new StoreSortMode() {
|
StoreSortMode DATE_DESC = new StoreSortMode() {
|
||||||
@Override
|
@Override
|
||||||
public StoreSection representative(StoreSection s) {
|
public StoreSection representative(StoreSection s) {
|
||||||
var c = comparator();
|
return Stream.concat(s.getShownChildren().stream().map(this::representative), Stream.of(s))
|
||||||
return Stream.of(
|
.max(Comparator.comparing(section -> section.getWrapper().getEntry().getLastAccess()))
|
||||||
s.getShownChildren().stream()
|
|
||||||
.max((o1, o2) -> {
|
|
||||||
return c.compare(representative(o1), representative(o2));
|
|
||||||
})
|
|
||||||
.orElse(s),
|
|
||||||
s)
|
|
||||||
.max(c)
|
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,25 +62,15 @@ public interface StoreSortMode {
|
||||||
@Override
|
@Override
|
||||||
public Comparator<StoreSection> comparator() {
|
public Comparator<StoreSection> comparator() {
|
||||||
return Comparator.comparing(e -> {
|
return Comparator.comparing(e -> {
|
||||||
return flatten(e)
|
return e.getWrapper().getEntry().getLastAccess();
|
||||||
.map(entry -> entry.getLastAccess())
|
|
||||||
.max(Comparator.naturalOrder())
|
|
||||||
.orElseThrow();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
StoreSortMode DATE_ASC = new StoreSortMode() {
|
StoreSortMode DATE_ASC = new StoreSortMode() {
|
||||||
@Override
|
@Override
|
||||||
public StoreSection representative(StoreSection s) {
|
public StoreSection representative(StoreSection s) {
|
||||||
var c = comparator();
|
return Stream.concat(s.getShownChildren().stream().map(this::representative), Stream.of(s))
|
||||||
return Stream.of(
|
.max(Comparator.comparing(section -> section.getWrapper().getEntry().getLastAccess()))
|
||||||
s.getShownChildren().stream()
|
|
||||||
.min((o1, o2) -> {
|
|
||||||
return c.compare(representative(o1), representative(o2));
|
|
||||||
})
|
|
||||||
.orElse(s),
|
|
||||||
s)
|
|
||||||
.min(c)
|
|
||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,10 +82,7 @@ public interface StoreSortMode {
|
||||||
@Override
|
@Override
|
||||||
public Comparator<StoreSection> comparator() {
|
public Comparator<StoreSection> comparator() {
|
||||||
return Comparator.<StoreSection, Instant>comparing(e -> {
|
return Comparator.<StoreSection, Instant>comparing(e -> {
|
||||||
return flatten(e)
|
return e.getWrapper().getEntry().getLastAccess();
|
||||||
.map(entry -> entry.getLastAccess())
|
|
||||||
.max(Comparator.naturalOrder())
|
|
||||||
.orElseThrow();
|
|
||||||
})
|
})
|
||||||
.reversed();
|
.reversed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,8 +116,7 @@ public class DataStoreCategory extends StorageElement {
|
||||||
var changed = this.sortMode != sortMode;
|
var changed = this.sortMode != sortMode;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.sortMode = sortMode;
|
this.sortMode = sortMode;
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,15 +124,13 @@ public class DataStoreCategory extends StorageElement {
|
||||||
var changed = share != newShare;
|
var changed = share != newShare;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.share = newShare;
|
this.share = newShare;
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParentCategory(UUID parentCategory) {
|
public void setParentCategory(UUID parentCategory) {
|
||||||
this.parentCategory = parentCategory;
|
this.parentCategory = parentCategory;
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canShare() {
|
public boolean canShare() {
|
||||||
|
|
|
@ -214,11 +214,11 @@ public class DataStoreEntry extends StorageElement {
|
||||||
var lastUsed = Optional.ofNullable(stateJson.get("lastUsed"))
|
var lastUsed = Optional.ofNullable(stateJson.get("lastUsed"))
|
||||||
.map(jsonNode -> jsonNode.textValue())
|
.map(jsonNode -> jsonNode.textValue())
|
||||||
.map(Instant::parse)
|
.map(Instant::parse)
|
||||||
.orElse(Instant.now());
|
.orElse(Instant.EPOCH);
|
||||||
var lastModified = Optional.ofNullable(stateJson.get("lastModified"))
|
var lastModified = Optional.ofNullable(stateJson.get("lastModified"))
|
||||||
.map(jsonNode -> jsonNode.textValue())
|
.map(jsonNode -> jsonNode.textValue())
|
||||||
.map(Instant::parse)
|
.map(Instant::parse)
|
||||||
.orElse(Instant.now());
|
.orElse(Instant.EPOCH);
|
||||||
var configuration = Optional.ofNullable(json.get("configuration"))
|
var configuration = Optional.ofNullable(json.get("configuration"))
|
||||||
.map(node -> {
|
.map(node -> {
|
||||||
try {
|
try {
|
||||||
|
@ -281,7 +281,7 @@ public class DataStoreEntry extends StorageElement {
|
||||||
var changed = inRefresh != newRefresh;
|
var changed = inRefresh != newRefresh;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.inRefresh = newRefresh;
|
this.inRefresh = newRefresh;
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ public class DataStoreEntry extends StorageElement {
|
||||||
|
|
||||||
public void setStoreCache(String key, Object value) {
|
public void setStoreCache(String key, Object value) {
|
||||||
if (!Objects.equals(storeCache.put(key, value), 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.storePersistentState = value;
|
||||||
this.storePersistentStateNode = JacksonMapper.getDefault().valueToTree(value);
|
this.storePersistentStateNode = JacksonMapper.getDefault().valueToTree(value);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfiguration(Configuration configuration) {
|
public void setConfiguration(Configuration configuration) {
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCategoryUuid(UUID categoryUuid) {
|
public void setCategoryUuid(UUID categoryUuid) {
|
||||||
this.dirty = true;
|
|
||||||
this.categoryUuid = categoryUuid;
|
this.categoryUuid = categoryUuid;
|
||||||
notifyUpdate();
|
notifyUpdate(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -376,8 +373,7 @@ public class DataStoreEntry extends StorageElement {
|
||||||
var changed = expanded != this.expanded;
|
var changed = expanded != this.expanded;
|
||||||
this.expanded = expanded;
|
this.expanded = expanded;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,8 +381,7 @@ public class DataStoreEntry extends StorageElement {
|
||||||
var changed = !Objects.equals(color, newColor);
|
var changed = !Objects.equals(color, newColor);
|
||||||
this.color = newColor;
|
this.color = newColor;
|
||||||
if (changed) {
|
if (changed) {
|
||||||
dirty = true;
|
notifyUpdate(false, true);
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,14 +394,12 @@ public class DataStoreEntry extends StorageElement {
|
||||||
storeNode = e.storeNode;
|
storeNode = e.storeNode;
|
||||||
store = e.store;
|
store = e.store;
|
||||||
validity = e.validity;
|
validity = e.validity;
|
||||||
lastModified = Instant.now();
|
|
||||||
dirty = true;
|
|
||||||
provider = e.provider;
|
provider = e.provider;
|
||||||
childrenCache = null;
|
childrenCache = null;
|
||||||
validity = store == null ? Validity.LOAD_FAILED : store.isComplete() ? Validity.COMPLETE : Validity.INCOMPLETE;
|
validity = store == null ? Validity.LOAD_FAILED : store.isComplete() ? Validity.COMPLETE : Validity.INCOMPLETE;
|
||||||
storePersistentState = e.storePersistentState;
|
storePersistentState = e.storePersistentState;
|
||||||
storePersistentStateNode = e.storePersistentStateNode;
|
storePersistentStateNode = e.storePersistentStateNode;
|
||||||
notifyUpdate();
|
notifyUpdate(false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStoreInternal(DataStore store, boolean updateTime) {
|
public void setStoreInternal(DataStore store, boolean updateTime) {
|
||||||
|
@ -475,7 +468,8 @@ public class DataStoreEntry extends StorageElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
validity = Validity.COMPLETE;
|
validity = Validity.COMPLETE;
|
||||||
notifyUpdate();
|
// Don't count this as modification as this is done always
|
||||||
|
notifyUpdate(false, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +494,7 @@ public class DataStoreEntry extends StorageElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
validity = Validity.INCOMPLETE;
|
validity = Validity.INCOMPLETE;
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,14 +503,14 @@ public class DataStoreEntry extends StorageElement {
|
||||||
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
|
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
|
||||||
try {
|
try {
|
||||||
inRefresh = true;
|
inRefresh = true;
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
lifecycleStore.initializeValidate();
|
lifecycleStore.initializeValidate();
|
||||||
inRefresh = false;
|
inRefresh = false;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
inRefresh = false;
|
inRefresh = false;
|
||||||
ErrorEvent.fromThrowable(e).handle();
|
ErrorEvent.fromThrowable(e).handle();
|
||||||
} finally {
|
} finally {
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,12 +520,12 @@ public class DataStoreEntry extends StorageElement {
|
||||||
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
|
if (store instanceof ExpandedLifecycleStore lifecycleStore) {
|
||||||
try {
|
try {
|
||||||
inRefresh = true;
|
inRefresh = true;
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
lifecycleStore.finalizeValidate();
|
lifecycleStore.finalizeValidate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ErrorEvent.fromThrowable(e).handle();
|
ErrorEvent.fromThrowable(e).handle();
|
||||||
} finally {
|
} finally {
|
||||||
notifyUpdate();
|
notifyUpdate(false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,15 @@ public abstract class StorageElement {
|
||||||
|
|
||||||
public abstract Path[] getShareableFiles();
|
public abstract Path[] getShareableFiles();
|
||||||
|
|
||||||
public void updateLastUsed() {
|
public void notifyUpdate(boolean used, boolean modified) {
|
||||||
this.lastUsed = Instant.now();
|
if (used) {
|
||||||
this.dirty = true;
|
lastUsed = Instant.now();
|
||||||
notifyUpdate();
|
dirty = true;
|
||||||
}
|
}
|
||||||
|
if (modified) {
|
||||||
protected void notifyUpdate() {
|
lastModified = Instant.now();
|
||||||
lastModified = Instant.now();
|
dirty = true;
|
||||||
|
}
|
||||||
listeners.forEach(l -> l.onUpdate());
|
listeners.forEach(l -> l.onUpdate());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +87,7 @@ public abstract class StorageElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.dirty = true;
|
notifyUpdate(false, true);
|
||||||
this.lastModified = Instant.now();
|
|
||||||
notifyUpdate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
|
|
Loading…
Reference in a new issue