From 860fd597daedfdd0e1ebb26a514a3bff3b958a07 Mon Sep 17 00:00:00 2001 From: itgaojian163 Date: Thu, 22 Dec 2022 16:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cm_utils/constant/PathConfig.java | 1 + .../cm_utils/utils/UserLgUtils.java | 10 ++- .../main/res/drawable/sel_btn_red_grad.xml | 7 ++ .../main/res/drawable/shape_circle_red.xml | 6 ++ .../main/res/drawable/shp_red_deep_grad.xml | 9 ++ .../src/main/res/drawable/shp_red_grad.xml | 9 ++ moduleshop/src/main/AndroidManifest.xml | 11 ++- .../activitys/GoodsDetailActivity.java | 88 ++++++++++++++++++- .../moduleshop/activitys/ShopCarActivity.java | 58 ++++++++++++ .../moduleshop/beans/GoodsStandardBean.java | 6 +- .../moduleshop/beans/ShopGoodsDetailBean.java | 10 +++ .../main/res/layout/activity_goods_detail.xml | 68 ++++++++++---- .../src/main/res/layout/activity_shop_car.xml | 14 +++ .../main/res/layout/item_second_shop_sort.xml | 3 + 14 files changed, 273 insertions(+), 27 deletions(-) create mode 100755 cm_utils/src/main/res/drawable/sel_btn_red_grad.xml create mode 100755 cm_utils/src/main/res/drawable/shape_circle_red.xml create mode 100644 cm_utils/src/main/res/drawable/shp_red_deep_grad.xml create mode 100644 cm_utils/src/main/res/drawable/shp_red_grad.xml create mode 100644 moduleshop/src/main/java/com/tenlionsoft/moduleshop/activitys/ShopCarActivity.java create mode 100644 moduleshop/src/main/res/layout/activity_shop_car.xml diff --git a/cm_utils/src/main/java/com/sucstepsoft/cm_utils/constant/PathConfig.java b/cm_utils/src/main/java/com/sucstepsoft/cm_utils/constant/PathConfig.java index dfe0faa..2954ab7 100755 --- a/cm_utils/src/main/java/com/sucstepsoft/cm_utils/constant/PathConfig.java +++ b/cm_utils/src/main/java/com/sucstepsoft/cm_utils/constant/PathConfig.java @@ -264,4 +264,5 @@ public class PathConfig { public static final String PATH_MODULE_SHOP_FRAGMENT_SORT_LIST = "/moduleshop/fragment/shopSortList";//商城分类 public static final String PATH_MODULE_SHOP_ACTIVITY_GOODS_LIST = "/moduleshop/activity/shopGoodsList";//商品列表 public static final String PATH_MODULE_SHOP_ACTIVITY_GOODS_DETAIL = "/moduleshop/activity/shopGoodsDetail";//商品详情 + public static final String PATH_MODULE_SHOP_ACTIVITY_SHOP_CAR = "/moduleshop/activity/shopGoodsCar";//购物车 } diff --git a/cm_utils/src/main/java/com/sucstepsoft/cm_utils/utils/UserLgUtils.java b/cm_utils/src/main/java/com/sucstepsoft/cm_utils/utils/UserLgUtils.java index 0fc75e3..c227b85 100755 --- a/cm_utils/src/main/java/com/sucstepsoft/cm_utils/utils/UserLgUtils.java +++ b/cm_utils/src/main/java/com/sucstepsoft/cm_utils/utils/UserLgUtils.java @@ -1,7 +1,5 @@ package com.sucstepsoft.cm_utils.utils; -import com.nightonke.boommenu.Animation.BoomEnum; - public class UserLgUtils { // // private String id; @@ -195,4 +193,12 @@ public class UserLgUtils { public static void setCityLevel(int level) { SPUtils.getInstance(SP_USER_INFO).put("cityLevel", level); } + + public static String getShopCar() { + return SPUtils.getInstance(SP_USER_INFO).getString("shopCar"); + } + + public static void setShopCar(String data) { + SPUtils.getInstance(SP_USER_INFO).put("shopCar", data); + } } diff --git a/cm_utils/src/main/res/drawable/sel_btn_red_grad.xml b/cm_utils/src/main/res/drawable/sel_btn_red_grad.xml new file mode 100755 index 0000000..b4d0a3c --- /dev/null +++ b/cm_utils/src/main/res/drawable/sel_btn_red_grad.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/cm_utils/src/main/res/drawable/shape_circle_red.xml b/cm_utils/src/main/res/drawable/shape_circle_red.xml new file mode 100755 index 0000000..bb62eec --- /dev/null +++ b/cm_utils/src/main/res/drawable/shape_circle_red.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/cm_utils/src/main/res/drawable/shp_red_deep_grad.xml b/cm_utils/src/main/res/drawable/shp_red_deep_grad.xml new file mode 100644 index 0000000..bd25198 --- /dev/null +++ b/cm_utils/src/main/res/drawable/shp_red_deep_grad.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/cm_utils/src/main/res/drawable/shp_red_grad.xml b/cm_utils/src/main/res/drawable/shp_red_grad.xml new file mode 100644 index 0000000..2e97e78 --- /dev/null +++ b/cm_utils/src/main/res/drawable/shp_red_grad.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/moduleshop/src/main/AndroidManifest.xml b/moduleshop/src/main/AndroidManifest.xml index d062e10..9eb6b15 100644 --- a/moduleshop/src/main/AndroidManifest.xml +++ b/moduleshop/src/main/AndroidManifest.xml @@ -4,14 +4,21 @@ + + + mBannerList = new ArrayList<>(); private BaseBannerImageAdapter mBannerImageAdapter; private ShopGoodsDetailBean mDetailBean; private GoodsStandardAdapter mStandardAdapter; private List mStandardBeanList; + private List mCarDatas = new ArrayList<>(); @Override protected int setLayoutId() { @@ -127,10 +143,66 @@ public class GoodsDetailActivity extends BaseActivity { finish(); } mStandardAdapter.addOnItemPosClickListener((b, p) -> { - mTvGoodsPrice.setText("¥ " + b.getGoodsItemUnitPrice()); + setPrice(b.getGoodsItemUnitPrice()); mTvGoodsStock.setText("库存:" + b.getGoodsItemTotal()); mStandardAdapter.setSelPos(p); }); + mTvAddCar.setOnClickListener(v -> addToCar(mDetailBean)); + + } + + private void parserShopCar() { + try { + String shopCar = UserLgUtils.getShopCar(); + if (TextUtils.isEmpty(shopCar)) { + mTvCarAmount.setVisibility(View.GONE); + } else { + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + mCarDatas = gson.fromJson(shopCar, type); + mTvCarAmount.setVisibility(View.VISIBLE); + addToCar(null); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addToCar(ShopGoodsDetailBean bean) { + mTvCarAmount.setVisibility(View.VISIBLE); + if (bean != null) { + int pos = -1; + for (int i = 0; i < mCarDatas.size(); i++) { + if (bean.getGoodsId().equals(mCarDatas.get(i).getGoodsId())) { + pos = i; + break; + } + } + if (pos != -1) { + LogUtils.e(pos + "====" + mCarDatas.get(pos).getCarAmount()); + mCarDatas.get(pos).setCarAmount(mCarDatas.get(pos).getCarAmount() + 1); + } else { + bean.setCarAmount(1); + mCarDatas.add(bean); + } + } + int num = 0; + for (int i = 0; i < mCarDatas.size(); i++) { + int carAmount = mCarDatas.get(i).getCarAmount(); + LogUtils.e(carAmount + "=============="); + num += carAmount; + } + LogUtils.e(num + "==数量=="); + if (num > 99) { + mTvCarAmount.setText("99+"); + } else { + mTvCarAmount.setText(num + ""); + } + Gson gson = new Gson(); + String s = gson.toJson(mCarDatas); + UserLgUtils.setShopCar(s); } private void initVideoView() { @@ -217,9 +289,21 @@ public class GoodsDetailActivity extends BaseActivity { @Override protected void onResume() { super.onResume(); + mCarDatas.clear(); + parserShopCar(); mVvVideo.pause(); } + /** + * 设置商品价格 + */ + private void setPrice(double price) { + SpannableString spannableString = new SpannableString("¥" + price); + RelativeSizeSpan relativeSizeSpan = new RelativeSizeSpan(0.6f); + spannableString.setSpan(relativeSizeSpan, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + mTvGoodsPrice.setText(spannableString); + } + /** * 初始化webview */ @@ -340,7 +424,7 @@ public class GoodsDetailActivity extends BaseActivity { private void doSetGoodsStandard(List list) { refreshView(STATE_LOAD_SUCCESS); GoodsStandardBean b = list.get(0); - mTvGoodsPrice.setText("¥ " + b.getGoodsItemUnitPrice()); + setPrice(b.getGoodsItemUnitPrice()); mTvGoodsStock.setText("库存:" + b.getGoodsItemTotal()); mTvGoodsSales.setText("销量:" + mDetailBean.getGoodsSalesVolume()); mTvGoodsEvaluate.setText("评分:" + mDetailBean.getUserEvaluate()); diff --git a/moduleshop/src/main/java/com/tenlionsoft/moduleshop/activitys/ShopCarActivity.java b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/activitys/ShopCarActivity.java new file mode 100644 index 0000000..9f0907d --- /dev/null +++ b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/activitys/ShopCarActivity.java @@ -0,0 +1,58 @@ +package com.tenlionsoft.moduleshop.activitys; + +import android.text.TextUtils; + +import com.alibaba.android.arouter.facade.annotation.Route; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +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.tenlionsoft.moduleshop.beans.ShopGoodsDetailBean; + +import java.lang.reflect.Type; +import java.util.List; + +import butterknife.ButterKnife; + +/** + * 购物车 + */ +@Route(path = PathConfig.PATH_MODULE_SHOP_ACTIVITY_SHOP_CAR) +public class ShopCarActivity extends BaseActivity { + + + private List mCarDatas; + + @Override + protected int setLayoutId() { + return R.layout.activity_shop_car; + } + + @Override + public void initData() { + ButterKnife.bind(this); + mTvBaseTitle.setText("购物车"); + parserShopCar(); + } + + + private void parserShopCar() { + try { + String shopCar = UserLgUtils.getShopCar(); + if (!TextUtils.isEmpty(shopCar)) { + Gson gson = new Gson(); + Type type = new TypeToken>() { + }.getType(); + mCarDatas = gson.fromJson(shopCar, type); + refreshView(STATE_LOAD_SUCCESS); + } else { + refreshView(STATE_LOAD_EMPTY); + mTvErrorHint.setText("购物车暂无数据"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/GoodsStandardBean.java b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/GoodsStandardBean.java index 7539616..930126b 100644 --- a/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/GoodsStandardBean.java +++ b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/GoodsStandardBean.java @@ -14,7 +14,7 @@ public class GoodsStandardBean { private String goodsItemStatus; private int goodsItemTotal; private String goodsItemUnit; - private int goodsItemUnitPrice; + private double goodsItemUnitPrice; private int goodsItemWeight; private int isDelete; private String modifier; @@ -132,11 +132,11 @@ public class GoodsStandardBean { this.goodsItemUnit = goodsItemUnit; } - public int getGoodsItemUnitPrice() { + public double getGoodsItemUnitPrice() { return goodsItemUnitPrice; } - public void setGoodsItemUnitPrice(int goodsItemUnitPrice) { + public void setGoodsItemUnitPrice(double goodsItemUnitPrice) { this.goodsItemUnitPrice = goodsItemUnitPrice; } diff --git a/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/ShopGoodsDetailBean.java b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/ShopGoodsDetailBean.java index 10bd95e..2cf2b54 100644 --- a/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/ShopGoodsDetailBean.java +++ b/moduleshop/src/main/java/com/tenlionsoft/moduleshop/beans/ShopGoodsDetailBean.java @@ -33,6 +33,16 @@ public class ShopGoodsDetailBean { private String shopId; private String shopName; private int userEvaluate; + private int carAmount; + + + public int getCarAmount() { + return carAmount; + } + + public void setCarAmount(int carAmount) { + this.carAmount = carAmount; + } public String getCategoryId() { return categoryId; diff --git a/moduleshop/src/main/res/layout/activity_goods_detail.xml b/moduleshop/src/main/res/layout/activity_goods_detail.xml index 6733ad9..63e3265 100644 --- a/moduleshop/src/main/res/layout/activity_goods_detail.xml +++ b/moduleshop/src/main/res/layout/activity_goods_detail.xml @@ -42,18 +42,11 @@ android:orientation="vertical" android:padding="10dp"> - + android:layout_alignParentBottom="true" + android:paddingLeft="10dp" + android:paddingRight="10dp"> - + + - + android:layout_centerVertical="true"> + + + + + - + android:id="@+id/tv_car_amount" + android:layout_width="20dp" + android:layout_height="20dp" + android:layout_alignParentRight="true" + android:background="@drawable/shape_circle_red" + android:gravity="center" + android:text="99" + android:textColor="@color/white" + android:textSize="12sp" /> + + + + + + + \ No newline at end of file diff --git a/moduleshop/src/main/res/layout/item_second_shop_sort.xml b/moduleshop/src/main/res/layout/item_second_shop_sort.xml index 1def0cf..c16107d 100644 --- a/moduleshop/src/main/res/layout/item_second_shop_sort.xml +++ b/moduleshop/src/main/res/layout/item_second_shop_sort.xml @@ -17,6 +17,8 @@ android:id="@+id/tv_second" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp" android:textColor="@color/black" android:textSize="15sp" android:textStyle="bold" @@ -27,6 +29,7 @@ android:layout_height="12dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" + android:layout_marginRight="5dp" android:src="@drawable/ic_arrow_right" />