Search in sources :

Example 1 with WalletDetailAdapter

use of com.odysee.app.adapter.WalletDetailAdapter in project odysee-android by OdyseeTeam.

the class WalletFragment method onWalletBalanceUpdated.

public void onWalletBalanceUpdated(WalletBalance walletBalance) {
    if (walletBalance == null) {
        return;
    }
    double totalBalance = walletBalance.getTotal().doubleValue();
    double spendableBalance = walletBalance.getAvailable().doubleValue();
    double supportingBalance = walletBalance.getClaims().doubleValue() + walletBalance.getTips().doubleValue() + walletBalance.getSupports().doubleValue();
    double usdBalance = totalBalance * Lbryio.LBCUSDRate;
    double tipsBalance = walletBalance.getTips().doubleValue();
    if (detailRows == null)
        detailRows = new ArrayList<>(3);
    if (detailAdapter == null) {
        detailAdapter = new WalletDetailAdapter(getContext(), detailRows);
        detailListView.setAdapter(detailAdapter);
    }
    Activity activity = (Activity) getContext();
    boolean tipsBeenUnlocked;
    if (activity instanceof MainActivity)
        tipsBeenUnlocked = ((MainActivity) activity).isUnlockingTips();
    else
        tipsBeenUnlocked = false;
    WalletDetailItem earnedBalance = new WalletDetailItem(getResources().getString(R.string.earned_from_others), getResources().getString(R.string.unlock_to_spend), Helper.SIMPLE_CURRENCY_FORMAT.format(tipsBalance), tipsBalance != 0, tipsBeenUnlocked);
    WalletDetailItem initialPublishes = new WalletDetailItem(getResources().getString(R.string.on_initial_publishes), getResources().getString(R.string.delete_or_edit_past_content), Helper.SIMPLE_CURRENCY_FORMAT.format(walletBalance.getClaims().doubleValue()), false, false);
    WalletDetailItem supportingContent = new WalletDetailItem(getResources().getString(R.string.supporting_content), getResources().getString(R.string.delete_supports_to_spend), Helper.SIMPLE_CURRENCY_FORMAT.format(walletBalance.getSupports().doubleValue()), false, false);
    if (detailRows.size() == 0) {
        detailRows.add(0, earnedBalance);
        detailRows.add(1, initialPublishes);
        detailRows.add(2, supportingContent);
    } else {
        if (!detailRows.get(0).detailAmount.equals(earnedBalance.detailAmount) || detailRows.get(0).isInProgress != earnedBalance.isInProgress || detailRows.get(0).isUnlockable != earnedBalance.isUnlockable) {
            detailRows.set(0, earnedBalance);
        }
        if (!detailRows.get(1).detailAmount.equals(initialPublishes.detailAmount)) {
            detailRows.set(1, initialPublishes);
        }
        if (!detailRows.get(2).detailAmount.equals(supportingContent.detailAmount)) {
            detailRows.set(2, supportingContent);
        }
    }
    detailListView.setAdapter(detailAdapter);
    String formattedTotalBalance = Helper.REDUCED_LBC_CURRENCY_FORMAT.format(totalBalance);
    String formattedSpendableBalance = Helper.SIMPLE_CURRENCY_FORMAT.format(spendableBalance);
    String formattedSupportingBalance = Helper.SIMPLE_CURRENCY_FORMAT.format(supportingBalance);
    Helper.setViewText(walletTotalBalanceView, totalBalance > 0 && formattedTotalBalance.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(totalBalance) : formattedTotalBalance);
    Helper.setViewText(walletSpendableBalanceView, spendableBalance > 0 && formattedSpendableBalance.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(spendableBalance) : formattedSpendableBalance);
    Helper.setViewText(walletSupportingBalanceView, supportingBalance > 0 && formattedSupportingBalance.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(supportingBalance) : formattedSupportingBalance);
    Helper.setViewText(textWalletInlineBalance, Helper.shortCurrencyFormat(spendableBalance));
    if (Lbryio.LBCUSDRate > 0) {
        // only update display usd values if the rate is loaded
        Helper.setViewText(textWalletBalanceUSD, String.format("≈$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(usdBalance)));
    }
    textWalletBalanceDesc.setText(spendableBalance == totalBalance ? getResources().getString(R.string.your_total_balance) : getResources().getString(R.string.all_of_this_is_yours));
    fetchRecentTransactions(true);
    checkRewardsDriver();
}
Also used : WalletDetailItem(com.odysee.app.model.WalletDetailItem) ArrayList(java.util.ArrayList) MainActivity(com.odysee.app.MainActivity) Activity(android.app.Activity) WalletDetailAdapter(com.odysee.app.adapter.WalletDetailAdapter) MainActivity(com.odysee.app.MainActivity)

Aggregations

Activity (android.app.Activity)1 MainActivity (com.odysee.app.MainActivity)1 WalletDetailAdapter (com.odysee.app.adapter.WalletDetailAdapter)1 WalletDetailItem (com.odysee.app.model.WalletDetailItem)1 ArrayList (java.util.ArrayList)1