Skip to content

Commit

Permalink
Merge pull request #57 from superwall-me/develop
Browse files Browse the repository at this point in the history
Release alpha 20
  • Loading branch information
anglinb authored Nov 10, 2023
2 parents eaca8f0 + 5f1d030 commit a6a2751
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

The changelog for `Superwall`. Also see the [releases](https://github.com/superwall-me/Superwall-Android/releases) on GitHub.

## 1.0.0-alpha.20

### Enhancements

### Fixes

- Fixes `app_open` race condition
- Prevents calling purchase twice
- Disables interactivity during purchase

## 1.0.0-alpha.19

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion superwall/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
id("maven-publish")
}

version = "1.0.0-alpha.19"
version = "1.0.0-alpha.20"

android {
compileSdk = 33
Expand Down
42 changes: 38 additions & 4 deletions superwall/src/main/java/com/superwall/sdk/Superwall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.net.Uri
import com.superwall.sdk.analytics.internal.track
import com.superwall.sdk.analytics.internal.trackable.InternalSuperwallEvent
import com.superwall.sdk.billing.BillingController
import com.superwall.sdk.config.models.getConfig
import com.superwall.sdk.config.options.SuperwallOptions
import com.superwall.sdk.delegate.SubscriptionStatus
import com.superwall.sdk.delegate.SuperwallDelegate
Expand All @@ -16,6 +17,7 @@ import com.superwall.sdk.delegate.subscription_controller.PurchaseController
import com.superwall.sdk.dependencies.DependencyContainer
import com.superwall.sdk.misc.ActivityProvider
import com.superwall.sdk.misc.SerialTaskManager
import com.superwall.sdk.models.config.Config
import com.superwall.sdk.paywall.presentation.PaywallCloseReason
import com.superwall.sdk.paywall.presentation.PresentationItems
import com.superwall.sdk.paywall.presentation.internal.dismiss
Expand All @@ -26,8 +28,13 @@ import com.superwall.sdk.paywall.vc.web_view.messaging.PaywallWebEvent
import com.superwall.sdk.paywall.vc.web_view.messaging.PaywallWebEvent.*
import com.superwall.sdk.store.ExternalNativePurchaseController
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.take
import java.util.*

class Superwall(
Expand Down Expand Up @@ -117,6 +124,15 @@ class Superwall(

companion object {
var initialized: Boolean = false

val _hasInitialized = MutableStateFlow<Boolean>(false)

// A flow that emits just once only when `hasInitialized` is non-`nil`.
val hasInitialized: Flow<Boolean> = _hasInitialized
.filter { it }
.take(1)


lateinit var instance: Superwall

/** Configures a shared instance of `Superwall` for use throughout your app.
Expand Down Expand Up @@ -152,6 +168,10 @@ class Superwall(
)
instance.setup()
initialized = true
// Ping everyone about the initialization
CoroutineScope(Dispatchers.Main).launch {
_hasInitialized.emit(true)
}
}
}

Expand Down Expand Up @@ -352,6 +372,9 @@ class Superwall(

//endregion

// Add a private variable for the purchase task
private var purchaseTask: Job? = null

override suspend fun eventDidOccur(
paywallEvent: PaywallWebEvent,
paywallViewController: PaywallViewController
Expand All @@ -373,10 +396,21 @@ class Superwall(
)
}
is InitiatePurchase -> {
dependencyContainer.transactionManager.purchase(
paywallEvent.productId,
paywallViewController
)
if (purchaseTask != null) {
// If a purchase is already in progress, do not start another
return@withContext
}
purchaseTask = launch {
try {
dependencyContainer.transactionManager.purchase(
paywallEvent.productId,
paywallViewController
)
} finally {
// Ensure the task is cleared once the purchase is complete or if an error occurs
purchaseTask = null
}
}
}
is InitiateRestore -> {
dependencyContainer.storeKitManager.purchaseController.tryToRestore(paywallViewController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import kotlinx.serialization.json.JsonObject
import java.util.*

suspend fun Superwall.track(event: Trackable): TrackingResult {
// Wait for the SDK to be fully initialized
Superwall.hasInitialized.first()


// Get parameters to be sent to the delegate and stored in an event.
// now with Date
val eventCreatedAt = Date()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ class LoadingViewController(context: Context) : FrameLayout(context) {

// Add the ProgressBar to this view
addView(progressBar)

// Set an OnTouchListener that does nothing but consume touch events
// to prevent taps from reaching the view this loading indicator obstructs
setOnTouchListener { _, _ -> true }
}
}

0 comments on commit a6a2751

Please sign in to comment.