From 1d180b047a80fad3ce191a1574d42cd210d78fa5 Mon Sep 17 00:00:00 2001 From: Andrey Stoyan Date: Sun, 18 Oct 2020 18:17:18 +0300 Subject: [PATCH] Fix hints in input dots step --- .../learnbraille/ui/Messages.kt | 34 ++++++++++++++----- .../steps/input/AbstractInputStepFragment.kt | 7 +++- .../theory/steps/input/InputDotsFragment.kt | 10 ++++++ app/src/main/res/values/strings.xml | 20 +++++++---- 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt index 6e9626c9..f9759767 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/Messages.kt @@ -22,23 +22,39 @@ fun Fragment.dotsMode(mode: BrailleDotsViewMode): String = BrailleDotsViewMode.Reading -> getString(R.string.braille_dots_mode_reading) } -private val Context.dotsHintRules by lazyWithContext> { +private val Context.dotsReadingHintRules by lazyWithContext> { listOf( - getString(R.string.input_dots_hint_1), - getString(R.string.input_dots_hint_2), - getString(R.string.input_dots_hint_3), - getString(R.string.input_dots_hint_4), - getString(R.string.input_dots_hint_5), - getString(R.string.input_dots_hint_6) + getString(R.string.input_dots_reading_hint_1), + getString(R.string.input_dots_reading_hint_2), + getString(R.string.input_dots_reading_hint_3), + getString(R.string.input_dots_reading_hint_4), + getString(R.string.input_dots_reading_hint_5), + getString(R.string.input_dots_reading_hint_6) ) } -fun Fragment.showHintDotsToast(expectedDots: BrailleDots) { +private val Context.dotsWritingHintRules by lazyWithContext> { + listOf( + getString(R.string.input_dots_writing_hint_1), + getString(R.string.input_dots_writing_hint_2), + getString(R.string.input_dots_writing_hint_3), + getString(R.string.input_dots_writing_hint_4), + getString(R.string.input_dots_writing_hint_5), + getString(R.string.input_dots_writing_hint_6) + ) +} + +fun Fragment.showHintDotsToast(expectedDots: BrailleDots, mode: BrailleDotsViewMode) { val template = getString(R.string.input_dots_hint_template) val hint = expectedDots .filled .joinToString(separator = ", ") { - contextNotNull.dotsHintRules[it - 1] + contextNotNull.run { + when (mode) { + BrailleDotsViewMode.Reading -> dotsReadingHintRules[it - 1] + BrailleDotsViewMode.Writing -> dotsWritingHintRules[it - 1] + } + } } checkedToast(template.format(hint)) } diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt index 26049080..ca7176e1 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/AbstractInputStepFragment.kt @@ -5,6 +5,7 @@ import android.view.View import androidx.core.content.getSystemService import androidx.lifecycle.ViewModelProvider import com.github.braillesystems.learnbraille.data.entities.BaseInput +import com.github.braillesystems.learnbraille.data.entities.BrailleDots import com.github.braillesystems.learnbraille.data.entities.StepData import com.github.braillesystems.learnbraille.ui.screens.* import com.github.braillesystems.learnbraille.ui.screens.theory.steps.AbstractStepFragment @@ -72,7 +73,7 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra viewModel.observeEventHint( viewLifecycleOwner, { dotsState } ) { - showHintToast(expectedDots) + toastHint(expectedDots) userTouchedDots = true } @@ -105,5 +106,9 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra showIncorrectToast() } + protected open fun toastHint(expectedDots: BrailleDots) { + showHintToast(expectedDots) + } + protected open fun onPassHint(data: StepData) = Unit } diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputDotsFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputDotsFragment.kt index 405941a4..6d50deac 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputDotsFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/input/InputDotsFragment.kt @@ -8,11 +8,13 @@ import android.widget.TextView import androidx.core.text.parseAsHtml import androidx.databinding.DataBindingUtil import com.github.braillesystems.learnbraille.R +import com.github.braillesystems.learnbraille.data.entities.BrailleDots import com.github.braillesystems.learnbraille.data.entities.InputDots import com.github.braillesystems.learnbraille.data.entities.spelling import com.github.braillesystems.learnbraille.databinding.FragmentLessonsInputDotsBinding import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo import com.github.braillesystems.learnbraille.ui.screens.theory.steps.StepBinding +import com.github.braillesystems.learnbraille.ui.showHintDotsToast import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode import com.github.braillesystems.learnbraille.utils.checkedAnnounce import com.github.braillesystems.learnbraille.utils.removeHtmlMarkup @@ -59,4 +61,12 @@ class InputDotsFragment : AbstractInputStepFragment(R.string.lessons_help_input_ lifecycleOwner = this@InputDotsFragment }.root + + override fun toastHint(expectedDots: BrailleDots) { + showHintDotsToast( + expectedDots, + stepBinding.brailleDotsInfo?.view?.mode + ?: error("Input dots step should have dots") + ) + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 721cb503..c91bf56f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,12 +32,20 @@ Подождите, задание загружается Ответ: точки %s Ответ: %s - точка 1 слева сверху - точка 2 слева посередине - точка 3 слева снизу - точка 4 справа сверху - точка 5 справа посередине - точка 6 справа снизу + + точка 1 слева сверху + точка 2 слева посередине + точка 3 слева снизу + точка 4 справа сверху + точка 5 справа посередине + точка 6 справа снизу + + точка 4 слева сверху + точка 5 слева посередине + точка 6 слева снизу + точка 1 справа сверху + точка 2 справа посередине + точка 3 справа снизу Введите букву: %s Введите латинскую букву: %s