@@ -16,89 +16,97 @@ import io.flutter.plugin.common.MethodChannel.MethodCallHandler
1616import io.flutter.plugin.common.MethodChannel.Result
1717
1818class MatiPluginFlutterPlugin : FlutterPlugin , MethodCallHandler , ActivityAware {
19- private lateinit var channel: MethodChannel
19+ private lateinit var channel: MethodChannel
2020
21- private var activity: Activity ? = null
21+ private var activity: Activity ? = null
2222
23- override fun onAttachedToEngine (@NonNull flutterPluginBinding : FlutterPlugin .FlutterPluginBinding ) {
24- channel = MethodChannel (flutterPluginBinding.binaryMessenger, " mati_flutter" )
25- channel.setMethodCallHandler(this )
26- }
23+ override fun onAttachedToEngine (@NonNull flutterPluginBinding : FlutterPlugin .FlutterPluginBinding ) {
24+ channel = MethodChannel (flutterPluginBinding.binaryMessenger, " mati_flutter" )
25+ channel.setMethodCallHandler(this )
26+ }
2727
28- override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
29- binding.addActivityResultListener { requestCode, resultCode, data ->
30- if (requestCode == MetamapSdk .DEFAULT_REQUEST_CODE ) {
31- val intent = data
32- if (resultCode == Activity .RESULT_OK && intent != null ) {
33- val result =
34- intent.getStringExtra(" ARG_VERIFICATION_ID" ) + " " + intent.getStringExtra(" ARG_IDENTITY_ID" )
35- channel.invokeMethod(" success" , result)
36- } else {
37- channel.invokeMethod(" cancelled" , null )
28+ override fun onAttachedToActivity (binding : ActivityPluginBinding ) {
29+ binding.addActivityResultListener { requestCode, resultCode, data ->
30+ if (requestCode == MetamapSdk .DEFAULT_REQUEST_CODE ) {
31+ val intent = data
32+ if (resultCode == Activity .RESULT_OK && intent != null ) {
33+ val result =
34+ intent.getStringExtra(" ARG_VERIFICATION_ID" ) + " " + intent.getStringExtra(" ARG_IDENTITY_ID" )
35+ channel.invokeMethod(" success" , result)
36+ } else {
37+ channel.invokeMethod(" cancelled" , null )
38+ }
39+ true
40+ }
41+ false
3842 }
39- true
40- }
41- false
43+ activity = binding.activity
44+ }
45+
46+ override fun onDetachedFromActivityForConfigChanges () {
47+ activity = null
4248 }
43- activity = binding.activity
44- }
4549
46- override fun onDetachedFromActivityForConfigChanges ( ) {
47- activity = null
48- }
50+ override fun onReattachedToActivityForConfigChanges ( binding : ActivityPluginBinding ) {
51+ activity = binding.activity
52+ }
4953
50- override fun onReattachedToActivityForConfigChanges ( binding : ActivityPluginBinding ) {
51- activity = binding.activity
52- }
54+ override fun onDetachedFromActivity ( ) {
55+ activity = null
56+ }
5357
54- override fun onDetachedFromActivity () {
55- activity = null
56- }
58+ private var clientId: String = " "
59+ private var flowId: String? = null
60+ private var metadata: Map <String , Any >? = null
61+ private var encryptionConfigurationId: String? = null
62+ private var configurationId: String? = null
5763
58- private var clientId: String = " "
59- private var flowId: String? = null
60- private var metadata: Map <String , Any >? = null
61- private var encryptionConfigurationId: String? = null
62- private var configurationId: String? = null
64+ override fun onMethodCall (@NonNull call : MethodCall , @NonNull result : Result ) {
65+ when (call.method) {
66+ " showMatiFlow" -> {
67+ clientId = call.argument(" clientId" )!!
68+ flowId = call.argument(" flowId" )
69+ metadata = call.argument(" metadata" )
70+ encryptionConfigurationId = call.argument(" encryptionConfigurationId" )
71+ configurationId = call.argument(" configurationId" )
6372
64- override fun onMethodCall (@NonNull call : MethodCall , @NonNull result : Result ) {
65- when (call.method) {
66- " showMatiFlow" -> {
67- clientId = call.argument(" clientId" )!!
68- flowId = call.argument(" flowId" )
69- metadata = call.argument(" metadata" )
70- encryptionConfigurationId = call.argument(" encryptionConfigurationId" )
71- configurationId = call.argument(" configurationId" )
73+ activity?.let { activity ->
74+ val metadataBuilder = Metadata .Builder ().apply {
75+ metadata?.entries?.forEach {
76+ this .with (
77+ it.key, if (it.key in arrayOf(" buttonColor" , " buttonTextColor" )) {
78+ Color .parseColor(it.value as String )
79+ } else {
80+ it.value
81+ }
82+ )
83+ }
84+ }
7285
73- activity?.let { activity ->
74- val metadata = Metadata .Builder ().apply {
75- metadata?.entries?.forEach {
76- this .with (
77- it.key, if (it.key in arrayOf(" buttonColor" , " buttonTextColor" )) {
78- Color .parseColor(it.value as String )
79- } else {
80- it.value
81- }
82- )
86+ MetamapSdk .startFlow(
87+ activity = activity,
88+ clientId = clientId,
89+ flowId = flowId,
90+ metadata = metadataBuilder.build(),
91+ requestCode = 2576 ,
92+ configurationId = configurationId,
93+ encryptionConfigurationId = encryptionConfigurationId,
94+ verificationStarted = { identityId, verificationId ->
95+ val resultData = " ${verificationId.orEmpty()} ${identityId.orEmpty()} "
96+ Handler (Looper .getMainLooper()).post {
97+ channel.invokeMethod(" created" , resultData)
98+ }
99+ }
100+ )
101+ result.success(" showMatiFlow ${android.os.Build .VERSION .RELEASE } " )
102+ } ? : result.error(" NO_ACTIVITY" , " Activity is null" , null )
83103 }
84- }
85- MetamapSdk .startFlow(
86- activity,
87- clientId,
88- flowId,
89- metadata.build(),
90- 2576 ,
91- configurationId,
92- encryptionConfigurationId
93- )
94- result.success(" showMatiFlow ${android.os.Build .VERSION .RELEASE } " )
104+
105+ else -> result.notImplemented()
95106 }
96- }
97- else -> result.notImplemented()
98107 }
99- }
100108
101- override fun onDetachedFromEngine (@NonNull binding : FlutterPlugin .FlutterPluginBinding ) {
102- channel.setMethodCallHandler(null )
103- }
109+ override fun onDetachedFromEngine (@NonNull binding : FlutterPlugin .FlutterPluginBinding ) {
110+ channel.setMethodCallHandler(null )
111+ }
104112}
0 commit comments