From 2b446a5fd5d8f9b8c0f1e3acef1eef7ad9adb6f9 Mon Sep 17 00:00:00 2001
From: tj <1378534974@qq.com>
Date: 星期三, 09 四月 2025 10:25:27 +0800
Subject: [PATCH] 1.1
---
app/src/main/java/com/example/firstapp/ui/dashboard/DashboardFragment.kt | 80 +++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 1 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardFragment.kt b/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardFragment.kt
index 8a67903..21cb233 100644
--- a/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardFragment.kt
+++ b/app/src/main/java/com/example/firstapp/ui/dashboard/DashboardFragment.kt
@@ -21,8 +21,18 @@
import java.util.*
import java.text.SimpleDateFormat
import android.graphics.Color
+import android.widget.Button
import android.widget.GridLayout
+import android.widget.Toast
+import androidx.core.content.ContextCompat
+import androidx.lifecycle.lifecycleScope
+import com.bumptech.glide.Glide
+import com.example.firstapp.database.response.UserInfo
+import com.example.firstapp.database.service.RetrofitClient
import com.example.firstapp.model.DailyStat
+import com.example.firstapp.utils.PreferencesManager
+import com.github.mikephil.charting.components.YAxis
+import kotlinx.coroutines.launch
class DashboardFragment : Fragment() {
@@ -34,6 +44,9 @@
private lateinit var barChart: BarChart
private lateinit var pieChart: PieChart
private lateinit var heatmapView: View
+ private var currentUserInfo: UserInfo? = null // 确保使用你的实际数据类
+
+
enum class DateType {
DAY, WEEK, MONTH, YEAR
}
@@ -48,6 +61,12 @@
return binding.root
}
+ override fun onResume() {
+ super.onResume()
+ // 重新加载用户信息
+ loadUserInfo()
+ }
+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@@ -60,7 +79,31 @@
setupView(view)
updateDateDisplay()
loadPackages()
+
+ // 遮罩层
+ loadUserInfo()
+
+ // 遮罩层点击时间
+ binding.overlayContent.setOnClickListener {
+ // 跳转到vipActivity
+ val intent = android.content.Intent(requireContext(), com.example.firstapp.activity.VipActivity::class.java)
+ startActivity(intent)
+ }
}
+
+ private fun showOverlay() {
+ binding.viewOverlay.visibility = View.VISIBLE
+ binding.overlayContent.visibility = View.VISIBLE
+
+ }
+
+ private fun hiddleOverlay() {
+ binding.viewOverlay.visibility = View.GONE
+ binding.overlayContent.visibility = View.GONE
+
+
+ }
+
private fun setupRecyclerView() {
binding.recyclerPackages.apply {
@@ -163,7 +206,8 @@
setDrawGridLines(false)
granularity = 1f
labelRotationAngle = 0f
- textSize = 12f
+ textSize = 10f //标签字体
+ setExtraLeftOffset(5f) // 减少左侧留白
setExtraBottomOffset(15f)
}
@@ -189,6 +233,8 @@
setExtraOffsets(10f, 10f, 10f, 20f)
}
+
+
updateBarChartData()
}
private fun updateBarChartData() {
@@ -512,6 +558,7 @@
binding.layoutWeekStats.root.visibility = View.VISIBLE
binding.layoutYearStats.root.visibility = View.GONE
binding.layoutWeekStats.chartDailyPackages.visibility = View.VISIBLE
+ (binding.layoutWeekStats.chartDailyPackages.parent as? View)?.visibility = View.VISIBLE
binding.layoutWeekStats.heatmapYearly.visibility = View.GONE
binding.cardPackageStats.visibility = View.VISIBLE
updateBarChartData()
@@ -549,4 +596,35 @@
super.onDestroyView()
_binding = null
}
+ private fun loadUserInfo() {
+
+ lifecycleScope.launch {
+ try {
+ // 从本地获取保存的手机号
+ val savedPhone = PreferencesManager.getPhone()
+ if (savedPhone.isNullOrEmpty()) {
+ Toast.makeText(context, "用户未登录", Toast.LENGTH_SHORT).show()
+ return@launch
+ }
+
+ val response = RetrofitClient.apiService.getUserInfo(savedPhone)
+ if (response.code == "0" && response.data != null) {
+ // 保存用户信息
+ currentUserInfo = response.data
+ val userInfo = response.data
+ if(userInfo.isMember){
+ hiddleOverlay()
+ }else{
+ // 显示遮罩层
+ showOverlay()
+ }
+
+ }
+ } catch (e: Exception) {
+ e.printStackTrace()
+ Toast.makeText(context, "获取用户信息失败", Toast.LENGTH_SHORT).show()
+ }
+ }
+
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3