/*
 * 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.util.UIUtil;
import net.bither.util.UnitUtilWrapper;

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){
            txCount = address.txCount();
            totalReceived = address.totalReceive();
            totalSent = totalReceived - address.getBalance();
        }
    }
}

@@ -756,16 +756,51 @@
 ddress;%0A
+import net.bither.bitherj.core.Tx;%0A
 import n
@@ -863,16 +863,40 @@
 apper;%0A%0A
+import java.util.List;%0A%0A
 public c
@@ -1892,16 +1892,61 @@
 dress)%7B%0A
+            List%3CTx%3E txs = address.getTxs();%0A
         
@@ -2010,31 +2010,212 @@
 d = 
-address.totalReceive();
+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
 %0A   

reset balance detail dialog