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

Remove embedding v1 support #1141

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.revenuecat.purchases.DangerousSettings;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.PurchasesAreCompletedBy;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.Store;
import com.revenuecat.purchases.common.PlatformInfo;
Expand Down Expand Up @@ -51,11 +50,6 @@ public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler,
private static final String CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated";
protected static final String LOG_HANDLER_EVENT = "Purchases-LogHandlerEvent";

// Only set registrar for v1 embedder.
@SuppressWarnings("deprecation")
private io.flutter.plugin.common.PluginRegistry.Registrar registrar;
// Only set activity for v2 embedder. Always access activity from getActivity()
// method.
@Nullable
private Context applicationContext;
@Nullable
Expand All @@ -68,27 +62,6 @@ public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler,
private static final String PLATFORM_NAME = "flutter";
private static final String PLUGIN_VERSION = "7.0.2";

/**
* Plugin registration.
*/
@SuppressWarnings("deprecation")
public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) {
PurchasesFlutterPlugin instance = new PurchasesFlutterPlugin();
instance.onAttachedToEngine(registrar.messenger(), registrar.context());
instance.registrar = registrar;
registrar.addViewDestroyListener(new io.flutter.plugin.common.PluginRegistry.ViewDestroyListener() {
@Override
public boolean onViewDestroy(io.flutter.view.FlutterNativeView flutterNativeView) {
try {
Purchases.getSharedInstance().close();
} catch (UninitializedPropertyAccessException e) {
// there's no instance so all good
}
return false;
}
});
}

@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
onAttachedToEngine(binding.getBinaryMessenger(), binding.getApplicationContext());
Expand Down Expand Up @@ -129,10 +102,6 @@ public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}

public Activity getActivity() {
return registrar != null ? registrar.activity() : activity;
}
Comment on lines -132 to -134
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to clean this up 👍


@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
Expand Down Expand Up @@ -219,7 +188,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
setDebugLogsEnabled(enabled, result);
break;
case "setLogLevel":
String level = (String) call.argument("level");
String level = call.argument("level");
setLogLevel(level, result);
break;
case "setProxyURLString":
Expand All @@ -232,10 +201,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "syncPurchases":
syncPurchases(result);
break;
case "enableAdServicesAttributionTokenCollection":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took the chance to cleanup a few warnings I was getting in Android studio.

// NOOP
result.success(null);
break;
case "isAnonymous":
isAnonymous(result);
break;
Expand All @@ -256,6 +221,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
case "beginRefundRequestForProduct":
case "beginRefundRequestForEntitlement":
case "recordPurchaseForProductID":
case "enableAdServicesAttributionTokenCollection":
// NOOP
result.success(null);
break;
Expand Down Expand Up @@ -457,7 +423,7 @@ private void purchaseProduct(final String productIdentifier,
@Nullable final Map<String, Object> presentedOfferingContext,
final Result result) {
CommonKt.purchaseProduct(
getActivity(),
activity,
productIdentifier,
type,
null,
Expand All @@ -475,7 +441,7 @@ private void purchasePackage(final String packageIdentifier,
@Nullable final Boolean googleIsPersonalizedPrice,
final Result result) {
CommonKt.purchasePackage(
getActivity(),
activity,
packageIdentifier,
presentedOfferingContext,
googleOldProductId,
Expand All @@ -492,7 +458,7 @@ private void purchaseSubscriptionOption(final String productIdentifier,
@Nullable final Map<String, Object> presentedOfferingContext,
final Result result) {
CommonKt.purchaseSubscriptionOption(
getActivity(),
activity,
productIdentifier,
optionIdentifier,
googleOldProductId,
Expand Down Expand Up @@ -744,12 +710,12 @@ private void runOnUiThread(Runnable runnable) {
private OnResult getOnResult(final Result result) {
return new OnResult() {
@Override
public void onReceived(Map<String, ?> map) {
public void onReceived(@NotNull Map<String, ?> map) {
result.success(map);
}

@Override
public void onError(ErrorContainer errorContainer) {
public void onError(@NotNull ErrorContainer errorContainer) {
reject(errorContainer, result);
}
};
Expand All @@ -764,7 +730,7 @@ public void onReceived(@Nullable Map<String, ?> map) {
}

@Override
public void onError(ErrorContainer errorContainer) {
public void onError(@NotNull ErrorContainer errorContainer) {
reject(errorContainer, result);
}
};
Expand Down