fix: sort mod downloads. Closes #942.

This commit is contained in:
huanghongxun 2021-08-05 01:50:59 +08:00
parent 1ad8beb49e
commit b8ca9a3b09
2 changed files with 19 additions and 0 deletions

View File

@ -46,7 +46,12 @@ import org.jackhuang.hmcl.util.StringUtils;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Collectors;
@ -82,6 +87,7 @@ public class ModDownloadPage extends Control implements DecoratorPage {
}
}
List<CurseAddon.LatestFile> files = CurseModManager.getFiles(addon);
files.sort(Comparator.comparing(CurseAddon.LatestFile::getParsedFileDate).reversed());
items.setAll(files);
}).start();
@ -208,6 +214,7 @@ public class ModDownloadPage extends Control implements DecoratorPage {
protected void updateControl(CurseAddon.LatestFile dataItem, boolean empty) {
if (empty) return;
content.setTitle(dataItem.getDisplayName());
content.setSubtitle(FORMATTER.format(dataItem.getParsedFileDate()));
content.getTags().setAll(dataItem.getGameVersion());
switch (dataItem.getReleaseType()) {
@ -239,6 +246,8 @@ public class ModDownloadPage extends Control implements DecoratorPage {
}
}
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault());
public interface DownloadCallback {
void download(Profile profile, @Nullable String version, CurseAddon.LatestFile file);
}

View File

@ -2,6 +2,7 @@ package org.jackhuang.hmcl.mod.curse;
import org.jackhuang.hmcl.util.Immutable;
import java.time.Instant;
import java.util.List;
@Immutable
@ -293,6 +294,8 @@ public class CurseAddon {
private final boolean isServerPack;
private final int serverPackFileId;
private transient Instant fileDataInstant;
public LatestFile(int id, String displayName, String fileName, String fileDate, int fileLength, int releaseType, int fileStatus, String downloadUrl, boolean isAlternate, int alternateFileId, List<Dependency> dependencies, boolean isAvailable, List<String> gameVersion, boolean hasInstallScript, boolean isCompatibleWIthClient, int categorySectionPackageType, int restrictProjectFileAccess, int projectStatus, int projectId, boolean isServerPack, int serverPackFileId) {
this.id = id;
this.displayName = displayName;
@ -400,6 +403,13 @@ public class CurseAddon {
public int getServerPackFileId() {
return serverPackFileId;
}
public Instant getParsedFileDate() {
if (fileDataInstant == null) {
fileDataInstant = Instant.parse(fileDate);
}
return fileDataInstant;
}
}
@Immutable