diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index a7b2cfc1..f4166456 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -119,7 +119,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener { mCameraImpl = getMyCamera() if (config.alwaysOpenBackCamera) { - config.lastUsedCamera = mCameraImpl.getBackCameraId() + config.lastUsedCamera = mCameraImpl.getBackCameraId().toString() } } @@ -196,7 +196,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener { mPreview = if (isLollipopPlus()) PreviewCameraTwo(this, camera_texture_view) else PreviewCameraOne(this, camera_surface_view) view_holder.addView(mPreview as ViewGroup) - val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear + val imageDrawable = if (config.lastUsedCamera == mCameraImpl.getBackCameraId().toString()) R.drawable.ic_camera_front else R.drawable.ic_camera_rear toggle_camera.setImageResource(imageDrawable) mFocusCircleView = FocusCircleView(applicationContext) 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 5ba8851d..14c8fa1f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Config.kt @@ -46,9 +46,9 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(FLIP_PHOTOS, true) set(flipPhotos) = prefs.edit().putBoolean(FLIP_PHOTOS, flipPhotos).apply() - var lastUsedCamera: Int - get() = prefs.getInt(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId()) - set(cameraId) = prefs.edit().putInt(LAST_USED_CAMERA, cameraId).apply() + var lastUsedCamera: String + get() = prefs.getString(LAST_USED_CAMERA, context.getMyCamera().getBackCameraId().toString()) + set(cameraId) = prefs.edit().putString(LAST_USED_CAMERA, cameraId).apply() var flashlightState: Int get() = prefs.getInt(FLASHLIGHT_STATE, FLASH_OFF) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt index 9de2ed92..252663a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/helpers/Constants.kt @@ -13,7 +13,7 @@ const val FOCUS_BEFORE_CAPTURE = "focus_before_capture" const val VOLUME_BUTTONS_AS_SHUTTER = "volume_buttons_as_shutter" const val TURN_FLASH_OFF_AT_STARTUP = "turn_flash_off_at_startup" const val FLIP_PHOTOS = "flip_photos" -const val LAST_USED_CAMERA = "last_used_camera" +const val LAST_USED_CAMERA = "last_used_camera_2" const val FLASHLIGHT_STATE = "flashlight_state" const val BACK_PHOTO_RESOLUTION_INDEX = "back_photo_resolution_index_2" const val BACK_VIDEO_RESOLUTION_INDEX = "back_video_resolution_index_2" diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraOne.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraOne.kt index eb11f421..25546292 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraOne.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraOne.kt @@ -202,7 +202,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview { mCameraImpl!!.getBackCameraId() } - mConfig.lastUsedCamera = mCurrCameraId + mConfig.lastUsedCamera = mCurrCameraId.toString() releaseCamera() if (resumeCamera()) { setFlashlightState(FLASH_OFF) @@ -243,7 +243,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview { } private fun getResolutionIndex(): Int { - val isBackCamera = mConfig.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK + val isBackCamera = mConfig.lastUsedCamera == Camera.CameraInfo.CAMERA_FACING_BACK.toString() return if (mIsInVideoMode) { if (isBackCamera) mConfig.backVideoResIndex else mConfig.frontVideoResIndex } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt index 1c166c0d..c0a21d6d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/PreviewCameraTwo.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import com.simplemobiletools.camera.activities.MainActivity import com.simplemobiletools.camera.dialogs.ChangeResolutionDialog import com.simplemobiletools.camera.extensions.config +import com.simplemobiletools.camera.extensions.getMyCamera import com.simplemobiletools.camera.helpers.* import com.simplemobiletools.camera.interfaces.MyPreview import com.simplemobiletools.camera.models.FocusArea @@ -81,6 +82,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie constructor(activity: MainActivity, textureView: AutoFitTextureView) : super(activity) { mActivity = activity mTextureView = textureView + mUseFrontCamera = activity.config.lastUsedCamera == activity.getMyCamera().getBackCameraId().toString() mTextureView.setOnTouchListener { view, event -> if (event.action == MotionEvent.ACTION_DOWN) { @@ -241,6 +243,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie } mCameraId = cameraId + mActivity.config.lastUsedCamera = mCameraId val configMap = getCameraCharacteristics().get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) val currentResolution = getCurrentResolution()