From 3466799c94227c5ebba9fb201621e745058867ee Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期二, 15 四月 2025 13:18:34 +0800 Subject: [PATCH] add: 消息提醒时间设定;会员到期时间调整; --- app/src/main/java/com/example/firstapp/ui/notifications/NotificationsFragment.kt | 268 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 241 insertions(+), 27 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 dbaa57e..b3fe265 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 @@ -11,13 +11,31 @@ import android.view.ViewGroup import android.widget.EditText 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.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() { @@ -27,6 +45,43 @@ // onDestroyView. private val binding get() = _binding!! + // 默认值 + private val DEFAULT_XIAOHONGSHU_URL = "https://www.xiaohongshu.com/user/profile/64978d5c000000001001ee26" + private val DEFAULT_EMAIL = "support@example.com" + private val DEFAULT_SHARE_TEXT = "推荐一个很棒的应用给你!\n下载地址:https://oia.xiaohongshu.com/oia" + + // 存储从接口获取的值 + private var xiaohongshuUrl = "" + private var contactEmail = "" + private var shareText = "" + private var currentUserInfo: UserInfo? = null // 确保使用你的实际数据类 + + + private val editProfileLauncher = registerForActivityResult( + ActivityResultContracts.StartActivityForResult() + ) { result -> + if (result.resultCode == AppCompatActivity.RESULT_OK) { + result.data?.let { data -> + // 更新昵称 + val newNickname = data.getStringExtra("nickname") + newNickname?.let { + binding.tvNickname.text = it + } + + // 更新头像 + val avatarUri = data.getStringExtra("avatar_uri") + avatarUri?.let { + Glide.with(requireContext()) + .load(Uri.parse(it)) + .circleCrop() + .into(binding.ivAvatar) + } + + // TODO: 将更新后的信息保存到服务器 + } + } + } + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -34,57 +89,160 @@ ): View { _binding = FragmentNotificationsBinding.inflate(inflater, container, false) - setupClickListeners() + // 先加载配置,再设置点击事件 + lifecycleScope.launch { + loadConfigurations() + setupClickListeners() + } return binding.root } + override fun onResume() { + super.onResume() + // 加载用户信息 + lifecycleScope.launch { + loadUserInfo() + } + } + + private suspend fun loadConfigurations() { + try { + // 获取小红书链接 + val xhsResponse = RetrofitClient.apiService.getDictValue("setting", "xiaohongshu") + if (xhsResponse.code == 200 && !xhsResponse.data?.itemValue.isNullOrEmpty()) { + xiaohongshuUrl = xhsResponse.data?.itemValue ?: DEFAULT_XIAOHONGSHU_URL + } else { + xiaohongshuUrl = DEFAULT_XIAOHONGSHU_URL + } + + // 获取邮箱 + val emailResponse = RetrofitClient.apiService.getDictValue("setting", "email") + if (emailResponse.code == 200 && !emailResponse.data?.itemValue.isNullOrEmpty()) { + contactEmail = emailResponse.data?.itemValue ?: DEFAULT_EMAIL + } else { + contactEmail = DEFAULT_EMAIL + } + + // 获取分享文本 + val shareResponse = RetrofitClient.apiService.getDictValue("setting", "share_link") + if (shareResponse.code == 200 && !shareResponse.data?.itemValue.isNullOrEmpty()) { + shareText = shareResponse.data?.itemValue ?: DEFAULT_SHARE_TEXT + } else { + shareText = DEFAULT_SHARE_TEXT + } + } catch (e: Exception) { + // 如果发生错误,使用默认值 + xiaohongshuUrl = DEFAULT_XIAOHONGSHU_URL + contactEmail = DEFAULT_EMAIL + shareText = DEFAULT_SHARE_TEXT + } + } + private fun setupClickListeners() { + + // 设置提醒 - binding.settingsReminder.setOnClickListener { - // 跳转到设置提醒页面 - findNavController().navigate(R.id.action_navigation_notifications_to_reminderSettingsFragment) + binding.layoutReminder.setOnClickListener { + Toast.makeText(context, "设置功能开发中", Toast.LENGTH_SHORT).show() } -// 设置其他提醒 暂时不需要 -// binding.settingsReminderOther.setOnClickListener { -// // 跳转到设置提醒页面 -// findNavController().navigate(R.id.action_settings_to_reminderSettingsFragmentOther) -// } + // 待办 + binding.layoutTodo.setOnClickListener { + // TODO: 实现待办功能 + Toast.makeText(context, "待办功能开发中", Toast.LENGTH_SHORT).show() + } + // 好友邀请 + binding.layoutInvite.setOnClickListener { + // 跳转到邀请活动页面 + val intent = Intent(requireActivity(), InvitationActivity::class.java) + startActivity(intent) + } + // AI助手 + binding.layoutAi.setOnClickListener { + // TODO: 实现AI助手功能 + Toast.makeText(context, "AI助手功能开发中", Toast.LENGTH_SHORT).show() + } + + // 离线模式 + binding.layoutOffline.setOnClickListener { + // TODO: 实现离线模式功能 + Toast.makeText(context, "离线模式功能开发中", Toast.LENGTH_SHORT).show() + } // 关于小红书 - binding.aboutApp.setOnClickListener { - // 跳转到小红书账号页面 - val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.xiaohongshu.com/user/profile/64978d5c000000001001ee26")) + binding.layoutAbout.setOnClickListener { + val intent = Intent(Intent.ACTION_VIEW, Uri.parse(xiaohongshuUrl)) startActivity(intent) } // 邮件联系 - binding.emailContact.setOnClickListener { + binding.layoutEmail.setOnClickListener { showEmailDialog() } // 意见与反馈 - binding.feedback.setOnClickListener { + binding.layoutFeedback.setOnClickListener { showFeedbackDialog() } - // 分享给好友 - binding.shareToFriends.setOnClickListener { - shareToWechat() + // 隐私协议 + binding.layoutPrivacy.setOnClickListener { + startContentActivity("隐私协议", "隐私协议") } + + // 使用教程 + binding.layoutTutorial.setOnClickListener { + startContentActivity("使用教程", "使用教程") + } + + // 头像点击老的处理逻辑 + binding.layoutUserInfo.setOnClickListener { + 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() + } + } + + // VIP续费 + binding.btnRenew.setOnClickListener { +// 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() { - val email = "support@example.com" MaterialAlertDialogBuilder(requireContext()) .setTitle("联系邮箱") - .setMessage(email) + .setMessage(contactEmail) .setPositiveButton("复制") { _, _ -> val clipboard = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - val clip = ClipData.newPlainText("email", email) + val clip = ClipData.newPlainText("email", contactEmail) clipboard.setPrimaryClip(clip) Toast.makeText(context, "邮箱已复制", Toast.LENGTH_SHORT).show() } @@ -115,9 +273,6 @@ // 获取应用程序的包名 //val packageName = requireContext().packageName - // 创建分享文本 - val shareText = "推荐一个很棒的应用给你!\n" + "下载地址:https://oia.xiaohongshu.com/oia" - // 创建分享意图 val intent = Intent().apply { action = Intent.ACTION_SEND @@ -127,16 +282,75 @@ // 指定分享到微信 setPackage("com.tencent.mm") } -// intent.setPackage("com.tencent.mm") -// intent.action = Intent.ACTION_SEND -// intent.type = "text/plain" -// intent.putExtra(Intent.EXTRA_TEXT, "推荐一个很棒的应用给你!") startActivity(Intent.createChooser(intent, "分享到微信")) } catch (e: Exception) { Toast.makeText(context, "请先安装微信", Toast.LENGTH_SHORT).show() } } + private fun startContentActivity(id: String, title: String) { + val intent = Intent(requireContext(), ContentDetailActivity::class.java).apply { + putExtra(ContentDetailActivity.ID, id) + putExtra(ContentDetailActivity.EXTRA_TITLE, title) + } + startActivity(intent) + } + + private suspend fun loadUserInfo() { + try { + // 从本地获取保存的手机号 + 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.isMember) { + binding.ivVip.visibility = View.VISIBLE + binding.cardVip.visibility = View.VISIBLE + binding.tvVipExpire.text = "${userInfo.memberOverDate} 到期" + } else { + //非会员信息 + 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) { + e.printStackTrace() + Toast.makeText(context, "获取用户信息失败", Toast.LENGTH_SHORT).show() + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + // 加载用户信息 + lifecycleScope.launch { + loadUserInfo() + } + } + override fun onDestroyView() { super.onDestroyView() _binding = null -- Gitblit v1.9.3