diff --git a/app/src/main/java/com/scouting/app/misc/ScoutingScheduleManager.kt b/app/src/main/java/com/scouting/app/misc/ScoutingScheduleManager.kt index 0d6b03d..c641e1e 100644 --- a/app/src/main/java/com/scouting/app/misc/ScoutingScheduleManager.kt +++ b/app/src/main/java/com/scouting/app/misc/ScoutingScheduleManager.kt @@ -14,7 +14,7 @@ class ScoutingScheduleManager { val currentCompetitionScheduleCSV = mutableListOf>() // Follows the format teamNumber, teamName - private val currentPitScheduleCSV = mutableListOf>() + val currentPitScheduleCSV = mutableListOf>() var currentMatchScoutingIteration by mutableStateOf(0) var currentPitScoutingIteration by mutableStateOf(0) @@ -152,6 +152,32 @@ class ScoutingScheduleManager { */ fun jumpToMatch(number: Int) { currentMatchScoutingIteration = number - 1 + MMKV.defaultMMKV().encode("COMPETITION_SCHEDULE_CURRENT_ITERATION", currentMatchScoutingIteration) + } + + /** + * Indicate if there is a pit to scout before the current one + */ + fun hasPrevPit(): Boolean = currentPitScoutingIteration > 0 + + /** + * Indicate if there is a pit to scout after the current one + */ + fun hasNextPit(): Boolean = currentPitScoutingIteration < currentPitScheduleCSV.size - 1 + + /** + * Decrement the current row of the pit scouting schedule we're + * on and save this to MMKV + */ + fun moveToPrevPit() { + if (currentPitScoutingIteration > 0) { + currentPitScoutingIteration-- + MMKV.defaultMMKV().encode("PIT_SCHEDULE_CURRENT_ITERATION", currentPitScoutingIteration) + } else { + // currentPitScoutingIteration *should* be 0, but still set to 0 in case of negatives somehow + currentPitScoutingIteration = 0 + MMKV.defaultMMKV().encode("PIT_SCOUTING_MODE", false) + } } /** @@ -168,4 +194,13 @@ class ScoutingScheduleManager { } } + /** + * Move to the specified pit index + * + * @param index The 0's based index in the pit list + */ + fun jumpToPit(index: Int) { + currentPitScoutingIteration = index + MMKV.defaultMMKV().encode("PIT_SCHEDULE_CURRENT_ITERATION", currentPitScoutingIteration) + } } \ No newline at end of file diff --git a/app/src/main/java/com/scouting/app/view/scouting/SelectPitDialog.kt b/app/src/main/java/com/scouting/app/view/scouting/SelectPitDialog.kt new file mode 100644 index 0000000..2eafa45 --- /dev/null +++ b/app/src/main/java/com/scouting/app/view/scouting/SelectPitDialog.kt @@ -0,0 +1,75 @@ +package com.scouting.app.view.scouting + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.scouting.app.R +import com.scouting.app.components.DialogScaffold +import com.scouting.app.misc.ScoutingScheduleManager +import com.scouting.app.theme.NeutralGrayLight +import com.scouting.app.theme.ScoutingTheme +import com.scouting.app.viewmodel.ScoutingViewModel + +@Composable +fun SelectPitDialog(scoutingScheduleManager: ScoutingScheduleManager, viewModel: ScoutingViewModel) { + if (!viewModel.showingSelectPitDialog) { + return + } + ScoutingTheme { + DialogScaffold( + icon = painterResource(id = R.drawable.ic_calendar_panel), + contentDescription = stringResource(id = R.string.ic_calendar_panel_content_desc), + title = stringResource(id = R.string.start_scouting_dialog_select_pit_title), + onDismissRequest = { + viewModel.showingSelectPitDialog = false + } + ) { + LazyColumn( + modifier = Modifier + .padding(vertical = 20.dp) + .heightIn(0.dp, 500.dp), + verticalArrangement = Arrangement.spacedBy(5.dp) + ) { + itemsIndexed(scoutingScheduleManager.currentPitScheduleCSV) { index, item -> + val number = item[0] + val teamName = item[1] + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 30.dp, vertical = 10.dp) + .background(color = NeutralGrayLight, shape = MaterialTheme.shapes.medium) + .clickable { + scoutingScheduleManager.jumpToPit(index) + viewModel.populatePitDataIfScheduled() + viewModel.showingSelectPitDialog = false + }, + horizontalArrangement = Arrangement.Start + ) { + MaterialTheme.typography.bodyLarge.color + Text( + text = number, + modifier = Modifier + .padding(15.dp) + .width(70.dp), + style = MaterialTheme.typography.bodyLarge + ) + Text( + text = teamName, + modifier = Modifier.padding(15.dp), + style = MaterialTheme.typography.bodyLarge + ) + } + } + } + } + } +} diff --git a/app/src/main/java/com/scouting/app/view/scouting/StartPitScoutingView.kt b/app/src/main/java/com/scouting/app/view/scouting/StartPitScoutingView.kt index b135c00..915a0b3 100644 --- a/app/src/main/java/com/scouting/app/view/scouting/StartPitScoutingView.kt +++ b/app/src/main/java/com/scouting/app/view/scouting/StartPitScoutingView.kt @@ -16,15 +16,13 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.scouting.app.R -import com.scouting.app.components.BasicInputField -import com.scouting.app.components.LargeButton -import com.scouting.app.components.LargeHeaderBar -import com.scouting.app.components.SpacedRow +import com.scouting.app.components.* import com.scouting.app.misc.NavDestination import com.scouting.app.misc.ScoutingScheduleManager import com.scouting.app.misc.ScoutingType import com.scouting.app.theme.AffirmativeGreen import com.scouting.app.theme.AffirmativeGreenDark +import com.scouting.app.theme.NeutralGrayMedium import com.scouting.app.theme.ScoutingTheme import com.scouting.app.utilities.composableContext import com.scouting.app.viewmodel.ScoutingViewModel @@ -49,6 +47,39 @@ fun StartPitScoutingView( title = stringResource(id = R.string.start_pit_scouting_header_title), navController = navController ) + if (viewModel.usingPitSchedule()) { + SpacedRow(modifier = Modifier.padding(top = 50.dp)) { + SmallButton( + text = "", + enabled = scoutingScheduleManager.hasPrevPit(), + icon = painterResource(id = R.drawable.ic_arrow_back), + contentDescription = stringResource(id = R.string.ic_arrow_back_content_desc), + onClick = { + scoutingScheduleManager.moveToPrevPit() + viewModel.populatePitDataIfScheduled() + }, + color = NeutralGrayMedium + ) + SmallButton( + text = stringResource(id = R.string.start_pit_scouting_select_team_button_text), + onClick = { + viewModel.showingSelectPitDialog = true + }, + color = NeutralGrayMedium + ) + SmallButton( + text = "", + enabled = scoutingScheduleManager.hasNextPit(), + icon = painterResource(id = R.drawable.ic_arrow_forward), + contentDescription = stringResource(id = R.string.ic_arrow_forward_content_desc), + onClick = { + scoutingScheduleManager.moveToNextPit() + viewModel.populatePitDataIfScheduled() + }, + color = NeutralGrayMedium + ) + } + } SpacedRow(modifier = Modifier.padding(top = 50.dp)) { Text( text = stringResource(id = R.string.start_pit_scouting_team_number_prefix), @@ -112,4 +143,5 @@ fun StartPitScoutingView( } } NoTemplateDialog(navController, viewModel) + SelectPitDialog(scoutingScheduleManager, viewModel) } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 72f0fd6..61247e9 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -115,6 +115,8 @@ Settings Got it! + Select team to pit scout + Start a match Match number Team number @@ -128,6 +130,7 @@ Team number Team name Begin scouting + Select team Pit scouting Monitoring team %1$s