| | |
| | | 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() { |
| | | |
| | |
| | | tabFlight.visibility = View.GONE |
| | | tabTrain.visibility = View.GONE |
| | | |
| | | // 非会员只显示快递和还款 |
| | | // 获取用户信息判断是否是会员 |
| | | val savedPhone = PreferencesManager.getPhone() |
| | | lifecycleScope.launch { |
| | | try { |
| | |
| | | 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() |
| | | } |
| | | } |
| | | } |
| | |
| | | _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() { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 添加提醒按钮点击事件 |
| | | // binding.reminderButton.setOnClickListener { |
| | | // startActivity(Intent(requireContext(), ReminderListActivity::class.java)) |
| | | // } |
| | | } |
| | | |
| | | private fun showCategorySelectorDialog() { |
| | |
| | | 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 { |