mirror of
https://github.com/cmclark00/TetriStats.git
synced 2025-05-25 02:05:20 +01:00
Fix conversion display issues and remove annoying toast notifications
This commit is contained in:
parent
857331566e
commit
f3bfa5650b
2 changed files with 49 additions and 33 deletions
|
@ -18,6 +18,9 @@ class EntryFragment : Fragment() {
|
||||||
private val viewModel: EntryViewModel by viewModels { EntryViewModelFactory(requireActivity().application) }
|
private val viewModel: EntryViewModel by viewModels { EntryViewModelFactory(requireActivity().application) }
|
||||||
private lateinit var equivalentScoreAdapter: EquivalentScoreAdapter
|
private lateinit var equivalentScoreAdapter: EquivalentScoreAdapter
|
||||||
|
|
||||||
|
// Flag to track if we already showed the requirements toast
|
||||||
|
private var hasShownRequirementsToast = false
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
|
@ -35,8 +38,7 @@ class EntryFragment : Fragment() {
|
||||||
setupSubmitButton()
|
setupSubmitButton()
|
||||||
setupAutoAnalysis()
|
setupAutoAnalysis()
|
||||||
|
|
||||||
// Check if we should show conversions on startup
|
// Don't need to check on startup anymore - being handled by ViewModel
|
||||||
viewModel.checkConversionCriteria()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupGameVersionDropdown() {
|
private fun setupGameVersionDropdown() {
|
||||||
|
@ -67,19 +69,7 @@ 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 ->
|
||||||
if (!shouldShow) {
|
// No need to show toast here - we'll do it only after score submission
|
||||||
// Hide analysis card if we don't meet criteria
|
|
||||||
binding.cardAnalysisResults.visibility = View.GONE
|
|
||||||
|
|
||||||
// Also show a message that not enough scores have been entered
|
|
||||||
if (viewModel.lastSubmittedGame.value != null) {
|
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
"Enter at least 3 scores across 2 different games to see conversions",
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only setup equivalence UI when we have scores
|
// Only setup equivalence UI when we have scores
|
||||||
|
@ -112,11 +102,13 @@ class EntryFragment : Fragment() {
|
||||||
// Observe last submitted score details
|
// Observe last submitted score details
|
||||||
viewModel.lastSubmittedGame.observe(viewLifecycleOwner) { game ->
|
viewModel.lastSubmittedGame.observe(viewLifecycleOwner) { game ->
|
||||||
// Only continue if showConversion is true
|
// Only continue if showConversion is true
|
||||||
if (viewModel.showConversion.value != true) return@observe
|
if (viewModel.showConversion.value != true) {
|
||||||
|
binding.cardAnalysisResults.visibility = View.GONE
|
||||||
|
return@observe
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.lastSubmittedScore.value?.let { score ->
|
viewModel.lastSubmittedScore.value?.let { score ->
|
||||||
binding.textViewOriginalScore.text = "Your $game score of ${"%,d".format(score)} is equivalent to:"
|
binding.textViewOriginalScore.text = "Your $game score of ${"%,d".format(score)} is equivalent to:"
|
||||||
binding.cardAnalysisResults.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
// Get the list of games with scores
|
// Get the list of games with scores
|
||||||
val playedGames = viewModel.gamesWithScores.value ?: listOf()
|
val playedGames = viewModel.gamesWithScores.value ?: listOf()
|
||||||
|
@ -124,6 +116,7 @@ class EntryFragment : Fragment() {
|
||||||
// Make sure we don't show the source game in the equivalent dropdown
|
// Make sure we don't show the source game in the equivalent dropdown
|
||||||
val filteredGames = playedGames.filter { it != game }
|
val filteredGames = playedGames.filter { it != game }
|
||||||
if (filteredGames.isNotEmpty()) {
|
if (filteredGames.isNotEmpty()) {
|
||||||
|
binding.cardAnalysisResults.visibility = View.VISIBLE
|
||||||
val filteredAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, filteredGames)
|
val filteredAdapter = ArrayAdapter(requireContext(), android.R.layout.simple_dropdown_item_1line, filteredGames)
|
||||||
binding.autoCompleteEquivalentGame.setAdapter(filteredAdapter)
|
binding.autoCompleteEquivalentGame.setAdapter(filteredAdapter)
|
||||||
|
|
||||||
|
@ -133,11 +126,6 @@ class EntryFragment : Fragment() {
|
||||||
} else {
|
} else {
|
||||||
// If no other games to convert to, hide the card
|
// If no other games to convert to, hide the card
|
||||||
binding.cardAnalysisResults.visibility = View.GONE
|
binding.cardAnalysisResults.visibility = View.GONE
|
||||||
Toast.makeText(
|
|
||||||
context,
|
|
||||||
"Add scores for other games to see conversions",
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,8 +159,15 @@ class EntryFragment : Fragment() {
|
||||||
)
|
)
|
||||||
clearInputs()
|
clearInputs()
|
||||||
|
|
||||||
// Only scroll down if we're going to show conversions
|
// Check after submission if we should show requirements toast
|
||||||
if (viewModel.showConversion.value == true) {
|
if (viewModel.showConversion.value == false) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"Enter at least 3 scores across 2 different games to see conversions",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
} else {
|
||||||
|
// Only scroll down if we're going to show conversions
|
||||||
binding.root.post {
|
binding.root.post {
|
||||||
binding.root.fullScroll(View.FOCUS_DOWN)
|
binding.root.fullScroll(View.FOCUS_DOWN)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.accidentalproductions.tetristats.ui.entry
|
package com.accidentalproductions.tetristats.ui.entry
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import com.accidentalproductions.tetristats.TetriStatsApplication
|
import com.accidentalproductions.tetristats.TetriStatsApplication
|
||||||
import com.accidentalproductions.tetristats.data.Score
|
import com.accidentalproductions.tetristats.data.Score
|
||||||
|
@ -43,6 +44,17 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
val lastSubmittedScore: LiveData<Int> = _lastSubmittedScore
|
val lastSubmittedScore: LiveData<Int> = _lastSubmittedScore
|
||||||
val showConversion: LiveData<Boolean> = _showConversion
|
val showConversion: LiveData<Boolean> = _showConversion
|
||||||
|
|
||||||
|
init {
|
||||||
|
// Set up observers to update conversion criteria whenever relevant data changes
|
||||||
|
gamesWithScores.observeForever {
|
||||||
|
checkConversionCriteria()
|
||||||
|
}
|
||||||
|
|
||||||
|
totalScoreCount.observeForever {
|
||||||
|
checkConversionCriteria()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getScoresForGame(gameVersion: String): LiveData<List<Score>> {
|
fun getScoresForGame(gameVersion: String): LiveData<List<Score>> {
|
||||||
return scoreDao.getScoresForGame(gameVersion)
|
return scoreDao.getScoresForGame(gameVersion)
|
||||||
}
|
}
|
||||||
|
@ -55,13 +67,16 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
* Check if we should show conversions based on score count and game count
|
* Check if we should show conversions based on score count and game count
|
||||||
*/
|
*/
|
||||||
fun checkConversionCriteria() {
|
fun checkConversionCriteria() {
|
||||||
viewModelScope.launch {
|
val scoreCount = totalScoreCount.value ?: 0
|
||||||
val scoreCount = totalScoreCount.value ?: 0
|
val gameCount = gamesWithScores.value?.size ?: 0
|
||||||
val gameCount = gamesWithScores.value?.size ?: 0
|
|
||||||
|
|
||||||
// Only show conversions if there are at least 3 scores across at least 2 games
|
// Only show conversions if there are at least 3 scores across at least 2 games
|
||||||
_showConversion.postValue(scoreCount >= 3 && gameCount >= 2)
|
val shouldShow = scoreCount >= 3 && gameCount >= 2
|
||||||
}
|
|
||||||
|
// For debugging
|
||||||
|
Log.d("TetriStats", "Checking conversion criteria: scores=$scoreCount, games=$gameCount, shouldShow=$shouldShow")
|
||||||
|
|
||||||
|
_showConversion.postValue(shouldShow)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertScore(
|
fun insertScore(
|
||||||
|
@ -85,8 +100,7 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
_lastSubmittedGame.postValue(gameVersion)
|
_lastSubmittedGame.postValue(gameVersion)
|
||||||
_lastSubmittedScore.postValue(score)
|
_lastSubmittedScore.postValue(score)
|
||||||
|
|
||||||
// Check if we should show conversions
|
// The criteria check will happen automatically through the observers in init
|
||||||
checkConversionCriteria()
|
|
||||||
|
|
||||||
// Only generate equivalent scores if we meet the criteria
|
// Only generate equivalent scores if we meet the criteria
|
||||||
if (_showConversion.value == true) {
|
if (_showConversion.value == true) {
|
||||||
|
@ -141,6 +155,13 @@ class EntryViewModel(application: Application) : AndroidViewModel(application) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
// Remove our observers to prevent leaks
|
||||||
|
gamesWithScores.removeObserver { checkConversionCriteria() }
|
||||||
|
totalScoreCount.removeObserver { checkConversionCriteria() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntryViewModelFactory(private val application: Application) : ViewModelProvider.Factory {
|
class EntryViewModelFactory(private val application: Application) : ViewModelProvider.Factory {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue