package com.docvcapture import com.trulioo.docvCapture.core.ui.CameraConfig import com.trulioo.docvCapture.core.ui.CameraProps import com.trulioo.docvCapture.core.ui.DetectionType import com.trulioo.docvCapture.sdk.TruliooCapture import org.json.JSONObject object TruliooCaptureObject { private var instance: TruliooCapture? = null fun getInstance(): TruliooCapture { synchronized(this) { if (instance == null) { instance = TruliooCapture() } return instance!! } } fun createTruliooCameraConfig(cameraConfigJson: String): CameraConfig { val cameraConfigString = JSONObject(cameraConfigJson) val detectionType = getCurrentDetectionType(cameraConfigString.optInt("detectionType")) val cameraId = cameraConfigString.getString("cameraId") return CameraConfig(cameraId = cameraId, detectionType = detectionType) } fun createNativeCameraViewProps(nativeCameraViewPropsJson: String): CameraProps { val cameraViewProps = JSONObject(nativeCameraViewPropsJson) val backgroundColor = if (cameraViewProps.has("backgroundColor")) { cameraViewProps.optString("backgroundColor") } else { "#00000050" } val shouldShowAnimation = cameraViewProps.getString("shouldShowAnimation").toBoolean() val cameraId = cameraViewProps.getString("cameraId") return CameraProps(cameraId, backgroundColor = backgroundColor) } private fun getCurrentDetectionType(detectionType: Number): DetectionType { return when (detectionType) { 0 -> DetectionType.DOCUMENT 1 -> DetectionType.PASSPORT 2 -> DetectionType.BIOMETRIC_SELFIE 3 -> DetectionType.NO_DETECTION else -> DetectionType.NO_DETECTION } } }