diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..aa724b7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,15 @@
+*.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
+local.properties
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..3f3f247
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..2a4d5b5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..42afabf
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..1cea42e
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,45 @@
+plugins {
+ id 'com.android.application'
+}
+
+android {
+ namespace 'com.example.test'
+ compileSdk 33
+
+ defaultConfig {
+ applicationId "com.example.test"
+ minSdk 27
+ targetSdk 33
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ debuggable true
+ }
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+}
+
+dependencies {
+
+ implementation 'com.github.gittjy:LoadingDialog:1.0.2'
+ implementation 'androidx.appcompat:appcompat:1.3.0'
+ implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.12'
+ implementation "com.squareup.okhttp3:okhttp:4.2.2"
+ implementation 'com.google.android.material:material:1.5.0'
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
+ testImplementation 'junit:junit:4.13.2'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+ implementation 'com.github.crazyandcoder:citypicker:6.0.2'
+ implementation 'com.github.zzz40500:android-shapeLoadingView:1.0.3.2'
+}
\ No newline at end of file
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..481bb43
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -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
\ No newline at end of file
diff --git a/app/src/androidTest/java/com/example/test/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/test/ExampleInstrumentedTest.java
new file mode 100644
index 0000000..6ea62a5
--- /dev/null
+++ b/app/src/androidTest/java/com/example/test/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.example.test;
+
+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 Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.example.test", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..54fc865
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/test/MainActivity.java b/app/src/main/java/com/example/test/MainActivity.java
new file mode 100644
index 0000000..6dc550d
--- /dev/null
+++ b/app/src/main/java/com/example/test/MainActivity.java
@@ -0,0 +1,96 @@
+package com.example.test;
+
+
+import android.content.Intent;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.os.Looper;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.example.test.activity.HomeActivity;
+import com.example.test.activity.RegisterActivity;
+import com.example.test.entity.User;
+import com.example.test.netrequest.UserOkHttp;
+import com.example.test.utils.Address;
+
+import java.io.IOException;
+
+public class MainActivity extends AppCompatActivity implements View.OnClickListener {
+ private Button registerButton, loginButton;
+ private EditText usernameText, paswdEdit;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.login);
+ init();
+ }
+
+
+ @Override
+ public void onClick(View view) {
+ switch (view.getId()){
+ case R.id.register:
+ Intent intent = new Intent(this, RegisterActivity.class);
+ startActivity(intent);
+ break;
+ case R.id.login:
+ Thread thread = new Thread(login);
+ thread.start();
+
+
+
+ }
+ }
+
+
+
+ public void init(){
+ registerButton = findViewById(R.id.register);
+ registerButton.setOnClickListener(this);
+ loginButton = findViewById(R.id.login);
+ loginButton.setOnClickListener(this);
+ usernameText = findViewById(R.id.username);
+ paswdEdit = findViewById(R.id.password);
+ }
+
+
+ Runnable login = new Runnable() {
+ @Override
+ public void run() {
+ String name = usernameText.getText().toString();
+ String pass = paswdEdit.getText().toString();
+ UserOkHttp userOkHttp = new UserOkHttp();
+ User u = new User();
+ u.setUsername(name);
+ u.setPassword(pass);
+ try {
+ User result = userOkHttp.login(u);
+ if(result!=null){
+ Intent intent = new Intent(MainActivity.this, HomeActivity.class);
+ Bundle bundle = new Bundle();
+ bundle.putString("username",result.getUsername());
+ bundle.putString("password",result.getPassword());
+ bundle.putString("sex",result.getSex());
+ bundle.putString("city",result.getCity());
+ bundle.putInt("id",result.getId());
+ intent.putExtras(bundle);
+ startActivity(intent);
+ }else{
+ Looper.prepare();
+ Toast.makeText(MainActivity.this,"用户名或密码错误",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+ };
+}
diff --git a/app/src/main/java/com/example/test/activity/HomeActivity.java b/app/src/main/java/com/example/test/activity/HomeActivity.java
new file mode 100644
index 0000000..d24f83e
--- /dev/null
+++ b/app/src/main/java/com/example/test/activity/HomeActivity.java
@@ -0,0 +1,306 @@
+package com.example.test.activity;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
+
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.GridView;
+import android.widget.Toast;
+
+import com.example.test.R;
+import com.example.test.adapter.HomeNavigationBottomAdapter;
+import com.example.test.entity.Cart;
+import com.example.test.entity.Product;
+import com.example.test.entity.ProductKind;
+import com.example.test.entity.ProductKindStorage;
+import com.example.test.entity.ProductStorage;
+import com.example.test.fragment.NavigationCartFragment;
+import com.example.test.fragment.NavigationGoodFragment;
+import com.example.test.fragment.NavigationHomeFragment;
+import com.example.test.fragment.NavigationLoadingFragment;
+import com.example.test.fragment.NavigationPersonFragment;
+import com.example.test.netrequest.CartOkHttp;
+import com.example.test.netrequest.ProductOkHttp;
+import com.example.test.service.MessageService;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+public class HomeActivity extends AppCompatActivity {
+ public static final int Home = 1;
+ public static final int Good = 2;
+ public static final int Cart = 3;
+ public static final int Person = 4;
+ public static final int Navigation = 5;
+ public static final int InsertProductToCart = 6;
+ public static final int LoadingData = 7;
+ public static final int UpdateCart = 7;
+ private int selectedProductId;
+ private ProductKindStorage productKindStorage = new ProductKindStorage();
+ private ProductStorage hotProductStorage = new ProductStorage();
+ private NavigationHomeFragment homeFragment = new NavigationHomeFragment();
+ private NavigationGoodFragment goodFragment = new NavigationGoodFragment();
+ private NavigationLoadingFragment loadingFragment = new NavigationLoadingFragment();
+ private NavigationCartFragment cartFragment = new NavigationCartFragment();
+ private NavigationPersonFragment personFragment = new NavigationPersonFragment();
+ private int sectionImgs[] = {R.drawable.section_home,R.drawable.section_good,
+ R.drawable.section_cart,R.drawable.section_mine};
+ private String sectionNames[] ={"首页","商品","购物车","我"};
+ public FragmentManager getManager() {
+ return manager;
+ }
+ public FragmentManager manager = getSupportFragmentManager();
+ private Bundle extras;
+ public Handler getHandler() {
+ return handler;
+ }
+ public Bundle getBundle(){
+ return extras;
+ }
+
+ public ProductKindStorage getProductKindStorage() {
+ return productKindStorage;
+ }
+ public ProductStorage getHotProductStorage() {
+ return hotProductStorage;
+ }
+ private Handler handler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message message) {
+ switch (message.what){
+ case Good:
+ changeFragment(goodFragment);
+ return true;
+
+ case Cart:
+ changeFragment(new NavigationCartFragment());
+ return true;
+
+ case Navigation:
+ initNavigation();
+ changeFragment(homeFragment);
+ return true;
+
+ case InsertProductToCart:
+// 添加商品进购物车
+ Map map = (Map) message.obj;
+ selectedProductId = (Integer) map.get("productId");
+ new Thread(insertProduct).start();
+ return true;
+
+ case LoadingData:
+ new Thread(getCart).start();
+ return true;
+ }
+ return false;
+ }
+ });
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.navigation);
+ Intent service = new Intent(HomeActivity.this, MessageService.class);
+ startService(service);
+ //获取登陆所携带的用户信息
+ Intent intent = getIntent();
+ extras = intent.getExtras();
+ initData();
+// 在initData中默认加载homeFragment
+
+ }
+
+ public void initData() {
+ //获取商品类别
+ new Thread(getProductKind).start();
+// 获取热门商品
+ new Thread(getHotProduct).start();
+
+ }
+
+
+ public void changeFragment(Fragment fragment){
+ FragmentTransaction transaction = manager.beginTransaction();
+ transaction.replace(R.id.navigation_section,fragment);
+ transaction.commit();
+ }
+
+ //初始化底端导航栏
+ protected void initNavigation(){
+
+ GridView navigation = (GridView)findViewById(R.id.home_navigation_bottom_gridview);
+ HomeNavigationBottomAdapter navigationAdapter = new HomeNavigationBottomAdapter(sectionImgs,sectionNames,this);
+ navigation.setAdapter(navigationAdapter);
+ navigation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ switch (position){
+ case 0:
+ changeFragment(homeFragment);
+ break;
+ case 1:
+ changeFragment(goodFragment);
+ break;
+ case 2:
+ changeFragment(loadingFragment);
+ break;
+ case 3:
+ changeFragment(personFragment);
+ break;
+ }
+ }
+ });
+ }
+
+ //获取产品种类
+ Runnable getProductKind = new Runnable() {
+ @Override
+ public void run() {
+ ProductOkHttp http = new ProductOkHttp();
+ try {
+ List productKinds = http.getProductKind();
+ if(productKinds!=null){
+ for (ProductKind p : productKinds) {
+ productKindStorage.getNames().add(p.getName());
+ productKindStorage.getBitmaps().add(http.getImg(p.getImgUrl()));
+ }
+ }else
+ {
+ Looper.prepare();
+ Toast.makeText(HomeActivity.this,"商品种类获取失败",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+
+ Runnable getHotProduct = new Runnable() {
+ @Override
+ public void run() {
+ ProductOkHttp productOkHttp = new ProductOkHttp();
+ try {
+ List products = productOkHttp.getHotProduct();
+ if(products != null){
+ for (Product product : products) {
+ hotProductStorage.getIds().add(product.getId());
+ hotProductStorage.getNames().add(product.getName());
+ hotProductStorage.getBitmaps().add(productOkHttp.getImg(product.getImgUrl()));
+ hotProductStorage.getPrices().add(product.getPrice());
+ hotProductStorage.getDescriptions().add(product.getDescription());
+ hotProductStorage.getTags().add(product.getTag());
+ hotProductStorage.getKinds().add(product.getKind());
+ }
+ Message message = new Message();
+ message.what = Navigation;
+ handler.sendMessage(message);
+ }else {
+ Looper.prepare();
+ Toast.makeText(HomeActivity.this,"商品获取失败",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+
+ }
+ };
+
+
+ Runnable getCart = new Runnable() {
+ @Override
+ public void run() {
+ CartOkHttp cartOkHttp = new CartOkHttp();
+ ProductOkHttp productOkHttp = new ProductOkHttp();
+ try {
+ int userId = (int) extras.get("id");
+ List carts = cartOkHttp.selectByUserId(userId);
+ if(carts.size()!=0){
+ cartFragment.clearLists();
+ List ids = NavigationCartFragment.productIds;
+ List names = NavigationCartFragment.names;
+ List bitmaps = NavigationCartFragment.bitmaps;
+ List prices = NavigationCartFragment.prices;
+ List nums = NavigationCartFragment.nums;
+ for (com.example.test.entity.Cart cart : carts) {
+ Integer productId = cart.getProductId();
+ Product product = productOkHttp.getProductById(productId);
+ ids.add(product.getId());
+ names.add(product.getName());
+ bitmaps.add(productOkHttp.getImg(product.getImgUrl()));
+ prices.add(product.getPrice());
+ nums.add(cart.getNum());
+ }
+ Message message = new Message();
+ message.what = Cart;
+ handler.sendMessage(message);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ Runnable insertProduct = new Runnable() {
+ @Override
+ public void run() {
+ Cart c = new Cart(extras.getInt("id"),selectedProductId,1);
+ CartOkHttp okHttp = new CartOkHttp();
+// 是否包含该商品
+ int postion = containProduct(selectedProductId);
+// 包含就加1
+ if(postion!=-1){
+ try {
+ int num = NavigationCartFragment.nums.get(postion);
+ c.setNum(num+1);
+ boolean updateResult = okHttp.updateCart(c);
+ if(!updateResult){
+ Looper.prepare();
+ Toast.makeText(HomeActivity.this,"添加失败",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }else{ //不包含新增
+ try {
+ boolean insertResult = okHttp.insertCart(c);
+ if(!insertResult){
+ Looper.prepare();
+ Toast.makeText(HomeActivity.this,"添加失败",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ };
+
+ public int containProduct(int id){
+ int positon = 0;
+ List ids = NavigationCartFragment.productIds;
+ for (Integer integer : ids) {
+ if(id==integer){
+ return positon;
+ }
+ positon++;
+ }
+ return -1;
+ }
+}
diff --git a/app/src/main/java/com/example/test/activity/RegisterActivity.java b/app/src/main/java/com/example/test/activity/RegisterActivity.java
new file mode 100644
index 0000000..c362975
--- /dev/null
+++ b/app/src/main/java/com/example/test/activity/RegisterActivity.java
@@ -0,0 +1,184 @@
+package com.example.test.activity;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import android.content.ContentValues;
+import android.content.Intent;
+import android.database.sqlite.SQLiteDatabase;
+import android.os.Bundle;
+import android.os.Looper;
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.RadioGroup;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.example.test.MainActivity;
+import com.example.test.R;
+import com.example.test.entity.User;
+import com.example.test.netrequest.UserOkHttp;
+import com.lljjcoder.Interface.OnCityItemClickListener;
+import com.lljjcoder.bean.CityBean;
+import com.lljjcoder.bean.DistrictBean;
+import com.lljjcoder.bean.ProvinceBean;
+import com.lljjcoder.citywheel.CityConfig;
+import com.lljjcoder.style.citypickerview.CityPickerView;
+
+import java.io.IOException;
+
+public class RegisterActivity extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
+ private EditText userEdit;
+ private EditText passEdit;
+ private EditText paEdit;
+ private RadioGroup sexBut;
+ private TextView adressText;
+ private String sex ="男";
+ private Button regBut;
+ CityPickerView citypv;
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.register);
+ init();
+ }
+
+ public void init(){
+ citypv = new CityPickerView();
+ citypv.init(this);
+ initConfig();
+ citypv.setOnCityItemClickListener(new OnCityItemClickListener() {
+ @Override
+ public void onSelected(ProvinceBean province, CityBean city, DistrictBean district) {
+ String pro = province.getName();
+ String ci = city.getName();
+ String dis = district.getName();
+ adressText.setText(String.format("%s %s %s",pro,ci,dis));
+ }
+
+ @Override
+ public void onCancel() {
+ }
+ });
+ userEdit = findViewById(R.id.reg_username);
+ passEdit = findViewById(R.id.reg_password);
+ paEdit = findViewById(R.id.reg_apassword);
+ adressText = findViewById(R.id.reg_adress);
+ adressText.setOnClickListener(this);
+ sexBut = findViewById(R.id.reg_sex);
+ sexBut.setOnCheckedChangeListener(this);
+ regBut = findViewById(R.id.reg_register);
+ regBut.setOnClickListener(this);
+ }
+
+ private void initConfig() {
+ CityConfig cityConfig = new CityConfig.Builder()
+ .title("选择城市")//标题
+ .titleTextSize(18)//标题文字大小
+ .titleTextColor("#585858")//标题文字颜 色
+ .titleBackgroundColor("#E9E9E9")//标题栏背景色
+ .confirTextColor("#585858")//确认按钮文字颜色
+ .confirmText("ok")//确认按钮文字
+ .confirmTextSize(16)//确认按钮文字大小
+ .cancelTextColor("#585858")//取消按钮文字颜色
+ .cancelText("cancel")//取消按钮文字
+ .cancelTextSize(16)//取消按钮文字大小
+ .setCityWheelType(CityConfig.WheelType.PRO_CITY_DIS)//显示类,只显示省份一级,显示省市两级还是显示省市区三级
+ .showBackground(true)//是否显示半透明背景
+ .visibleItemsCount(7)//显示item的数量
+ .province("浙江省")//默认显示的省份
+ .city("杭州市")//默认显示省份下面的城市
+ .district("滨江区")//默认显示省市下面的区县数据
+ .provinceCyclic(true)//省份滚轮是否可以循环滚动
+ .cityCyclic(true)//城市滚轮是否可以循环滚动
+ .districtCyclic(true)//区县滚轮是否循环滚动
+ .drawShadows(false)//滚轮不显示模糊效果
+ .setLineColor("#03a9f4")//中间横线的颜色
+ .setLineHeigh(5)//中间横线的高度
+ .setShowGAT(true)//是否显示港澳台数据,默认不显示
+ .build();
+ citypv.setConfig(cityConfig);
+ }
+
+
+
+
+ @Override
+ public void onClick(View view) {
+ switch (view.getId()){
+ case R.id.reg_adress:
+ citypv.showCityPicker();
+ break;
+ case R.id.reg_register:
+ Thread thread = new Thread(register);
+ thread.start();
+ break;
+ }
+ }
+
+
+
+
+
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ //根据用户选择来改变sex的值
+ sex = R.id.reg_male==checkedId?"男":"女";
+ }
+
+
+ Runnable register = new Runnable() {
+ @Override
+ public void run() {
+ Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
+ String username = userEdit.getText().toString();
+ String password = passEdit.getText().toString();
+ String apassword = paEdit.getText().toString();
+ String adress = adressText.getText().toString();
+ if(password.equals(apassword)){
+ if(username.isEmpty()||password.isEmpty()){
+ Looper.prepare();
+ Toast.makeText(RegisterActivity.this,"用户名或密码为空",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }else {
+ if(adress.equals("")||adress.equals("地址选择")) {
+ Looper.prepare();
+ Toast.makeText(RegisterActivity.this, "未选择地址", Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ else{
+ User u = new User(username,password,sex,adress);
+ UserOkHttp http = new UserOkHttp();
+ try {
+ boolean selectResult = http.selectUser(username);
+ if(!selectResult){
+ Looper.prepare();
+ Toast.makeText(RegisterActivity.this, "用户名已存在", Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ return;
+ }
+ boolean register = http.register(u);
+ if(register)
+ {
+ startActivity(intent);
+ }else{
+ Looper.prepare();
+ Toast.makeText(RegisterActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+ else {
+ Looper.prepare();
+ Toast.makeText(RegisterActivity.this,"两次密码不一致",Toast.LENGTH_SHORT).show();
+ Looper.loop();
+ }
+ }
+ };
+
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/test/adapter/CartAdapter.java b/app/src/main/java/com/example/test/adapter/CartAdapter.java
new file mode 100644
index 0000000..fc362c5
--- /dev/null
+++ b/app/src/main/java/com/example/test/adapter/CartAdapter.java
@@ -0,0 +1,177 @@
+package com.example.test.adapter;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.example.test.R;
+import com.example.test.activity.HomeActivity;
+import com.example.test.entity.Cart;
+import com.example.test.fragment.NavigationCartFragment;
+import com.example.test.netrequest.CartOkHttp;
+import com.example.test.utils.LoadingDialog;
+
+import java.io.IOException;
+import java.io.PipedReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.PrimitiveIterator;
+
+public class CartAdapter extends BaseAdapter {
+ private List bitmaps;
+ private List names;
+ private List prices;
+ private List nums;
+ private List productIds;
+ private Context context;
+ private Handler handler;
+ private int userId;
+ public int selectedNum;
+ public int selectedProductId;
+ private viewHolder holder;
+ private List status = new ArrayList<>();
+
+
+ public CartAdapter(List bitmaps, List names, List prices, List nums , List productIds, Handler handler,int userId , Context context) {
+ this.bitmaps = bitmaps;
+ this.names = names;
+ this.prices = prices;
+ this.nums = nums;
+ this.context = context;
+ this.userId = userId;
+ this.productIds = productIds;
+ this.handler = handler;
+ }
+
+ public CartAdapter(Context context) {
+ this.context = context;
+ }
+
+ @Override
+ public int getCount() {
+ return bitmaps.size();
+ }
+
+ @Override
+ public Object getItem(int i) {
+ List