| | |
| | | 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.lifecycleScope |
| | | import androidx.navigation.fragment.findNavController |
| | |
| | | import com.example.firstapp.ui.profile.EditProfileActivity |
| | | 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() |
| | |
| | | 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) |
| | |
| | | |
| | | // 设置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 |
| | | } |
| | | } |