public class CartActivity extends BaseCartActivity<CartPresenterImpl> implements ICartView {
private static final String TAG = "CartActivity";
private ExpandableListView expandableListView;
private MyExpandAdapter myExpandAdapter;
private CheckBox quan;
private TextView total;
private TextView sum;
private List<CartBean.DataBean> cartData;
@Override
protected int initLayout() {
return R.layout.activity_cart;
}
@Override
protected CartPresenterImpl getPresenter() {
presenter = new CartPresenterImpl(this);
presenter.attach(this);
return presenter;
}
@Override
protected void initView() {
expandableListView = findViewById(R.id.cart_expand);
expandableListView.setGroupIndicator(null);
myExpandAdapter = new MyExpandAdapter(this);
expandableListView.setAdapter(myExpandAdapter);
quan = findViewById(R.id.cart_quanxuan);
total = findViewById(R.id.cart_total);
sum = findViewById(R.id.cart_sum);
}
@Override
protected void initData() {
// 4243
presenter.getCartInfo(4243);
}
@Override
protected void initClick() {
}
@Override
public void getCartData(CartBean bean) {
Log.d(TAG, "getCartData: " + bean.getCode());
cartData = bean.getData();
myExpandAdapter.add(cartData);
/************************************************/
myExpandAdapter.setOnCartListener(new MyExpandAdapter.onCartListener() {
@Override
public void onGroupChecked(int groupId) {
boolean b = myExpandAdapter.groupIsSlected(groupId);
myExpandAdapter.setGroupSlected(groupId,!b);
myExpandAdapter.notifyDataSetChanged();
//底部刷新
refreshBottom();
}
@Override
public void onGoodChecked(int groupId, int childId) {
myExpandAdapter.setGroupAndChildSlected(groupId, childId);
myExpandAdapter.notifyDataSetChanged();
//底部刷新
refreshBottom();
}
@Override
public void onGoodNumChange(int sellerid, int pid, int num, String selected, int groupId, int childId) {
myExpandAdapter.setNumber1(groupId, childId, num);
myExpandAdapter.notifyDataSetChanged();
refreshBottom();
//联网更新
presenter.updata("4243",sellerid+"",pid+"",num+"",selected);
}
@Override
public void onDelete(final int groupId, final int childId, String pid) {
AlertDialog.Builder builder = new AlertDialog.Builder(CartActivity.this);
builder.setMessage("是否删除当前商品")
.setNegativeButton("取消", null)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO: 2018/8/23 联网删除
myExpandAdapter.Removechild(groupId, childId);
myExpandAdapter.setNumber(groupId);
myExpandAdapter.notifyDataSetChanged();
// TODO: 2018/8/23
refreshBottom();
//联网删除
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
});
groupShow();
refreshBottom();
quan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean b = myExpandAdapter.ALLgroupIsSlected();
myExpandAdapter.setAllSlected(!b);
myExpandAdapter.notifyDataSetChanged();
refreshBottom();
}
});
}
@Override
public void updata(ShowBean bean) {
if (bean.getCode().equals("0")){
Toast.makeText(CartActivity.this,"刷新成功",Toast.LENGTH_SHORT).show();
}
}
private void groupShow() {
int groupCount = myExpandAdapter.getGroupCount();
for (int i = 0; i < groupCount; i++) {
expandableListView.expandGroup(i);
}
}
public void refreshBottom(){
boolean b = myExpandAdapter.ALLgroupIsSlected();
quan.setChecked(b);
total.setText("$:"+myExpandAdapter.getTotalPrice());
sum.setText(myExpandAdapter.getSum()+"");
}
}
购物车activity
最新推荐文章于 2021-08-19 17:45:20 发布