Skip to content

Commit

Permalink
Merge pull request braille-systems#286 from braille-systems/fix/input…
Browse files Browse the repository at this point in the history
…-dots-step-hint

Fix hints in input dots step
  • Loading branch information
zuevval authored Oct 18, 2020
2 parents b1c679d + 1d180b0 commit 80bb242
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context, List<String>> {
private val Context.dotsReadingHintRules by lazyWithContext<Context, List<String>> {
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<Context, List<String>> {
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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,7 +73,7 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra
viewModel.observeEventHint(
viewLifecycleOwner, { dotsState }
) {
showHintToast(expectedDots)
toastHint(expectedDots)
userTouchedDots = true
}

Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
)
}
}
20 changes: 14 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,20 @@
<string name="input_loading">Подождите, задание загружается</string>
<string name="input_hint_template">Ответ: точки %s</string>
<string name="input_dots_hint_template">Ответ: %s</string>
<string name="input_dots_hint_1">точка 1 слева сверху</string>
<string name="input_dots_hint_2">точка 2 слева посередине</string>
<string name="input_dots_hint_3">точка 3 слева снизу</string>
<string name="input_dots_hint_4">точка 4 справа сверху</string>
<string name="input_dots_hint_5">точка 5 справа посередине</string>
<string name="input_dots_hint_6">точка 6 справа снизу</string>

<string name="input_dots_reading_hint_1">точка 1 слева сверху</string>
<string name="input_dots_reading_hint_2">точка 2 слева посередине</string>
<string name="input_dots_reading_hint_3">точка 3 слева снизу</string>
<string name="input_dots_reading_hint_4">точка 4 справа сверху</string>
<string name="input_dots_reading_hint_5">точка 5 справа посередине</string>
<string name="input_dots_reading_hint_6">точка 6 справа снизу</string>

<string name="input_dots_writing_hint_4">точка 4 слева сверху</string>
<string name="input_dots_writing_hint_5">точка 5 слева посередине</string>
<string name="input_dots_writing_hint_6">точка 6 слева снизу</string>
<string name="input_dots_writing_hint_1">точка 1 справа сверху</string>
<string name="input_dots_writing_hint_2">точка 2 справа посередине</string>
<string name="input_dots_writing_hint_3">точка 3 справа снизу</string>

<string name="input_letter_intro_template">Введите букву: %s</string>
<string name="input_latin_letter_intro_template">Введите латинскую букву: %s</string>
Expand Down

0 comments on commit 80bb242

Please sign in to comment.