diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 36d689d..25151c7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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") + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8dd057d..ca73005 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,11 +7,12 @@ - - - - + + + + diff --git a/app/src/main/java/com/example/myapplication/Api.java b/app/src/main/java/com/example/myapplication/Api.java index 2c46c8c..a0af490 100644 --- a/app/src/main/java/com/example/myapplication/Api.java +++ b/app/src/main/java/com/example/myapplication/Api.java @@ -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 login(@Body Map map); + + @GET("system/goods/list") + Call shouyeshuiguolist(@Header("Authorization") String token); + + @GET("") + Call getUserInformation(@Header("Authorization") String token); + } diff --git a/app/src/main/java/com/example/myapplication/HomeFragment.java b/app/src/main/java/com/example/myapplication/HomeFragment.java index 260fa4d..cbd1300 100644 --- a/app/src/main/java/com/example/myapplication/HomeFragment.java +++ b/app/src/main/java/com/example/myapplication/HomeFragment.java @@ -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 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 shouyeshuiguoResultCall = + RetrofitUtils.getRetrofit("http://10.138.77.128:8080/").create(Api.class).shouyeshuiguolist("Bearer " + token); + shouyeshuiguoResultCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response 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 call, Throwable t) { + // 处理网络错误或其他异常 + t.printStackTrace(); + Log.e("HomeFragment", "Network error: " + t.getMessage()); + } + }); + + return view; } -} \ No newline at end of file + + 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 { + private List list; + + public MyAdapter(List 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(); + } + } +} diff --git a/app/src/main/java/com/example/myapplication/dao/ShouyeshuiguoResult.java b/app/src/main/java/com/example/myapplication/dao/ShouyeshuiguoResult.java new file mode 100644 index 0000000..d923305 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/dao/ShouyeshuiguoResult.java @@ -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 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; + } +} diff --git a/app/src/main/java/com/example/myapplication/dao/UserInformationResult.java b/app/src/main/java/com/example/myapplication/dao/UserInformationResult.java new file mode 100644 index 0000000..94b829b --- /dev/null +++ b/app/src/main/java/com/example/myapplication/dao/UserInformationResult.java @@ -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 permissions; + @SerializedName("roles") + public List 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 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 + } + } + } +} diff --git a/app/src/main/java/com/example/myapplication/shuiguoxiangqingActivity.java b/app/src/main/java/com/example/myapplication/shuiguoxiangqingActivity.java new file mode 100644 index 0000000..2e1fb20 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/shuiguoxiangqingActivity.java @@ -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); + } + }); + + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_shuiguoxiangqing.xml b/app/src/main/res/layout/activity_shuiguoxiangqing.xml new file mode 100644 index 0000000..0470b5e --- /dev/null +++ b/app/src/main/res/layout/activity_shuiguoxiangqing.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 619eacd..f5a86a5 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -128,6 +128,7 @@ app:layout_constraintTop_toBottomOf="@+id/constraintLayout3">