From 5fc9567cfa6b6beee4f52a9f835f304865d693e1 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期四, 10 四月 2025 18:13:58 +0800
Subject: [PATCH] add: 消息提醒后版本
---
app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt | 76 ++++++++++++++++++++++++++-----------
1 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt b/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
index 2a10248..a6782f5 100644
--- a/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
+++ b/app/src/main/java/com/example/firstapp/ui/home/HomeFragment.kt
@@ -34,6 +34,7 @@
import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.coroutines.launch
import com.example.firstapp.view.UnderlineTextView
+import com.example.firstapp.activity.ReminderListActivity
class HomeFragment : Fragment() {
@@ -322,7 +323,7 @@
tabFlight.visibility = View.GONE
tabTrain.visibility = View.GONE
- // 非会员只显示快递和还款
+ // 获取用户信息判断是否是会员
val savedPhone = PreferencesManager.getPhone()
lifecycleScope.launch {
try {
@@ -343,24 +344,24 @@
categories.forEach { category ->
when (category.name) {
"快递" -> {
- tabExpress.visibility = View.VISIBLE
- if (categories.indexOf(category) == 0) tabExpress.performClick()
+ tabExpress.visibility = if (category.isEnabled) View.VISIBLE else View.GONE
+ if (categories.indexOf(category) == 0 && category.isEnabled) tabExpress.performClick()
}
"还款" -> {
- tabFinance.visibility = View.VISIBLE
- if (categories.indexOf(category) == 0) tabFinance.performClick()
+ tabFinance.visibility = if (category.isEnabled) View.VISIBLE else View.GONE
+ if (categories.indexOf(category) == 0 && category.isEnabled) tabFinance.performClick()
}
"收入" -> {
- tabIncome.visibility = View.VISIBLE
- if (categories.indexOf(category) == 0) tabIncome.performClick()
+ tabIncome.visibility = if (category.isEnabled) View.VISIBLE else View.GONE
+ if (categories.indexOf(category) == 0 && category.isEnabled) tabIncome.performClick()
}
"航班" -> {
- tabFlight.visibility = View.VISIBLE
- if (categories.indexOf(category) == 0) tabFlight.performClick()
+ tabFlight.visibility = if (category.isEnabled) View.VISIBLE else View.GONE
+ if (categories.indexOf(category) == 0 && category.isEnabled) tabFlight.performClick()
}
"火车票" -> {
- tabTrain.visibility = View.VISIBLE
- if (categories.indexOf(category) == 0) tabTrain.performClick()
+ tabTrain.visibility = if (category.isEnabled) View.VISIBLE else View.GONE
+ if (categories.indexOf(category) == 0 && category.isEnabled) tabTrain.performClick()
}
}
}
@@ -406,16 +407,16 @@
_binding = null
}
- private fun loadAdvertisements() {
- // 使用 Glide 加载网络图片
- Glide.with(this)
- .load("http://192.168.1.235:9999/advertisement/up.png")
- .into(binding.adBanner)
-
- Glide.with(this)
- .load("http://192.168.1.235:9999/advertisement/down.png")
- .into(binding.bottomAdBanner)
- }
+// private fun loadAdvertisements() {
+// // 使用 Glide 加载网络图片
+// Glide.with(this)
+// .load("http://192.168.1.235:9999/advertisement/up.png")
+// .into(binding.adBanner)
+//
+// Glide.with(this)
+// .load("http://192.168.1.235:9999/advertisement/down.png")
+// .into(binding.bottomAdBanner)
+// }
// 设置分类选择器 检查会员状态
private fun setupCategorySelector() {
@@ -448,6 +449,11 @@
}
}
}
+
+ // 添加提醒按钮点击事件
+// binding.reminderButton.setOnClickListener {
+// startActivity(Intent(requireContext(), ReminderListActivity::class.java))
+// }
}
private fun showCategorySelectorDialog() {
@@ -461,9 +467,33 @@
this.adapter = adapter
}
- // 加载现有分类
+ // 加载所有分类
homeViewModel.categories.observe(viewLifecycleOwner) { categories ->
- adapter.setCategories(categories)
+ // 如果是会员,显示所有分类供选择
+ lifecycleScope.launch {
+ try {
+ val savedPhone = PreferencesManager.getPhone()
+ val response = RetrofitClient.apiService.getUserInfo(savedPhone ?: "")
+ val isMember = response.code == "0" && response.data?.isMember == true
+
+ if (isMember) {
+ // 会员可以看到所有分类
+ adapter.setCategories(categories)
+ } else {
+ // 非会员只能看到快递和还款
+ val limitedCategories = categories.filter {
+ it.name == "快递" || it.name == "还款"
+ }
+ adapter.setCategories(limitedCategories)
+ }
+ } catch (e: Exception) {
+ // 发生错误时只显示基础分类
+ val limitedCategories = categories.filter {
+ it.name == "快递" || it.name == "还款"
+ }
+ adapter.setCategories(limitedCategories)
+ }
+ }
}
dialogBinding.saveButton.setOnClickListener {
--
Gitblit v1.9.3