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
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ configure<ApplicationExtension> {
minSdk = 34
targetSdk = 36
versionCode = 1
versionName = "1.0.0"
versionName = "1.0.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -121,6 +121,7 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation(libs.androidx.lifecycle.process)
testImplementation(libs.junit)
testImplementation(libs.junit.jupiter)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ class NetworkMonitor(
}

gameDetailRepository.fetch()
gameDetailRepository.isReady.first { it }

println("fetched, trying to push")
retryFetchUntilSuccess()

gameDetailRepository.push()
retryPushUntilSuccess()

delay(FETCH_INTERVAL)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun SelectAllTasksWithTime.createTaskFromDb() = createTaskFromDb(
type,
matchNum,
teamNum,
time,
time_,
progress
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.flow.StateFlow

import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
import kotlin.coroutines.cancellation.CancellationException
import kotlin.text.toLong


Expand All @@ -37,10 +38,12 @@ class GameDetailRepository(
private val appService: AppService,
private val db: AppDatabase,
): Repository {

/*
val isReady: MutableStateFlow<Boolean> = MutableStateFlow(false)

var pulledConstants = false
private set
*/

override suspend fun push(): Result<List<GameDetails>> {
return withContext(Dispatchers.IO) {
Expand Down Expand Up @@ -184,11 +187,6 @@ class GameDetailRepository(
}

override suspend fun fetch(): Result<GameConstants> {
if (pulledConstants)
return Result.failure(Exception("already pulled game constants"))

pulledConstants = true

return withContext(Dispatchers.IO) {
try {
val result: ApiResponse<GameConstants> = gameDetailsService.getGameConstants(
Expand All @@ -197,7 +195,6 @@ class GameDetailRepository(

if (result.data != null) {
if (result.data != GameConstantsStore.constants) {

// clear all data
db.transaction {
db.taskQueries.clearAllTasks()
Expand Down Expand Up @@ -233,20 +230,16 @@ class GameDetailRepository(
app_version = app_version
)

isReady.value = true

return@withContext Result.success(result.data)
} else {
pulledConstants = false

return@withContext Result.failure(
Exception("Game constants are empty")
)
}
} catch (e: CancellationException) {
// rethrow so the coroutine cancels
throw e
} catch (e: Exception) {
pulledConstants = false
isReady.value = true

Log.e("Game Constants", "Error when trying to fetch gameConstants: $e")
return@withContext Result.failure(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TaskRepository(
.mapToList(Dispatchers.IO)
.map { entities ->
entities.map { entity ->
println("TASK: $entity")
entity.createTaskFromDb()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class TeamNameRepository (
)
}

Result.success(Unit)
return@withContext Result.success(Unit)
}
catch (e: Exception) {
Log.d("TeamNames", "Error when trying to fetch team names: $e")
Result.failure(e)
return@withContext Result.failure(e)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ fun EndgameDetails(
)
val previousTimer = formState.teleopCachedMilliseconds - currentTimer
val coroutineScope = rememberCoroutineScope()
val endgameCompleted = formState.gameDetails.endgameProgress == 1f && formState.gameDetails.teleopCompleted == true
val endgameCompleted = formState.gameDetails.endgameProgress == 1f &&
formState.gameDetails.teleopCompleted == true &&
formState.teleopCachedMilliseconds == 0

val timers = listOf(
Timer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fun MatchSchedule(
) {
var searchQuery: String by remember { mutableStateOf("") }
val matchState by homeViewModel.matchState.collectAsStateWithLifecycle()
val readyState by homeViewModel.isReady.collectAsStateWithLifecycle()
val teamState by homeViewModel.teamsState.collectAsStateWithLifecycle()

val sortedMatches = remember(matchState) {
Expand Down Expand Up @@ -274,7 +273,7 @@ fun MatchSchedule(
}
}
}
if (matchState.isNullOrEmpty() || !readyState) {
if (matchState.isNullOrEmpty()) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,51 @@ fun TasksCard(
val tabs = arrayOf("Incomplete", "Complete")

val tasksState by homeViewModel.tasksState.collectAsStateWithLifecycle()
val sortedTasks = tasksState?.sorted()

val completeTasks = sortedTasks?.filter { it.progress >= 100 }
val incompleteTasks = sortedTasks?.filter { it.progress < 100 }
val sortedIncompleteTasks = arrayOfNulls<Task>(incompleteTasks?.size ?: 0)

if (incompleteTasks != null && completeTasks?.size!! > 0) {
val latestCompleteTask = completeTasks[completeTasks.size - 1]
val len = sortedIncompleteTasks.size

var missed = 0
var idx = 0
println("got here: ${latestCompleteTask.matchNum} ${latestCompleteTask.time}")

for (task in incompleteTasks) {
//println(latestCompleteTask.time - task.time)
if (task.time < latestCompleteTask.time) {
++missed
sortedIncompleteTasks[len - missed] = task
} else {
sortedIncompleteTasks[idx] = task
++idx
}
}
} else if (incompleteTasks != null) {
var idx = 0

for (task in incompleteTasks) {
sortedIncompleteTasks[idx] = task
++idx
}
}

val incompleteTasks = tasksState?.filter { it.progress != 100 }?.sorted()
val completeTasks = tasksState?.filter { it.progress >= 100 }?.sorted()
Log.d("TASKS_CARD", "RE-RENDER")

Box(
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth()
.clip(RoundedCornerShape(8.dp))
.border(1.dp, LightGunmetal, RoundedCornerShape(smallCornerRadius))
.border(
1.dp,
LightGunmetal,
RoundedCornerShape(smallCornerRadius)
)
) {
Box(
modifier = Modifier.wrapContentWidth(unbounded = true)
Expand All @@ -108,7 +142,11 @@ fun TasksCard(
Box (
modifier = Modifier
.clip(RoundedCornerShape(8.dp))
.border(1.dp, LightGunmetal, RoundedCornerShape(smallCornerRadius))
.border(
1.dp,
LightGunmetal,
RoundedCornerShape(smallCornerRadius)
)
.background(Background)
) {
PrimaryTabRow(
Expand Down Expand Up @@ -162,11 +200,14 @@ fun TasksCard(
}
Spacer(modifier = Modifier.height(16.dp))
LazyColumn(verticalArrangement = Arrangement.spacedBy(8.dp)) {
val tasks = (if (tabState.selectedTab == 0) incompleteTasks else completeTasks)
val tasks = if (tabState.selectedTab == 0)
sortedIncompleteTasks.toList()
else
completeTasks

if(tasks != null) {
items(tasks) { task ->
TaskItem(task = task, onPress = {onPress.invoke(task.id)})
TaskItem(task = task!!, onPress = {onPress.invoke(task.id)})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CommentsViewModel (
fun onMatchSelected(match: String) {
autoSaveJob?.cancel()
_selectedMatch.value = match
match.toIntOrNull()?.let { // safe check cuz it was crashing when going to home
match.toIntOrNull()?.let {
fetchComments(it)
}
updateTeamNames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class HomeViewModel(
private val _tabState = MutableStateFlow(TabState())
val tabState: StateFlow<TabState> = _tabState

val isReady: StateFlow<Boolean> = gameDetailRepository.isReady

val teamsState = taskRepository.teams
.stateIn(
scope = viewModelScope,
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ datastore = "1.2.0"
adaptiveNavigation = "1.2.0"
webkit = "1.15.0"
lifecycleProcess = "2.10.0"
junitJupiter = "5.14.0"

[libraries]
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanistSystemuicontroller" }
Expand Down Expand Up @@ -56,6 +57,7 @@ androidx-datastore = { group = "androidx.datastore", name = "datastore-preferenc
androidx-compose-adaptive-navigation = { group = "androidx.compose.material3.adaptive", name = "adaptive-navigation", version.ref = "adaptiveNavigation" }
androidx-webkit = { group = "androidx.webkit", name = "webkit", version.ref = "webkit" }
androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycleProcess" }
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter", version.ref = "junitJupiter" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
Loading