Search in sources :

Example 1 with GoodsInfo

use of com.litingzhe.justandroid.main.model.GoodsInfo in project JustAndroid by chinaltz.

the class ShopFragment method calculate.

/**
     * 统计操作<br>
     * 1.先清空全局计数器<br>
     * 2.遍历所有子元素,只要是被选中状态的,就进行相关的计算操作<br>
     * 3.给底部的textView进行数据填充
     */
private void calculate() {
    totalCount = 0;
    totalPrice = 0.00;
    for (int i = 0; i < groups.size(); i++) {
        StoreInfo group = groups.get(i);
        List<GoodsInfo> childs = children.get(group.getId());
        for (int j = 0; j < childs.size(); j++) {
            GoodsInfo product = childs.get(j);
            if (product.isChoosed()) {
                totalCount++;
                totalPrice += product.getPrice() * product.getCount();
            }
        }
    }
    tvTotalPrice.setText("¥" + totalPrice);
    tvGoToPay.setText("去支付(" + totalCount + ")");
    //计算购物车的金额为0时候清空购物车的视图
    if (totalCount == 0) {
        setCartNum();
    } else {
    //            title.setText("购物车" + "(" + totalCount + ")");
    }
}
Also used : GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) StoreInfo(com.litingzhe.justandroid.main.model.StoreInfo)

Example 2 with GoodsInfo

use of com.litingzhe.justandroid.main.model.GoodsInfo in project JustAndroid by chinaltz.

the class ShopFragment method doDelete.

/**
     * 删除操作<br>
     * 1.不要边遍历边删除,容易出现数组越界的情况<br>
     * 2.现将要删除的对象放进相应的列表容器中,待遍历完后,以removeAll的方式进行删除
     */
protected void doDelete() {
    // 待删除的组元素列表
    List<StoreInfo> toBeDeleteGroups = new ArrayList<StoreInfo>();
    for (int i = 0; i < groups.size(); i++) {
        StoreInfo group = groups.get(i);
        if (group.isChoosed()) {
            toBeDeleteGroups.add(group);
        }
        // 待删除的子元素列表
        List<GoodsInfo> toBeDeleteProducts = new ArrayList<GoodsInfo>();
        List<GoodsInfo> childs = children.get(group.getId());
        for (int j = 0; j < childs.size(); j++) {
            if (childs.get(j).isChoosed()) {
                toBeDeleteProducts.add(childs.get(j));
            }
        }
        childs.removeAll(toBeDeleteProducts);
    }
    groups.removeAll(toBeDeleteGroups);
    //记得重新设置购物车
    setCartNum();
    selva.notifyDataSetChanged();
}
Also used : ArrayList(java.util.ArrayList) GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) StoreInfo(com.litingzhe.justandroid.main.model.StoreInfo)

Example 3 with GoodsInfo

use of com.litingzhe.justandroid.main.model.GoodsInfo in project JustAndroid by chinaltz.

the class ShopFragment method doDecrease.

@Override
public void doDecrease(int groupPosition, int childPosition, View showCountView, boolean isChecked) {
    GoodsInfo product = (GoodsInfo) selva.getChild(groupPosition, childPosition);
    int currentCount = product.getCount();
    if (currentCount == 1)
        return;
    currentCount--;
    product.setCount(currentCount);
    ((TextView) showCountView).setText(currentCount + "");
    selva.notifyDataSetChanged();
    calculate();
}
Also used : GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) TextView(android.widget.TextView)

Example 4 with GoodsInfo

use of com.litingzhe.justandroid.main.model.GoodsInfo in project JustAndroid by chinaltz.

the class ShopFragment method doIncrease.

@Override
public void doIncrease(int groupPosition, int childPosition, View showCountView, boolean isChecked) {
    GoodsInfo product = (GoodsInfo) selva.getChild(groupPosition, childPosition);
    int currentCount = product.getCount();
    currentCount++;
    product.setCount(currentCount);
    ((TextView) showCountView).setText(currentCount + "");
    selva.notifyDataSetChanged();
    calculate();
}
Also used : GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) TextView(android.widget.TextView)

Example 5 with GoodsInfo

use of com.litingzhe.justandroid.main.model.GoodsInfo in project JustAndroid by chinaltz.

the class ShopcartAdapter method getChildView.

@Override
public View getChildView(final int groupPosition, final int childPosition, final boolean isLastChild, View convertView, final ViewGroup parent) {
    final ChildViewHolder cholder;
    if (convertView == null) {
        convertView = View.inflate(context, R.layout.item_shopcart_product, null);
        //            if(isLastChild&&getChild(groupPosition,childPosition)!=null)
        //            {
        //                View    v = View.inflate(context, R.layout.child_footer,null);
        //                TextView txtFooter = (TextView)v.findViewById(R.id.txtFooter);
        //                txtFooter.setText("店铺满99元包邮");
        //                if(convertView instanceof ViewGroup){
        //                    ((ViewGroup) convertView).addView(v);
        //                }
        //            }
        cholder = new ChildViewHolder(convertView);
        convertView.setTag(cholder);
    } else {
        cholder = (ChildViewHolder) convertView.getTag();
    }
    if (groups.get(groupPosition).isEdtor() == true) {
        cholder.llEdtor.setVisibility(View.VISIBLE);
        cholder.rlNoEdtor.setVisibility(View.GONE);
    } else {
        cholder.llEdtor.setVisibility(View.GONE);
        cholder.rlNoEdtor.setVisibility(View.VISIBLE);
    }
    final GoodsInfo goodsInfo = (GoodsInfo) getChild(groupPosition, childPosition);
    if (isLastChild && getChild(groupPosition, childPosition) != null) {
    //            cholder.stub.setVisibility(View.VISIBLE);
    //  TextView tv= (TextView) cholder.stub.findViewById(R.id.txtFooter);//这里用来动态显示店铺满99元包邮文字内容
    } else {
    //            cholder.stub.setVisibility(View.GONE);
    }
    if (goodsInfo != null) {
        cholder.tvIntro.setText(goodsInfo.getDesc());
        cholder.tvPrice.setText("¥" + goodsInfo.getPrice() + "");
        cholder.etNum.setText(goodsInfo.getCount() + "");
        cholder.ivAdapterListPic.setImageResource(goodsInfo.getGoodsImg());
        cholder.tvColorsize.setText("颜色:" + goodsInfo.getColor() + "," + "尺码:" + goodsInfo.getSize() + "瓶/斤");
        SpannableString spanString = new SpannableString("¥" + String.valueOf(goodsInfo.getDiscountPrice()));
        StrikethroughSpan span = new StrikethroughSpan();
        spanString.setSpan(span, 0, String.valueOf(goodsInfo.getDiscountPrice()).length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //避免无限次的appand
        if (cholder.tvDiscountPrice.getText().toString().length() > 0) {
            cholder.tvDiscountPrice.setText("");
        }
        cholder.tvDiscountPrice.append(spanString);
        cholder.tvBuyNum.setText("x" + goodsInfo.getCount());
        cholder.checkBox.setChecked(goodsInfo.isChoosed());
        cholder.checkBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                goodsInfo.setChoosed(((CheckBox) v).isChecked());
                cholder.checkBox.setChecked(((CheckBox) v).isChecked());
                // 暴露子选接口
                checkInterface.checkChild(groupPosition, childPosition, ((CheckBox) v).isChecked());
            }
        });
        cholder.btAdd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 暴露增加接口
                modifyCountInterface.doIncrease(groupPosition, childPosition, cholder.etNum, cholder.checkBox.isChecked());
            }
        });
        cholder.btReduce.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 暴露删减接口
                modifyCountInterface.doDecrease(groupPosition, childPosition, cholder.etNum, cholder.checkBox.isChecked());
            }
        });
        /********************方案一:弹出软键盘修改数量,应为又不知名的bug会使然键盘强行关闭***********************/
        /****在清单文件的activity下设置键盘:
            android:windowSoftInputMode="adjustUnspecified|stateHidden|adjustPan"
            android:configChanges="orientation|keyboardHidden"****/
        //监听文本输入框的文字变化,并且刷新数据
        cholder.etNum.addTextChangedListener(new GoodsNumWatcher(goodsInfo));
        notifyDataSetChanged();
        /********************方案一***************************************************************************/
        /********************方案二:让软键盘不能弹出,文本框不可编辑弹出dialog修改***********************/
        //            cholder.etNum.setOnFocusChangeListener(new android.view.View.
        //                    OnFocusChangeListener() {
        //                @Override
        //                public void onFocusChange(View v, boolean hasFocus) {//监听焦点的变化
        //                    if (hasFocus) {//获取到焦点也就是文本框被点击修改了
        //                        // 1,先强制键盘不弹出
        //                        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        //                        imm.hideSoftInputFromWindow(v.getWindowToken(), 0); //强制隐藏键盘
        //                        // 2.显示弹出dialog进行修改
        //                        showDialog(goodsInfo,cholder.etNum);
        //3.清除焦点防止不断弹出dialog和软键盘
        //                        cholder.etNum.clearFocus();
        // 4. 数据刷型
        //                        ShopcartAdapter.this.notifyDataSetChanged();
        //                    }
        //                }
        //            });
        /********************方案二***********************/
        //删除 购物车
        cholder.tvGoodsDelete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                AlertDialog alert = new AlertDialog.Builder(context).create();
                alert.setTitle("操作提示");
                alert.setMessage("您确定要将这些商品从购物车中移除吗?");
                alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
                alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        modifyCountInterface.childDelete(groupPosition, childPosition);
                    }
                });
                alert.show();
            }
        });
    }
    return convertView;
}
Also used : SpannableString(android.text.SpannableString) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) CheckBox(android.widget.CheckBox) GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) StrikethroughSpan(android.text.style.StrikethroughSpan)

Aggregations

GoodsInfo (com.litingzhe.justandroid.main.model.GoodsInfo)11 StoreInfo (com.litingzhe.justandroid.main.model.StoreInfo)8 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 SpannableString (android.text.SpannableString)1 StrikethroughSpan (android.text.style.StrikethroughSpan)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 BindView (butterknife.BindView)1 Random (java.util.Random)1