Search in sources :

Example 1 with WalletBalance

use of com.odysee.app.model.WalletBalance in project odysee-android by OdyseeTeam.

the class WalletBalanceFetch method call.

@Override
public WalletBalance call() throws Exception {
    WalletBalance balance;
    try {
        JSONObject json = (JSONObject) Lbry.authenticatedGenericApiCall(Lbry.METHOD_WALLET_BALANCE, null, authToken);
        balance = WalletBalance.fromJSONObject(json);
    } catch (ApiCallException | ClassCastException ex) {
        ex.printStackTrace();
        return null;
    }
    return balance;
}
Also used : WalletBalance(com.odysee.app.model.WalletBalance) JSONObject(org.json.JSONObject) ApiCallException(com.odysee.app.exceptions.ApiCallException)

Example 2 with WalletBalance

use of com.odysee.app.model.WalletBalance in project odysee-android by OdyseeTeam.

the class MainActivity method updateWalletBalance.

public void updateWalletBalance() {
    if (isSignedIn()) {
        Activity a = this;
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                ExecutorService executorService = Executors.newSingleThreadExecutor();
                Callable<WalletBalance> c = new WalletBalanceFetch(getAuthToken());
                Future<WalletBalance> f = executorService.submit(c);
                try {
                    WalletBalance balance = f.get();
                    a.runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Lbry.walletBalance = balance;
                            for (WalletBalanceListener listener : walletBalanceListeners) {
                                if (listener != null) {
                                    listener.onWalletBalanceUpdated(balance);
                                }
                            }
                            sendBroadcast(new Intent(ACTION_WALLET_BALANCE_UPDATED));
                            ((TextView) findViewById(R.id.floating_balance_value)).setText(Helper.shortCurrencyFormat(Lbry.getTotalBalance()));
                        }
                    });
                } catch (ExecutionException | InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    if (!executorService.isShutdown()) {
                        executorService.shutdown();
                    }
                }
            }
        });
        t.start();
    } else {
        Lbry.walletBalance = new WalletBalance();
        for (WalletBalanceListener listener : walletBalanceListeners) {
            if (listener != null) {
                listener.onWalletBalanceUpdated(Lbry.walletBalance);
            }
        }
        sendBroadcast(new Intent(ACTION_WALLET_BALANCE_UPDATED));
        ((TextView) findViewById(R.id.floating_balance_value)).setText(Helper.shortCurrencyFormat(Lbry.getTotalBalance()));
    }
}
Also used : WalletBalanceFetch(com.odysee.app.callable.WalletBalanceFetch) WalletBalance(com.odysee.app.model.WalletBalance) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Activity(android.app.Activity) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) ScheduledFuture(java.util.concurrent.ScheduledFuture) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) TextView(android.widget.TextView) WalletBalanceListener(com.odysee.app.listener.WalletBalanceListener) Callable(java.util.concurrent.Callable)

Example 3 with WalletBalance

use of com.odysee.app.model.WalletBalance in project odysee-android by OdyseeTeam.

the class FirstRunActivity method checkWalletBalanceForChannelStep.

private void checkWalletBalanceForChannelStep() {
    Activity a = this;
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            ExecutorService executorService = Executors.newSingleThreadExecutor();
            Callable<WalletBalance> c = new WalletBalanceFetch(Lbryio.AUTH_TOKEN);
            Future<WalletBalance> f = executorService.submit(c);
            try {
                WalletBalance wb = f.get();
                a.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (wb.getAvailable().doubleValue() < Helper.MIN_SPEND) {
                            // proceed to rewards step
                            viewPager.setVisibility(View.VISIBLE);
                            progressIndicator.setVisibility(View.GONE);
                            proceedToRewardsStep();
                        } else {
                            emailRewardChecked();
                        }
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                emailRewardChecked();
            } finally {
                if (!executorService.isShutdown()) {
                    executorService.shutdown();
                }
            }
        }
    });
    t.start();
}
Also used : WalletBalanceFetch(com.odysee.app.callable.WalletBalanceFetch) WalletBalance(com.odysee.app.model.WalletBalance) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) IOException(java.io.IOException)

Aggregations

WalletBalance (com.odysee.app.model.WalletBalance)3 Activity (android.app.Activity)2 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)2 WalletBalanceFetch (com.odysee.app.callable.WalletBalanceFetch)2 ApiCallException (com.odysee.app.exceptions.ApiCallException)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 TextView (android.widget.TextView)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 WalletBalanceListener (com.odysee.app.listener.WalletBalanceListener)1 IOException (java.io.IOException)1 Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1