From 9bb9389ad00453b0a2773b0673fe823e0d72c479 Mon Sep 17 00:00:00 2001 From: Deepesh Date: Thu, 17 Apr 2025 12:17:32 +0530 Subject: [PATCH] working with flutter v3.29 --- android/.gitignore | 9 ---- android/build.gradle | 9 ++-- android/src/main/AndroidManifest.xml | 3 +- .../GooglePayButtonViewManager.java | 43 +++++++++++-------- .../TapGooglePayKitFlutterPlugin.java | 26 +++++++---- .../res/layout/google_pay_button_layout.xml | 18 +++----- android/src/main/res/values/ids.xml | 4 ++ 7 files changed, 57 insertions(+), 55 deletions(-) delete mode 100644 android/.gitignore create mode 100644 android/src/main/res/values/ids.xml diff --git a/android/.gitignore b/android/.gitignore deleted file mode 100644 index 161bdcd..0000000 --- a/android/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures -.cxx diff --git a/android/build.gradle b/android/build.gradle index cd152fa..2761776 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -2,6 +2,7 @@ group 'tap.company.tap_google_pay_kit_flutter' version '1.0' buildscript { + ext.kotlin_version = '2.1.0' repositories { google() mavenCentral() @@ -23,8 +24,8 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 34 - namespace 'tap.company.tap_google_pay_kit_flutter' + namespace "company.tap.google.pay.kit.flutter" + compileSdkVersion 31 compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -37,6 +38,6 @@ android { } dependencies { - implementation 'com.github.Tap-Payments:TapGooglePayKit:1.0.2' - implementation "com.google.android.gms:play-services-wallet:19.4.0" + implementation 'com.github.Tap-Payments:TapGooglePayKit:1.0.0' + implementation "com.google.android.gms:play-services-wallet:18.1.3" } diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 447bdde..9022e6f 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + creationParams) { - view = LayoutInflater.from(context).inflate(R.layout.google_pay_button_layout,null); - googlePayButton = view.findViewById(R.id.googlePayView); - googlePayButton.setGooglePayButtonType(getGooglePayType(creationParams.get("type").toString())); - System.out.println("Google Pay Button View Manager >>>>>>>>>>>>>>"); - } + // Create views programmatically instead of using XML inflation + containerView = new FrameLayout(context); + googlePayButton = new GooglePayButton(context); + + // Add GooglePayButton to the container + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + FrameLayout.LayoutParams.MATCH_PARENT, + FrameLayout.LayoutParams.WRAP_CONTENT); + containerView.addView(googlePayButton, params); + // Set button type if provided in creation params + if (creationParams != null && creationParams.containsKey("type")) { + googlePayButton.setGooglePayButtonType(getGooglePayType(creationParams.get("type").toString())); + } else { + // Default type + googlePayButton.setGooglePayButtonType(GooglePayButtonType.NORMAL_GOOGLE_PAY); + } + + System.out.println("Google Pay Button View Manager programmatically created >>>>>>>>>>>>>>"); + } @NonNull private GooglePayButtonType getGooglePayType(String typeValue) { @@ -56,21 +70,14 @@ private GooglePayButtonType getGooglePayType(String typeValue) { return type; } - -// public void setType(@NonNull View view, String type) { -// googlePayButton = view.findViewById(R.id.googlePayView); -// googlePayButton.setGooglePayButtonType(getGooglePayType("BUY_WITH_GOOGLE_PAY")); -// } - @Nullable @Override public View getView() { - return view; + return containerView; } - @Override public void dispose() { - + // Clean up any resources } -} +} \ No newline at end of file diff --git a/android/src/main/java/tap/company/tap_google_pay_kit_flutter/TapGooglePayKitFlutterPlugin.java b/android/src/main/java/tap/company/tap_google_pay_kit_flutter/TapGooglePayKitFlutterPlugin.java index f4123cb..a1f3fa2 100644 --- a/android/src/main/java/tap/company/tap_google_pay_kit_flutter/TapGooglePayKitFlutterPlugin.java +++ b/android/src/main/java/tap/company/tap_google_pay_kit_flutter/TapGooglePayKitFlutterPlugin.java @@ -26,8 +26,6 @@ */ public class TapGooglePayKitFlutterPlugin implements MethodChannel.MethodCallHandler, FlutterPlugin, ActivityAware { - - /** * LifeCycleObserver */ @@ -116,7 +114,16 @@ public void onActivityStopped(Activity activity) { private LifeCycleObserver observer; private static final String CHANNEL = "tap_google_pay_kit_flutter"; + /** + * Register with + * + * @param registrar + */ + public static void registerWith(Object registrar) { + // This method is kept for compatibility with older Flutter versions + // but is no longer used with the v2 embedding API + } /** * Default constructor for the plugin. @@ -126,7 +133,6 @@ public void onActivityStopped(Activity activity) { public TapGooglePayKitFlutterPlugin() { } - /** * @param binding */ @@ -150,6 +156,7 @@ public void onAttachedToActivity(ActivityPluginBinding binding) { pluginBinding.getBinaryMessenger(), (Application) pluginBinding.getApplicationContext(), activityBinding.getActivity(), + null, activityBinding); } @@ -163,7 +170,6 @@ public void onDetachedFromActivityForConfigChanges() { onDetachedFromActivity(); } - @Override public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) { onAttachedToActivity(binding); @@ -177,6 +183,7 @@ private void setup( final BinaryMessenger messenger, final Application application, final Activity activity, + final Object registrar, // Changed from PluginRegistry.Registrar final ActivityPluginBinding activityBinding) { this.activity = activity; this.application = application; @@ -184,7 +191,10 @@ private void setup( channel = new MethodChannel(messenger, "tap_google_pay_kit_flutter"); channel.setMethodCallHandler(this); observer = new LifeCycleObserver(activity); - if (activityBinding != null) { + if (registrar != null) { + // V1 embedding setup for activity listeners is no longer supported + application.registerActivityLifecycleCallbacks(observer); + } else { // V2 embedding setup for activity listeners. activityBinding.addActivityResultListener(delegate); activityBinding.addRequestPermissionsResultListener(delegate); @@ -193,7 +203,6 @@ private void setup( } } - /** * tearDown() */ @@ -211,7 +220,6 @@ private void tearDown() { application = null; } - /** * construct delegate */ @@ -275,11 +283,11 @@ public void onMethodCall(MethodCall call, MethodChannel.Result rawResult) { if (call.method.equals("terminate_session")) { System.out.println("terminate session!"); - // delegate.terminateSDKSession(); + // delegate.terminateSDKSession(); return; } MethodChannel.Result result = new MethodResultWrapper(rawResult); delegate.start(activity, result, args); } -} +} \ No newline at end of file diff --git a/android/src/main/res/layout/google_pay_button_layout.xml b/android/src/main/res/layout/google_pay_button_layout.xml index b5f1862..78e1027 100644 --- a/android/src/main/res/layout/google_pay_button_layout.xml +++ b/android/src/main/res/layout/google_pay_button_layout.xml @@ -1,19 +1,11 @@ - - + android:layout_height="wrap_content"> - + android:layout_height="wrap_content" /> + + diff --git a/android/src/main/res/values/ids.xml b/android/src/main/res/values/ids.xml new file mode 100644 index 0000000..4e4cd73 --- /dev/null +++ b/android/src/main/res/values/ids.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file