Skip to content

Commit

Permalink
Remove embedding v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
tonidero committed Aug 13, 2024
1 parent 0bc1274 commit 2d1df95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 44 deletions.
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;
}

@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":
// 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import FlutterMacOS
import Foundation

import purchases_flutter
import purchases_ui_flutter

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PurchasesFlutterPlugin.register(with: registry.registrar(forPlugin: "PurchasesFlutterPlugin"))
PurchasesUiFlutterPlugin.register(with: registry.registrar(forPlugin: "PurchasesUiFlutterPlugin"))
}

0 comments on commit 2d1df95

Please sign in to comment.