|
38 | 38 | import java.util.HashMap; |
39 | 39 | import java.util.Map; |
40 | 40 |
|
| 41 | +import io.flutter.embedding.engine.plugins.FlutterPlugin; |
| 42 | +import io.flutter.embedding.engine.plugins.activity.ActivityAware; |
| 43 | +import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; |
41 | 44 | import io.flutter.plugin.common.MethodChannel; |
42 | 45 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; |
43 | 46 | import io.flutter.plugin.common.MethodChannel.Result; |
|
46 | 49 |
|
47 | 50 | import static com.adjust.sdk.flutter.AdjustUtils.*; |
48 | 51 |
|
49 | | -public class AdjustSdk implements MethodCallHandler { |
| 52 | +public class AdjustSdk implements FlutterPlugin, ActivityAware, MethodCallHandler { |
50 | 53 | private static String TAG = "AdjustBridge"; |
51 | 54 | private static boolean launchDeferredDeeplink = true; |
52 | 55 | private MethodChannel channel; |
53 | 56 | private Context applicationContext; |
| 57 | + private boolean v2Plugin; |
| 58 | + private boolean v2Attached = false; |
54 | 59 |
|
55 | 60 | AdjustSdk(MethodChannel channel, Context applicationContext) { |
56 | 61 | this.channel = channel; |
57 | 62 | this.applicationContext = applicationContext; |
| 63 | + |
| 64 | + v2Plugin = false; |
| 65 | + } |
| 66 | + |
| 67 | + public AdjustSdk() { |
| 68 | + v2Plugin = true; |
| 69 | + } |
| 70 | + |
| 71 | + // FlutterPlugin |
| 72 | + @Override |
| 73 | + public void onAttachedToEngine(FlutterPluginBinding binding) { |
| 74 | + if (!v2Plugin) { |
| 75 | + return; |
| 76 | + } |
| 77 | + if (v2Attached) { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + v2Attached = true; |
| 82 | + applicationContext = binding.getApplicationContext(); |
| 83 | + channel = new MethodChannel(binding.getBinaryMessenger(), "com.adjust.sdk/api"); |
| 84 | + channel.setMethodCallHandler(this); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void onDetachedFromEngine(FlutterPluginBinding binding) { |
| 89 | + v2Attached = false; |
| 90 | + applicationContext = null; |
| 91 | + if (channel != null) { |
| 92 | + channel.setMethodCallHandler(null); |
| 93 | + } |
| 94 | + channel = null; |
| 95 | + } |
| 96 | + |
| 97 | + // ActivityAware |
| 98 | + @Override |
| 99 | + public void onAttachedToActivity(ActivityPluginBinding binding) { |
| 100 | + Adjust.onResume(); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public void onDetachedFromActivityForConfigChanges() { |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public void onReattachedToActivityForConfigChanges( |
| 109 | + ActivityPluginBinding binding) |
| 110 | + { |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void onDetachedFromActivity() { |
| 115 | + Adjust.onPause(); |
58 | 116 | } |
59 | 117 |
|
60 | 118 | // Plugin registration. |
|
0 commit comments