| | |
| | | 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() { |
| | | |
| | |
| | | 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 |
| | | } |
| | |
| | | return binding.root |
| | | } |
| | | |
| | | override fun onResume() { |
| | | super.onResume() |
| | | // 重新加载用户信息 |
| | | loadUserInfo() |
| | | } |
| | | |
| | | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| | | super.onViewCreated(view, savedInstanceState) |
| | | |
| | |
| | | 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 { |
| | |
| | | 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() |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |