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 list = new ArrayList<>(); + list.add(bitmaps.get(i)); + list.add(names.get(i)); + list.add(prices.get(i)); + list.add(nums.get(i)); + return list; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View convertView, ViewGroup viewGroup) { + if(convertView==null){ + holder = new viewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.cart_listview_item,null); + holder.ivImg = convertView.findViewById(R.id.cart_good_img); + holder.tvName = convertView.findViewById(R.id.cart_good_name); + holder.tvPrice = convertView.findViewById(R.id.cart_good_price); + holder.tvNum = convertView.findViewById(R.id.cart_good_num); + holder.ibAdd = convertView.findViewById(R.id.cart_good_add); + holder.ibSub = convertView.findViewById(R.id.cart_good_minus); + holder.cbChecked = convertView.findViewById(R.id.cart_checked); + convertView.setTag(holder); + }else { + holder = (viewHolder) convertView.getTag(); + } + + holder.ivImg.setImageBitmap(bitmaps.get(i)); + holder.tvName.setText(names.get(i)); + holder.tvPrice.setText(prices.get(i)+""); + holder.tvNum.setText(nums.get(i)+""); + holder.ibAdd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //计算点击之后的数量 + selectedNum = nums.get(i)+1; + selectedProductId = productIds.get(i); + new Thread(updateCart).start(); + } + }); + + holder.ibSub.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + //计算点击之后的数量 + selectedNum = nums.get(i)-1; + selectedProductId = productIds.get(i); + new Thread(updateCart).start(); + } + }); + + holder.cbChecked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + if(b){ + NavigationCartFragment.checkedProductIds.add(productIds.get(i)); + }else{ + NavigationCartFragment.checkedProductIds.remove(productIds.get(i)); + } + Message message = new Message(); + message.what = NavigationCartFragment.updatePrice; + handler.sendMessage(message); + + } + }); + + return convertView; + } + static class viewHolder{ + ImageView ivImg; + TextView tvName; + TextView tvPrice; + TextView tvNum; + ImageButton ibAdd; + ImageButton ibSub; + CheckBox cbChecked; + + } + + Runnable updateCart = new Runnable() { + @Override + public void run() { + Looper.prepare(); + LoadingDialog dialog = new LoadingDialog.Builder(context, "加载中").create(); + dialog.show(); + CartOkHttp cartOkHttp = new CartOkHttp(); + Cart cart = new Cart(userId, selectedProductId, selectedNum); + try { + boolean updateResult = cartOkHttp.updateCart(cart); + dialog.dismiss(); + if(!updateResult){ + Toast.makeText(context,"更新失败",Toast.LENGTH_SHORT).show(); + Looper.loop(); + }else{ + holder.tvNum.setText(selectedNum+""); + Message message = new Message(); + message.what = NavigationCartFragment.updateCart; + handler.sendMessage(message); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; +} diff --git a/app/src/main/java/com/example/test/adapter/CartDetailAdapter.java b/app/src/main/java/com/example/test/adapter/CartDetailAdapter.java new file mode 100644 index 0000000..85301d6 --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/CartDetailAdapter.java @@ -0,0 +1,63 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.graphics.Bitmap; +import android.os.Message; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.CheckBox; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CartDetailAdapter extends BaseAdapter { + private Context context; + private List bitmaps; + private viewHolder holder; + + public CartDetailAdapter(Context context, List bitmaps) { + this.context = context; + this.bitmaps = bitmaps; + } + + @Override + public int getCount() { + return bitmaps.size(); + } + + @Override + public Object getItem(int i) { + return bitmaps.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View convertView, ViewGroup viewGroup) { + if(convertView==null){ + holder = new viewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.cart_detail_item,null); + holder.ivImg = convertView.findViewById(R.id.cart_detail_gridview_img); + convertView.setTag(holder); + }else { + holder = (viewHolder) convertView.getTag(); + } + holder.ivImg.setImageBitmap(bitmaps.get(i)); + return convertView; + } + static class viewHolder{ + private ImageView ivImg; + } +} diff --git a/app/src/main/java/com/example/test/adapter/GoodItemAdapter.java b/app/src/main/java/com/example/test/adapter/GoodItemAdapter.java new file mode 100644 index 0000000..0ebe808 --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/GoodItemAdapter.java @@ -0,0 +1,117 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.graphics.Bitmap; +import android.icu.text.DateFormat; +import android.os.Handler; +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.ImageView; +import android.widget.TextView; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; +import com.example.test.entity.ProductStorage; + +import java.io.PipedReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GoodItemAdapter extends BaseAdapter { + private List ids; + private List names; + private List bitmaps; + private List prices; + private List descriptions; + private List tags; + private List kinds; + private Context context; + private viewHolder holder; + private Handler handler; + + + public GoodItemAdapter(ProductStorage productStorage, Handler handler,Context context) { + this.ids = productStorage.getIds(); + this.names = productStorage.getNames(); + this.bitmaps = productStorage.getBitmaps(); + this.prices = productStorage.getPrices(); + this.descriptions = productStorage.getDescriptions(); + this.tags = productStorage.getTags(); + this.kinds = productStorage.getKinds(); + this.context = context; + this.handler = handler; + } + + @Override + public int getCount() { + return ids.size(); + } + + @Override + public Object getItem(int i) { + List list = new ArrayList(); + list.add(ids.get(i)); + list.add(names.get(i)); + list.add(bitmaps.get(i)); + list.add(prices.get(i)); + list.add(descriptions.get(i)); + list.add(tags.get(i)); + list.add(kinds.get(i)); + return list; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View convertView, ViewGroup viewGroup) { + if(convertView==null){ + holder = new viewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.good_item_listview_item,null); + holder.ivImg = convertView.findViewById(R.id.good_item_listview_img); + holder.tvName = convertView.findViewById(R.id.good_item_listview_name); + holder.tvDescription = convertView.findViewById(R.id.good_item_listview_description); + holder.tvTag = convertView.findViewById(R.id.good_item_listview_tag); + holder.tvPrice = convertView.findViewById(R.id.good_item_listview_price); + holder.ivCart = convertView.findViewById(R.id.good_item_listview_cart); + holder.ivCart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Map map = new HashMap(); + map.put("productId",ids.get(i)); + Message message = new Message(); + message.what = HomeActivity.InsertProductToCart; + message.obj = map; + handler.sendMessage(message); + + } + }); + convertView.setTag(holder); + }else { + holder = (viewHolder) convertView.getTag(); + } + holder.ivImg.setImageBitmap(bitmaps.get(i)); + holder.tvName.setText(names.get(i)); + holder.tvDescription.setText(descriptions.get(i)); + holder.tvTag.setText(tags.get(i)); + holder.tvPrice.setText("¥"+prices.get(i)+""); + return convertView; + } + + static class viewHolder{ + ImageView ivImg; + TextView tvName; + TextView tvDescription; + TextView tvTag; + TextView tvPrice; + ImageView ivCart; + } +} diff --git a/app/src/main/java/com/example/test/adapter/GoodKindAdapter.java b/app/src/main/java/com/example/test/adapter/GoodKindAdapter.java new file mode 100644 index 0000000..8e3a066 --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/GoodKindAdapter.java @@ -0,0 +1,61 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.example.test.R; + +import java.util.List; + +public class GoodKindAdapter extends BaseAdapter { + private Context context; + private List kinds; + private viewHolder holder; + private int selected =0; + + public GoodKindAdapter(Context context, List kinds) { + this.context = context; + this.kinds = kinds; + } + + @Override + public int getCount() { + return kinds.size(); + } + + @Override + public Object getItem(int i) { + return kinds.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + if(view==null){ + view = LayoutInflater.from(context).inflate(R.layout.good_kind_listview_item,null); + if(i==selected){ + view.setBackgroundColor(Color.rgb(192,192,192)); + } + holder = new viewHolder(); + holder.tvKind = view.findViewById(R.id.good_kind_listview_kind); + view.setTag(holder); + }else { + holder = (viewHolder) view.getTag(); + } + holder.tvKind.setText(kinds.get(i)); + return view; + } + + static class viewHolder{ + TextView tvKind; + } +} diff --git a/app/src/main/java/com/example/test/adapter/HomeNavigationBottomAdapter.java b/app/src/main/java/com/example/test/adapter/HomeNavigationBottomAdapter.java new file mode 100644 index 0000000..00bff0a --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/HomeNavigationBottomAdapter.java @@ -0,0 +1,66 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.test.R; + +import java.util.HashMap; +import java.util.Map; + +public class HomeNavigationBottomAdapter extends BaseAdapter { + private int imgs[]; + private String names[]; + private Context context; + + public HomeNavigationBottomAdapter(int[] imgs, String[] names, Context context) { + this.imgs = imgs; + this.names = names; + this.context = context; + } + + @Override + public int getCount() { + return imgs.length; + } + + @Override + public Object getItem(int position) { + Map section = new HashMap<>(); + section.put("img",imgs[position]); + section.put("name",names[position]); + return section; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + viewHolder holder; + if(convertView==null){ + holder = new viewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.home_navigation_bottom_item,null); + holder.ivImg = convertView.findViewById(R.id.home_navigation_bottom_img); + holder.tvName = convertView.findViewById(R.id.home_navigation_bottom_name); + convertView.setTag(holder); + }else { + holder = (viewHolder) convertView.getTag(); + } + holder.ivImg.setImageResource(imgs[position]); + holder.tvName.setText(names[position]); + return convertView; + } + + static class viewHolder{ + ImageView ivImg; + TextView tvName; + } +} diff --git a/app/src/main/java/com/example/test/adapter/HomeProductAdapter.java b/app/src/main/java/com/example/test/adapter/HomeProductAdapter.java new file mode 100644 index 0000000..010cbcf --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/HomeProductAdapter.java @@ -0,0 +1,97 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.graphics.Bitmap; +import android.os.Handler; +import android.os.Message; +import android.telephony.SmsManager; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class HomeProductAdapter extends BaseAdapter { + private List names; + private List prices; + private List bitmaps; + private List ids; + private Context context; + private Handler handler; + + + public HomeProductAdapter(List bitmaps, List names, List prices, List ids, Context context, Handler handler) { + this.bitmaps = bitmaps; + this.names = names; + this.prices = prices; + this.ids = ids; + this.context = context; + this.handler = handler; + } + + @Override + public int getCount() { + return names.size(); + } + + @Override + public Object getItem(int position) { + Map fruit = new HashMap<>(); + fruit.put("bitmap",bitmaps.get(position)); + fruit.put("name",names.get(position)); + fruit.put("price",prices.get(position)); + return fruit; + } + + @Override + public long getItemId(int position) { + return position; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + viewHolder holder; + if(convertView==null){ + holder = new viewHolder(); + convertView = LayoutInflater.from(context).inflate(R.layout.home_goods_fruit_item,null); + holder.ivImg = convertView.findViewById(R.id.home_goods_fruit_img); + holder.tvName = convertView.findViewById(R.id.home_goods_fruit_name); + holder.tvPrice = convertView.findViewById(R.id.home_goods_fruit_price); + holder.ivCart = convertView.findViewById(R.id.navigation_cart); + holder.ivCart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Map cartItem = new HashMap<>(); + cartItem.put("productId",ids.get(position)); + Message message = new Message(); + message.what = HomeActivity.InsertProductToCart; + message.obj = cartItem; + handler.sendMessage(message); + } + }); + convertView.setTag(holder); + }else { + holder = (viewHolder) convertView.getTag(); + } + holder.ivImg.setImageBitmap(bitmaps.get(position)); + holder.tvName.setText(names.get(position)); + holder.tvPrice.setText("¥"+prices.get(position)+""); + return convertView; + } + static class viewHolder{ + ImageView ivImg; + TextView tvName; + TextView tvPrice; + ImageView ivCart; + } +} diff --git a/app/src/main/java/com/example/test/adapter/HomeProductKindAdapter.java b/app/src/main/java/com/example/test/adapter/HomeProductKindAdapter.java new file mode 100644 index 0000000..e5c0d23 --- /dev/null +++ b/app/src/main/java/com/example/test/adapter/HomeProductKindAdapter.java @@ -0,0 +1,55 @@ +package com.example.test.adapter; + +import android.content.Context; +import android.graphics.Bitmap; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import com.example.test.R; + +import java.util.ArrayList; +import java.util.List; + +public class HomeProductKindAdapter extends BaseAdapter { + private List names; + private List bitmaps; + private Context context; + + + public HomeProductKindAdapter(Listbitmaps,List names, Context context) { + this.bitmaps = bitmaps; + this.names = names; + this.context = context; + } + @Override + public int getCount() { + return names.size(); + } + + @Override + public Object getItem(int i) { + List fruit = new ArrayList<>(); + fruit.add(bitmaps.get(i)); + fruit.add(names.get(i)); + return fruit; + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View ConvertView, ViewGroup viewGroup) { + View view = LayoutInflater.from(context).inflate(R.layout.home_fruit_kind_item,null); + ImageView img = view.findViewById(R.id.home_fruit_kind_img); + TextView name = view.findViewById(R.id.home_fruit_kind_name); + img.setImageBitmap(bitmaps.get(i)); + name.setText(names.get(i)); + return view; + } +} diff --git a/app/src/main/java/com/example/test/entity/Cart.java b/app/src/main/java/com/example/test/entity/Cart.java new file mode 100644 index 0000000..df82f88 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/Cart.java @@ -0,0 +1,50 @@ +package com.example.test.entity; + +public class Cart { + private Integer id; + private Integer userId; + private Integer productId; + private Integer num; + + public Cart(Integer userId, Integer productId, Integer num) { + this.id = id; + this.userId = userId; + this.productId = productId; + this.num = num; + } + + public Cart() { + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getUserId() { + return userId; + } + + public void setUserId(Integer userId) { + this.userId = userId; + } + + public Integer getProductId() { + return productId; + } + + public void setProductId(Integer productId) { + this.productId = productId; + } + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } +} diff --git a/app/src/main/java/com/example/test/entity/Message.java b/app/src/main/java/com/example/test/entity/Message.java new file mode 100644 index 0000000..b4a6ec5 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/Message.java @@ -0,0 +1,52 @@ +package com.example.test.entity; + +import java.sql.Timestamp; + +public class Message { + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Timestamp getSendTime() { + return sendTime; + } + + public void setSendTime(Timestamp sendTime) { + this.sendTime = sendTime; + } + + public String getUsed() { + return used; + } + + public void setUsed(String used) { + this.used = used; + } + + private Integer id; + private String content; + private Timestamp sendTime; + private String used; + + @Override + public String toString() { + return "OrangeMessage{" + + "id=" + id + + ", content='" + content + '\'' + + ", sendTime=" + sendTime + + ", used='" + used + '\'' + + '}'; + } +} diff --git a/app/src/main/java/com/example/test/entity/Product.java b/app/src/main/java/com/example/test/entity/Product.java new file mode 100644 index 0000000..f6db214 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/Product.java @@ -0,0 +1,78 @@ +package com.example.test.entity; + +public class Product { + private int id; + private String name; + private double price; + private String description; + private String tag; + private String imgUrl; + private String kind; + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + + public Product() { + } + + public Product(int id, String name, double price, String imgUrl) { + this.id = id; + this.name = name; + this.price = price; + this.imgUrl = imgUrl; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } +} diff --git a/app/src/main/java/com/example/test/entity/ProductKind.java b/app/src/main/java/com/example/test/entity/ProductKind.java new file mode 100644 index 0000000..4a424d2 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/ProductKind.java @@ -0,0 +1,42 @@ +package com.example.test.entity; + +import java.sql.Timestamp; + +public class ProductKind { + private int id; + private String name; + private String imgUrl; + + public ProductKind() { + } + + public ProductKind(String name, String imgUrl) { + this.name = name; + this.imgUrl = imgUrl; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getImgUrl() { + return imgUrl; + } + + public void setImgUrl(String imgUrl) { + this.imgUrl = imgUrl; + } + +} diff --git a/app/src/main/java/com/example/test/entity/ProductKindStorage.java b/app/src/main/java/com/example/test/entity/ProductKindStorage.java new file mode 100644 index 0000000..bb8afce --- /dev/null +++ b/app/src/main/java/com/example/test/entity/ProductKindStorage.java @@ -0,0 +1,44 @@ +package com.example.test.entity; + +import android.graphics.Bitmap; + +import com.example.test.entity.ProductKind; +import com.example.test.netrequest.ProductOkHttp; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ProductKindStorage { + private List names; + private List bitmaps; + + public ProductKindStorage() { + } + + public ProductKindStorage(List names, List bitmaps) { + this.names = names; + this.bitmaps = bitmaps; + } + + public List getNames() { + if(names == null) + names = new ArrayList<>(); + return names; + } + + public List getBitmaps() { + if(bitmaps == null) + bitmaps = new ArrayList<>(); + return bitmaps; + } + + + public void setNames(List names) { + this.names = names; + } + + public void setBitmaps(List bitmaps) { + this.bitmaps = bitmaps; + } +} diff --git a/app/src/main/java/com/example/test/entity/ProductStorage.java b/app/src/main/java/com/example/test/entity/ProductStorage.java new file mode 100644 index 0000000..c7c2764 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/ProductStorage.java @@ -0,0 +1,86 @@ +package com.example.test.entity; + +import android.graphics.Bitmap; + +import java.util.ArrayList; +import java.util.List; + +public class ProductStorage { + private List ids; + private List names; + private List bitmaps; + private List prices; + private List descriptions; + private List tags; + private List kinds; + + public List getIds() { + if(ids == null) + ids = new ArrayList<>(); + return ids; + } + + public void setIds(List ids) { + this.ids = ids; + } + + public List getNames() { + if(names == null) + names = new ArrayList<>(); + return names; + } + + public void setNames(List names) { + this.names = names; + } + + public List getBitmaps() { + if(bitmaps == null) + bitmaps = new ArrayList<>(); + return bitmaps; + } + + public void setBitmaps(List bitmaps) { + this.bitmaps = bitmaps; + } + + public List getPrices() { + if(prices == null) + prices = new ArrayList<>(); + return prices; + } + + public void setPrices(List prices) { + this.prices = prices; + } + + public List getDescriptions() { + if(descriptions == null) + descriptions = new ArrayList<>(); + return descriptions; + } + + public void setDescriptions(List descriptions) { + this.descriptions = descriptions; + } + + public List getTags() { + if(tags == null) + tags = new ArrayList<>(); + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public List getKinds() { + if(kinds == null) + kinds = new ArrayList<>(); + return kinds; + } + + public void setKinds(List kinds) { + this.kinds = kinds; + } +} diff --git a/app/src/main/java/com/example/test/entity/User.java b/app/src/main/java/com/example/test/entity/User.java new file mode 100644 index 0000000..dd47de8 --- /dev/null +++ b/app/src/main/java/com/example/test/entity/User.java @@ -0,0 +1,58 @@ +package com.example.test.entity; + +public class User { + private String username; + private String password; + private String sex; + private String city; + private int id; + + public User() { + } + + public User(String username, String password, String sex, String city) { + this.username = username; + this.password = password; + this.sex = sex; + this.city = city; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/app/src/main/java/com/example/test/fragment/GoodItemFragment.java b/app/src/main/java/com/example/test/fragment/GoodItemFragment.java new file mode 100644 index 0000000..89a461b --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/GoodItemFragment.java @@ -0,0 +1,7 @@ +package com.example.test.fragment; + +import androidx.fragment.app.Fragment; + +public class GoodItemFragment extends Fragment { + +} diff --git a/app/src/main/java/com/example/test/fragment/GoodKindFragment.java b/app/src/main/java/com/example/test/fragment/GoodKindFragment.java new file mode 100644 index 0000000..f71a66d --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/GoodKindFragment.java @@ -0,0 +1,35 @@ +package com.example.test.fragment; + +import android.os.Bundle; +import android.os.Handler; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; + +import androidx.fragment.app.Fragment; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; +import com.example.test.adapter.GoodKindAdapter; + +import java.util.List; + +public class GoodKindFragment extends Fragment { + private View view; + private HomeActivity activity; + private Handler handler; + private ListView listView; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + view = inflater.inflate(R.layout.good_kind_listview, container, false); + activity = (HomeActivity) getActivity(); + handler = activity.getHandler(); + listView = (ListView) view.findViewById(R.id.good_kind_listview); + GoodKindAdapter adapter = new GoodKindAdapter(activity, activity.getProductKindStorage().getNames()); + listView.setAdapter(adapter); + return view; + } +} diff --git a/app/src/main/java/com/example/test/fragment/NavigationCartFragment.java b/app/src/main/java/com/example/test/fragment/NavigationCartFragment.java new file mode 100644 index 0000000..4e7c969 --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/NavigationCartFragment.java @@ -0,0 +1,266 @@ +package com.example.test.fragment; + +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.util.Log; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.GridView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.PopupWindow; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; +import com.example.test.adapter.CartAdapter; +import com.example.test.adapter.CartDetailAdapter; +import com.example.test.entity.Cart; +import com.example.test.netrequest.CartOkHttp; +import com.example.test.utils.LoadingDialog; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class NavigationCartFragment extends Fragment { + private View cartView; + private HomeActivity activity; + public static List bitmaps = new ArrayList<>(); + public static List names = new ArrayList<>(); + public static List prices = new ArrayList<>(); + public static List nums = new ArrayList<>(); + public static List productIds = new ArrayList<>(); + private ListView listView; + private CheckBox cbChecked; + private TextView tvPrice; + private TextView tvDetail; + private Button pay; + public static int selectedNum = 0; + private int userId; + public Handler handler; + private boolean cartDetailShow = false; + private PopupWindow popupWindow; + private AlertDialog dialog; + private LoadingDialog loading; + public static List checkedProductIds = new ArrayList<>(); + private List checkedBitmaps = new ArrayList<>(); + public static final int updatePrice = 1; + public static final int updateCart = 2; + public static final int updateListview = 3; + + Handler myHandler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(@NonNull Message message) { + switch (message.what){ + case updatePrice: + updatePrice(); + return true; + case updateCart: + Message updateCartMsg = new Message(); + updateCartMsg.what = HomeActivity.UpdateCart; + handler.sendMessage(updateCartMsg); + return true; + case updateListview: + CartAdapter adapter = new CartAdapter(bitmaps, names, prices, nums, productIds, myHandler, userId, activity); + listView.setAdapter(adapter); + tvPrice.setText("0"); + loading.dismiss(); + return true; + } + return false; + } + }); + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + activity = (HomeActivity) getActivity(); + userId = activity.getBundle().getInt("id"); + handler = activity.getHandler(); + if(productIds.size()==0){ + cartView = inflater.inflate(R.layout.navigation_cart_empty, container, false); + goShopping(); + }else{ + cartView = inflater.inflate(R.layout.navigation_cart, container, false); + initListview(); + initCashier(); + } + return cartView; + } + + public void clearLists(){ + productIds.clear(); + names.clear(); + bitmaps.clear(); + prices.clear(); + nums.clear(); + } + + public void updatePrice(){ + checkedBitmaps.clear(); + double total = 0; + for (Integer productId : checkedProductIds) { + int index = productIds.indexOf(productId); + int num = nums.get(index); + double price = prices.get(index); + total += price*num; + checkedBitmaps.add(bitmaps.get(index)); + } + tvPrice.setText(total+""); + if(total==0.0){ + tvDetail.setVisibility(View.INVISIBLE); + }else{ + tvDetail.setVisibility(View.VISIBLE); + } + } + + public void setPrice(double price){ + tvPrice.setText(price+""); + } + + private void goShopping() { + Button button = cartView.findViewById(R.id.navigation_cart_shopping); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + activity.changeFragment(new NavigationGoodFragment()); + } + }); + } + +// 初始化购物车item + public void initListview(){ + if(listView == null) { + listView = (ListView) cartView.findViewById(R.id.navigation_cart_listview); + } + CartAdapter adpter = new CartAdapter(bitmaps, names, prices, nums, productIds, myHandler, userId,activity); + listView.setDivider(null); + listView.setDividerHeight(5); + listView.setAdapter(adpter); + + } + + public void initCashier() { + cbChecked = (CheckBox) cartView.findViewById(R.id.cashier_checked); + Log.i("view",cbChecked+""); + tvPrice = (TextView) cartView.findViewById(R.id.cashier_price); + pay =(Button) cartView.findViewById(R.id.cashier_pay); + tvDetail = (TextView) cartView.findViewById(R.id.cashier_detail); + if(selectedNum==0){ + tvPrice.setText("0"); + } + //全选绑定监听器 + cbChecked.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(cbChecked.isChecked()){ + tvDetail.setVisibility(View.VISIBLE); + double total=0.0; + for (int i = 0; i < prices.size(); i++) { + double price = prices.get(i); + total += price*nums.get(i); + } + tvPrice.setText(total+""); + }else{ + tvDetail.setVisibility(View.INVISIBLE); + tvPrice.setText("0"); + } + } + }); + //查看明细绑定监听器 + tvDetail.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + cartDetailShow = !cartDetailShow; + if(cartDetailShow) { + View detailView = LayoutInflater.from(activity).inflate(R.layout.cart_detail, null); + popupWindow = new PopupWindow(detailView, ViewGroup.LayoutParams.MATCH_PARENT, listView.getHeight()); + GridView detailGridview = (GridView) detailView.findViewById(R.id.cart_detail_gridview); + detailGridview.setAdapter(new CartDetailAdapter(activity, checkedBitmaps)); + LinearLayout rootView = (LinearLayout) cartView.findViewById(R.id.cart_detail_linearlayout); + popupWindow.setBackgroundDrawable(new BitmapDrawable()); + popupWindow.setOutsideTouchable(true); + popupWindow.showAtLocation(rootView, Gravity.TOP, 0, 0); + + }else{ + popupWindow.dismiss(); + } + } + }); + pay.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(popupWindow!=null&&cartDetailShow) { + popupWindow.dismiss(); + } + if(Double.parseDouble(tvPrice.getText().toString())==0.0){ + Toast.makeText(activity,"您未选中任何商品",Toast.LENGTH_SHORT).show(); + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setMessage("您确认购买吗?"); + builder.setCancelable(true); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialog.dismiss(); + loading = new LoadingDialog.Builder(activity, "加载中").create(); + dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); + loading.show(); + new Thread(deletCart).start(); + } + }); + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + dialog.dismiss(); + } + }); + dialog = builder.create(); + dialog.show(); + } + }); + } + + Runnable deletCart = new Runnable() { + @Override + public void run() { + CartOkHttp cartOkHttp = new CartOkHttp(); + for (Integer id : checkedProductIds) { + int index = productIds.indexOf(id); + Cart cart = new Cart(); + cart.setUserId(userId); + cart.setProductId(id); + productIds.remove(index); + bitmaps.remove(index); + names.remove(index); + prices.remove(index); + nums.remove(index); + try { + cartOkHttp.deleteCart(cart); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + Message message = new Message(); + message.what = updateListview; + myHandler.sendMessage(message); + } + }; +} \ No newline at end of file diff --git a/app/src/main/java/com/example/test/fragment/NavigationGoodFragment.java b/app/src/main/java/com/example/test/fragment/NavigationGoodFragment.java new file mode 100644 index 0000000..68eeae2 --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/NavigationGoodFragment.java @@ -0,0 +1,255 @@ +package com.example.test.fragment; + +import android.graphics.Bitmap; +import android.graphics.Color; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.SearchView; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; +import com.example.test.adapter.GoodItemAdapter; +import com.example.test.adapter.GoodKindAdapter; +import com.example.test.entity.Product; +import com.example.test.entity.ProductStorage; +import com.example.test.netrequest.ProductOkHttp; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class NavigationGoodFragment extends Fragment { + private List bitmapsList = new ArrayList<>(); + private String names[]; + private double prices[]; + private HomeActivity activity; + private View view; + private Handler handler; + private ListView kind; + private ListView item; + private List productKind; + private ProductStorage productStorage = new ProductStorage(); + private int selectedPostion = 0; + public static final int updateProduct = 1; + private TextView tvAll; + private TextView tvPrice; + private TextView tvTime; + private SearchView searchView; + private String keyword; + Handler myHandle = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(@NonNull Message message) { + switch (message.what){ + case updateProduct: + item.setAdapter(new GoodItemAdapter(productStorage,handler,activity)); + return true; + } + return false; + } + }); + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + view = inflater.inflate(R.layout.navigation_good, container, false); + activity = (HomeActivity) getActivity(); + productKind = activity.getProductKindStorage().getNames(); + handler = activity.getHandler(); + initListview(); + initOptions(); + return view; + } + + public void initOptions() { + tvAll = view.findViewById(R.id.good_item_all); + tvPrice = view.findViewById(R.id.good_item_price); + tvTime = view.findViewById(R.id.good_item_time); + searchView = view.findViewById(R.id.good_searchview); + tvAll.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new Thread(getAllProduct).start(); + } + }); + tvPrice.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new Thread(getProcutOrderByPrice).start(); + } + }); + tvTime.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + new Thread(getProcutOrderByPrice).start(); + } + }); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + keyword= s; + new Thread(search).start(); + searchView.setIconified(true); + return false; + } + + @Override + public boolean onQueryTextChange(String s) { + return false; + } + }); + } + + public void initListview() { + kind = (ListView) view.findViewById(R.id.good_kind_listview); + item = (ListView) view.findViewById(R.id.good_item_listview); + GoodKindAdapter kindAdapter = new GoodKindAdapter(activity, productKind); + kind.setAdapter(kindAdapter); + new Thread(updateItem).start(); + kind.setDivider(null); + item.setDivider(null); + kind.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + if(selectedPostion!=i){ + adapterView.getChildAt(selectedPostion).setBackgroundColor(Color.WHITE); + view.setBackgroundColor(Color.rgb(192,192,192)); + } + selectedPostion = i; + new Thread(updateItem).start(); + } + }); + } + + + + public void clearProductStorage(){ + productStorage.getIds().clear(); + productStorage.getNames().clear(); + productStorage.getBitmaps().clear(); + productStorage.getPrices().clear(); + productStorage.getDescriptions().clear(); + productStorage.getTags().clear(); + } + + private void setProductStorage(List products) throws IOException { + clearProductStorage(); + ProductOkHttp productOkHttp = new ProductOkHttp(); + List storageNames = productStorage.getNames(); + List storageTags = productStorage.getTags(); + List storageDescriptions = productStorage.getDescriptions(); + List storagePrices = productStorage.getPrices(); + List storageBitmaps = productStorage.getBitmaps(); + List storageIds = productStorage.getIds(); + for (Product product : products) { + storageNames.add(product.getName()); + storageTags.add(product.getTag()); + storageDescriptions.add(product.getDescription()); + storagePrices.add(product.getPrice()); + storageBitmaps.add(productOkHttp.getImg(product.getImgUrl())); + storageIds.add(product.getId()); + } + } + + Runnable updateItem = new Runnable() { + @Override + public void run() { + ProductOkHttp productOkHttp = new ProductOkHttp(); + try { + List products = productOkHttp.getProductByKind(productKind.get(selectedPostion)); + setProductStorage(products); + Message message = new Message(); + message.what = updateProduct; + myHandle.sendMessage(message); +// Log.i("data",productStorage.getIds()+"names"+productStorage.getNames()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + + Runnable getAllProduct = new Runnable() { + @Override + public void run() { + ProductOkHttp productOkHttp = new ProductOkHttp(); + try { + List products = productOkHttp.getProduct(); + setProductStorage(products); + Message message = new Message(); + message.what = updateProduct; + myHandle.sendMessage(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + Runnable getProcutOrderByPrice = new Runnable() { + @Override + public void run() { + ProductOkHttp productOkHttp = new ProductOkHttp(); + try { + List products = productOkHttp.getProductOrderByPrice(); + setProductStorage(products); + Message message = new Message(); + message.what = updateProduct; + myHandle.sendMessage(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + Runnable getProcutOrderByTime = new Runnable() { + @Override + public void run() { + ProductOkHttp productOkHttp = new ProductOkHttp(); + try { + List products = productOkHttp.getProductOrderByTime(); + setProductStorage(products); + Message message = new Message(); + message.what = updateProduct; + myHandle.sendMessage(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }; + + + Runnable search = new Runnable() { + @Override + public void run() { + ProductOkHttp productOkHttp = new ProductOkHttp(); + try { + List products = productOkHttp.getProductByKeyword(keyword); + if(products==null){ + Looper.prepare(); + Toast.makeText(activity,"换个关键字",Toast.LENGTH_SHORT).show(); + Looper.loop(); + return; + } + setProductStorage(products); + Message message = new Message(); + message.what = updateProduct; + myHandle.sendMessage(message); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + }; +} \ No newline at end of file diff --git a/app/src/main/java/com/example/test/fragment/NavigationHomeFragment.java b/app/src/main/java/com/example/test/fragment/NavigationHomeFragment.java new file mode 100644 index 0000000..823c648 --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/NavigationHomeFragment.java @@ -0,0 +1,71 @@ +package com.example.test.fragment; + +import android.graphics.Bitmap; +import android.os.Bundle; +import androidx.fragment.app.Fragment; +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.AdapterView; +import android.widget.GridView; +import android.widget.Toast; +import com.example.test.R; +import com.example.test.activity.HomeActivity; +import com.example.test.adapter.HomeProductAdapter; +import com.example.test.adapter.HomeProductKindAdapter; +import com.example.test.entity.Cart; +import com.example.test.entity.ProductKindStorage; +import com.example.test.entity.ProductStorage; +import com.example.test.netrequest.CartOkHttp; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class NavigationHomeFragment extends Fragment { + private ProductStorage hotProductStorage; + private ProductKindStorage productKindStorage; + private HomeActivity activity; + private int productIDNow; + + private View view; + private Handler handler; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + view = inflater.inflate(R.layout.navigation_home, container, false); + activity = (HomeActivity) getActivity(); + handler = activity.getHandler(); + initData(); + initView(); + return view; + + } + + + public void initView() { + //初始化商品种类 + GridView kindGridview = (GridView) view.findViewById(R.id.fruit_kind_gridview); + HomeProductKindAdapter kindAdapter = new HomeProductKindAdapter(productKindStorage.getBitmaps(), productKindStorage.getNames(), activity); + kindGridview.setAdapter(kindAdapter); + + //初始化商品 + GridView fruitGridview = (GridView) view.findViewById(R.id.home_goods_fruit_gridview); + HomeProductAdapter fruitAdapter = new HomeProductAdapter(hotProductStorage.getBitmaps(), hotProductStorage.getNames(), hotProductStorage.getPrices(),hotProductStorage.getIds(), activity, handler); + fruitGridview.setAdapter(fruitAdapter); + } + + public void initData() { + productKindStorage = activity.getProductKindStorage(); + hotProductStorage = activity.getHotProductStorage(); + } +} + + diff --git a/app/src/main/java/com/example/test/fragment/NavigationLoadingFragment.java b/app/src/main/java/com/example/test/fragment/NavigationLoadingFragment.java new file mode 100644 index 0000000..43b4908 --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/NavigationLoadingFragment.java @@ -0,0 +1,30 @@ +package com.example.test.fragment; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; + +import android.os.Handler; +import android.os.Message; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; + +public class NavigationLoadingFragment extends Fragment { + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.navigation_cart_loading, container, false); + HomeActivity activity = (HomeActivity)getActivity(); + Handler handler = activity.getHandler(); + Message message = new Message(); + message.what = HomeActivity.LoadingData; + handler.sendMessage(message); + return view; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/test/fragment/NavigationPersonFragment.java b/app/src/main/java/com/example/test/fragment/NavigationPersonFragment.java new file mode 100644 index 0000000..bddce12 --- /dev/null +++ b/app/src/main/java/com/example/test/fragment/NavigationPersonFragment.java @@ -0,0 +1,41 @@ +package com.example.test.fragment; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.example.test.R; +import com.example.test.activity.HomeActivity; + + +public class NavigationPersonFragment extends Fragment { + + private TextView tvName; + private TextView tvSex; + private TextView tvCity; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View view = inflater.inflate(R.layout.user, container, false); + HomeActivity activity = (HomeActivity) getActivity(); + Bundle bundle = activity.getBundle(); + String username = bundle.getString("username"); + String sex = bundle.getString("sex"); + String city = bundle.getString("city"); + tvName = view.findViewById(R.id.user_username); + tvSex = view.findViewById(R.id.user_sex); + tvCity = view.findViewById(R.id.user_city); + tvName.setText("用户名:"+username); + tvSex.setText("性别:"+sex); + tvCity.setText("城市:"+city); + return view; + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/test/netrequest/CartOkHttp.java b/app/src/main/java/com/example/test/netrequest/CartOkHttp.java new file mode 100644 index 0000000..a5fcdf0 --- /dev/null +++ b/app/src/main/java/com/example/test/netrequest/CartOkHttp.java @@ -0,0 +1,88 @@ +package com.example.test.netrequest; + + +import android.util.Log; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.example.test.entity.Cart; +import com.example.test.utils.Address; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import okhttp3.ConnectionPool; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class CartOkHttp { + private OkHttpClient okHttpClient = new OkHttpClient(); + public List selectAll() throws IOException { + Request request = new Request.Builder() + .url("http://" + Address.ip + ":8081/orange/shoppingCart/search") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List carts = JSON.parseObject(data, new TypeReference>() { + }); + return carts; + } + + public List selectByUserId(int userId) throws IOException { + RequestBody requestBody = RequestBody.create(userId+"",MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://" + Address.ip + ":8081/orange/shoppingCart/searchByUserId") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List carts = JSON.parseObject(data, new TypeReference>() { + }); + return carts; + } + + public boolean insertCart(Cart c) throws IOException { + String data = JSONObject.toJSONString(c); + RequestBody requestBody = RequestBody.create(data,MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/shoppingCart/insert") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + return jsonObject.getBoolean("flag"); + } + + public boolean updateCart(Cart c) throws IOException { + OkHttpClient client = new OkHttpClient(); + String data = JSONObject.toJSONString(c); + RequestBody requestBody = RequestBody.create(data,MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/shoppingCart/update") + .post(requestBody) + .build(); + Response response = client.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + return jsonObject.getBoolean("flag"); + } + + public boolean deleteCart(Cart c) throws IOException { + OkHttpClient client = new OkHttpClient(); + String data = JSONObject.toJSONString(c); + RequestBody requestBody = RequestBody.create(data,MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/shoppingCart/delete") + .post(requestBody) + .build(); + Response response = client.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + return jsonObject.getBoolean("flag"); + } +} diff --git a/app/src/main/java/com/example/test/netrequest/MessageOkHttp.java b/app/src/main/java/com/example/test/netrequest/MessageOkHttp.java new file mode 100644 index 0000000..bab1724 --- /dev/null +++ b/app/src/main/java/com/example/test/netrequest/MessageOkHttp.java @@ -0,0 +1,32 @@ +package com.example.test.netrequest; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.example.test.entity.Message; +import com.example.test.utils.Address; + +import java.io.IOException; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class MessageOkHttp { + public Message getMessage() throws IOException { +// 获取消息 + OkHttpClient okHttpClient = new OkHttpClient(); + Message data = null; + Request request = new Request.Builder() + .url("http://"+ Address.ip+":8081/orange/message/consumeMessage") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + data = JSON.parseObject(jsonObject.getString("data"), Message.class); +// 将获取到的消息设为已用 + Request comsume = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/message/updateMessage") + .build(); + Response execute = okHttpClient.newCall(comsume).execute(); + return data; + } +} diff --git a/app/src/main/java/com/example/test/netrequest/ProductOkHttp.java b/app/src/main/java/com/example/test/netrequest/ProductOkHttp.java new file mode 100644 index 0000000..2b1b067 --- /dev/null +++ b/app/src/main/java/com/example/test/netrequest/ProductOkHttp.java @@ -0,0 +1,169 @@ +package com.example.test.netrequest; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.util.Log; +import android.util.TimeUtils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.example.test.entity.Product; +import com.example.test.entity.ProductKind; +import com.example.test.utils.Address; + +import java.io.IOException; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +import javax.xml.datatype.Duration; + +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class ProductOkHttp { + private OkHttpClient okHttpClient = new OkHttpClient(); + public Bitmap getImg(String imgUrl) throws IOException { +// 替换ip + String url = Address.getImgUrl(imgUrl); + Request request = new Request.Builder() + .url(url) + .build(); + Response response = okHttpClient.newCall(request).execute(); + byte[] bytes = Objects.requireNonNull(response.body()).bytes(); + Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); + return bitmap; + + } + + + + public Product getProductById(int productId) throws IOException { + RequestBody requestBody = RequestBody.create(productId+"", MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/searchById") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + Product p = JSON.parseObject(data, Product.class); + return p; + } + + + public List getProductKind() throws IOException { + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/searchProductKind") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List productKinds = JSON.parseObject(data, new TypeReference>() { + }); + return productKinds; + } + + public List getHotProduct() throws IOException { + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/searchHotProduct") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } + + + //获取全部商品 + public List getProduct() throws IOException { + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/search") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } + + //按照种类获取商品 + public List getProductByKind(String kind) throws IOException { + RequestBody requestBody = RequestBody.create(kind, MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/searchProductByKind") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } + + + //按照关键字获取商品 + public List getProductByKeyword(String keyword) throws IOException { + RequestBody requestBody = RequestBody.create(keyword, MediaType.parse("application/json;charset=UTF-8")); + Request request = new Request.Builder() + .url("http://"+ Address.ip +":8081/orange/product/searchProductByKeyword") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } + + //按时间排序 + public List getProductOrderByTime() throws IOException { + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/product/time") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } +// 价格排序 + public List getProductOrderByPrice() throws IOException { + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/product/price") + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + String data = jsonObject.getString("data"); + List products = JSON.parseObject(data, new TypeReference>() { + }); + return products; + } + +// 上传图片 + public boolean uploadImg(byte[] bytes) throws IOException { + RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) + .addFormDataPart("file", "baixiangguo.png", RequestBody.create(bytes)).build(); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/product/uploadCover") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject jsonObject = JSON.parseObject(response.body().string()); + return jsonObject.getBoolean("flag"); + + } + + +} diff --git a/app/src/main/java/com/example/test/netrequest/UserOkHttp.java b/app/src/main/java/com/example/test/netrequest/UserOkHttp.java new file mode 100644 index 0000000..8ffe732 --- /dev/null +++ b/app/src/main/java/com/example/test/netrequest/UserOkHttp.java @@ -0,0 +1,63 @@ +package com.example.test.netrequest; + +import android.util.Log; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.example.test.MainActivity; +import com.example.test.entity.User; +import com.example.test.utils.Address; + +import java.io.IOException; +import java.util.PrimitiveIterator; + +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class UserOkHttp { + private OkHttpClient okHttpClient = new OkHttpClient(); + + public User login(User u) throws IOException { + String JSONString = JSONObject.toJSONString(u); + MediaType type = MediaType.parse("application/json;charset=utf-8"); + RequestBody requestBody = RequestBody.create(JSONString, type); + Request request = new Request.Builder() + .url("http://"+ Address.ip+":8081/orange/user/login") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject result = JSON.parseObject(response.body().string()); + JSONObject data = result.getJSONObject("data"); + User user = JSON.toJavaObject(data, User.class); + return user; + } + + public boolean register(User u) throws IOException { + String jsonString = JSONObject.toJSONString(u); + MediaType type = MediaType.parse("application/json;charset=utf-8"); + RequestBody requestBody = RequestBody.create(jsonString, type); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/user/register") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject result = JSON.parseObject(response.body().string()); + return result.getBoolean("flag"); + } + + public boolean selectUser(String username) throws IOException { + String jsonString = JSONObject.toJSONString(username); + MediaType type = MediaType.parse("application/json;charset=utf-8"); + RequestBody requestBody = RequestBody.create(jsonString, type); + Request request = new Request.Builder() + .url("http://"+Address.ip+":8081/orange/user/selectUser") + .post(requestBody) + .build(); + Response response = okHttpClient.newCall(request).execute(); + JSONObject result = JSON.parseObject(response.body().string()); + return result.getBoolean("flag"); + } +} diff --git a/app/src/main/java/com/example/test/service/MessageService.java b/app/src/main/java/com/example/test/service/MessageService.java new file mode 100644 index 0000000..bbf4a50 --- /dev/null +++ b/app/src/main/java/com/example/test/service/MessageService.java @@ -0,0 +1,106 @@ +package com.example.test.service; + +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.os.AsyncTask; +import android.os.IBinder; +import android.util.Log; + +import androidx.annotation.Nullable; +import androidx.core.app.NotificationCompat; + +import com.example.test.R; +import com.example.test.entity.Message; +import com.example.test.netrequest.MessageOkHttp; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Objects; +import java.util.Timer; +import java.util.TimerTask; + +public class MessageService extends Service { + private static Timer timer = null; + private NotificationManager manager; + private NotificationCompat.Builder builder; + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + /** + * 清除通知 + */ + private void cleanAllNotification() { + manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + manager.cancelAll(); + if (timer != null) { + timer.cancel(); + timer = null; + } + + } + + /** + * 添加通知 + */ + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + long period = 60 * 1000; //1分钟一个周期 + if (timer == null) { + timer = new Timer(); + } + timer.schedule(new TimerTask() { + @Override + public void run() { + new ConsumeMessageTask().execute(); + } + }, 0, period); + + return super.onStartCommand(intent, flags, startId); + } + + class ConsumeMessageTask extends AsyncTask { + @Override + protected Void doInBackground(Void... voids) { + /** + * NotificationChannel是android8.0新增的特性,如果App的targetSDKVersion>=26, + * 没有设置channel通知渠道的话,就会导致通知无法展示。 + * 报错内容:Failed to post notification on channel “null” + */ + Log.i("start service","enter"); + MessageOkHttp http = new MessageOkHttp(); + Message msg; + try { + msg = http.getMessage(); + if (Objects.nonNull(msg)) { + Log.i("orangeMessage", "run: " + msg.getContent() ); + NotificationChannel channel = new NotificationChannel("channel", "通知", NotificationManager.IMPORTANCE_HIGH); + manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + manager.createNotificationChannel(channel); + builder = new NotificationCompat.Builder(MessageService.this,"channel"); + Date date = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + builder.setContentTitle("来自橙一色的系统通知消息"); + builder.setSmallIcon(R.drawable.chengzi); + builder.setChannelId("channel"); + builder.setContentText(msg.getContent()); + builder.setAutoCancel(true); + builder.setDefaults(Notification.DEFAULT_ALL); + Notification notification = builder.build(); + manager.notify(1, notification); + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/test/utils/Address.java b/app/src/main/java/com/example/test/utils/Address.java new file mode 100644 index 0000000..8722f79 --- /dev/null +++ b/app/src/main/java/com/example/test/utils/Address.java @@ -0,0 +1,22 @@ +package com.example.test.utils; + +import android.util.Log; + +public class Address { + public static String ip = "192.168.43.226"; + public static String getImgUrl(String url){ + StringBuilder sb = new StringBuilder(); + String start = url.substring(0,7); + String end = url.substring(7); + sb.append(start); + String[] splits = end.split(":"); + for (int i = 0; i < splits.length; i++) { + if(i==0){ + sb.append(ip).append(":"); + }else{ + sb.append(splits[i]); + } + } + return sb.toString(); + } +} diff --git a/app/src/main/java/com/example/test/utils/LoadingDialog.java b/app/src/main/java/com/example/test/utils/LoadingDialog.java new file mode 100644 index 0000000..7fe3025 --- /dev/null +++ b/app/src/main/java/com/example/test/utils/LoadingDialog.java @@ -0,0 +1,64 @@ +package com.example.test.utils; + +import android.app.Dialog; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import com.example.test.R; + +public class LoadingDialog extends Dialog { + public LoadingDialog(@NonNull Context context) { + super(context); + } + + public static class Builder{ + private Context context; + private String message; + + private boolean isShowMessage=true; + + private boolean isCancelable=false; + + private boolean isCancelOutside=false; + + public Builder(Context context, String message) { + this.context = context; + this.message = message; + } + + public void setShowMessage(boolean showMessage) { + isShowMessage = showMessage; + } + + public void setMessage(String message) { + this.message = message; + } + + public void setCancelable(boolean cancelable) { + isCancelable = cancelable; + } + + public void setCancelOutside(boolean cancelOutside) { + isCancelOutside = cancelOutside; + } + + public LoadingDialog create(){ + View view = LayoutInflater.from(context).inflate(R.layout.loading_dialog, null); + LoadingDialog loadingDialog = new LoadingDialog(context); + TextView tvMessage = view.findViewById(R.id.loading_message);; + if(isShowMessage){ + tvMessage.setText(message); + }else{ + tvMessage.setVisibility(View.GONE); + } + loadingDialog.setContentView(view); + loadingDialog.setCancelable(isCancelable); + loadingDialog.setCanceledOnTouchOutside(isCancelOutside); + return loadingDialog; + } + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/add.png b/app/src/main/res/drawable/add.png new file mode 100644 index 0000000..446e0d0 Binary files /dev/null and b/app/src/main/res/drawable/add.png differ diff --git a/app/src/main/res/drawable/address.png b/app/src/main/res/drawable/address.png new file mode 100644 index 0000000..7318be0 Binary files /dev/null and b/app/src/main/res/drawable/address.png differ diff --git a/app/src/main/res/drawable/all.png b/app/src/main/res/drawable/all.png new file mode 100644 index 0000000..1fabb14 Binary files /dev/null and b/app/src/main/res/drawable/all.png differ diff --git a/app/src/main/res/drawable/animation.xml b/app/src/main/res/drawable/animation.xml new file mode 100644 index 0000000..5fb556a --- /dev/null +++ b/app/src/main/res/drawable/animation.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/app/src/main/res/drawable/apple.jpg b/app/src/main/res/drawable/apple.jpg new file mode 100644 index 0000000..5f7a431 Binary files /dev/null and b/app/src/main/res/drawable/apple.jpg differ diff --git a/app/src/main/res/drawable/apple1.jpg b/app/src/main/res/drawable/apple1.jpg new file mode 100644 index 0000000..adcb63f Binary files /dev/null and b/app/src/main/res/drawable/apple1.jpg differ diff --git a/app/src/main/res/drawable/arrow_down.png b/app/src/main/res/drawable/arrow_down.png new file mode 100644 index 0000000..6d95bb5 Binary files /dev/null and b/app/src/main/res/drawable/arrow_down.png differ diff --git a/app/src/main/res/drawable/arrow_right.png b/app/src/main/res/drawable/arrow_right.png new file mode 100644 index 0000000..84ded85 Binary files /dev/null and b/app/src/main/res/drawable/arrow_right.png differ diff --git a/app/src/main/res/drawable/banana.jpg b/app/src/main/res/drawable/banana.jpg new file mode 100644 index 0000000..5c5c801 Binary files /dev/null and b/app/src/main/res/drawable/banana.jpg differ diff --git a/app/src/main/res/drawable/button_login.xml b/app/src/main/res/drawable/button_login.xml new file mode 100644 index 0000000..d093f1b --- /dev/null +++ b/app/src/main/res/drawable/button_login.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_register.xml b/app/src/main/res/drawable/button_register.xml new file mode 100644 index 0000000..3eb0673 --- /dev/null +++ b/app/src/main/res/drawable/button_register.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_shape.xml b/app/src/main/res/drawable/button_shape.xml new file mode 100644 index 0000000..437de92 --- /dev/null +++ b/app/src/main/res/drawable/button_shape.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/drawable/carambola.jpg b/app/src/main/res/drawable/carambola.jpg new file mode 100644 index 0000000..dfdbaf1 Binary files /dev/null and b/app/src/main/res/drawable/carambola.jpg differ diff --git a/app/src/main/res/drawable/cart.png b/app/src/main/res/drawable/cart.png new file mode 100644 index 0000000..96c1cfd Binary files /dev/null and b/app/src/main/res/drawable/cart.png differ diff --git a/app/src/main/res/drawable/chengzi.png b/app/src/main/res/drawable/chengzi.png new file mode 100644 index 0000000..fff0306 Binary files /dev/null and b/app/src/main/res/drawable/chengzi.png differ diff --git a/app/src/main/res/drawable/city.png b/app/src/main/res/drawable/city.png new file mode 100644 index 0000000..790fb2b Binary files /dev/null and b/app/src/main/res/drawable/city.png differ diff --git a/app/src/main/res/drawable/coconut.jpg b/app/src/main/res/drawable/coconut.jpg new file mode 100644 index 0000000..1b0cb32 Binary files /dev/null and b/app/src/main/res/drawable/coconut.jpg differ diff --git a/app/src/main/res/drawable/dog.png b/app/src/main/res/drawable/dog.png new file mode 100644 index 0000000..0d3bb2a Binary files /dev/null and b/app/src/main/res/drawable/dog.png differ diff --git a/app/src/main/res/drawable/fresh.png b/app/src/main/res/drawable/fresh.png new file mode 100644 index 0000000..4ab4c93 Binary files /dev/null and b/app/src/main/res/drawable/fresh.png differ diff --git a/app/src/main/res/drawable/grape.jpg b/app/src/main/res/drawable/grape.jpg new file mode 100644 index 0000000..226c2aa Binary files /dev/null and b/app/src/main/res/drawable/grape.jpg differ diff --git a/app/src/main/res/drawable/grape1.jpg b/app/src/main/res/drawable/grape1.jpg new file mode 100644 index 0000000..ee9a568 Binary files /dev/null and b/app/src/main/res/drawable/grape1.jpg differ diff --git a/app/src/main/res/drawable/grapefruit.jpg b/app/src/main/res/drawable/grapefruit.jpg new file mode 100644 index 0000000..08d15ba Binary files /dev/null and b/app/src/main/res/drawable/grapefruit.jpg differ diff --git a/app/src/main/res/drawable/grapefruit1.jpg b/app/src/main/res/drawable/grapefruit1.jpg new file mode 100644 index 0000000..5baab34 Binary files /dev/null and b/app/src/main/res/drawable/grapefruit1.jpg differ diff --git a/app/src/main/res/drawable/grapefruit2.jpg b/app/src/main/res/drawable/grapefruit2.jpg new file mode 100644 index 0000000..596e1e1 Binary files /dev/null and b/app/src/main/res/drawable/grapefruit2.jpg differ diff --git a/app/src/main/res/drawable/greengrape.jpg b/app/src/main/res/drawable/greengrape.jpg new file mode 100644 index 0000000..a1df67f Binary files /dev/null and b/app/src/main/res/drawable/greengrape.jpg differ diff --git a/app/src/main/res/drawable/hamimelon.jpg b/app/src/main/res/drawable/hamimelon.jpg new file mode 100644 index 0000000..ba789c0 Binary files /dev/null and b/app/src/main/res/drawable/hamimelon.jpg differ diff --git a/app/src/main/res/drawable/hamimelon1.jpg b/app/src/main/res/drawable/hamimelon1.jpg new file mode 100644 index 0000000..c7ebc14 Binary files /dev/null and b/app/src/main/res/drawable/hamimelon1.jpg differ diff --git a/app/src/main/res/drawable/home_kind_apple.png b/app/src/main/res/drawable/home_kind_apple.png new file mode 100644 index 0000000..6f4be2c Binary files /dev/null and b/app/src/main/res/drawable/home_kind_apple.png differ diff --git a/app/src/main/res/drawable/home_kind_grapefruit.png b/app/src/main/res/drawable/home_kind_grapefruit.png new file mode 100644 index 0000000..65ac424 Binary files /dev/null and b/app/src/main/res/drawable/home_kind_grapefruit.png differ diff --git a/app/src/main/res/drawable/home_kind_lemon.png b/app/src/main/res/drawable/home_kind_lemon.png new file mode 100644 index 0000000..ce4bc3c Binary files /dev/null and b/app/src/main/res/drawable/home_kind_lemon.png differ diff --git a/app/src/main/res/drawable/home_kind_mango.png b/app/src/main/res/drawable/home_kind_mango.png new file mode 100644 index 0000000..bce702d Binary files /dev/null and b/app/src/main/res/drawable/home_kind_mango.png differ diff --git a/app/src/main/res/drawable/home_kind_orange.png b/app/src/main/res/drawable/home_kind_orange.png new file mode 100644 index 0000000..1d7c015 Binary files /dev/null and b/app/src/main/res/drawable/home_kind_orange.png differ diff --git a/app/src/main/res/drawable/home_kind_orange1.png b/app/src/main/res/drawable/home_kind_orange1.png new file mode 100644 index 0000000..1c9bb02 Binary files /dev/null and b/app/src/main/res/drawable/home_kind_orange1.png differ diff --git a/app/src/main/res/drawable/home_kind_pear.png b/app/src/main/res/drawable/home_kind_pear.png new file mode 100644 index 0000000..99f0702 Binary files /dev/null and b/app/src/main/res/drawable/home_kind_pear.png differ diff --git a/app/src/main/res/drawable/home_kind_watermelon.png b/app/src/main/res/drawable/home_kind_watermelon.png new file mode 100644 index 0000000..57c3a0d Binary files /dev/null and b/app/src/main/res/drawable/home_kind_watermelon.png differ diff --git a/app/src/main/res/drawable/hot.png b/app/src/main/res/drawable/hot.png new file mode 100644 index 0000000..89d5cf8 Binary files /dev/null and b/app/src/main/res/drawable/hot.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/leechee.jpg b/app/src/main/res/drawable/leechee.jpg new file mode 100644 index 0000000..413828c Binary files /dev/null and b/app/src/main/res/drawable/leechee.jpg differ diff --git a/app/src/main/res/drawable/loading.png b/app/src/main/res/drawable/loading.png new file mode 100644 index 0000000..7ef8ee3 Binary files /dev/null and b/app/src/main/res/drawable/loading.png differ diff --git a/app/src/main/res/drawable/loading_bg.xml b/app/src/main/res/drawable/loading_bg.xml new file mode 100644 index 0000000..89b3581 --- /dev/null +++ b/app/src/main/res/drawable/loading_bg.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/drawable/orange.png b/app/src/main/res/drawable/orange.png new file mode 100644 index 0000000..70e8db8 Binary files /dev/null and b/app/src/main/res/drawable/orange.png differ diff --git a/app/src/main/res/drawable/orange1.jpg b/app/src/main/res/drawable/orange1.jpg new file mode 100644 index 0000000..65d181c Binary files /dev/null and b/app/src/main/res/drawable/orange1.jpg differ diff --git a/app/src/main/res/drawable/password.png b/app/src/main/res/drawable/password.png new file mode 100644 index 0000000..1c6c4f5 Binary files /dev/null and b/app/src/main/res/drawable/password.png differ diff --git a/app/src/main/res/drawable/pear.jpg b/app/src/main/res/drawable/pear.jpg new file mode 100644 index 0000000..d8d231c Binary files /dev/null and b/app/src/main/res/drawable/pear.jpg differ diff --git a/app/src/main/res/drawable/pear1.jpg b/app/src/main/res/drawable/pear1.jpg new file mode 100644 index 0000000..5f8bab2 Binary files /dev/null and b/app/src/main/res/drawable/pear1.jpg differ diff --git a/app/src/main/res/drawable/people.png b/app/src/main/res/drawable/people.png new file mode 100644 index 0000000..8655e29 Binary files /dev/null and b/app/src/main/res/drawable/people.png differ diff --git a/app/src/main/res/drawable/pineapple.jpg b/app/src/main/res/drawable/pineapple.jpg new file mode 100644 index 0000000..2599727 Binary files /dev/null and b/app/src/main/res/drawable/pineapple.jpg differ diff --git a/app/src/main/res/drawable/price.png b/app/src/main/res/drawable/price.png new file mode 100644 index 0000000..73cb13d Binary files /dev/null and b/app/src/main/res/drawable/price.png differ diff --git a/app/src/main/res/drawable/purplegrape.jpg b/app/src/main/res/drawable/purplegrape.jpg new file mode 100644 index 0000000..5ff7050 Binary files /dev/null and b/app/src/main/res/drawable/purplegrape.jpg differ diff --git a/app/src/main/res/drawable/recomend.png b/app/src/main/res/drawable/recomend.png new file mode 100644 index 0000000..faf215e Binary files /dev/null and b/app/src/main/res/drawable/recomend.png differ diff --git a/app/src/main/res/drawable/reduce.png b/app/src/main/res/drawable/reduce.png new file mode 100644 index 0000000..29d5c6a Binary files /dev/null and b/app/src/main/res/drawable/reduce.png differ diff --git a/app/src/main/res/drawable/sale.png b/app/src/main/res/drawable/sale.png new file mode 100644 index 0000000..5d71a07 Binary files /dev/null and b/app/src/main/res/drawable/sale.png differ diff --git a/app/src/main/res/drawable/section_cart.png b/app/src/main/res/drawable/section_cart.png new file mode 100644 index 0000000..6812ae8 Binary files /dev/null and b/app/src/main/res/drawable/section_cart.png differ diff --git a/app/src/main/res/drawable/section_good.png b/app/src/main/res/drawable/section_good.png new file mode 100644 index 0000000..6799e9c Binary files /dev/null and b/app/src/main/res/drawable/section_good.png differ diff --git a/app/src/main/res/drawable/section_home.png b/app/src/main/res/drawable/section_home.png new file mode 100644 index 0000000..c1793d6 Binary files /dev/null and b/app/src/main/res/drawable/section_home.png differ diff --git a/app/src/main/res/drawable/section_mine.png b/app/src/main/res/drawable/section_mine.png new file mode 100644 index 0000000..04837f3 Binary files /dev/null and b/app/src/main/res/drawable/section_mine.png differ diff --git a/app/src/main/res/drawable/setting.png b/app/src/main/res/drawable/setting.png new file mode 100644 index 0000000..34c2f2f Binary files /dev/null and b/app/src/main/res/drawable/setting.png differ diff --git a/app/src/main/res/drawable/sex.png b/app/src/main/res/drawable/sex.png new file mode 100644 index 0000000..acb8197 Binary files /dev/null and b/app/src/main/res/drawable/sex.png differ diff --git a/app/src/main/res/drawable/shopping.png b/app/src/main/res/drawable/shopping.png new file mode 100644 index 0000000..f3e0b57 Binary files /dev/null and b/app/src/main/res/drawable/shopping.png differ diff --git a/app/src/main/res/drawable/small_orange.jpg b/app/src/main/res/drawable/small_orange.jpg new file mode 100644 index 0000000..a4dad83 Binary files /dev/null and b/app/src/main/res/drawable/small_orange.jpg differ diff --git a/app/src/main/res/drawable/spinner_drop_down_shape.xml b/app/src/main/res/drawable/spinner_drop_down_shape.xml new file mode 100644 index 0000000..64306b1 --- /dev/null +++ b/app/src/main/res/drawable/spinner_drop_down_shape.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/sure_apssword.png b/app/src/main/res/drawable/sure_apssword.png new file mode 100644 index 0000000..0e7cee9 Binary files /dev/null and b/app/src/main/res/drawable/sure_apssword.png differ diff --git a/app/src/main/res/drawable/time.png b/app/src/main/res/drawable/time.png new file mode 100644 index 0000000..07bfe3a Binary files /dev/null and b/app/src/main/res/drawable/time.png differ diff --git a/app/src/main/res/drawable/user.png b/app/src/main/res/drawable/user.png new file mode 100644 index 0000000..47d8362 Binary files /dev/null and b/app/src/main/res/drawable/user.png differ diff --git a/app/src/main/res/drawable/user_account.png b/app/src/main/res/drawable/user_account.png new file mode 100644 index 0000000..e70142a Binary files /dev/null and b/app/src/main/res/drawable/user_account.png differ diff --git a/app/src/main/res/drawable/user_general.png b/app/src/main/res/drawable/user_general.png new file mode 100644 index 0000000..cf57947 Binary files /dev/null and b/app/src/main/res/drawable/user_general.png differ diff --git a/app/src/main/res/drawable/user_icon.png b/app/src/main/res/drawable/user_icon.png new file mode 100644 index 0000000..d5309b1 Binary files /dev/null and b/app/src/main/res/drawable/user_icon.png differ diff --git a/app/src/main/res/drawable/user_pay.png b/app/src/main/res/drawable/user_pay.png new file mode 100644 index 0000000..3fd6f50 Binary files /dev/null and b/app/src/main/res/drawable/user_pay.png differ diff --git a/app/src/main/res/drawable/user_sex.png b/app/src/main/res/drawable/user_sex.png new file mode 100644 index 0000000..da0e318 Binary files /dev/null and b/app/src/main/res/drawable/user_sex.png differ diff --git a/app/src/main/res/drawable/watermelon.jpg b/app/src/main/res/drawable/watermelon.jpg new file mode 100644 index 0000000..6c757e7 Binary files /dev/null and b/app/src/main/res/drawable/watermelon.jpg differ diff --git a/app/src/main/res/drawable/watermelon1.jpg b/app/src/main/res/drawable/watermelon1.jpg new file mode 100644 index 0000000..ec169ce Binary files /dev/null and b/app/src/main/res/drawable/watermelon1.jpg differ diff --git a/app/src/main/res/drawable/zomm.png b/app/src/main/res/drawable/zomm.png new file mode 100644 index 0000000..9aff41c Binary files /dev/null and b/app/src/main/res/drawable/zomm.png differ diff --git a/app/src/main/res/layout/activity_fruit_fragment.xml b/app/src/main/res/layout/activity_fruit_fragment.xml new file mode 100644 index 0000000..08ab80f --- /dev/null +++ b/app/src/main/res/layout/activity_fruit_fragment.xml @@ -0,0 +1,21 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cart_detail.xml b/app/src/main/res/layout/cart_detail.xml new file mode 100644 index 0000000..9fa8383 --- /dev/null +++ b/app/src/main/res/layout/cart_detail.xml @@ -0,0 +1,34 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cart_detail_item.xml b/app/src/main/res/layout/cart_detail_item.xml new file mode 100644 index 0000000..bddc49a --- /dev/null +++ b/app/src/main/res/layout/cart_detail_item.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/cart_listview_item.xml b/app/src/main/res/layout/cart_listview_item.xml new file mode 100644 index 0000000..6340b5d --- /dev/null +++ b/app/src/main/res/layout/cart_listview_item.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_fruit_content.xml b/app/src/main/res/layout/fragment_fruit_content.xml new file mode 100644 index 0000000..e5a7412 --- /dev/null +++ b/app/src/main/res/layout/fragment_fruit_content.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_fruit_kind.xml b/app/src/main/res/layout/fragment_fruit_kind.xml new file mode 100644 index 0000000..b97f315 --- /dev/null +++ b/app/src/main/res/layout/fragment_fruit_kind.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fruit_content_item.xml b/app/src/main/res/layout/fruit_content_item.xml new file mode 100644 index 0000000..b214981 --- /dev/null +++ b/app/src/main/res/layout/fruit_content_item.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fruit_kind_item.xml b/app/src/main/res/layout/fruit_kind_item.xml new file mode 100644 index 0000000..a5ee4e7 --- /dev/null +++ b/app/src/main/res/layout/fruit_kind_item.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/good_item_listview.xml b/app/src/main/res/layout/good_item_listview.xml new file mode 100644 index 0000000..41d2ef1 --- /dev/null +++ b/app/src/main/res/layout/good_item_listview.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/good_item_listview_item.xml b/app/src/main/res/layout/good_item_listview_item.xml new file mode 100644 index 0000000..8876d4a --- /dev/null +++ b/app/src/main/res/layout/good_item_listview_item.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/good_kind_listview.xml b/app/src/main/res/layout/good_kind_listview.xml new file mode 100644 index 0000000..6b82f56 --- /dev/null +++ b/app/src/main/res/layout/good_kind_listview.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/good_kind_listview_item.xml b/app/src/main/res/layout/good_kind_listview_item.xml new file mode 100644 index 0000000..51ce479 --- /dev/null +++ b/app/src/main/res/layout/good_kind_listview_item.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/home_fruit_kind_item.xml b/app/src/main/res/layout/home_fruit_kind_item.xml new file mode 100644 index 0000000..a5c631e --- /dev/null +++ b/app/src/main/res/layout/home_fruit_kind_item.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/home_goods_fruit_item.xml b/app/src/main/res/layout/home_goods_fruit_item.xml new file mode 100644 index 0000000..d2e50d8 --- /dev/null +++ b/app/src/main/res/layout/home_goods_fruit_item.xml @@ -0,0 +1,37 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/home_navigation_bottom_item.xml b/app/src/main/res/layout/home_navigation_bottom_item.xml new file mode 100644 index 0000000..61199a3 --- /dev/null +++ b/app/src/main/res/layout/home_navigation_bottom_item.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/loading_dialog.xml b/app/src/main/res/layout/loading_dialog.xml new file mode 100644 index 0000000..088ca1f --- /dev/null +++ b/app/src/main/res/layout/loading_dialog.xml @@ -0,0 +1,24 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/login.xml b/app/src/main/res/layout/login.xml new file mode 100644 index 0000000..481ff0e --- /dev/null +++ b/app/src/main/res/layout/login.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +