-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added kotlin enhanced biometric views
- Loading branch information
Showing
2 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
android/src/main/kotlin/com/smileidentity/flutter/v2/SmileIDSmartSelfieAuthenticationV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package android.src.main.kotlin.com.smileidentity.flutter.v2 | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import com.smileidentity.SmileID | ||
import com.smileidentity.compose.SmartSelfieAuthentication | ||
import com.smileidentity.flutter.results.SmartSelfieCaptureResult | ||
import com.smileidentity.flutter.utils.SelfieCaptureResultAdapter | ||
import com.smileidentity.results.SmileIDResult | ||
import com.smileidentity.util.randomUserId | ||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.plugin.common.StandardMessageCodec | ||
import io.flutter.plugin.platform.PlatformView | ||
import io.flutter.plugin.platform.PlatformViewFactory | ||
import kotlinx.collections.immutable.toImmutableMap | ||
|
||
internal class SmileIDSmartSelfieAuthenticationV2 private constructor( | ||
context: Context, | ||
viewId: Int, | ||
messenger: BinaryMessenger, | ||
args: Map<String, Any?>, | ||
) : SmileComposablePlatformView(context, VIEW_TYPE_ID, viewId, messenger, args) { | ||
companion object { | ||
const val VIEW_TYPE_ID = "SmileIDSmartSelfieAuthenticationV2" | ||
} | ||
|
||
@Composable | ||
override fun Content(args: Map<String, Any?>) { | ||
val extraPartnerParams = args["extraPartnerParams"] as? Map<String, String> ?: emptyMap() | ||
SmileID.SmartSelfieAuthentication( | ||
userId = args["userId"] as? String ?: randomUserId(), | ||
allowNewEnroll = args["allowNewEnroll"] as? Boolean ?: false, | ||
showAttribution = args["showAttribution"] as? Boolean ?: true, | ||
showInstructions = args["showInstructions"] as? Boolean ?: true, | ||
extraPartnerParams = extraPartnerParams.toImmutableMap(), | ||
) { | ||
when (it) { | ||
is SmileIDResult.Success -> { | ||
val result = | ||
SmartSelfieResult( | ||
selfieFile = it.data.selfieFile, | ||
livenessFiles = it.data.livenessFiles, | ||
apiResponse = it.data.apiResponse, | ||
) | ||
val moshi = | ||
SmileID.moshi | ||
.newBuilder() | ||
.add(SelfieCaptureResultAdapter.FACTORY) | ||
.build() | ||
val json = | ||
try { | ||
moshi | ||
.adapter(SmartSelfieResult::class.java) | ||
.toJson(result) | ||
} catch (e: Exception) { | ||
onError(e) | ||
return@SmartSelfieAuthentication | ||
} | ||
json?.let { js -> | ||
onSuccessJson(js) | ||
} | ||
} | ||
|
||
is SmileIDResult.Error -> onError(it.throwable) | ||
} | ||
} | ||
} | ||
|
||
class Factory( | ||
private val messenger: BinaryMessenger, | ||
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) { | ||
override fun create( | ||
context: Context, | ||
viewId: Int, | ||
args: Any?, | ||
): PlatformView { | ||
@Suppress("UNCHECKED_CAST") | ||
return SmileIDSmartSelfieAuthenticationV2( | ||
context, | ||
viewId, | ||
messenger, | ||
args as Map<String, Any?>, | ||
) | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
android/src/main/kotlin/com/smileidentity/flutter/v2/SmileIDSmartSelfieEnrollmentV2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package android.src.main.kotlin.com.smileidentity.flutter.v2 | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import com.smileidentity.SmileID | ||
import com.smileidentity.compose.SmartSelfieEnrollment | ||
import com.smileidentity.flutter.results.SmartSelfieCaptureResult | ||
import com.smileidentity.flutter.utils.SelfieCaptureResultAdapter | ||
import com.smileidentity.results.SmileIDResult | ||
import com.smileidentity.util.randomUserId | ||
import io.flutter.plugin.common.BinaryMessenger | ||
import io.flutter.plugin.common.StandardMessageCodec | ||
import io.flutter.plugin.platform.PlatformView | ||
import io.flutter.plugin.platform.PlatformViewFactory | ||
import kotlinx.collections.immutable.toImmutableMap | ||
|
||
internal class SmileIDSmartSelfieEnrollmentV2 private constructor( | ||
context: Context, | ||
viewId: Int, | ||
messenger: BinaryMessenger, | ||
args: Map<String, Any?>, | ||
) : SmileComposablePlatformView(context, VIEW_TYPE_ID, viewId, messenger, args) { | ||
companion object { | ||
const val VIEW_TYPE_ID = "SmileIDSmartSelfieEnrollmentV2" | ||
} | ||
|
||
@Composable | ||
override fun Content(args: Map<String, Any?>) { | ||
val extraPartnerParams = args["extraPartnerParams"] as? Map<String, String> ?: emptyMap() | ||
SmileID.SmartSelfieEnrollment( | ||
userId = args["userId"] as? String ?: randomUserId(), | ||
allowNewEnroll = args["allowNewEnroll"] as? Boolean ?: false, | ||
showAttribution = args["showAttribution"] as? Boolean ?: true, | ||
showInstructions = args["showInstructions"] as? Boolean ?: true, | ||
extraPartnerParams = extraPartnerParams.toImmutableMap(), | ||
) { | ||
when (it) { | ||
is SmileIDResult.Success -> { | ||
val result = | ||
SmartSelfieResult( | ||
selfieFile = it.data.selfieFile, | ||
livenessFiles = it.data.livenessFiles, | ||
apiResponse = it.data.apiResponse, | ||
) | ||
val moshi = | ||
SmileID.moshi | ||
.newBuilder() | ||
.add(SelfieCaptureResultAdapter.FACTORY) | ||
.build() | ||
val json = | ||
try { | ||
moshi | ||
.adapter(SmartSelfieResult::class.java) | ||
.toJson(result) | ||
} catch (e: Exception) { | ||
onError(e) | ||
return@SmartSelfieEnrollment | ||
} | ||
json?.let { js -> | ||
onSuccessJson(js) | ||
} | ||
} | ||
|
||
is SmileIDResult.Error -> onError(it.throwable) | ||
} | ||
} | ||
} | ||
|
||
class Factory( | ||
private val messenger: BinaryMessenger, | ||
) : PlatformViewFactory(StandardMessageCodec.INSTANCE) { | ||
override fun create( | ||
context: Context, | ||
viewId: Int, | ||
args: Any?, | ||
): PlatformView { | ||
@Suppress("UNCHECKED_CAST") | ||
return SmileIDSmartSelfieEnrollmentV2( | ||
context, | ||
viewId, | ||
messenger, | ||
args as Map<String, Any?>, | ||
) | ||
} | ||
} | ||
} |