Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
30b3f57
Update MapsScreen.kt
ChrisRoe2004 Mar 10, 2026
e19465d
Update UserPreferencesRepository.kt
ChrisRoe2004 Mar 24, 2026
bbf07d8
Update UserPreferencesRepository.kt
ChrisRoe2004 Mar 24, 2026
49e304b
Update UserPreferencesRepository.kt
ChrisRoe2004 Mar 24, 2026
5d67d7b
Update UserPreferencesRepository.kt
ChrisRoe2004 Mar 24, 2026
b1763d3
Update MapsViewModel.kt
ChrisRoe2004 Mar 27, 2026
6ad4242
Update MapsViewModel.kt
ChrisRoe2004 Mar 27, 2026
f9716e7
Update MapsViewModel.kt
ChrisRoe2004 Mar 27, 2026
9fa16ae
Update MapsScreen.kt
ChrisRoe2004 Mar 27, 2026
e3b1b61
Update MapsScreen.kt
ChrisRoe2004 Mar 27, 2026
62d233a
Update MapsScreen.kt
ChrisRoe2004 Mar 27, 2026
f023677
Update SettingsScreen.kt
ChrisRoe2004 Mar 27, 2026
5904612
Update SettingsScreen.kt
ChrisRoe2004 Mar 27, 2026
4c00494
Update SettingsScreen.kt
ChrisRoe2004 Mar 27, 2026
5e9b6d3
Update SettingsScreen.kt
ChrisRoe2004 Mar 27, 2026
a34ba65
Update SettingsScreen.kt
ChrisRoe2004 Mar 27, 2026
19a415e
Update VehicleLocation.kt
ChrisRoe2004 Apr 10, 2026
0e24b3d
Update UserPreferencesRepository.kt
ChrisRoe2004 Apr 10, 2026
37e7f00
Update UserPreferencesRepository.kt
ChrisRoe2004 Apr 10, 2026
87c0350
Update UserPreferencesRepository.kt
ChrisRoe2004 Apr 10, 2026
885161a
Update MapsViewModel.kt
ChrisRoe2004 Apr 10, 2026
dd7ab96
Update MapsViewModel.kt
ChrisRoe2004 Apr 10, 2026
51de378
Update MapsViewModel.kt
ChrisRoe2004 Apr 10, 2026
5689c9d
Update MapsScreen.kt
ChrisRoe2004 Apr 10, 2026
cef1ec7
Update MapsScreen.kt
ChrisRoe2004 Apr 10, 2026
01c5a4d
Update MapsScreen.kt
ChrisRoe2004 Apr 10, 2026
a9144d0
Update MapsScreen.kt
ChrisRoe2004 Apr 10, 2026
80c1f4c
Update DevMenuScreen.kt
ChrisRoe2004 Apr 10, 2026
1182d7c
Update DevMenuScreen.kt
ChrisRoe2004 Apr 10, 2026
82431dc
Update DevMenuScreen.kt
ChrisRoe2004 Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class VehicleLocation(
@SerializedName("speed_mph") val speedMph: Double,
@SerializedName("route_name") val routeName: String,
@SerializedName("timestamp") val date: String,
@SerializedName("heading_degrees") val headingDegrees: Int?,
) {
/**
* Turns the date stored into a time of a generalized time ago from current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class UserPreferencesRepository
private val DEV_OPTIONS_ACTIVE = booleanPreferencesKey("dev_options_active")
private val THEME_MODE = stringPreferencesKey("theme_mode")
private val MAP_TYPE = stringPreferencesKey("map_type")
private val SHUTTLE_ANIMATIONS = booleanPreferencesKey("shuttle-animations")
private val SHUTTLE_ROTATION = booleanPreferencesKey("shuttle_rotation")
}

suspend fun getUserId(): String =
Expand Down Expand Up @@ -198,4 +200,28 @@ class UserPreferencesRepository
}
}
}

fun getShuttleAnimations(): Flow<Boolean> =
dataStore.data.map {
it[SHUTTLE_ANIMATIONS] ?:
true
}

suspend fun saveShuttleAnimations(animationsEnable: Boolean) {
dataStore.edit {
it[SHUTTLE_ANIMATIONS] = animationsEnable
}
}

fun getShuttleRotation(): Flow<Boolean> =
dataStore.data.map {
it[SHUTTLE_ROTATION] ?: false
}

suspend fun saveShuttleRotations(rotationsEnable: Boolean) {
dataStore.edit {
it[SHUTTLE_ROTATION] = rotationsEnable
}
}

}
45 changes: 40 additions & 5 deletions app/src/main/java/edu/rpi/shuttletracker/ui/maps/MapsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package edu.rpi.shuttletracker.ui.maps
import android.Manifest
import android.content.pm.PackageManager
import android.location.Location
import androidx.compose.animation.core.tween
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -233,6 +234,8 @@ private fun ShuttleMap(
mapsUiState.vehicleLocations.values.forEach {
VehicleMarker(
vehicleLocation = it,
animationsEnabled = mapsUiState.shuttleAnimationsEnabled,
rotationEnabled = mapsUiState.shuttleRotationEnabled,
)
}

Expand Down Expand Up @@ -346,13 +349,43 @@ private fun StopMarker(
* Creates a marker for a vehicle
* */
@Composable
private fun VehicleMarker(vehicleLocation: VehicleLocation) {
private fun VehicleMarker(vehicleLocation: VehicleLocation, animationsEnabled: Boolean, rotationEnabled: Boolean,) {
val context = LocalContext.current
val markerState = rememberUpdatedMarkerState(position = vehicleLocation.latLng())
val target = vehicleLocation.latLng()
val heading = vehicleLocation.headingDegrees?.toFloat() ?: 0f

val lat = remember { androidx.compose.animation.core.Animatable(target.latitude.toFloat()) }
val lng = remember { androidx.compose.animation.core.Animatable(target.longitude.toFloat()) }

val markerState = rememberUpdatedMarkerState(
position = LatLng(lat.value.toDouble(), lng.value.toDouble())
)

LaunchedEffect(target,animationsEnabled) {
if (animationsEnabled) {
launch {
lat.animateTo(
target.latitude.toFloat(),
animationSpec = tween(durationMillis = 2000),
)
}

launch {
lng.animateTo(
target.longitude.toFloat(),
animationSpec = tween(durationMillis = 2000),
)
}
}

else {

lat.snapTo(target.latitude.toFloat())
lng.snapTo(target.longitude.toFloat())

}


// every time the vehicle changes, update the position of the marker
LaunchedEffect(vehicleLocation) {
markerState.position = vehicleLocation.latLng()
}

val vehicleColor =
Expand Down Expand Up @@ -385,6 +418,8 @@ private fun VehicleMarker(vehicleLocation: VehicleLocation) {
snippet = snippetText,
anchor = Offset(0.5f, 0.5f),
zIndex = 3f,
rotation = if (rotationEnabled) heading else 0f,
flat = rotationEnabled,
onClick = {
it.showInfoWindow()
true
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/edu/rpi/shuttletracker/ui/maps/MapsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ class MapsViewModel
it.copy(mapType = mapType)
}
}.launchIn(viewModelScope)

userPreferencesRepository
.getShuttleAnimations()
.flowOn(Dispatchers.Default)
.onEach { animationsEnable ->
_mapsUiState.update {
it.copy(shuttleAnimationsEnabled = animationsEnable)
}
}.launchIn(viewModelScope)

userPreferencesRepository
.getShuttleRotation()
.flowOn(Dispatchers.Default)
.onEach { rotationEnable ->
_mapsUiState.update {
it.copy(shuttleRotationEnabled = rotationEnable)
}
}.launchIn(viewModelScope)
}

fun updateMapType(mapType: MapType) {
Expand All @@ -155,6 +173,21 @@ class MapsViewModel
updateMapType(next)
}

fun setShuttleAnimations(animationsEnable: Boolean) {
viewModelScope.launch {
userPreferencesRepository.saveShuttleAnimations(animationsEnable)

}

}

fun setShuttleRotation(rotationEnable: Boolean) {
viewModelScope.launch {
userPreferencesRepository.saveShuttleRotations(rotationEnable)
}
}


/**
* Reads the network response and maps it to correct place
* */
Expand Down Expand Up @@ -198,4 +231,6 @@ data class MapsUiState(
val totalAnnouncements: Int = -1,
val themeMode: ThemeMode = ThemeMode.System,
val mapType: MapType = MapType.NORMAL,
val shuttleAnimationsEnabled: Boolean = true,
val shuttleRotationEnabled: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.ramcosta.composedestinations.generated.destinations.DevMenuScreenDest
import com.ramcosta.composedestinations.generated.destinations.SetupScreenDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import edu.rpi.shuttletracker.R
import edu.rpi.shuttletracker.ui.maps.MapsViewModel
import edu.rpi.shuttletracker.ui.theme.ThemeMode
import edu.rpi.shuttletracker.ui.util.SettingsItem
import kotlinx.coroutines.launch
Expand All @@ -51,6 +52,7 @@ import kotlinx.coroutines.launch
fun SettingsScreen(
navigator: DestinationsNavigator,
viewModel: SettingsViewModel = hiltViewModel(),
mapsViewModel: MapsViewModel = hiltViewModel(),
) {
val scrollBehavior =
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
Expand All @@ -63,6 +65,8 @@ fun SettingsScreen(

val scope = rememberCoroutineScope()

val mapsUiState = mapsViewModel.mapsUiState.collectAsStateWithLifecycle().value

Scaffold(
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
Expand Down Expand Up @@ -124,6 +128,14 @@ fun SettingsScreen(
onClick = { navigator.navigate(AboutScreenDestination()) },
)
}

item {
ShuttleAnimationSettingItem(
animationsEnabled = mapsUiState.shuttleAnimationsEnabled,
updateAnimations = mapsViewModel::setShuttleAnimations,
)
}

}
}
}
Expand Down Expand Up @@ -175,3 +187,19 @@ fun ThemeModeSettingItem(
}
}
}

@Composable
fun ShuttleAnimationSettingItem(
animationsEnabled: Boolean,
updateAnimations: (Boolean) -> Unit,) {
SettingsItem(
icon = Icons.Outlined.Contrast,
title = "Shuttle Animations",)
{
Switch(
checked = animationsEnabled,
onCheckedChange = {updateAnimations(it)},
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import edu.rpi.shuttletracker.R
import edu.rpi.shuttletracker.ui.MainActivity
import edu.rpi.shuttletracker.ui.maps.MapsViewModel
import edu.rpi.shuttletracker.ui.util.SettingsItem

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -59,6 +60,8 @@ fun DevMenuScreen(
TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())

val devMenuUiState = viewModel.devMenuUiState.collectAsStateWithLifecycle().value
val mapsViewModel: MapsViewModel = hiltViewModel()
val mapsUiState = mapsViewModel.mapsUiState.collectAsStateWithLifecycle().value

val snackbarHostState = remember { SnackbarHostState() }

Expand Down Expand Up @@ -87,6 +90,17 @@ fun DevMenuScreen(
})
}

SettingsItem(
icon = Icons.Outlined.Code,
title = "Shuttle Rotation",
description = "Rotate shuttle based on heading",
) {
Switch(
checked = mapsUiState.shuttleRotationEnabled,
onCheckedChange = { mapsViewModel.setShuttleRotation(it) },
)
}

// MinStopDistItem(
// maxStopDist = devMenuUiState.maxStopDist,
// updateMaxStopDist = viewModel::updateMinStopDist,
Expand Down