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_48d17a"> <include layout="@layout/wc_base_top_title"/> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/receive_payment_layout" android:layout_width="match_parent" android:layout_height="340dp" android:layout_marginVertical="20dp" android:layout_marginHorizontal="12dp" app:layout_constraintTop_toBottomOf="@+id/base_top_root_layout" app:layout_constraintStart_toStartOf="parent" android:background="#FFFFFF"> <androidx.appcompat.widget.AppCompatImageView android:id="@+id/receive_payment_icon" android:layout_width="26dp" android:layout_height="26dp" android:layout_marginTop="12dp" android:layout_marginLeft="10dp" app:layout_constraintTop_toTopOf="@+id/receive_payment_layout" app:layout_constraintStart_toStartOf="parent" android:src="@drawable/wc_receive_payment_icon"/> <TextView android:id="@+id/receive_payment_tip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" app:layout_constraintTop_toTopOf="@+id/receive_payment_icon" app:layout_constraintBottom_toBottomOf="@+id/receive_payment_icon" app:layout_constraintStart_toEndOf="@+id/receive_payment_icon" android:text="向商家付款" android:textSize="16sp" android:textStyle="bold" android:textColor="#48d17a"/> <ImageView android:id="@+id/receive_payment_qrcode_icon" app:layout_constraintTop_toTopOf="@+id/receive_payment_layout" app:layout_constraintBottom_toBottomOf="@+id/receive_payment_layout" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_marginTop="0dp" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/ic_launcher"/> <LinearLayout android:id="@+id/receive_payment_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/receive_payment_qrcode_icon" /> <LinearLayout android:id="@+id/receive_payment_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/receive_payment_qrcode_icon"> <androidx.appcompat.widget.AppCompatImageView android:id="@+id/receive_payment_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/receive_payment_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/receive_payment_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> </androidx.constraintlayout.widget.ConstraintLayout> <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/receive_payment_mask_layout" android:layout_width="match_parent" android:layout_height="340dp" 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/receive_payment_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/receive_payment_mask_name" app:layout_constraintStart_toStartOf="@+id/receive_payment_mask_icon" app:layout_constraintEnd_toEndOf="@+id/receive_payment_mask_icon" app:layout_constraintTop_toBottomOf="@+id/receive_payment_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/receive_payment_mask_balance" app:layout_constraintStart_toStartOf="@+id/receive_payment_mask_icon" app:layout_constraintEnd_toEndOf="@+id/receive_payment_mask_icon" app:layout_constraintTop_toBottomOf="@+id/receive_payment_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> <com.wn.wechatclientdemo.view.LineBaseSmallView android:id="@+id/receive_payment_qrcode" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/receive_payment_layout" android:layout_marginTop="20dp" android:layout_width="match_parent" android:layout_height="wrap_content" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout>
/** * Author : wangning * Email : maoning20080809@163.com * Date : 2022/5/20 21:08 * Description : 收付款 */ class ReceivePaymentFragment : BaseDataBindingFragment<WcReceivePaymentBinding>(){ override fun getLayoutRes() = R.layout.wc_receive_payment override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) super.builder() .setTitleContent(R.string.wc_base_top_receive_payment) .setTitleColor(R.color.white) .setBack(R.drawable.wc_white_back) UIStatusUtils.setStatusBarColor(requireActivity(), BaseUtils.getColor(R.color.color_48d17a)) //先判断是否已经注册 if(!EventBus.getDefault().isRegistered(this)){ EventBus.getDefault().register(this) } //二维码收款 receive_payment_qrcode.builder() .setLeftImage(R.drawable.wc_receive_payment_item_icon) .setTitle(BaseUtils.getString(R.string.wc_receive_payment_qrcode)) .hideContent() .hideDevideingView() .setTitleColor(R.color.white) .setTitleSize(18f) .setRootClick { Navigation.findNavController(it).navigate(R.id.action_qrcode_receive) } var account = DataStoreUtils.getAccount() var result = CommonUtils.QRCommon.QR_PAYMENT_CODE + account var bitmap = QRUtils.createQRCode(result, 300, 300,null); receive_payment_qrcode_icon.setImageBitmap(bitmap) } //向商家付款成功,显示动画 private fun processMask(account : String, balace: Float){ receive_payment_mask_layout.visibility = View.VISIBLE receive_payment_mask_balance.text = CommonUtils.Base.getFormatBalanceUnit(balace) BaseUtils.showAvatar(account, receive_payment_mask_icon, receive_payment_mask_name) CoroutineScope(Dispatchers.Main).launch { delay(1000) val animationSet = AnimationSet(true) animationSet.setAnimationListener(object : Animation.AnimationListener{ override fun onAnimationEnd(p0: Animation?) { receive_payment_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) receive_payment_mask_layout.startAnimation(animationSet) } } @Subscribe(threadMode = ThreadMode.MAIN) fun onMessageCallback(paymentBean: PaymentBean) { if(paymentBean == null){ receive_payment_from_balance.text = "支付失败!" } else if(paymentBean.operator == CommonUtils.User.OPERATOR_MINUS){ TagUtils.d("向商家付款:${paymentBean.balance} , ${paymentBean.fromAccount} , ${paymentBean.toAccount} , ${paymentBean.operator}") receive_payment_from_layout.visibility = View.VISIBLE receive_payment_from_divide.visibility = View.VISIBLE receive_payment_from_balance.text = paymentBean.balance.toString() BaseUtils.showAvatar(paymentBean.fromAccount, receive_payment_from_avatar,receive_payment_from_name) processMask(paymentBean.fromAccount, paymentBean.balance) } } override fun onDestroy() { super.onDestroy() EventBus.getDefault().unregister(this) UIStatusUtils.setStatusBarColor(requireActivity(), BaseUtils.getColor(R.color.wc_base_bg)) } }