Search in sources :

Example 1 with WalletBalanceListener

use of com.odysee.app.listener.WalletBalanceListener 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)

Aggregations

Activity (android.app.Activity)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 TextView (android.widget.TextView)1 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1 WalletBalanceFetch (com.odysee.app.callable.WalletBalanceFetch)1 WalletBalanceListener (com.odysee.app.listener.WalletBalanceListener)1 WalletBalance (com.odysee.app.model.WalletBalance)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