@Override public void bindView(final View view, final Context context, final Cursor cursor) { final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); final boolean isDefaultCurrency = exchangeRate.getCurrencyCode().equals(defaultCurrency); view.setBackgroundResource(isDefaultCurrency ? R.color.bg_list_selected : R.color.bg_list); final View defaultView = view.findViewById(R.id.exchange_rate_row_default); defaultView.setVisibility(isDefaultCurrency ? View.VISIBLE : View.INVISIBLE); final TextView currencyCodeView = (TextView) view.findViewById(R.id.exchange_rate_row_currency_code); currencyCodeView.setText(exchangeRate.getCurrencyCode()); final CurrencyTextView rateView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_rate); rateView.setFormat(Constants.LOCAL_FORMAT); rateView.setAmount(exchangeRate.rate.coinToFiat(rateBase)); final CurrencyTextView walletView = (CurrencyTextView) view.findViewById(R.id.exchange_rate_row_balance); walletView.setFormat(Constants.LOCAL_FORMAT); if (blockchainState == null || !blockchainState.replaying) { walletView.setAmount(exchangeRate.rate.coinToFiat(balance)); walletView.setStrikeThru(Constants.TEST); } else { walletView.setText("n/a"); walletView.setStrikeThru(false); } walletView.setTextColor(getResources().getColor(R.color.fg_less_significant)); }
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { if (data != null && data.getCount() > 0) { data.moveToFirst(); final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(data); amountCalculatorLink.setExchangeRate(exchangeRate); updateView(); } }
@Override public void onAttach(final Activity activity) { super.onAttach(activity); this.activity = (AbstractWalletActivity) activity; this.application = (WalletApplication) activity.getApplication(); this.config = application.getConfiguration(); this.wallet = application.getWallet(); this.contentUri = ExchangeRatesProvider.contentUri(activity.getPackageName(), false); this.loaderManager = getLoaderManager(); }
@Override public void onListItemClick(final ListView l, final View v, final int position, final long id) { final Cursor cursor = (Cursor) adapter.getItem(position); final ExchangeRate exchangeRate = ExchangeRatesProvider.getExchangeRate(cursor); activity.startActionMode( new ActionMode.Callback() { @Override public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.exchange_rates_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { mode.setTitle(exchangeRate.getCurrencyCode()); mode.setSubtitle( getString(R.string.exchange_rates_fragment_source, exchangeRate.source)); return true; } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.exchange_rates_context_set_as_default: handleSetAsDefault(exchangeRate.getCurrencyCode()); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) {} private void handleSetAsDefault(final String currencyCode) { config.setExchangeCurrencyCode(currencyCode); WalletBalanceWidgetProvider.updateWidgets(activity, wallet); } }); }