1111
1212import com .revenuecat .purchases .DangerousSettings ;
1313import com .revenuecat .purchases .Purchases ;
14- import com .revenuecat .purchases .PurchasesAreCompletedBy ;
1514import com .revenuecat .purchases .PurchasesErrorCode ;
1615import com .revenuecat .purchases .Store ;
1716import com .revenuecat .purchases .common .PlatformInfo ;
@@ -51,11 +50,6 @@ public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler,
5150 private static final String CUSTOMER_INFO_UPDATED = "Purchases-CustomerInfoUpdated" ;
5251 protected static final String LOG_HANDLER_EVENT = "Purchases-LogHandlerEvent" ;
5352
54- // Only set registrar for v1 embedder.
55- @ SuppressWarnings ("deprecation" )
56- private io .flutter .plugin .common .PluginRegistry .Registrar registrar ;
57- // Only set activity for v2 embedder. Always access activity from getActivity()
58- // method.
5953 @ Nullable
6054 private Context applicationContext ;
6155 @ Nullable
@@ -68,27 +62,6 @@ public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler,
6862 private static final String PLATFORM_NAME = "flutter" ;
6963 private static final String PLUGIN_VERSION = "7.0.2" ;
7064
71- /**
72- * Plugin registration.
73- */
74- @ SuppressWarnings ("deprecation" )
75- public static void registerWith (io .flutter .plugin .common .PluginRegistry .Registrar registrar ) {
76- PurchasesFlutterPlugin instance = new PurchasesFlutterPlugin ();
77- instance .onAttachedToEngine (registrar .messenger (), registrar .context ());
78- instance .registrar = registrar ;
79- registrar .addViewDestroyListener (new io .flutter .plugin .common .PluginRegistry .ViewDestroyListener () {
80- @ Override
81- public boolean onViewDestroy (io .flutter .view .FlutterNativeView flutterNativeView ) {
82- try {
83- Purchases .getSharedInstance ().close ();
84- } catch (UninitializedPropertyAccessException e ) {
85- // there's no instance so all good
86- }
87- return false ;
88- }
89- });
90- }
91-
9265 @ Override
9366 public void onAttachedToEngine (@ NonNull FlutterPluginBinding binding ) {
9467 onAttachedToEngine (binding .getBinaryMessenger (), binding .getApplicationContext ());
@@ -129,10 +102,6 @@ public void onDetachedFromActivityForConfigChanges() {
129102 onDetachedFromActivity ();
130103 }
131104
132- public Activity getActivity () {
133- return registrar != null ? registrar .activity () : activity ;
134- }
135-
136105 @ Override
137106 public void onMethodCall (@ NonNull MethodCall call , @ NonNull Result result ) {
138107 switch (call .method ) {
@@ -219,7 +188,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
219188 setDebugLogsEnabled (enabled , result );
220189 break ;
221190 case "setLogLevel" :
222- String level = ( String ) call .argument ("level" );
191+ String level = call .argument ("level" );
223192 setLogLevel (level , result );
224193 break ;
225194 case "setProxyURLString" :
@@ -232,10 +201,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
232201 case "syncPurchases" :
233202 syncPurchases (result );
234203 break ;
235- case "enableAdServicesAttributionTokenCollection" :
236- // NOOP
237- result .success (null );
238- break ;
239204 case "isAnonymous" :
240205 isAnonymous (result );
241206 break ;
@@ -256,6 +221,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
256221 case "beginRefundRequestForProduct" :
257222 case "beginRefundRequestForEntitlement" :
258223 case "recordPurchaseForProductID" :
224+ case "enableAdServicesAttributionTokenCollection" :
259225 // NOOP
260226 result .success (null );
261227 break ;
@@ -457,7 +423,7 @@ private void purchaseProduct(final String productIdentifier,
457423 @ Nullable final Map <String , Object > presentedOfferingContext ,
458424 final Result result ) {
459425 CommonKt .purchaseProduct (
460- getActivity () ,
426+ activity ,
461427 productIdentifier ,
462428 type ,
463429 null ,
@@ -475,7 +441,7 @@ private void purchasePackage(final String packageIdentifier,
475441 @ Nullable final Boolean googleIsPersonalizedPrice ,
476442 final Result result ) {
477443 CommonKt .purchasePackage (
478- getActivity () ,
444+ activity ,
479445 packageIdentifier ,
480446 presentedOfferingContext ,
481447 googleOldProductId ,
@@ -492,7 +458,7 @@ private void purchaseSubscriptionOption(final String productIdentifier,
492458 @ Nullable final Map <String , Object > presentedOfferingContext ,
493459 final Result result ) {
494460 CommonKt .purchaseSubscriptionOption (
495- getActivity () ,
461+ activity ,
496462 productIdentifier ,
497463 optionIdentifier ,
498464 googleOldProductId ,
@@ -744,12 +710,12 @@ private void runOnUiThread(Runnable runnable) {
744710 private OnResult getOnResult (final Result result ) {
745711 return new OnResult () {
746712 @ Override
747- public void onReceived (Map <String , ?> map ) {
713+ public void onReceived (@ NotNull Map <String , ?> map ) {
748714 result .success (map );
749715 }
750716
751717 @ Override
752- public void onError (ErrorContainer errorContainer ) {
718+ public void onError (@ NotNull ErrorContainer errorContainer ) {
753719 reject (errorContainer , result );
754720 }
755721 };
@@ -764,7 +730,7 @@ public void onReceived(@Nullable Map<String, ?> map) {
764730 }
765731
766732 @ Override
767- public void onError (ErrorContainer errorContainer ) {
733+ public void onError (@ NotNull ErrorContainer errorContainer ) {
768734 reject (errorContainer , result );
769735 }
770736 };
0 commit comments