/*
 * Copyright 2014 http://Bither.net
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.bither.ui.base.dialog;

import android.content.Context;
import android.widget.TextView;

import net.bither.R;
import net.bither.bitherj.core.Address;
import net.bither.bitherj.core.Tx;
import net.bither.util.UIUtil;
import net.bither.util.UnitUtilWrapper;

import java.util.List;

public class DialogBalanceDetail extends DialogWithArrow {
    private TextView tvTransactionCount;
    private TextView tvReceived;
    private TextView tvSent;

    public DialogBalanceDetail(Context context, Info info) {
        super(context);
        setContentView(R.layout.dialog_balance_detail);
        tvTransactionCount = (TextView) findViewById(R.id.tv_transaction_count);
        tvReceived = (TextView) findViewById(R.id.tv_received);
        tvSent = (TextView) findViewById(R.id.tv_sent);
        tvTransactionCount.setText(Integer.toString(info.txCount));
        tvReceived.setText(UnitUtilWrapper.formatValueWithBold(info.totalReceived));
        tvSent.setText(UnitUtilWrapper.formatValueWithBold(info.totalSent));
    }

    @Override
    public int getSuggestHeight() {
        return UIUtil.dip2pix(200);
    }


    public static final class Info{
        public int txCount;
        public long totalReceived;
        public long totalSent;

        public Info(Address address){
            List<Tx> txs = address.getTxs();
            txCount = address.txCount();
            totalReceived = 0;
            for (Tx tx : txs) {
                long amount = tx.deltaAmountFrom(address);
                if (amount > 0) {
                    totalReceived += amount;
                }
            }
            totalSent = totalReceived - address.getBalance();
        }
    }
}

@@ -1896,53 +1896,8 @@
 s)%7B%0A
-            List%3CTx%3E txs = address.getTxs();%0A
     
@@ -1965,212 +1965,31 @@
 d = 
-0;%0A            for (Tx tx : txs) %7B%0A                long amount = tx.deltaAmountFrom(address);%0A                if (amount %3E 0) %7B%0A                    totalReceived += amount;%0A                %7D%0A            %7D
+address.totalReceive();
 %0A   

edit balance detail dialog