-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
322 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/ComposeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.ixam97.carStatsViewer.compose | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.background | ||
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.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.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Divider | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.unit.dp | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
import com.ixam97.carStatsViewer.compose.components.CarIconButton | ||
import com.ixam97.carStatsViewer.compose.components.CarSwitchRow | ||
import com.ixam97.carStatsViewer.compose.theme.ComposeTestTheme | ||
import com.ixam97.carStatsViewer.compose.theme.Typography | ||
import com.ixam97.carStatsViewer.compose.theme.darkBackground | ||
import com.ixam97.carStatsViewer.compose.theme.headerBackground | ||
import com.ixam97.carStatsViewer.utils.InAppLogger | ||
|
||
class ComposeActivity: ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setTheme(R.style.AppTheme) | ||
|
||
val brand = CarStatsViewer.dataProcessor.staticVehicleData.vehicleMake | ||
|
||
InAppLogger.d("brand: $brand") | ||
|
||
setContent { | ||
|
||
ComposeTestTheme(brand) { | ||
|
||
val composeViewModel: ComposeViewModel = viewModel() | ||
|
||
val composeActivityState by composeViewModel.composeActivityState.collectAsState() | ||
|
||
Box(modifier = Modifier | ||
.fillMaxSize() | ||
.padding(15.dp) | ||
.clip(RoundedCornerShape(10.dp)) | ||
.background(color = darkBackground) | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.background(color = headerBackground), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
CarIconButton(onCLick = { finish() }, iconResId = R.drawable.ic_arrow_back) | ||
Spacer(modifier = Modifier.width(10.dp)) | ||
Text(text = "Hello World!", style = Typography.h1) | ||
} | ||
Divider( | ||
modifier = Modifier.height(3.dp), | ||
color = MaterialTheme.colors.secondary | ||
) | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
) { | ||
CarSwitchRow( | ||
switchState = composeActivityState.switchStates[0], | ||
onClick = { composeViewModel.setSwitch(0, !composeActivityState.switchStates[0]) } | ||
) { | ||
Text(text = "Row 1") | ||
} | ||
CarSwitchRow( | ||
switchState = composeActivityState.switchStates[1], | ||
onClick = { composeViewModel.setSwitch(1, !composeActivityState.switchStates[1]) } | ||
) { | ||
Text(text = "Row 2") | ||
} | ||
CarSwitchRow( | ||
switchState = composeActivityState.switchStates[2], | ||
onClick = { composeViewModel.setSwitch(2, !composeActivityState.switchStates[2]) } | ||
) { | ||
Text(text = "Row 3") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/ComposeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.ixam97.carStatsViewer.compose | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.update | ||
|
||
class ComposeViewModel: ViewModel() { | ||
|
||
data class ComposeActivityState( | ||
val switchStates: List<Boolean> = listOf(false, false, false) | ||
) | ||
|
||
private val _composeActivityState = MutableStateFlow(ComposeActivityState()) | ||
val composeActivityState = _composeActivityState.asStateFlow() | ||
|
||
fun setSwitch(switchIndex: Int, value: Boolean) { | ||
if (switchIndex >= _composeActivityState.value.switchStates.size || switchIndex < 0) return | ||
|
||
_composeActivityState.update { | ||
val newSwitchStates = it.switchStates.toMutableList() | ||
newSwitchStates[switchIndex] = value | ||
it.copy(switchStates = newSwitchStates) | ||
} | ||
} | ||
|
||
} | ||
|
29 changes: 29 additions & 0 deletions
29
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/components/CarIconButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.ixam97.carStatsViewer.compose.components | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
|
||
@Composable | ||
fun CarIconButton(onCLick: () -> Unit, @DrawableRes iconResId: Int) { | ||
IconButton( | ||
modifier = Modifier | ||
.padding(10.dp) | ||
.size(70.dp), | ||
onClick = onCLick | ||
) { | ||
Icon( | ||
painterResource(id = iconResId), | ||
tint = MaterialTheme.colors.secondary, | ||
contentDescription = null | ||
) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/components/CarSwitchRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ixam97.carStatsViewer.compose.components | ||
|
||
import androidx.compose.foundation.clickable | ||
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.unit.dp | ||
|
||
@Composable | ||
fun CarSwitchRow( | ||
switchState: Boolean, | ||
onClick: () -> Unit, | ||
content: @Composable () -> Unit | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.height(100.dp) | ||
.clickable { onClick() } | ||
.padding(horizontal = 30.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
content() | ||
Spacer(modifier = Modifier.weight(1f)) | ||
Switch( | ||
modifier = Modifier | ||
.scale(2f) | ||
.padding(horizontal = 10.dp), | ||
checked = switchState, | ||
onCheckedChange = { onClick() } | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/theme/Color.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.ixam97.carStatsViewer.compose.theme | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
val polestarOrange = Color(0xFFD96C00) | ||
val volvoBlue = Color(0xFF2F6093) | ||
|
||
val darkBackground = Color(0xFF1B1B1B) | ||
val mainBackground = Color(0xFF1F1F1F) | ||
val headerBackground = Color(0xFF282A2D) | ||
val primaryButtonGray = Color(0xFF3E4146) | ||
val primaryGray = Color(0xFF7B858A) | ||
val secondaryGray = Color(0xFFA3B1B8) |
11 changes: 11 additions & 0 deletions
11
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/theme/Shape.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ixam97.carStatsViewer.compose.theme | ||
|
||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Shapes | ||
import androidx.compose.ui.unit.dp | ||
|
||
val Shapes = Shapes( | ||
small = RoundedCornerShape(4.dp), | ||
medium = RoundedCornerShape(4.dp), | ||
large = RoundedCornerShape(0.dp) | ||
) |
34 changes: 34 additions & 0 deletions
34
automotive/src/carapp/java/com/ixam97/carStatsViewer/compose/theme/Theme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.ixam97.carStatsViewer.compose.theme | ||
|
||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.darkColors | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.graphics.Color | ||
|
||
private fun carAppColorPalate(primaryColor: Color? = null) = darkColors( | ||
primary = primaryColor ?: primaryGray, | ||
secondary = primaryColor ?: secondaryGray, | ||
background = darkBackground, | ||
onBackground = Color.White, | ||
surface = darkBackground, | ||
onSurface = Color.White, | ||
onPrimary = Color.White | ||
) | ||
|
||
@Composable | ||
fun ComposeTestTheme(carMake: String? = null, content: @Composable () -> Unit) { | ||
val colors = carAppColorPalate( | ||
primaryColor = when (carMake) { | ||
"Polestar" -> polestarOrange | ||
"Volvo" -> volvoBlue | ||
else -> null | ||
} | ||
) | ||
|
||
MaterialTheme( | ||
colors = colors, | ||
typography = Typography, | ||
shapes = Shapes, | ||
content = content | ||
) | ||
} |
Oops, something went wrong.