-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
129 changed files
with
7,191 additions
and
5,939 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
adapty-ui/src/main/java/com/adapty/ui/AdaptyPaywallInsets.kt
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
adapty-ui/src/main/java/com/adapty/ui/AdaptyPaywallScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.adapty.ui | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.adapty.models.AdaptyPaywallProduct | ||
import com.adapty.ui.internal.ui.AdaptyPaywallInternal | ||
import com.adapty.ui.internal.ui.PaywallViewModel | ||
import com.adapty.ui.internal.ui.PaywallViewModelArgs | ||
import com.adapty.ui.internal.ui.PaywallViewModelFactory | ||
import com.adapty.ui.internal.ui.UserArgs | ||
import com.adapty.ui.internal.utils.ProductLoadingFailureCallback | ||
import com.adapty.ui.internal.utils.getCurrentLocale | ||
import com.adapty.ui.listeners.AdaptyUiDefaultEventListener | ||
import com.adapty.ui.listeners.AdaptyUiEventListener | ||
import com.adapty.ui.listeners.AdaptyUiObserverModeHandler | ||
import com.adapty.ui.listeners.AdaptyUiPersonalizedOfferResolver | ||
import com.adapty.ui.listeners.AdaptyUiTagResolver | ||
import com.adapty.ui.listeners.AdaptyUiTimerResolver | ||
import java.util.UUID | ||
|
||
/** | ||
* Paywall screen composable representation | ||
* | ||
* @param[viewConfiguration] An [AdaptyUI.LocalizedViewConfiguration] object containing information | ||
* about the visual part of the paywall. To load it, use the [AdaptyUI.getViewConfiguration] method. | ||
* | ||
* @param[products] Optional [AdaptyPaywallProduct] list. Pass this value in order to optimize | ||
* the display time of the products on the screen. If you pass `null`, `AdaptyUI` will | ||
* automatically fetch the required products. | ||
* | ||
* @param[eventListener] An object that implements the [AdaptyUiEventListener] interface. | ||
* Use it to respond to different events happening inside the purchase screen. | ||
* Also you can extend [AdaptyUiDefaultEventListener] so you don't need to override all the methods. | ||
* | ||
* @param[personalizedOfferResolver] In case you want to indicate whether the price is personalized ([read more](https://developer.android.com/google/play/billing/integrate#personalized-price)), | ||
* you can implement [AdaptyUiPersonalizedOfferResolver] and pass your own logic | ||
* that maps [AdaptyPaywallProduct] to `true`, if the price of the product is personalized, otherwise `false`. | ||
* | ||
* @param[tagResolver] If you are going to use custom tags functionality, pass the resolver function here. | ||
* | ||
* @param[timerResolver] If you are going to use custom timer functionality, pass the resolver function here. | ||
* | ||
* @param[observerModeHandler] If you use Adapty in [Observer mode](https://adapty.io/docs/observer-vs-full-mode), | ||
* pass the [AdaptyUiObserverModeHandler] implementation to handle purchases on your own. | ||
*/ | ||
@Composable | ||
public fun AdaptyPaywallScreen( | ||
viewConfiguration: AdaptyUI.LocalizedViewConfiguration, | ||
products: List<AdaptyPaywallProduct>?, | ||
eventListener: AdaptyUiEventListener, | ||
personalizedOfferResolver: AdaptyUiPersonalizedOfferResolver = AdaptyUiPersonalizedOfferResolver.DEFAULT, | ||
tagResolver: AdaptyUiTagResolver = AdaptyUiTagResolver.DEFAULT, | ||
timerResolver: AdaptyUiTimerResolver = AdaptyUiTimerResolver.DEFAULT, | ||
observerModeHandler: AdaptyUiObserverModeHandler? = null, | ||
) { | ||
val context = LocalContext.current | ||
val vmArgs = remember { | ||
val userArgs = UserArgs.create( | ||
viewConfiguration, | ||
eventListener, | ||
personalizedOfferResolver, | ||
tagResolver, | ||
timerResolver, | ||
observerModeHandler, | ||
products, | ||
ProductLoadingFailureCallback { error -> eventListener.onLoadingProductsFailure(error, context) }, | ||
) | ||
PaywallViewModelArgs.create( | ||
"${UUID.randomUUID().toString().hashCode()}", | ||
userArgs, | ||
context.getCurrentLocale(), | ||
) | ||
} ?: return | ||
|
||
val viewModel: PaywallViewModel = viewModel( | ||
factory = PaywallViewModelFactory(vmArgs) | ||
) | ||
AdaptyPaywallInternal(viewModel) | ||
} |
Oops, something went wrong.