GWWWWWWWWE

public class GWCFragment extends Fragment implements GWDataFac{

    private View view;
    private MyExpanableListView myExpanableListView;
    private GWPersent gwPersent;
    private CheckBox checkBox;
    private TextView gwc_zongjia;
    private TextView gwc_allsum;
    private CountPriceBean countPriceBean;
    private Handler handler=new Handler(){

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what==0){
                countPriceBean = (CountPriceBean) msg.obj;
                //设置价格和数量
                gwc_zongjia.setText("合计:¥"+ countPriceBean.getPriceString());
                gwc_allsum.setText("去结算("+ countPriceBean.getCount()+")");
            }
        }
    };
    private RelativeLayout relative_progress;
    private GwAdapter gwAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = View.inflate(getActivity(), R.layout.gwc_layout, null);

        //查找控件
        initView();

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        gwPersent = new GWPersent(this);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gwAdapter.setAllChildsChecked(checkBox.isChecked());
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        //显示进度条
        relative_progress.setVisibility(View.VISIBLE);
        gwPersent.setUrl(ApiUtil.cartUrl);
    }

    //查找控件
    private void initView() {
        myExpanableListView = (MyExpanableListView) view.findViewById(R.id.gw_myExpanableListView);
        myExpanableListView.setGroupIndicator(null);
        checkBox = (CheckBox) view.findViewById(R.id.gwc_quanxuan_checkbox);
        gwc_zongjia = (TextView) view.findViewById(R.id.gwc_zj);
        gwc_allsum = (TextView) view.findViewById(R.id.gwc_zs);
        relative_progress = (RelativeLayout) view.findViewById(R.id.relative_progress);
    }

    @Override
    public void onSuccess(final GWBean gwBean) {
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                //获取数据成功...隐藏
                relative_progress.setVisibility(View.GONE);

                //点击结算  创建订单
                gwc_allsum.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (countPriceBean.getCount()>0){
                            Map<String,String> map=new HashMap<String, String>();
                            map.put("uid","3410");
                            map.put("price",countPriceBean.getPriceString());
                            OkHttp3Util.doPost(ApiUtil.createOrderUrl, map, new Callback() {
                                @Override
                                public void onFailure(Call call, IOException e) {

                                }

                                @Override
                                public void onResponse(Call call, Response response) throws IOException {

                                }
                            });
                            Intent intent=new Intent(getActivity(), DDActivity.class);
                            startActivity(intent);
                        }else {
                            Toast.makeText(getActivity(), "购物车为空", Toast.LENGTH_SHORT).show();
                        }

                    }
                });
                if (gwBean!=null){
                    for (int i=0;i<gwBean.getData().size();i++){
                        List<GWBean.DataBean.ListBean> list = gwBean.getData().get(i).getList();
                        gwBean.getData().get(i).setGroupChecked(isChildInGroupChecked(list));

                    }
                   //2.根据所有商家选中的状态,改变全选的状态
                    checkBox.setChecked(isAllGroupChecked(gwBean));

                    //设置适配器
                    final List<GWBean.DataBean> data = gwBean.getData();
                    gwAdapter = new GwAdapter(data,getActivity(),handler,gwPersent,relative_progress);
                    myExpanableListView.setAdapter(gwAdapter);
                    //展开所有的组...expanableListView.expandGroup()
                    for (int i = 0;i<data.size();i++){
                        myExpanableListView.expandGroup(i);
                    }
                    //3.计算总价和商品的数量
                    gwAdapter.sendPriceAndCount();
                }
            }
        });
    }

    private boolean isAllGroupChecked(GWBean gwBean) {
        for (int i=0;i<gwBean.getData().size();i++){
            if (!gwBean.getData().get(i).isGroupChecked()){
                return false;
            }
        }
        return true;
    }

    private boolean isChildInGroupChecked(List<GWBean.DataBean.ListBean> list) {
        for (int j=0;j<list.size();j++){
            if (list.get(j).getSelected()==0){
                return false;
            }
        }
        return true;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值