Skip to content

Commit ce00030

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents ecd8eef + 15c72d6 commit ce00030

File tree

5 files changed

+84
-41
lines changed

5 files changed

+84
-41
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 2 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/LookupView.kt

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sunkensplashstudios.VRCRoboScout
22

33
import androidx.compose.foundation.clickable
4+
import androidx.compose.foundation.interaction.FocusInteraction
45
import androidx.compose.foundation.interaction.MutableInteractionSource
56
import androidx.compose.foundation.interaction.PressInteraction
67
import androidx.compose.foundation.layout.Arrangement
@@ -96,7 +97,7 @@ class LookupViewModel : ViewModel() {
9697

9798
// EventLookup
9899
var eventTextColor = mutableStateOf(Color.Gray)
99-
var eventName = mutableStateOf("Event Name")
100+
var eventName = mutableStateOf("Event Name\u200B")
100101
var events = mutableStateOf(listOf<Event>())
101102
var page = mutableIntStateOf(1)
102103
var fetchedEvents = mutableStateOf(false)
@@ -285,6 +286,7 @@ fun TeamLookup(lookupViewModel: LookupViewModel, navController: NavController) {
285286

286287
val localContext = LocalContext.current
287288
val userSettings = remember { UserSettings(localContext) }
289+
val isFocused = remember { mutableStateOf(false) }
288290

289291
Column(
290292
horizontalAlignment = Alignment.CenterHorizontally,
@@ -314,26 +316,29 @@ fun TeamLookup(lookupViewModel: LookupViewModel, navController: NavController) {
314316
)
315317
Spacer(modifier = Modifier.weight(1.0f))
316318
TextField(
317-
modifier = Modifier.sizeIn(
318-
maxWidth = 200.dp,
319-
),
319+
modifier = Modifier.sizeIn(maxWidth = 200.dp),
320320
value = lookupViewModel.number.value,
321-
onValueChange = { lookupViewModel.number.value = it },
321+
onValueChange = { lookupViewModel.number.value = it.trim() },
322322
singleLine = true,
323323
interactionSource = remember { MutableInteractionSource() }
324324
.also { interactionSource ->
325325
LaunchedEffect(interactionSource) {
326326
interactionSource.interactions.collect {
327-
if (it is PressInteraction.Release) {
328-
lookupViewModel.number.value = ""
329-
lookupViewModel.fetchedTeams.value = false
327+
when (it) {
328+
is FocusInteraction.Focus -> isFocused.value = true
329+
is FocusInteraction.Unfocus -> isFocused.value = false
330+
is PressInteraction.Release -> {
331+
lookupViewModel.number.value = ""
332+
lookupViewModel.fetchedTeams.value = false
333+
}
330334
}
331335
}
332336
}
333337
},
334338
textStyle = LocalTextStyle.current.copy(
335339
textAlign = TextAlign.Center,
336-
fontSize = 34.sp
340+
fontSize = 34.sp,
341+
color = if (lookupViewModel.number.value.isEmpty() || lookupViewModel.number.value == "229V\u200B") Color.Gray else MaterialTheme.colorScheme.onSurface
337342
),
338343
colors = TextFieldDefaults.colors(
339344
focusedContainerColor = Color.Transparent,
@@ -342,31 +347,51 @@ fun TeamLookup(lookupViewModel: LookupViewModel, navController: NavController) {
342347
focusedIndicatorColor = Color.Transparent,
343348
unfocusedIndicatorColor = Color.Transparent,
344349
disabledIndicatorColor = Color.Transparent,
345-
unfocusedTextColor = lookupViewModel.teamTextColor.value
350+
unfocusedTextColor = lookupViewModel.teamTextColor.value,
346351
),
347352
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
348353
keyboardActions = KeyboardActions(
349354
onDone = {
350355
keyboardController?.hide()
351356
lookupViewModel.fetchTeam()
352-
})
357+
}),
358+
placeholder = {
359+
if (!isFocused.value && lookupViewModel.number.value.isEmpty()) {
360+
Text(
361+
"229V\u200B",
362+
modifier = Modifier.fillMaxWidth(),
363+
style = LocalTextStyle.current.copy(
364+
color = Color.Gray,
365+
fontSize = 34.sp,
366+
textAlign = TextAlign.Center,
367+
)
368+
)
369+
}
370+
}
353371
)
354372
Spacer(modifier = Modifier.weight(1.0f))
355373
Box {
356374
IconButton(onClick = {
357375
favoriteTeams =
358-
if (lookupViewModel.number.value.isEmpty() || lookupViewModel.number.value == "229V\u200B" || !lookupViewModel.fetchedTeams.value) {
376+
if (lookupViewModel.number.value.isEmpty() || lookupViewModel.number.value == "229V\u200B") {
359377
return@IconButton
360-
} else if (favoriteTeams.contains(lookupViewModel.number.value.uppercase()) && lookupViewModel.teamTextColor.value != Color.Unspecified) {
378+
} else if (favoriteTeams.contains(lookupViewModel.number.value.uppercase()) && !lookupViewModel.loadingTeams.value) {
361379
userSettings.removeFavoriteTeam(lookupViewModel.number.value.uppercase())
362380
userSettings.getData("favoriteTeams", "").replace("[", "")
363381
.replace("]", "")
364382
.split(", ")
365383
} else {
366-
userSettings.addFavoriteTeam(lookupViewModel.number.value.uppercase())
367-
userSettings.getData("favoriteTeams", "").replace("[", "")
368-
.replace("]", "")
369-
.split(", ")
384+
// allow adding to favorites only after fetching team data
385+
if (!lookupViewModel.fetchedTeams.value) {
386+
return@IconButton
387+
}
388+
389+
else {
390+
userSettings.addFavoriteTeam(lookupViewModel.number.value.uppercase())
391+
userSettings.getData("favoriteTeams", "").replace("[", "")
392+
.replace("]", "")
393+
.split(", ")
394+
}
370395
}
371396
}) {
372397
if (favoriteTeams.contains(lookupViewModel.number.value.uppercase()) && lookupViewModel.number.value.isNotBlank()) {
@@ -676,6 +701,7 @@ fun TeamLookup(lookupViewModel: LookupViewModel, navController: NavController) {
676701
fun EventLookup(lookupViewModel: LookupViewModel, navController: NavController) {
677702

678703
val keyboardController = LocalSoftwareKeyboardController.current
704+
val isFocused = remember { mutableStateOf(false) }
679705

680706
Column(
681707
horizontalAlignment = Alignment.CenterHorizontally,
@@ -697,16 +723,21 @@ fun EventLookup(lookupViewModel: LookupViewModel, navController: NavController)
697723
.also { interactionSource ->
698724
LaunchedEffect(interactionSource) {
699725
interactionSource.interactions.collect {
700-
if (it is PressInteraction.Release) {
701-
lookupViewModel.eventName.value = ""
702-
lookupViewModel.fetchedEvents.value = false
726+
when (it) {
727+
is FocusInteraction.Focus -> isFocused.value = true
728+
is FocusInteraction.Unfocus -> isFocused.value = false
729+
is PressInteraction.Release -> {
730+
lookupViewModel.eventName.value = ""
731+
lookupViewModel.fetchedEvents.value = false
732+
}
703733
}
704734
}
705735
}
706736
},
707737
textStyle = LocalTextStyle.current.copy(
708738
textAlign = TextAlign.Center,
709-
fontSize = 34.sp
739+
fontSize = 34.sp,
740+
color = if (lookupViewModel.eventName.value.isEmpty() || lookupViewModel.eventName.value == "Event Name\u200B") Color.Gray else MaterialTheme.colorScheme.onSurface
710741
),
711742
colors = TextFieldDefaults.colors(
712743
focusedContainerColor = Color.Transparent,
@@ -723,7 +754,20 @@ fun EventLookup(lookupViewModel: LookupViewModel, navController: NavController)
723754
keyboardController?.hide()
724755
lookupViewModel.fetchEvents(name = lookupViewModel.eventName.value, page = 1)
725756
lookupViewModel.page.intValue = 1
726-
})
757+
}),
758+
placeholder = {
759+
if (!isFocused.value && lookupViewModel.eventName.value.isEmpty()) {
760+
Text(
761+
"Event Name\u200B",
762+
modifier = Modifier.fillMaxWidth(),
763+
style = LocalTextStyle.current.copy(
764+
color = Color.Gray,
765+
fontSize = 34.sp,
766+
textAlign = TextAlign.Center,
767+
)
768+
)
769+
}
770+
}
727771
)
728772
}
729773
if (lookupViewModel.loadingEvents.value) {

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/RoboScoutAPI.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.ejml.simple.SimpleMatrix
2424
import java.text.SimpleDateFormat
2525
import java.util.Date
2626
import java.util.Locale
27+
import java.util.concurrent.CopyOnWriteArrayList
2728

2829
val API = RoboScoutAPI()
2930
val jsonWorker = Json {
@@ -159,8 +160,8 @@ class VDAEntry : MutableState<VDAEntry> {
159160

160161
class RoboScoutAPI {
161162

162-
var wsCache: MutableList<WSEntry> = mutableListOf<WSEntry>()
163-
var vdaCache: MutableList<VDAEntry> = mutableListOf<VDAEntry>()
163+
var wsCache: CopyOnWriteArrayList<WSEntry> = CopyOnWriteArrayList<WSEntry>()
164+
var vdaCache: CopyOnWriteArrayList<VDAEntry> = CopyOnWriteArrayList<VDAEntry>()
164165
var regionsMap: MutableMap<String, Int> = mutableMapOf<String, Int>()
165166
var importedWS: Boolean = false
166167
var importedVDA: Boolean = false

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/RootActivity.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,16 @@ class RootActivity : ComponentActivity() {
399399

400400
@Composable
401401
fun TabView(tabBarItems: List<TabBarItem>, navController: NavController, selectedTabIndex: Int, onSelectedTabIndexChange: (Int) -> Unit) {
402+
val navBackStackEntry by navController.currentBackStackEntryAsState()
403+
val currentRoute = navBackStackEntry?.destination?.route
404+
405+
LaunchedEffect(currentRoute) {
406+
val index = tabBarItems.indexOfFirst { it.direction.route == currentRoute }
407+
if (index != -1 && index != selectedTabIndex) {
408+
onSelectedTabIndexChange(index)
409+
}
410+
}
411+
402412
val localContext = LocalContext.current
403413
val userSettings = UserSettings(localContext)
404414
NavigationBar(

app/src/main/java/com/sunkensplashstudios/VRCRoboScout/SettingsView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ fun SettingsView(navController: NavController) {
6464
)
6565
}
6666
) { padding ->
67+
var update by remember { mutableStateOf(false) }
68+
6769
Column(
6870
modifier = Modifier.verticalScroll(rememberScrollState())
6971
) {
@@ -242,8 +244,6 @@ fun SettingsView(navController: NavController) {
242244
Row(
243245
modifier = Modifier.padding(vertical = 10.dp)
244246
) {
245-
var update by remember { mutableStateOf(false) }
246-
247247
if (minimalistic && update) {
248248
val background = MaterialTheme.colorScheme.background
249249
MaterialTheme.colorScheme.topContainer = background
@@ -325,6 +325,7 @@ fun SettingsView(navController: NavController) {
325325
userSettings.setMinimalisticMode(true)
326326
minimalistic = true
327327
reset = true
328+
update = true
328329
}
329330
)
330331
}

0 commit comments

Comments
 (0)