$cameraPath = 'app\src\main\kotlin\com\bodycamera\twentyfoulabs\camera\M530CameraActivity.kt' $mainPath = 'app\src\main\kotlin\com\bodycamera\twentyfoulabs\MainActivity.kt' $camera = Get-Content $cameraPath -Raw $main = Get-Content $mainPath -Raw # ============================================================ # M530CameraActivity.kt # ============================================================ # 1. Agregar modo FRONT_PREVIEW $camera = [regex]::Replace( $camera, 'const val MODE_VIDEO = "video"', 'const val MODE_VIDEO = "video"' + [Environment]::NewLine + ' const val MODE_FRONT_PREVIEW = "front_preview"', 1 ) # 2. Texto superior $camera = $camera.Replace( 'text = if (mode == MODE_VIDEO) "VIDEO" else "FOTO"', 'text = when (mode) {' + [Environment]::NewLine + ' MODE_VIDEO -> "VIDEO"' + [Environment]::NewLine + ' MODE_FRONT_PREVIEW -> "CAMARA FRONTAL"' + [Environment]::NewLine + ' else -> "FOTO"' + [Environment]::NewLine + ' }' ) # 3. Ocultar botón de captura cuando sea preview frontal $camera = $camera.Replace( 'text = if (mode == MODE_VIDEO) "REC" else "FOTO"', 'text = if (mode == MODE_VIDEO) "REC" else "FOTO"' + [Environment]::NewLine + ' visibility = if (mode == MODE_FRONT_PREVIEW) View.GONE else View.VISIBLE' ) # 4. Texto inferior $camera = $camera.Replace( 'text = if (mode == MODE_VIDEO) "F5 VIDEO" else "F2 FOTO"', 'text = when (mode) {' + [Environment]::NewLine + ' MODE_VIDEO -> "F5 VIDEO"' + [Environment]::NewLine + ' MODE_FRONT_PREVIEW -> "VISTA EN VIVO"' + [Environment]::NewLine + ' else -> "F2 FOTO"' + [Environment]::NewLine + ' }' ) # 5. Estado inicial $camera = [regex]::Replace( $camera, 'text = if \(mode == MODE_VIDEO\) "Preparando video\.\.\." else ".*?"', 'text = when (mode) {' + [Environment]::NewLine + ' MODE_VIDEO -> "Preparando video..."' + [Environment]::NewLine + ' MODE_FRONT_PREVIEW -> "Preparando camara frontal..."' + [Environment]::NewLine + ' else -> "Preparando camara..."' + [Environment]::NewLine + ' }', 1 ) # 6. Evitar acciones de foto/video en preview frontal $camera = [regex]::Replace( $camera, 'if \(mode == MODE_VIDEO\) \{\s*toggleVideoRecording\(\)\s*\} else \{\s*takePhoto\(\)\s*\}', 'when (mode) {' + [Environment]::NewLine + ' MODE_VIDEO -> toggleVideoRecording()' + [Environment]::NewLine + ' MODE_FRONT_PREVIEW -> Unit' + [Environment]::NewLine + ' else -> takePhoto()' + [Environment]::NewLine + ' }', 1 ) # 7. Usar cámara frontal solo en FRONT_PREVIEW $camera = [regex]::Replace( $camera, '(\s*provider\.unbindAll\(\)\s*)if \(mode == MODE_VIDEO\) \{', '$1if (mode == MODE_FRONT_PREVIEW) {' + [Environment]::NewLine + ' imageCapture = null' + [Environment]::NewLine + ' videoCapture = null' + [Environment]::NewLine + '' + [Environment]::NewLine + ' provider.bindToLifecycle(' + [Environment]::NewLine + ' this,' + [Environment]::NewLine + ' CameraSelector.DEFAULT_FRONT_CAMERA,' + [Environment]::NewLine + ' preview' + [Environment]::NewLine + ' )' + [Environment]::NewLine + '' + [Environment]::NewLine + ' stateText.text = "Camara frontal lista"' + [Environment]::NewLine + ' captureButton.isEnabled = false' + [Environment]::NewLine + ' } else if (mode == MODE_VIDEO) {', 1 ) # ============================================================ # MainActivity.kt # ============================================================ # 8. Variable para abrir la cámara frontal una sola vez por inicio $main = $main.Replace( '@Volatile private var isAuthenticated = false', '@Volatile private var isAuthenticated = false' + [Environment]::NewLine + ' private var frontPreviewOpened = false' ) # 9. Al detectar sesión válida, abrir preview frontal $main = [regex]::Replace( $main, 'authSessionStore\.token\.collect \{ token -> isAuthenticated = !token\.isNullOrBlank\(\) \}', 'authSessionStore.token.collect { token ->' + [Environment]::NewLine + ' isAuthenticated = !token.isNullOrBlank()' + [Environment]::NewLine + '' + [Environment]::NewLine + ' if (isAuthenticated && !frontPreviewOpened) {' + [Environment]::NewLine + ' frontPreviewOpened = true' + [Environment]::NewLine + ' runOnUiThread {' + [Environment]::NewLine + ' openFrontPreview()' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' }' + [Environment]::NewLine + ' }', 1 ) # 10. Función para abrir la cámara frontal $frontFunction = @' private fun openFrontPreview() { if (!isAuthenticated) return startActivity( android.content.Intent( this, com.bodycamera.twentyfoulabs.camera.M530CameraActivity::class.java ).putExtra( com.bodycamera.twentyfoulabs.camera.M530CameraActivity.EXTRA_MODE, com.bodycamera.twentyfoulabs.camera.M530CameraActivity.MODE_FRONT_PREVIEW ).addFlags(android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP) ) } '@ $main = $main.Replace( ' private fun handlePhotoButton() {', $frontFunction + ' private fun handlePhotoButton() {' ) # ============================================================ # Guardar cambios # ============================================================ Set-Content -Path $cameraPath -Value $camera -Encoding UTF8 Set-Content -Path $mainPath -Value $main -Encoding UTF8 Write-Host '' Write-Host '==========================================' Write-Host 'FRONT PREVIEW V2 APLICADO' Write-Host '==========================================' Write-Host 'MODE_FRONT_PREVIEW agregado' Write-Host 'Camara frontal configurada' Write-Host 'F2 y F5 mantienen camara trasera' Write-Host ''