购物车页面

This commit is contained in:
itgaojian163 2022-12-23 17:15:57 +08:00
parent 860fd597da
commit e191fc9108
19 changed files with 513 additions and 8 deletions

View File

@ -0,0 +1,78 @@
package com.sucstepsoft.cm_utils.core.widget.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.sucstepsoft.cm_utils.R;
public class AddOrDelView extends LinearLayout {
private OnAddDelClickListener listener;
private EditText et_number;
public interface OnAddDelClickListener {
void onAddClick(View v);
void onDelClick(View v);
}
public AddOrDelView(Context context) {
this(context, null);
}
public AddOrDelView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public AddOrDelView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context, attrs, defStyleAttr);
}
private void initView(Context context, AttributeSet attrs, int defStyleAttr) {
View.inflate(context, R.layout.layout_add_delete, this);
ImageView but_add = findViewById(R.id.iv_add);
ImageView but_delete = findViewById(R.id.iv_del);
et_number = findViewById(R.id.et_number);
//释放资源 typedArray.recycle();
but_add.setOnClickListener(view -> listener.onAddClick(view));
but_delete.setOnClickListener(view -> listener.onDelClick(view));
}
/**
* 对外提供设置EditText值的方法
*/
public void setNumber(int number) {
if (number > 0) {
et_number.setText(number + "");
}
}
/**
* 得到控件原来的值
*/
public int getNumber() {
int number = 0;
try {
String numberStr = et_number.getText().toString().trim();
number = Integer.valueOf(numberStr);
} catch (Exception e) {
number = 0;
}
return number;
}
public void setOnAddDelClickListener(OnAddDelClickListener listener) {
if (listener != null) {
this.listener = listener;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_del"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/ic_del_circle_icon"
android:scaleType="fitXY" />
<EditText
android:id="@+id/et_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:gravity="center"
android:inputType="number"
android:minWidth="30dp" />
<ImageView
android:id="@+id/iv_add"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/ic_add_circle_icon"
android:scaleType="fitXY" />
</LinearLayout>
</LinearLayout>

View File

@ -4,21 +4,21 @@
<application>
<activity
android:name=".ShopCarActivity"
android:name="com.tenlionsoft.moduleshop.activitys.ShopCarActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".GoodsListActivity"
android:name="com.tenlionsoft.moduleshop.activitys.GoodsListActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".GoodsDetailActivity"
android:name="com.tenlionsoft.moduleshop.activitys.GoodsDetailActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
android:exported="false"
android:screenOrientation="portrait"

View File

@ -22,6 +22,7 @@ import android.widget.RelativeLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
@ -144,11 +145,14 @@ public class GoodsDetailActivity extends BaseActivity {
}
mStandardAdapter.addOnItemPosClickListener((b, p) -> {
setPrice(b.getGoodsItemUnitPrice());
mDetailBean.setGoodsPrice(b.getGoodsItemUnitPrice()+"");
mTvGoodsStock.setText("库存:" + b.getGoodsItemTotal());
mStandardAdapter.setSelPos(p);
});
mTvAddCar.setOnClickListener(v -> addToCar(mDetailBean));
mLlCar.setOnClickListener(v -> ARouter.getInstance()
.build(PathConfig.PATH_MODULE_SHOP_ACTIVITY_SHOP_CAR)
.navigation());
}
private void parserShopCar() {
@ -185,6 +189,7 @@ public class GoodsDetailActivity extends BaseActivity {
mCarDatas.get(pos).setCarAmount(mCarDatas.get(pos).getCarAmount() + 1);
} else {
bean.setCarAmount(1);
bean.setGoodsPrice("");
mCarDatas.add(bean);
}
}

View File

@ -2,6 +2,9 @@ package com.tenlionsoft.moduleshop.activitys;
import android.text.TextUtils;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
@ -9,11 +12,16 @@ import com.sucstepsoft.cm_utils.constant.PathConfig;
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
import com.tengshisoft.moduleshop.R;
import com.tengshisoft.moduleshop.R2;
import com.tenlionsoft.moduleshop.adapter.GoodsCarAdapter;
import com.tenlionsoft.moduleshop.beans.CustomCarBean;
import com.tenlionsoft.moduleshop.beans.ShopGoodsDetailBean;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
@ -21,9 +29,11 @@ import butterknife.ButterKnife;
*/
@Route(path = PathConfig.PATH_MODULE_SHOP_ACTIVITY_SHOP_CAR)
public class ShopCarActivity extends BaseActivity {
@BindView(R2.id.rlv_car)
RecyclerView mRlvCar;
private List<ShopGoodsDetailBean> mCarDatas;
private List<CustomCarBean> mDatas;
private GoodsCarAdapter mAdapter;
@Override
protected int setLayoutId() {
@ -34,6 +44,10 @@ public class ShopCarActivity extends BaseActivity {
public void initData() {
ButterKnife.bind(this);
mTvBaseTitle.setText("购物车");
mDatas = new ArrayList<>();
mAdapter = new GoodsCarAdapter(mActivity, mDatas);
mRlvCar.setLayoutManager(new LinearLayoutManager(mActivity));
mRlvCar.setAdapter(mAdapter);
parserShopCar();
}
@ -46,7 +60,7 @@ public class ShopCarActivity extends BaseActivity {
Type type = new TypeToken<List<ShopGoodsDetailBean>>() {
}.getType();
mCarDatas = gson.fromJson(shopCar, type);
refreshView(STATE_LOAD_SUCCESS);
parserDatas();
} else {
refreshView(STATE_LOAD_EMPTY);
mTvErrorHint.setText("购物车暂无数据");
@ -55,4 +69,26 @@ public class ShopCarActivity extends BaseActivity {
e.printStackTrace();
}
}
/**
* 构建数据
*/
private void parserDatas() {
mDatas = new ArrayList<>();
for (int i = 0; i < mCarDatas.size(); i++) {
ShopGoodsDetailBean bean = mCarDatas.get(i);
CustomCarBean b = new CustomCarBean();
b.setShopId(bean.getShopId());
b.setShopName(bean.getShopName());
b.setGoods(new ArrayList<>());
for (int j = 0; j < mCarDatas.size(); j++) {
if (bean.getShopId().equals(mCarDatas.get(j).getShopId())) {
b.getGoods().add(mCarDatas.get(j));
}
}
mDatas.add(b);
}
mAdapter.setData(mDatas);
refreshView(STATE_LOAD_SUCCESS);
}
}

View File

@ -0,0 +1,64 @@
package com.tenlionsoft.moduleshop.adapter;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.sucstepsoft.cm_utils.core.widget.views.AddOrDelView;
import com.tengshisoft.moduleshop.R;
import com.tenlionsoft.moduleshop.beans.ShopGoodsDetailBean;
import com.tenlionsoft.moduleshop.holder.CarGoodsHolder;
import java.util.List;
/**
* 购物车中商品适配器
*/
public class CarGoodsAdapter extends BaseRecyclerAdapter<ShopGoodsDetailBean, CarGoodsHolder> {
public CarGoodsAdapter(Context ctx, List<ShopGoodsDetailBean> list) {
super(ctx, list);
}
@Override
public CarGoodsHolder createHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_car_goods, parent, false);
return new CarGoodsHolder(view);
}
@Override
public void bindHolder(CarGoodsHolder h, int i) {
ShopGoodsDetailBean bean = mData.get(i);
h.mTvName.setText(Html.fromHtml(bean.getGoodsName()));
Glide.with(mContext)
.load(BaseUrlApi.BASE_SHOP_IMG_URL + bean.getGoodsIcon())
.apply(new RequestOptions()
.placeholder(R.drawable.ic_img_default)
.error(R.drawable.ic_img_default))
.into(h.mIvIcon);
h.mTvPrice.setText("¥ " + bean.getGoodsPrice());
h.mTvSales.setText("销量:" + bean.getGoodsSalesVolume() + "");
h.mTvFreight.setText("1".equals(bean.getGoodsNotFreight()) ? "不包邮" : "包邮");
h.mTvEvaluate.setText("评分:" + bean.getGoodStar() + "");
h.mAodView.setNumber(bean.getCarAmount());
h.mAodView.setOnAddDelClickListener(new AddOrDelView.OnAddDelClickListener() {
@Override
public void onAddClick(View v) {
bean.setCarAmount(bean.getCarAmount() + 1);
notifyDataSetChanged();
}
@Override
public void onDelClick(View v) {
bean.setCarAmount(bean.getCarAmount() - 1);
notifyDataSetChanged();
}
});
}
}

View File

@ -0,0 +1,40 @@
package com.tenlionsoft.moduleshop.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.tengshisoft.moduleshop.R;
import com.tenlionsoft.moduleshop.beans.CustomCarBean;
import com.tenlionsoft.moduleshop.holder.GoodsCarHolder;
import java.util.List;
/**
* 购物车适配器
*/
public class GoodsCarAdapter extends BaseRecyclerAdapter<CustomCarBean, GoodsCarHolder> {
public GoodsCarAdapter(Context ctx, List<CustomCarBean> list) {
super(ctx, list);
}
@Override
public GoodsCarHolder createHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_goods_car, parent, false);
return new GoodsCarHolder(view);
}
@Override
public void bindHolder(GoodsCarHolder h, int i) {
CustomCarBean bean = mData.get(i);
h.mTvShopName.setText(bean.getShopName());
CarGoodsAdapter adapter = new CarGoodsAdapter(mContext, bean.getGoods());
h.mRlvGoods.setLayoutManager(new LinearLayoutManager(mContext));
h.mRlvGoods.setAdapter(adapter);
}
}

View File

@ -5,6 +5,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.tengshisoft.moduleshop.R;
import com.tenlionsoft.moduleshop.beans.ShopSortListBean;
@ -28,5 +31,11 @@ public class ShopSortAdapter extends BaseRecyclerAdapter<ShopSortListBean.SubLis
public void bindHolder(ShopSortHolder h, int i) {
ShopSortListBean.SubListBean bean = mData.get(i);
h.mTvName.setText(bean.getName());
Glide.with(mContext)
.load(BaseUrlApi.BASE_SHOP_IMG_URL + bean.getIcon())
.apply(new RequestOptions()
.placeholder(R.drawable.ic_goods_sort_default)
.error(R.drawable.ic_goods_sort_default))
.into(h.mIvIcon);
}
}

View File

@ -7,6 +7,10 @@ import android.view.ViewGroup;
import androidx.recyclerview.widget.GridLayoutManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.request.RequestOptions;
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
import com.sucstepsoft.cm_utils.core.widget.base.BaseRecyclerAdapter;
import com.tengshisoft.moduleshop.R;
import com.tenlionsoft.moduleshop.beans.ShopSortListBean;

View File

@ -0,0 +1,37 @@
package com.tenlionsoft.moduleshop.beans;
import java.util.List;
/**
* 自定义购物
*/
public class CustomCarBean {
private String shopName;
private String shopId;
private List<ShopGoodsDetailBean> goods;
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public List<ShopGoodsDetailBean> getGoods() {
return goods;
}
public void setGoods(List<ShopGoodsDetailBean> goods) {
this.goods = goods;
}
}

View File

@ -33,8 +33,18 @@ public class ShopGoodsDetailBean {
private String shopId;
private String shopName;
private int userEvaluate;
private int carAmount;
//自定义 购物车中数量与商品单价
private int carAmount;
private String goodsPrice;
public String getGoodsPrice() {
return goodsPrice;
}
public void setGoodsPrice(String goodsPrice) {
this.goodsPrice = goodsPrice;
}
public int getCarAmount() {
return carAmount;

View File

@ -0,0 +1,35 @@
package com.tenlionsoft.moduleshop.holder;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sucstepsoft.cm_utils.core.widget.views.AddOrDelView;
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
import com.tengshisoft.moduleshop.R;
/**
* 购物车中商品
*/
public class CarGoodsHolder extends RecyclerView.ViewHolder {
public ImageView mIvIcon;
public TypeFaceTextView mTvName;
public TypeFaceTextView mTvPrice;
public TypeFaceTextView mTvSales;
public TypeFaceTextView mTvEvaluate;
public TypeFaceTextView mTvFreight;
public AddOrDelView mAodView;
public CarGoodsHolder(@NonNull View itemView) {
super(itemView);
mIvIcon = itemView.findViewById(R.id.iv_goods_icon);
mTvName = itemView.findViewById(R.id.tv_goods_name);
mTvPrice = itemView.findViewById(R.id.tv_goods_price);
mTvSales = itemView.findViewById(R.id.tv_goods_sales);
mTvEvaluate = itemView.findViewById(R.id.tv_goods_evaluate);
mTvFreight = itemView.findViewById(R.id.tv_goods_freight);
mAodView = itemView.findViewById(R.id.aod_control);
}
}

View File

@ -0,0 +1,24 @@
package com.tenlionsoft.moduleshop.holder;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
import com.tengshisoft.moduleshop.R;
/**
* 购物车列表
*/
public class GoodsCarHolder extends RecyclerView.ViewHolder {
public TypeFaceTextView mTvShopName;
public RecyclerView mRlvGoods;
public GoodsCarHolder(@NonNull View itemView) {
super(itemView);
mTvShopName = itemView.findViewById(R.id.tv_shop_name);
mRlvGoods = itemView.findViewById(R.id.rlv_goods);
}
}

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="8dp">
<ImageView
android:id="@+id/iv_goods_icon"
android:layout_width="90dp"
android:layout_height="90dp"
android:scaleType="fitXY"
tools:src="@drawable/ic_img_default" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/iv_goods_icon"
android:orientation="vertical"
android:paddingLeft="10dp">
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_goods_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
tools:text="Redmi Note 12 %G 120Hz OLED屏幕 晓龙4移动平台 5000mAh 长续航 6GbOLED屏幕 晓龙4移动平台 5000mAh 长续航 6GbOLED屏幕 晓龙4移动平台 5000mAh 长续航 6Gb" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_goods_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColor="@color/app_title_9f_no"
android:textSize="16sp"
tools:text="¥1299" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_goods_sales"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:background="@drawable/shp_rectangle_gray"
android:paddingLeft="8dp"
android:paddingTop="2dp"
android:paddingRight="8dp"
android:paddingBottom="2dp"
android:textColor="@color/app_title_9f_no"
android:textSize="10sp"
tools:text="销量" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_goods_evaluate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/tv_goods_sales"
android:background="@drawable/shp_rectangle_gray"
android:paddingLeft="8dp"
android:paddingTop="2dp"
android:paddingRight="8dp"
android:visibility="gone"
android:paddingBottom="2dp"
android:textColor="@color/app_title_9f_no"
android:textSize="10sp"
tools:text="评分" />
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_goods_freight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_toRightOf="@id/tv_goods_evaluate"
android:background="@drawable/shp_rectangle_gray"
android:paddingLeft="8dp"
android:paddingTop="2dp"
android:paddingRight="8dp"
android:paddingBottom="2dp"
android:textColor="@color/app_title_9f_no"
android:textSize="10sp"
tools:text="包邮" />
<com.sucstepsoft.cm_utils.core.widget.views.AddOrDelView
android:id="@+id/aod_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
android:id="@+id/tv_shop_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
tools:text="商店名称" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rlv_goods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</LinearLayout>

View File

@ -40,6 +40,8 @@
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="1dp">
<RelativeLayout