Skip to content

Commit

Permalink
added side tab view and multi select
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixam97 committed Jun 3, 2024
1 parent aa818ef commit 5704859
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal fun CarStatsViewerScreen.MenuList() = ListTemplate.Builder().apply {
}.build())
addItem(Row.Builder().apply {
setTitle(carContext.getString(R.string.car_app_show_real_time_data_title))
addText(carContext.getString(R.string.car_app_show_real_time_data_hint))
addText("Lorem ipsum dolor sit amet")// carContext.getString(R.string.car_app_show_real_time_data_hint))
setToggle(Toggle.Builder {
appPreferences.carAppRealTimeData = it
invalidateTabView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Switch
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.scale
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.unit.dp

@Composable
Expand All @@ -31,8 +30,11 @@ fun CarSwitchRow(
Spacer(modifier = Modifier.weight(1f))
Switch(
modifier = Modifier
.scale(2f)
.padding(horizontal = 10.dp),
// .scale(2f)
.graphicsLayer(
transformOrigin = TransformOrigin(1f,.5f),
scaleX = 2f,
scaleY = 2f),
checked = switchState,
onCheckedChange = null
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.ixam97.carStatsViewer.compose.components

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.coerceAtLeast
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.R
import com.ixam97.carStatsViewer.compose.theme.disabledOverlayColor
import com.ixam97.carStatsViewer.compose.theme.polestarOrange

@Composable
fun Polestar2MultiSelect(
modifier: Modifier = Modifier,
title: String,
text: String? = null,
options: List<String>,
onIndexChanged: (index: Int) -> Unit,
selectedIndex: Int,
enabled: Boolean = true
) {
Box(modifier = modifier) {
Column {

Polestar2Row(
title = title,
text = text,
enabled = enabled,
minHeight = 0.dp
)

var size by remember {
mutableStateOf(IntSize.Zero)
}
Box(
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 6.dp)
.height(101.dp)
.padding(horizontal = 24.dp)
.background(colorResource(id = R.color.default_button_color))
.onSizeChanged { size = it }
) {

Row (
modifier = Modifier
.fillMaxSize()
) {
options.forEachIndexed { index, s ->
Spacer(modifier = Modifier.weight(1f))
if (index < options.size - 1) {
Divider(
modifier = Modifier
.width(2.dp)
.fillMaxHeight()
.padding(vertical = 20.dp)
)
}
}
}

val animatedLeftPadding = animateDpAsState(targetValue = with(LocalDensity.current) { ((size.width.toFloat() / options.size) * selectedIndex).toDp() - 2.dp})

Box(
modifier = Modifier
.fillMaxHeight()
.padding(start = animatedLeftPadding.value.coerceAtLeast(0.dp))
.width(with(LocalDensity.current) { (size.width.toFloat() / options.size).toDp() + if (selectedIndex == 0) 2.dp else 4.dp })
.background(polestarOrange)
)

Row(
modifier = Modifier
.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically
) {
options.forEachIndexed { index, s ->
Column(
modifier = Modifier
.clickable(enabled = enabled) {
onIndexChanged(index)
}
.fillMaxHeight()
.weight(1f),
verticalArrangement = Arrangement.Center
) {
Text(
modifier = Modifier
.fillMaxWidth(),
text = s,
textAlign = TextAlign.Center,
)
}
}
}

if (!enabled) {
Box(
modifier = Modifier
.fillMaxSize()
.background(disabledOverlayColor)
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fun Polestar2Radiobutton(
Spacer(modifier = Modifier.width(20.dp))
Column(
modifier = Modifier
.size(101.dp)
.padding(vertical = 6.dp),
.padding(vertical = 6.dp)
.size(101.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -20,6 +21,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.coerceAtLeast
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.R
import com.ixam97.carStatsViewer.compose.theme.disabledTextColor
Expand All @@ -31,15 +34,16 @@ fun Polestar2Row(
text: String? = null,
@DrawableRes iconResId: Int? = null,
onClick: (() -> Unit)? = null,
enabled: Boolean = true
enabled: Boolean = true,
minHeight: Dp = 113.dp
) {
val rowModifier = if (onClick != null) {
modifier
.clickable(onClick = onClick, enabled = enabled)
.defaultMinSize(minHeight = 101.dp)
.defaultMinSize(minHeight = minHeight)
} else {
modifier
.defaultMinSize(minHeight = 101.dp)
.defaultMinSize(minHeight = minHeight)
}
Row (
modifier = rowModifier
Expand All @@ -49,7 +53,7 @@ fun Polestar2Row(
if (iconResId != null) {
Icon(
modifier = Modifier
.height(101.dp)
.height(minHeight.coerceAtLeast(80.dp))
.width(80.dp),
painter = painterResource(id = iconResId),
contentDescription = null,
Expand All @@ -58,18 +62,20 @@ fun Polestar2Row(
Spacer(modifier = Modifier.size(24.dp))
}
Row(
modifier = Modifier
.defaultMinSize(minHeight = minHeight),
verticalAlignment = Alignment.CenterVertically
) {
Column(
modifier = Modifier
.weight(1f)
.defaultMinSize(minHeight = 101.dp)
.padding(vertical = 21.dp),
.fillMaxSize()
.padding(top = 21.dp, bottom = 15.dp),
verticalArrangement = Arrangement.Center
) {
Text(text = title, color = if (enabled) Color.White else disabledTextColor)
if (text != null) {
Spacer(modifier = Modifier.size(20.dp))
Spacer(modifier = Modifier.size(15.dp))
Text(
text = text,
color = if (enabled) colorResource(id = R.color.secondary_text_color) else disabledTextColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -55,9 +56,9 @@ fun Polestar2Switch(
Spacer(modifier = Modifier.width(20.dp))
Box(
modifier = Modifier
.padding(vertical = 6.dp)
.height(101.dp)
.width(288.dp)
.padding(vertical = 6.dp)
.background(colorResource(id = R.color.default_button_color))
) {
Box(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.ixam97.carStatsViewer.compose.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.R

@Composable
fun SideTabLayout(
modifier: Modifier = Modifier,
tabs: List<SideTab>,
tabsColumnWidth: Dp?
) {
var selectedIndex by remember { mutableStateOf(0) }
Box(modifier = modifier) {
Row {
Column(
modifier = Modifier
.width(IntrinsicSize.Min)
.fillMaxHeight()
.background(colorResource(id = R.color.slideup_activity_background)),
// verticalArrangement = Arrangement.spacedBy(30.dp)
) {
tabs.forEachIndexed { index, tab ->
Text(
modifier = Modifier
.clickable { selectedIndex = index }
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 30.dp),
text = tab.tabTitle,
style = MaterialTheme.typography.h2,
color = if (index == selectedIndex) MaterialTheme.colors.secondary else Color.White
)
}
}
Column(
modifier = Modifier.fillMaxSize()
) {
tabs[selectedIndex].tabContent()
}
}
}
}

data class SideTab(
val tabTitle: String,
val tabContent: @Composable () -> Unit
)
Loading

0 comments on commit 5704859

Please sign in to comment.