//导入依赖
//okhttp compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okio:okio:1.11.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' //gson compile 'com.google.code.gson:gson:2.8.2' compile 'com.jcodecraeer:xrecyclerview:1.3.2' compile 'com.youth.banner:banner:1.4.10' //最新版本 implementation 'com.android.support:design:27.1.1' compile 'com.sunfusheng:marqueeview:1.3.3'
//清单
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.shopcartdome"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.CAMERA" /> <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=".activity.MainActivity"></activity> <activity android:name=".activity.LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".activity.MineActivity"></activity> <activity android:name=".activity.ZhuceActivity"></activity> </application> </manifest>
//布局
main
add_sub_view<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical" tools:context="com.example.shopcartdome.activity.MainActivity"> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:gravity="center" android:text="购物车"/> <ExpandableListView android:id="@+id/elv" android:groupIndicator="@null" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"></ExpandableListView> <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp"> <CheckBox android:id="@+id/cbAll" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="全选\反选"/> <TextView android:id="@+id/tvMoney" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_toRightOf="@id/cbAll" android:text="合计:"/> <TextView android:id="@+id/tvTotal" android:layout_width="wrap_content" android:layout_height="match_parent" android:paddingLeft="10dp" android:paddingRight="10dp" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:textColor="#ffffff" android:background="#ff0000" android:gravity="center" android:layout_marginLeft="10dp" android:text="去结算:"/> </RelativeLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/child_image" android:layout_marginRight="5dp" android:layout_toLeftOf="@+id/child_text_delete" android:orientation="horizontal"> <TextView android:id="@+id/child_text_jian" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/cart_biankuang" android:padding="5dp" android:text="-"/> <TextView android:id="@+id/child_text_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/cart_biankuang" android:paddingBottom="5dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="5dp"/> <TextView android:id="@+id/child_text_add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/cart_biankuang" android:padding="5dp" android:text="+"/> </LinearLayout>
activitya_login
<?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" > <RelativeLayout android:id="@+id/login_title_relative" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textSize="26dp" android:text="登录"/> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/login_title_relative" android:layout_margin="10dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号"/> <EditText android:id="@+id/edit_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入手机号"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码"/> <EditText android:id="@+id/edit_pwd" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:inputType="textPassword" android:singleLine="true"/> </LinearLayout> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:gravity="center" android:onClick="login" android:text="登录"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:orientation="horizontal"> <TextView android:id="@+id/text_regist" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="手机快速注册"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="忘记密码"/> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="20dp" android:orientation="horizontal"> <ImageView android:id="@+id/login_by_wechat" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/umeng_socialize_wechat"/> <ImageView android:id="@+id/login_by_qq" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:src="@drawable/umeng_socialize_qq"/> </LinearLayout> </RelativeLayout>
activity_mine
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/ll" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="100dp" android:layout_height="100dp" android:src="@drawable/umeng_socialize_qq"/> </LinearLayout>
activity_zhuce
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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" tools:context="com.example.shopcartdome.activity.ZhuceActivity"> </android.support.constraint.ConstraintLayout>
pop_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/tvCamera" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:gravity="center" android:text="拍照上传"/> <TextView android:id="@+id/tvPhoto" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:gravity="center" android:text="本地上传"/> <TextView android:id="@+id/tvCancle" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="20dp" android:background="#ffffff" android:gravity="center" android:text="取消"/> </LinearLayout>
shopcart_seller_item
<?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="30dp" android:gravity="center_vertical" android:orientation="horizontal"> <CheckBox android:id="@+id/cbSeller" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp"/> <TextView android:id="@+id/tvSeller" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp"/> </LinearLayout>
shopcart_seller_product_item
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <CheckBox android:id="@+id/cbProduct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="20dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toEndOf="@+id/cbProduct" android:layout_toRightOf="@id/cbProduct" android:orientation="horizontal"> <ImageView android:id="@+id/iv" android:layout_width="70dp" android:layout_height="70dp" android:layout_gravity="center_vertical"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="5dp" android:layout_marginTop="5dp" android:orientation="vertical"> <TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="5dp"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/tvPrice" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="12312" android:textColor="#ff0000"/> <com.example.shopcartdome.view.AddSubView android:id="@+id/addSubCard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true"></com.example.shopcartdome.view.AddSubView> </RelativeLayout> </LinearLayout> </LinearLayout> </RelativeLayout>
///////activity
//LoginActivity
package com.example.shopcartdome.activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.example.shopcartdome.R; import com.example.shopcartdome.bean.UserBean; import com.example.shopcartdome.net.Api; import com.example.shopcartdome.net.OkHttpUtils; import com.example.shopcartdome.net.OnNetListener; import com.example.shopcartdome.presenter.LoginPresenterImp; import com.example.shopcartdome.view.LoginView; import com.google.gson.Gson; public class LoginActivity extends AppCompatActivity implements View.OnClickListener, LoginView { private RelativeLayout mLoginTitleRelative; /** * 请输入手机号 */ private EditText mEditPhone; /** * 请输入密码 */ private EditText mEditPwd; /** * 手机快速注册 */ private TextView mTextRegist; private ImageView mLoginByWechat; private ImageView mLoginByQq; private LoginPresenterImp imp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); initView(); //绑定 imp = new LoginPresenterImp(this); } private void initView() { mLoginTitleRelative = (RelativeLayout) findViewById(R.id.login_title_relative); mEditPhone = (EditText) findViewById(R.id.edit_phone); mEditPwd = (EditText) findViewById(R.id.edit_pwd); mTextRegist = (TextView) findViewById(R.id.text_regist); mTextRegist.setOnClickListener(this); mLoginByWechat = (ImageView) findViewById(R.id.login_by_wechat); mLoginByQq = (ImageView) findViewById(R.id.login_by_qq); mLoginByQq.setOnClickListener(this); } //登录 public void login(View view) { //获取用户名和密码 String mobile = mEditPhone.getText().toString(); String password = mEditPwd.getText().toString(); imp.login(mobile, password); SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE); String uid = sharedPreferences.getString("uid", "-1"); if ("-1".equals(uid)){ setContentView(R.layout.activity_login); }else { Intent intent = new Intent(LoginActivity.this,MainActivity.class); startActivity(intent); finish(); } } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.text_regist: Intent intent = new Intent(LoginActivity.this,ZhuceActivity.class); startActivity(intent); finish(); break; case R.id.login_by_qq: break; } } @Override public void loginSuccess(UserBean userBean) { //保存用户信息到SharedPreferences SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE); SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString("uid", userBean.getData().getUid() + ""); edit.putString("name", userBean.getData().getUsername() + ""); edit.putString("iconUrl", userBean.getData().getIcon() + ""); edit.putString("token", userBean.getData().getToken() + ""); edit.commit(); Toast.makeText(LoginActivity.this,"登陆完成",Toast.LENGTH_SHORT).show(); //关闭当前页面 this.finish(); } }
//MainActivity
package com.example.shopcartdome.activity; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.CheckBox; import android.widget.ExpandableListView; import android.widget.TextView; import com.example.shopcartdome.ElvShopcartAdapter; import com.example.shopcartdome.R; import com.example.shopcartdome.bean.SellerBean; import com.example.shopcartdome.bean.ShopCartsBean; import com.example.shopcartdome.presenter.GetCartsPresenterImp; import com.example.shopcartdome.view.GetCartsView; import java.util.List; public class MainActivity extends AppCompatActivity implements GetCartsView, View.OnClickListener { private ExpandableListView mElv; /** * 全选\反选 */ private CheckBox mCbAll; /** * 合计: */ private TextView mTvMoney; /** * 去结算: */ private TextView mTvTotal; private GetCartsPresenterImp getCartsPresenterImp; private ElvShopcartAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); getCartsPresenterImp = new GetCartsPresenterImp(this); getCartsPresenterImp.getCarts(14381 + "", ""); } @Override protected void onDestroy() { super.onDestroy(); getCartsPresenterImp.detach(); } private void initView() { mElv = (ExpandableListView) findViewById(R.id.elv); mCbAll = (CheckBox) findViewById(R.id.cbAll); mTvMoney = (TextView) findViewById(R.id.tvMoney); mTvTotal = (TextView) findViewById(R.id.tvTotal); mCbAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (adapter != null) { adapter.changeAllState(mCbAll.isChecked()); } } }); mTvTotal.setOnClickListener(this); } @Override public void getCarts(List<SellerBean> groupList, List<List<ShopCartsBean.DataBean.ListBean>> childList) { //判断所有商家是否全部选中 mCbAll.setChecked(isSellerAddSelected(groupList)); //创建适配器 adapter = new ElvShopcartAdapter(this, groupList, childList, getCartsPresenterImp); mElv.setAdapter(adapter); //获取数量和总价 String[] strings = adapter.computeMoneyAndNum(); mTvMoney.setText("总计:" + strings[0] + "元"); mTvTotal.setText("去结算(" + strings[1] + "个)"); // //默认展开列表 for (int i = 0; i < groupList.size(); i++) { mElv.expandGroup(i); } } private boolean isSellerAddSelected(List<SellerBean> groupList) { for (int i = 0; i < groupList.size(); i++) { SellerBean sellerBean = groupList.get(i); if (!sellerBean.isSelected()) { return false; } } return true; } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.tvTotal: //跳转到我的页面 Intent intent = new Intent(MainActivity.this,MineActivity.class); startActivity(intent); break; } } }
//MineActivity
package com.example.shopcartdome.activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.provider.MediaStore; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.Toast; import com.example.shopcartdome.R; import com.example.shopcartdome.net.Api; import com.example.shopcartdome.net.OkHttpUtils; import com.example.shopcartdome.net.OnNetListener; import java.io.File; import java.io.FileOutputStream; import java.util.HashMap; import java.util.Map; public class MineActivity extends AppCompatActivity implements View.OnClickListener { private ImageView mIv; private LinearLayout mLl; private PopupWindow popupWindow; private String imgPath; private String imgCropPath; private Uri imageFileUri; private String uid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_mine); imgPath = getExternalCacheDir().getPath() + "/header.jpg"; imgCropPath = getExternalCacheDir().getPath() + "/header_crop.jpg"; File file = new File(imgPath); imageFileUri = Uri.fromFile(file); initView(); SharedPreferences sharedPreferences = getSharedPreferences("user", Context.MODE_PRIVATE); uid = sharedPreferences.getString("uid", ""); } private void initView() { mIv = (ImageView) findViewById(R.id.iv); mIv.setOnClickListener(this); mLl = (LinearLayout) findViewById(R.id.ll); } @Override public void onClick(View v) { switch (v.getId()) { default: break; case R.id.iv: //弹出PopupWindow View view = View.inflate(MineActivity.this, R.layout.pop_item, null); initPopItem(view); popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout .LayoutParams.WRAP_CONTENT); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new ColorDrawable()); popupWindow.showAtLocation(mLl, Gravity.BOTTOM, 0, 0); break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case 1000: if (resultCode == RESULT_OK) { //拍照成功,剪切图片 Toast.makeText(MineActivity.this, "拍照成功", Toast.LENGTH_SHORT).show(); crop(imageFileUri); } break; case 2000: try { //拍照后裁剪成功 //先获取裁剪后的图片 Bitmap bitmap = data.getParcelableExtra("data"); File file = new File(imgCropPath); //判断该文件创建 if (file.exists()) { file.delete(); } //创建出新的文件 file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); //把裁剪后的图片保存到本地 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); //上传到服务器 Map<String, String> params = new HashMap<>(); params.put("uid", uid); OkHttpUtils.getInstance().uploadFile(Api.UPLOADHEADER, params, "header_crop.jpg", file, new OnNetListener() { @Override public void onSuccess(String result) { Toast.makeText(MineActivity.this, result, Toast.LENGTH_SHORT).show(); } @Override public void onFaild(Exception e) { } }); } catch (Exception e) { e.printStackTrace(); } break; case 3000: Uri uri = data.getData(); //crop(uri); break; } } private void crop(Uri uri) { Intent intent = new Intent(); //指定裁剪的动作 intent.setAction("com.android.camera.action.CROP"); //设置裁剪的数据(uri路径)....裁剪的类型(image/*) intent.setDataAndType(uri, "image/*"); //执行裁剪的指令 intent.putExtra("crop", "true"); //指定裁剪框的宽高比 intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); //指定输出的时候宽度和高度 intent.putExtra("outputX", 300); intent.putExtra("outputY", 300); //设置取消人脸识别 intent.putExtra("noFaceDetection", false); //设置返回数据 intent.putExtra("return-data", true); // startActivityForResult(intent, 2000); } private void initPopItem(View view) { TextView tvCamera = view.findViewById(R.id.tvCamera); TextView tvCancle = view.findViewById(R.id.tvCancle); TextView tvPhoto = view.findViewById(R.id.tvPhoto); tvCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } //调用相机,需要隐式意图 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri); startActivityForResult(intent, 1000); } }); tvPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } Intent intent = new Intent(); //指定选择/获取的动作...PICK获取,拿 intent.setAction(Intent.ACTION_PICK); //指定获取的数据的类型 intent.setType("image/*"); startActivityForResult(intent, 3000); } }); tvCancle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); } }
//ZhuceActivity
package com.example.shopcartdome.activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import com.example.shopcartdome.R; public class ZhuceActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_zhuce); } }
///////////////model层
//
GetCartsModel
package com.example.shopcartdome.model; import com.example.shopcartdome.net.OnNetListener; /** * Created by Administrator on 2018/4/29. */ public interface GetCartsModel { void getCarts(String uid, String token, OnNetListener onNetListener); }
//
GetCartsModelImp
package com.example.shopcartdome.model; import com.example.shopcartdome.bean.ShopCartsBean; import com.example.shopcartdome.net.Api; import com.example.shopcartdome.net.OkHttpUtils; import com.example.shopcartdome.net.OnNetListener; import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; /** * Created by Administrator on 2018/4/29. */ public class GetCartsModelImp implements GetCartsModel{ @Override public void getCarts(String uid, String token, final OnNetListener onNetListener) { Map<String,String> params= new HashMap<>(); params.put("uid",uid); params.put("token",token); OkHttpUtils.getInstance().doPost(Api.URL, params, new OnNetListener() { @Override public void onSuccess(String result) { ShopCartsBean getCartsBean = new Gson().fromJson(result, ShopCartsBean.class); if ("0".equals(getCartsBean.getCode())){ onNetListener.onSuccess(result); } } @Override public void onFaild(Exception e) { onNetListener.onFaild(e); } }); } }
//LoginModel
package com.example.shopcartdome.model; import com.example.shopcartdome.net.OnNetListener; /** * Created by Administrator on 2018/5/3. */ public interface LoginModel { void login(String mobile, String password, OnNetListener onNetListener); }
LoginModelImp
package com.example.shopcartdome.model; import com.example.shopcartdome.bean.UserBean; import com.example.shopcartdome.net.Api; import com.example.shopcartdome.net.OkHttpUtils; import com.example.shopcartdome.net.OnNetListener; import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; /** * Created by Administrator on 2018/5/3. */ public class LoginModelImp implements LoginModel { @Override public void login(String mobile, String password, final OnNetListener onNetListener) { Map<String, String> params = new HashMap<>(); params.put("mobile", mobile); params.put("password", password); OkHttpUtils.getInstance().doPost(Api.LOGIN_URL, params, new OnNetListener() { @Override public void onSuccess(String result) { UserBean userBean = new Gson().fromJson(result, UserBean.class); if ("0".equals(userBean.getCode())) { onNetListener.onSuccess(result); } } @Override public void onFaild(Exception e) { onNetListener.onFaild(e); } }); } }
UpdateCartsModel
package com.example.shopcartdome.model; import com.example.shopcartdome.net.OnNetListener; /** * Created by Administrator on 2018/4/29. */ public interface UpdateCartsModel { void updateCarts(String uid, String sellerid, String pid, String num, String selected, String token, OnNetListener onNetListener); }
UpdateCartsModelImp
//////////////netpackage com.example.shopcartdome.model; import com.example.shopcartdome.net.Api; import com.example.shopcartdome.net.OkHttpUtils; import com.example.shopcartdome.net.OnNetListener; import java.util.HashMap; import java.util.Map; /** * Created by Administrator on 2018/4/29. */ public class UpdateCartsModelImp implements UpdateCartsModel { @Override public void updateCarts(String uid, String sellerid, String pid, String num, String selected, String token, final OnNetListener onNetListener) { Map<String,String> params = new HashMap<>(); params.put("uid",uid); params.put("sellerid",sellerid); params.put("pid",pid); params.put("num",num); params.put("selected",selected); params.put("token",token); OkHttpUtils.getInstance().doPost(Api.UPDATECARTS_URL, params, new OnNetListener() { @Override public void onSuccess(String result) { onNetListener.onSuccess(result); } @Override public void onFaild(Exception e) { } }); } }
Api
package com.example.shopcartdome.net; /** * Created by Administrator on 2018/4/29. */ public interface Api { String URL="https://www.zhaoapi.cn/product/getCarts"; String UPDATECARTS_URL = "https://www.zhaoapi.cn/product/updateCarts"; String UPLOADHEADER = "https://www.zhaoapi.cn/file/upload"; String LOGIN_URL = "https://www.zhaoapi.cn/user/login"; }
MyInterceptor
package com.example.shopcartdome.net; import java.io.IOException; import okhttp3.FormBody; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.Request; import okhttp3.Response; /** * Created by Administrator on 2018/4/29. */ public class MyInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Response response; //区分是GET请求还是POST请求 Request originRequest = chain.request(); if ("GET".equals(originRequest.method())) { HttpUrl httpUrl = originRequest.url() .newBuilder() .addQueryParameter("source", "android") .build(); Request request = new Request.Builder().url(httpUrl).build(); //发送请求 response = chain.proceed(request); } else { FormBody.Builder builder = new FormBody.Builder(); FormBody body = (FormBody) originRequest.body(); int size = body.size(); for (int i = 0; i < size; i++) { builder.add(body.name(i), body.value(i)); } builder.add("source", "android"); FormBody formBody = builder.build(); Request request = new Request.Builder() .url(originRequest.url()) .post(formBody) .build(); response = chain.proceed(request); } return response; } }
OkHttpUtils
package com.example.shopcartdome.net; import android.os.Handler; import android.os.Looper; import android.telecom.Call; import java.io.File; import java.io.IOException; import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.logging.HttpLoggingInterceptor; /** * Created by Administrator on 2018/4/29. */ public class OkHttpUtils { private static OkHttpUtils instance; private final OkHttpClient okHttpClient; private final Handler handler; private OkHttpUtils() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); okHttpClient = new OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS)//连接超时 .writeTimeout(20, TimeUnit.SECONDS)//写入超时 .readTimeout(20, TimeUnit.SECONDS)//读取超时 .addInterceptor(new MyInterceptor()) .addInterceptor(logging) .build(); handler = new Handler(Looper.getMainLooper()); } public static OkHttpUtils getInstance() { if (instance == null) { instance = new OkHttpUtils(); } return instance; } /** * GET请求 * * @param url */ public void doGet(String url, final OnNetListener onNetListener) { //创建Request final Request request = new Request.Builder() .url(url) .build(); //发送请求 okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(okhttp3.Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { onNetListener.onFaild(e); } }); } @Override public void onResponse(okhttp3.Call call, Response response) throws IOException { //拿到服务器返回的数据 final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { onNetListener.onSuccess(string); } }); } }); } /** * POST请求 * * @param url * @param params * @param onNetListener */ public void doPost(String url, Map<String, String> params, final OnNetListener onNetListener) { FormBody.Builder builder = new FormBody.Builder(); for (Map.Entry<String, String> entry : params.entrySet()) { builder.add(entry.getKey(), entry.getValue()); } //创建FormBody FormBody formBody = builder.build(); //创建Request Request request = new Request.Builder() .url(url) .post(formBody) .build(); //请求数据 okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(okhttp3.Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { onNetListener.onFaild(e); } }); } @Override public void onResponse(okhttp3.Call call, Response response) throws IOException { //拿到服务器返回的数据 final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { onNetListener.onSuccess(string); } }); } }); } public void uploadFile(String url, Map<String, String> params, String fileName, File file, final OnNetListener onNetListener) { MultipartBody.Builder builder = new MultipartBody.Builder(); builder.setType(MultipartBody.FORM); //上传参数 for (Map.Entry<String, String> entry : params.entrySet()) { builder.addFormDataPart(entry.getKey(), entry.getValue()); } builder.addFormDataPart("file", fileName, RequestBody.create(MediaType.parse("application/octet-stream"), file)); MultipartBody multipartBody = builder.build(); final Request request = new Request.Builder() .url(url) .post(multipartBody) .build(); okHttpClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(okhttp3.Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { onNetListener.onFaild(e); } }); } @Override public void onResponse(okhttp3.Call call, Response response) throws IOException { final String string = response.body().string(); handler.post(new Runnable() { @Override public void run() { onNetListener.onSuccess(string); } }); } }); } }
OnNetListener
package com.example.shopcartdome.net; import java.io.IOException; /** * Created by Administrator on 2018/4/29. */ public interface OnNetListener { void onSuccess(String result); void onFaild(Exception e); }
/////////////////presenter层
GetCartsPresenter
package com.example.shopcartdome.presenter; /** * Created by Administrator on 2018/4/29. */ public interface GetCartsPresenter { void getCarts(String uid, String token); }
GetCartsPresenterImp
package com.example.shopcartdome.presenter; import com.example.shopcartdome.bean.SellerBean; import com.example.shopcartdome.bean.ShopCartsBean; import com.example.shopcartdome.model.GetCartsModelImp; import com.example.shopcartdome.net.OnNetListener; import com.example.shopcartdome.view.GetCartsView; import com.google.gson.Gson; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 2018/4/29. */ public class GetCartsPresenterImp implements GetCartsPresenter { private GetCartsView getCartsView; private final GetCartsModelImp getCartsModelImp; public GetCartsPresenterImp(GetCartsView getCartsView) { this.getCartsView = getCartsView; getCartsModelImp = new GetCartsModelImp(); } @Override public void getCarts(String uid, String token) { getCartsModelImp.getCarts(uid, token, new OnNetListener() { @Override public void onSuccess(String result) { if (getCartsView!=null){ List<SellerBean> groupList= new ArrayList<>(); List<List<ShopCartsBean.DataBean.ListBean>> childList = new ArrayList<>(); ShopCartsBean shopCartsBean = new Gson().fromJson(result, ShopCartsBean.class); List<ShopCartsBean.DataBean> data = shopCartsBean.getData(); for (int i=0;i<data.size();i++){ ShopCartsBean.DataBean dataBean = data.get(i); SellerBean sellerBean = new SellerBean(); sellerBean.setSelected(isSellerProductAllSelect(dataBean)); sellerBean.setSellerid(dataBean.getSellerid()); sellerBean.setSellerName(dataBean.getSellerName()); groupList.add(sellerBean); List<ShopCartsBean.DataBean.ListBean> list = dataBean.getList(); childList.add(list); } getCartsView.getCarts(groupList,childList); } } @Override public void onFaild(Exception e) { } }); } private boolean isSellerProductAllSelect(ShopCartsBean.DataBean dataBean) { //获取该商家下面的所有商品 List<ShopCartsBean.DataBean.ListBean> list = dataBean.getList(); for (int i = 0; i < list.size(); i++) { ShopCartsBean.DataBean.ListBean listBean = list.get(i); if (0 == listBean.getSelected()) { //如果是0的话,表示有一个商品未选中 return false; } } return true; } public void detach() { if (getCartsView != null) { getCartsView = null; } } }
LoginPresenter
package com.example.shopcartdome.presenter; /** * Created by Administrator on 2018/5/3. */ public interface LoginPresenter { void login(String mobile, String password); }
LoginPresenterImp
package com.example.shopcartdome.presenter; import com.example.shopcartdome.bean.UserBean; import com.example.shopcartdome.model.LoginModelImp; import com.example.shopcartdome.net.OnNetListener; import com.example.shopcartdome.view.LoginView; import com.google.gson.Gson; /** * Created by Administrator on 2018/5/3. */ public class LoginPresenterImp implements LoginPresenter { private LoginView loginView; private final LoginModelImp loginModelImp; public LoginPresenterImp(LoginView loginView) { this.loginView = loginView; loginModelImp = new LoginModelImp(); } @Override public void login(String mobile, String password) { //判断账号密码是否合法 loginModelImp.login(mobile, password, new OnNetListener() { @Override public void onSuccess(String result) { if (loginView != null) { UserBean userBean = new Gson().fromJson(result, UserBean.class); loginView.loginSuccess(userBean); } } @Override public void onFaild(Exception e) { } }); } public void detach() { if (loginView != null) { loginView = null; } } }
UpdateCartsPresenter
package com.example.shopcartdome.presenter; /** * Created by Administrator on 2018/4/29. */ public interface UpdateCartsPresenter { void updateCarts(String uid,String sellerid,String pid,String num ,String selected,String token); }
UpdateCartsPresenterImp
package com.example.shopcartdome.presenter; import com.example.shopcartdome.model.UpdateCartsModelImp; import com.example.shopcartdome.net.OnNetListener; import com.example.shopcartdome.view.UpdateCartsView; /** * Created by Administrator on 2018/4/29. */ public class UpdateCartsPresenterImp implements UpdateCartsPresenter { private final UpdateCartsModelImp updateCartsModelImp; private UpdateCartsView updateCartsView; public UpdateCartsPresenterImp(UpdateCartsView updateCartsView) { this.updateCartsView = updateCartsView; updateCartsModelImp = new UpdateCartsModelImp(); } @Override public void updateCarts(String uid, String sellerid, String pid, String num, String selected, String token) { updateCartsModelImp.updateCarts(uid, sellerid, pid, num, selected, token, new OnNetListener() { @Override public void onSuccess(String result) { updateCartsView.updataSuccess(); } @Override public void onFaild(Exception e) { } }); } }
/////////////view层
AddSubView
package com.example.shopcartdome.view; import android.content.Context; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import com.example.shopcartdome.R; /** * Created by Administrator on 2018/4/29. */ public class AddSubView extends LinearLayout { private TextView sub; private TextView num; private TextView add; public AddSubView(Context context) { this(context, null); } public AddSubView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); View view = LayoutInflater.from(context).inflate(R.layout.add_sub_view, this); sub = findViewById(R.id.child_text_jian); num = findViewById(R.id.child_text_num); add = findViewById(R.id.child_text_add); } /** * 设置数量 * @param str */ public void setNum(String str) { num.setText(str); } /** * 获取数量 * * @return */ public String getNum() { return num.getText().toString(); } /** * 给加号设置点击事件 * * @param onclickListener */ public void setAddOnclickListener(OnClickListener onclickListener) { add.setOnClickListener(onclickListener); } /** * 给减号设置点击事件 * * @param onclickListener */ public void setSubOnclickListener(OnClickListener onclickListener) { sub.setOnClickListener(onclickListener); } }
DialogUtil
package com.example.shopcartdome.view; import android.app.ProgressDialog; import android.content.Context; /** * Created by Administrator on 2018/4/29. */ public class DialogUtil { public static ProgressDialog getProgressDialog(Context context) { ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("正在加载..."); progressDialog.setCancelable(false); return progressDialog; } }
GetCartsView
package com.example.shopcartdome.view; import com.example.shopcartdome.bean.SellerBean; import com.example.shopcartdome.bean.ShopCartsBean; import java.util.List; /** * Created by Administrator on 2018/4/29. */ public interface GetCartsView { void getCarts(List<SellerBean> groupList, List<List<ShopCartsBean.DataBean.ListBean>> childList); }
LoginView
package com.example.shopcartdome.view; import com.example.shopcartdome.bean.UserBean; /** * Created by Administrator on 2018/5/3. */ public interface LoginView { void loginSuccess(UserBean userBean); }
UpdateCartsView
package com.example.shopcartdome.view; /** * Created by Administrator on 2018/4/29. */ public interface UpdateCartsView { void updataSuccess(); }
///////ElvShopcartAdapter
package com.example.shopcartdome; import android.app.ProgressDialog; import android.content.Context; import android.content.SharedPreferences; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.bumptech.glide.Glide; import com.example.shopcartdome.bean.SellerBean; import com.example.shopcartdome.bean.ShopCartsBean; import com.example.shopcartdome.presenter.GetCartsPresenterImp; import com.example.shopcartdome.presenter.UpdateCartsPresenterImp; import com.example.shopcartdome.view.AddSubView; import com.example.shopcartdome.view.UpdateCartsView; import java.util.List; /** * Created by Administrator on 2018/4/29. */ public class ElvShopcartAdapter extends BaseExpandableListAdapter implements UpdateCartsView { private Context context; private List<SellerBean> groupList; private List<List<ShopCartsBean.DataBean.ListBean>> childList; private LayoutInflater inflater; private final UpdateCartsPresenterImp updateCartsPresenterImp; private GetCartsPresenterImp getCartsPresenterImp; private final String uid=14381+""; private final String token=""; private int productIndex; private int groupPosition; private boolean checked; private static final int GETCARTS = 0;//查询购物车 private static final int UPDATE_PRODUCT = 1; //更新商品 private static final int UPDATE_SELLER = 2; //更新卖家 private static int state = GETCARTS; private boolean allSelected; public ElvShopcartAdapter(Context context, List<SellerBean> groupList, List<List<ShopCartsBean.DataBean.ListBean>> childList, GetCartsPresenterImp getCartsPresenterImp) { this.context = context; this.groupList = groupList; this.childList = childList; inflater = LayoutInflater.from(context); this.getCartsPresenterImp = getCartsPresenterImp; //绑定 updateCartsPresenterImp = new UpdateCartsPresenterImp(this); SharedPreferences sharedPreferences = context.getSharedPreferences("user", Context.MODE_PRIVATE); // uid = sharedPreferences.getString("uid", "-1"); // token = sharedPreferences.getString("token", ""); } @Override public int getGroupCount() { return groupList.size(); } @Override public int getChildrenCount(int groupPosition) { return childList.get(groupPosition).size(); } @Override public Object getGroup(int groupPosition) { return groupList.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return childList.get(groupPosition).get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { final GroupViewHolder groupViewHolder; if (convertView == null) { groupViewHolder = new GroupViewHolder(); convertView = inflater.inflate(R.layout.shopcart_seller_item, null); groupViewHolder.cbSeller = convertView.findViewById(R.id.cbSeller); groupViewHolder.tvSeller = convertView.findViewById(R.id.tvSeller); convertView.setTag(groupViewHolder); } else { groupViewHolder = (GroupViewHolder) convertView.getTag(); } //设置值 SellerBean sellerBean = groupList.get(groupPosition); groupViewHolder.tvSeller.setText(sellerBean.getSellerName()); groupViewHolder.cbSeller.setChecked(sellerBean.isSelected()); //给商家checkbox设置点击事件 groupViewHolder.cbSeller.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //设置当前的更新状态 state = UPDATE_PRODUCT; //显示进度条 //progressDialog.show(); //默认从第一个商品开始更新购物车状态 productIndex = 0; //全局记录一下当前更新的商家 ElvShopcartAdapter.this.groupPosition = groupPosition; //该商家是否选中 checked = groupViewHolder.cbSeller.isChecked(); //更新商家下的商品状态 updateProductInSeller(); } }); return convertView; } @Override public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { final ChildViewHolder childViewHolder; if (convertView == null) { childViewHolder = new ChildViewHolder(); convertView = inflater.inflate(R.layout.shopcart_seller_product_item, null); childViewHolder.cbProduct = convertView.findViewById(R.id.cbProduct); childViewHolder.iv = convertView.findViewById(R.id.iv); childViewHolder.tvTitle = convertView.findViewById(R.id.tvTitle); childViewHolder.tvPrice = convertView.findViewById(R.id.tvPrice); childViewHolder.addSubView = convertView.findViewById(R.id.addSubCard); convertView.setTag(childViewHolder); } else { childViewHolder = (ChildViewHolder) convertView.getTag(); } final ShopCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(childPosition); //根据服务器返回的select值,给checkBox设置是否选中 childViewHolder.cbProduct.setChecked(listBean.getSelected() == 1 ? true : false); childViewHolder.tvTitle.setText(listBean.getTitle()); childViewHolder.tvPrice.setText(listBean.getPrice() + ""); Glide.with(context).load(listBean.getImages().split("\\|")[0]).into(childViewHolder.iv); childViewHolder.addSubView.setNum(listBean.getNum() + ""); //给二级列表的checkbox设置点击事件 childViewHolder.cbProduct.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { state = GETCARTS; //显示进度条 //progressDialog.show(); ElvShopcartAdapter.this.groupPosition = groupPosition; //调用更新购物车接口,改变购物车的状态 //获取卖家id String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid String pid = listBean.getPid() + ""; //是否选中 boolean childChecked = childViewHolder.cbProduct.isChecked(); updateCartsPresenterImp.updateCarts(uid, sellerid, pid, "1", childChecked ? "1" : "0", token); } }); //给加号设置点击事件 childViewHolder.addSubView.setAddOnclickListener(new View.OnClickListener() { @Override public void onClick(View v) { ///progressDialog.show(); state = GETCARTS; //获取sellerId String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid int pid = listBean.getPid(); //获取数量 int num = listBean.getNum(); num += 1; //是否选中 String isChecked = childViewHolder.cbProduct.isChecked() ? "1" : "0"; //调用更新购物车的接口即可 updateCartsPresenterImp.updateCarts(uid, sellerid, pid + "", num + "", isChecked, token); } }); //给减号设置点击事件 childViewHolder.addSubView.setSubOnclickListener(new View.OnClickListener() { @Override public void onClick(View v) { //progressDialog.show(); state = GETCARTS; //获取当前商品的数量 int num = listBean.getNum(); if (num <= 1) { //progressDialog.dismiss(); Toast.makeText(context, "数量不能小于1", Toast.LENGTH_SHORT).show(); return; } num -= 1; //获取sellerId String sellerid = groupList.get(groupPosition).getSellerid(); //获取pid int pid = listBean.getPid(); //是否选中 String isChecked = childViewHolder.cbProduct.isChecked() ? "1" : "0"; //更新购物车 updateCartsPresenterImp.updateCarts(uid, sellerid, pid + "", num + "", isChecked, token); } }); return convertView; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } class GroupViewHolder { CheckBox cbSeller; TextView tvSeller; } class ChildViewHolder { CheckBox cbProduct; ImageView iv; TextView tvTitle; TextView tvPrice; TextView tvDel; AddSubView addSubView; } //更新购物车成功回调的方法 public void updataSuccess() { switch (state) { case GETCARTS: //更新成功以后调用查询购物车接口 productIndex = 0; groupPosition = 0; getCartsPresenterImp.getCarts(uid, token); break; case UPDATE_PRODUCT: //更新成功一个商品以后,再接着更新该商家下面的其它商品,直到没有商品为止 productIndex++; //下标是否越界 if (productIndex < childList.get(groupPosition).size()) { //可以继续跟新商品 updateProductInSeller(); } else { //商品已经全部更新完成,请查询购物车 state = GETCARTS; updataSuccess(); } break; case UPDATE_SELLER: //遍历所有商家下的商品,并更新状态 productIndex++; //下标是否越界 if (productIndex < childList.get(groupPosition).size()) { //可以继续跟新商品 updateProductInSeller(allSelected); } else { //商品已经全部更新完成,请查询购物车 productIndex = 0; groupPosition++; if (groupPosition < groupList.size()) { //可以继续跟新商品 updateProductInSeller(allSelected); } else { //商品已经全部更新完成,请查询购物车 state = GETCARTS; updataSuccess(); } } break; } } private void updateProductInSeller() { //获取SellerId SellerBean sellerBean = groupList.get(groupPosition); String sellerid = sellerBean.getSellerid(); //获取pid ShopCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(productIndex); int num = listBean.getNum(); int pid = listBean.getPid(); updateCartsPresenterImp.updateCarts(uid, sellerid, pid + "", num + "", checked ? "1" : "0", token); } private void updateProductInSeller(boolean bool) { //获取SellerId SellerBean sellerBean = groupList.get(groupPosition); String sellerid = sellerBean.getSellerid(); //获取pid ShopCartsBean.DataBean.ListBean listBean = childList.get(groupPosition).get(productIndex); int pid = listBean.getPid(); int num = listBean.getNum(); updateCartsPresenterImp.updateCarts(uid, sellerid, pid + "", num + "", bool ? "1" : "0", token); } /** * 计算数量和价钱 * * @return */ public String[] computeMoneyAndNum() { double sum = 0; int num = 0; for (int i = 0; i < groupList.size(); i++) { for (int j = 0; j < childList.get(i).size(); j++) { //判断商品是否选中 ShopCartsBean.DataBean.ListBean listBean = childList.get(i).get(j); if (listBean.getSelected() == 1) { //该商品为选中状态 sum += listBean.getPrice() * listBean.getNum(); num += listBean.getNum(); } } } return new String[]{sum + "", num + ""}; } public void changeAllState(boolean bool) { this.allSelected = bool; state = UPDATE_SELLER; //遍历商家下的商品,修改状态 updateProductInSeller(bool); } }
////////////bean
SellerBean
package com.example.shopcartdome.bean; /** * Created by Administrator on 2018/4/29. */ public class SellerBean { private String sellerName; private String sellerid; private boolean selected;//商家是否选中 public boolean isSelected() { return selected; } public void setSelected(boolean selected) { this.selected = selected; } public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public String getSellerid() { return sellerid; } public void setSellerid(String sellerid) { this.sellerid = sellerid; } }
ShopCartsBean
package com.example.shopcartdome.bean; import java.util.List; /** * Created by Administrator on 2018/4/29. */ public class ShopCartsBean { /** * code : 0 * data : [{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":3,"pid":24,"price":288,"pscid":2,"selected":1,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":3,"pid":45,"price":2999,"pscid":39,"selected":1,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"}],"sellerName":"商家1","sellerid":"1"},{"list":[{"bargainPrice":22.9,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":2,"pid":25,"price":399,"pscid":2,"selected":1,"sellerid":2,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","num":2,"pid":58,"price":6399,"pscid":40,"selected":1,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":6666,"createtime":"2017-10-10T16:01:31","detailUrl":"https://item.m.jd.com/product/5089273.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8284/363/1326459580/71585/6d3e8013/59b857f2N6ca75622.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9346/182/1406837243/282106/68af5b54/59b8480aNe8af7f5c.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8434/54/1359766007/56140/579509d9/59b85801Nfea207db.jpg!q70.jpg","num":1,"pid":46,"price":234,"pscid":39,"selected":1,"sellerid":2,"subhead":"【iPhone新品上市】新一代iPhone,让智能看起来更不一样","title":"Apple iPhone 8 Plus (A1864) 64GB 金色 移动联通电信4G手机"}],"sellerName":"商家2","sellerid":"2"},{"list":[{"bargainPrice":1599,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/1993026402.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t5863/302/8961270302/97126/41feade1/5981c81cNc1b1fbef.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7003/250/1488538438/195825/53bf31ba/5981c57eN51e95176.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5665/100/8954482513/43454/418611a9/5981c57eNd5fc97ba.jpg!q70.jpg","num":3,"pid":47,"price":111,"pscid":39,"selected":1,"sellerid":3,"subhead":"碳黑色 32GB 全网通 官方标配 1件","title":"锤子 坚果Pro 特别版 巧克力色 酒红色 全网通 移动联通电信4G手机 双卡双待 碳黑色 32GB 全网通"},{"bargainPrice":22.9,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":1,"pid":26,"price":88,"pscid":2,"selected":1,"sellerid":3,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"}],"sellerName":"商家3","sellerid":"3"},{"list":[{"bargainPrice":1999,"createtime":"2017-10-10T16:09:02","detailUrl":"https://item.m.jd.com/product/5025971.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t7210/232/3738666823/232298/9004583e/59c3a9a7N8de42e15.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8356/82/2107423621/109733/c019b8c6/59c3a9a6Ne9a4bdd7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t10219/74/25356012/171379/7d55e296/59c3a9a8N82fa6e02.jpg!q70.jpg","num":1,"pid":49,"price":333,"pscid":39,"selected":1,"sellerid":5,"subhead":"vivo X20 带你开启全面屏时代!逆光也清晰,照亮你的美!","title":"vivo X20 全面屏手机 全网通 4GB+64GB 金色 移动联通电信4G手机 双卡双待"}],"sellerName":"商家5","sellerid":"5"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":51,"price":555,"pscid":39,"selected":1,"sellerid":7,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"}],"sellerName":"商家7","sellerid":"7"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":5,"pid":54,"price":888,"pscid":39,"selected":1,"sellerid":10,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":111.99,"createtime":"2017-10-03T23:53:28","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":4,"pid":17,"price":299,"pscid":1,"selected":1,"sellerid":10,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家10","sellerid":"10"},{"list":[{"bargainPrice":3455,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/12224420750.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t9106/106/1785172479/537280/253bc0ab/59bf78a7N057e5ff7.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8461/5/1492479653/68388/7255e013/59ba5e84N91091843.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t8803/356/1478945529/489755/2a163ace/59ba5e84N7bb9a666.jpg!q70.jpg","num":1,"pid":56,"price":99,"pscid":39,"selected":1,"sellerid":12,"subhead":"【现货新品抢购】全面屏2.0震撼来袭,骁龙835处理器,四曲面陶瓷机","title":"小米(MI) 小米MIX2 手机 黑色 全网通 (6GB+64GB)【标配版】"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":68,"price":15000,"pscid":40,"selected":1,"sellerid":12,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家12","sellerid":"12"},{"list":[{"bargainPrice":111.99,"createtime":"2017-10-14T21:39:05","detailUrl":"https://item.m.jd.com/product/4719303.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t9004/210/1160833155/647627/ad6be059/59b4f4e1N9a2b1532.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7504/338/63721388/491286/f5957f53/598e95f1N7f2adb87.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t7441/10/64242474/419246/adb30a7d/598e95fbNd989ba0a.jpg!q70.jpg","num":1,"pid":2,"price":299,"pscid":1,"selected":1,"sellerid":18,"subhead":"每个中秋都不能简单,无论身在何处,你总需要一块饼让生活更圆满,京东月饼让爱更圆满京东自营,闪电配送,更多惊喜,快用手指戳一下","title":"北京稻香村 稻香村中秋节月饼 老北京月饼礼盒655g"}],"sellerName":"商家18","sellerid":"18"},{"list":[{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","num":1,"pid":79,"price":888,"pscid":40,"selected":1,"sellerid":23,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}],"sellerName":"商家23","sellerid":"23"}] * msg : 请求成功 */ private String code; private String msg; private List<DataBean> data; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean { /** * list : [{"bargainPrice":22.9,"createtime":"2017-10-14T21:48:08","detailUrl":"https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg","num":3,"pid":24,"price":288,"pscid":2,"selected":1,"sellerid":1,"subhead":"三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》","title":"三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋"},{"bargainPrice":99,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/4345173.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6037/35/2944615848/95178/6cd6cff0/594a3a10Na4ec7f39.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6607/258/1025744923/75738/da120a2d/594a3a12Ne3e6bc56.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t6370/292/1057025420/64655/f87644e3/594a3a12N5b900606.jpg!q70.jpg","num":3,"pid":45,"price":2999,"pscid":39,"selected":1,"sellerid":1,"subhead":"高清双摄,就是清晰!2000+1600万高清摄像头,6GB大内存+高通骁龙835处理器,性能怪兽!","title":"一加手机5 (A5000) 6GB+64GB 月岩灰 全网通 双卡双待 移动联通电信4G手机"}] * sellerName : 商家1 * sellerid : 1 */ private String sellerName; private String sellerid; private List<ListBean> list; public String getSellerName() { return sellerName; } public void setSellerName(String sellerName) { this.sellerName = sellerName; } public String getSellerid() { return sellerid; } public void setSellerid(String sellerid) { this.sellerid = sellerid; } public List<ListBean> getList() { return list; } public void setList(List<ListBean> list) { this.list = list; } public static class ListBean { /** * bargainPrice : 22.9 * createtime : 2017-10-14T21:48:08 * detailUrl : https://item.m.jd.com/product/2542855.html?utm_source=androidapp&utm_medium=appshare&utm_campaign=t_335139774&utm_term=QQfriends * images : https://m.360buyimg.com/n0/jfs/t1930/284/2865629620/390243/e3ade9c4/56f0a08fNbd3a1235.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2137/336/2802996626/155915/e5e90d7a/56f0a09cN33e01bd0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t1882/31/2772215910/389956/c8dbf370/56f0a0a2Na0c86ea6.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t2620/166/2703833710/312660/531aa913/57709035N33857877.jpg!q70.jpg * num : 3 * pid : 24 * price : 288.0 * pscid : 2 * selected : 1 * sellerid : 1 * subhead : 三只松鼠零食特惠,专区满99减50,满199减100,火速抢购》 * title : 三只松鼠 坚果炒货 零食奶油味 碧根果225g/袋 */ private double bargainPrice; private String createtime; private String detailUrl; private String images; private int num; private int pid; private double price; private int pscid; private int selected; private int sellerid; private String subhead; private String title; public double getBargainPrice() { return bargainPrice; } public void setBargainPrice(double bargainPrice) { this.bargainPrice = bargainPrice; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getDetailUrl() { return detailUrl; } public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public int getNum() { return num; } public void setNum(int num) { this.num = num; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } public int getSelected() { return selected; } public void setSelected(int selected) { this.selected = selected; } public int getSellerid() { return sellerid; } public void setSellerid(int sellerid) { this.sellerid = sellerid; } public String getSubhead() { return subhead; } public void setSubhead(String subhead) { this.subhead = subhead; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } } }
UserBean
package com.example.shopcartdome.bean; /** * Created by Administrator on 2018/5/3. */ public class UserBean { /** * msg : 登录成功 * code : 0 * data : {"age":null,"appkey":"07258a7bbfd8b132","appsecret":"E243E12B205A861F4BBC0492A373A36F", * "createtime":"2018-04-25T09:32:05","email":null,"fans":null,"follow":null,"gender":null,"icon":null, * "latitude":null,"longitude":null,"mobile":"18310830365","money":null,"nickname":null, * "password":"8F669074CAF5513351A2DE5CC22AC04C","praiseNum":null,"token":"5B5E60DC8960BA6DBCF3CBA638A1EC32", * "uid":1235,"userId":null,"username":"18310830365"} */ private String msg; private String code; private DataBean data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public DataBean getData() { return data; } public void setData(DataBean data) { this.data = data; } public static class DataBean { /** * age : null * appkey : 07258a7bbfd8b132 * appsecret : E243E12B205A861F4BBC0492A373A36F * createtime : 2018-04-25T09:32:05 * email : null * fans : null * follow : null * gender : null * icon : null * latitude : null * longitude : null * mobile : 18310830365 * money : null * nickname : null * password : 8F669074CAF5513351A2DE5CC22AC04C * praiseNum : null * token : 5B5E60DC8960BA6DBCF3CBA638A1EC32 * uid : 1235 * userId : null * username : 18310830365 */ private Object age; private String appkey; private String appsecret; private String createtime; private Object email; private Object fans; private Object follow; private Object gender; private Object icon; private Object latitude; private Object longitude; private String mobile; private Object money; private Object nickname; private String password; private Object praiseNum; private String token; private int uid; private Object userId; private String username; public Object getAge() { return age; } public void setAge(Object age) { this.age = age; } public String getAppkey() { return appkey; } public void setAppkey(String appkey) { this.appkey = appkey; } public String getAppsecret() { return appsecret; } public void setAppsecret(String appsecret) { this.appsecret = appsecret; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Object getEmail() { return email; } public void setEmail(Object email) { this.email = email; } public Object getFans() { return fans; } public void setFans(Object fans) { this.fans = fans; } public Object getFollow() { return follow; } public void setFollow(Object follow) { this.follow = follow; } public Object getGender() { return gender; } public void setGender(Object gender) { this.gender = gender; } public Object getIcon() { return icon; } public void setIcon(Object icon) { this.icon = icon; } public Object getLatitude() { return latitude; } public void setLatitude(Object latitude) { this.latitude = latitude; } public Object getLongitude() { return longitude; } public void setLongitude(Object longitude) { this.longitude = longitude; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; } public Object getMoney() { return money; } public void setMoney(Object money) { this.money = money; } public Object getNickname() { return nickname; } public void setNickname(Object nickname) { this.nickname = nickname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Object getPraiseNum() { return praiseNum; } public void setPraiseNum(Object praiseNum) { this.praiseNum = praiseNum; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public Object getUserId() { return userId; } public void setUserId(Object userId) { this.userId = userId; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } } }