This commit is contained in:
Aman S
2023-10-03 13:57:17 +05:30
committed by GitHub
parent ae3ce95a8b
commit 4e3f6c6143
2 changed files with 41 additions and 17 deletions

View File

@@ -18,6 +18,7 @@ import java.io.ByteArrayOutputStream
import java.io.File
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
@@ -25,6 +26,7 @@ import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.toRequestBody
import kotlin.coroutines.cancellation.CancellationException
object CommonUtils {
fun getUserLocation(): UserLocation? {
@@ -98,4 +100,12 @@ object CommonUtils {
fun getSSLKeyFromPreference(): String? {
return PreferenceManager.getSecureString(CommonPrefConstants.PREFERENCE_SSL_KEY)
}
fun Job.handleCancellation() {
invokeOnCompletion { cause ->
if (cause is CancellationException) {
cause.log()
}
}
}
}

View File

@@ -36,6 +36,7 @@ import com.navi.common.model.ModuleNameV2
import com.navi.common.network.models.GenericErrorResponse
import com.navi.common.ui.activity.BaseActivity
import com.navi.common.ui.fragment.BaseFragment
import com.navi.common.utils.CommonUtils.handleCancellation
import com.navi.common.utils.Constants.EMPTY_ERROR_CODE_BY_3rd_PARTY
import com.navi.common.utils.Constants.EMPTY_REASON_BY_3rd_PARTY
import com.navi.common.utils.log
@@ -101,6 +102,7 @@ import `in`.digio.sdk.gateway.event.model.GatewayEvent
import `in`.digio.sdk.kyc.workflow.WorkflowResponseListener
import `in`.digio.sdk.kyc.workflow.model.WorkflowResponse
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.json.JSONObject
@@ -353,22 +355,28 @@ class GetLoanV2Activity :
override fun changeHeaderBackgroundColor(color: Int) {}
private fun startAnimationGreenBackground() {
lifecycleScope.launch {
val job =lifecycleScope.launch {
delay(Constants.SUCCESS_ANIMATION_WHITE_BG_TIME)
binding.autopaySuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.green)
)
startAnimationWhiteBackground()
if (isActive) {
binding.autopaySuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.green)
)
startAnimationWhiteBackground()
}
}
job.handleCancellation()
}
private fun startAnimationWhiteBackground() {
lifecycleScope.launch {
val job = lifecycleScope.launch {
delay(Constants.SUCCESS_ANIMATION_GREEN_BG_TIME)
binding.autopaySuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.white)
)
if (isActive) {
binding.autopaySuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.white)
)
}
}
job.handleCancellation()
}
override fun showAutoPayAnimation() {
@@ -393,10 +401,13 @@ class GetLoanV2Activity :
}
private fun startSuccessAnimationEndListener(animationEnd: () -> Unit) {
lifecycleScope.launch {
delay(Constants.GREEN_SUCCESS_ANIMATION_TIME)
animationEnd.invoke()
val job = lifecycleScope.launch {
if (isActive) {
delay(Constants.GREEN_SUCCESS_ANIMATION_TIME)
animationEnd.invoke()
}
}
job.handleCancellation()
}
override fun onSelfiCaptureClick(data: SelfieSetting?) {
@@ -567,13 +578,16 @@ class GetLoanV2Activity :
}
private fun startKycAnimationGreenBackground() {
lifecycleScope.launch {
val job = lifecycleScope.launch {
delay(Constants.SUCCESS_ANIMATION_WHITE_BG_TIME)
binding.kycSuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.green)
)
startKycAnimationWhiteBackground()
if (isActive) {
binding.kycSuccessAnimationHolderFl.setBackgroundColor(
ContextCompat.getColor(this@GetLoanV2Activity, appR.color.green)
)
startKycAnimationWhiteBackground()
}
}
job.handleCancellation()
}
private fun startKycAnimationWhiteBackground() {