Compare commits

...

7 Commits

@ -1,2 +0,0 @@
include ':app'
rootProject.name='OrangeSale_05'

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="http://maven.aliyun.com/nexus/content/repositories/jcenter" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven2" />
<option name="name" value="maven2" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -0,0 +1,50 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.llw.cart"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
//Gson
implementation 'com.google.code.gson:gson:2.8.6'
//RecyclerView
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//RecyclerView
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.47'
//
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-14'
//使Header
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14'
}

@ -0,0 +1,27 @@
package com.llw.cart;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.llw.cart", appContext.getPackageName());
}
}

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.orangesale_05">
xmlns:tools="http://schemas.android.com/tools"
package="com.llw.cart">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
@ -8,7 +12,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -16,10 +21,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activity.RegisterActivity"></activity>
<activity android:name=".activity.UserActivity" />
<activity android:name=".activity.CategoryActivity" />
<activity android:name=".activity.IndexActivity" />
</application>
</manifest>

@ -0,0 +1,389 @@
package com.llw.cart;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.llw.cart.adapter.StoreAdapter;
import com.llw.cart.bean.CarResponse;
import com.llw.cart.util.Constant;
import com.llw.cart.util.GoodsCallback;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
*
* @author llw
*/
public class MainActivity extends AppCompatActivity implements GoodsCallback, View.OnClickListener {
public static final String TAG = "MainActivity";
private RecyclerView rvStore;
private StoreAdapter storeAdapter;
private List<CarResponse.OrderDataBean> mList = new ArrayList<>();
private TextView tvEdit;//编辑
private ImageView ivCheckedAll;//全选
private TextView tvTotal;//合计价格
private TextView tvSettlement;//结算
private LinearLayout layEdit;//编辑底部布局
private TextView tvShareGoods;//分享商品
private TextView tvCollectGoods;//收藏商品
private TextView tvDeleteGoods;//删除商品
private boolean isEdit = false;//是否编辑
private boolean isAllChecked = false;//是否全选
private List<Integer> shopIdList = new ArrayList<>();//店铺列表
private double totalPrice = 0.00;//商品总价
private int totalCount = 0;//商品总数量
private AlertDialog dialog;//弹窗
private boolean isHaveGoods = false;//购物车是否有商品
private SmartRefreshLayout refresh;//刷新布局
private LinearLayout layEmpty;//空布局
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
/**
*
*/
private void initView() {
//设置亮色状态栏模式 systemUiVisibility在Android11中弃用了可以尝试一下。
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
rvStore = findViewById(R.id.rv_store);
tvEdit = findViewById(R.id.tv_edit);
ivCheckedAll = findViewById(R.id.iv_checked_all);
tvTotal = findViewById(R.id.tv_total);
tvSettlement = findViewById(R.id.tv_settlement);
layEdit = findViewById(R.id.lay_edit);
tvShareGoods = findViewById(R.id.tv_share_goods);
tvCollectGoods = findViewById(R.id.tv_collect_goods);
tvDeleteGoods = findViewById(R.id.tv_delete_goods);
refresh = findViewById(R.id.refresh);
layEmpty = findViewById(R.id.lay_empty);
//禁用下拉刷新和上拉加载更多
refresh.setEnableRefresh(false);
refresh.setEnableLoadMore(false);
//下拉刷新监听
refresh.setOnRefreshListener(refreshLayout -> initView());
tvEdit.setOnClickListener(this);
ivCheckedAll.setOnClickListener(this);
tvSettlement.setOnClickListener(this);
tvShareGoods.setOnClickListener(this);
tvCollectGoods.setOnClickListener(this);
tvDeleteGoods.setOnClickListener(this);
CarResponse carResponse = new Gson().fromJson(Constant.CAR_JSON, CarResponse.class);
mList.addAll(carResponse.getOrderData());
storeAdapter = new StoreAdapter(R.layout.item_store, mList, this);
rvStore.setLayoutManager(new LinearLayoutManager(this));
rvStore.setAdapter(storeAdapter);
//店铺点击
storeAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
CarResponse.OrderDataBean storeBean = mList.get(position);
if (view.getId() == R.id.iv_checked_store) {
storeBean.setChecked(!storeBean.isChecked());
storeAdapter.notifyDataSetChanged();
//传递选中店铺的id
if (storeBean.isChecked()) {
//全选商品
storeAdapter.controlGoods(storeBean.getShopId(), true);
//添加到列表中
if (!shopIdList.contains(storeBean.getShopId())) {
//如果列表中没有这个店铺Id且当前店铺为选中状态
shopIdList.add(storeBean.getShopId());
}
} else {
//清除全选商品
storeAdapter.controlGoods(storeBean.getShopId(), false);
//从列表中清除
if (shopIdList.contains(storeBean.getShopId())) {
shopIdList.remove((Integer) storeBean.getShopId());
}
}
//控制页面全选
controlAllChecked();
}
}
});
//有商品
isHaveGoods = true;
//下拉加载数据完成后,关闭下拉刷新动画
refresh.finishRefresh();
//隐藏布局
layEmpty.setVisibility(View.GONE);
}
/**
*
*/
private void controlAllChecked() {
if (shopIdList.size() == mList.size() && mList.size() != 0) {
//全选
ivCheckedAll.setImageDrawable(getDrawable(R.drawable.ic_checked));
isAllChecked = true;
} else {
//不全选
ivCheckedAll.setImageDrawable(getDrawable(R.drawable.ic_check));
isAllChecked = false;
}
//计算价格
calculationPrice();
}
/**
*
*
* @param shopId id
*/
@Override
public void checkedStore(int shopId, boolean state) {
for (CarResponse.OrderDataBean bean : mList) {
//遍历
if (shopId == bean.getShopId()) {
bean.setChecked(state);
storeAdapter.notifyDataSetChanged();
//记录选中店铺的shopid,添加到一个列表中。
if (!shopIdList.contains(bean.getShopId()) && state) {
//如果列表中没有这个店铺Id且当前店铺为选中状态
shopIdList.add(bean.getShopId());
} else {
if (shopIdList.contains(bean.getShopId())) {
//通过list.indexOf获取属性的在列表中的下标不过强转Integer更简洁
shopIdList.remove((Integer) bean.getShopId());
}
}
}
}
//控制页面全选
controlAllChecked();
}
/**
*
*/
@Override
public void calculationPrice() {
//每次计算之前先置零
totalPrice = 0.00;
totalCount = 0;
//循环购物车中的店铺列表
for (int i = 0; i < mList.size(); i++) {
CarResponse.OrderDataBean orderDataBean = mList.get(i);
//循环店铺中的商品列表
for (int j = 0; j < orderDataBean.getCartlist().size(); j++) {
CarResponse.OrderDataBean.CartlistBean cartlistBean = orderDataBean.getCartlist().get(j);
//当有选中商品时计算数量和价格
if (cartlistBean.isChecked()) {
totalCount++;
totalPrice += cartlistBean.getPrice() * cartlistBean.getCount();
}
}
}
tvTotal.setText("¥" + totalPrice);
tvSettlement.setText(totalCount == 0 ? "结算" : "结算(" + totalCount + ")");
}
/**
*
*
* @param v
*/
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_edit://编辑
if (!isHaveGoods) {
showMsg("当前购物车空空如也~");
return;
}
if (isEdit) {
tvEdit.setText("编辑");
layEdit.setVisibility(View.GONE);
isEdit = false;
} else {
tvEdit.setText("完成");
layEdit.setVisibility(View.VISIBLE);
isEdit = true;
}
break;
case R.id.iv_checked_all://全选
if (!isHaveGoods) {
showMsg("当前购物车空空如也~");
return;
}
if (isAllChecked) {
//取消全选
isSelectAllStore(false);
} else {
//全选
isSelectAllStore(true);
}
break;
case R.id.tv_settlement://结算
if (!isHaveGoods) {
showMsg("当前购物车空空如也~");
return;
}
if (totalCount == 0) {
showMsg("请选择要结算的商品");
return;
}
//弹窗
dialog = new AlertDialog.Builder(this)
.setMessage("总计:" + totalCount + "种商品," + totalPrice + "元")
.setPositiveButton("确定", (dialog, which) -> deleteGoods())
.setNegativeButton("取消", (dialog, which) -> dialog.dismiss())
.create();
dialog.show();
break;
case R.id.tv_delete_goods://删除
if (totalCount == 0) {
showMsg("请选择要删除的商品");
return;
}
//弹窗
dialog = new AlertDialog.Builder(this)
.setMessage("确定要删除所选商品吗?")
.setPositiveButton("确定", (dialog, which) -> deleteGoods())
.setNegativeButton("取消", (dialog, which) -> dialog.dismiss())
.create();
dialog.show();
break;
case R.id.tv_collect_goods://收藏
if (totalCount == 0) {
showMsg("请选择要收藏的商品");
return;
}
showMsg("收藏成功!");
break;
case R.id.tv_share_goods://分享
if (totalCount == 0) {
showMsg("请选择要分享的商品");
return;
}
showMsg("分享成功!");
break;
default:
break;
}
}
/**
*
*/
private void deleteGoods() {
//店铺列表
List<CarResponse.OrderDataBean> storeList = new ArrayList<>();
for (int i = 0; i < mList.size(); i++) {
CarResponse.OrderDataBean store = mList.get(i);
if (store.isChecked()) {
//店铺如果选择则添加到此列表中
storeList.add(store);
}
//商品列表
List<CarResponse.OrderDataBean.CartlistBean> goodsList = new ArrayList<>();
List<CarResponse.OrderDataBean.CartlistBean> goods = store.getCartlist();
//循环店铺中的商品列表
for (int j = 0; j < goods.size(); j++) {
CarResponse.OrderDataBean.CartlistBean cartlistBean = goods.get(j);
//当有选中商品时添加到此列表中
if (cartlistBean.isChecked()) {
goodsList.add(cartlistBean);
}
}
//删除商品
goods.removeAll(goodsList);
}
//删除店铺
mList.removeAll(storeList);
shopIdList.clear();//删除了选中商品,清空已选择的标识
controlAllChecked();//控制去全选
//改变界面UI
tvEdit.setText("编辑");
layEdit.setVisibility(View.GONE);
isEdit = false;
//刷新数据
storeAdapter.notifyDataSetChanged();
if (mList.size() <= 0) {
//无商品
isHaveGoods = false;
//启用下拉刷新
refresh.setEnableRefresh(true);
//显示空布局
layEmpty.setVisibility(View.VISIBLE);
}
}
/**
*
*
* @param state
*/
private void isSelectAllStore(boolean state) {
//修改背景
ivCheckedAll.setImageDrawable(getDrawable(state ? R.drawable.ic_checked : R.drawable.ic_check));
for (CarResponse.OrderDataBean orderDataBean : mList) {
//商品是否选中
storeAdapter.controlGoods(orderDataBean.getShopId(), state);
//店铺是否选中
checkedStore(orderDataBean.getShopId(), state);
}
isAllChecked = state;
}
/**
* Toast
*
* @param msg
*/
private void showMsg(String msg) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}

@ -0,0 +1,49 @@
package com.llw.cart.adapter;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llw.cart.bean.CarResponse;
import com.llw.cart.R;
import java.util.List;
/**
*
*
* @author llw
*/
public class GoodsAdapter extends BaseQuickAdapter<CarResponse.OrderDataBean.CartlistBean, BaseViewHolder> {
public GoodsAdapter(int layoutResId, @Nullable List<CarResponse.OrderDataBean.CartlistBean> data) {
super(layoutResId, data);
}
@Override
protected void convert(BaseViewHolder helper, CarResponse.OrderDataBean.CartlistBean item) {
helper.setText(R.id.tv_good_name, item.getProductName())
.setText(R.id.tv_good_color, item.getColor())
.setText(R.id.tv_good_size, item.getSize())
.setText(R.id.tv_goods_price, item.getPrice() + "")
.setText(R.id.tv_goods_num, item.getCount() + "");
ImageView goodImg = helper.getView(R.id.iv_goods);
Glide.with(mContext).load(item.getDefaultPic()).into(goodImg);
ImageView checkedGoods = helper.getView(R.id.iv_checked_goods);
//判断商品是否选中
if (item.isChecked()) {
checkedGoods.setImageDrawable(mContext.getDrawable(R.drawable.ic_checked));
} else {
checkedGoods.setImageDrawable(mContext.getDrawable(R.drawable.ic_check));
}
//添加点击事件
helper.addOnClickListener(R.id.iv_checked_goods)//选中商品
.addOnClickListener(R.id.tv_increase_goods_num)//增加商品
.addOnClickListener(R.id.tv_reduce_goods_num);//减少商品
}
}

@ -0,0 +1,155 @@
package com.llw.cart.adapter;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llw.cart.MainActivity;
import com.llw.cart.bean.CarResponse;
import com.llw.cart.R;
import com.llw.cart.util.GoodsCallback;
import java.util.List;
/**
*
*
* @author llw
*/
public class StoreAdapter extends BaseQuickAdapter<CarResponse.OrderDataBean, BaseViewHolder> {
private RecyclerView rvGood;
//商品回调
private GoodsCallback goodsCallback;
//店铺对象
private List<CarResponse.OrderDataBean> storeBean;
public StoreAdapter(int layoutResId, @Nullable List<CarResponse.OrderDataBean> data, GoodsCallback goodsCallback) {
super(layoutResId, data);
this.goodsCallback = goodsCallback;
storeBean = data;//赋值
}
@Override
protected void convert(BaseViewHolder helper, final CarResponse.OrderDataBean item) {
rvGood = helper.getView(R.id.rv_goods);
helper.setText(R.id.tv_store_name, item.getShopName());
ImageView checkedStore = helper.getView(R.id.iv_checked_store);
if (item.isChecked()) {
checkedStore.setImageDrawable(mContext.getDrawable(R.drawable.ic_checked));
} else {
checkedStore.setImageDrawable(mContext.getDrawable(R.drawable.ic_check));
}
//点击事件
helper.addOnClickListener(R.id.iv_checked_store);//选中店铺
final GoodsAdapter goodsAdapter = new GoodsAdapter(R.layout.item_good, item.getCartlist());
rvGood.setLayoutManager(new LinearLayoutManager(mContext));
rvGood.setAdapter(goodsAdapter);
//商品item中的点击事件
goodsAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
CarResponse.OrderDataBean.CartlistBean goodsBean = item.getCartlist().get(position);
switch (view.getId()) {
case R.id.iv_checked_goods://选中商品
//如果已选中则取消选中,未选中则选中
goodsBean.setChecked(!goodsBean.isChecked());
//刷新适配器
goodsAdapter.notifyDataSetChanged();
//控制店铺是否选中
controlStore(item);
//商品控制价格
goodsCallback.calculationPrice();
break;
case R.id.tv_increase_goods_num://增加商品数量
updateGoodsNum(goodsBean, goodsAdapter,true);
break;
case R.id.tv_reduce_goods_num://减少商品数量
updateGoodsNum(goodsBean, goodsAdapter,false);
break;
default:
break;
}
}
});
}
/**
*
* @param goodsBean
* @param goodsAdapter
* @param state true false
*/
private void updateGoodsNum(CarResponse.OrderDataBean.CartlistBean goodsBean, GoodsAdapter goodsAdapter,boolean state) {
//其实商品应该还有一个库存值或者其他的限定值我这里写一个假的库存值为10
int inventory = 10;
int count = goodsBean.getCount();
if(state){
if (count >= inventory){
Toast.makeText(mContext,"商品数量不可超过库存值~",Toast.LENGTH_SHORT).show();
return;
}
count++;
}else {
if (count <= 1){
Toast.makeText(mContext,"已是最低商品数量~",Toast.LENGTH_SHORT).show();
return;
}
count--;
}
goodsBean.setCount(count);//设置商品数量
//刷新适配器
goodsAdapter.notifyDataSetChanged();
//计算商品价格
goodsCallback.calculationPrice();
}
/**
*
*/
private void controlStore(CarResponse.OrderDataBean item) {
int num = 0;
for (CarResponse.OrderDataBean.CartlistBean bean : item.getCartlist()) {
if (bean.isChecked()) {
++num;
}
}
if (num == item.getCartlist().size()) {
//全选中 传递需要选中的店铺的id过去
goodsCallback.checkedStore(item.getShopId(), true);
} else {
goodsCallback.checkedStore(item.getShopId(), false);
}
}
/**
*
*/
public void controlGoods(int shopId, boolean state) {
//根据店铺id选中该店铺下所有商品
for (CarResponse.OrderDataBean orderDataBean : storeBean) {
//店铺id等于传递过来的店铺id 则选中该店铺下所有商品
if (orderDataBean.getShopId() == shopId) {
for (CarResponse.OrderDataBean.CartlistBean cartlistBean : orderDataBean.getCartlist()) {
cartlistBean.setChecked(state);
//刷新
notifyDataSetChanged();
}
}
}
}
}

@ -0,0 +1,196 @@
package com.llw.cart.bean;
import java.util.List;
/**
*
* @author llw
*/
public class CarResponse {
/**
* code : 200
* orderData : [{"shopId":1,"shopName":"京东自营","cartlist":[{"id":1,"shopId":1,"shopName":"京东自营","defaultPic":"https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg","productId":1,"productName":"三只松鼠_零食大礼包","color":"黑色","size":"18L","price":20,"count":1},{"id":2,"shopId":1,"shopName":"京东自营","defaultPic":"https://img14.360buyimg.com/n0/jfs/t2971/15/167732091/93002/204c1016/574d9d9aNe4e6fa7a.jpg","productId":2,"productName":"小米心跳手环","color":"白色","size":"20XXL","price":148,"count":1}]},{"shopId":2,"shopName":"海澜之家","cartlist":[{"id":1,"shopId":2,"shopName":"海澜之家","defaultPic":"https://img30.360buyimg.com/popWaterMark/jfs/t4075/83/1343091204/132469/9034cb9c/5873496bN68020ba8.jpg","productId":1,"productName":"短袖T恤男 2017夏季新品","color":"蓝色","size":"30X","price":181,"count":1}]},{"shopId":3,"shopName":"OPPO官方旗舰店","cartlist":[{"id":1,"shopId":3,"shopName":"OPPO官方旗舰店","defaultPic":"https://img10.360buyimg.com/cms/jfs/t6064/272/2163314583/157700/442d6477/593c1c49N7c63a7d9.jpg","productId":1,"productName":"OPPO R11 全网通","color":"蓝色","size":"30X","price":1999,"count":1},{"id":2,"shopId":3,"shopName":"OPPO官方旗舰店","defaultPic":"https://img14.360buyimg.com/n0/jfs/t3142/194/4953241722/254855/1651c2b1/585b9021Nf653e48a.jpg","productId":1,"productName":"OPPO R9 全网通","color":"蓝色","size":"30X","price":999,"count":1}]}]
*/
private int code;
private List<OrderDataBean> orderData;
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public List<OrderDataBean> getOrderData() {
return orderData;
}
public void setOrderData(List<OrderDataBean> orderData) {
this.orderData = orderData;
}
public static class OrderDataBean {
/**
* shopId : 1
* shopName :
* cartlist : [{"id":1,"shopId":1,"shopName":"京东自营","defaultPic":"https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg","productId":1,"productName":"三只松鼠_零食大礼包","color":"黑色","size":"18L","price":20,"count":1},{"id":2,"shopId":1,"shopName":"京东自营","defaultPic":"https://img14.360buyimg.com/n0/jfs/t2971/15/167732091/93002/204c1016/574d9d9aNe4e6fa7a.jpg","productId":2,"productName":"小米心跳手环","color":"白色","size":"20XXL","price":148,"count":1}]
*/
private int shopId;
private String shopName;
private List<CartlistBean> cartlist;
private boolean isChecked;//店铺是否选中
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public List<CartlistBean> getCartlist() {
return cartlist;
}
public void setCartlist(List<CartlistBean> cartlist) {
this.cartlist = cartlist;
}
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
public static class CartlistBean {
/**
* id : 1
* shopId : 1
* shopName :
* defaultPic : https://img30.360buyimg.com/popWareDetail/jfs/t3208/194/7616404169/244198/369625db/58b7d093N03520fb7.jpg
* productId : 1
* productName : _
* color :
* size : 18L
* price : 20
* count : 1
*/
private int id;
private int shopId;
private String shopName;
private String defaultPic;
private int productId;
private String productName;
private String color;
private String size;
private int price;
private int count;
private boolean isChecked;//商品是否选中
public boolean isChecked() {
return isChecked;
}
public void setChecked(boolean checked) {
isChecked = checked;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getShopId() {
return shopId;
}
public void setShopId(int shopId) {
this.shopId = shopId;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getDefaultPic() {
return defaultPic;
}
public void setDefaultPic(String defaultPic) {
this.defaultPic = defaultPic;
}
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
}
}

@ -0,0 +1,95 @@
package com.llw.cart.util;
/**
*
* @author llw
*/
public class Constant {
public static final String CAR_JSON = "{ \"code\" : 200 ,\n" +
" \"orderData\" : [\n" +
" {\n" +
"\n" +
" \"shopId\": 1,\n" +
" \"shopName\":\"水果拼盘\",\n" +
" \"cartlist\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"shopId\": 1,\n" +
" \"shopName\": \"水果拼盘\",\n" +
" \"defaultPic\": \"https://tse1-mm.cn.bing.net/th/id/OIP-C.vJftgCb8g6v_gSHsD5HGNgHaE8?w=280&h=187&c=7&r=0&o=5&pid=1.7\",\n" +
" \"productId\": 1,\n" +
" \"productName\": \"优质新鲜水果\",\n" +
" \"color\": \"\",\n" +
" \"size\": \"\",\n" +
" \"price\": 25,\n" +
" \"count\":1\n" +
" },\n" +
" {\n" +
" \"id\": 2,\n" +
" \"shopId\": 1,\n" +
" \"shopName\": \"\",\n" +
" \"defaultPic\": \"https://tse4-mm.cn.bing.net/th/id/OIP-C.L32QENiAMoSmmqLf1Ks2BgHaFS?w=288&h=206&c=7&r=0&o=5&pid=1.7\",\n" +
" \"productId\": 2,\n" +
" \"productName\": \"花彩拼盘\",\n" +
" \"color\": \"\",\n" +
" \"size\": \"\",\n" +
" \"price\": 16,\n" +
" \"count\": 1\n" +
" }\n" +
" ]\n" +
" }\n" +
" ,\n" +
" {\n" +
" \"shopId\": 2,\n" +
" \"shopName\":\"水果奶茶\",\n" +
" \"cartlist\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"shopId\": 2,\n" +
" \"shopName\": \"水果奶茶\",\n" +
" \"defaultPic\": \"https://tse4-mm.cn.bing.net/th/id/OIP-C.THBnn4_4YiWfbtKTlzdZawHaLG?w=199&h=298&c=7&r=0&o=5&pid=1.7\",\n" +
" \"productId\": 1,\n" +
" \"productName\": \"青柠芒果\",\n" +
" \"color\": \"\",\n" +
" \"size\": \"\",\n" +
" \"price\": 15,\n" +
" \"count\":1\n" +
" }\n" +
" ]\n" +
" }\n" +
" ,\n" +
" {\n" +
" \"shopId\": 3,\n" +
" \"shopName\":\"水果蛋糕\",\n" +
" \"cartlist\": [\n" +
" {\n" +
" \"id\": 1,\n" +
" \"shopId\": 3,\n" +
" \"shopName\": \"水果蛋糕\",\n" +
" \"defaultPic\": \"https://tse1-mm.cn.bing.net/th/id/OIP-C.-MylYp2cdCyNM5ijjLQqSwHaHa?w=192&h=191&c=7&r=0&o=5&pid=1.7\",\n" +
" \"productId\": 1,\n" +
" \"productName\": \"多彩水果拼盘蛋糕\",\n" +
" \"color\": \"\",\n" +
" \"size\": \"\",\n" +
" \"price\": 50,\n" +
" \"count\":1\n" +
" },\n" +
" {\n" +
" \"id\": 2,\n" +
" \"shopId\": 3,\n" +
" \"shopName\": \"水果蛋糕\",\n" +
" \"defaultPic\": \"https://tse1-mm.cn.bing.net/th/id/OIP-C.GFSAz_9r7WIXWpGCo72K3AHaGv?w=218&h=199&c=7&r=0&o=5&pid=1.7\",\n" +
" \"productId\": 1,\n" +
" \"productName\": \"心动情人草莓蛋糕\",\n" +
" \"color\": \"\",\n" +
" \"size\": \"\",\n" +
" \"price\": 68,\n" +
" \"count\":1\n" +
" }\n" +
" ]\n" +
" }\n" +
"\n" +
" ]\n" +
"}";
}

@ -0,0 +1,21 @@
package com.llw.cart.util;
/**
*
* @author llw
*/
public interface GoodsCallback {
/**
*
* @param shopId id
* @param state
*/
void checkedStore(int shopId,boolean state);
/**
*
*/
void calculationPrice();
}

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#000"
android:width="0.5dp"/>
</shape>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#000"
android:width="0.5dp"/>
<corners android:topRightRadius="4dp"
android:bottomRightRadius="4dp" />
</shape>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#000"
android:width="0.5dp"/>
<corners android:topLeftRadius="4dp"
android:bottomLeftRadius="4dp" />
</shape>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="20dp"/>
<gradient
android:startColor="#FF5C13"
android:endColor="#FC7D0B"
android:angle="90" />
</shape>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFF"/>
<corners android:radius="8dp"/>
</shape>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M12,22.5c-5.79,0 -10.5,-4.71 -10.5,-10.5S6.21,1.5 12,1.5 22.5,6.21 22.5,12 17.79,22.5 12,22.5zM12,3c-4.963,0 -9,4.037 -9,9s4.037,9 9,9 9,-4.037 9,-9S16.963,3 12,3z"
android:fillColor="#a9b7b7"/>
</vector>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#eb4f38"
android:pathData="M12,1.546c-5.764,0 -10.454,4.69 -10.454,10.454 0,5.765 4.689,10.454 10.454,10.454S22.454,17.765 22.454,12C22.454,6.236 17.765,1.546 12,1.546zM17.044,10.276 L11.039,16.346c-0.001,0.001 -0.005,0.002 -0.006,0.005 -0.002,0.001 -0.002,0.005 -0.005,0.006 -0.048,0.046 -0.107,0.075 -0.163,0.107 -0.028,0.016 -0.05,0.04 -0.08,0.051 -0.09,0.036 -0.185,0.055 -0.28,0.055 -0.096,0 -0.193,-0.019 -0.284,-0.056 -0.03,-0.013 -0.054,-0.038 -0.082,-0.054 -0.056,-0.031 -0.113,-0.059 -0.161,-0.107 -0.001,-0.001 -0.002,-0.005 -0.004,-0.006 -0.001,-0.002 -0.005,-0.002 -0.006,-0.005l-2.954,-3.035c-0.289,-0.297 -0.282,-0.772 0.015,-1.061 0.297,-0.288 0.771,-0.283 1.061,0.015l2.42,2.487 5.467,-5.527c0.291,-0.295 0.767,-0.298 1.061,-0.006C17.333,9.506 17.335,9.981 17.044,10.276z" />
</vector>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:tint="#616161"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M7,18c-1.1,0 -1.99,0.9 -1.99,2S5.9,22 7,22s2,-0.9 2,-2 -0.9,-2 -2,-2zM1,3c0,0.55 0.45,1 1,1h1l3.6,7.59 -1.35,2.44C4.52,15.37 5.48,17 7,17h11c0.55,0 1,-0.45 1,-1s-0.45,-1 -1,-1L7,15l1.1,-2h7.45c0.75,0 1.41,-0.41 1.75,-1.03l3.58,-6.49c0.37,-0.66 -0.11,-1.48 -0.87,-1.48L5.21,4l-0.67,-1.43c-0.16,-0.35 -0.52,-0.57 -0.9,-0.57L2,2c-0.55,0 -1,0.45 -1,1zM17,18c-1.1,0 -1.99,0.9 -1.99,2s0.89,2 1.99,2 2,-0.9 2,-2 -0.9,-2 -2,-2z" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<!--顶部-->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="购物车"
android:textColor="#000"
android:textSize="18sp" />
<!--编辑-->
<TextView
android:id="@+id/tv_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="12dp"
android:padding="@dimen/dp_4"
android:text="编辑"
android:textColor="#000"
android:textSize="16sp" />
</androidx.appcompat.widget.Toolbar>
<!--下拉刷新区域-->
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/lay_bottom"
android:layout_below="@+id/toolbar"
app:srlAccentColor="#000"
app:srlPrimaryColor="#00000000">
<!--刷新头部样式-->
<com.scwang.smartrefresh.header.StoreHouseHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:shhText="SHOPPING CART" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--列表-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_store"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp" />
<!--购物车为空时显示-->
<LinearLayout
android:id="@+id/lay_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_shopping_cart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="空空如也~" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="下拉可以增加数据喔~" />
</LinearLayout>
</RelativeLayout>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
<!--底部-->
<RelativeLayout
android:id="@+id/lay_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#FFF"
android:paddingLeft="12dp">
<ImageView
android:id="@+id/iv_checked_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:src="@drawable/ic_check" />
<TextView
android:id="@+id/tv_checked_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/iv_checked_all"
android:text="全选"
android:textSize="16sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/tv_total"
android:text="合计:"
android:textColor="#000"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:layout_toLeftOf="@+id/tv_settlement"
android:text="¥0"
android:textColor="#DF3B0D"
android:textSize="14sp" />
<!--结算-->
<TextView
android:id="@+id/tv_settlement"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="12dp"
android:background="@drawable/bg_settlement"
android:gravity="center"
android:text="结算"
android:textColor="#FFF"
android:textSize="16sp" />
<!--点击编辑时出现底部布局-->
<LinearLayout
android:id="@+id/lay_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="24dp"
android:layout_toRightOf="@+id/tv_checked_all"
android:background="#FFF"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/tv_share_goods"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.3"
android:background="#f4c600"
android:foreground="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="分享宝贝"
android:textColor="@android:color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_collect_goods"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="1dp"
android:layout_weight="0.3"
android:background="#ea8010"
android:foreground="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="移到收藏夹"
android:textColor="@android:color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_delete_goods"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="1dp"
android:layout_weight="0.3"
android:background="#eb4f38"
android:foreground="?android:attr/selectableItemBackground"
android:gravity="center"
android:text="删除"
android:textColor="@android:color/white"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

@ -0,0 +1,117 @@
<?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:layout_marginBottom="12dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<!--选中商品-->
<ImageView
android:id="@+id/iv_checked_goods"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:src="@drawable/ic_check" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp">
<!--商品图片-->
<ImageView
android:id="@+id/iv_goods"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginRight="12dp"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tv_good_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/iv_goods"
android:text="商品名"
android:textColor="#000"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_good_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_good_name"
android:layout_marginTop="4dp"
android:layout_toRightOf="@+id/iv_goods"
android:text="商品颜色"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_good_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_good_name"
android:layout_marginLeft="6dp"
android:layout_marginTop="4dp"
android:layout_toRightOf="@+id/tv_good_color"
android:text="商品尺寸"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_goods_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginBottom="4dp"
android:layout_toRightOf="@+id/iv_goods"
android:lines="1"
android:text="¥100000.00"
android:textColor="#DF550B"
android:textSize="20sp"
android:textStyle="bold" />
<!--改变商品数量-->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="4dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_reduce_goods_num"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="@drawable/bg_reduce_goods_num"
android:gravity="center"
android:text="—"
android:textColor="#000"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_goods_num"
android:layout_width="40dp"
android:layout_height="24dp"
android:layout_marginLeft="-0.5dp"
android:layout_marginRight="-0.5dp"
android:layout_toRightOf="@+id/tv_reduce_goods_num"
android:background="@drawable/bg_goods_num"
android:gravity="center"
android:text="1"
android:textColor="#000"
android:textSize="16sp" />
<TextView
android:id="@+id/tv_increase_goods_num"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toRightOf="@+id/tv_goods_num"
android:background="@drawable/bg_increase_goods_num"
android:gravity="center"
android:text="+"
android:textColor="#000"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>

@ -0,0 +1,38 @@
<?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:layout_marginBottom="12dp"
android:background="@drawable/bg_white_8"
android:orientation="vertical"
android:padding="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:gravity="center_vertical">
<!--选中店铺-->
<ImageView
android:id="@+id/iv_checked_store"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:src="@drawable/ic_check" />
<TextView
android:id="@+id/tv_store_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="店铺名"
android:textColor="#000"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<!--店铺商品列表-->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_goods"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFF</color>
<color name="colorPrimaryDark">#FFF</color>
<color name="colorAccent">#D81B60</color>
</resources>

@ -0,0 +1,3 @@
<resources>
<string name="app_name">ShoppingCart</string>
</resources>

@ -0,0 +1,11 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>

@ -0,0 +1,28 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

@ -0,0 +1,6 @@
#Mon Dec 07 09:36:35 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

@ -0,0 +1,2 @@
include ':app'
rootProject.name='ShoppingCart'

@ -0,0 +1,76 @@
package com.example.myapplication;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.ListView;
import androidx.annotation.Nullable;
import com.google.android.material.slider.RangeSlider;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class CategoryActivity extends Activity {
public RangeSlider.OnChangeListener onchangeListener
private List<Product>productList;
private List<String>productCategory = new ArrayList<>();
private ListView titleList;
private MyAdapter adapter;
@Override
public void onCreate(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.content_category);
initData();
init();
setDetailFragment fragment = new SetDetailFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.category_detail,fragment);
transaction.commit();
titleList.setOnItemClickListener((parent,view,position,id) - >{
adapter.setSelectedPosition(position);
adapter.notifyDataSetInvalidated();
if (onchangeListener!=null) {
onchangeListener.changeText(productList.get(position));
}
});
}
public void setOnChangeListener(OnChangeListener onChangeListener){
this.onchangeListener=onChangeListener;
}
public interface OnChageListener{
void changeText(Product product);
}
private void initData(){
productList=new ArrayList<>();
productCategory.add("橘子");
productCategory.add("橙子");
productCategory.add("柚子");
Product product=new Product();
product.setImageUrlId(R.drawable.juzi);
product.setProductName("橘子");
product.setProductPrice(new BigDecimal("9.9"));
Product product1=new Product();
product.setImageUrlId(R.drawable.chengzi);
product.setProductName("橙子");
product.setProductPrice(new BigDecimal("29.9"));
Product product2=new Product();
product.setImageUrlId(R.drawable.youzi);
product.setProductName("柚子");
product.setProductPrice(new BigDecimal("19.9"));
productList.add(product);
productList.add(product1);
productList.add(product2);
}
private void init(){
titleList=findViewById(R.id.category_title_list);
adapter=new MyAdapter(productCategory,CategoryActivity.this);
titleList.setAdapter(adapter);
}
}

@ -0,0 +1,64 @@
package com.example.myapplication;
import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.List;
public class MyAdapter extends BaseAdapter {
private List<String>productCategory;
private LayoutInflater layoutInflater;
private int selectionPosition=-1;
public MyAdapter(List<String>productCategory, Context context){
this.productCategory=productCategory;
this.layoutInflater=LayoutInflater.from(context);
}
@Override
public int getCount(){
return productCategory.size();
}
@Override
public Object getItem(int position){
return productCategory.get(position);
}
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
ViewHolder viewHolder =null;
if(convertView==null){
viewHolder=new ViewHolder();
convertView=layoutInflater.inflate(R.layout.category_detail_item,null);
Log.i("adapts","getView:"+convertView);
viewHolder.tv=convertView.findViewById(R.id.categor_titles);
convertView.setTag(viewHolder);
}else{
viewHolder=(ViewHolder) convertView.getTag();
}
viewHolder.tv.setText(productCategory.get(position));
if(selectionPosition==position){
viewHolder.tv.setBackgroundColor(Color.YELLOW);
}else {
viewHolder.tv.setBackgroundColor(Color.WHITE);
}
return convertView;
}
public void setSelectedPosition(int position){
this.selectionPosition=position;
}
class ViewHolder{
TextView tv;
}
}

@ -0,0 +1,30 @@
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
public class SetDetailFragment extends Fragment {
private View view;
private ImageView imageView;
private TextView nameText,priceText;
@SuppressLint("SetTextI18n")
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState){
view=inflater.inflate(R.layout.category_detail_content,container,false);
if(view!=null){
init();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

@ -0,0 +1,30 @@
<?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="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/category_product_image"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center" />
<TextView
android:id="@+id/category_product_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:textColor="#050505"
android:text="666"
android:textSize="16sp"/>
<TextView
android:id="@+id/category_product_price"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:gravity="center"
android:textColor="#050505"
android:text="777"
android:textSize="16sp" />
</LinearLayout>

@ -0,0 +1,13 @@
<?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="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/categor_titles"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18sp"
android:text="标题"/>
</LinearLayout>

@ -0,0 +1,43 @@
<?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="match_parent"
android:background="#E8E8E8"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#EFB81C"
android:orientation="horizontal">
<ImageView
android:id="@+id/category_return"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/jt2" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:gravity="center"
android:text="商品种类"
android:textColor="#FFF"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ListView
android:id="@+id/category_title_list"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/category_detail"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

@ -170,6 +170,30 @@
android:src="@drawable/jt" />
</LinearLayout>
<LinearLayout
android:id="@+id/user_searchProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="35dp"
android:layout_weight="1"
android:drawableLeft="@drawable/search"
android:textColor="#000"
android:text="查看商品"
android:gravity="center_vertical"
android:drawablePadding="6dp"
android:textSize="14sp"
android:layout_marginLeft="5dp"/>
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:src="@drawable/jt" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"

@ -0,0 +1,14 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

@ -4,7 +4,7 @@ android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.orangesale_05"
applicationId "com.example.Fruitparty"
minSdkVersion 23
targetSdkVersion 30
versionCode 1

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.Fruitparty">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.Fruitparty.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.Fruitparty.activity.RegisterActivity"></activity>
<activity android:name="com.example.Fruitparty.activity.UserActivity" />
<activity android:name="com.example.Fruitparty.activity.CategoryActivity" />
<activity android:name="com.example.Fruitparty.activity.IndexActivity" />
</application>
</manifest>

@ -1,4 +1,4 @@
package com.example.orangesale_05;
package com.example.Fruitparty;
import android.content.Intent;
import android.database.Cursor;
@ -11,9 +11,9 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.orangesale_05.activity.IndexActivity;
import com.example.orangesale_05.activity.RegisterActivity;
import com.example.orangesale_05.dataoperation.OrangeDatabase;
import com.example.Fruitparty.activity.IndexActivity;
import com.example.Fruitparty.activity.RegisterActivity;
import com.example.Fruitparty.dataoperation.OrangeDatabase;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button registerButton, loginButton;

@ -1,4 +1,4 @@
package com.example.orangesale_05.activity;
package com.example.Fruitparty.activity;
import android.app.Activity;
import android.app.FragmentManager;
@ -8,10 +8,10 @@ import android.widget.ListView;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.orangesale_05.adapter.Adapter;
import com.example.orangesale_05.entity.Product;
import com.example.orangesale_05.fragment.SetDetailFragment;
import com.example.Fruitparty.R;
import com.example.Fruitparty.adapter.Adapter;
import com.example.Fruitparty.entity.Product;
import com.example.Fruitparty.fragment.SetDetailFragment;
import java.math.BigDecimal;
import java.util.ArrayList;

@ -1,4 +1,4 @@
package com.example.orangesale_05.activity;
package com.example.Fruitparty.activity;
import android.app.Activity;
import android.app.FragmentTransaction;
@ -9,11 +9,11 @@ import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.orangesale_05.fragment.IndexFragment;
import com.example.orangesale_05.fragment.PearsonFragment;
import com.example.orangesale_05.fragment.ProductFragment;
import com.example.orangesale_05.fragment.ShoppingCartFragment;
import com.example.Fruitparty.R;
import com.example.Fruitparty.fragment.IndexFragment;
import com.example.Fruitparty.fragment.PearsonFragment;
import com.example.Fruitparty.fragment.ProductFragment;
import com.example.Fruitparty.fragment.ShoppingCartFragment;
public class IndexActivity extends Activity implements View.OnClickListener {
private IndexFragment indexFragment;

@ -1,4 +1,4 @@
package com.example.orangesale_05.activity;
package com.example.Fruitparty.activity;
import android.content.ContentValues;
import android.content.Intent;
@ -16,8 +16,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.lljjcoder.citypickerview.widget.CityPicker;
import com.example.orangesale_05.R;
import com.example.orangesale_05.dataoperation.OrangeDatabase;
import com.example.Fruitparty.R;
import com.example.Fruitparty.dataoperation.OrangeDatabase;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
private EditText usernameEdit, passwordEdit, surePasswordEdit;

@ -1,4 +1,4 @@
package com.example.orangesale_05.activity;
package com.example.Fruitparty.activity;
import android.app.Activity;
import android.content.Intent;
@ -10,7 +10,7 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.Fruitparty.R;
public class UserActivity extends Activity implements View.OnClickListener {
private ImageView userIconImage;

@ -1,4 +1,4 @@
package com.example.orangesale_05.adapter;
package com.example.Fruitparty.adapter;
import android.content.Context;
import android.graphics.Color;
@ -9,7 +9,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.orangesale_05.R;
import com.example.Fruitparty.R;
import java.util.List;

@ -1,4 +1,4 @@
package com.example.orangesale_05.adapter;
package com.example.Fruitparty.adapter;
import android.content.Context;
import android.util.Log;
@ -9,8 +9,8 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.orangesale_05.R;
import com.example.orangesale_05.entity.Product;
import com.example.Fruitparty.R;
import com.example.Fruitparty.entity.Product;
import java.util.List;

@ -1,4 +1,4 @@
package com.example.orangesale_05.dataoperation;
package com.example.Fruitparty.dataoperation;
import android.content.ContentValues;
import android.content.Context;

@ -1,4 +1,4 @@
package com.example.orangesale_05.entity;
package com.example.Fruitparty.entity;
public class OrangeUser {
private Integer id;

@ -1,4 +1,4 @@
package com.example.orangesale_05.entity;
package com.example.Fruitparty.entity;
import java.math.BigDecimal;

@ -0,0 +1,107 @@
package com.example.Fruitparty.fragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.Fruitparty.R;
import com.example.Fruitparty.adapter.ProductAdapter;
import com.example.Fruitparty.entity.Product;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class IndexFragment extends Fragment implements View.OnClickListener {
private SearchView searchView;
private LinearLayout orangeLine, youziLine, juziLine, xiguaLine, liLine, appleLine, lemonLine, mangguoLine;
private GridView gridView;
private List<Product> productList;
private ProductAdapter productAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index, container, false);
init(view);
return view;
}
/**
*
*/
private void init(View view) {
searchView = view.findViewById(R.id.searchView);
searchView.setOnClickListener(this);
orangeLine = view.findViewById(R.id.chengzi);
orangeLine.setOnClickListener(this);
youziLine = view.findViewById(R.id.youzi);
youziLine.setOnClickListener(this);
juziLine = view.findViewById(R.id.juzi);
juziLine.setOnClickListener(this);
liLine = view.findViewById(R.id.li);
liLine.setOnClickListener(this);
lemonLine = view.findViewById(R.id.lemon);
lemonLine.setOnClickListener(this);
appleLine = view.findViewById(R.id.apple);
appleLine.setOnClickListener(this);
gridView = view.findViewById(R.id.index_famous_gridview);
initData();
productAdapter = new ProductAdapter(getActivity(), productList);
gridView.setAdapter(productAdapter);
}
@Override
public void onClick(View v) {
}
/**
*
*/
private void initData() {
productList = new ArrayList<>();
Product product = new Product();
product.setImageUrlId(R.drawable.water2);
product.setProductName("珍珠果茶");
product.setProductPrice(new BigDecimal("9.9"));
Product product1 = new Product();
product1.setImageUrlId(R.drawable.apple2);
product1.setProductName("苹果");
product1.setProductPrice(new BigDecimal("5.9"));
Product product2 = new Product();
product2.setImageUrlId(R.drawable.red2);
product2.setProductName("火龙果");
product2.setProductPrice(new BigDecimal("7.9"));
Product product3 = new Product();
product3.setImageUrlId(R.drawable.a);
product3.setProductName("果盘A");
product3.setProductPrice(new BigDecimal("9.9"));
Product product4 = new Product();
product4.setImageUrlId(R.drawable.b);
product4.setProductName("果盘B");
product4.setProductPrice(new BigDecimal("9.9"));
Product product5 = new Product();
product5.setImageUrlId(R.drawable.c);
product5.setProductName("果盘C");
product5.setProductPrice(new BigDecimal("9.9"));
productList.add(product);
productList.add(product1);
productList.add(product2);
productList.add(product3);
productList.add(product4);
productList.add(product5);
}
}

@ -1,4 +1,4 @@
package com.example.orangesale_05.fragment;
package com.example.Fruitparty.fragment;
import android.app.Fragment;
import android.os.Bundle;
@ -12,7 +12,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.Fruitparty.R;
public class PearsonFragment extends Fragment implements View.OnClickListener {
private ImageView userIconImage;

@ -1,4 +1,4 @@
package com.example.orangesale_05.fragment;
package com.example.Fruitparty.fragment;
import android.app.Fragment;
import android.os.Bundle;
@ -9,7 +9,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.Fruitparty.R;
public class ProductFragment extends Fragment {
@Nullable

@ -1,4 +1,4 @@
package com.example.orangesale_05.fragment;
package com.example.Fruitparty.fragment;
import android.annotation.SuppressLint;
import android.app.Fragment;
@ -13,8 +13,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.orangesale_05.activity.CategoryActivity;
import com.example.Fruitparty.R;
import com.example.Fruitparty.activity.CategoryActivity;
import java.util.Objects;

@ -1,4 +1,4 @@
package com.example.orangesale_05.fragment;
package com.example.Fruitparty.fragment;
import android.app.Fragment;
import android.os.Bundle;
@ -9,7 +9,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.orangesale_05.R;
import com.example.Fruitparty.R;
public class ShoppingCartFragment extends Fragment {
@Nullable

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save