Search in sources :

Example 1 with StoreInfo

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

the class ShopcartAdapter method getGroupView.

@Override
public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    final GroupViewHolder gholder;
    if (convertView == null) {
        convertView = View.inflate(context, R.layout.item_shopcart_group, null);
        gholder = new GroupViewHolder(convertView);
        convertView.setTag(gholder);
    } else {
        gholder = (GroupViewHolder) convertView.getTag();
    }
    final StoreInfo group = (StoreInfo) getGroup(groupPosition);
    gholder.tvSourceName.setText(group.getName());
    gholder.determineChekbox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            group.setChoosed(((CheckBox) v).isChecked());
            // 暴露组选接口
            checkInterface.checkGroup(groupPosition, ((CheckBox) v).isChecked());
        }
    });
    gholder.determineChekbox.setChecked(group.isChoosed());
    if (group.isEdtor()) {
        gholder.tvStoreEdtor.setText("完成");
    } else {
        gholder.tvStoreEdtor.setText("编辑");
    }
    gholder.tvStoreEdtor.setOnClickListener(new GroupViewClick(groupPosition, gholder.tvStoreEdtor, group));
    notifyDataSetChanged();
    return convertView;
}
Also used : CheckBox(android.widget.CheckBox) StoreInfo(com.litingzhe.justandroid.main.model.StoreInfo) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView)

Example 2 with StoreInfo

use of com.litingzhe.justandroid.main.model.StoreInfo 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 3 with StoreInfo

use of com.litingzhe.justandroid.main.model.StoreInfo 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 4 with StoreInfo

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

the class ShopFragment method setCartNum.

//    @Override
//    protected void onResume() {
//        super.onResume();
//        setCartNum();
//    }
/**
     * 设置购物车产品数量
     */
private void setCartNum() {
    int count = 0;
    for (int i = 0; i < groups.size(); i++) {
        groups.get(i).setChoosed(allChekbox.isChecked());
        StoreInfo group = groups.get(i);
        List<GoodsInfo> childs = children.get(group.getId());
        for (GoodsInfo goodsInfo : childs) {
            count += 1;
        }
    }
    //购物车已清空
    if (count == 0) {
        clearCart();
    } else {
    }
}
Also used : GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) StoreInfo(com.litingzhe.justandroid.main.model.StoreInfo)

Example 5 with StoreInfo

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

the class ShopFragment method checkChild.

@Override
public void checkChild(int groupPosition, int childPosiTion, boolean isChecked) {
    // 判断改组下面的所有子元素是否是同一种状态
    boolean allChildSameState = true;
    StoreInfo group = groups.get(groupPosition);
    List<GoodsInfo> childs = children.get(group.getId());
    for (int i = 0; i < childs.size(); i++) {
        // 不全选中
        if (childs.get(i).isChoosed() != isChecked) {
            allChildSameState = false;
            break;
        }
    }
    //获取店铺选中商品的总金额
    if (allChildSameState) {
        // 如果所有子元素状态相同,那么对应的组元素被设为这种统一状态
        group.setChoosed(isChecked);
    } else {
        // 否则,组元素一律设置为未选中状态
        group.setChoosed(false);
    }
    if (isAllCheck()) {
        // 全选
        allChekbox.setChecked(true);
    } else {
        // 反选
        allChekbox.setChecked(false);
    }
    selva.notifyDataSetChanged();
    calculate();
}
Also used : GoodsInfo(com.litingzhe.justandroid.main.model.GoodsInfo) StoreInfo(com.litingzhe.justandroid.main.model.StoreInfo)

Aggregations

StoreInfo (com.litingzhe.justandroid.main.model.StoreInfo)9 GoodsInfo (com.litingzhe.justandroid.main.model.GoodsInfo)8 ArrayList (java.util.ArrayList)2 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1 Random (java.util.Random)1