This commit is contained in:
Lixin 2024-12-18 23:06:48 +08:00
parent 9ee997cd8a
commit d025d69efb
9 changed files with 481 additions and 9 deletions

View File

@ -42,6 +42,11 @@ dependencies {
implementation ("com.squareup.okhttp3:okhttp:4.9.3")
implementation ("com.squareup.okhttp3:logging-interceptor:4.9.3")
implementation ("com.google.android.material:material:1.4.0")
compileOnly ("org.projectlombok:lombok:1.18.24")
annotationProcessor ("org.projectlombok:lombok:1.18.24")
implementation ("com.github.bumptech.glide:glide:4.15.1")
annotationProcessor ("com.github.bumptech.glide:compiler:4.15.1")

View File

@ -7,11 +7,12 @@
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<application
android:allowBackup="true"
@ -24,6 +25,9 @@
android:theme="@style/Theme.MyApplication"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".shuiguoxiangqingActivity"
android:exported="false" />
<activity
android:name=".wodeguanzhuActivity"
android:exported="false" />

View File

@ -1,6 +1,8 @@
package com.example.myapplication;
import com.example.myapplication.dao.LoginResult;
import com.example.myapplication.dao.ShouyeshuiguoResult;
import com.example.myapplication.dao.UserInformationResult;
import java.util.Map;
@ -12,4 +14,11 @@ import retrofit2.http.POST;
public interface Api {
@POST("login")
Call<LoginResult> login(@Body Map<String,String> map);
@GET("system/goods/list")
Call<ShouyeshuiguoResult> shouyeshuiguolist(@Header("Authorization") String token);
@GET("")
Call<UserInformationResult> getUserInformation(@Header("Authorization") String token);
}

View File

@ -1,19 +1,158 @@
package com.example.myapplication;
import static android.content.Context.MODE_PRIVATE;
import android.content.SharedPreferences;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.myapplication.Utils.RetrofitUtils;
import com.example.myapplication.dao.ShouyeshuiguoResult;
import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class HomeFragment extends Fragment {
private List<ShouyeshuiguoResult.RowsBean> list = new ArrayList<>();
private RecyclerView recyclerView;
private MyAdapter myAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
View view = inflater.inflate(R.layout.fragment_home, container, false);
recyclerView = view.findViewById(R.id.recyclerView);
myAdapter = new MyAdapter(list);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.setAdapter(myAdapter);
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("data", MODE_PRIVATE);
String token = sharedPreferences.getString("token", "");
Call<ShouyeshuiguoResult> shouyeshuiguoResultCall =
RetrofitUtils.getRetrofit("http://10.138.77.128:8080/").create(Api.class).shouyeshuiguolist("Bearer " + token);
shouyeshuiguoResultCall.enqueue(new Callback<ShouyeshuiguoResult>() {
@Override
public void onResponse(Call<ShouyeshuiguoResult> call, Response<ShouyeshuiguoResult> response) {
ShouyeshuiguoResult shouyeshuiguoResult = response.body();
if (shouyeshuiguoResult != null) {
if (shouyeshuiguoResult.code == 200) {
// 清空原有数据
list.clear();
// 将新数据添加到列表中
for (ShouyeshuiguoResult.RowsBean rowsBean : shouyeshuiguoResult.rows) {
list.add(rowsBean);
}
myAdapter.notifyDataSetChanged();
} else if (shouyeshuiguoResult.code == 401) {
// 处理未授权的情况例如提示用户重新登录
Log.e("HomeFragment", "Unauthorized access");
} else {
// 处理其他错误情况
Log.e("HomeFragment", "Error code: " + shouyeshuiguoResult.code);
}
} else {
// 处理响应为空的情况
Log.e("HomeFragment", "Response body is null");
}
}
@Override
public void onFailure(Call<ShouyeshuiguoResult> call, Throwable t) {
// 处理网络错误或其他异常
t.printStackTrace();
Log.e("HomeFragment", "Network error: " + t.getMessage());
}
});
return view;
}
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView textView1, textView2, textView3, textView4;
ImageButton imageButton1;
ConstraintLayout constraintLayout;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
textView1 = itemView.findViewById(R.id.textView67);
textView2 = itemView.findViewById(R.id.textView68);
textView3 = itemView.findViewById(R.id.textView70);
textView4 = itemView.findViewById(R.id.textView72);
imageButton1 = itemView.findViewById(R.id.imageButton30);
constraintLayout = itemView.findViewById(R.id.constraintLayout4);
}
}
public class MyAdapter extends RecyclerView.Adapter<MyViewHolder> {
private List<ShouyeshuiguoResult.RowsBean> list;
public MyAdapter(List<ShouyeshuiguoResult.RowsBean> list) {
this.list = list;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.home_moban, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
int adapterPosition = holder.getAdapterPosition();
if (adapterPosition != RecyclerView.NO_POSITION) {
holder.textView1.setText(list.get(adapterPosition).goodsname);
holder.textView2.setText(String.valueOf(list.get(adapterPosition).price));
holder.textView3.setText(list.get(adapterPosition).time1);
holder.textView4.setText(list.get(adapterPosition).time2);
// 使用 Glide 加载图片
String pictureUrl = list.get(adapterPosition).picture;
if (pictureUrl != null && !pictureUrl.isEmpty()) {
Glide.with(holder.itemView.getContext())
.load(pictureUrl)
.into(holder.imageButton1);
}
holder.imageButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int clickedPosition = holder.getAdapterPosition();
if (clickedPosition != RecyclerView.NO_POSITION) {
Intent intent = new Intent(HomeFragment.this.getActivity(), shuiguoxiangqingActivity.class);
intent.putExtra("id", list.get(clickedPosition).picture);
startActivity(intent);
}
}
});
}
}
@Override
public int getItemCount() {
return list.size();
}
}
}

View File

@ -0,0 +1,48 @@
package com.example.myapplication.dao;
import com.google.gson.annotations.SerializedName;
import java.util.List;
@lombok.NoArgsConstructor
@lombok.Data
public class ShouyeshuiguoResult {
@SerializedName("total")
public Integer total;
@SerializedName("rows")
public List<RowsBean> rows;
@SerializedName("code")
public Integer code;
@SerializedName("msg")
public String msg;
@lombok.NoArgsConstructor
@lombok.Data
public static class RowsBean {
@SerializedName("createBy")
public Object createBy;
@SerializedName("createTime")
public Object createTime;
@SerializedName("updateBy")
public Object updateBy;
@SerializedName("updateTime")
public Object updateTime;
@SerializedName("remark")
public Object remark;
@SerializedName("goodsId")
public Integer goodsId;
@SerializedName("goodsname")
public String goodsname;
@SerializedName("time1")
public String time1;
@SerializedName("time2")
public String time2;
@SerializedName("price")
public Double price;
@SerializedName("amount")
public String amount;
@SerializedName("picture")
public String picture;
}
}

View File

@ -0,0 +1,186 @@
package com.example.myapplication.dao;
import com.google.gson.annotations.SerializedName;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data
public class UserInformationResult {
@SerializedName("msg")
public String msg;
@SerializedName("code")
public Integer code;
@SerializedName("permissions")
public List<String> permissions;
@SerializedName("roles")
public List<String> roles;
@SerializedName("user")
public UserBean user;
@NoArgsConstructor
@Data
public static class UserBean {
@SerializedName("createBy")
public String createBy;
@SerializedName("createTime")
public String createTime;
@SerializedName("updateBy")
public Object updateBy;
@SerializedName("updateTime")
public Object updateTime;
@SerializedName("remark")
public String remark;
@SerializedName("params")
public ParamsBean params;
@SerializedName("userId")
public Integer userId;
@SerializedName("deptId")
public Integer deptId;
@SerializedName("userName")
public String userName;
@SerializedName("nickName")
public String nickName;
@SerializedName("email")
public String email;
@SerializedName("phonenumber")
public String phonenumber;
@SerializedName("sex")
public String sex;
@SerializedName("avatar")
public Object avatar;
@SerializedName("password")
public String password;
@SerializedName("status")
public String status;
@SerializedName("delFlag")
public String delFlag;
@SerializedName("loginIp")
public String loginIp;
@SerializedName("loginDate")
public String loginDate;
@SerializedName("dept")
public DeptBean dept;
@SerializedName("roles")
public List<RolesBean> roles;
@SerializedName("roleIds")
public Object roleIds;
@SerializedName("postIds")
public Object postIds;
@SerializedName("roleId")
public Object roleId;
@SerializedName("admin")
public Boolean admin;
@NoArgsConstructor
@Data
public static class ParamsBean {
@SerializedName("@type")
public String _$Type176;// FIXME check this code
}
@NoArgsConstructor
@Data
public static class DeptBean {
@SerializedName("createBy")
public Object createBy;
@SerializedName("createTime")
public Object createTime;
@SerializedName("updateBy")
public Object updateBy;
@SerializedName("updateTime")
public Object updateTime;
@SerializedName("remark")
public Object remark;
@SerializedName("params")
public ParamsBean params;
@SerializedName("deptId")
public Integer deptId;
@SerializedName("parentId")
public Integer parentId;
@SerializedName("ancestors")
public String ancestors;
@SerializedName("deptName")
public String deptName;
@SerializedName("orderNum")
public Integer orderNum;
@SerializedName("leader")
public String leader;
@SerializedName("phone")
public Object phone;
@SerializedName("email")
public Object email;
@SerializedName("status")
public String status;
@SerializedName("delFlag")
public Object delFlag;
@SerializedName("parentName")
public Object parentName;
@SerializedName("children")
public List<?> children;
@NoArgsConstructor
@Data
public static class ParamsBean {
@SerializedName("@type")
public String _$Type17;// FIXME check this code
}
}
@NoArgsConstructor
@Data
public static class RolesBean {
@SerializedName("createBy")
public Object createBy;
@SerializedName("createTime")
public Object createTime;
@SerializedName("updateBy")
public Object updateBy;
@SerializedName("updateTime")
public Object updateTime;
@SerializedName("remark")
public Object remark;
@SerializedName("params")
public ParamsBean params;
@SerializedName("roleId")
public Integer roleId;
@SerializedName("roleName")
public String roleName;
@SerializedName("roleKey")
public String roleKey;
@SerializedName("roleSort")
public Integer roleSort;
@SerializedName("dataScope")
public String dataScope;
@SerializedName("menuCheckStrictly")
public Boolean menuCheckStrictly;
@SerializedName("deptCheckStrictly")
public Boolean deptCheckStrictly;
@SerializedName("status")
public String status;
@SerializedName("delFlag")
public Object delFlag;
@SerializedName("flag")
public Boolean flag;
@SerializedName("menuIds")
public Object menuIds;
@SerializedName("deptIds")
public Object deptIds;
@SerializedName("permissions")
public Object permissions;
@SerializedName("admin")
public Boolean admin;
@NoArgsConstructor
@Data
public static class ParamsBean {
@SerializedName("@type")
public String _$Type33;// FIXME check this code
}
}
}
}

View File

@ -0,0 +1,29 @@
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.ImageButton;
public class shuiguoxiangqingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shuiguoxiangqing);
//返回
ImageButton imageButton = findViewById(R.id.imageButton31);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(shuiguoxiangqingActivity.this,yindaoActivity.class);
intent.putExtra("homefragment","HomeFragment");
startActivity(intent);
}
});
}
}

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".shuiguoxiangqingActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="409dp"
android:layout_height="729dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="407dp"
android:layout_height="60dp"
android:background="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView74"
android:layout_width="110dp"
android:layout_height="37dp"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="商品详情"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imageButton31"
android:layout_width="44dp"
android:layout_height="30dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/fanhui" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -128,6 +128,7 @@
app:layout_constraintTop_toBottomOf="@+id/constraintLayout3">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="407dp"
android:layout_height="537dp"
app:layout_constraintBottom_toBottomOf="parent"