Skip to content

Commit

Permalink
Add match type
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Mar 30, 2024
1 parent 690062f commit 4a3ddcf
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.scouting.app.view.settings

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.scouting.app.R
import com.scouting.app.components.BasicInputField
import com.scouting.app.components.DialogScaffold
import com.scouting.app.components.SmallButton
import com.scouting.app.viewmodel.SettingsViewModel

@Composable
fun MatchTypeDialog(viewModel: SettingsViewModel) {
if (!viewModel.showingMatchTypeDialog) {
return
}
DialogScaffold(icon = painterResource(id = R.drawable.ic_edit_pen),
contentDescription = stringResource(R.string.ic_edit_pen_content_desc),
title = stringResource(id = R.string.settings_choose_match_type_dialog_title),
onDismissRequest = {
viewModel.apply {
showingMatchTypeDialog = false
restoreMatchType()
}
}
) {
Column {
BasicInputField(
icon = painterResource(id = R.drawable.ic_edit_pen),
contentDescription = stringResource(id = R.string.ic_edit_pen_content_desc),
hint = stringResource(id = R.string.settings_choose_match_type_dialog_input_title),
textFieldValue = viewModel.matchType,
onValueChange = { value ->
viewModel.apply {
matchType = value
}
},
modifier = Modifier
.fillMaxWidth()
.padding(25.dp)
)
SmallButton(
text = stringResource(id = R.string.home_page_device_edit_dialog_save_button),
icon = painterResource(id = R.drawable.ic_checkmark_outline),
contentDescription = stringResource(id = R.string.ic_checkmark_outline_content_desc),
onClick = {
viewModel.apply {
showingMatchTypeDialog = false
applyMatchTypeChange(matchType.text)
// Reset text field value
matchType = TextFieldValue(matchType.text)
}
},
color = MaterialTheme.colorScheme.secondary,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(bottom = 25.dp)
)
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/scouting/app/view/settings/SettingsView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,21 @@ fun SettingsView(
},
modifier = Modifier.padding(top = 50.dp)
)
SettingsPreference(
title = stringResource(id = R.string.settings_choose_match_type_title),
endContent = {
MediumButton(
text = viewModel.matchType.text,
onClick = {
viewModel.apply {
showingMatchTypeDialog = true
}
},
color = NeutralGrayLight
)
},
modifier = Modifier.padding(top = 50.dp)
)
SettingsDivider(modifier = Modifier.padding(vertical = 50.dp))
SettingsPreference(
title = stringResource(id = R.string.settings_choose_default_template_pit_title),
Expand Down Expand Up @@ -283,6 +298,7 @@ fun SettingsView(
}
}
FileNameDialog(viewModel)
MatchTypeDialog(viewModel)
DevicePositionDialog(viewModel)
CompetitionModeDialog(viewModel)
}
Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/com/scouting/app/viewmodel/ScoutingViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ class ScoutingViewModel : ViewModel() {
* template.
*/
fun saveScoutingDataToFile(context: MainActivity) {
var csvRowDraft = ""
val csvRowDraft = StringBuilder()
val templateType = if (scoutingType == PIT) "PIT" else "MATCH"
val specialColumnName = if (scoutingType == PIT) "name" else "match"
val contentResolver = context.contentResolver
val itemList = if (scoutingType == PIT) {
pitListItems
Expand All @@ -149,22 +148,26 @@ class ScoutingViewModel : ViewModel() {

val tabletName = preferences.decodeString("DEVICE_ALLIANCE_POSITION", "RED") + "-" +
preferences.decodeInt("DEVICE_ROBOT_POSITION", 1).toString()
val csvHeaderRow = "device,scout,$specialColumnName,team," + saveKeyOrderList!!.joinToString(",")
val matchType = preferences.decodeString("MATCH_TYPE", "NONE")
val csvHeaderRow = if (scoutingType == PIT) {
"device,scout,name,team," + saveKeyOrderList!!.joinToString(",")
} else {
"device,scout,match,match-type,team," + saveKeyOrderList!!.joinToString(",")
}

// Add device name, scout name, match number and team number
// OR if pit scouting add team name in place of match number
csvRowDraft += "$tabletName,${scoutName.text},${
csvRowDraft.append(
if (scoutingType == PIT) {
currentTeamNameMonitoring.text
"$tabletName,${scoutName.text},${currentTeamNameMonitoring.text},${currentTeamNumberMonitoring.text},"
} else {
currentMatchMonitoring.text
"$tabletName,${scoutName.text},${currentMatchMonitoring.text},$matchType,${currentTeamNumberMonitoring.text},"
}
},${currentTeamNumberMonitoring.text},"
)


// Append ordered, user-inputted match data
csvRowDraft += saveKeyOrderList!!.joinToString(",") { key ->
csvRowDraft.append(saveKeyOrderList!!.joinToString(",") { key ->
itemList.findItemValueWithKey(key).toString().quoteForCSV()
}
})

val userSelectedOutputFileName = preferences.decodeString(
"DEFAULT_OUTPUT_FILE_NAME_$templateType",
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/scouting/app/viewmodel/SettingsViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class SettingsViewModel : ViewModel() {
var defaultPitTemplateFileName by mutableStateOf("NONE")
var defaultPitOutputFileName by mutableStateOf(TextFieldValue("output-pit.csv"))

var matchType by mutableStateOf(TextFieldValue("NONE"))

var competitionScheduleFileName by mutableStateOf("NONE")
var pitScheduleFileName by mutableStateOf("NONE")
var deviceAlliancePosition by mutableStateOf(RED)
Expand All @@ -35,6 +37,7 @@ class SettingsViewModel : ViewModel() {
var scheduledScoutingModeType by mutableStateOf(MATCH)

var showingFileNameDialog by mutableStateOf(false)
var showingMatchTypeDialog by mutableStateOf(false)
var showingDevicePositionDialog by mutableStateOf(false)
var showingScheduledScoutingModeDialog by mutableStateOf(false)

Expand Down Expand Up @@ -63,6 +66,9 @@ class SettingsViewModel : ViewModel() {
defaultPitOutputFileName = TextFieldValue(
File(decodeString("DEFAULT_OUTPUT_FILE_NAME_PIT", "output-pit.csv")!!).name
)
matchType = TextFieldValue(
decodeString("MATCH_TYPE", matchType.text)!!
)
competitionMode = decodeBool("COMPETITION_MODE", false)
pitScoutingMode = decodeBool("PIT_SCOUTING_MODE", false)
}
Expand Down Expand Up @@ -181,6 +187,20 @@ class SettingsViewModel : ViewModel() {
)
}

/**
* Save the new match type to MMKV
*/
fun applyMatchTypeChange(matchType: String) {
preferences.encode("MATCH_TYPE", matchType)
}

/**
* Resets the matchType to what's on MMKV
*/
fun restoreMatchType() {
matchType = TextFieldValue(preferences.decodeString("MATCH_TYPE", "NONE")!!)
}

/**
* Make sure that when a user enters a new file name that it ends with
* ".csv", otherwise add it before saving
Expand Down
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 @@ -157,6 +157,9 @@
<string name="settings_choose_default_pit_output_location_title">Pit output file name</string>
<string name="settings_choose_default_output_location_dialog_input_hint">File name</string>
<string name="settings_choose_default_output_location_dialog_title">Default output file name</string>
<string name="settings_choose_match_type_title">Match type</string>
<string name="settings_choose_match_type_dialog_input_title">Match type</string>
<string name="settings_choose_match_type_dialog_title">Match type</string>
<string name="settings_tablet_configuration_title">Device position</string>
<string name="settings_load_competition_schedule_title">Competition schedule</string>
<string name="settings_load_pit_schedule_title">Pit scouting schedule</string>
Expand Down

0 comments on commit 4a3ddcf

Please sign in to comment.