Skip to content

Commit d351523

Browse files
committed
update
1 parent 404548d commit d351523

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ protected ModDownloadPageSkin(DownloadPage control) {
301301

302302
for (String gameVersion : control.versions.keys().stream()
303303
.sorted(Collections.reverseOrder(GameVersionNumber::compare))
304-
.collect(Collectors.toList())) {
304+
.toList()) {
305305
List<RemoteMod.Version> versions = control.versions.get(gameVersion);
306306
if (versions == null || versions.isEmpty()) {
307307
continue;
@@ -449,22 +449,12 @@ private static final class ModVersion extends JFXDialogLayout {
449449
public ModVersion(RemoteMod.Version version, DownloadPage selfPage) {
450450
RemoteModRepository.Type type = selfPage.repository.getType();
451451

452-
String title;
453-
switch (type) {
454-
case WORLD:
455-
title = "world.download.title";
456-
break;
457-
case MODPACK:
458-
title = "modpack.download.title";
459-
break;
460-
case RESOURCE_PACK:
461-
title = "resourcepack.download.title";
462-
break;
463-
case MOD:
464-
default:
465-
title = "mods.download.title";
466-
break;
467-
}
452+
String title = switch (type) {
453+
case WORLD -> "world.download.title";
454+
case MODPACK -> "modpack.download.title";
455+
case RESOURCE_PACK -> "resourcepack.download.title";
456+
default -> "mods.download.title";
457+
};
468458
this.setHeading(new HBox(new Label(i18n(title, version.getName()))));
469459

470460
VBox box = new VBox(8);
@@ -530,12 +520,13 @@ private void loadChangelogAndDependencies(RemoteMod.Version version, DownloadPag
530520
Task.supplyAsync(() -> {
531521
Optional<String> changelog;
532522
if (version.getChangelog() != null) {
533-
changelog = Optional.ofNullable(version.getChangelog().isBlank() ? null : version.getChangelog());
523+
changelog = StringUtils.nullIfBlank(version.getChangelog());
534524
} else {
535525
try {
536-
String changelogText = StringUtils.htmlToText(selfPage.repository.getModChangelog(version.getModid(), version.getVersionId()));
537-
changelog = changelogText.isBlank() ? Optional.empty() : Optional.of(changelogText);
538-
} catch (UnsupportedOperationException e) {
526+
changelog = StringUtils.nullIfBlank(
527+
StringUtils.htmlToText(selfPage.repository.getModChangelog(version.getModid(), version.getVersionId()))
528+
);
529+
} catch (UnsupportedOperationException e) { // Should be impossible
539530
changelog = Optional.empty();
540531
}
541532
}

HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.jackhuang.hmcl.ui.SVG;
4040
import org.jackhuang.hmcl.ui.construct.*;
4141
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
42-
import org.jackhuang.hmcl.util.Lang;
4342
import org.jackhuang.hmcl.util.Pair;
4443
import org.jackhuang.hmcl.util.StringUtils;
4544
import org.jackhuang.hmcl.util.TaskCancellationAction;
@@ -351,8 +350,7 @@ private static final class ModItem extends StackPane {
351350
pane.getChildren().add(descPane);
352351
}
353352

354-
RipplerContainer container = new RipplerContainer(pane);
355-
getChildren().setAll(container);
353+
getChildren().setAll(new RipplerContainer(pane));
356354

357355
// Workaround for https://github.com/HMCL-dev/HMCL/issues/2129
358356
this.setMinHeight(50);
@@ -370,13 +368,11 @@ public ModDetail(RemoteMod.Version targetVersion, RemoteModRepository repository
370368

371369
VBox box = new VBox(8);
372370
box.setPadding(new Insets(8));
373-
ModItem modItem = new ModItem(targetVersion, source);
374-
modItem.setMouseTransparent(true); // Item is displayed for info, clicking shouldn't open the dialog again
375-
box.getChildren().setAll(modItem);
371+
box.getChildren().setAll(new ModItem(targetVersion, source));
376372

377373
SpinnerPane spinnerPane = new SpinnerPane();
378374
ScrollPane scrollPane = new ScrollPane();
379-
ComponentList changelogComponent = new ComponentList(Lang::immutableListOf);
375+
ComponentList changelogComponent = new ComponentList(null);
380376
loadChangelog(targetVersion, spinnerPane, changelogComponent);
381377
spinnerPane.setOnFailedAction(e -> loadChangelog(targetVersion, spinnerPane, changelogComponent));
382378

@@ -405,25 +401,19 @@ private void loadChangelog(RemoteMod.Version version, SpinnerPane spinnerPane, C
405401
spinnerPane.setLoading(true);
406402
Task.supplyAsync(() -> {
407403
if (version.getChangelog() != null) {
408-
return version.getChangelog().isBlank() ? null : version.getChangelog();
404+
return StringUtils.nullIfBlank(version.getChangelog());
409405
} else {
410406
try {
411-
String changelog = StringUtils.htmlToText(repository.getModChangelog(version.getModid(), version.getVersionId()));
412-
return changelog.isBlank() ? null : changelog;
407+
return StringUtils.nullIfBlank(StringUtils.htmlToText(repository.getModChangelog(version.getModid(), version.getVersionId())));
413408
} catch (UnsupportedOperationException e) {
414-
return null;
409+
return Optional.<String>empty();
415410
}
416411
}
417412
}).whenComplete(Schedulers.javafx(), (result, exception) -> {
418413
if (exception == null) {
419-
if (result != null) {
420-
componentList.getContent().setAll(new HBox(new Text(result)));
421-
} else {
422-
componentList.getContent().setAll();
423-
}
414+
result.ifPresent(s -> componentList.getContent().setAll(new HBox(new Text(s))));
424415
spinnerPane.setFailedReason(null);
425416
} else {
426-
componentList.getContent().setAll();
427417
spinnerPane.setFailedReason(i18n("download.failed.refresh"));
428418
}
429419
spinnerPane.setLoading(false);

HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ public static boolean isAlphabeticOrNumber(String str) {
534534
return true;
535535
}
536536

537+
@Contract(pure = true)
538+
public static Optional<String> nullIfBlank(String str) {
539+
return Optional.ofNullable(str).map(s -> s.isBlank() ? null : s);
540+
}
541+
537542
@Contract(value = "null -> null", pure = true)
538543
public static String htmlToText(String html) {
539544
if (html == null) {
@@ -546,7 +551,7 @@ public static String htmlToText(String html) {
546551
document.select("p").prepend("\\n");
547552
document.select("p").append("\\n");
548553
String newHtml = document.html().replaceAll("\\\\n", System.lineSeparator());
549-
return Jsoup.clean(newHtml, "", Safelist.none(), outputSettings).trim();
554+
return Jsoup.clean(newHtml, "", Safelist.none(), outputSettings);
550555
}
551556

552557
public static class LevCalculator {

0 commit comments

Comments
 (0)