feat: show spinner while refreshing account

This commit is contained in:
Haowei Wen 2021-02-17 02:40:32 +08:00 committed by Yuhui Huang
parent e3fa7428bf
commit 454cc1e702
2 changed files with 10 additions and 7 deletions

View File

@ -100,7 +100,7 @@ public class AccountListItem extends RadioButton {
return new AccountListItemSkin(this); return new AccountListItemSkin(this);
} }
private Task<?> refreshAsync() { public Task<?> refreshAsync() {
return Task.runAsync(() -> { return Task.runAsync(() -> {
account.clearCache(); account.clearCache();
try { try {
@ -121,10 +121,6 @@ public class AccountListItem extends RadioButton {
}); });
} }
public void refresh() {
refreshAsync().whenComplete(e -> {}).start();
}
public ObservableBooleanValue canUploadSkin() { public ObservableBooleanValue canUploadSkin() {
if (account instanceof YggdrasilAccount) { if (account instanceof YggdrasilAccount) {
if (account instanceof AuthlibInjectorAccount) { if (account instanceof AuthlibInjectorAccount) {

View File

@ -89,11 +89,18 @@ public class AccountListItemSkin extends SkinBase<AccountListItem> {
right.setAlignment(Pos.CENTER_RIGHT); right.setAlignment(Pos.CENTER_RIGHT);
JFXButton btnRefresh = new JFXButton(); JFXButton btnRefresh = new JFXButton();
btnRefresh.setOnMouseClicked(e -> skinnable.refresh()); SpinnerPane spinnerRefresh = new SpinnerPane();
btnRefresh.setOnMouseClicked(e -> {
spinnerRefresh.showSpinner();
skinnable.refreshAsync()
.whenComplete(ex -> spinnerRefresh.hideSpinner())
.start();
});
btnRefresh.getStyleClass().add("toggle-icon4"); btnRefresh.getStyleClass().add("toggle-icon4");
btnRefresh.setGraphic(SVG.refresh(Theme.blackFillBinding(), -1, -1)); btnRefresh.setGraphic(SVG.refresh(Theme.blackFillBinding(), -1, -1));
runInFX(() -> FXUtils.installFastTooltip(btnRefresh, i18n("button.refresh"))); runInFX(() -> FXUtils.installFastTooltip(btnRefresh, i18n("button.refresh")));
right.getChildren().add(btnRefresh); spinnerRefresh.setContent(btnRefresh);
right.getChildren().add(spinnerRefresh);
JFXButton btnUpload = new JFXButton(); JFXButton btnUpload = new JFXButton();
SpinnerPane spinnerUpload = new SpinnerPane(); SpinnerPane spinnerUpload = new SpinnerPane();