• Kotlin高仿微信-第35篇-支付-二维码收款(二维码)


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

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

    效果图:

    实现代码:

    
    
    
        
    
            
    
            
    
                
    
                
    
                
    
                    
    
                    
    
                    
                
    
                
    
                
    
                
    
                
    
                
    
                
    
            
    
        
            
            
            
        
    
    
        
    

    /**
     * Author : wangning
     * Email : maoning20080809@163.com
     * Date : 2022/5/22 16:12
     * Description : 二维码收款
     */
    class QRCodeReceiveFragment : BaseDataBindingFragment() {
    
        private var resultBalance : Float = 0f
    
        override fun getLayoutRes()  = R.layout.wc_qrcode_receive
    
        private var navController : NavController? = null
    
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
    
            super.builder()
                .setTitleContent(R.string.wc_base_top_qrcode_payment)
                .setTitleColor(R.color.white)
                .setBack(R.drawable.wc_white_back)
    
    
            UIStatusUtils.setStatusBarColor(requireActivity(), BaseUtils.getColor(R.color.color_FFD700))
    
            navController = findNavController()
            //设置金额页面点击返回接收的值
            navController?.currentBackStackEntry?.savedStateHandle?.getLiveData(CommonUtils.QRCommon.BALANCE)?.observe(viewLifecycleOwner){
                TagUtils.d("接收返回金额:${it}")
                resultBalance = it
                if(resultBalance > 0){
                    qrcode_receive_balance.visibility = View.VISIBLE
                    refresh()
                }
            }
    
            qrcode_receive_set_amount.setOnClickListener {
                navController?.navigate(R.id.action_qrcode_set_amount)
            }
            refresh()
            if(!EventBus.getDefault().isRegistered(this)){
                EventBus.getDefault().register(this)
            }
        }
    
        @Subscribe(threadMode = ThreadMode.MAIN)
        fun onMessageCallback(paymentBean: PaymentBean) {
            TagUtils.d("二维码扫描接收的值:${paymentBean.balance} , ${paymentBean.fromAccount} , ${paymentBean.toAccount}")
            qrcode_receive_from_layout.visibility = View.VISIBLE
            qrcode_receive_from_divide.visibility = View.VISIBLE
            if(paymentBean == null){
                qrcode_receive_from_balance.text = "支付失败!"
            } else if(paymentBean.operator == CommonUtils.User.OPERATOR_PLUS){
                qrcode_receive_from_balance.text = paymentBean.balance.toString()
                BaseUtils.showAvatar(paymentBean.fromAccount, qrcode_receive_from_avatar,qrcode_receive_from_name)
                processMask(paymentBean.fromAccount, paymentBean.balance)
                //暂停使用语言播放
                /*CoroutineScope(Dispatchers.Main).launch {
                    delay(2000)
                    AudioUtils().processStart(paymentBean.balance.toInt())
                }*/
            }
    
        }
    
        //刷新页面
        private fun refresh(){
            qrcode_receive_balance.text = resultBalance.toString()
            var qrBalance = 0f
            //如果不输入金额, 默认传递0
            if(resultBalance >  0){
                qrBalance = resultBalance
            }
            CoroutineScope(Dispatchers.IO).launch {
                var account = DataStoreUtils.getAccount()
                var userBean =  UserRepository.getUserByAccount(account)
                var filePath = CommonUtils.Base.getReallyImage(userBean.avatar)
                var content = CommonUtils.QRCommon.QR_RECEIVE_CODE + qrBalance + ":" + account
                CoroutineScope(Dispatchers.Main).launch {
                    //在二维码中显示头像
                    GlideUtils.loadQRCode(qrcode_receive_qrcode, content, filePath)
                }
            }
        }
    
        //收款成功后,显示动画
        private fun processMask(account : String, balace: Float){
            qrcode_receive_mask_layout.visibility = View.VISIBLE
            qrcode_receive_mask_balance.text = CommonUtils.Base.getFormatBalanceUnit(balace)
            BaseUtils.showAvatar(account, qrcode_receive_mask_icon, qrcode_receive_mask_name)
            CoroutineScope(Dispatchers.Main).launch {
                delay(1000)
                val animationSet = AnimationSet(true)
                animationSet.setAnimationListener(object : Animation.AnimationListener{
                    override fun onAnimationEnd(p0: Animation?) {
                        qrcode_receive_mask_layout.visibility = View.GONE
                    }
    
                    override fun onAnimationRepeat(p0: Animation?) {
    
                    }
    
                    override fun onAnimationStart(p0: Animation?) {
    
                    }
                })
                var scaleAnimation = ScaleAnimation(1f,0.0f,1f,0.0f,
                    Animation.RELATIVE_TO_SELF,1f,
                    Animation.RELATIVE_TO_SELF,1f)
                scaleAnimation.duration = 1500
                animationSet.addAnimation(scaleAnimation)
                qrcode_receive_mask_layout.startAnimation(animationSet)
            }
        }
    
    
        override fun onDestroy() {
            super.onDestroy()
            EventBus.getDefault().unregister(this)
            UIStatusUtils.setStatusBarColor(requireActivity(), BaseUtils.getColor(R.color.color_48d17a))
        }
    
    
    }

  • 相关阅读:
    Python基础知识从hello world 开始(第四天完结)
    在Mac上一键安装Mysql(解决所有安装问题)
    亚马逊账户评级多久更新一次,亚马逊账户评级一般多少分-站斧浏览器
    二叉树--递归和回溯
    Asp-Net-Core开发笔记:使用RateLimit中间件实现接口限流
    CV&NLP基础12之自然语言处理引入
    rust学习(第一章)
    设计师值得收藏的5个设计网站
    k8s面试题大全(持续更新中)
    IP包头分析
  • 原文地址:https://blog.csdn.net/maoning20080808/article/details/128132480