Skip to content

Commit

Permalink
expanded settings layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixam97 committed Aug 17, 2024
1 parent 209cc15 commit 1f87ae3
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class ComposeSettingsActivity: ComponentActivity() {
if (it.consume() == true) finish()
}

CarTheme( if (themeSetting.value == 0) Build.BRAND else null ) {
val brand = when (themeSetting.value) {
0 -> Build.BRAND
2 -> "Orange"
else -> null
}

CarTheme(brand) {
SettingsScreen(viewModel = settingsViewModel)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.ixam97.carStatsViewer.compose

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ixam97.carStatsViewer.BuildConfig
import com.ixam97.carStatsViewer.CarStatsViewer
import com.ixam97.carStatsViewer.utils.InAppLogger
import kotlinx.coroutines.Dispatchers
Expand All @@ -19,13 +23,16 @@ class SettingsViewModel: ViewModel() {
val isInitialized: Boolean = false,
val detailedNotifications: Boolean = false,
val altConsumptionUnit: Boolean = false,
val showConsumptionGages: Boolean = false,
val showChargingGages: Boolean = false,
val locationTracking: Boolean = false,
val autoAppStart: Boolean = false,
val phoneNotification: Boolean = false,
val selectedTripType: Int = 0,
val selectedConnection: Int = 0,
val primaryPlotColor: Int = 0,
val secondaryPlotColor: Int = 0
val secondaryConsumptionPlotColor: Int = 0,
val secondaryChargePlotColor: Int = 0
)

private val _themeSettingState = MutableStateFlow<Int>(0)
Expand All @@ -34,43 +41,57 @@ class SettingsViewModel: ViewModel() {
private val _finishActivityLiveData = MutableLiveData<Event<Boolean>>()
val finishActivityLiveData: LiveData<Event<Boolean>> = _finishActivityLiveData

private val _settingsStateFlow = MutableStateFlow(SettingsState())
val settingsStateFlow = _settingsStateFlow.asStateFlow()
// private val _settingsStateFlow = MutableStateFlow(SettingsState())
// val settingsStateFlow = _settingsStateFlow.asStateFlow()

var isDevEnabled by mutableStateOf(BuildConfig.FLAVOR_version != "dev")
private set

var settingsState by mutableStateOf(SettingsState())
// private set

private var versionClickedNum: Int = 0

init {
val preferences = CarStatsViewer.appPreferences
viewModelScope.launch {
withContext(Dispatchers.IO) {
_settingsStateFlow.update {
it.copy(
isInitialized = true,
detailedNotifications = preferences.notifications,
altConsumptionUnit = preferences.consumptionUnit,
locationTracking = preferences.useLocation,
autoAppStart = preferences.autostart,
phoneNotification = preferences.phoneNotification,
selectedTripType = preferences.mainViewTrip,
selectedConnection = preferences.mainViewConnectionApi,
primaryPlotColor = 0,
secondaryPlotColor = if (preferences.consumptionPlotSecondaryColor) 1 else 0
)
}
// _settingsStateFlow.update {
// it.copy(
// isInitialized = true,
// detailedNotifications = preferences.notifications,
// altConsumptionUnit = preferences.consumptionUnit,
// showChargingGages = preferences.chargePlotVisibleGages,
// showConsumptionGages = preferences.chargePlotVisibleGages,
// locationTracking = preferences.useLocation,
// autoAppStart = preferences.autostart,
// phoneNotification = preferences.phoneNotification,
// selectedTripType = preferences.mainViewTrip,
// selectedConnection = preferences.mainViewConnectionApi,
// primaryPlotColor = 0,
// secondaryPlotColor = if (preferences.consumptionPlotSecondaryColor) 1 else 0
// )
// }
settingsState = settingsState.copy(
isInitialized = true,
detailedNotifications = preferences.notifications,
altConsumptionUnit = preferences.consumptionUnit,
showChargingGages = preferences.chargePlotVisibleGages,
showConsumptionGages = preferences.chargePlotVisibleGages,
locationTracking = preferences.useLocation,
autoAppStart = preferences.autostart,
phoneNotification = preferences.phoneNotification,
selectedTripType = preferences.mainViewTrip,
selectedConnection = preferences.mainViewConnectionApi,
primaryPlotColor = 0,
secondaryConsumptionPlotColor = if (preferences.consumptionPlotSecondaryColor) 1 else 0,
secondaryChargePlotColor = if (preferences.chargePlotSecondaryColor) 1 else 0
)
}
}
}

fun finishActivity() = _finishActivityLiveData.postValue(Event(true))
fun setLocationTracking(locationTracking: Boolean) {
_settingsStateFlow.update { it.copy(locationTracking = locationTracking) }
}

fun setAltConsumptionUnit(altConsumptionUnit: Boolean) {
_settingsStateFlow.update { it.copy(altConsumptionUnit = altConsumptionUnit) }
}

fun setAutoAppStart(autoAppStart: Boolean) {
_settingsStateFlow.update { it.copy(autoAppStart = autoAppStart) }
}

fun setTheme(themeIndex: Int) {
_themeSettingState.update { themeIndex }
Expand All @@ -81,4 +102,11 @@ class SettingsViewModel: ViewModel() {
super.onCleared()
}

fun versionClick() {
versionClickedNum++
if (versionClickedNum >= 7) {
isDevEnabled = true
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.compose.theme.CarTheme
import com.ixam97.carStatsViewer.compose.theme.LocalBrushes

@Composable
fun CarGradientButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
active: Boolean = false,
gradient: Brush = CarTheme.activeElementBrush,
gradient: Brush = CarTheme.brushes.activeElementBrush,
shape: Shape = RoundedCornerShape(CarTheme.buttonCornerRadius),
contentPadding: PaddingValues = CarTheme.buttonPaddingValues,
content: @Composable (RowScope.() -> Unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.R
import com.ixam97.carStatsViewer.compose.theme.CarTheme
import com.ixam97.carStatsViewer.compose.theme.LocalBrushes

@Composable
fun CarHeader(
title: String,
onBackClick: (() -> Unit)? = null,
minimal: Boolean = false
minimal: Boolean = false,
headerLineBrush: Brush = CarTheme.brushes.headerLineBrush
) {
Column {
Row(
Expand All @@ -47,7 +50,7 @@ fun CarHeader(
.height(3.dp)
.fillMaxWidth()
.background(
brush = CarTheme.headerLineBrush
brush = headerLineBrush
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.Dp
Expand All @@ -39,6 +40,7 @@ fun CarRow(
leadingContent: ( @Composable () -> Unit)? = null,
trailingContent: ( @Composable () -> Unit)? = null,
@DrawableRes iconResId: Int? = null,
iconImageVector: ImageVector? = null,
browsable: Boolean = false,
external: Boolean = false,
onClick: (() -> Unit)? = null,
Expand Down Expand Up @@ -76,6 +78,16 @@ fun CarRow(
tint = if (enabled) Color.White else disabledTextColor
)
Spacer(modifier = Modifier.size(24.dp))
} else if (iconImageVector != null) {
Icon(
modifier = Modifier
.height(minHeight.coerceAtLeast(50.dp))
.width(50.dp),
imageVector = iconImageVector,
contentDescription = null,
tint = if (enabled) Color.White else disabledTextColor
)
Spacer(modifier = Modifier.size(24.dp))
}
Row(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.ixam97.carStatsViewer.compose.theme.CarTheme
import com.ixam97.carStatsViewer.compose.theme.LocalBrushes

@Composable
fun CarSegmentedButton(
Expand All @@ -36,7 +37,7 @@ fun CarSegmentedButton(
selectedIndex: Int,
onSelectedIndexChanged: (index: Int) -> Unit,
enabled: Boolean = true,
gradient: Brush = CarTheme.activeElementBrush,
gradient: Brush = CarTheme.brushes.activeElementBrush,
contentPadding: PaddingValues = CarTheme.buttonPaddingValues,
shape: Shape = RoundedCornerShape(CarTheme.buttonCornerRadius),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import androidx.compose.ui.unit.dp
@Composable
fun CarSwitchRow(
switchState: Boolean,
onClick: () -> Unit,
onClick: (newState: Boolean) -> Unit,
content: @Composable () -> Unit
) {
Row(
modifier = Modifier
.heightIn(min = 100.dp)
.clickable { onClick() }
.clickable { onClick(!switchState) }
.padding(horizontal = 30.dp),
verticalAlignment = Alignment.CenterVertically
) {
Expand Down
Loading

0 comments on commit 1f87ae3

Please sign in to comment.