Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
defaultConfig {
applicationId = "com.example.trackpro"
minSdk = 26
targetSdk = 34
targetSdk = 34 // intentionally behind compileSdk 35, not yet verified against Android 15 behavior changes
versionCode = 1
versionName = "1.1"

Expand Down Expand Up @@ -54,7 +54,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
implementation("androidx.activity:activity-compose:1.7.0")
implementation(platform("androidx.compose:compose-bom:2023.08.00"))
implementation(platform("androidx.compose:compose-bom:2024.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
Expand All @@ -68,7 +68,7 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.2.1")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.08.00"))
androidTestImplementation(platform("androidx.compose:compose-bom:2024.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
Expand Down Expand Up @@ -101,8 +101,6 @@ dependencies {
implementation ("com.google.accompanist:accompanist-pager:0.31.1-alpha")
implementation ("com.google.accompanist:accompanist-pager-indicators:0.31.1-alpha")

implementation(platform("androidx.compose:compose-bom:2024.03.00")) // Update to latest BOM

implementation ("com.google.code.gson:gson:2.10.1")

//MAP
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<!-- Phone GPS — ALL THREE are required -->
<!-- Phone GPS -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required for FusedLocationProviderClient on Android 12+ -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />


</manifest>
21 changes: 20 additions & 1 deletion app/src/main/java/com/example/trackpro/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.Text
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -112,6 +114,22 @@ class TrackProApp : Application() {

val useExternalGps = MutableStateFlow(true)

private val themePrefs by lazy { getSharedPreferences("theme_prefs", MODE_PRIVATE) }
val useDarkTheme by lazy { MutableStateFlow(themePrefs.getBoolean("dark_theme", true)) }

fun setDarkTheme(enabled: Boolean) {
themePrefs.edit().putBoolean("dark_theme", enabled).apply()
useDarkTheme.value = enabled
}

private val unitPrefs by lazy { getSharedPreferences("unit_prefs", MODE_PRIVATE) }
val useMetricUnits by lazy { MutableStateFlow(unitPrefs.getBoolean("metric_units", true)) }

fun setMetricUnits(enabled: Boolean) {
unitPrefs.edit().putBoolean("metric_units", enabled).apply()
useMetricUnits.value = enabled
}

val gpsManager: GpsManager by lazy {
GpsManager(
espProvider = espTcpClient,
Expand Down Expand Up @@ -168,7 +186,8 @@ class MainActivity : ComponentActivity() {


setContent {
TrackProTheme {
val useDarkTheme by (application as TrackProApp).useDarkTheme.collectAsState()
TrackProTheme(darkTheme = useDarkTheme) {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "main") {
composable("main") {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/example/trackpro/dao/LapTimeDataDAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ interface LapTimeDataDAO {
@Query("SELECT * FROM lap_time_data WHERE sessionid = :sessionId ORDER BY laptime ASC LIMIT 1")
suspend fun getBestLapForSession(sessionId: Long): LapTimeData?

// Get best completed lap across all sessions recorded on a track
@Query("""
SELECT lap_time_data.* FROM lap_time_data
INNER JOIN session_data ON lap_time_data.sessionid = session_data.id
WHERE session_data.trackId = :trackId
AND lap_time_data.laptime != 'IN PROGRESS'
AND lap_time_data.laptime != 'INVALID'
ORDER BY lap_time_data.laptime ASC
LIMIT 1
""")
suspend fun getBestLapForTrack(trackId: Long): LapTimeData?

// Get total number of laps in a session
@Query("SELECT COUNT(*) FROM lap_time_data WHERE sessionid = :sessionId")
suspend fun getLapCountForSession(sessionId: Long): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ interface RawGPSDataDao {
suspend fun getGPSDataBySession(sessionId: Long?): List<RawGPSData>

@Query("DELETE FROM raw_gps_data WHERE sessionId = :sessionId")
suspend fun deleteGPSDataBySession(sessionId: Int)
suspend fun deleteGPSDataBySession(sessionId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ interface TrackCoordinatesDataDAO {
//OR
// IF the user filters the coordinates (if the full track is complete)
@Query("DELETE FROM track_coordinates_data WHERE trackId = :trackId")
suspend fun deleteTrackCoordinates(trackId: Int)
suspend fun deleteTrackCoordinates(trackId: Long)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey


Expand All @@ -10,7 +11,8 @@ import androidx.room.PrimaryKey
parentColumns = ["id"],
childColumns = ["sessionid"],
onDelete = androidx.room.ForeignKey.CASCADE
)])
)],
indices = [Index("sessionid")])

data class DerivedData(
@PrimaryKey(autoGenerate = true) val id: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
Expand All @@ -11,7 +12,8 @@ import androidx.room.PrimaryKey
parentColumns = ["id"],
childColumns = ["lapid"],
onDelete = ForeignKey.CASCADE
)]
)],
indices = [Index("lapid")]
)
data class LapInfoData(
@PrimaryKey(autoGenerate = true) val id: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
Expand All @@ -11,7 +12,8 @@ import androidx.room.PrimaryKey
parentColumns = ["id"],
childColumns = ["sessionid"],
onDelete = ForeignKey.CASCADE
)]
)],
indices = [Index("sessionid")]
)

data class LapTimeData (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
Expand All @@ -12,7 +13,8 @@ import androidx.room.PrimaryKey
parentColumns = ["id"],
childColumns = ["sessionid"],
onDelete = ForeignKey.CASCADE
)]
)],
indices = [Index("sessionid")]
)

data class RawGPSData(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
Expand All @@ -10,7 +11,8 @@ import androidx.room.PrimaryKey
parentColumns = ["vehicleId"],
childColumns = ["vehicleId"],
onDelete = androidx.room.ForeignKey.CASCADE
)]
)],
indices = [Index("vehicleId"), Index("trackId")]

)
data class SessionData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.trackpro.dataClasses
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.ForeignKey
import androidx.room.Index

@Entity(
tableName = "smoothed_gps_data" ,
Expand All @@ -11,7 +12,8 @@ import androidx.room.ForeignKey
parentColumns = ["id"],
childColumns = ["sessionid"],
onDelete = ForeignKey.CASCADE
)]
)],
indices = [Index("sessionid")]
)

data class SmoothedGPSData (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.trackpro.dataClasses

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey


Expand All @@ -12,7 +13,8 @@ import androidx.room.PrimaryKey
parentColumns = ["trackId"],
childColumns = ["trackId"],
onDelete = ForeignKey.CASCADE
)]
)],
indices = [Index("trackId")]
)
data class TrackCoordinatesData(
@PrimaryKey(autoGenerate = true)
Expand All @@ -21,5 +23,7 @@ data class TrackCoordinatesData(
val latitude: Double,
val longitude: Double,
val altitude: Double?,
val isStartPoint: Boolean = false
val isStartPoint: Boolean = false,
val isSectorPoint: Boolean = false,
val sectorIndex: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.input.KeyboardType

Expand All @@ -20,17 +19,25 @@ fun CustomTextField(
OutlinedTextField(
value = value,
onValueChange = onValueChange,
label = { Text(label, color = Color.White) },
label = { Text(label, color = TrackProTheme.colors.textMuted) },
keyboardOptions = if (isNumber) KeyboardOptions(keyboardType = KeyboardType.Number) else KeyboardOptions.Default,
leadingIcon = if (leadingIcon != null) {
{
Icon(
imageVector = leadingIcon,
contentDescription = null,
tint = Color.LightGray
tint = TrackProTheme.colors.textMuted
)
}
} else null,
colors = OutlinedTextFieldDefaults.colors(
focusedTextColor = TrackProTheme.colors.textPrimary,
unfocusedTextColor = TrackProTheme.colors.textPrimary,
focusedBorderColor = TrackProTheme.colors.accentCyan,
unfocusedBorderColor = TrackProTheme.colors.sectorLine,
focusedLabelColor = TrackProTheme.colors.accentCyan,
cursorColor = TrackProTheme.colors.accentCyan
),
modifier = Modifier.fillMaxWidth()
)
}
Expand Down
Loading
Loading