@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); if (args != null) { if (args.containsKey(Constants.ARG_ACCOUNT_ID)) { String accountId = args.getString(Constants.ARG_ACCOUNT_ID); pocket = checkNotNull(application.getAccount(accountId)); } if (args.containsKey(Constants.ARG_URI)) { try { processUri(args.getString(Constants.ARG_URI)); } catch (CoinURIParseException e) { // TODO handle more elegantly Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); ACRA.getErrorReporter().handleException(e); } } if (pocket == null) { List<WalletAccount> accounts = application.getAllAccounts(); if (accounts.size() > 0) pocket = accounts.get(0); if (pocket == null) { ACRA.getErrorReporter() .putCustomData("wallet-exists", application.getWallet() == null ? "no" : "yes"); Toast.makeText(getActivity(), R.string.no_such_pocket_error, Toast.LENGTH_LONG).show(); getActivity().finish(); return; } } checkNotNull(pocket, "No account selected"); } else { throw new RuntimeException("Must provide account ID or a payment URI"); } sendAmountType = pocket.getCoinType(); messageFactory = pocket.getCoinType().getMessagesFactory(); if (savedInstanceState != null) { address = (Address) savedInstanceState.getSerializable(STATE_ADDRESS); addressTypeCanChange = savedInstanceState.getBoolean(STATE_ADDRESS_CAN_CHANGE_TYPE); sendAmount = (Value) savedInstanceState.getSerializable(STATE_AMOUNT); sendAmountType = (CoinType) savedInstanceState.getSerializable(STATE_AMOUNT_TYPE); } updateBalance(); setHasOptionsMenu(true); mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer); String localSymbol = config.getExchangeCurrencyCode(); for (ExchangeRatesProvider.ExchangeRate rate : getRates(getActivity(), localSymbol)) { localRates.put(rate.currencyCodeId, rate.rate); } loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks); loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks); }
private void setAmountForEmptyWallet() { updateBalance(); if (state != State.INPUT || pocket == null || lastBalance == null) return; if (lastBalance.isZero()) { String message = getResources().getString(R.string.amount_error_not_enough_money_plain); Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show(); } else { amountCalculatorLink.setPrimaryAmount(lastBalance); validateAmount(); } }
@Override public void onResume() { super.onResume(); amountCalculatorLink.setListener(amountsListener); resolver.registerContentObserver( AddressBookProvider.contentUri(getActivity().getPackageName()), true, addressBookObserver); if (pocket != null) { pocket.addEventListener(transactionChangeListener, Threading.SAME_THREAD); } updateBalance(); updateView(); }
private void onWalletUpdate() { updateBalance(); validateAmount(); }