购物车
This commit is contained in:
parent
73c5c483db
commit
860fd597da
@ -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";//购物车
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
7
cm_utils/src/main/res/drawable/sel_btn_red_grad.xml
Executable file
7
cm_utils/src/main/res/drawable/sel_btn_red_grad.xml
Executable file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/shp_red_grad" android:state_enabled="false" />
|
||||
<item android:drawable="@drawable/shp_red_grad" android:state_pressed="false" />
|
||||
<item android:drawable="@drawable/shp_red_deep_grad" android:state_pressed="true" />
|
||||
<item android:drawable="@drawable/shp_red_deep_grad" android:state_enabled="true" />
|
||||
</selector>
|
6
cm_utils/src/main/res/drawable/shape_circle_red.xml
Executable file
6
cm_utils/src/main/res/drawable/shape_circle_red.xml
Executable file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid android:color="@color/app_title_9f_no" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
9
cm_utils/src/main/res/drawable/shp_red_deep_grad.xml
Normal file
9
cm_utils/src/main/res/drawable/shp_red_deep_grad.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="45"
|
||||
android:endColor="#ff9f1512"
|
||||
android:startColor="#FF0900" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
9
cm_utils/src/main/res/drawable/shp_red_grad.xml
Normal file
9
cm_utils/src/main/res/drawable/shp_red_grad.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="45"
|
||||
android:endColor="#ff9f1512"
|
||||
android:startColor="#EF6C67" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
@ -4,14 +4,21 @@
|
||||
|
||||
<application>
|
||||
<activity
|
||||
android:name="com.tenlionsoft.moduleshop.activitys.GoodsListActivity"
|
||||
android:name=".ShopCarActivity"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.tenlionsoft.moduleshop.activitys.GoodsDetailActivity"
|
||||
android:name=".GoodsListActivity"
|
||||
android:exported="false">
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".GoodsDetailActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout"
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait"
|
||||
|
@ -3,7 +3,10 @@ package com.tenlionsoft.moduleshop.activitys;
|
||||
import android.net.http.SslError;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.view.View;
|
||||
import android.webkit.HttpAuthHandler;
|
||||
import android.webkit.JsResult;
|
||||
@ -14,12 +17,15 @@ import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.beloo.widget.chipslayoutmanager.ChipsLayoutManager;
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
import com.sucstepsoft.cm_utils.constant.PathConfig;
|
||||
import com.sucstepsoft.cm_utils.core.beans.BaseImageBean;
|
||||
@ -30,6 +36,8 @@ import com.sucstepsoft.cm_utils.core.widget.base.BaseBannerImageAdapter;
|
||||
import com.sucstepsoft.cm_utils.core.widget.views.NestedScrollWebView;
|
||||
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
|
||||
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
|
||||
import com.sucstepsoft.cm_utils.utils.LogUtils;
|
||||
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
|
||||
import com.sucstepsoft.cm_utils.utils.toast.ToastUtils;
|
||||
import com.tengshisoft.moduleijkplayer.controller.CompleteView;
|
||||
import com.tengshisoft.moduleijkplayer.controller.ErrorView;
|
||||
@ -50,6 +58,7 @@ import com.tenlionsoft.moduleshop.net.ShopApi;
|
||||
import com.youth.banner.Banner;
|
||||
import com.youth.banner.transformer.ScaleInTransformer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -91,12 +100,19 @@ public class GoodsDetailActivity extends BaseActivity {
|
||||
VideoView mVvVideo;//介绍视频
|
||||
@BindView(R2.id.nswv_web)
|
||||
NestedScrollWebView mNswvWeb;//详情
|
||||
@BindView(R2.id.tv_add_car)
|
||||
TypeFaceTextView mTvAddCar;//添加购物车
|
||||
@BindView(R2.id.ll_car)
|
||||
RelativeLayout mLlCar;//购物车
|
||||
@BindView(R2.id.tv_car_amount)
|
||||
TypeFaceTextView mTvCarAmount;//购物车数量
|
||||
private String mId;
|
||||
private List<BaseImageBean> mBannerList = new ArrayList<>();
|
||||
private BaseBannerImageAdapter mBannerImageAdapter;
|
||||
private ShopGoodsDetailBean mDetailBean;
|
||||
private GoodsStandardAdapter mStandardAdapter;
|
||||
private List<GoodsStandardBean> mStandardBeanList;
|
||||
private List<ShopGoodsDetailBean> 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<List<ShopGoodsDetailBean>>() {
|
||||
}.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<GoodsStandardBean> 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());
|
||||
|
@ -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<ShopGoodsDetailBean> 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<List<ShopGoodsDetailBean>>() {
|
||||
}.getType();
|
||||
mCarDatas = gson.fromJson(shopCar, type);
|
||||
refreshView(STATE_LOAD_SUCCESS);
|
||||
} else {
|
||||
refreshView(STATE_LOAD_EMPTY);
|
||||
mTvErrorHint.setText("购物车暂无数据");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -42,18 +42,11 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<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:textColor="@color/app_title_9f_no"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="¥ 37666" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
|
||||
@ -232,25 +225,64 @@
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:layout_alignParentBottom="true">
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp">
|
||||
|
||||
<LinearLayout
|
||||
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
|
||||
android:id="@+id/tv_goods_price"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:textColor="@color/app_title_9f_no"
|
||||
android:textSize="25sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="¥ 37666" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/ll_car"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_toLeftOf="@id/tv_add_car"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_car"
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_car"
|
||||
android:layout_width="25dp"
|
||||
android:layout_height="25dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:src="@drawable/ic_shop_car_icon" />
|
||||
|
||||
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="购物车" />
|
||||
</LinearLayout>
|
||||
android:layout_below="@id/iv_car"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="购物车"
|
||||
android:textSize="12sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
|
||||
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" />
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView
|
||||
android:id="@+id/tv_add_car"
|
||||
@ -258,7 +290,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="@drawable/shp_status_red"
|
||||
android:background="@drawable/sel_btn_red_grad"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingLeft="10dp"
|
||||
|
14
moduleshop/src/main/res/layout/activity_shop_car.xml
Normal file
14
moduleshop/src/main/res/layout/activity_shop_car.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?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="match_parent"
|
||||
android:background="@color/gray_bg"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.tenlionsoft.moduleshop.activitys.ShopCarActivity">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rlv_car"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
@ -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" />
|
||||
</RelativeLayout>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user