package com.dev.bins.shop;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dev.bins.shop.bean.GoodsItem;
import com.dev.bins.shop.bean.OrderAddress;

import org.litepal.crud.DataSupport;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderActivity extends AppCompatActivity {

    /**
     * 商品展示列表
     */
    @BindView(R.id.recycler_orderlist)
    RecyclerView mRecyclerViewGoods;

    /**
     * 收件人
     */
    @BindView(R.id.tv_receiver)
    TextView mTvReceiver;

    /**
     * 地址
     */
    @BindView(R.id.tv_addr)
    TextView mTvAddress;

    /**
     * 收件人和地址
     */
    @BindView(R.id.rl_add)
    RelativeLayout mRlReceAddress;

    /**
     * 总价格
     */
    @BindView(R.id.tv_total_price)
    TextView mTvTotalPrice;
    /**
     * 提交订单
     */
    @BindView(R.id.tv_submit)
    TextView mTvSubmit;

    @BindView(R.id.tv_good_count)
    TextView mTvGoodsCount;
    private List<GoodsItem> mGoods;
    private OrderAddress mDefaultOrderAddress;
    private GoodsAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        mGoods = DataSupport.findAll(GoodsItem.class);
//        mGoods = DataSupport.where("isChecked=?", "true").find(GoodsItem.class);
        mTvGoodsCount.setText("共" + String.valueOf(mGoods.size()) + "件");
        List<OrderAddress> orderAddresses = DataSupport.where("isDefault=?", "true").find(OrderAddress.class);
        if (null != orderAddresses && orderAddresses.size() > 0) {
            mDefaultOrderAddress = orderAddresses.get(0);
            mTvReceiver.setText(mDefaultOrderAddress.getName());
            mTvAddress.setText(mDefaultOrderAddress.getAdd() + mDefaultOrderAddress.getAddress());
        }
        mTvTotalPrice.setText("应付款:￥" + String.valueOf(calcPrice()));
        mAdapter = new GoodsAdapter(mGoods);
        mRecyclerViewGoods.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        mRecyclerViewGoods.setAdapter(mAdapter);
    }

    public double calcPrice() {
        if (null == mGoods || 0 == mGoods.size()) {
            return 0;
        }
        double price = 0;
        for (GoodsItem mGood : mGoods) {
            price = mGood.getPrice() * mGood.getCount();
        }
        return price;
    }


}

@@ -1503,24 +1503,26 @@
 nitData() %7B%0A
+//
         mGoo
@@ -1564,18 +1564,16 @@
 class);%0A
-//
         
@@ -1611,28 +1611,25 @@
 hecked=?%22, %22
-true
+1
 %22).find(Good
@@ -1798,12 +1798,9 @@
 %22, %22
-true
+1
 %22).f

fix get data from database is size == 0