欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

乱七八糟

程序员文章站 2024-03-25 08:05:46
...
goodsAdapter.setLisenter(new GoodsAdapter.onGoodsLisenter() {
            @Override
            public void onSendGoods() {
                //回调给Activity刷新价格
                if (lisenter_shop!=null){
                    lisenter_shop.onSendShop(shopResponse);
                }

                List<ShopListBean> list1 = shopResponse.get(i).getList();
                //临时使用标志位
                boolean isCheckAll=true;
                //遍历商品判断是否全部选中
                for (int j = 0; j < list1.size(); j++) {
                    ShopListBean shopListBean = list1.get(j);
                    if (!shopListBean.isFlag()){
                        //只要有一个未选中那么就设为false
                        isCheckAll=false;
                        break;
                    }
                }
                myShopViewHodelr.box_shop.setChecked(isCheckAll);
                shopResponse.get(i).setFlags(isCheckAll);

            }
        });
shopAdapter.setLisenter_shop(new ShopAdapter.onShopLisenter() {
            @Override
            public void onSendShop(List<ShopDataBean> data1) {
                double total=0.0;
                //选中数量
                int sums=0;
                //总共数量
                int total_sum=0;
                for (int i = 0; i < data1.size(); i++) {
                    List<ShopListBean> list_goods = data1.get(i).getList();
                    for (int j = 0; j < list_goods.size(); j++) {
                        total_sum += list_goods.get(j).getNum();
                        if (list_goods.get(j).isFlag()){
                            //如果此商品选中,则获取商品的数量和价格获取总价
                            int price = list_goods.get(j).getPrice();
                            int num = list_goods.get(j).getNum();
                            total+=num*price;
                            sums+=list_goods.get(j).getNum();
                        }
                    }
                }
                /*
                * 如果选中的商品的数量小于总共的商品的数量,说明没有全部选中,
                * 全选框设置为false,否则说明全部选中设为true
                * */
                if (total_sum>sums){
                    box_all.setChecked(false);
                }else {
                    box_all.setChecked(true);
                }

                total_price.setText(total+"");
                sum.setText("去结算"+"("+sums+")");

            }
        });
/*
     * 商家控制商品的状态
     * */
    public void select(boolean isSelectAll){
        for (ShopListBean listBean: shopListBean) {
            listBean.setFlag(isSelectAll);
        }
        notifyDataSetChanged();
    }
 //加减器加的时候价格联动
        myGoodsViewHolder.addview.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myGoodsViewHolder.addview.nnn++;
                myGoodsViewHolder.addview.num.setText(myGoodsViewHolder.addview.nnn+"");
                shopListBean.get(i).setNum(myGoodsViewHolder.addview.nnn);
                lisenter.onSendGoods();
            }
        });
        //加减器减的时候价格联动
        myGoodsViewHolder.addview.reduce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (myGoodsViewHolder.addview.nnn>1){
                    myGoodsViewHolder.addview.nnn--;
                    myGoodsViewHolder.addview.num.setText(myGoodsViewHolder.addview.nnn+"");
                    shopListBean.get(i).setNum(myGoodsViewHolder.addview.nnn);
                    lisenter.onSendGoods();
                }else {
                    Toast.makeText(context, "再减还买个锤子呀", Toast.LENGTH_SHORT).show();
                }

            }
        });

缓存

leftResultDao.deleteAll();
        result.get(0).setSelect(true);
        for (LeftResult leftResult:result) {
            LeftResult bean=leftResult;
            bean.setPid(Long.parseLong(leftResult.getId()));
            leftResultDao.insertOrReplace(bean);
            List<LeftResult> leftResults = leftResultDao.loadAll();
            int size = leftResults.size();
        }
//rightResultDao.deleteAll();
        for (int i = 0; i <result_right.size() ; i++) {
            RightResult rightResult = result_right.get(i);
            rightResult.setPid(Long.parseLong(id));
            rightResultDao.insertOrReplace(rightResult);
        }
 /*
     * 没网的时候从数据库查询展示,左边的数据
     * */
    private void getLeftData() {
        Toast.makeText(this, "没网", Toast.LENGTH_SHORT).show();
        QueryBuilder leftResultQueryBuilder = leftResultDao.queryBuilder();
        QueryBuilder where = leftResultQueryBuilder.where(LeftResultDao.Properties.Pid.gt(0));
        //排序
        where.orderAsc(LeftResultDao.Properties.Pid);
        //返回查询结果
        List<Object> list = where.list();
       /* LeftResultDao list_dao= (LeftResultDao) list;
        list_dao.getKey()
*/
        if (list.size()>0){
            for (Object o: list){
                if (o instanceof  LeftResult){
                    leftResult = new LeftResult();
                    leftResult.setId(((LeftResult)o).getId());
                    leftResult.setName(((LeftResult)o).getName());
                    leftResult.setPid(Long.valueOf(((LeftResult)o).getId()));
                    result1.add(leftResult);
                }
            }
            LogUtil.json(result1.toString());
            //展示
            LinearLayoutManager linearLayoutManager1 = new LinearLayoutManager(this);
            rlvLeft.setLayoutManager(linearLayoutManager1);
            ShowLeftAdapter showLeftAdapter1 = new ShowLeftAdapter(MainActivity.this, result1);
            rlvLeft.setAdapter(showLeftAdapter1);

        }
    }
/*
     * 没网的时候从数据库根据左边Id,在数据库中查询相应的条目数据,右边的数据
     * */
    private void getRightDada(String id) {
        QueryBuilder<RightResult> rightResultQueryBuilder = rightResultDao.queryBuilder();
        QueryBuilder<RightResult> where = rightResultQueryBuilder.where(RightResultDao.Properties.Pid.eq(this.id));
        where.orderAsc(RightResultDao.Properties.Pid);
        List<RightResult> list = where.list();
        if (list.size()>0){
            if (result_right.size()>0){
                result_right.clear();
            }
            for (Object o:list){
                if (o instanceof RightResult){
                    rightResult = new RightResult();
                    rightResult.setCommodityName(((RightResult)o).getCommodityName());
                    rightResult.setCommodityId(((RightResult)o).getCommodityId());
                    rightResult.setMasterPic(((RightResult)o).getMasterPic());
                    result_right.add(rightResult);
                }
            }

            GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
            rlvRight.setLayoutManager(gridLayoutManager);
            ShowRightAdapter showRightAdapter = new ShowRightAdapter(MainActivity.this, result_right);
            rlvRight.setAdapter(showRightAdapter);

        }
    }