| | |
| | | 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.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.database.response.UserInfo |
| | | |
| | | class NotificationsFragment : Fragment() { |
| | | |
| | |
| | | private var xiaohongshuUrl = "" |
| | | private var contactEmail = "" |
| | | private var shareText = "" |
| | | private var currentUserInfo: UserInfo? = null // 确保使用你的实际数据类 |
| | | |
| | | |
| | | private val editProfileLauncher = registerForActivityResult( |
| | | ActivityResultContracts.StartActivityForResult() |
| | |
| | | } |
| | | |
| | | private fun setupClickListeners() { |
| | | |
| | | // 支付插件 |
| | | binding.payPlugin.setOnClickListener { |
| | | // 跳转到支付插件页面 |
| | | lifecycleScope.launch { |
| | | try { |
| | | val response = RetrofitClient.apiService.getPayOrderInfo() |
| | | var orderInfo=response.data |
| | | Log.d("AliPayHelper","获取订单信息时: ${response}") |
| | | // 这里调用支付宝 |
| | | PayAbility.aliPay(requireActivity(), orderInfo, Observer { |
| | | when (it.resultStatus) { |
| | | "9000" -> { |
| | | // Snackbar.make(binding.root, "支付成功", Snackbar.LENGTH_LONG).show() |
| | | requireActivity().runOnUiThread { |
| | | Toast.makeText(requireContext(), "支付成功", Toast.LENGTH_LONG).show() |
| | | } |
| | | } |
| | | else -> { |
| | | // Snackbar.make(binding.root, "支付失败", Snackbar.LENGTH_LONG).show() |
| | | requireActivity().runOnUiThread { |
| | | Toast.makeText(requireContext(), "支付失败", Toast.LENGTH_LONG).show() |
| | | } |
| | | |
| | | } |
| | | } |
| | | }) |
| | | |
| | | } catch (e: Exception) { |
| | | Log.d("AliPayHelper","获取订单信息时发生错误: ${e.message}") |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 设置提醒 |
| | | binding.layoutReminder.setOnClickListener { |
| | | findNavController().navigate(R.id.action_navigation_notifications_to_reminderSettingsFragment) |
| | |
| | | startContentActivity("user_guide", "使用教程") |
| | | } |
| | | |
| | | // 头像点击 |
| | | // 头像点击老的处理逻辑 |
| | | 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续费 |
| | |
| | | try { |
| | | val response = RetrofitClient.apiService.getUserInfo("17586582287") |
| | | if (response.code == "0" && response.data != null) { |
| | | // 保存用户信息 |
| | | currentUserInfo = response.data |
| | | val userInfo = response.data |
| | | |
| | | |
| | | // 设置头像 |
| | | 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) { |
| | | binding.ivVip.visibility = View.VISIBLE |
| | | binding.cardVip.visibility = View.VISIBLE |
| | | binding.tvVipExpire.text = "${userInfo.passTime} 到期" |
| | | binding.tvVipExpire.text = "${userInfo.overTime} 到期" |
| | | } else { |
| | | //非会员信息 |
| | | binding.btnRenew.text = "立即开通" |
| | | binding.linearVipContainer.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.gray)) |
| | | binding.cardVip.visibility = View.GONE |
| | | } |
| | | } |
| | |
| | | |
| | | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
| | | super.onViewCreated(view, savedInstanceState) |
| | | |
| | | |
| | | // 加载用户信息 |
| | | lifecycleScope.launch { |
| | | loadUserInfo() |