Dialog System
๐งฉ DialogUtils.kt
โ Unified Dialog and Feedback Handler
This utility centralizes animated result feedback in zMantra, providing both inline overlays and fallback AlertDialogs for results like "Excellent", "Wrong", "Try Again", etc.
It also integrates:
- ๐๏ธ
TTSUtility
for speech feedback - ๐ผ๏ธ
Glide
for animated GIFs - ๐ Consistent timing and user experience
๐ Location
com.zendalona.zmantra.utility.common.DialogUtils
๐ง Usage Overview
Call methods like showResultDialog()
, showRetryDialog()
, or showCorrectAnswerDialog()
from your game fragment to show user feedback. Internally, they delegate to a shared showCustomDialog()
which prefers inline overlay (if present) or gracefully falls back to a standard dialog.
โ Supported Dialog Types
Method | Purpose | Overlay or Dialog | TTS | Example Visual |
---|---|---|---|---|
showResultDialog() |
Final grading (Excellent, Good, etc.) | โ Inline or fallback | โ | |
showRetryDialog() |
Wrong answer (attempt remaining) | โ Inline or fallback | โ | |
showCorrectAnswerDialog() |
Show correct answer after failures | โ Inline or fallback | โ | |
showNextDialog() |
Congratulate and move to next question | โ Inline or fallback | โ |
๐งฑ Inline Overlay Structure
If the following views are present in the fragment layout, the dialog is shown inline:
R.id.feedbackOverlay
(ViewGroup)R.id.messageTextView
(TextView)R.id.gifImageView
(ImageView)
Fallback to AlertDialog if any view is missing.
๐ก Sample Integration
DialogUtils.showRetryDialog(
context = requireContext(),
inflater = layoutInflater,
ttsUtility = ttsUtility,
message = "Try again!",
onContinue = { loadNextQuestion() }
)
๐๏ธ Grade โ Message and GIF Mapping
Defined in appreciationData
:
Grade | Messages (R.string.* ) |
GIFs (R.drawable.* ) |
---|---|---|
"Excellent" |
excellent_1..5 | dialog_excellent_1..3 |
"Very Good" |
very_good_1..5 | dialog_very_good_1..3 |
"Good" |
good_1..5 | dialog_good_1..3 |
"Not Bad" |
not_bad_1..5 | dialog_not_bad_1..3 |
"Okay" |
okay_1..5 | dialog_okay_1..3 |
"Wrong" |
wrong_answer | dialog_wrong_answer_1..3 |
๐งฉ showCustomDialog()
Parameters
Param | Description |
---|---|
context |
Activity context |
inflater |
For inflating fallback layout |
grade |
Grade category ("Good" , "Wrong" , etc.) |
ttsUtility |
Optional text-to-speech speaker |
message |
Custom override text |
drawableRes |
Custom override image |
speakText |
Custom override for TTS |
vibrationDuration |
Device vibration duration (default: 150ms) |
onContinue |
Callback after 2.5 seconds |
๐ Dialog Lifecycle
- Visible for 2.5 seconds
- Plays TTS immediately
- Auto-dismisses and calls
onContinue()
๐ Recommendations
- Use
showResultDialog()
inonGameOver()
- Use
showRetryDialog()
after each wrong answer attempt - Use
showCorrectAnswerDialog()
on final failure - Use
showNextDialog()
after correct answer