mirror of
https://github.com/cmclark00/TetriStats.git
synced 2025-05-17 22:55:21 +01:00
Fix entry view refresh issue to ensure conversion scores are updated when returning to tab
This commit is contained in:
parent
f3bfa5650b
commit
b7d0382ecc
2 changed files with 39 additions and 2 deletions
|
@ -37,8 +37,27 @@ class EntryFragment : Fragment() {
|
||||||
setupRecyclerView()
|
setupRecyclerView()
|
||||||
setupSubmitButton()
|
setupSubmitButton()
|
||||||
setupAutoAnalysis()
|
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() {
|
private fun setupGameVersionDropdown() {
|
||||||
|
@ -70,6 +89,10 @@ class EntryFragment : Fragment() {
|
||||||
// Observe if we should show conversions
|
// Observe if we should show conversions
|
||||||
viewModel.showConversion.observe(viewLifecycleOwner) { shouldShow ->
|
viewModel.showConversion.observe(viewLifecycleOwner) { shouldShow ->
|
||||||
// No need to show toast here - we'll do it only after score submission
|
// 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
|
// Only setup equivalence UI when we have scores
|
||||||
|
@ -78,6 +101,9 @@ class EntryFragment : Fragment() {
|
||||||
if (games.isNotEmpty()) {
|
if (games.isNotEmpty()) {
|
||||||
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, games)
|
val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, games)
|
||||||
binding.autoCompleteEquivalentGame.setAdapter(adapter)
|
binding.autoCompleteEquivalentGame.setAdapter(adapter)
|
||||||
|
|
||||||
|
// Also refresh conversions when game list changes
|
||||||
|
refreshConversions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,17 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
_showConversion.postValue(shouldShow)
|
_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(
|
fun insertScore(
|
||||||
gameVersion: String,
|
gameVersion: String,
|
||||||
score: Int,
|
score: Int,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue