Search in sources :

Example 1 with WalletDetailItem

use of com.odysee.app.model.WalletDetailItem 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)

Example 2 with WalletDetailItem

use of com.odysee.app.model.WalletDetailItem in project odysee-android by OdyseeTeam.

the class WalletDetailAdapter method getView.

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    if (view == null) {
        view = inflater.inflate(R.layout.list_item_boosting_balance, viewGroup, false);
        CreditsBalanceView balanceView = view.findViewById(R.id.wallet_supporting_balance);
        TextView detailTextView = view.findViewById(R.id.detail);
        TextView detailExplanationTextView = view.findViewById(R.id.detail_explanation);
        WalletDetailItem item = (WalletDetailItem) getItem(i);
        detailTextView.setText(item.detail);
        detailExplanationTextView.setText(item.detailDesc);
        Helper.setViewText(balanceView, item.detailAmount);
        ProgressBar progressUnlockTips = view.findViewById(R.id.wallet_unlock_tips_progress);
        progressUnlockTips.setVisibility(item.isInProgress ? View.VISIBLE : View.GONE);
        ImageButton buttonLock = view.findViewById(R.id.lock_button);
        buttonLock.setVisibility((item.isUnlockable && !item.isInProgress) ? View.VISIBLE : View.GONE);
        if (item.isUnlockable) {
            buttonLock.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (view.getContext() != null) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()).setTitle(R.string.unlock_tips).setMessage(R.string.confirm_unlock_tips).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                unlockTips(view);
                            }
                        }).setNegativeButton(R.string.no, null);
                        builder.show();
                    }
                }
            });
        }
    }
    return view;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) TextView(android.widget.TextView) CreditsBalanceView(com.odysee.app.views.CreditsBalanceView) View(android.view.View) CreditsBalanceView(com.odysee.app.views.CreditsBalanceView) WalletDetailItem(com.odysee.app.model.WalletDetailItem) ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar)

Aggregations

WalletDetailItem (com.odysee.app.model.WalletDetailItem)2 Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 MainActivity (com.odysee.app.MainActivity)1 WalletDetailAdapter (com.odysee.app.adapter.WalletDetailAdapter)1 CreditsBalanceView (com.odysee.app.views.CreditsBalanceView)1 ArrayList (java.util.ArrayList)1