cleanup selection of media size
- add MediaSizeStore to manage write/read operations for the media size
This commit is contained in:
parent
fd5f64ecf3
commit
0fdb751909
|
@ -702,29 +702,16 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||
resolutions: List<ResolutionOption>,
|
||||
isPhotoCapture: Boolean,
|
||||
isFrontCamera: Boolean,
|
||||
onSelect: (changed: Boolean) -> Unit
|
||||
onSelect: (index: Int, changed: Boolean) -> Unit
|
||||
) {
|
||||
|
||||
media_size_toggle_group.removeAllViews()
|
||||
media_size_toggle_group.clearChecked()
|
||||
|
||||
val onItemClick = { clickedViewId: Int ->
|
||||
val index = resolutions.indexOfFirst { it.buttonViewId == clickedViewId }
|
||||
if (isPhotoCapture) {
|
||||
if (isFrontCamera) {
|
||||
config.frontPhotoResIndex = index
|
||||
} else {
|
||||
config.backPhotoResIndex = index
|
||||
}
|
||||
} else {
|
||||
if (isFrontCamera) {
|
||||
config.frontVideoResIndex = index
|
||||
} else {
|
||||
config.backVideoResIndex = index
|
||||
}
|
||||
}
|
||||
closeOptions()
|
||||
onSelect.invoke(selectedResolution.buttonViewId != clickedViewId)
|
||||
val index = resolutions.indexOfFirst { it.buttonViewId == clickedViewId }
|
||||
onSelect.invoke(index, selectedResolution.buttonViewId != clickedViewId)
|
||||
}
|
||||
|
||||
resolutions.map {
|
||||
|
|
|
@ -20,8 +20,8 @@ class ImageQualityManager(
|
|||
}
|
||||
|
||||
private val cameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||
private val config = activity.config
|
||||
private val imageQualities = mutableListOf<CameraSelectorImageQualities>()
|
||||
private val mediaSizeStore = MediaSizeStore(activity.config)
|
||||
|
||||
fun initSupportedQualities() {
|
||||
if (imageQualities.isEmpty()) {
|
||||
|
@ -52,7 +52,8 @@ class ImageQualityManager(
|
|||
|
||||
fun getUserSelectedResolution(cameraSelector: CameraSelector): MySize {
|
||||
val resolutions = getSupportedResolutions(cameraSelector)
|
||||
var index = if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) config.frontPhotoResIndex else config.backPhotoResIndex
|
||||
val isFrontCamera = cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA
|
||||
var index = mediaSizeStore.getCurrentSizeIndex(isPhotoCapture = true, isFrontCamera = isFrontCamera)
|
||||
index = index.coerceAtMost(resolutions.lastIndex).coerceAtLeast(0)
|
||||
return resolutions[index]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.simplemobiletools.camera.helpers
|
||||
|
||||
class MediaSizeStore(
|
||||
private val config: Config,
|
||||
) {
|
||||
|
||||
fun storeSize(isPhotoCapture: Boolean, isFrontCamera: Boolean, currentIndex: Int) {
|
||||
if (isPhotoCapture) {
|
||||
if (isFrontCamera) {
|
||||
config.frontPhotoResIndex = currentIndex
|
||||
} else {
|
||||
config.backPhotoResIndex = currentIndex
|
||||
}
|
||||
} else {
|
||||
if (isFrontCamera) {
|
||||
config.frontVideoResIndex = currentIndex
|
||||
} else {
|
||||
config.backVideoResIndex = currentIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getCurrentSizeIndex(isPhotoCapture: Boolean, isFrontCamera: Boolean): Int {
|
||||
return if (isPhotoCapture) {
|
||||
if (isFrontCamera) {
|
||||
config.frontPhotoResIndex
|
||||
} else {
|
||||
config.backPhotoResIndex
|
||||
}
|
||||
} else {
|
||||
if (isFrontCamera) {
|
||||
config.frontVideoResIndex
|
||||
} else {
|
||||
config.backVideoResIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ class VideoQualityManager(
|
|||
private val CAMERA_SELECTORS = arrayOf(CameraSelector.DEFAULT_BACK_CAMERA, CameraSelector.DEFAULT_FRONT_CAMERA)
|
||||
}
|
||||
|
||||
private val config = activity.config
|
||||
private val videoQualities = mutableListOf<CameraSelectorVideoQualities>()
|
||||
private val mediaSizeStore = MediaSizeStore(activity.config)
|
||||
|
||||
fun initSupportedQualities(cameraProvider: ProcessCameraProvider) {
|
||||
if (videoQualities.isEmpty()) {
|
||||
|
@ -45,8 +45,8 @@ class VideoQualityManager(
|
|||
}
|
||||
|
||||
fun getUserSelectedQuality(cameraSelector: CameraSelector): VideoQuality {
|
||||
var selectionIndex = if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) config.frontVideoResIndex else config.backVideoResIndex
|
||||
selectionIndex = selectionIndex.coerceAtLeast(0)
|
||||
val isFrontCamera = cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA
|
||||
val selectionIndex = mediaSizeStore.getCurrentSizeIndex(isPhotoCapture = false, isFrontCamera = isFrontCamera).coerceAtLeast(0)
|
||||
return getSupportedQualities(cameraSelector).getOrElse(selectionIndex) { VideoQuality.HD }
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ class CameraXPreview(
|
|||
private val videoQualityManager = VideoQualityManager(activity)
|
||||
private val imageQualityManager = ImageQualityManager(activity)
|
||||
private val exifRemover = ExifRemover(contentResolver)
|
||||
private val mediaSizeStore = MediaSizeStore(config)
|
||||
|
||||
private val orientationEventListener = object : OrientationEventListener(activity, SensorManager.SENSOR_DELAY_NORMAL) {
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
@ -359,10 +360,11 @@ class CameraXPreview(
|
|||
resolutions = resolutions,
|
||||
isPhotoCapture = isPhotoCapture,
|
||||
isFrontCamera = isFrontCameraInUse()
|
||||
) { changed ->
|
||||
) { index, changed ->
|
||||
if (changed) {
|
||||
currentRecording?.stop()
|
||||
}
|
||||
mediaSizeStore.storeSize(isPhotoCapture, isFrontCameraInUse(), index)
|
||||
startCamera()
|
||||
}
|
||||
} else {
|
||||
|
@ -371,19 +373,7 @@ class CameraXPreview(
|
|||
}
|
||||
|
||||
private fun toggleResolutions(resolutions: List<ResolutionOption>) {
|
||||
val currentIndex = if (isPhotoCapture) {
|
||||
if (isFrontCameraInUse()) {
|
||||
config.frontPhotoResIndex
|
||||
} else {
|
||||
config.backPhotoResIndex
|
||||
}
|
||||
} else {
|
||||
if (isFrontCameraInUse()) {
|
||||
config.frontVideoResIndex
|
||||
} else {
|
||||
config.backVideoResIndex
|
||||
}
|
||||
}
|
||||
val currentIndex = mediaSizeStore.getCurrentSizeIndex(isPhotoCapture, isFrontCameraInUse())
|
||||
|
||||
val nextIndex = if (currentIndex >= resolutions.lastIndex) {
|
||||
0
|
||||
|
@ -391,19 +381,7 @@ class CameraXPreview(
|
|||
currentIndex + 1
|
||||
}
|
||||
|
||||
if (isPhotoCapture) {
|
||||
if (isFrontCameraInUse()) {
|
||||
config.frontPhotoResIndex = nextIndex
|
||||
} else {
|
||||
config.backPhotoResIndex = nextIndex
|
||||
}
|
||||
} else {
|
||||
if (isFrontCameraInUse()) {
|
||||
config.frontVideoResIndex = nextIndex
|
||||
} else {
|
||||
config.backVideoResIndex = nextIndex
|
||||
}
|
||||
}
|
||||
mediaSizeStore.storeSize(isPhotoCapture, isFrontCameraInUse(), nextIndex)
|
||||
currentRecording?.stop()
|
||||
startCamera()
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ interface CameraXPreviewListener {
|
|||
resolutions: List<ResolutionOption>,
|
||||
isPhotoCapture: Boolean,
|
||||
isFrontCamera: Boolean,
|
||||
onSelect: (changed:Boolean) -> Unit,
|
||||
onSelect: (index: Int, changed: Boolean) -> Unit,
|
||||
)
|
||||
|
||||
fun showFlashOptions(photoCapture: Boolean)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue