refresh authlib injector account && upload authlib injector account skin

This commit is contained in:
Tungstend 2023-07-04 18:54:22 +08:00
parent 9ff0670847
commit 2b323fb98d
4 changed files with 49 additions and 15 deletions

View File

@ -358,9 +358,9 @@ public final class Accounts {
// ==== authlib-injector ==== // ==== authlib-injector ====
private static AuthlibInjectorArtifactProvider createAuthlibInjectorArtifactProvider() { private static AuthlibInjectorArtifactProvider createAuthlibInjectorArtifactProvider() {
String authlibinjectorLocation = FCLPath.AUTHLIB_INJECTOR_PATH; String authlibinjectorLocation = FCLPath.AUTHLIB_INJECTOR_PATH;
if (authlibinjectorLocation == null) { if (!new File(authlibinjectorLocation).exists()) {
return new AuthlibInjectorDownloader( return new AuthlibInjectorDownloader(
new File(FCLPath.AUTHLIB_INJECTOR_PATH).toPath(), new File(authlibinjectorLocation).toPath(),
DownloadProviders::getDownloadProvider) { DownloadProviders::getDownloadProvider) {
@Override @Override
public Optional<AuthlibInjectorArtifactInfo> getArtifactInfoImmediately() { public Optional<AuthlibInjectorArtifactInfo> getArtifactInfoImmediately() {

View File

@ -10,6 +10,7 @@ import com.tungsten.fcl.R;
import com.tungsten.fcl.setting.Accounts; import com.tungsten.fcl.setting.Accounts;
import com.tungsten.fcl.ui.UIManager; import com.tungsten.fcl.ui.UIManager;
import com.tungsten.fclcore.auth.Account; import com.tungsten.fclcore.auth.Account;
import com.tungsten.fclcore.auth.authlibinjector.AuthlibInjectorAccount;
import com.tungsten.fclcore.fakefx.beans.binding.Bindings; import com.tungsten.fclcore.fakefx.beans.binding.Bindings;
import com.tungsten.fclcore.fakefx.collections.ObservableList; import com.tungsten.fclcore.fakefx.collections.ObservableList;
import com.tungsten.fclcore.task.Schedulers; import com.tungsten.fclcore.task.Schedulers;
@ -136,6 +137,27 @@ public class AccountListAdapter extends FCLAdapter {
}); });
viewHolder.skin.setOnClickListener(v -> { viewHolder.skin.setOnClickListener(v -> {
try { try {
if (account.getAccount() instanceof AuthlibInjectorAccount) {
new Thread(() -> {
try {
Task<?> uploadTask = Objects.requireNonNull(account.uploadSkin()).get();
Schedulers.androidUIThread().execute(() -> {
if (uploadTask != null) {
viewHolder.skin.setVisibility(View.GONE);
viewHolder.skinProgress.setVisibility(View.VISIBLE);
uploadTask
.whenComplete(Schedulers.androidUIThread(), ex -> {
viewHolder.skin.setVisibility(View.VISIBLE);
viewHolder.skinProgress.setVisibility(View.GONE);
})
.start();
}
});
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}).start();
} else {
Task<?> uploadTask = Objects.requireNonNull(account.uploadSkin()).get(); Task<?> uploadTask = Objects.requireNonNull(account.uploadSkin()).get();
if (uploadTask != null) { if (uploadTask != null) {
viewHolder.skin.setVisibility(View.GONE); viewHolder.skin.setVisibility(View.GONE);
@ -147,6 +169,7 @@ public class AccountListAdapter extends FCLAdapter {
}) })
.start(); .start();
} }
}
} catch (ExecutionException | InterruptedException e) { } catch (ExecutionException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -168,7 +168,10 @@ public class AccountListItem {
ArrayList<String> suffix = new ArrayList<>(); ArrayList<String> suffix = new ArrayList<>();
suffix.add(".png"); suffix.add(".png");
builder.setSuffix(suffix); builder.setSuffix(suffix);
builder.create().browse(MainActivity.getInstance(), RequestCodes.SELECT_SKIN_CODE, (requestCode, resultCode, data) -> {
CountDownLatch latch = new CountDownLatch(1);
Schedulers.androidUIThread().execute(() -> builder.create().browse(MainActivity.getInstance(), RequestCodes.SELECT_SKIN_CODE, (requestCode, resultCode, data) -> {
if (requestCode == RequestCodes.SELECT_SKIN_CODE && resultCode == Activity.RESULT_OK && data != null) { if (requestCode == RequestCodes.SELECT_SKIN_CODE && resultCode == Activity.RESULT_OK && data != null) {
String selectedFile = FileBrowser.getSelectedFiles(data).get(0); String selectedFile = FileBrowser.getSelectedFiles(data).get(0);
if (selectedFile == null) { if (selectedFile == null) {
@ -205,7 +208,14 @@ public class AccountListItem {
} else { } else {
completableFuture.complete(null); completableFuture.complete(null);
} }
}); latch.countDown();
}));
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return completableFuture; return completableFuture;
} }

View File

@ -15,6 +15,7 @@ import com.tungsten.fcl.setting.Accounts;
import com.tungsten.fclcore.auth.authlibinjector.AuthlibInjectorServer; import com.tungsten.fclcore.auth.authlibinjector.AuthlibInjectorServer;
import com.tungsten.fclcore.fakefx.beans.InvalidationListener; import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
import com.tungsten.fclcore.fakefx.collections.ObservableList; import com.tungsten.fclcore.fakefx.collections.ObservableList;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fcllibrary.component.FCLAdapter; import com.tungsten.fcllibrary.component.FCLAdapter;
import com.tungsten.fcllibrary.component.view.FCLImageButton; import com.tungsten.fcllibrary.component.view.FCLImageButton;
import com.tungsten.fcllibrary.component.view.FCLTextView; import com.tungsten.fcllibrary.component.view.FCLTextView;
@ -27,7 +28,7 @@ public class ServerListAdapter extends FCLAdapter {
super(context); super(context);
list = config().getAuthlibInjectorServers(); list = config().getAuthlibInjectorServers();
list.addListener((InvalidationListener) i -> notifyDataSetChanged()); list.addListener((InvalidationListener) i -> Schedulers.androidUIThread().execute(this::notifyDataSetChanged));
} }
static class ViewHolder { static class ViewHolder {