fix(download): should update category list after download soruce changed.

This commit is contained in:
huanghongxun 2022-05-23 22:27:30 +08:00
parent 8cfde9d5c6
commit f12882a389

View File

@ -191,7 +191,10 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
} }
protected String getLocalizedCategoryIndent(ModDownloadListPageSkin.CategoryIndented category) { protected String getLocalizedCategoryIndent(ModDownloadListPageSkin.CategoryIndented category) {
return StringUtils.repeats(' ', category.indent * 4) + getLocalizedCategory(category.getCategory() == null ? "0" : category.getCategory().getId()); return StringUtils.repeats(' ', category.indent * 4) +
(category.getCategory() == null
? i18n("curse.category.0")
: getLocalizedCategory(category.getCategory().getId()));
} }
protected String getLocalizedOfficialPage() { protected String getLocalizedOfficialPage() {
@ -309,15 +312,17 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
categoryComboBox.setPromptText(i18n("mods.category")); categoryComboBox.setPromptText(i18n("mods.category"));
categoryComboBox.getSelectionModel().select(0); categoryComboBox.getSelectionModel().select(0);
categoryComboBox.setConverter(stringConverter(getSkinnable()::getLocalizedCategoryIndent)); categoryComboBox.setConverter(stringConverter(getSkinnable()::getLocalizedCategoryIndent));
Task.supplyAsync(() -> getSkinnable().repository.getCategories()) FXUtils.onChangeAndOperate(getSkinnable().downloadSource, downloadSource -> {
.thenAcceptAsync(Schedulers.javafx(), categories -> { Task.supplyAsync(() -> getSkinnable().repository.getCategories())
List<CategoryIndented> result = new ArrayList<>(); .thenAcceptAsync(Schedulers.javafx(), categories -> {
result.add(new CategoryIndented(0, null)); List<CategoryIndented> result = new ArrayList<>();
for (RemoteModRepository.Category category : Lang.toIterable(categories)) { result.add(new CategoryIndented(0, null));
resolveCategory(category, 0, result); for (RemoteModRepository.Category category : Lang.toIterable(categories)) {
} resolveCategory(category, 0, result);
categoryComboBox.getItems().setAll(result); }
}).start(); categoryComboBox.getItems().setAll(result);
}).start();
});
StackPane sortStackPane = new StackPane(); StackPane sortStackPane = new StackPane();
JFXComboBox<RemoteModRepository.SortType> sortComboBox = new JFXComboBox<>(); JFXComboBox<RemoteModRepository.SortType> sortComboBox = new JFXComboBox<>();