use of com.odysee.app.supplier.UnlockingTipsSupplier in project odysee-android by OdyseeTeam.
the class MainActivity method unlockTips.
public void unlockTips() {
if (unlockingTips) {
return;
}
Map<String, Object> options = new HashMap<>();
options.put("type", "support");
options.put("is_not_my_input", true);
options.put("blocking", true);
AccountManager am = AccountManager.get(getApplicationContext());
String authToken = am.peekAuthToken(am.getAccounts()[0], "auth_token_type");
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
unlockingTips = true;
Supplier<Boolean> task = new UnlockingTipsSupplier(options, authToken);
CompletableFuture<Boolean> completableFuture = CompletableFuture.supplyAsync(task);
completableFuture.thenAccept(result -> {
unlockingTips = false;
});
} else {
Thread unlockingThread = new Thread(new Runnable() {
@Override
public void run() {
Callable<Boolean> callable = () -> {
try {
Lbry.directApiCall(Lbry.METHOD_TXO_SPEND, options, authToken);
return true;
} catch (ApiCallException | ClassCastException ex) {
ex.printStackTrace();
return false;
}
};
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<Boolean> future = executorService.submit(callable);
try {
unlockingTips = true;
// This doesn't block main thread as it is called from a different thread
future.get();
unlockingTips = false;
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
});
unlockingThread.start();
}
}
Aggregations