Explorar o código

1.优化消息内容弹窗UI

王鹏鹏 %!s(int64=2) %!d(string=hai) anos
pai
achega
661e8f935f

+ 40 - 15
workbenches/src/main/java/com/yingyang/workbenches/dialog/PurchaseServicesDialog.kt

@@ -1,6 +1,7 @@
 package com.yingyang.workbenches.dialog
 
 import android.annotation.SuppressLint
+import android.content.Context
 import android.graphics.Color
 import android.os.Bundle
 import android.text.SpannableString
@@ -32,6 +33,8 @@ import com.yingyangfly.baselib.net.BaseObserver
 import com.yingyangfly.baselib.net.MyRxScheduler
 import com.yingyangfly.baselib.net.XUtils
 import com.yingyangfly.baselib.utils.GsonUtil
+import com.yingyangfly.baselib.utils.LiveEventBusUtil
+import com.yingyangfly.baselib.utils.RxBusCodes
 import com.yingyangfly.baselib.utils.RxTimer
 import com.yingyangfly.baselib.utils.ViewTool
 import io.reactivex.schedulers.Schedulers
@@ -58,6 +61,7 @@ class PurchaseServicesDialog : DialogFragment() {
     private var paySuccessBtn: Button? = null
     private var purchaseServicesLayout: ConstraintLayout? = null
     private var purchaseServicesBtn: AppCompatButton? = null
+    private var mContext: Context? = null
 
     fun setPackageBean(
         packageId: String, payMoney: String, packageName: String, packageType: String
@@ -92,6 +96,7 @@ class PurchaseServicesDialog : DialogFragment() {
         val rootView = ViewTool.inflateFragmentPixels(
             activity, R.layout.dialog_purchase_services, container, 1194, 834
         )
+        mContext = activity
         findId(rootView)
         init()
         return rootView
@@ -121,36 +126,45 @@ class PurchaseServicesDialog : DialogFragment() {
         tvPackageMoney?.text = spannableString
         //微信支付
         weChatLayout?.setOnSingleClickListener {
-            getPayImage(
-                GetPayImageBean(
-                    packageId, "1", payMoney, packageName, packageType, "B"
+            if (mContext != null) {
+                getPayImage(
+                    GetPayImageBean(
+                        packageId, "1", payMoney, packageName, packageType, "B"
+                    )
                 )
-            )
+            }
         }
         //支付宝支付
         alipayLayout?.setOnSingleClickListener {
-            getPayImage(
-                GetPayImageBean(
-                    packageId, "2", payMoney, packageName, packageType, "B"
+            if (mContext != null) {
+                getPayImage(
+                    GetPayImageBean(
+                        packageId, "2", payMoney, packageName, packageType, "B"
+                    )
                 )
-            )
+            }
         }
         //查询支付状态
         paySuccessBtn?.setOnSingleClickListener {
-            queryPaymentStatus()
+            if (mContext != null) {
+                queryPaymentStatus()
+            }
         }
         val imageClose = rootView.findViewById<AppCompatImageView>(R.id.imageClose)
         imageClose.setOnSingleClickListener {
             if (orderNo.isNullOrEmpty()) {
                 dismiss()
             } else {
-                delPayOrder()
+                if (mContext != null) {
+                    delPayOrder()
+                }
             }
         }
     }
 
     private fun init() {
         rxTimer = RxTimer()
+        successfulPurchase()
     }
 
     /**
@@ -165,7 +179,9 @@ class PurchaseServicesDialog : DialogFragment() {
             if (it == time - 1) {
                 rxTimer.cancel()
                 tvCountdown?.show(false)
-                delPayOrder()
+                if (mContext != null) {
+                    delPayOrder()
+                }
             } else {
                 tvCountdown?.show(true)
                 tvCountdown?.text = if (minutes > 0) {
@@ -187,7 +203,7 @@ class PurchaseServicesDialog : DialogFragment() {
     private fun getPayImage(bean: GetPayImageBean) {
         val body = XUtils.createJson(GsonUtil.GsonString(bean))
         WorkbenchesServiceFactory.getService().getPayImage(body).subscribeOn(Schedulers.io())
-            .compose(MyRxScheduler.ioMain(activity, true))
+            .compose(MyRxScheduler.ioMain(mContext!!, true))
             .subscribe(object : BaseObserver<PayImageBean>() {
                 override fun onSuccess(t: PayImageBean?) {
                     t?.let {
@@ -212,7 +228,7 @@ class PurchaseServicesDialog : DialogFragment() {
                             payImage?.show(false)
                             payImage?.show(true)
                             paySuccessBtn?.show(true)
-                            Glide.with(activity!!).load(bitmap).into(payImage!!)
+                            Glide.with(context!!).load(bitmap).into(payImage!!)
                         }
                     }
                 }
@@ -228,7 +244,7 @@ class PurchaseServicesDialog : DialogFragment() {
      */
     private fun delPayOrder() {
         WorkbenchesServiceFactory.getService().delPayOrder(orderNo).subscribeOn(Schedulers.io())
-            .compose(MyRxScheduler.ioMain(activity, true))
+            .compose(MyRxScheduler.ioMain(mContext!!, true))
             .subscribe(object : BaseObserver<String>() {
                 override fun onSuccess(t: String?) {
                     dismiss()
@@ -245,7 +261,7 @@ class PurchaseServicesDialog : DialogFragment() {
      */
     private fun queryPaymentStatus() {
         WorkbenchesServiceFactory.getService().getSelectPayResult(orderNo)
-            .subscribeOn(Schedulers.io()).compose(MyRxScheduler.ioMain(activity, true))
+            .subscribeOn(Schedulers.io()).compose(MyRxScheduler.ioMain(mContext!!, true))
             .subscribe(object : BaseObserver<String>() {
                 override fun onSuccess(t: String?) {
                     if (t.isNullOrEmpty().not()) {
@@ -281,4 +297,13 @@ class PurchaseServicesDialog : DialogFragment() {
                 }
             })
     }
+
+    /**
+     * 服务购买成功
+     */
+    private fun successfulPurchase() {
+        LiveEventBusUtil.observer<String>(this, RxBusCodes.SuccessfulPurchase) {
+            dismiss()
+        }
+    }
 }