Kotlin高仿微信-第58篇-开通VIP

本篇详细介绍了使用Kotlin实现微信VIP功能的过程,包括弹窗确认对话框的设计及VIP续费逻辑。通过实际代码展示了如何进行用户交互、界面布局调整及后台处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  Kotlin高仿微信-项目实践58篇详细讲解了各个功能点,包括:注册、登录、主页、单聊(文本、表情、语音、图片、小视频、视频通话、语音通话、红包、转账)、群聊、个人信息、朋友圈、支付服务、扫一扫、搜索好友、添加好友、开通VIP等众多功能。

Kotlin高仿微信-项目实践58篇,点击查看详情

效果图:

实现代码:

**
 * 开通vip确认框
 */
private fun showVipConfirmDialog(month: Int, vipBean: VipBean){

    if(month < 1 || vipBean == null){
        ToastUtils.makeText(R.string.wc_vip_confirm_show_error)
        return
    }
    getFocus(true)
    var view = LayoutInflater.from(requireContext()).inflate(R.layout.wc_vip_confirm_view, null)
    var width = DisplayUtils.getScreenWidth() - BaseUtils.getDimension(R.dimen.distance_40) * 2
    val popupWindow = PopupWindow(view, width, ViewGroup.LayoutParams.WRAP_CONTENT)
    popupWindow.isOutsideTouchable = false //点击弹窗外部是否取消弹窗

    //弹窗出现外部为阴影
    val attributes: WindowManager.LayoutParams = requireActivity().window.getAttributes()
    attributes.alpha = 0.5f
    requireActivity().window.setAttributes(attributes)
    //弹窗取消监听 取消之后恢复阴影
    popupWindow.setOnDismissListener {
        val attributes: WindowManager.LayoutParams = requireActivity().window.getAttributes()
        attributes.alpha = 1f
        requireActivity().window.setAttributes(attributes)
        getFocus(false)
    }
    popupWindow.showAtLocation(vip_recyclerview, Gravity.CENTER, 0, 0)

    var accountTextView = view.findViewById<TextView>(R.id.vip_confirm_account)
    var nameTextView = view.findViewById<TextView>(R.id.vip_confirm_name)
    var monthTextView = view.findViewById<TextView>(R.id.vip_confirm_month)
    accountTextView.text = BaseUtils.getString(R.string.wc_vip_manager_user_account, vipBean.userAccount)
    nameTextView.text = BaseUtils.getString(R.string.wc_vip_manager_user_name, vipBean.userName)
    monthTextView.text = BaseUtils.getString(R.string.wc_vip_confirm_month, "${month}")
    view.findViewById<TextView>(R.id.vip_confirm_cancel).setOnClickListener {
        popupWindow.dismiss()
    }

    view.findViewById<TextView>(R.id.vip_confirm_ok).setOnClickListener {
        popupWindow.dismiss()
        vipManagerViewModel.updateVip(vipBean.userAccount, vipBean.operatorAccount, month)
    }
}

/**
 * vip会员续费
 */
fun updateVip(userAccount : String, operatorAccount : String, month : Int){
    if(TextUtils.isEmpty(userAccount)
        ||TextUtils.isEmpty(operatorAccount)
        || month < 1){
        isSuccessLiveData.postValue(false)
        return
    }
    CoroutineScope(Dispatchers.IO).launch {
        var result = VipManagerRepository.updateVip(userAccount, operatorAccount, month)
        isSuccessLiveData.postValue(result.isSuccess)
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王宁-Android

你的鼓励是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值