Skip to content

Commit

Permalink
fix(core): previewview: fix camera facing direction
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Apr 8, 2024
1 parent 685295e commit 555e532
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ class PreviewView @JvmOverloads constructor(
val a = context.obtainStyledAttributes(attrs, R.styleable.PreviewView)

try {
cameraFacingDirection = CameraFacingDirection.entryOf(
a.getString(R.styleable.PreviewView_cameraFacingDirection) ?: DEFAULT_CAMERA_FACING.value
)
cameraFacingDirection =
CameraFacingDirection.entryOf(
a.getInt(R.styleable.PreviewView_cameraFacingDirection, DEFAULT_CAMERA_FACING.value)
)

defaultCameraId = when (cameraFacingDirection) {
CameraFacingDirection.FRONT -> {
Expand Down Expand Up @@ -465,22 +466,27 @@ class PreviewView @JvmOverloads constructor(
/**
* Options for the camera facing direction.
*/
enum class CameraFacingDirection(val value: String) {
enum class CameraFacingDirection(val value: Int, val id: String) {
/**
* The facing of the camera is the same as that of the screen.
*/
FRONT("front"),
FRONT(0, "front"),

/**
* The facing of the camera is opposite to that of the screen.
*/
BACK("back");
BACK(1, "back");

companion object {
/**
* Returns the [CameraFacingDirection] from the given id.
*/
internal fun entryOf(value: String) = entries.first { it.value == value }
internal fun entryOf(value: Int) = entries.first { it.value == value }

/**
* Returns the [CameraFacingDirection] from the given id.
*/
internal fun entryOf(value: String) = entries.first { it.id == value }
}
}

Expand Down

0 comments on commit 555e532

Please sign in to comment.