Skip to content

Commit

Permalink
Create and Implement UI Components
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimblebee committed Jul 27, 2023
1 parent 1d50e3d commit 45445f9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fun PreviewScreen(
currentCameraSettings = previewUiState.currentCameraSettings,
onLensFaceClick = viewModel::flipCamera,
onFlashModeClick = viewModel::setFlash,
onDemoSwitchClick = viewModel::setDemoSwitch,
onDemoMultipleClick = viewModel::setDemoMultiple
//onAspectRatioClick = {}/*TODO*/,
//onTimerClick = {}/*TODO*/
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
import com.google.jetpackcamera.feature.quicksettings.ui.DemoMultiple
import com.google.jetpackcamera.feature.quicksettings.ui.DemoSetSwitch
import com.google.jetpackcamera.feature.quicksettings.ui.DropDownIcon
import com.google.jetpackcamera.feature.quicksettings.ui.ExpandedDemoMultiple
import com.google.jetpackcamera.feature.quicksettings.ui.ExpandedQuickSetRatio
import com.google.jetpackcamera.feature.quicksettings.ui.QuickFlipCamera
import com.google.jetpackcamera.feature.quicksettings.ui.QuickSetFlash
import com.google.jetpackcamera.feature.quicksettings.ui.QuickSetRatio
import com.google.jetpackcamera.feature.quicksettings.ui.QuickSettingsGrid
import com.google.jetpackcamera.quicksettings.R
import com.google.jetpackcamera.settings.model.CameraAppSettings
import com.google.jetpackcamera.settings.model.DemoMultipleStatus
import com.google.jetpackcamera.settings.model.FlashModeStatus

/**
Expand All @@ -59,6 +63,8 @@ fun QuickSettingsScreen(
toggleIsOpen: () -> Unit,
onLensFaceClick: (lensFace: Boolean) -> Unit,
onFlashModeClick: (flashMode: FlashModeStatus) -> Unit,
onDemoSwitchClick: (Boolean) -> Unit,
onDemoMultipleClick: (DemoMultipleStatus) -> Unit
) {
var shouldShowQuickSetting by remember {
mutableStateOf(IsExpandedQuickSetting.NONE)
Expand Down Expand Up @@ -104,6 +110,8 @@ fun QuickSettingsScreen(
},
onLensFaceClick = onLensFaceClick,
onFlashModeClick = onFlashModeClick,
onDemoSwitchClick = onDemoSwitchClick,
onDemoMultipleClick = onDemoMultipleClick,
//onAspectRatioClick = onAspectRatioClick,
//onTimerClick = onTimerClick,
)
Expand All @@ -116,6 +124,7 @@ fun QuickSettingsScreen(
private enum class IsExpandedQuickSetting {
NONE,
ASPECT_RATIO,
DEMO,
}

/**
Expand All @@ -126,6 +135,8 @@ private fun ExpandedQuickSettingsUi(
currentCameraSettings: CameraAppSettings,
onLensFaceClick: (lensFacingFront: Boolean) -> Unit,
onFlashModeClick: (flashMode: FlashModeStatus) -> Unit,
onDemoSwitchClick: (Boolean) -> Unit,
onDemoMultipleClick: (DemoMultipleStatus) -> Unit,
shouldShowQuickSetting: IsExpandedQuickSetting,
setVisibleQuickSetting: (IsExpandedQuickSetting) -> Unit
) {
Expand All @@ -152,6 +163,12 @@ private fun ExpandedQuickSettingsUi(
currentFacingFront = currentCameraSettings.default_front_camera
)
},
{
DemoSetSwitch(onClick = onDemoSwitchClick, currentDemoSwitchValue = currentCameraSettings.demo_switch)
},
{
DemoMultiple(onClick = { setVisibleQuickSetting(IsExpandedQuickSetting.DEMO) }, assignedValue = currentCameraSettings.demo_multiple)
}
//TODO: Implement Set Ratio
/*
{
Expand All @@ -171,6 +188,9 @@ private fun ExpandedQuickSettingsUi(
if (shouldShowQuickSetting == IsExpandedQuickSetting.ASPECT_RATIO) {
ExpandedQuickSetRatio(setRatio = {}, currentRatio = 1)
}
else if (shouldShowQuickSetting == IsExpandedQuickSetting.DEMO) {
ExpandedDemoMultiple(onClick = onDemoMultipleClick, currentDemoMultipleStatus = currentCameraSettings.demo_multiple)
}
}
Spacer(modifier = Modifier.height(dimensionResource(id = R.dimen.quick_settings_spacer_height)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.jetpackcamera.feature.quicksettings.CameraAspectRatio
import com.google.jetpackcamera.feature.quicksettings.CameraDemoExpandedSetting
import com.google.jetpackcamera.feature.quicksettings.CameraDemoSwitch
import com.google.jetpackcamera.feature.quicksettings.CameraFlashMode
import com.google.jetpackcamera.feature.quicksettings.CameraLensFace
import com.google.jetpackcamera.quicksettings.R
import com.google.jetpackcamera.settings.model.DemoMultipleStatus
import com.google.jetpackcamera.settings.model.FlashModeStatus
import kotlin.math.min

Expand Down Expand Up @@ -120,6 +123,79 @@ fun QuickFlipCamera(flipCamera: (Boolean) -> Unit, currentFacingFront: Boolean)
)
}

@Composable
fun ExpandedDemoMultiple(
onClick: (DemoMultipleStatus) -> Unit,
currentDemoMultipleStatus: DemoMultipleStatus
) {
val buttons: Array<@Composable () -> Unit> = arrayOf(
{
DemoMultiple(
onClick = { onClick(DemoMultipleStatus.APPLE) },
assignedValue = DemoMultipleStatus.APPLE,
isHighlighted = currentDemoMultipleStatus == DemoMultipleStatus.APPLE
)
},
{
DemoMultiple(
onClick = { onClick(DemoMultipleStatus.BANANA) },
assignedValue = DemoMultipleStatus.BANANA,
isHighlighted = currentDemoMultipleStatus == DemoMultipleStatus.BANANA
)
},
{
DemoMultiple(
onClick = { onClick(DemoMultipleStatus.CANTALOUPE) },
assignedValue = DemoMultipleStatus.CANTALOUPE,
isHighlighted = currentDemoMultipleStatus == DemoMultipleStatus.CANTALOUPE
)
}
)
ExpandedQuickSetting(quickSettingButtons = buttons)
}

@Composable
fun DemoMultiple(
onClick: () -> Unit,
assignedValue: DemoMultipleStatus,
isHighlighted: Boolean = false
) {
val enum = when (assignedValue) {
DemoMultipleStatus.APPLE -> CameraDemoExpandedSetting.APPLE
DemoMultipleStatus.BANANA -> CameraDemoExpandedSetting.BANANA
DemoMultipleStatus.CANTALOUPE -> CameraDemoExpandedSetting.CANTALOUPE
}
QuickSettingUiItem(
drawableResId = enum.getDrawableResId(),
text = stringResource(id = enum.getTextResId()),
accessibilityText = stringResource(id = enum.getDescriptionResId()),
onClick = { onClick() },
isHighLighted = isHighlighted
)
}

@Composable
fun DemoSetSwitch(
onClick: (Boolean) -> Unit,
currentDemoSwitchValue: Boolean,
isHighlighted: Boolean = false
) {
val enum = when (currentDemoSwitchValue) {
true -> CameraDemoSwitch.TRUE
false -> CameraDemoSwitch.FALSE
}
QuickSettingUiItem(
drawableResId = enum.getDrawableResId(),
text = stringResource(id = enum.getTextResId()),
accessibilityText = stringResource(id = enum.getDescriptionResId()),
isHighLighted = isHighlighted,
onClick =
{
onClick(!currentDemoSwitchValue)
}
)
}

@Composable
fun DropDownIcon(toggleDropDown: () -> Unit, isOpen: Boolean) {
Row(
Expand Down

0 comments on commit 45445f9

Please sign in to comment.