fix: sort mod downloads. Closes #942.
This commit is contained in:
@@ -46,7 +46,12 @@ import org.jackhuang.hmcl.util.StringUtils;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
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.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -82,6 +87,7 @@ public class ModDownloadPage extends Control implements DecoratorPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<CurseAddon.LatestFile> files = CurseModManager.getFiles(addon);
|
List<CurseAddon.LatestFile> files = CurseModManager.getFiles(addon);
|
||||||
|
files.sort(Comparator.comparing(CurseAddon.LatestFile::getParsedFileDate).reversed());
|
||||||
items.setAll(files);
|
items.setAll(files);
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@@ -208,6 +214,7 @@ public class ModDownloadPage extends Control implements DecoratorPage {
|
|||||||
protected void updateControl(CurseAddon.LatestFile dataItem, boolean empty) {
|
protected void updateControl(CurseAddon.LatestFile dataItem, boolean empty) {
|
||||||
if (empty) return;
|
if (empty) return;
|
||||||
content.setTitle(dataItem.getDisplayName());
|
content.setTitle(dataItem.getDisplayName());
|
||||||
|
content.setSubtitle(FORMATTER.format(dataItem.getParsedFileDate()));
|
||||||
content.getTags().setAll(dataItem.getGameVersion());
|
content.getTags().setAll(dataItem.getGameVersion());
|
||||||
|
|
||||||
switch (dataItem.getReleaseType()) {
|
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 {
|
public interface DownloadCallback {
|
||||||
void download(Profile profile, @Nullable String version, CurseAddon.LatestFile file);
|
void download(Profile profile, @Nullable String version, CurseAddon.LatestFile file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jackhuang.hmcl.mod.curse;
|
|||||||
|
|
||||||
import org.jackhuang.hmcl.util.Immutable;
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
@@ -293,6 +294,8 @@ public class CurseAddon {
|
|||||||
private final boolean isServerPack;
|
private final boolean isServerPack;
|
||||||
private final int serverPackFileId;
|
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) {
|
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.id = id;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
@@ -400,6 +403,13 @@ public class CurseAddon {
|
|||||||
public int getServerPackFileId() {
|
public int getServerPackFileId() {
|
||||||
return serverPackFileId;
|
return serverPackFileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Instant getParsedFileDate() {
|
||||||
|
if (fileDataInstant == null) {
|
||||||
|
fileDataInstant = Instant.parse(fileDate);
|
||||||
|
}
|
||||||
|
return fileDataInstant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
|
|||||||
Reference in New Issue
Block a user