Claude refactoring
This commit is contained in:
@@ -4,7 +4,6 @@ import android.content.Context
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
|
||||
@@ -6,13 +6,13 @@ import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -22,45 +22,83 @@ import com.kouros.data.R
|
||||
import com.kouros.navigation.data.StepData
|
||||
import com.kouros.navigation.utils.round
|
||||
|
||||
private const val MANEUVER_TYPE_EXIT_RIGHT = 45
|
||||
private const val MANEUVER_TYPE_EXIT_LEFT = 46
|
||||
private const val METERS_PER_KILOMETER = 1000.0
|
||||
private const val DISTANCE_THRESHOLD_METERS = 1000
|
||||
|
||||
private val CardTopPadding = 60.dp
|
||||
private val CardElevation = 6.dp
|
||||
private val IconSize = 48.dp
|
||||
private val ExitTextSize = 18.sp
|
||||
private val PrimaryTextSize = 24.sp
|
||||
private val SpacerWidth = 8.dp
|
||||
private val CardPadding = 16.dp
|
||||
private val ElementSpacing = 8.dp
|
||||
|
||||
@Composable
|
||||
fun NavigationInfo(step: StepData?, nextStep: StepData?) {
|
||||
if (step != null && step.instruction.isNotEmpty()) {
|
||||
fun NavigationInfo(
|
||||
step: StepData?,
|
||||
nextStep: StepData?
|
||||
) {
|
||||
step?.takeIf { it.instruction.isNotEmpty() }?.let { currentStep ->
|
||||
ElevatedCard(
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 6.dp
|
||||
|
||||
), modifier = Modifier
|
||||
.padding(top = 60.dp)
|
||||
elevation = CardDefaults.cardElevation(defaultElevation = CardElevation),
|
||||
modifier = Modifier
|
||||
.padding(top = CardTopPadding)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Column {
|
||||
Column(
|
||||
modifier = Modifier.padding(CardPadding),
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(step.icon),
|
||||
contentDescription = stringResource(id = R.string.accept_action_title),
|
||||
modifier = Modifier.size(48.dp, 48.dp),
|
||||
painter = painterResource(currentStep.icon),
|
||||
contentDescription = stringResource(id = R.string.navigation_icon_description),
|
||||
modifier = Modifier.size(IconSize),
|
||||
tint = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
if (step.currentManeuverType == 46
|
||||
|| step.currentManeuverType == 45
|
||||
) {
|
||||
Text(text = "Exit ${step.exitNumber}", fontSize = 18.sp)
|
||||
}
|
||||
Row {
|
||||
if (step.leftStepDistance < 1000) {
|
||||
Text(text = "${step.leftStepDistance.toInt()} m", fontSize = 24.sp, color = MaterialTheme.colorScheme.primary)
|
||||
} else {
|
||||
Text(
|
||||
text = "${(step.leftStepDistance / 1000).round(1)} km",
|
||||
fontSize = 24.sp,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
Spacer(
|
||||
modifier = Modifier.padding(5.dp)
|
||||
|
||||
if (currentStep.isExitManeuver) {
|
||||
Text(
|
||||
text = stringResource(R.string.exit_number, currentStep.exitNumber),
|
||||
fontSize = ExitTextSize,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
modifier = Modifier.padding(top = ElementSpacing)
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(top = ElementSpacing)
|
||||
) {
|
||||
DistanceText(distance = currentStep.leftStepDistance)
|
||||
Spacer(modifier = Modifier.padding(horizontal = SpacerWidth))
|
||||
Text(
|
||||
text = currentStep.instruction,
|
||||
fontSize = PrimaryTextSize,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
Text(text = step.instruction, fontSize = 24.sp, color = MaterialTheme.colorScheme.primary)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DistanceText(distance: Double) {
|
||||
val formattedDistance = when {
|
||||
distance < DISTANCE_THRESHOLD_METERS -> "${distance.toInt()} m"
|
||||
else -> "${(distance / METERS_PER_KILOMETER).round(1)} km"
|
||||
}
|
||||
|
||||
Text(
|
||||
text = formattedDistance,
|
||||
fontSize = PrimaryTextSize,
|
||||
color = MaterialTheme.colorScheme.primary
|
||||
)
|
||||
}
|
||||
|
||||
private val StepData.isExitManeuver: Boolean
|
||||
get() = currentManeuverType == MANEUVER_TYPE_EXIT_RIGHT ||
|
||||
currentManeuverType == MANEUVER_TYPE_EXIT_LEFT
|
||||
Reference in New Issue
Block a user