From 97526598ea27bbe5449fe409d85e6fb423606221 Mon Sep 17 00:00:00 2001 From: Lixin <2563946749@qq.com> Date: Sun, 22 Dec 2024 16:21:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A410?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/myapplication/Api.java | 4 + .../example/myapplication/MineFragment.java | 13 ++- .../example/myapplication/VipFragment.java | 100 +++++++++++++++++- .../myapplication/dao/VipdataResult.java | 61 +++++++++++ .../example/myapplication/yindaoActivity.java | 3 +- app/src/main/res/layout/fragment_vip.xml | 2 +- 6 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/com/example/myapplication/dao/VipdataResult.java diff --git a/app/src/main/java/com/example/myapplication/Api.java b/app/src/main/java/com/example/myapplication/Api.java index 143dafc..8f972c6 100644 --- a/app/src/main/java/com/example/myapplication/Api.java +++ b/app/src/main/java/com/example/myapplication/Api.java @@ -6,6 +6,7 @@ import com.example.myapplication.dao.ShouyeshuiguoResult; import com.example.myapplication.dao.UserInformationResult; import com.example.myapplication.dao.UserInformationResult2; import com.example.myapplication.dao.TwodimensionResult; +import com.example.myapplication.dao.VipdataResult; import java.util.Map; @@ -33,4 +34,7 @@ public interface Api { @GET("system/goodsinformation/list") Call getGoodsinformation(@Header("Authorization") String token); + @GET("system/vip/list") + Call getVipdata(@Header("Authorization") String token); + } diff --git a/app/src/main/java/com/example/myapplication/MineFragment.java b/app/src/main/java/com/example/myapplication/MineFragment.java index 2b15b36..db4766f 100644 --- a/app/src/main/java/com/example/myapplication/MineFragment.java +++ b/app/src/main/java/com/example/myapplication/MineFragment.java @@ -2,9 +2,12 @@ package com.example.myapplication; import static android.content.Context.MODE_PRIVATE; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.content.Intent; + +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import android.util.Log; import android.view.LayoutInflater; @@ -25,7 +28,6 @@ import retrofit2.Callback; import retrofit2.Response; public class MineFragment extends Fragment { - private HomeFragment.MyAdapter myAdapter; private List list; @@ -133,6 +135,15 @@ public class MineFragment extends Fragment { Glide.with(getContext()).load(avatarUrl).into(imageView); } + + // 保存 nickName 和 avatar 到 SharedPreferences + SharedPreferences userSharedPreferences = getActivity().getSharedPreferences("UserInformation", MODE_PRIVATE); + SharedPreferences.Editor editor = userSharedPreferences.edit(); + editor.putString("nickName", user.nickName); + editor.putString("avatar", avatarUrl); + editor.apply(); + + } else if (userInformationResult.code == 401) { Log.e("MineFragment", "Unauthorized access"); } else { diff --git a/app/src/main/java/com/example/myapplication/VipFragment.java b/app/src/main/java/com/example/myapplication/VipFragment.java index bce6d99..0c5ec3d 100644 --- a/app/src/main/java/com/example/myapplication/VipFragment.java +++ b/app/src/main/java/com/example/myapplication/VipFragment.java @@ -1,18 +1,114 @@ 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.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.example.myapplication.Utils.RetrofitUtils; +import com.example.myapplication.dao.UserInformationResult2; +import com.example.myapplication.dao.VipdataResult; + +import java.util.List; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; public class VipFragment extends Fragment { + + private TextView textView37; + private ImageView imageView5; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_vip, container, false); + View view = inflater.inflate(R.layout.fragment_vip, container, false); + + // 初始化其他TextView + TextView textView24 = view.findViewById(R.id.textView24); + TextView textView25 = view.findViewById(R.id.textView25); + TextView textView26 = view.findViewById(R.id.textView26); + TextView textView27 = view.findViewById(R.id.textView27); + TextView textView28 = view.findViewById(R.id.textView28); + TextView textView29 = view.findViewById(R.id.textView29); + TextView textView30 = view.findViewById(R.id.textView30); + TextView textView31 = view.findViewById(R.id.textView31); + TextView textView32 = view.findViewById(R.id.textView32); + TextView textView33 = view.findViewById(R.id.textView33); + + // 初始化 textView37 和 imageView5 + textView37 = view.findViewById(R.id.textView37); + imageView5 = view.findViewById(R.id.imageView5); + + +// 从 SharedPreferences 读取数据 + SharedPreferences userSharedPreferences = getActivity().getSharedPreferences("UserInformation", MODE_PRIVATE); + String nickName = userSharedPreferences.getString("nickName", ""); + String avatarUrl = userSharedPreferences.getString("avatar", ""); + +// 设置数据到 UI 组件 + textView37.setText(nickName); + if (!avatarUrl.isEmpty()) { + Glide.with(this).load(avatarUrl).into(imageView5); + } + + SharedPreferences sharedPreferences = getActivity().getSharedPreferences("data", MODE_PRIVATE); + String token = sharedPreferences.getString("token", ""); + Call vipdataResultCall = + RetrofitUtils.getRetrofit("http://192.168.56.115:8080/").create(Api.class).getVipdata("Bearer " + token); + vipdataResultCall.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + VipdataResult vipdataResult = response.body(); + if (vipdataResult != null) { + if (vipdataResult.code == 200) { + // 清空原有数据 + for (VipdataResult.RowsBean rowsBean : vipdataResult.rows) { + // 将新数据添加到列表中 + textView24.setText(String.valueOf(rowsBean.totalallpeople)); + textView25.setText(String.valueOf(rowsBean.zhixituanzhang)); + textView26.setText(String.valueOf(rowsBean.xinzengtuanzhang)); + textView27.setText(String.valueOf(rowsBean.xinzengyonghu)); + textView28.setText(String.valueOf(rowsBean.dingdanzongshu)); + textView29.setText(String.valueOf(rowsBean.jinridingdan)); + textView30.setText(String.valueOf(rowsBean.shouhoudingdan)); + textView31.setText(String.valueOf(rowsBean.allshouyi)); + textView32.setText(String.valueOf(rowsBean.todayyongjin)); + textView33.setText(String.valueOf(rowsBean.todaylaxin)); + } + } else if (vipdataResult.code == 401) { + // 处理未授权的情况,例如提示用户登录 + Log.e("VipFragment", "Unauthorized access"); + } else { + // 处理其他错误情况 + Log.e("VipFragment", "Error code: " + vipdataResult.code); + } + } else { + // 处理响应为空的情况 + Log.e("VipFragment", "Response body is null"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + // 处理网络错误或其他异常 + t.printStackTrace(); + Log.e("VipFragment", "Network error: " + t.getMessage()); + } + }); + + return view; } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/myapplication/dao/VipdataResult.java b/app/src/main/java/com/example/myapplication/dao/VipdataResult.java new file mode 100644 index 0000000..26ba678 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/dao/VipdataResult.java @@ -0,0 +1,61 @@ +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 VipdataResult { + + @SerializedName("total") + public Integer total; + @SerializedName("rows") + public List rows; + @SerializedName("code") + public Integer code; + @SerializedName("msg") + public String msg; + + @NoArgsConstructor + @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("id") + public Integer id; + @SerializedName("totalallpeople") + public Integer totalallpeople; + @SerializedName("zhixituanzhang") + public Integer zhixituanzhang; + @SerializedName("xinzengtuanzhang") + public Integer xinzengtuanzhang; + @SerializedName("xinzengyonghu") + public Integer xinzengyonghu; + @SerializedName("dingdanzongshu") + public Integer dingdanzongshu; + @SerializedName("jinridingdan") + public Integer jinridingdan; + @SerializedName("shouhoudingdan") + public Integer shouhoudingdan; + @SerializedName("allshouyi") + public Integer allshouyi; + @SerializedName("todayyongjin") + public Integer todayyongjin; + @SerializedName("todaylaxin") + public Integer todaylaxin; + @SerializedName("twodimensionid") + public Integer twodimensionid; + } +} diff --git a/app/src/main/java/com/example/myapplication/yindaoActivity.java b/app/src/main/java/com/example/myapplication/yindaoActivity.java index 625dc56..dc3f7a5 100644 --- a/app/src/main/java/com/example/myapplication/yindaoActivity.java +++ b/app/src/main/java/com/example/myapplication/yindaoActivity.java @@ -9,7 +9,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; -public class yindaoActivity extends AppCompatActivity { +public class yindaoActivity extends AppCompatActivity { private HomeFragment homeFragment; private FindFragment findFragment; @@ -94,4 +94,5 @@ public class yindaoActivity extends AppCompatActivity { button.setSelected(button == selectedButton); } } + } diff --git a/app/src/main/res/layout/fragment_vip.xml b/app/src/main/res/layout/fragment_vip.xml index 755f369..52639c9 100644 --- a/app/src/main/res/layout/fragment_vip.xml +++ b/app/src/main/res/layout/fragment_vip.xml @@ -136,7 +136,7 @@ android:layout_width="99dp" android:layout_height="29dp" android:gravity="center" - android:text="39" + android:text="DFSWA2" android:textColor="#FFFFFF" android:textSize="18dp" android:textStyle="bold"