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

Commit 7df68ed

Browse files
Merge pull request #1813 from openedx/farhan_ar/LEARNER-9527
fix: App Crashing on background for IAP users
2 parents a44aa61 + 32754c8 commit 7df68ed

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.edx.mobile.extenstion
2+
3+
import kotlinx.coroutines.CancellableContinuation
4+
import kotlin.coroutines.resume
5+
6+
fun CancellableContinuation<Boolean>.resumeIfActive(value: Boolean) {
7+
if (isActive && isCompleted.not()) {
8+
resume(value)
9+
}
10+
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import dagger.hilt.android.qualifiers.ApplicationContext
2424
import kotlinx.coroutines.CoroutineScope
2525
import kotlinx.coroutines.Dispatchers
2626
import kotlinx.coroutines.launch
27+
import kotlinx.coroutines.suspendCancellableCoroutine
2728
import kotlinx.coroutines.withContext
2829
import org.edx.mobile.extenstion.encodeToString
30+
import org.edx.mobile.extenstion.resumeIfActive
2931
import org.edx.mobile.logger.Logger
3032
import javax.inject.Inject
3133
import javax.inject.Singleton
32-
import kotlin.coroutines.resume
33-
import kotlin.coroutines.suspendCoroutine
3434

3535
/**
3636
* The BillingProcessor implements all billing functionality for application.
@@ -69,14 +69,14 @@ class BillingProcessor @Inject constructor(
6969
}
7070

7171
private suspend fun connect(): Boolean {
72-
return suspendCoroutine { continuation ->
72+
return suspendCancellableCoroutine { continuation ->
7373
billingClientStateListener = object : BillingClientStateListener {
7474
override fun onBillingSetupFinished(billingResult: BillingResult) {
7575
logger.debug("BillingSetupFinished -> $billingResult")
7676
if (billingResult.responseCode == BillingResponseCode.OK) {
77-
continuation.resume(true)
77+
continuation.resumeIfActive(true)
7878
} else {
79-
continuation.resume(false)
79+
continuation.resumeIfActive(false)
8080
}
8181
}
8282

@@ -89,7 +89,7 @@ class BillingProcessor @Inject constructor(
8989
connectionTryCount++
9090
retryBillingServiceConnectionWithExponentialBackoff()
9191
}
92-
continuation.resume(false)
92+
continuation.resumeIfActive(false)
9393
}
9494
}
9595
billingClient.startConnection(billingClientStateListener)

OpenEdXMobile/src/main/java/org/edx/mobile/view/CourseUnitNavigationActivity.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ public void onConfigurationChanged(@NonNull Configuration newConfig) {
469469
}
470470

471471
private void updateUIForOrientation() {
472-
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE && selectedUnit.isVideoBlock()) {
472+
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE &&
473+
selectedUnit != null && selectedUnit.isVideoBlock()) {
473474
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
474475
setActionBarVisible(false);
475476
findViewById(R.id.course_unit_nav_bar).setVisibility(View.GONE);

0 commit comments

Comments
 (0)