diff --git a/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryFragment.kt b/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryFragment.kt index 5e2c8f5..8c73b79 100644 --- a/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryFragment.kt +++ b/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryFragment.kt @@ -37,8 +37,27 @@ class EntryFragment : Fragment() { setupRecyclerView() setupSubmitButton() setupAutoAnalysis() - - // Don't need to check on startup anymore - being handled by ViewModel + } + + override fun onResume() { + super.onResume() + // Refresh conversions when returning to this fragment + refreshConversions() + } + + /** + * Force refresh the conversions using the last submitted values + */ + private fun refreshConversions() { + if (viewModel.showConversion.value == true) { + // If we have last submitted values, regenerate conversions + val game = viewModel.lastSubmittedGame.value + val score = viewModel.lastSubmittedScore.value + + if (game != null && score != null) { + viewModel.refreshEquivalentScores(game, score) + } + } } private fun setupGameVersionDropdown() { @@ -70,6 +89,10 @@ class EntryFragment : Fragment() { // Observe if we should show conversions viewModel.showConversion.observe(viewLifecycleOwner) { shouldShow -> // No need to show toast here - we'll do it only after score submission + if (shouldShow) { + // Refresh conversions whenever showConversion becomes true + refreshConversions() + } } // Only setup equivalence UI when we have scores @@ -78,6 +101,9 @@ class EntryFragment : Fragment() { if (games.isNotEmpty()) { val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, games) binding.autoCompleteEquivalentGame.setAdapter(adapter) + + // Also refresh conversions when game list changes + refreshConversions() } } diff --git a/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryViewModel.kt b/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryViewModel.kt index 13853b7..b4178de 100644 --- a/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryViewModel.kt +++ b/app/src/main/java/com/accidentalproductions/tetristats/ui/entry/EntryViewModel.kt @@ -78,6 +78,17 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) { _showConversion.postValue(shouldShow) } + + /** + * Force refresh the equivalent scores - use this to ensure UI has latest values + */ + fun refreshEquivalentScores(fromGame: String, score: Int) { + // Only refresh if conversions should be showing + if (_showConversion.value == true) { + Log.d("TetriStats", "Refreshing equivalent scores for $fromGame score $score") + generateEquivalentScores(fromGame, score) + } + } fun insertScore( gameVersion: String,