Skip to content

Commit

Permalink
Allow navigating pit schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Apr 11, 2024
1 parent 2820bb6 commit 13c2a96
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ScoutingScheduleManager {
val currentCompetitionScheduleCSV = mutableListOf<List<String>>()

// Follows the format teamNumber, teamName
private val currentPitScheduleCSV = mutableListOf<List<String>>()
val currentPitScheduleCSV = mutableListOf<List<String>>()

var currentMatchScoutingIteration by mutableStateOf(0)
var currentPitScoutingIteration by mutableStateOf(0)
Expand Down Expand Up @@ -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)
}
}

/**
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -112,4 +143,5 @@ fun StartPitScoutingView(
}
}
NoTemplateDialog(navController, viewModel)
SelectPitDialog(scoutingScheduleManager, viewModel)
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
<string name="start_scouting_dialog_no_template_neutral_button_text">Settings</string>
<string name="start_scouting_dialog_no_template_positive_button_text">Got it!</string>

<string name="start_scouting_dialog_select_pit_title">Select team to pit scout</string>

<string name="start_match_header_title">Start a match</string>
<string name="start_match_match_number_text">Match number</string>
<string name="start_match_team_number_text">Team number</string>
Expand All @@ -128,6 +130,7 @@
<string name="start_pit_scouting_team_number_prefix">Team number</string>
<string name="start_pit_scouting_team_name_prefix">Team name</string>
<string name="start_pit_scouting_begin_button_text">Begin scouting</string>
<string name="start_pit_scouting_select_team_button_text">Select team</string>

<string name="in_pit_scouting_header_text">Pit scouting</string>
<string name="in_pit_scouting_primary_subtitle_text">Monitoring team %1$s</string>
Expand Down

0 comments on commit 13c2a96

Please sign in to comment.