Aperture: Parse camera infos on PhysicalCamera constructor
* They can't change at runtime
* Also get rid of useless getters
Change-Id: Id96e6538cf22173ff11466addcc0f55a37b2c764
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index 8b2d52d..6f62cea 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -656,7 +656,7 @@
(flipCameraButton.drawable as AnimatedVectorDrawable).start()
sharedPreferences.lastCameraFacing =
- when (cameraController.physicalCamera?.getCameraFacing()) {
+ when (cameraController.physicalCamera?.cameraFacing) {
// We can definitely do it better
CameraFacing.FRONT -> CameraFacing.BACK
CameraFacing.BACK -> CameraFacing.FRONT
@@ -804,7 +804,7 @@
* Update the flash mode button icon based on the value set in imageCapture
*/
private fun updateFlashModeIcon() {
- flashButton.isVisible = cameraMode == CameraMode.PHOTO && camera.hasFlashUnit()
+ flashButton.isVisible = cameraMode == CameraMode.PHOTO && camera.hasFlashUnit
flashButton.setImageDrawable(
ContextCompat.getDrawable(
this,
diff --git a/app/src/main/java/org/lineageos/aperture/utils/PhysicalCamera.kt b/app/src/main/java/org/lineageos/aperture/utils/PhysicalCamera.kt
index 7acf0c5..f493a1a 100644
--- a/app/src/main/java/org/lineageos/aperture/utils/PhysicalCamera.kt
+++ b/app/src/main/java/org/lineageos/aperture/utils/PhysicalCamera.kt
@@ -14,46 +14,30 @@
* Class representing a physical device camera
*/
@androidx.camera.camera2.interop.ExperimentalCamera2Interop
-class PhysicalCamera(private val cameraInfo: CameraInfo) {
- private val camera2CameraInfo = Camera2CameraInfo.from(cameraInfo)
+class PhysicalCamera(val cameraInfo: CameraInfo) {
+ /**
+ * Camera2 CameraInfo
+ */
+ val camera2CameraInfo = Camera2CameraInfo.from(cameraInfo)
/**
- * Return a CameraX's CameraInfo object
+ * Camera2 compatible camera ID
*/
- fun getCameraInfo(): CameraInfo {
- return cameraInfo
- }
+ val cameraId = camera2CameraInfo.cameraId.toInt()
/**
- * Return a CameraX's Camera2CameraInfo object
+ * Facing of the camera
*/
- fun getCamera2CameraInfo(): Camera2CameraInfo {
- return camera2CameraInfo
- }
-
- /**
- * Returns a Camera2 compatible camera ID
- */
- fun getCameraId(): Int {
- return camera2CameraInfo.cameraId.toInt()
- }
-
- /**
- * Return the facing of the camera
- */
- fun getCameraFacing(): CameraFacing {
- return when (camera2CameraInfo.getCameraCharacteristic(CameraCharacteristics.LENS_FACING)) {
+ val cameraFacing =
+ when (camera2CameraInfo.getCameraCharacteristic(CameraCharacteristics.LENS_FACING)) {
CameraCharacteristics.LENS_FACING_FRONT -> CameraFacing.FRONT
CameraCharacteristics.LENS_FACING_BACK -> CameraFacing.BACK
CameraCharacteristics.LENS_FACING_EXTERNAL -> CameraFacing.EXTERNAL
else -> CameraFacing.UNKNOWN
}
- }
/**
- * Return if flash is available or not
+ * Flash is available or not
*/
- fun hasFlashUnit(): Boolean {
- return cameraInfo.hasFlashUnit()
- }
+ val hasFlashUnit = cameraInfo.hasFlashUnit()
}