JusPay making HyperPaymentsCallback to null.
This commit is contained in:
@@ -8,18 +8,15 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.navi.common.extensions.isNull
|
||||
import org.json.JSONObject
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
|
||||
object HyperServicesHolder : HyperPaymentsCallback {
|
||||
|
||||
|
||||
const val EVENT_INITIATE_RESULT = "initiate_result"
|
||||
const val EVENT = "event"
|
||||
|
||||
private var hyperServices: WeakReference<HyperServices>? = null
|
||||
lateinit var hyperServiceCallback: HyperPaymentsCallback
|
||||
private var hyperServiceCallback: HyperPaymentsCallback? = null
|
||||
|
||||
enum class EventsType {
|
||||
onEvent, onStartWaitingDialogCreated, getMerchantView
|
||||
@@ -27,8 +24,6 @@ object HyperServicesHolder : HyperPaymentsCallback {
|
||||
|
||||
private val eventQueue: Queue<QueuedEvents> = LinkedList()
|
||||
|
||||
var isInitiated = false
|
||||
|
||||
fun initiateSDK(activity: FragmentActivity, initiatePayload: JSONObject) {
|
||||
hyperServices = WeakReference<HyperServices>(HyperServices(activity))
|
||||
hyperServices?.get()?.initiate(activity, initiatePayload, this)
|
||||
@@ -53,41 +48,37 @@ object HyperServicesHolder : HyperPaymentsCallback {
|
||||
// queued events are fired later when call back is set during process call
|
||||
|
||||
override fun onEvent(event: JSONObject?, handler: JuspayResponseHandler?) {
|
||||
val eventName = if (event == null) "" else event.optString(EVENT, "")
|
||||
if (eventName == EVENT_INITIATE_RESULT)
|
||||
isInitiated = true
|
||||
|
||||
if (!this::hyperServiceCallback.isInitialized) {
|
||||
if (hyperServiceCallback.isNull()) {
|
||||
val qEvent = QueuedEvents()
|
||||
qEvent.eventType = EventsType.onEvent
|
||||
qEvent.event = event
|
||||
qEvent.handler = handler
|
||||
eventQueue.add(qEvent)
|
||||
} else {
|
||||
hyperServiceCallback.onEvent(event, handler)
|
||||
hyperServiceCallback?.onEvent(event, handler)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartWaitingDialogCreated(parent: View?) {
|
||||
if (!this::hyperServiceCallback.isInitialized) {
|
||||
if (hyperServiceCallback.isNull()) {
|
||||
val qEvent = QueuedEvents()
|
||||
qEvent.eventType = EventsType.onStartWaitingDialogCreated
|
||||
qEvent.parent = parent
|
||||
eventQueue.add(qEvent)
|
||||
} else {
|
||||
hyperServiceCallback.onStartWaitingDialogCreated(parent);
|
||||
hyperServiceCallback?.onStartWaitingDialogCreated(parent);
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMerchantView(parent: ViewGroup?, viewType: MerchantViewType): View? {
|
||||
if (!this::hyperServiceCallback.isInitialized) {
|
||||
if (hyperServiceCallback.isNull()) {
|
||||
val qEvent = QueuedEvents()
|
||||
qEvent.eventType = EventsType.getMerchantView
|
||||
qEvent.viewGroup = parent
|
||||
qEvent.mViewType = viewType
|
||||
eventQueue.add(qEvent)
|
||||
} else {
|
||||
hyperServiceCallback.getMerchantView(parent, viewType)
|
||||
hyperServiceCallback?.getMerchantView(parent, viewType)
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -101,16 +92,13 @@ object HyperServicesHolder : HyperPaymentsCallback {
|
||||
if (head != null) {
|
||||
when (head.eventType) {
|
||||
EventsType.onEvent ->
|
||||
if (this::hyperServiceCallback.isInitialized)
|
||||
hyperServiceCallback.onEvent(head.event, head.handler)
|
||||
hyperServiceCallback?.onEvent(head.event, head.handler)
|
||||
|
||||
EventsType.onStartWaitingDialogCreated ->
|
||||
if (this::hyperServiceCallback.isInitialized)
|
||||
hyperServiceCallback.onStartWaitingDialogCreated(head.parent)
|
||||
hyperServiceCallback?.onStartWaitingDialogCreated(head.parent)
|
||||
|
||||
EventsType.getMerchantView ->
|
||||
if (this::hyperServiceCallback.isInitialized)
|
||||
hyperServiceCallback.getMerchantView(head.viewGroup, head.mViewType)
|
||||
hyperServiceCallback?.getMerchantView(head.viewGroup, head.mViewType)
|
||||
|
||||
else -> {
|
||||
}
|
||||
@@ -129,6 +117,10 @@ object HyperServicesHolder : HyperPaymentsCallback {
|
||||
return true
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
hyperServiceCallback = null
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class QueuedEvents {
|
||||
|
||||
@@ -956,4 +956,9 @@ class PaymentActivity : BaseActivity(), PaymentResultWithDataListener, PaymentLi
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
HyperServicesHolder.clear()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user