assentify-sdk-react-native 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +65 -0
  3. package/android/build.gradle +111 -0
  4. package/android/gradle.properties +9 -0
  5. package/android/src/main/AndroidManifest.xml +55 -0
  6. package/android/src/main/java/com/assentifysdk/AndroidProgressBarModule.kt +33 -0
  7. package/android/src/main/java/com/assentifysdk/AssentifySdkBaseModule.kt +39 -0
  8. package/android/src/main/java/com/assentifysdk/AssentifySdkModule.kt +432 -0
  9. package/android/src/main/java/com/assentifysdk/AssentifySdkPackage.kt +19 -0
  10. package/android/src/main/java/com/assentifysdk/FaceMatchActivity.kt +309 -0
  11. package/android/src/main/java/com/assentifysdk/ImageToBase64Converter.kt +40 -0
  12. package/android/src/main/java/com/assentifysdk/ReactApplicationContextObject.kt +14 -0
  13. package/android/src/main/java/com/assentifysdk/ScanIDActivity.kt +431 -0
  14. package/android/src/main/java/com/assentifysdk/ScanOtherActivity.kt +328 -0
  15. package/android/src/main/java/com/assentifysdk/ScanPassportActivity.kt +364 -0
  16. package/android/src/main/java/com/assentifysdk/StepsKeys.kt +91 -0
  17. package/android/src/main/res/drawable/back_icon.png +0 -0
  18. package/android/src/main/res/drawable/button_rounded_background.xml +6 -0
  19. package/android/src/main/res/drawable/card.gif +0 -0
  20. package/android/src/main/res/drawable/expire.png +0 -0
  21. package/android/src/main/res/drawable/id.gif +0 -0
  22. package/android/src/main/res/drawable/id_warning.png +0 -0
  23. package/android/src/main/res/drawable/info_icon.png +0 -0
  24. package/android/src/main/res/drawable/info_rounded_background.xml +6 -0
  25. package/android/src/main/res/drawable/passport.gif +0 -0
  26. package/android/src/main/res/drawable/rounded_background.xml +3 -0
  27. package/android/src/main/res/drawable/sending.png +0 -0
  28. package/android/src/main/res/drawable/warning.png +0 -0
  29. package/android/src/main/res/drawable/zoom_in.png +0 -0
  30. package/android/src/main/res/drawable/zoom_out.png +0 -0
  31. package/android/src/main/res/layout/activity_face_scan.xml +242 -0
  32. package/android/src/main/res/layout/activity_scan.xml +297 -0
  33. package/android/src/main/res/raw/sending_video.MP4 +0 -0
  34. package/android/src/main/res/values/colors.xml +8 -0
  35. package/android/src/main/res/values/strings.xml +3 -0
  36. package/android/src/main/res/values/styles.xml +4 -0
  37. package/assentify-sdk.podspec +43 -0
  38. package/ios/AssentifySdkBaseModule.swift +15 -0
  39. package/ios/Info.plist +27 -0
  40. package/ios/NativeAssentifySdk-Bridging-Header.h +3 -0
  41. package/ios/NativeAssentifySdk.mm +45 -0
  42. package/ios/NativeAssentifySdk.swift +460 -0
  43. package/ios/Resources/card.gif +0 -0
  44. package/ios/Resources/expire.png +0 -0
  45. package/ios/Resources/id.gif +0 -0
  46. package/ios/Resources/id_warning.png +0 -0
  47. package/ios/Resources/info_icon.png +0 -0
  48. package/ios/Resources/passport.gif +0 -0
  49. package/ios/Resources/sending.png +0 -0
  50. package/ios/Resources/warning.png +0 -0
  51. package/ios/Resources/zoom_in.png +0 -0
  52. package/ios/Resources/zoom_out.png +0 -0
  53. package/ios/UIComponents/RNIOSProgressBar.h +4 -0
  54. package/ios/UIComponents/RNIOSProgressBar.m +34 -0
  55. package/ios/UIComponents/RNPassportScanner.m +26 -0
  56. package/ios/UIComponents/RNPassportScanner.swift +245 -0
  57. package/ios/UIComponents/RNTMapManager.h +4 -0
  58. package/ios/UIComponents/RNTMapManager.m +19 -0
  59. package/ios/View/DataDecoder.swift +469 -0
  60. package/ios/View/FaceMatchController.swift +258 -0
  61. package/ios/View/IDCardController.swift +360 -0
  62. package/ios/View/OtherController.swift +283 -0
  63. package/ios/View/PassportController.swift +302 -0
  64. package/ios/View/UI.swift +298 -0
  65. package/lib/commonjs/AssentifyProvider.js +202 -0
  66. package/lib/commonjs/AssentifyProvider.js.map +1 -0
  67. package/lib/commonjs/AssentifyWrapper.js +76 -0
  68. package/lib/commonjs/AssentifyWrapper.js.map +1 -0
  69. package/lib/commonjs/Language.js +27 -0
  70. package/lib/commonjs/Language.js.map +1 -0
  71. package/lib/commonjs/helpers/index.js +2 -0
  72. package/lib/commonjs/helpers/index.js.map +1 -0
  73. package/lib/commonjs/helpers/parsers/FaceMatchParser.js +27 -0
  74. package/lib/commonjs/helpers/parsers/FaceMatchParser.js.map +1 -0
  75. package/lib/commonjs/helpers/parsers/IDCardParser.js +25 -0
  76. package/lib/commonjs/helpers/parsers/IDCardParser.js.map +1 -0
  77. package/lib/commonjs/helpers/parsers/OtherIDParser.js +29 -0
  78. package/lib/commonjs/helpers/parsers/OtherIDParser.js.map +1 -0
  79. package/lib/commonjs/helpers/parsers/PassportParser.js +25 -0
  80. package/lib/commonjs/helpers/parsers/PassportParser.js.map +1 -0
  81. package/lib/commonjs/index.js +49 -0
  82. package/lib/commonjs/index.js.map +1 -0
  83. package/lib/commonjs/types.js +42 -0
  84. package/lib/commonjs/types.js.map +1 -0
  85. package/lib/module/AssentifyProvider.js +193 -0
  86. package/lib/module/AssentifyProvider.js.map +1 -0
  87. package/lib/module/AssentifyWrapper.js +70 -0
  88. package/lib/module/AssentifyWrapper.js.map +1 -0
  89. package/lib/module/Language.js +21 -0
  90. package/lib/module/Language.js.map +1 -0
  91. package/lib/module/helpers/index.js +2 -0
  92. package/lib/module/helpers/index.js.map +1 -0
  93. package/lib/module/helpers/parsers/FaceMatchParser.js +21 -0
  94. package/lib/module/helpers/parsers/FaceMatchParser.js.map +1 -0
  95. package/lib/module/helpers/parsers/IDCardParser.js +19 -0
  96. package/lib/module/helpers/parsers/IDCardParser.js.map +1 -0
  97. package/lib/module/helpers/parsers/OtherIDParser.js +23 -0
  98. package/lib/module/helpers/parsers/OtherIDParser.js.map +1 -0
  99. package/lib/module/helpers/parsers/PassportParser.js +19 -0
  100. package/lib/module/helpers/parsers/PassportParser.js.map +1 -0
  101. package/lib/module/index.js +6 -0
  102. package/lib/module/index.js.map +1 -0
  103. package/lib/module/types.js +36 -0
  104. package/lib/module/types.js.map +1 -0
  105. package/lib/typescript/babel.config.d.ts +3 -0
  106. package/lib/typescript/babel.config.d.ts.map +1 -0
  107. package/lib/typescript/commitlint.config.d.ts +7 -0
  108. package/lib/typescript/commitlint.config.d.ts.map +1 -0
  109. package/lib/typescript/example/babel.config.d.ts +8 -0
  110. package/lib/typescript/example/babel.config.d.ts.map +1 -0
  111. package/lib/typescript/example/index.d.ts +2 -0
  112. package/lib/typescript/example/index.d.ts.map +1 -0
  113. package/lib/typescript/example/jest.config.d.ts +2 -0
  114. package/lib/typescript/example/jest.config.d.ts.map +1 -0
  115. package/lib/typescript/example/metro.config.d.ts +3 -0
  116. package/lib/typescript/example/metro.config.d.ts.map +1 -0
  117. package/lib/typescript/example/react-native.config.d.ts +6 -0
  118. package/lib/typescript/example/react-native.config.d.ts.map +1 -0
  119. package/lib/typescript/example/src/App.d.ts +3 -0
  120. package/lib/typescript/example/src/App.d.ts.map +1 -0
  121. package/lib/typescript/example/src/Home.d.ts +4 -0
  122. package/lib/typescript/example/src/Home.d.ts.map +1 -0
  123. package/lib/typescript/example/src/navigator.d.ts +4 -0
  124. package/lib/typescript/example/src/navigator.d.ts.map +1 -0
  125. package/lib/typescript/lib/commonjs/AssentifyProvider.d.ts +3 -0
  126. package/lib/typescript/lib/commonjs/AssentifyProvider.d.ts.map +1 -0
  127. package/lib/typescript/lib/commonjs/AssentifyWrapper.d.ts +11 -0
  128. package/lib/typescript/lib/commonjs/AssentifyWrapper.d.ts.map +1 -0
  129. package/lib/typescript/lib/commonjs/Language.d.ts +22 -0
  130. package/lib/typescript/lib/commonjs/Language.d.ts.map +1 -0
  131. package/lib/typescript/lib/commonjs/helpers/index.d.ts +1 -0
  132. package/lib/typescript/lib/commonjs/helpers/index.d.ts.map +1 -0
  133. package/lib/typescript/lib/commonjs/helpers/parsers/FaceMatchParser.d.ts +12 -0
  134. package/lib/typescript/lib/commonjs/helpers/parsers/FaceMatchParser.d.ts.map +1 -0
  135. package/lib/typescript/lib/commonjs/helpers/parsers/IDCardParser.d.ts +11 -0
  136. package/lib/typescript/lib/commonjs/helpers/parsers/IDCardParser.d.ts.map +1 -0
  137. package/lib/typescript/lib/commonjs/helpers/parsers/OtherIDParser.d.ts +13 -0
  138. package/lib/typescript/lib/commonjs/helpers/parsers/OtherIDParser.d.ts.map +1 -0
  139. package/lib/typescript/lib/commonjs/helpers/parsers/PassportParser.d.ts +11 -0
  140. package/lib/typescript/lib/commonjs/helpers/parsers/PassportParser.d.ts.map +1 -0
  141. package/lib/typescript/lib/commonjs/index.d.ts +2 -0
  142. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -0
  143. package/lib/typescript/lib/commonjs/types.d.ts +18 -0
  144. package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
  145. package/lib/typescript/lib/module/AssentifyProvider.d.ts +3 -0
  146. package/lib/typescript/lib/module/AssentifyProvider.d.ts.map +1 -0
  147. package/lib/typescript/lib/module/AssentifyWrapper.d.ts +10 -0
  148. package/lib/typescript/lib/module/AssentifyWrapper.d.ts.map +1 -0
  149. package/lib/typescript/lib/module/Language.d.ts +21 -0
  150. package/lib/typescript/lib/module/Language.d.ts.map +1 -0
  151. package/lib/typescript/lib/module/helpers/index.d.ts +1 -0
  152. package/lib/typescript/lib/module/helpers/index.d.ts.map +1 -0
  153. package/lib/typescript/lib/module/helpers/parsers/FaceMatchParser.d.ts +11 -0
  154. package/lib/typescript/lib/module/helpers/parsers/FaceMatchParser.d.ts.map +1 -0
  155. package/lib/typescript/lib/module/helpers/parsers/IDCardParser.d.ts +10 -0
  156. package/lib/typescript/lib/module/helpers/parsers/IDCardParser.d.ts.map +1 -0
  157. package/lib/typescript/lib/module/helpers/parsers/OtherIDParser.d.ts +12 -0
  158. package/lib/typescript/lib/module/helpers/parsers/OtherIDParser.d.ts.map +1 -0
  159. package/lib/typescript/lib/module/helpers/parsers/PassportParser.d.ts +10 -0
  160. package/lib/typescript/lib/module/helpers/parsers/PassportParser.d.ts.map +1 -0
  161. package/lib/typescript/lib/module/index.d.ts +12 -0
  162. package/lib/typescript/lib/module/index.d.ts.map +1 -0
  163. package/lib/typescript/lib/module/types.d.ts +17 -0
  164. package/lib/typescript/lib/module/types.d.ts.map +1 -0
  165. package/lib/typescript/src/AssentifyProvider.d.ts +4 -0
  166. package/lib/typescript/src/AssentifyProvider.d.ts.map +1 -0
  167. package/lib/typescript/src/AssentifyWrapper.d.ts +12 -0
  168. package/lib/typescript/src/AssentifyWrapper.d.ts.map +1 -0
  169. package/lib/typescript/src/Language.d.ts +22 -0
  170. package/lib/typescript/src/Language.d.ts.map +1 -0
  171. package/lib/typescript/src/helpers/index.d.ts +1 -0
  172. package/lib/typescript/src/helpers/index.d.ts.map +1 -0
  173. package/lib/typescript/src/helpers/parsers/FaceMatchParser.d.ts +4 -0
  174. package/lib/typescript/src/helpers/parsers/FaceMatchParser.d.ts.map +1 -0
  175. package/lib/typescript/src/helpers/parsers/IDCardParser.d.ts +4 -0
  176. package/lib/typescript/src/helpers/parsers/IDCardParser.d.ts.map +1 -0
  177. package/lib/typescript/src/helpers/parsers/OtherIDParser.d.ts +4 -0
  178. package/lib/typescript/src/helpers/parsers/OtherIDParser.d.ts.map +1 -0
  179. package/lib/typescript/src/helpers/parsers/PassportParser.d.ts +4 -0
  180. package/lib/typescript/src/helpers/parsers/PassportParser.d.ts.map +1 -0
  181. package/lib/typescript/src/index.d.ts +12 -0
  182. package/lib/typescript/src/index.d.ts.map +1 -0
  183. package/lib/typescript/src/types.d.ts +308 -0
  184. package/lib/typescript/src/types.d.ts.map +1 -0
  185. package/package.json +201 -0
  186. package/src/AssentifyProvider.tsx +189 -0
  187. package/src/AssentifyWrapper.ts +142 -0
  188. package/src/Language.ts +22 -0
  189. package/src/helpers/index.ts +1 -0
  190. package/src/helpers/parsers/FaceMatchParser.ts +28 -0
  191. package/src/helpers/parsers/IDCardParser.ts +27 -0
  192. package/src/helpers/parsers/OtherIDParser.ts +31 -0
  193. package/src/helpers/parsers/PassportParser.ts +27 -0
  194. package/src/index.ts +6 -0
  195. package/src/types.ts +373 -0
@@ -0,0 +1,328 @@
1
+ package com.assentifysdk
2
+
3
+ import com.assentify.sdk.AssentifySdk
4
+ import com.assentify.sdk.RemoteClient.Models.SubmitRequestModel
5
+ import android.content.Context
6
+ import android.content.Intent
7
+ import androidx.appcompat.app.AppCompatActivity
8
+ import android.os.Bundle
9
+ import com.facebook.react.bridge.Arguments
10
+ import com.facebook.react.bridge.ReactApplicationContext
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule
12
+ import com.assentify.sdk.Core.Constants.MotionType
13
+ import com.assentify.sdk.Core.Constants.ZoomType
14
+ import ImageToBase64Converter
15
+ import android.widget.TextView
16
+ import androidx.appcompat.widget.Toolbar
17
+ import com.google.gson.Gson
18
+ import com.google.gson.reflect.TypeToken
19
+ import com.assentify.sdk.RemoteClient.Models.StepDefinitions
20
+ import com.assentify.sdk.Models.BaseResponseDataModel
21
+ import com.assentify.sdk.ScanOther.OtherResponseModel
22
+ import com.assentify.sdk.ScanOther.ScanOtherCallback
23
+ import com.assentify.sdk.AssentifySdkObject
24
+ import com.assentify.sdk.ScanOther.ScanOther
25
+ import android.view.View
26
+ import android.widget.Button
27
+ import android.widget.ImageView
28
+ import java.time.LocalDate
29
+ import java.time.format.DateTimeFormatter
30
+ import java.util.Date
31
+ import android.graphics.Color
32
+ import android.graphics.PorterDuff
33
+ import android.widget.LinearLayout
34
+ import android.widget.RelativeLayout
35
+ import java.text.SimpleDateFormat
36
+
37
+
38
+
39
+ class ScanOtherActivity: AppCompatActivity(),
40
+ ScanOtherCallback {
41
+ private lateinit var reactApplicationContext: ReactApplicationContext
42
+ private lateinit var assentifySdk: AssentifySdk
43
+ private lateinit var scanOther: ScanOther
44
+ private lateinit var infoText: TextView
45
+ private lateinit var infoIcon: ImageView
46
+ private lateinit var infoLayout: LinearLayout
47
+ private lateinit var popUpContainer: LinearLayout
48
+ private lateinit var popUpIcon: ImageView
49
+ private lateinit var popUpText: TextView
50
+ private lateinit var popUpSubText: TextView
51
+ private lateinit var idGif: LinearLayout
52
+
53
+ private lateinit var holdHandColor: String;
54
+ private lateinit var processingColor: String;
55
+ private lateinit var language: String;
56
+ private lateinit var popUpButton: Button
57
+ private var start: Boolean = false;
58
+ private var showCountDown: Boolean = true;
59
+ private var apiKey: String = "";
60
+ override fun onCreate(savedInstanceState: Bundle?) {
61
+ super.onCreate(savedInstanceState)
62
+ setContentView(R.layout.activity_scan)
63
+ reactApplicationContext = ReactApplicationContextObject.getReactApplicationContextObject()
64
+ holdHandColor = intent.getStringExtra("holdHandColor")!!
65
+ processingColor = intent.getStringExtra("processingColor")!!
66
+ language = intent.getStringExtra("language")!!
67
+ apiKey = intent.getStringExtra("apiKey")!!
68
+ showCountDown = intent.getBooleanExtra("showCountDown",true)
69
+ startAssentifySdk()
70
+
71
+
72
+
73
+ val backButton = findViewById<RelativeLayout>(R.id.backButton)
74
+ val drawable = getResources().getDrawable(R.drawable.rounded_background)
75
+ drawable?.setColorFilter(Color.parseColor(holdHandColor), PorterDuff.Mode.SRC_ATOP)
76
+ backButton.setBackground(drawable)
77
+
78
+ backButton.setOnClickListener {
79
+ runOnUiThread {
80
+ triggerEvent("onBackClick", null)
81
+ scanOther.stopScanning();
82
+ finish()
83
+ }
84
+ }
85
+
86
+
87
+ infoLayout = findViewById<LinearLayout>(R.id.infoLayout)
88
+ val drawableInfo = getResources().getDrawable(R.drawable.info_rounded_background)
89
+ drawableInfo?.setColorFilter(Color.parseColor(holdHandColor), PorterDuff.Mode.SRC_ATOP)
90
+ infoLayout.setBackground(drawableInfo)
91
+
92
+
93
+ val toolbarTitle = findViewById<TextView>(R.id.toolbar_title)
94
+ toolbarTitle.setText("ID Capture")
95
+ toolbarTitle.setTextColor(Color.parseColor(processingColor))
96
+
97
+
98
+ infoText = findViewById(R.id.infoText)
99
+ infoText.setText("Please present ID")
100
+ infoText.setTextColor(Color.parseColor(processingColor))
101
+
102
+ infoIcon = findViewById<ImageView>(R.id.info_icon)
103
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
104
+
105
+
106
+
107
+ popUpContainer = findViewById<LinearLayout>(R.id.popUpContainer)
108
+ val drawablePopUpContainer = getResources().getDrawable(R.drawable.info_rounded_background)
109
+ drawablePopUpContainer?.setColorFilter(
110
+ Color.parseColor(holdHandColor),
111
+ PorterDuff.Mode.SRC_ATOP
112
+ )
113
+ popUpContainer.setBackground(drawablePopUpContainer)
114
+ popUpContainer.visibility = View.GONE
115
+ popUpContainer.setOnClickListener {
116
+ if(!start){
117
+ popUpContainer.visibility = View.GONE
118
+ }
119
+ }
120
+ }
121
+
122
+
123
+ fun showPopUpMessage(icon: Int, title: String, subTitle: String, isSending: Boolean) {
124
+ popUpContainer.visibility = View.VISIBLE
125
+
126
+ popUpIcon = findViewById<ImageView>(R.id.popUpIcon)
127
+ popUpIcon.setImageDrawable(getResources().getDrawable(icon))
128
+
129
+ idGif = findViewById<LinearLayout>(R.id.idGif)
130
+
131
+ popUpText = findViewById(R.id.popUpText)
132
+ popUpText.setText(title)
133
+ popUpText.setTextColor(Color.parseColor(processingColor))
134
+
135
+ popUpSubText = findViewById(R.id.popUpSubText)
136
+ popUpSubText.setText(subTitle)
137
+ popUpSubText.setTextColor(Color.parseColor(processingColor))
138
+
139
+ val drawablePopUpButton = getResources().getDrawable(R.drawable.button_rounded_background)
140
+ drawablePopUpButton?.setColorFilter(Color.parseColor(processingColor), PorterDuff.Mode.SRC_ATOP)
141
+ popUpButton= findViewById(R.id.popUpButton)
142
+ popUpButton.setBackground(drawablePopUpButton)
143
+ popUpButton.setTextColor(Color.parseColor(holdHandColor))
144
+
145
+ popUpButton.setOnClickListener {
146
+ if(!start){
147
+ popUpContainer.visibility = View.GONE
148
+ }
149
+ }
150
+
151
+ idGif.visibility = View.GONE
152
+ popUpIcon.visibility = View.GONE
153
+ popUpSubText.visibility = View.GONE
154
+ popUpButton.visibility = View.GONE
155
+
156
+
157
+ if (isSending) {
158
+ idGif.visibility = View.VISIBLE
159
+ } else {
160
+ popUpIcon.visibility = View.VISIBLE
161
+ popUpSubText.visibility = View.VISIBLE
162
+ popUpButton.visibility = View.VISIBLE
163
+ }
164
+
165
+
166
+ }
167
+
168
+ fun hidePopUpMessage() {
169
+ popUpContainer.visibility = View.GONE
170
+ }
171
+
172
+ fun startAssentifySdk() {
173
+ assentifySdk = AssentifySdkObject.getAssentifySdkObject();
174
+ scanOther = assentifySdk!!.startScanOther(
175
+ this@ScanOtherActivity,
176
+ language
177
+ );
178
+ Thread.sleep(500);
179
+ var fragmentManager = supportFragmentManager
180
+ var transaction = fragmentManager.beginTransaction()
181
+ transaction.replace(R.id.fragmentContainer, scanOther)
182
+ transaction.commit()
183
+
184
+ }
185
+
186
+ override fun onError(dataModel: BaseResponseDataModel) {
187
+ triggerEvent("onError", dataModel)
188
+ runOnUiThread {
189
+ start = false;
190
+ showPopUpMessage(R.drawable.warning, "Unable to extract", "Let's try again", false)
191
+ }
192
+ }
193
+
194
+ override fun onSend() {
195
+ triggerEvent("onSend", null)
196
+ runOnUiThread {
197
+ start = true;
198
+ runOnUiThread {
199
+ showPopUpMessage(R.drawable.sending, "Transmitting", "Transmitting", true)
200
+ }
201
+ }
202
+ }
203
+
204
+ override fun onRetry(dataModel: BaseResponseDataModel) {
205
+ triggerEvent("onRetry", dataModel)
206
+ runOnUiThread {
207
+ start = false;
208
+ showPopUpMessage(R.drawable.warning, "Unable to extract", "Let's try again", false)
209
+ }
210
+ }
211
+
212
+
213
+
214
+ override fun onComplete(dataModel: OtherResponseModel) {
215
+ triggerCompleteEvent("onComplete",dataModel)
216
+ /** Steps **/
217
+ val sharedStepDefinitions =
218
+ reactApplicationContext.getSharedPreferences("StepDefinitions", Context.MODE_PRIVATE)
219
+ val gson = Gson()
220
+ val json: String = sharedStepDefinitions.getString("Steps", "")!!
221
+ val steps: List<StepDefinitions>? =
222
+ gson.fromJson(json, object : TypeToken<List<StepDefinitions>>() {}.type)
223
+ steps!!.forEach { item ->
224
+ if (item.stepDefinition == StepsName.DocumentCapture) {
225
+ val documentCaptureModel = SubmitRequestModel(
226
+ item.stepId, StepsName.DocumentCapture,
227
+ convertMap(dataModel.otherExtractedModel!!.transformedProperties)
228
+ );
229
+ val documentCaptureSharedPreferences = reactApplicationContext.getSharedPreferences("DocumentCaptureStepModel", Context.MODE_PRIVATE)
230
+ val documentCaptureSharedPreferencesEditor = documentCaptureSharedPreferences.edit()
231
+ val documentCaptureGson = Gson()
232
+ val documentCaptureStep: String = documentCaptureGson.toJson(documentCaptureModel)
233
+ documentCaptureSharedPreferencesEditor.putString("DocumentCaptureStep", documentCaptureStep);
234
+ documentCaptureSharedPreferencesEditor.apply()
235
+ }
236
+ }
237
+ /** End **/
238
+ runOnUiThread {
239
+ scanOther.stopScanning();
240
+ finish()
241
+ }
242
+
243
+ /* var base64Image = ImageToBase64Converter(apiKey).execute(dataModel.otherExtractedModel!!.imageUrl).get()
244
+ val sharedPreferences =
245
+ reactApplicationContext.getSharedPreferences("FaceMatch", Context.MODE_PRIVATE)
246
+ val editor = sharedPreferences.edit()
247
+ editor.putString("Base64SecondImage", base64Image)
248
+ editor.apply()
249
+ val intent = Intent(reactApplicationContext, FaceMatchActivity::class.java)
250
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
251
+ intent.putExtra("holdHandColor", holdHandColor)
252
+ intent.putExtra("processingColor", processingColor)
253
+ intent.putExtra("showCountDown", showCountDown)
254
+ reactApplicationContext?.startActivity(intent)*/
255
+
256
+ }
257
+
258
+ override fun onEnvironmentalConditionsChange(
259
+ brightness: Double,
260
+ motion: MotionType,
261
+ zoomType: ZoomType
262
+ ) {
263
+ runOnUiThread {
264
+ if (start == false) {
265
+ infoLayout.visibility = View.VISIBLE
266
+ if (zoomType != ZoomType.SENDING && zoomType != ZoomType.NO_DETECT) {
267
+ if (zoomType == ZoomType.ZOOM_IN) {
268
+ infoText.setText("Move ID Closer")
269
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.zoom_in))
270
+ }
271
+ if (zoomType == ZoomType.ZOOM_OUT) {
272
+ infoText.setText("Move ID Further")
273
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.zoom_out))
274
+ }
275
+ } else if (motion == MotionType.HOLD_YOUR_HAND) {
276
+ infoText.setText("Please Hold Your Hand")
277
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
278
+ } else {
279
+ if (motion == MotionType.SENDING && zoomType == ZoomType.SENDING) {
280
+ infoText.setText("Hold Steady")
281
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
282
+ }
283
+ if (motion == MotionType.NO_DETECT && zoomType == ZoomType.NO_DETECT) {
284
+ infoText.setText("Please present ID")
285
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
286
+ }
287
+
288
+ }
289
+ } else {
290
+ infoLayout.visibility = View.GONE
291
+ }
292
+
293
+
294
+ }
295
+ }
296
+
297
+
298
+ fun convertMap(map: Map<String, Any>?): Map<String, String> {
299
+ return map?.mapValues {
300
+ it.value.toString()
301
+ } ?: emptyMap()
302
+ }
303
+
304
+ private fun triggerCompleteEvent(eventName:String, dataModel: OtherResponseModel?){
305
+ val eventResultMap = Arguments.createMap().apply {
306
+ if(dataModel!=null){
307
+ val gson = Gson()
308
+ val jsonString = gson.toJson(dataModel.otherExtractedModel!!)
309
+ putString("OtherDataModel", jsonString)
310
+ }
311
+ }
312
+ reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
313
+ .emit(eventName, eventResultMap)
314
+
315
+ }
316
+
317
+ private fun triggerEvent(eventName:String, dataModel: BaseResponseDataModel?){
318
+ val eventResultMap = Arguments.createMap().apply {
319
+ if(dataModel!=null){
320
+ putString("OtherDataModel", dataModel.response)
321
+ }
322
+ }
323
+ reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
324
+ .emit(eventName, eventResultMap)
325
+
326
+ }
327
+
328
+ }
@@ -0,0 +1,364 @@
1
+ package com.assentifysdk
2
+
3
+ import com.assentify.sdk.AssentifySdk
4
+ import com.assentify.sdk.RemoteClient.Models.SubmitRequestModel
5
+ import android.content.Context
6
+ import android.content.Intent
7
+ import androidx.appcompat.app.AppCompatActivity
8
+ import android.os.Bundle
9
+ import com.facebook.react.bridge.Arguments
10
+ import com.facebook.react.bridge.ReactApplicationContext
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule
12
+ import com.assentify.sdk.Core.Constants.MotionType
13
+ import com.assentify.sdk.Core.Constants.ZoomType
14
+ import ImageToBase64Converter
15
+ import android.widget.TextView
16
+ import androidx.appcompat.widget.Toolbar
17
+ import com.google.gson.Gson
18
+ import com.google.gson.reflect.TypeToken
19
+ import com.assentify.sdk.RemoteClient.Models.StepDefinitions
20
+ import com.assentify.sdk.Models.BaseResponseDataModel
21
+ import com.assentify.sdk.ScanPassport.PassportResponseModel
22
+ import com.assentify.sdk.ScanPassport.ScanPassportCallback
23
+ import com.assentify.sdk.AssentifySdkObject
24
+ import com.assentify.sdk.ScanPassport.ScanPassport
25
+ import android.view.View
26
+ import android.widget.Button
27
+ import android.widget.ImageView
28
+ import java.time.LocalDate
29
+ import java.time.format.DateTimeFormatter
30
+ import java.util.Date
31
+ import android.graphics.Color
32
+ import android.graphics.PorterDuff
33
+ import android.widget.LinearLayout
34
+ import android.widget.RelativeLayout
35
+ import java.text.SimpleDateFormat
36
+ import android.util.Log
37
+ class ScanPassportActivity : AppCompatActivity(),
38
+ ScanPassportCallback {
39
+ private lateinit var assentifySdk: AssentifySdk
40
+ private lateinit var reactApplicationContext: ReactApplicationContext
41
+ private lateinit var scanPassport: ScanPassport
42
+ private lateinit var infoText: TextView
43
+ private lateinit var infoIcon: ImageView
44
+ private lateinit var infoLayout: LinearLayout
45
+ private lateinit var popUpContainer: LinearLayout
46
+ private lateinit var popUpIcon: ImageView
47
+ private lateinit var popUpText: TextView
48
+ private lateinit var popUpSubText: TextView
49
+ private lateinit var passportGif: LinearLayout
50
+ private lateinit var popUpButton: Button
51
+
52
+ private lateinit var holdHandColor: String;
53
+ private lateinit var processingColor: String;
54
+ private lateinit var language: String;
55
+ private var showCountDown: Boolean = true;
56
+ private var start: Boolean = false;
57
+ private var isDone: Boolean = false;
58
+ private var apiKey: String = "";
59
+
60
+ override fun onCreate(savedInstanceState: Bundle?) {
61
+ super.onCreate(savedInstanceState)
62
+ setContentView(R.layout.activity_scan)
63
+ reactApplicationContext = ReactApplicationContextObject.getReactApplicationContextObject()
64
+ holdHandColor = intent.getStringExtra("holdHandColor")!!
65
+ processingColor = intent.getStringExtra("processingColor")!!
66
+ language = intent.getStringExtra("language")!!
67
+ apiKey = intent.getStringExtra("apiKey")!!
68
+ showCountDown = intent.getBooleanExtra("showCountDown",true)
69
+
70
+ startAssentifySdk()
71
+
72
+ val backButton = findViewById<RelativeLayout>(R.id.backButton)
73
+ val drawable = getResources().getDrawable(R.drawable.rounded_background)
74
+ drawable?.setColorFilter(Color.parseColor(holdHandColor), PorterDuff.Mode.SRC_ATOP)
75
+ backButton.setBackground(drawable)
76
+
77
+ backButton.setOnClickListener {
78
+ runOnUiThread {
79
+ triggerEvent("onBackClick", null)
80
+ scanPassport.stopScanning();
81
+ finish()
82
+ }
83
+ }
84
+
85
+
86
+ infoLayout = findViewById<LinearLayout>(R.id.infoLayout)
87
+ val drawableInfo = getResources().getDrawable(R.drawable.info_rounded_background)
88
+ drawableInfo?.setColorFilter(Color.parseColor(holdHandColor), PorterDuff.Mode.SRC_ATOP)
89
+ infoLayout.setBackground(drawableInfo)
90
+
91
+
92
+ val toolbarTitle = findViewById<TextView>(R.id.toolbar_title)
93
+ toolbarTitle.setText("Passport Capture")
94
+ toolbarTitle.setTextColor(Color.parseColor(processingColor))
95
+
96
+
97
+ infoText = findViewById(R.id.infoText)
98
+ infoText.setText("Please present passport")
99
+ infoText.setTextColor(Color.parseColor(processingColor))
100
+
101
+ infoIcon = findViewById<ImageView>(R.id.info_icon)
102
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
103
+
104
+
105
+
106
+ popUpContainer = findViewById<LinearLayout>(R.id.popUpContainer)
107
+ val drawablePopUpContainer = getResources().getDrawable(R.drawable.info_rounded_background)
108
+ drawablePopUpContainer?.setColorFilter(
109
+ Color.parseColor(holdHandColor),
110
+ PorterDuff.Mode.SRC_ATOP
111
+ )
112
+ popUpContainer.setBackground(drawablePopUpContainer)
113
+ popUpContainer.visibility = View.GONE
114
+ popUpContainer.setOnClickListener {
115
+ if (!start) {
116
+ popUpContainer.visibility = View.GONE
117
+ }
118
+ }
119
+
120
+ }
121
+
122
+ fun showPopUpMessage(icon: Int, title: String, subTitle: String, isSending: Boolean) {
123
+ popUpContainer.visibility = View.VISIBLE
124
+
125
+ popUpIcon = findViewById<ImageView>(R.id.popUpIcon)
126
+ popUpIcon.setImageDrawable(getResources().getDrawable(icon))
127
+
128
+ passportGif = findViewById<LinearLayout>(R.id.passportGif)
129
+
130
+ popUpText = findViewById(R.id.popUpText)
131
+ popUpText.setText(title)
132
+ popUpText.setTextColor(Color.parseColor(processingColor))
133
+
134
+ popUpSubText = findViewById(R.id.popUpSubText)
135
+ popUpSubText.setTextColor(Color.parseColor(processingColor))
136
+
137
+
138
+ val drawablePopUpButton = getResources().getDrawable(R.drawable.button_rounded_background)
139
+ drawablePopUpButton?.setColorFilter(Color.parseColor(processingColor), PorterDuff.Mode.SRC_ATOP)
140
+ popUpButton = findViewById(R.id.popUpButton)
141
+ popUpButton.setBackground(drawablePopUpButton)
142
+ popUpButton.setTextColor(Color.parseColor(holdHandColor))
143
+
144
+ popUpButton.setOnClickListener {
145
+ if (!start) {
146
+ popUpContainer.visibility = View.GONE
147
+ }
148
+ }
149
+
150
+ passportGif.visibility = View.GONE
151
+ popUpIcon.visibility = View.GONE
152
+ popUpSubText.visibility = View.GONE
153
+ popUpButton.visibility = View.GONE
154
+
155
+ if (isSending) {
156
+ passportGif.visibility = View.VISIBLE
157
+ } else {
158
+ popUpIcon.visibility = View.VISIBLE
159
+ popUpSubText.visibility = View.VISIBLE
160
+ popUpButton.visibility = View.VISIBLE
161
+ }
162
+
163
+
164
+ }
165
+
166
+ fun hidePopUpMessage() {
167
+ popUpContainer.visibility = View.GONE
168
+ }
169
+
170
+
171
+ fun startAssentifySdk() {
172
+ assentifySdk = AssentifySdkObject.getAssentifySdkObject();
173
+ scanPassport = assentifySdk!!.startScanPassport(
174
+ this@ScanPassportActivity,
175
+ language
176
+ );
177
+ Thread.sleep(500);
178
+ var fragmentManager = supportFragmentManager
179
+ var transaction = fragmentManager.beginTransaction()
180
+ transaction.replace(R.id.fragmentContainer, scanPassport)
181
+ transaction.commit()
182
+
183
+ }
184
+
185
+ override fun onError(dataModel: BaseResponseDataModel) {
186
+ triggerEvent("onError", dataModel)
187
+ runOnUiThread {
188
+ start = false;
189
+ showPopUpMessage(R.drawable.warning, "Unable to extract", "Let's try again", false)
190
+ }
191
+ }
192
+
193
+ override fun onSend() {
194
+ triggerEvent("onSend", null)
195
+ runOnUiThread {
196
+ start = true;
197
+ runOnUiThread {
198
+ showPopUpMessage(R.drawable.sending, "Transmitting", "Transmitting", true)
199
+ }
200
+ }
201
+ }
202
+
203
+ override fun onRetry(dataModel: BaseResponseDataModel) {
204
+ triggerEvent("onRetry", dataModel)
205
+ runOnUiThread {
206
+ start = false;
207
+ showPopUpMessage(R.drawable.warning, "Unable to extract", "Let's try again", false)
208
+ }
209
+ }
210
+
211
+ override fun onLivenessUpdate(dataModel: BaseResponseDataModel) {
212
+ triggerEvent("onLivenessUpdate", dataModel)
213
+ runOnUiThread {
214
+ start = false;
215
+ showPopUpMessage(R.drawable.warning,"Failed ID Check","Please real ID (Not copy)",false)
216
+ }
217
+ }
218
+
219
+ override fun onComplete(dataModel: PassportResponseModel) {
220
+
221
+ if (isExpired(dataModel.passportExtractedModel!!.identificationDocumentCapture!!.expiryDate.toString())) {
222
+ runOnUiThread {
223
+ start = false;
224
+ showPopUpMessage(R.drawable.expire, "Expired", "Please provide valid ID", false)
225
+ }
226
+ } else {
227
+ triggerCompleteEvent("onComplete", dataModel)
228
+ /** Steps **/
229
+ val sharedStepDefinitions =
230
+ reactApplicationContext.getSharedPreferences("StepDefinitions", Context.MODE_PRIVATE)
231
+ val gson = Gson()
232
+ val json: String = sharedStepDefinitions.getString("Steps", "")!!
233
+ val steps: List<StepDefinitions>? =
234
+ gson.fromJson(json, object : TypeToken<List<StepDefinitions>>() {}.type)
235
+ steps!!.forEach { item ->
236
+ if (item.stepDefinition == StepsName.DocumentCapture) {
237
+ val documentCaptureModel = SubmitRequestModel(
238
+ item.stepId, StepsName.DocumentCapture,
239
+ convertMap(dataModel.passportExtractedModel!!.transformedProperties)
240
+ );
241
+ val documentCaptureSharedPreferences = reactApplicationContext.getSharedPreferences(
242
+ "DocumentCaptureStepModel",
243
+ Context.MODE_PRIVATE
244
+ )
245
+ val documentCaptureSharedPreferencesEditor = documentCaptureSharedPreferences.edit()
246
+ val documentCaptureGson = Gson()
247
+ val documentCaptureStep: String = documentCaptureGson.toJson(documentCaptureModel)
248
+ documentCaptureSharedPreferencesEditor.putString(
249
+ "DocumentCaptureStep",
250
+ documentCaptureStep
251
+ );
252
+ documentCaptureSharedPreferencesEditor.apply()
253
+ }
254
+ runOnUiThread {
255
+ scanPassport.stopScanning();
256
+ /** End **/
257
+ if(!isDone){
258
+ isDone = true;
259
+ finish();
260
+ /* var base64Image =
261
+ ImageToBase64Converter(apiKey).execute(dataModel.passportExtractedModel!!.imageUrl).get()
262
+ val sharedPreferences =
263
+ reactApplicationContext.getSharedPreferences("FaceMatch", Context.MODE_PRIVATE)
264
+ val editor = sharedPreferences.edit()
265
+ editor.putString("Base64SecondImage", base64Image)
266
+ editor.apply()
267
+ val intent = Intent(reactApplicationContext, FaceMatchActivity::class.java)
268
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
269
+ intent.putExtra("holdHandColor", holdHandColor)
270
+ intent.putExtra("processingColor", processingColor)
271
+ intent.putExtra("showCountDown", showCountDown)
272
+ reactApplicationContext?.startActivity(intent)*/
273
+ }
274
+
275
+
276
+ }
277
+ }
278
+ }
279
+
280
+
281
+ }
282
+
283
+ override fun onEnvironmentalConditionsChange(
284
+ brightness: Double,
285
+ motion: MotionType,
286
+ zoomType: ZoomType
287
+ ) {
288
+ runOnUiThread {
289
+ if (start == false) {
290
+ infoLayout.visibility = View.VISIBLE
291
+ if (zoomType != ZoomType.SENDING && zoomType != ZoomType.NO_DETECT) {
292
+ if (zoomType == ZoomType.ZOOM_IN) {
293
+ infoText.setText("Move Passport Closer")
294
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.zoom_in))
295
+ }
296
+ if (zoomType == ZoomType.ZOOM_OUT) {
297
+ infoText.setText("Move Passport Further")
298
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.zoom_out))
299
+ }
300
+ } else if (motion == MotionType.HOLD_YOUR_HAND) {
301
+ infoText.setText("Please Hold Your Hand")
302
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
303
+ } else {
304
+ if (motion == MotionType.SENDING && zoomType == ZoomType.SENDING) {
305
+ infoText.setText("Hold Steady")
306
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
307
+ }
308
+ if (motion == MotionType.NO_DETECT && zoomType == ZoomType.NO_DETECT) {
309
+ infoText.setText("Please present passport")
310
+ infoIcon.setImageDrawable(getResources().getDrawable(R.drawable.info_icon))
311
+ }
312
+
313
+ }
314
+ } else {
315
+ infoLayout.visibility = View.GONE
316
+ }
317
+
318
+ }
319
+ }
320
+
321
+
322
+ fun convertMap(map: Map<String, Any>?): Map<String, String> {
323
+ return map?.mapValues {
324
+ it.value.toString()
325
+ } ?: emptyMap()
326
+ }
327
+
328
+ private fun triggerCompleteEvent(eventName: String, dataModel: PassportResponseModel?) {
329
+ val eventResultMap = Arguments.createMap().apply {
330
+ if (dataModel != null) {
331
+ val gson = Gson()
332
+ val jsonString = gson.toJson(dataModel.passportExtractedModel!!)
333
+ putString("PassportDataModel", jsonString)
334
+ }
335
+ }
336
+ reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
337
+ .emit(eventName, eventResultMap)
338
+
339
+ }
340
+
341
+ private fun triggerEvent(eventName: String, dataModel: BaseResponseDataModel?) {
342
+ val eventResultMap = Arguments.createMap().apply {
343
+ if (dataModel != null) {
344
+ putString("PassportDataModel", dataModel.response)
345
+ }
346
+ }
347
+ reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
348
+ .emit(eventName, eventResultMap)
349
+
350
+ }
351
+
352
+ fun isExpired(date: String): Boolean {
353
+ val sdf = SimpleDateFormat("dd/MM/yyyy")
354
+ val currentDate: LocalDate = LocalDate.now()
355
+ val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
356
+ val currentDateStr: String = currentDate.format(formatter)
357
+ val parsedCurrentDate: Date = sdf.parse(currentDateStr)
358
+ val dataDate = sdf.parse(date)
359
+ if (parsedCurrentDate.after(dataDate)) {
360
+ return true;
361
+ }
362
+ return false;
363
+ }
364
+ }