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

news2024/9/26 15:26:20

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

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

效果图:

实现代码:

<?xml version="1.0" encoding="utf-8"?>
<layout>

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/color_FFD700">

        <include layout="@layout/wc_base_top_title" />

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/qrcode_receive_layout"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:layout_marginHorizontal="12dp"
            android:layout_marginVertical="20dp"
            android:background="#FFFFFF"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/base_top_root_layout">

            <ImageView
                android:id="@+id/qrcode_receive_qrcode"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_marginTop="12dp"
                android:src="@drawable/ic_launcher"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_balance" />

            <LinearLayout
                android:id="@+id/qrcode_receive_from_divide"
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:layout_marginHorizontal="12dp"
                android:layout_marginTop="8dp"
                android:background="@color/gray"
                android:orientation="horizontal"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_set_amount" />

            <LinearLayout
                android:id="@+id/qrcode_receive_from_layout"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginHorizontal="12dp"
                android:layout_marginTop="12dp"
                android:orientation="horizontal"
                android:visibility="gone"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_set_amount">

                <androidx.appcompat.widget.AppCompatImageView
                    android:id="@+id/qrcode_receive_from_avatar"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/ic_launcher" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/qrcode_receive_from_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="12dp"
                    android:text="名称"
                    android:textColor="@color/black" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/qrcode_receive_from_balance"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|right"
                    android:layout_marginRight="12dp"
                    android:gravity="right"
                    android:text="金额"
                    android:textColor="@color/gray" />
            </LinearLayout>

            <TextView
                android:id="@+id/qrcode_receive_tip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="二维码收款"
                android:textColor="#FFD700"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintBottom_toBottomOf="@+id/qrcode_receive_icon"
                app:layout_constraintStart_toEndOf="@+id/qrcode_receive_icon"
                app:layout_constraintTop_toTopOf="@+id/qrcode_receive_icon" />

            <TextView
                android:id="@+id/qrcode_receive_add_friend_tip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:text="无需加好友,扫收款码向我付钱"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_icon" />

            <TextView
                android:id="@+id/qrcode_receive_balance"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:text="¥0.00"
                android:textColor="@color/black"
                android:textSize="24sp"
                android:textStyle="bold"
                android:visibility="gone"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_add_friend_tip" />

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/qrcode_receive_icon"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="12dp"
                android:src="@drawable/wc_qrcode_receive_icon"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="@+id/qrcode_receive_layout" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/qrcode_receive_set_amount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="设置金额"
                android:textColor="@color/black"
                android:textSize="14sp"
                app:layout_constraintStart_toStartOf="@+id/qrcode_receive_qrcode"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_qrcode" />

            <androidx.appcompat.widget.AppCompatTextView
                android:id="@+id/qrcode_receive_save_qrcode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="保存收款码"
                android:textColor="@color/black"
                android:textSize="14sp"
                app:layout_constraintEnd_toEndOf="@+id/qrcode_receive_qrcode"
                app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_qrcode" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/qrcode_receive_mask_layout"
        android:layout_width="match_parent"
        android:layout_height="360dp"
        android:layout_marginHorizontal="12dp"
        android:layout_marginVertical="20dp"
        android:background="#FFFFFF"
        android:visibility="gone"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/base_top_root_layout">
        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/qrcode_receive_mask_icon"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="80dp"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:src="@drawable/ic_launcher"/>
        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/qrcode_receive_mask_name"
            app:layout_constraintStart_toStartOf="@+id/qrcode_receive_mask_icon"
            app:layout_constraintEnd_toEndOf="@+id/qrcode_receive_mask_icon"
            app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_mask_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="名称"
            android:textSize="20sp"
            android:textColor="@color/black"/>
        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/qrcode_receive_mask_balance"
            app:layout_constraintStart_toStartOf="@+id/qrcode_receive_mask_icon"
            app:layout_constraintEnd_toEndOf="@+id/qrcode_receive_mask_icon"
            app:layout_constraintTop_toBottomOf="@+id/qrcode_receive_mask_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:text="¥0.00"
            android:textSize="30sp"
            android:textColor="@color/black"/>
    </androidx.constraintlayout.widget.ConstraintLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

/**
 * Author : wangning
 * Email : maoning20080809@163.com
 * Date : 2022/5/22 16:12
 * Description : 二维码收款
 */
class QRCodeReceiveFragment : BaseDataBindingFragment<WcQrcodeReceiveBinding>() {

    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<Float>(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))
    }


}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/56299.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【python可视化】python编码规范、标准库与扩展库对象的导入与使用

&#x1f64b;‍ 哈喽大家好&#xff0c;本次是python数据分析、挖掘与可视化专栏第一期 ⭐本期内容&#xff1a;python编码规范、标准库与扩展库对象的导入与使用 &#x1f3c6;系列专栏&#xff1a;Python数据分析、挖掘与可视化 &#x1f44d;欢迎大佬指正&#xff0c;一起学…

嵌入式分享合集115

一、数字万用表电压、电流、电阻、电容、频率、电池、二极管等测量方法 数字万用表可用来测量直流和交流电压、直流和交流电流、电阻、电容、频率、电池、二极管等等。整机电路设计以大规模集成电路双积分A/D转换器为核心&#xff0c;并配以全过程过载保护电路&#xff0c;使之…

动态改变列数做分页

【问题】 My question is: How can I prepare template which will receive various number of columns in such way, that if they won’t fit to page, next columns would be printed on a second page. For example If I have 10 columns, but only 6 fit to the page 1,…

[附源码]计算机毕业设计springboot万佳商城管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

33K Star?这才是程序员需要的神器。。。

程序员宝藏库&#xff1a;https://gitee.com/sharetech_lee/CS-Books-Store 你想要的&#xff0c;这里都有&#xff01; 作为程序员用的比较多的工具是什么&#xff1f; 我觉得搜索引擎绝对能名列前茅。 在开发过程中&#xff0c;总会遇到这样或者那样的问题超出我们自身的知…

【愚公系列】华为云系列之ModelArts+AppCube带你识别101种西式美食【我的低代码AI体验】

文章目录前言1.ModelArts是什么2.AppCube是什么一、华为云系列之ModelArtsAppCube带你识别101种西式美食1. AI Gallery 订阅模型及部署2. 获取访问秘钥3. 使用示例安装包创建 AppCube 应用4. 创建 ModelArts 连接器前言 1.ModelArts是什么 ModelArts是面向AI开发者的一站式开…

[附源码]Python计算机毕业设计SSM考勤系统设计(程序+LW)

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

Java项目:ssm教材征订与发放管理系统

作者主页&#xff1a;源码空间站2022 简介&#xff1a;Java领域优质创作者、Java项目、学习资料、技术互助 文末获取源码 项目介绍 教材征订与发放管理系统。本系统共分三种角色&#xff0c;分别为管理员、老师、班长&#xff1b;现在分别来介绍各个角色的功能&#xff1a; …

java计算机毕业设计ssm魔术教学网站k304y(附源码、数据库)

java计算机毕业设计ssm魔术教学网站k304y&#xff08;附源码、数据库&#xff09; 项目运行 环境配置&#xff1a; Jdk1.8 Tomcat8.5 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。…

Springboot旅游网站管理系统毕业设计、Springboot旅游线路和景点网站设计与实现 毕设作品参考

功能清单 【后台功能】 系统设置&#xff1a;设置关于我们、联系我们、加入我们、法律声明 广告管理&#xff1a;设置小程序首页轮播图广告和链接 留言列表&#xff1a;所有用户留言信息列表&#xff0c;支持删除 会员列表&#xff1a;查看所有注册会员信息&#xff0c;支持删…

QT登录界面设计及跳转主界面

文章目录QT登录界面设计及跳转主界面界面样式创建流程界面设计所需控件界面外观设计添加底色设置密码输入框以密文显示&#xff1a;程序设计取消按钮登录按钮注&#xff1a;QT登录界面设计及跳转主界面 界面样式 先贴图 创建流程 首先创建界面&#xff1a; 选择无按钮界面…

[附源码]计算机毕业设计springboot校园便携系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

【第 8 章 MySQL InnoDB ClusterSet 】

【第 8 章 MySQL InnoDB ClusterSet 】 文章目录【第 8 章 MySQL InnoDB ClusterSet 】本章内容本章简介本章内容 8.1 InnoDB ClusterSet 要求 8.2 InnoDB ClusterSet 限制 8.3 User Accounts for InnoDB ClusterSet 8.4 Deploying InnoDB ClusterSet 8.5 Integrating MySQL R…

VS系列多通道无线采发仪

VS101/104/208/416/432 是以振弦、温度传感信号为主的多通道无线采发仪&#xff0c;并可扩展其它模拟&#xff08;电流、 电压、电阻&#xff09;信号和数字信号&#xff08;RS485、RS232&#xff09;传感器通道&#xff0c;内置电池&#xff0c;可外接太阳能电池板。最多可实…

QT学习日记28——QT动态库制作和使用

学习视频链接 课时3 控件介绍,使用和样式修改_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV14t411b7EL/?p3&spm_id_from333.337.top_right_bar_window_history.content.click&vd_source0471cde1c644648fafd07b54e303c905 目录 一、动态库项目 1.1 新建工程…

[附源码]Python计算机毕业设计Django家庭医生签约服务管理系统

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;…

车载测试好就业?车载测试就业薪资和前景怎么样?

什么是车载智能系统测试&#xff1f; 车载测试&#xff0c;又叫车载智能系统测试&#xff0c;是汽车智能化重要的组成部分&#xff0c;由旧有的车载资通讯系统结合联网汽车技术所演进而来&#xff0c;随着软硬件技术的不断进步&#xff0c; 让车载智能系统拥有强大的运算能力及…

时序数据库-6-[IoTDB]的数据模式

1 数据模型 我们以风电场物联网场景为例&#xff0c;说明如何在IoTDB中创建一个正确的数据模型。 根据企业组织结构和设备实体层次结构&#xff0c;我们将其物联网数据模型表示为如下图所示的属性层级组织结构&#xff0c;即电力集团层-风电场层-实体层-物理量层。 其中ROOT…

[附源码]计算机毕业设计JAVA校园期刊网络投稿系统

[附源码]计算机毕业设计JAVA校园期刊网络投稿系统 项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM my…

设计模式-桥接模式

桥接模式( Bridge Pattern &#xff09;也称为桥梁模式、接口(Interfce)模式或柄体&#xff08; Handle and Body)模 式&#xff0c;是将抽象部分与它的具体实现部分分离&#xff0c;使它们都可以独立地变化&#xff0c;属于结构型模式。 原文&#xff1a;Decouple an abstract…