• 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))
        }
    
    
    }

  • 相关阅读:
    深入了解 Docker 容器操作命令:掌握容器化管理的关键
    每日三题 8.24
    基于HTML(甜品奶茶店)餐饮美食项目的设计与实现(html前端源码和论文设计)
    计算机毕业设计Javavue学习视频课程网站(源码+系统+mysql数据库+lw文档)
    基于Java的二手手机回收平台系统
    vue ant 两个页面 调用同一个接口 想在 前端的一个 接口传 一个固定的值 ,另外一个不变 ,查询条件默认值加上自己要的就好啦
    【EasyRL学习笔记】第十二章 Deep Deterministic Policy Gradient 深度确定性策略梯度(DDPG)算法
    ESP8266-Arduino编程实例-SPIFFS及数据上传(Arduino IDE和PlatformIO IDE)
    Hadoop3 - MapReduce ORC 列式存储
    Flink+ice 实现可视化规则编排与灵活配置(Demo)
  • 原文地址:https://blog.csdn.net/maoning20080808/article/details/128132480