From 210f3e35c01e5828a7e87320b6b719bca62873ed Mon Sep 17 00:00:00 2001 From: darthpaul Date: Wed, 13 Jul 2022 01:38:54 +0100 Subject: [PATCH] use the resolution index instead of the qualities - store and use the resolution index in Config class for video capture --- .../camera/dialogs/ChangeResolutionDialogX.kt | 17 ++++++++++------- .../simplemobiletools/camera/helpers/Config.kt | 15 --------------- .../camera/helpers/VideoQualityManager.kt | 9 ++++----- .../camera/implementations/CameraXPreview.kt | 2 +- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialogX.kt b/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialogX.kt index 0961ca35..77a79376 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialogX.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/dialogs/ChangeResolutionDialogX.kt @@ -42,7 +42,7 @@ class ChangeResolutionDialogX( } private fun setupPhotoResolutionPicker(view: View) { - val items = photoResolutions.mapIndexed { index, resolution-> + val items = photoResolutions.mapIndexed { index, resolution -> val megapixels = resolution.megaPixels val aspectRatio = resolution.getAspectRatio(activity) RadioItem(index, "${resolution.width} x ${resolution.height} ($megapixels MP, $aspectRatio)") @@ -74,24 +74,27 @@ class ChangeResolutionDialogX( RadioItem(index, "${videoQuality.width} x ${videoQuality.height} ($megapixels MP, $aspectRatio)") } - val videoQuality = if (isFrontCamera) config.frontVideoQuality else config.backVideoQuality - var selectionIndex = videoResolutions.indexOf(videoQuality) + var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex + selectionIndex = selectionIndex.coerceAtLeast(0) + Log.i(TAG, "videoResolutions=$videoResolutions") + Log.i(TAG, "setupVideoResolutionPicker: selectionIndex=$selectionIndex") view.change_resolution_video_holder.setOnClickListener { RadioGroupDialog(activity, ArrayList(items), selectionIndex) { selectionIndex = it as Int val selectedItem = items[selectionIndex] - val selectedQuality = videoResolutions[selectionIndex] view.change_resolution_video.text = selectedItem.title if (isFrontCamera) { - config.frontVideoQuality = selectedQuality + config.frontVideoResIndex = selectionIndex } else { - config.backVideoQuality = selectedQuality + config.backPhotoResIndex = selectionIndex } dialog.dismiss() callback.invoke() } } - view.change_resolution_video.text = items.getOrNull(selectionIndex)?.title + val selectedItem = items.getOrNull(selectionIndex) + view.change_resolution_video.text = selectedItem?.title + Log.i(TAG, "setupVideoResolutionPicker: selectedItem=$selectedItem") } } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt index 6ae1a3ed..5ede2c12 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt @@ -3,7 +3,6 @@ package com.simplemobiletools.camera.helpers import android.content.Context import android.os.Environment import androidx.camera.core.CameraSelector -import com.simplemobiletools.camera.models.VideoQuality import com.simplemobiletools.commons.helpers.BaseConfig import java.io.File @@ -63,20 +62,6 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(FRONT_PHOTO_RESOLUTION_INDEX, 0) set(frontPhotoResIndex) = prefs.edit().putInt(FRONT_PHOTO_RESOLUTION_INDEX, frontPhotoResIndex).apply() - var backVideoQuality: VideoQuality - get() { - val backQuality = prefs.getString(BACK_VIDEO_QUALITY, VideoQuality.UHD.name) - return VideoQuality.values().first { it.name == backQuality } - } - set(backVideoQuality) = prefs.edit().putString(BACK_VIDEO_QUALITY, backVideoQuality.name).apply() - - var frontVideoQuality: VideoQuality - get() { - val frontQuality = prefs.getString(FRONT_VIDEO_QUALITY, VideoQuality.UHD.name) - return VideoQuality.values().first { it.name == frontQuality } - } - set(frontVideoQuality) = prefs.edit().putString(FRONT_VIDEO_QUALITY, frontVideoQuality.name).apply() - var frontVideoResIndex: Int get() = prefs.getInt(FRONT_VIDEO_RESOLUTION_INDEX, 0) set(frontVideoResIndex) = prefs.edit().putInt(FRONT_VIDEO_RESOLUTION_INDEX, frontVideoResIndex).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/VideoQualityManager.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/VideoQualityManager.kt index 26f3dc3b..7f2962ff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/VideoQualityManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/VideoQualityManager.kt @@ -34,6 +34,7 @@ class VideoQualityManager(private val config: Config) { .also { allQualities -> val qualities = allQualities.map { it.toVideoQuality() } videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities)) + } Log.i(TAG, "bindCameraUseCases: videoQualities=$videoQualities") } @@ -45,11 +46,9 @@ class VideoQualityManager(private val config: Config) { } fun getUserSelectedQuality(cameraSelector: CameraSelector): Quality { - return if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) { - config.frontVideoQuality.toCameraXQuality() - } else { - config.backVideoQuality.toCameraXQuality() - } + var selectionIndex = if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) config.frontVideoResIndex else config.backVideoResIndex + selectionIndex = selectionIndex.coerceAtLeast(0) + return getSupportedQualities(cameraSelector)[selectionIndex].toCameraXQuality() } fun getSupportedQualities(cameraSelector: CameraSelector): List { diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt index 58b37803..5cb1536b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/implementations/CameraXPreview.kt @@ -223,7 +223,7 @@ class CameraXPreview( private fun buildVideoCapture(): VideoCapture { val qualitySelector = QualitySelector.from( videoQualityManager.getUserSelectedQuality(cameraSelector), - FallbackStrategy.lowerQualityOrHigherThan(Quality.SD), + FallbackStrategy.higherQualityOrLowerThan(Quality.SD), ) val recorder = Recorder.Builder() .setQualitySelector(qualitySelector)