From 33c7ed565ad6bfb30eee84acc33b39e6b639ade9 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期五, 18 四月 2025 08:54:45 +0800
Subject: [PATCH] fix: 样式

---
 app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt |  119 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 98 insertions(+), 21 deletions(-)

diff --git a/app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt b/app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt
index a2becfc..09bd8da 100644
--- a/app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt
+++ b/app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt
@@ -13,19 +13,30 @@
 import android.widget.Toast
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.ContextCompat
 import androidx.fragment.app.Fragment
+import androidx.lifecycle.Observer
 import androidx.lifecycle.lifecycleScope
 import androidx.navigation.fragment.findNavController
 import com.google.android.material.dialog.MaterialAlertDialogBuilder
 import com.example.firstapp.R
 import com.example.firstapp.activity.ContentDetailActivity
+import com.example.firstapp.activity.ReminderSettingsActivity
 import com.example.firstapp.database.service.RetrofitClient
 import com.example.firstapp.databinding.FragmentNotificationsBinding
+import com.example.firstapp.pay.PayAbility
 import com.example.firstapp.ui.reminderOther.ReminderOtherAddActivity2
 import com.example.firstapp.ui.reminderOther.ReminderSettingsFragmentOther
 import com.example.firstapp.ui.profile.EditProfileActivity
+import com.example.firstapp.utils.Log
+import com.google.android.material.snackbar.Snackbar
 import kotlinx.coroutines.launch
 import com.bumptech.glide.Glide
+import com.example.firstapp.activity.SettingActivity
+import com.example.firstapp.activity.VipActivity
+import com.example.firstapp.database.response.UserInfo
+import com.example.firstapp.ui.invitation.InvitationActivity
+import com.example.firstapp.utils.PreferencesManager
 
 class NotificationsFragment : Fragment() {
 
@@ -44,6 +55,8 @@
     private var xiaohongshuUrl = ""
     private var contactEmail = ""
     private var shareText = ""
+    private var currentUserInfo: UserInfo? = null // 确保使用你的实际数据类
+
 
     private val editProfileLauncher = registerForActivityResult(
         ActivityResultContracts.StartActivityForResult()
@@ -86,6 +99,14 @@
         return binding.root
     }
 
+    override fun onResume() {
+        super.onResume()
+        // 加载用户信息
+        lifecycleScope.launch {
+            loadUserInfo()
+        }
+    }
+
     private suspend fun loadConfigurations() {
         try {
             // 获取小红书链接
@@ -120,9 +141,25 @@
     }
 
     private fun setupClickListeners() {
+
         // 设置提醒
         binding.layoutReminder.setOnClickListener {
-            findNavController().navigate(R.id.action_navigation_notifications_to_reminderSettingsFragment)
+            // 判断是否是会员
+            currentUserInfo?.let { user ->
+                if (user.isMember) {
+                    // 是会员,跳转到提醒设置页面
+                    val intent = Intent(requireContext(), ReminderSettingsActivity::class.java)
+                    startActivity(intent)
+                } else {
+                    // 不是会员,跳转到VIP页面
+                    val intent = Intent(requireContext(), VipActivity::class.java)
+                    intent.putExtra("source", "reminder")
+                    startActivity(intent)
+                    Toast.makeText(context, "开通会员后可使用提醒功能", Toast.LENGTH_SHORT).show()
+                }
+            } ?: run {
+                Toast.makeText(context, "正在加载用户信息,请稍后再试", Toast.LENGTH_SHORT).show()
+            }
         }
 
         // 待办
@@ -133,7 +170,9 @@
 
         // 好友邀请
         binding.layoutInvite.setOnClickListener {
-            shareToWechat()
+            // 跳转到邀请活动页面
+            val intent = Intent(requireActivity(), InvitationActivity::class.java)
+            startActivity(intent)
         }
 
         // AI助手
@@ -166,28 +205,50 @@
 
         // 隐私协议
         binding.layoutPrivacy.setOnClickListener {
-            startContentActivity("privacy_policy", "隐私协议")
+            startContentActivity("隐私协议", "隐私协议")
         }
 
         // 使用教程
         binding.layoutTutorial.setOnClickListener {
-            startContentActivity("user_guide", "使用教程")
+            startContentActivity("使用教程", "使用教程")
         }
 
-        // 头像点击
+        // 头像点击老的处理逻辑
         binding.layoutUserInfo.setOnClickListener {
-            val intent = Intent(requireContext(), EditProfileActivity::class.java).apply {
-                putExtra("nickname", binding.tvNickname.text.toString())
-                // 如果有当前头像的URL,也可以传递
-                // putExtra("avatar_url", currentAvatarUrl)
+            currentUserInfo?.let { user ->
+                val intent = Intent(requireContext(), EditProfileActivity::class.java).apply {
+                    putExtra("nickname", user.name) // 使用数据模型中的字段
+                    putExtra("avatar_url", user.cover) // 使用正确的URL字段
+                }
+                editProfileLauncher.launch(intent)
+            } ?: run {
+                Toast.makeText(context, "用户信息未加载完成", Toast.LENGTH_SHORT).show()
             }
-            editProfileLauncher.launch(intent)
         }
 
         // VIP续费
         binding.btnRenew.setOnClickListener {
-            Toast.makeText(context, "VIP续费功能开发中", Toast.LENGTH_SHORT).show()
+//            Toast.makeText(context, "VIP续费功能开发中", Toast.LENGTH_SHORT).show()
+            // 跳转到vipActivity
+            val intent = Intent(requireContext(), VipActivity::class.java)
+            startActivity(intent)
         }
+
+        binding.cardVip.setOnClickListener {
+//            Toast.makeText(context, "VIP续费功能开发中", Toast.LENGTH_SHORT).show()
+            // 跳转到vipActivity
+            val intent = Intent(requireContext(), VipActivity::class.java)
+            startActivity(intent)
+        }
+
+        // 设置按钮点击
+        binding.ivSetting.setOnClickListener {
+            // 跳转到
+            val intent = Intent(requireContext(), SettingActivity::class.java)
+            startActivity(intent)
+        }
+
+
     }
 
     private fun showEmailDialog() {
@@ -242,9 +303,9 @@
         }
     }
 
-    private fun startContentActivity(type: String, title: String) {
+    private fun startContentActivity(id: String, title: String) {
         val intent = Intent(requireContext(), ContentDetailActivity::class.java).apply {
-            putExtra(ContentDetailActivity.EXTRA_CONTENT_TYPE, type)
+            putExtra(ContentDetailActivity.ID, id)
             putExtra(ContentDetailActivity.EXTRA_TITLE, title)
         }
         startActivity(intent)
@@ -252,26 +313,42 @@
 
     private suspend fun loadUserInfo() {
         try {
-            val response = RetrofitClient.apiService.getUserInfo("17586582287")
+            // 从本地获取保存的手机号
+            val savedPhone = PreferencesManager.getPhone()
+            if (savedPhone.isNullOrEmpty()) {
+                Toast.makeText(context, "用户未登录", Toast.LENGTH_SHORT).show()
+                return
+            }
+
+            val response = RetrofitClient.apiService.getUserInfo(savedPhone)
             if (response.code == "0" && response.data != null) {
+                // 保存用户信息
+                currentUserInfo = response.data
                 val userInfo = response.data
-                
+
+                // 本地保存我的邀请码
+//                PreferencesManager.setInviteCode(userInfo.intervialcode);
                 // 设置头像
                 Glide.with(this)
                     .load(userInfo.cover)
                     .placeholder(R.drawable.default_avatar)
                     .into(binding.ivAvatar)
-                
+
                 // 设置昵称和账号
                 binding.tvNickname.text = userInfo.name
                 binding.tvUserId.text = "个人账号:${userInfo.contactTel}"
-                
+
                 // 设置VIP信息
-                if (userInfo.showed) {
+                if (userInfo.isMember) {
+                    binding.ivVip.visibility = View.VISIBLE
                     binding.cardVip.visibility = View.VISIBLE
-                    binding.tvVipExpire.text = "${userInfo.passTime} 到期"
+                    binding.tvVipExpire.text = "${userInfo.memberOverDate} 到期"
                 } else {
-                    binding.cardVip.visibility = View.GONE
+                    //非会员信息
+                    binding.ivVip.visibility = View.GONE
+                    binding.cardVip.visibility = View.VISIBLE
+                    binding.btnRenew.text = "立即开通"
+                    binding.linearVipContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.gray))
                 }
             }
         } catch (e: Exception) {
@@ -282,7 +359,7 @@
 
     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
         super.onViewCreated(view, savedInstanceState)
-        
+
         // 加载用户信息
         lifecycleScope.launch {
             loadUserInfo()

--
Gitblit v1.9.3