Search in sources :

Example 1 with ExchangeRatesRepository

use of de.schildbach.wallet.exchangerate.ExchangeRatesRepository in project bitcoin-wallet by bitcoin-wallet.

the class WalletBalanceWidgetProvider method onUpdate.

@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    final PendingResult result = goAsync();
    AsyncTask.execute(() -> {
        final WalletApplication application = (WalletApplication) context.getApplicationContext();
        final Coin balance = application.getWallet().getBalance(BalanceType.ESTIMATED);
        final Configuration config = application.getConfiguration();
        final ExchangeRatesRepository exchangeRatesRepository = ExchangeRatesRepository.get(application);
        final ExchangeRateEntry exchangeRate = config.isEnableExchangeRates() ? exchangeRatesRepository.exchangeRateDao().findByCurrencyCode(config.getExchangeCurrencyCode()) : null;
        updateWidgets(context, appWidgetManager, appWidgetIds, balance, exchangeRate != null ? exchangeRate.exchangeRate() : null);
        result.finish();
    });
}
Also used : Coin(org.bitcoinj.core.Coin) ExchangeRateEntry(de.schildbach.wallet.exchangerate.ExchangeRateEntry) ExchangeRatesRepository(de.schildbach.wallet.exchangerate.ExchangeRatesRepository)

Example 2 with ExchangeRatesRepository

use of de.schildbach.wallet.exchangerate.ExchangeRatesRepository in project bitcoin-wallet by bitcoin-wallet.

the class WalletBalanceWidgetProvider method onAppWidgetOptionsChanged.

@Override
public void onAppWidgetOptionsChanged(final Context context, final AppWidgetManager appWidgetManager, final int appWidgetId, final Bundle newOptions) {
    if (newOptions != null)
        log.info("app widget {} options changed: minWidth={}", appWidgetId, newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH));
    final PendingResult result = goAsync();
    AsyncTask.execute(() -> {
        final WalletApplication application = (WalletApplication) context.getApplicationContext();
        final Coin balance = application.getWallet().getBalance(BalanceType.ESTIMATED);
        final Configuration config = application.getConfiguration();
        final ExchangeRatesRepository exchangeRatesRepository = ExchangeRatesRepository.get(application);
        final ExchangeRateEntry exchangeRate = config.isEnableExchangeRates() ? exchangeRatesRepository.exchangeRateDao().findByCurrencyCode(config.getExchangeCurrencyCode()) : null;
        updateWidget(context, appWidgetManager, appWidgetId, newOptions, balance, exchangeRate != null ? exchangeRate.exchangeRate() : null);
        result.finish();
    });
}
Also used : Coin(org.bitcoinj.core.Coin) ExchangeRateEntry(de.schildbach.wallet.exchangerate.ExchangeRateEntry) ExchangeRatesRepository(de.schildbach.wallet.exchangerate.ExchangeRatesRepository)

Aggregations

ExchangeRateEntry (de.schildbach.wallet.exchangerate.ExchangeRateEntry)2 ExchangeRatesRepository (de.schildbach.wallet.exchangerate.ExchangeRatesRepository)2 Coin (org.bitcoinj.core.Coin)2