Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1813 from openedx/farhan_ar/LEARNER-9527
Browse files Browse the repository at this point in the history
fix: App Crashing on background for IAP users
  • Loading branch information
farhan-arshad-dev authored Aug 15, 2023
2 parents a44aa61 + 32754c8 commit 7df68ed
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.edx.mobile.extenstion

import kotlinx.coroutines.CancellableContinuation
import kotlin.coroutines.resume

fun CancellableContinuation<Boolean>.resumeIfActive(value: Boolean) {
if (isActive && isCompleted.not()) {
resume(value)

Check warning on line 8 in OpenEdXMobile/src/main/java/org/edx/mobile/extenstion/ContinuationExt.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/extenstion/ContinuationExt.kt#L8

Added line #L8 was not covered by tests
}
}

Check warning on line 10 in OpenEdXMobile/src/main/java/org/edx/mobile/extenstion/ContinuationExt.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/extenstion/ContinuationExt.kt#L10

Added line #L10 was not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
import org.edx.mobile.extenstion.encodeToString
import org.edx.mobile.extenstion.resumeIfActive
import org.edx.mobile.logger.Logger
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

/**
* The BillingProcessor implements all billing functionality for application.
Expand Down Expand Up @@ -69,14 +69,14 @@ class BillingProcessor @Inject constructor(
}

private suspend fun connect(): Boolean {
return suspendCoroutine { continuation ->
return suspendCancellableCoroutine { continuation ->

Check warning on line 72 in OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt#L72

Added line #L72 was not covered by tests
billingClientStateListener = object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
logger.debug("BillingSetupFinished -> $billingResult")
if (billingResult.responseCode == BillingResponseCode.OK) {
continuation.resume(true)
continuation.resumeIfActive(true)

Check warning on line 77 in OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt#L77

Added line #L77 was not covered by tests
} else {
continuation.resume(false)
continuation.resumeIfActive(false)

Check warning on line 79 in OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt#L79

Added line #L79 was not covered by tests
}
}

Expand All @@ -89,7 +89,7 @@ class BillingProcessor @Inject constructor(
connectionTryCount++
retryBillingServiceConnectionWithExponentialBackoff()
}
continuation.resume(false)
continuation.resumeIfActive(false)

Check warning on line 92 in OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt

View check run for this annotation

Codecov / codecov/patch

OpenEdXMobile/src/main/java/org/edx/mobile/inapppurchases/BillingProcessor.kt#L92

Added line #L92 was not covered by tests
}
}
billingClient.startConnection(billingClientStateListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
}

private void updateUIForOrientation() {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && selectedUnit.isVideoBlock()) {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE &&
selectedUnit != null && selectedUnit.isVideoBlock()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setActionBarVisible(false);
findViewById(R.id.course_unit_nav_bar).setVisibility(View.GONE);
Expand Down

0 comments on commit 7df68ed

Please sign in to comment.