Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RevenueCatUI API issues and add API tests #1433

Merged
merged 4 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api-tester/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ dependencies {
implementation project(path: ':purchases')
implementation project(path: ':feature:amazon')
implementation project(path: ':ui:debugview')
implementation project(path: ':ui:revenuecatui')

implementation(platform(libs.kotlin.bom))
implementation platform(libs.compose.bom)
implementation libs.compose.ui
implementation libs.activity.compose
implementation libs.androidx.fragment.ktx
implementation libs.compose.ui.google.fonts
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.revenuecat.apitester.java.revenuecatui;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.compose.ui.text.font.FontFamily;
import androidx.compose.ui.text.font.FontWeight;
import androidx.compose.ui.text.googlefonts.GoogleFont;

import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI;
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider;
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomParcelizableFontProvider;
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider;
import com.revenuecat.purchases.ui.revenuecatui.fonts.GoogleFontProvider;
import com.revenuecat.purchases.ui.revenuecatui.fonts.ParcelizableFontProvider;
import com.revenuecat.purchases.ui.revenuecatui.fonts.PaywallFont;
import com.revenuecat.purchases.ui.revenuecatui.fonts.PaywallFontFamily;
import com.revenuecat.purchases.ui.revenuecatui.fonts.TypographyType;

import java.util.List;

@SuppressWarnings({"unused"})
@OptIn(markerClass = ExperimentalPreviewRevenueCatUIPurchasesAPI.class)
final class FontProviderAPI {
static void check(TypographyType typographyType) {
FontProvider fontProvider = new FontProvider() {
@Nullable
@Override
public FontFamily getFont(@NonNull TypographyType type) {
return null;
}
};
FontFamily fontFamily = fontProvider.getFont(typographyType);
CustomFontProvider customFontProvider = new CustomFontProvider(FontFamily.Companion.getDefault());
}

static void checkParcelizableFontProvider(TypographyType typographyType, List<PaywallFont> fonts) {
ParcelizableFontProvider fontProvider = new ParcelizableFontProvider() {
@Nullable
@Override
public PaywallFontFamily getFont(@NonNull TypographyType type) {
return null;
}
};
PaywallFontFamily fontFamily = fontProvider.getFont(typographyType);
CustomParcelizableFontProvider customFontProvider = new CustomParcelizableFontProvider(new PaywallFontFamily(fonts));
}

static void checkPaywallFontFamily(PaywallFontFamily fontFamily) {
List<PaywallFont> fonts = fontFamily.getFonts();
}

static void checkPaywallFont(PaywallFont font) {
if (font instanceof PaywallFont.GoogleFont) {
final PaywallFont.GoogleFont googleFont = (PaywallFont.GoogleFont) font;
String fontName = googleFont.getFontName();
GoogleFontProvider provider = googleFont.getFontProvider();
FontWeight fontWeight = googleFont.getFontWeight();
int fontStyle = googleFont.getFontStyle();
final PaywallFont.GoogleFont googleFont2 = new PaywallFont.GoogleFont(
fontName,
provider,
fontWeight,
fontStyle
);
} else if (font instanceof PaywallFont.ResourceFont) {
final PaywallFont.ResourceFont resourceFont = (PaywallFont.ResourceFont) font;
int fontRes = resourceFont.getResourceId();
FontWeight fontWeight = resourceFont.getFontWeight();
int fontStyle = resourceFont.getFontStyle();
final PaywallFont.ResourceFont resourceFont2 = new PaywallFont.ResourceFont(fontRes, fontWeight, fontStyle);
}
}

static void checkGoogleFontProvider(
int certificates,
String providerAuthority,
String providerPackage
) {
GoogleFontProvider provider = new GoogleFontProvider(certificates, providerAuthority, providerPackage);
int providerCertificates = provider.getCertificates();
String providerAuthority2 = provider.getProviderAuthority();
String providerPackage2 = provider.getProviderPackage();
GoogleFont.Provider googleProvider = provider.toGoogleProvider();
}

static Boolean checkTypographyType(TypographyType type) {
switch (type) {
case DISPLAY_LARGE:
case DISPLAY_MEDIUM:
case DISPLAY_SMALL:
case HEADLINE_LARGE:
case HEADLINE_MEDIUM:
case HEADLINE_SMALL:
case TITLE_LARGE:
case TITLE_MEDIUM:
case TITLE_SMALL:
case BODY_LARGE:
case BODY_MEDIUM:
case BODY_SMALL:
case LABEL_LARGE:
case LABEL_MEDIUM:
case LABEL_SMALL:
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.revenuecat.apitester.java.revenuecatui;


import androidx.activity.ComponentActivity;
import androidx.fragment.app.Fragment;

import com.revenuecat.purchases.Offering;
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResultHandler;
import com.revenuecat.purchases.ui.revenuecatui.fonts.ParcelizableFontProvider;

@SuppressWarnings({"unused"})
@ExperimentalPreviewRevenueCatUIPurchasesAPI
final class PaywallActivityLauncherAPI {

static void check(
ComponentActivity activity,
Fragment fragment,
PaywallResultHandler resultHandler,
Offering offering,
ParcelizableFontProvider fontProvider
) {
PaywallActivityLauncher launcher = new PaywallActivityLauncher(activity, resultHandler);
PaywallActivityLauncher launcher2 = new PaywallActivityLauncher(fragment, resultHandler);
launcher.launch();
launcher.launch(offering);
launcher.launch(null, fontProvider);
launcher.launch(null, null, true);
launcher.launchIfNeeded("requiredEntitlementIdentifier");
launcher.launchIfNeeded(null, null, true, customerInfo -> null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.revenuecat.apitester.java.revenuecatui;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.activity.result.ActivityResultCallback;
import androidx.annotation.NonNull;

import com.revenuecat.purchases.CustomerInfo;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResult;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResultHandler;

@SuppressWarnings({"unused"})
@ExperimentalPreviewRevenueCatUIPurchasesAPI
final class PaywallResultAPI {

static void checkResultHandler(
final PaywallResultHandler resultHandler
) {
final ActivityResultCallback<PaywallResult> callback = resultHandler;
}

static void checkResult(PurchasesError error, CustomerInfo customerInfo) {
final PaywallResult result = PaywallResult.Cancelled.INSTANCE;
final Parcelable parcelable = result;
final PaywallResult.Error result2 = new PaywallResult.Error(error);
PurchasesError error2 = result2.getError();
final PaywallResult.Purchased result3 = new PaywallResult.Purchased(customerInfo);
CustomerInfo customerInfo2 = result3.getCustomerInfo();
final PaywallResult result2AsSealedClass = result2;
final PaywallResult result3AsSealedClass = result3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.revenuecat.apitester.kotlin.revenuecatui

import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontFamily.Companion.Default
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.googlefonts.GoogleFont
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomFontProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.CustomParcelizableFontProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.GoogleFontProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.ParcelizableFontProvider
import com.revenuecat.purchases.ui.revenuecatui.fonts.PaywallFont
import com.revenuecat.purchases.ui.revenuecatui.fonts.PaywallFontFamily
import com.revenuecat.purchases.ui.revenuecatui.fonts.TypographyType

@Suppress("unused", "UNUSED_VARIABLE")
@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
private class FontProviderAPI {
fun check(typographyType: TypographyType) {
val fontProvider: FontProvider = object : FontProvider {
override fun getFont(type: TypographyType): FontFamily? {
return null
}
}
val fontFamily = fontProvider.getFont(typographyType)
val customFontProvider = CustomFontProvider(Default)
}

fun checkParcelizableFontProvider(typographyType: TypographyType, fonts: List<PaywallFont>) {
val fontProvider: ParcelizableFontProvider = object : ParcelizableFontProvider {
override fun getFont(type: TypographyType): PaywallFontFamily? {
return null
}
}
val fontFamily = fontProvider.getFont(typographyType)
val customFontProvider = CustomParcelizableFontProvider(PaywallFontFamily(fonts))
}

fun checkPaywallFontFamily(fontFamily: PaywallFontFamily) {
val fonts = fontFamily.fonts
}

fun checkPaywallFont(font: PaywallFont) {
if (font is PaywallFont.GoogleFont) {
val fontName: String = font.fontName
val provider: GoogleFontProvider = font.fontProvider
val fontWeight: FontWeight = font.fontWeight
val fontStyle: FontStyle = font.fontStyle
val googleFont = PaywallFont.GoogleFont(
fontName,
provider,
fontWeight,
fontStyle,
)
} else if (font is PaywallFont.ResourceFont) {
val fontRes: Int = font.resourceId
val fontWeight: FontWeight = font.fontWeight
val fontStyle: FontStyle = font.fontStyle
val resourceFont = PaywallFont.ResourceFont(fontRes, fontWeight, fontStyle)
}
}

fun checkGoogleFontProvider(
certificates: Int,
providerAuthority: String?,
providerPackage: String?,
) {
val provider = GoogleFontProvider(certificates, providerAuthority!!, providerPackage!!)
val providerCertificates = provider.certificates
val providerAuthority2 = provider.providerAuthority
val providerPackage2 = provider.providerPackage
val googleProvider: GoogleFont.Provider = provider.toGoogleProvider()
}

fun checkTypographyType(type: TypographyType): Boolean {
when (type) {
TypographyType.DISPLAY_LARGE,
TypographyType.DISPLAY_MEDIUM,
TypographyType.DISPLAY_SMALL,
TypographyType.HEADLINE_LARGE,
TypographyType.HEADLINE_MEDIUM,
TypographyType.HEADLINE_SMALL,
TypographyType.TITLE_LARGE,
TypographyType.TITLE_MEDIUM,
TypographyType.TITLE_SMALL,
TypographyType.BODY_LARGE,
TypographyType.BODY_MEDIUM,
TypographyType.BODY_SMALL,
TypographyType.LABEL_LARGE,
TypographyType.LABEL_MEDIUM,
TypographyType.LABEL_SMALL,
-> return true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.revenuecat.apitester.kotlin.revenuecatui

import androidx.compose.runtime.Composable
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI
import com.revenuecat.purchases.ui.revenuecatui.Paywall
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialogOptions
import com.revenuecat.purchases.ui.revenuecatui.PaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions

@Suppress("unused", "UNUSED_VARIABLE")
@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
private class PaywallAPI {

@Composable
fun check(options: PaywallOptions) {
Paywall(options = options)
}

@Composable
fun checkFooter(options: PaywallOptions) {
PaywallFooter(options = options, condensed = true) {}
}

@Composable
fun checkDialog(options: PaywallDialogOptions) {
PaywallDialog(paywallDialogOptions = options)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.revenuecat.apitester.kotlin.revenuecatui

import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.ui.revenuecatui.ExperimentalPreviewRevenueCatUIPurchasesAPI
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallResultHandler
import com.revenuecat.purchases.ui.revenuecatui.fonts.ParcelizableFontProvider

@Suppress("unused", "UNUSED_VARIABLE")
@OptIn(ExperimentalPreviewRevenueCatUIPurchasesAPI::class)
private class PaywallActivityLauncherAPI {
fun check(
componentActivity: ComponentActivity,
fragment: Fragment,
resultHandler: PaywallResultHandler,
offering: Offering,
fontProvider: ParcelizableFontProvider,
) {
val activityLauncher = PaywallActivityLauncher(componentActivity, resultHandler)
val activityLauncher2 = PaywallActivityLauncher(fragment, resultHandler)
activityLauncher.launch()
activityLauncher.launch(offering)
activityLauncher.launch(
offering = offering,
fontProvider = fontProvider,
shouldDisplayDismissButton = true,
)
activityLauncher.launchIfNeeded("requiredEntitlementIdentifier")
activityLauncher.launchIfNeeded(
requiredEntitlementIdentifier = "requiredEntitlementIdentifier",
offering = offering,
fontProvider = fontProvider,
shouldDisplayDismissButton = true,
)
activityLauncher.launchIfNeeded {
val customerInfo: CustomerInfo = it
true
}
activityLauncher.launchIfNeeded(
offering = offering,
fontProvider = fontProvider,
shouldDisplayDismissButton = true,
) {
val customerInfo: CustomerInfo = it
true
}
}
}
Loading