master
unknown 2 years ago
parent 1072a3625b
commit 13469717bf

@ -36,9 +36,9 @@ dependencies {
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.alibaba:fastjson:1.2.0'
implementation 'liji.library.dev:citypickerview:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
}

@ -76,12 +76,15 @@ public class TimeService extends Service {
* Failed to post notification on channel null
*/
OkHttpMessage okHttpMessage = new OkHttpMessage();
OrangeMessage orangeMessage;
OrangeMessage Message;
try {
orangeMessage = okHttpMessage.consumeMessage();
if (!Objects.isNull(orangeMessage)) {
Log.i("orangeMessage", "run: " + orangeMessage.toString());
NotificationChannel channel = new NotificationChannel("channel", "通知", NotificationManager.IMPORTANCE_DEFAULT);
Message = okHttpMessage.consumeMessage();
if (!Objects.isNull(Message)) {
Log.i("orangeMessage", "run: " + Message.toString());
NotificationChannel channel = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
channel = new NotificationChannel("channel", "通知", NotificationManager.IMPORTANCE_DEFAULT);
}
manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
manager.createNotificationChannel(channel);
@ -89,10 +92,10 @@ public class TimeService extends Service {
builder = new NotificationCompat.Builder(TimeService.this);
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
builder.setContentTitle("来自橙一色的系统通知消息" + " " + formatter.format(date));
builder.setContentTitle("来自美团的系统通知消息" + " " + formatter.format(date));
builder.setSmallIcon(R.drawable.chengzi);
builder.setChannelId("channel");
builder.setContentText(orangeMessage.getContent());
builder.setContentText(Message.getContent());
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_ALL);
Notification notification = builder.build();

@ -4,6 +4,7 @@ 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;
@ -13,6 +14,10 @@ import androidx.appcompat.app.AppCompatActivity;
import com.example.register.R;
import com.example.register.dateoperation.Database;
import com.example.register.entity.User;
import com.example.register.netrequest.OkHttpUser;
import java.io.IOException;
public class loginActivity extends AppCompatActivity implements View.OnClickListener {
@ -78,7 +83,41 @@ public class loginActivity extends AppCompatActivity implements View.OnClickList
}
return false;
}
/**
*
*/
Runnable runnable = new Runnable() {
@Override
public void run() {
String username = usernameT.getText().toString();
String password = passwordT.getText().toString();
User orangeUser = new User();
orangeUser.setUsername(username);
orangeUser.setPassword(password);
OkHttpUser okHttpUser = new OkHttpUser();
User orangeUser1 = null;
try {
orangeUser1 = okHttpUser.userLogin(orangeUser);
if (orangeUser1 != null) {
Intent intent1 = new Intent(loginActivity.this, IndexActivity.class);
Bundle bundle = new Bundle();
bundle.putString("username", usernameT.getText().toString());
bundle.putString("password", orangeUser1.getPassword());
bundle.putString("city", orangeUser1.getCity());
bundle.putString("sex", orangeUser1.getSex());
intent1.putExtras(bundle);
startActivity(intent1);
} else {
//解决在子线程中调用Toast的异常情况处理
Looper.prepare();
Toast.makeText(loginActivity.this, "账号或者密码错误", Toast.LENGTH_SHORT).show();
Looper.loop();
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
}

@ -1,7 +1,6 @@
package com.example.register.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -9,28 +8,29 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.register.entity.Product;
import com.example.register.R;
import com.example.register.entity.OrangeProductPack;
import java.util.List;
public class ProductAdapter extends BaseAdapter {
private List<Product> productList;
//private List<Product> productList;
private List<OrangeProductPack> orangeProductList;
private LayoutInflater layoutInflater;
public ProductAdapter(Context context, List<Product> productList) {
this.productList = productList;
public ProductAdapter(Context context, List<OrangeProductPack> orangeProductList) {
this.orangeProductList = orangeProductList;
this.layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return productList.size();
return orangeProductList.size();
}
@Override
public Object getItem(int position) {
return productList.get(position);
return orangeProductList.get(position);
}
@Override
@ -42,7 +42,6 @@ public class ProductAdapter extends BaseAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
Log.i("aa", "getView: "+"aa");
convertView = layoutInflater.inflate(R.layout.categoty_detail_content, null);
viewHolder = new ViewHolder();
viewHolder.productImage = convertView.findViewById(R.id.category_product_image);
@ -52,12 +51,11 @@ public class ProductAdapter extends BaseAdapter {
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Product product = productList.get(position);
Log.i("product", "getView: "+product.toString());
OrangeProductPack product = orangeProductList.get(position);
if (product != null) {
viewHolder.productImage.setBackgroundResource(product.getImageUrlId());
viewHolder.productName.setText(product.getProductName());
viewHolder.productPrice.setText(String.valueOf(product.getProductPrice()));
viewHolder.productImage.setImageBitmap(product.getImgBitmap());
viewHolder.productName.setText(product.getName());
viewHolder.productPrice.setText(String.format("%s元", String.valueOf(product.getPrice())));
}
return convertView;
}
@ -66,4 +64,5 @@ public class ProductAdapter extends BaseAdapter {
ImageView productImage;
TextView productName, productPrice;
}
}

@ -28,6 +28,9 @@ public class User {
return password;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
@ -47,6 +50,9 @@ public class User {
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return address;
}
@Override
public String toString() {

@ -1,6 +1,7 @@
package com.example.register.fragment;
import android.app.Fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -13,9 +14,12 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.register.adapter.ProductAdapter;
import com.example.register.entity.OrangeProductPack;
import com.example.register.entity.Product;
import com.example.register.R;
import com.example.register.netrequest.OkHttpClientProduct;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@ -26,7 +30,7 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
private GridView gridView;
private List<Product> productList;
private ProductAdapter productAdapter;
private List<OrangeProductPack> list = new ArrayList<>();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -59,8 +63,9 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
ktvLine.setOnClickListener(this);
gridView = view.findViewById(R.id.index_famous_gridview);
initData();
productAdapter = new ProductAdapter(getActivity(), productList);
gridView.setAdapter(productAdapter);
//productAdapter = new ProductAdapter(getActivity(), productList);
//gridView.setAdapter(productAdapter);
new SearchProductTask().execute();
}
@ -106,4 +111,28 @@ public class IndexFragment extends Fragment implements View.OnClickListener {
productList.add(product5);
}
/**
*
*/
class SearchProductTask extends AsyncTask<Void, Void, List<OrangeProductPack>> {
@Override
protected List<OrangeProductPack> doInBackground(Void... voids) {
OkHttpClientProduct clientProduct = new OkHttpClientProduct();
try {
list = clientProduct.getProductPack();
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
@Override
protected void onPostExecute(List<OrangeProductPack> orangeProducts) {
productAdapter = new ProductAdapter(getActivity(), list);
gridView.setAdapter(productAdapter);
}
}
}

@ -1,21 +1,102 @@
package com.example.register.fragment;
import android.app.Fragment;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.register.R;
import com.example.register.adapter.ListViewAdapter;
import com.example.register.adapter.ProductAdapter;
import com.example.register.entity.Condition;
import com.example.register.entity.OrangeProductPack;
import com.example.register.netrequest.OkHttpClientProduct;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ProductFragment extends Fragment {
private Spinner conditonListSpinner;
private ListViewAdapter listViewAdapter;
private List<Condition> conditionList;
private GridView productGridView;
private List<OrangeProductPack> orangeProductList = new ArrayList<>();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false);
init(view);
return view;
}
/**
*
*
* @param view
*/
private void init(View view) {
conditonListSpinner = view.findViewById(R.id.product_select_condition);
initCondList();
listViewAdapter = new ListViewAdapter(getActivity(), conditionList);
conditonListSpinner.setAdapter(listViewAdapter);
productGridView = view.findViewById(R.id.product_list);
new SearchProductTask().execute();
}
/**
* conditionList
*/
private void initCondList() {
conditionList = new ArrayList<>();
Condition allCondition = new Condition();
allCondition.setConditionIcon(R.drawable.all);
allCondition.setConditionName("全部");
Condition saleCondition = new Condition();
saleCondition.setConditionIcon(R.drawable.salenum);
saleCondition.setConditionName("按销量高低排序");
Condition timeCondition = new Condition();
timeCondition.setConditionIcon(R.drawable.time);
timeCondition.setConditionName("按上市时间排序");
Condition priceCondition = new Condition();
priceCondition.setConditionIcon(R.drawable.price);
priceCondition.setConditionName("按商品价格排序");
conditionList.add(allCondition);
conditionList.add(saleCondition);
conditionList.add(timeCondition);
conditionList.add(priceCondition);
}
/**
*
*/
class SearchProductTask extends AsyncTask<Void, Void, List<OrangeProductPack>> {
@Override
protected List<OrangeProductPack> doInBackground(Void... voids) {
OkHttpClientProduct clientProduct = new OkHttpClientProduct();
try {
orangeProductList = clientProduct.getProductPack();
} catch (IOException e) {
e.printStackTrace();
}
return orangeProductList;
}
@Override
protected void onPostExecute(List<OrangeProductPack> orangeProducts) {
ProductAdapter productAdapter = new ProductAdapter(getActivity(), orangeProductList);
productGridView.setAdapter(productAdapter);
}
}
}

@ -1,21 +1,61 @@
package com.example.register.fragment;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.register.R;
import com.example.register.entity.ShoppingCart;
import java.util.ArrayList;
import java.util.List;
public class ShoppingCartFragment extends Fragment implements View.OnClickListener {
private Button walkButton;
private List<ShoppingCart> cartList = new ArrayList<>();
private ProductFragment productFragment;
public class ShoppingCartFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_shopping, container, false);
View view;
if (cartList.size() > 0) {
//有商品
view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_have_product, container, false);
} else {
view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_no_product, container, false);
}
init(view);
return view;
}
/**
*
*/
private void init(View view) {
walkButton = view.findViewById(R.id.random_search);
walkButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.random_search:
//开启事务fragment的控制是由事务来实现的
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (productFragment == null) {
productFragment = new ProductFragment();
}
transaction.replace(R.id.main_content, productFragment);
transaction.commit();
break;
}
}
}

@ -6,8 +6,8 @@ import android.graphics.BitmapFactory;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.orangesale_end.entity.OrangeProduct;
import com.example.orangesale_end.entity.OrangeProductPack;
import com.example.register.entity.OrangeProduct;
import com.example.register.entity.OrangeProductPack;
import java.io.IOException;
import java.util.ArrayList;

@ -2,7 +2,7 @@ package com.example.register.netrequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.orangesale_end.entity.OrangeMessage;
import com.example.register.entity.OrangeMessage;
import java.io.IOException;
import java.util.Objects;

@ -4,7 +4,7 @@ import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.orangesale_end.entity.OrangeUser;
import com.example.register.entity.User;
import java.io.IOException;
@ -15,12 +15,13 @@ import okhttp3.RequestBody;
import okhttp3.Response;
public class OkHttpUser {
/**
*
*
* @param orangeUser
*/
public OrangeUser userLogin(OrangeUser orangeUser) throws IOException {
public User userLogin(User orangeUser) throws IOException {
OkHttpClient okHttpClient= new OkHttpClient();
//数据类型为json格式
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
@ -39,7 +40,7 @@ public class OkHttpUser {
System.out.println("responseStr = " + responseStr);
JSONObject jsonObject = JSON.parseObject(responseStr);
JSONObject jsonObject1 = jsonObject.getJSONObject("data");
OrangeUser orangeUser1 = JSON.toJavaObject(jsonObject1, OrangeUser.class);
User orangeUser1 = JSON.toJavaObject(jsonObject1, User.class);
return orangeUser1;
}
@ -50,7 +51,7 @@ public class OkHttpUser {
* @return
* @throws IOException
*/
public boolean userRegister(OrangeUser orangeUser) throws IOException {
public boolean userRegister(User orangeUser) throws IOException {
OkHttpClient okHttpClient = new OkHttpClient();
//数据类型为json格式
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 790 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -1,11 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
<include layout="@layout/content_product_title" />
<Spinner
android:id="@+id/product_select_condition"
android:layout_width="match_parent"
android:paddingHorizontal="1dp"
android:layout_height="wrap_content" />
<GridView
android:id="@+id/product_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product" />
android:layout_marginTop="10dp"
android:background="#E8E8E8"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:numColumns="2"/>
</LinearLayout>
Loading…
Cancel
Save