Skip to content

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() in onGameOver()
  • Use showRetryDialog() after each wrong answer attempt
  • Use showCorrectAnswerDialog() on final failure
  • Use showNextDialog() after correct answer