From 678df654fe758b4b546509917bdcb04424d8cc5b Mon Sep 17 00:00:00 2001 From: Andrey Stoyan Date: Fri, 25 Sep 2020 17:21:10 +0300 Subject: [PATCH] Fix caption mechanism --- CONTRIBUTING.md | 2 + .../learnbraille/res/ResourceTest.kt | 49 ++ .../data/db/LearnBrailleDatabase.kt | 2 + .../data/repository/TheoryRepository.kt | 21 +- .../braillesystems/learnbraille/res/Data.kt | 13 +- .../learnbraille/res/GolubinaCourse.kt | 11 +- .../learnbraille/res/Materials.kt | 441 ++++++++++-------- .../ui/screens/browser/SymbolViewFragment.kt | 5 +- .../ui/screens/practice/CardFragment.kt | 11 +- .../ui/screens/practice/CardViewModel.kt | 6 - .../theory/steps/InputSymbolFragment.kt | 9 +- .../theory/steps/ShowSymbolFragment.kt | 7 +- .../learnbraille/ui/views/BrailleDotsView.kt | 2 +- .../learnbraille/utils/_Kotlin.kt | 2 + app/src/main/res/layout/fragment_card.xml | 4 +- .../layout/fragment_lessons_input_symbol.xml | 4 +- .../layout/fragment_lessons_show_symbol.xml | 4 +- .../main/res/layout/fragment_symbol_view.xml | 4 +- app/src/main/res/values/strings.xml | 1 - build.gradle | 2 +- 20 files changed, 332 insertions(+), 268 deletions(-) create mode 100644 app/src/androidTest/java/com/github/braillesystems/learnbraille/res/ResourceTest.kt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 29f4ed06..ae3bdb82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,3 +24,5 @@ There are handy DSL that allows write content in the typesafe way. - All app content should be placed into `com.github.braillesystems.learnbraille.res` package. - Use `DslTest.kt` file as DSL tutorial. + +Symbols that are not from particular alphabet and does not exist on classical american keyboard should be treated as special and added via `enum class`. diff --git a/app/src/androidTest/java/com/github/braillesystems/learnbraille/res/ResourceTest.kt b/app/src/androidTest/java/com/github/braillesystems/learnbraille/res/ResourceTest.kt new file mode 100644 index 00000000..8779ddde --- /dev/null +++ b/app/src/androidTest/java/com/github/braillesystems/learnbraille/res/ResourceTest.kt @@ -0,0 +1,49 @@ +package com.github.braillesystems.learnbraille.res + +import android.content.Context +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import com.github.braillesystems.learnbraille.utils.get +import org.junit.Assert.assertNotNull +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class ResourceTest { + + private lateinit var context: Context + + @Before + fun before() { + context = InstrumentationRegistry.getInstrumentation().targetContext + } + + @Test + fun inputSymbolPrintRulesTest() { + content.symbols.keys.forEach { + assertNotNull(context.inputSymbolPrintRules[it]) + } + } + + @Test + fun showSymbolPrintRulesTest() { + content.symbols.keys.forEach { + assertNotNull(context.showSymbolPrintRules[it]) + } + } + + @Test + fun inputMarkerPrintRulesTest() { + content.markers.keys.forEach { + assertNotNull(context.inputMarkerPrintRules[it]) + } + } + + @Test + fun showMarkerPrintRulesTest() { + content.markers.keys.forEach { + assertNotNull(context.showMarkerPrintRules[it]) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/data/db/LearnBrailleDatabase.kt b/app/src/main/java/com/github/braillesystems/learnbraille/data/db/LearnBrailleDatabase.kt index 665a01bf..850b7d22 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/data/db/LearnBrailleDatabase.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/data/db/LearnBrailleDatabase.kt @@ -207,3 +207,5 @@ private val MIGRATION_17_18 = object : Migration(17, 18), KoinComponent { Timber.i("Actions table created") } } + +// TODO materials migration diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/data/repository/TheoryRepository.kt b/app/src/main/java/com/github/braillesystems/learnbraille/data/repository/TheoryRepository.kt index fe192a5c..f80b9f26 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/data/repository/TheoryRepository.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/data/repository/TheoryRepository.kt @@ -3,7 +3,6 @@ package com.github.braillesystems.learnbraille.data.repository import com.github.braillesystems.learnbraille.data.entities.* import com.github.braillesystems.learnbraille.res.StepAnnotation import com.github.braillesystems.learnbraille.utils.devnull -import com.github.braillesystems.learnbraille.utils.runIf import com.github.braillesystems.learnbraille.utils.scope import kotlinx.coroutines.launch @@ -31,19 +30,13 @@ class TheoryRepositoryImpl( private val actionsRepository: MutableActionsRepository ) : MutableTheoryRepository { - private fun getProscribedAnnotation(): List { - val result = arrayListOf() - listOf( - !preferenceRepository.golubinaBookStepsEnabled to StepAnnotation.golubinaBookRequired, - !preferenceRepository.slateStylusStepsEnabled to StepAnnotation.slateStylusRequired - ).forEach { - runIf (it.first) { result.add(it.second) } - } - return result - } - - private val proscribedAnnotations - get() = getProscribedAnnotation() + private val proscribedAnnotations: List + get() = listOfNotNull( + if (preferenceRepository.golubinaBookStepsEnabled) null + else StepAnnotation.golubinaBookRequired, + if (preferenceRepository.slateStylusStepsEnabled) null + else StepAnnotation.slateStylusRequired + ) @Suppress("ReturnCount") override suspend fun getNextStepAndUpdate(thisStep: Step, markThisAsPassed: Boolean): Step? { diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/res/Data.kt b/app/src/main/java/com/github/braillesystems/learnbraille/res/Data.kt index 08dc0ca0..54891c8d 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/res/Data.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/res/Data.kt @@ -61,12 +61,12 @@ val prepopulationData by data( decks { // All cards deck should always exist and be first in the list deck(DeckTags.all) { true } + deck(DeckTags.allWithRus) { data -> - data is Symbol && data.type !in listOf( - SymbolType.greek, - SymbolType.latin - ) - || data !is Symbol + val isNative = data is Symbol + && data.type != SymbolType.greek + && data.type != SymbolType.latin + isNative || data !is Symbol } deck(DeckTags.ruLetters) { data -> data is Symbol && data.type == SymbolType.ru @@ -86,10 +86,9 @@ val prepopulationData by data( deck(DeckTags.digits) { data -> data is Symbol && data.type == SymbolType.digit } - deck(DeckTags.math) {data -> + deck(DeckTags.math) { data -> data is Symbol && data.type == SymbolType.math } - } } diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/res/GolubinaCourse.kt b/app/src/main/java/com/github/braillesystems/learnbraille/res/GolubinaCourse.kt index f80100b0..89a44333 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/res/GolubinaCourse.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/res/GolubinaCourse.kt @@ -6,6 +6,7 @@ import com.github.braillesystems.learnbraille.data.dsl.lessons import com.github.braillesystems.learnbraille.data.entities.* import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F +import com.github.braillesystems.learnbraille.res.PunctuationSigns.Hyphen internal val golubinaIntroLessons by lessons { @@ -917,7 +918,7 @@ internal val golubinaIntroLessons by lessons { точки буквы Ц — в верхней трети шеститочия, точки дефиса — в самой нижней. """ ) - +Show(content.symbols.getValue('—')) + +Show(content.symbols.getValue(Hyphen.c)) +Info( """ Переверните страницу в пособии. На странице 31 найдите по центру знак "дефис", @@ -927,11 +928,11 @@ internal val golubinaIntroLessons by lessons { +Info( """Введите по символам слово ПОЛ-ЛИМОНА""" ) - inputChars("ПОЛ—ЛИМОНА") + inputChars("ПОЛ${Hyphen.c}ЛИМОНА") +Info( """И последнее слово, которое нужно ввести в этом уроке — местоимение ГДЕ-ЛИБО""" ) - inputChars("ГДЕ—ЛИБО") + inputChars("ГДЕ${Hyphen.c}ЛИБО") +Info( """ Теперь рекомендуем Вам записать на брайлевском приборе изученные слова: @@ -1270,7 +1271,7 @@ internal val golubinaIntroLessons by lessons { В конце поставьте литературную точку. """ ) - inputChars("ЛЕНИНГРАД—ГОРОД—ГЕРОЙ.") + inputChars("ЛЕНИНГРАД${Hyphen.c}ГОРОД${Hyphen.c}ГЕРОЙ.") +Info( """ Теперь запишите на брайлевском приборе то же самое предложение: @@ -1302,7 +1303,7 @@ internal val golubinaIntroLessons by lessons { Введите цифровой знак, запятую, дефис и точку""" ) +Input(content.markers.getValue(MarkerType.NumberSign)) - inputChars(",—.") + inputChars(",${Hyphen.c}.") +Info( """ Переходим к изучению точечного состава буквы Ы. diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/res/Materials.kt b/app/src/main/java/com/github/braillesystems/learnbraille/res/Materials.kt index 7b417013..d518e6f0 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/res/Materials.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/res/Materials.kt @@ -1,6 +1,7 @@ package com.github.braillesystems.learnbraille.res import android.content.Context +import androidx.fragment.app.Fragment import com.github.braillesystems.learnbraille.R import com.github.braillesystems.learnbraille.data.dsl.known import com.github.braillesystems.learnbraille.data.dsl.markers @@ -10,6 +11,9 @@ import com.github.braillesystems.learnbraille.data.entities.BrailleDot.E import com.github.braillesystems.learnbraille.data.entities.BrailleDot.F import com.github.braillesystems.learnbraille.data.entities.BrailleDots import com.github.braillesystems.learnbraille.data.entities.Symbol +import com.github.braillesystems.learnbraille.res.MathSigns.* +import com.github.braillesystems.learnbraille.res.PunctuationSigns.* +import com.github.braillesystems.learnbraille.utils.contextNotNull import com.github.braillesystems.learnbraille.utils.rules import kotlinx.serialization.Serializable @@ -38,9 +42,6 @@ enum class MarkerType { * * Always use this variable to get materials. */ - -// TODO write a migration for lat, greek, etc - val content by materials { +ruSymbols +punctuationSigns @@ -55,6 +56,167 @@ val knownMaterials by known( 'А', 'Б', 'Ц', 'Д', 'Е', 'Ф', 'Г' ) + +private val ruSymbols by symbols(SymbolType.ru) { + // UTF-16: 0410-042F + symbol(char = 'А', brailleDots = BrailleDots(F, E, E, E, E, E)) + symbol(char = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E)) + symbol(char = 'В', brailleDots = BrailleDots(E, F, E, F, F, F)) + symbol(char = 'Г', brailleDots = BrailleDots(F, F, E, F, F, E)) + symbol(char = 'Д', brailleDots = BrailleDots(F, E, E, F, F, E)) + symbol(char = 'Е', brailleDots = BrailleDots(F, E, E, E, F, E)) + symbol(char = 'Ё', brailleDots = BrailleDots(F, E, E, E, E, F)) + symbol(char = 'Ж', brailleDots = BrailleDots(E, F, E, F, F, E)) + symbol(char = 'З', brailleDots = BrailleDots(F, E, F, E, F, F)) + symbol(char = 'И', brailleDots = BrailleDots(E, F, E, F, E, E)) + symbol(char = 'Й', brailleDots = BrailleDots(F, F, F, F, E, F)) + symbol(char = 'К', brailleDots = BrailleDots(F, E, F, E, E, E)) + symbol(char = 'Л', brailleDots = BrailleDots(F, F, F, E, E, E)) + symbol(char = 'М', brailleDots = BrailleDots(F, E, F, F, E, E)) + symbol(char = 'Н', brailleDots = BrailleDots(F, E, F, F, F, E)) + symbol(char = 'О', brailleDots = BrailleDots(F, E, F, E, F, E)) + symbol(char = 'П', brailleDots = BrailleDots(F, F, F, F, E, E)) + symbol(char = 'Р', brailleDots = BrailleDots(F, F, F, E, F, E)) + symbol(char = 'С', brailleDots = BrailleDots(E, F, F, F, E, E)) + symbol(char = 'Т', brailleDots = BrailleDots(E, F, F, F, F, E)) + symbol(char = 'У', brailleDots = BrailleDots(F, E, F, E, E, F)) + symbol(char = 'Ф', brailleDots = BrailleDots(F, F, E, F, E, E)) + symbol(char = 'Х', brailleDots = BrailleDots(F, F, E, E, F, E)) + symbol(char = 'Ц', brailleDots = BrailleDots(F, E, E, F, E, E)) + symbol(char = 'Ч', brailleDots = BrailleDots(F, F, F, F, F, E)) + symbol(char = 'Ш', brailleDots = BrailleDots(F, E, E, E, F, F)) + symbol(char = 'Щ', brailleDots = BrailleDots(F, E, F, F, E, F)) + symbol(char = 'Ъ', brailleDots = BrailleDots(F, F, F, E, F, F)) + symbol(char = 'Ы', brailleDots = BrailleDots(E, F, F, F, E, F)) + symbol(char = 'Ь', brailleDots = BrailleDots(E, F, F, F, F, F)) + symbol(char = 'Э', brailleDots = BrailleDots(E, F, E, F, E, F)) + symbol(char = 'Ю', brailleDots = BrailleDots(F, F, E, E, F, F)) + symbol(char = 'Я', brailleDots = BrailleDots(F, F, E, F, E, F)) +} + +enum class PunctuationSigns(val c: Char) { + Hyphen('—'), + LeftQuotation('«'), + RightQuotation('»') +} + +private val punctuationSigns by symbols(SymbolType.special) { + symbol(char = ',', brailleDots = BrailleDots(E, F, E, E, E, E)) // Comma + symbol(char = Hyphen.c, brailleDots = BrailleDots(E, E, F, E, E, F)) // Hyphen + symbol(char = '.', brailleDots = BrailleDots(E, F, E, E, F, F)) // Dot + symbol(char = '!', brailleDots = BrailleDots(E, F, F, E, F, E)) // Exclamation mark + symbol(char = '?', brailleDots = BrailleDots(E, F, E, E, E, F)) // Question mark + symbol(char = LeftQuotation.c, brailleDots = BrailleDots(E, F, F, E, E, F)) + symbol(char = RightQuotation.c, brailleDots = BrailleDots(E, E, F, E, F, F)) + symbol(char = '(', brailleDots = BrailleDots(F, F, E, E, E, F)) // Left parenthesis + symbol(char = ')', brailleDots = BrailleDots(E, E, F, F, F, E)) // Right parenthesis + symbol(char = '*', brailleDots = BrailleDots(E, E, F, E, F, E)) // Asterisk + symbol(char = ':', brailleDots = BrailleDots(E, F, E, E, F, E)) // Colon + symbol(char = ';', brailleDots = BrailleDots(E, F, F, E, E, E)) // Semicolon + symbol(char = '\'', brailleDots = BrailleDots(E, E, E, F, E, E)) // Stress +} + +enum class MathSigns(val c: Char) { + DotMul('·'), + CrossMul('✕'), + Div('÷') +} + +private val mathSigns by symbols(SymbolType.math) { + symbol(char = '+', brailleDots = BrailleDots(E, F, F, E, F, E)) // Plus + symbol(char = '-', brailleDots = BrailleDots(E, E, F, E, E, F)) // Minus + symbol(char = DotMul.c, brailleDots = BrailleDots(E, E, F, E, E, E)) // Dot multiplication + symbol(char = CrossMul.c, brailleDots = BrailleDots(E, F, F, E, E, F)) // Cross multiplication + symbol(char = '/', brailleDots = BrailleDots(E, E, F, E, F, F)) // Division (fraction) + symbol(char = Div.c, brailleDots = BrailleDots(E, F, E, E, F, F)) // Division + symbol(char = '=', brailleDots = BrailleDots(E, F, F, E, F, F)) // Equality +} + +private val uebDigits by symbols(SymbolType.digit) { + // UTF-16: 0030-0039 + symbol(char = '0', brailleDots = BrailleDots(E, F, E, F, F, E)) + symbol(char = '1', brailleDots = BrailleDots(F, E, E, E, E, E)) + symbol(char = '2', brailleDots = BrailleDots(F, F, E, E, E, E)) + symbol(char = '3', brailleDots = BrailleDots(F, E, E, F, E, E)) + symbol(char = '4', brailleDots = BrailleDots(F, E, E, F, F, E)) + symbol(char = '5', brailleDots = BrailleDots(F, E, E, E, F, E)) + symbol(char = '6', brailleDots = BrailleDots(F, F, E, F, E, E)) + symbol(char = '7', brailleDots = BrailleDots(F, F, E, F, F, E)) + symbol(char = '8', brailleDots = BrailleDots(F, F, E, E, F, E)) + symbol(char = '9', brailleDots = BrailleDots(E, F, E, F, E, E)) +} + +private val latinLetters by symbols(SymbolType.latin) { + // UTF-16: 0041-005A + symbol(char = 'A', brailleDots = BrailleDots(F, E, E, E, E, E)) + symbol(char = 'B', brailleDots = BrailleDots(F, F, E, E, E, E)) + symbol(char = 'C', brailleDots = BrailleDots(F, E, E, F, E, E)) + symbol(char = 'D', brailleDots = BrailleDots(F, E, E, F, F, E)) + symbol(char = 'E', brailleDots = BrailleDots(F, E, E, E, F, E)) + symbol(char = 'F', brailleDots = BrailleDots(F, F, E, F, E, E)) + symbol(char = 'G', brailleDots = BrailleDots(F, F, E, F, F, E)) + symbol(char = 'H', brailleDots = BrailleDots(F, F, E, E, F, E)) + symbol(char = 'I', brailleDots = BrailleDots(E, F, E, F, E, E)) + symbol(char = 'J', brailleDots = BrailleDots(E, F, E, F, F, E)) + symbol(char = 'K', brailleDots = BrailleDots(F, E, F, E, E, E)) + symbol(char = 'L', brailleDots = BrailleDots(F, F, F, E, E, E)) + symbol(char = 'M', brailleDots = BrailleDots(F, E, F, F, E, E)) + symbol(char = 'N', brailleDots = BrailleDots(F, E, F, F, F, E)) + symbol(char = 'O', brailleDots = BrailleDots(F, E, F, E, F, E)) + symbol(char = 'P', brailleDots = BrailleDots(F, F, F, F, E, E)) + symbol(char = 'Q', brailleDots = BrailleDots(F, F, F, F, F, E)) + symbol(char = 'R', brailleDots = BrailleDots(F, F, F, E, F, E)) + symbol(char = 'S', brailleDots = BrailleDots(E, F, F, F, E, E)) + symbol(char = 'T', brailleDots = BrailleDots(E, F, F, F, F, E)) + symbol(char = 'U', brailleDots = BrailleDots(F, E, F, E, E, F)) + symbol(char = 'V', brailleDots = BrailleDots(F, F, F, E, E, F)) + symbol(char = 'W', brailleDots = BrailleDots(E, F, E, F, F, F)) + symbol(char = 'X', brailleDots = BrailleDots(F, E, F, F, E, F)) + symbol(char = 'Y', brailleDots = BrailleDots(F, E, F, F, F, F)) + symbol(char = 'Z', brailleDots = BrailleDots(F, E, F, E, F, F)) +} + +private val greekLetters by symbols(SymbolType.greek) { + // Note: A - Alpha (Unicode char 0391); A - English (0041); А - Russian (0410) + // You may check the code by copying and pasting at https://r12a.github.io/app-conversion/ + // Capital greek letters in UTF-16: 0391-03A9 + symbol(char = 'Α', brailleDots = BrailleDots(F, E, E, E, E, E)) + symbol(char = 'Β', brailleDots = BrailleDots(F, F, E, E, E, E)) + symbol(char = 'Γ', brailleDots = BrailleDots(F, F, E, F, F, E)) + symbol(char = 'Δ', brailleDots = BrailleDots(F, E, E, F, F, E)) + symbol(char = 'Ε', brailleDots = BrailleDots(F, E, E, E, F, E)) + symbol(char = 'Ζ', brailleDots = BrailleDots(F, E, F, E, F, F)) + symbol(char = 'Η', brailleDots = BrailleDots(E, F, E, F, F, E)) + symbol(char = 'Θ', brailleDots = BrailleDots(F, F, E, E, F, E)) + symbol(char = 'Ι', brailleDots = BrailleDots(E, F, E, F, E, E)) + symbol(char = 'Κ', brailleDots = BrailleDots(F, E, F, E, E, E)) + symbol(char = 'Λ', brailleDots = BrailleDots(F, F, F, E, E, E)) + symbol(char = 'Μ', brailleDots = BrailleDots(F, E, F, F, E, E)) + symbol(char = 'Ν', brailleDots = BrailleDots(F, E, F, F, F, E)) + symbol(char = 'Ξ', brailleDots = BrailleDots(F, E, F, F, E, F)) + symbol(char = 'Ο', brailleDots = BrailleDots(F, E, F, E, F, E)) + symbol(char = 'Π', brailleDots = BrailleDots(F, F, F, F, E, E)) + symbol(char = 'Ρ', brailleDots = BrailleDots(F, F, F, E, F, E)) + symbol(char = 'Σ', brailleDots = BrailleDots(E, F, F, F, E, E)) + symbol(char = 'Τ', brailleDots = BrailleDots(E, F, F, F, F, E)) + symbol(char = 'Υ', brailleDots = BrailleDots(F, E, F, E, E, F)) + symbol(char = 'Φ', brailleDots = BrailleDots(F, F, E, F, E, E)) + symbol(char = 'Χ', brailleDots = BrailleDots(F, E, E, F, E, E)) + symbol(char = 'Ψ', brailleDots = BrailleDots(F, E, F, F, F, F)) + symbol(char = 'Ω', brailleDots = BrailleDots(E, F, E, F, F, F)) +} + +private val ms by markers { + marker(MarkerType.GreekCapital, BrailleDots(E, E, E, F, F, F)) + marker(MarkerType.LatinCapital, BrailleDots(E, E, E, F, E, F)) + marker(MarkerType.LatinSmall, BrailleDots(E, E, E, E, E, F)) + marker(MarkerType.RussianCapital, BrailleDots(E, E, E, F, F, E)) + marker(MarkerType.BoldFont, BrailleDots(F, F, E, F, F, F)) + marker(MarkerType.ItalicFont, BrailleDots(E, E, E, F, F, F)) + marker(MarkerType.NumberSign, BrailleDots(E, E, F, F, F, F)) +} + + /* * Add here rules, how to display hints for symbols. * @@ -62,6 +224,8 @@ val knownMaterials by known( * so use `Fragment.getString` outside of lambdas. */ +val Fragment.captionRules get() = contextNotNull.captionRules + val Context.inputSymbolPrintRules by rules( { val t = getString(R.string.input_letter_intro_template) @@ -84,7 +248,6 @@ val Context.inputSymbolPrintRules by rules( }, { - val other = getString(R.string.input_special_intro_template) val dotIntro = getString(R.string.input_special_intro_dot) val commaIntro = getString(R.string.input_special_intro_comma) val hyphenIntro = getString(R.string.input_special_intro_hyphen) @@ -102,24 +265,23 @@ val Context.inputSymbolPrintRules by rules( when (c) { '.' -> dotIntro ',' -> commaIntro - '—' -> hyphenIntro + Hyphen.c -> hyphenIntro '!' -> exclamationIntro '?' -> questionIntro - '«' -> quotationLeftIntro - '»' -> quotationRightIntro + LeftQuotation.c -> quotationLeftIntro + RightQuotation.c -> quotationRightIntro '(' -> parenthesisLeftIntro ')' -> parenthesisRightIntro '*' -> asteriskIntro ':' -> colonIntro ';' -> semicolonIntro '\'' -> stressIntro - else -> other.format(c) + else -> error("Undefined symbol: $c") } } }, { - val other = getString(R.string.input_math_intro_template) val plusIntro = getString(R.string.input_math_plus) val minusIntro = getString(R.string.input_math_minus) val dotMultIntro = getString(R.string.input_math_dot_mult) @@ -131,12 +293,12 @@ val Context.inputSymbolPrintRules by rules( when (c) { '+' -> plusIntro '-' -> minusIntro - '·' -> dotMultIntro - '✕' -> crossMultIntro + DotMul.c -> dotMultIntro + CrossMul.c -> crossMultIntro '/' -> fracDivisionIntro - '÷' -> divisionIntro + Div.c -> divisionIntro '=' -> equalityIntro - else -> other.format(c) + else -> error("Undefined symbol: $c") } } } @@ -165,7 +327,6 @@ val Context.showSymbolPrintRules by rules( }, { - val other = getString(R.string.show_special_intro_template) val dotIntro = getString(R.string.show_special_intro_dot) val commaIntro = getString(R.string.show_special_intro_comma) val hyphenIntro = getString(R.string.show_special_intro_hyphen) @@ -183,24 +344,23 @@ val Context.showSymbolPrintRules by rules( when (c) { '.' -> dotIntro ',' -> commaIntro - '—' -> hyphenIntro + Hyphen.c -> hyphenIntro '!' -> exclamationIntro '?' -> questionIntro - '«' -> quotationLeftIntro - '»' -> quotationRightIntro + LeftQuotation.c -> quotationLeftIntro + RightQuotation.c -> quotationRightIntro '(' -> parenthesisLeftIntro ')' -> parenthesisRightIntro '*' -> asteriskIntro ':' -> colonIntro ';' -> semicolonIntro '\'' -> stressIntro - else -> other.format(c) + else -> error("Undefined symbol: $c") } } }, { - val other = getString(R.string.show_math_intro_template) val plusIntro = getString(R.string.show_math_plus) val minusIntro = getString(R.string.show_math_minus) val dotMultIntro = getString(R.string.show_math_dot_mult) @@ -212,56 +372,71 @@ val Context.showSymbolPrintRules by rules( when (c) { '+' -> plusIntro '-' -> minusIntro - '·' -> dotMultIntro - '✕' -> crossMultIntro + DotMul.c -> dotMultIntro + CrossMul.c -> crossMultIntro '/' -> fracDivisionIntro - '÷' -> divisionIntro + Div.c -> divisionIntro '=' -> equalityIntro - else -> other.format(c) + else -> error("Undefined symbol: $c") } } } ) -fun getSpecialCaptionId(symbol: Symbol): Int? { - val specialCaptions = mapOf( - '.' to R.string.show_special_intro_dot, ',' to R.string.show_special_intro_comma, - '—' to R.string.show_special_intro_hyphen, - '!' to R.string.show_special_intro_exclamation, - '?' to R.string.show_special_intro_question, - '«' to R.string.show_special_intro_quotation_left, - '»' to R.string.show_special_intro_quotation_right, - '(' to R.string.show_special_intro_parenthesis_left, - ')' to R.string.show_special_intro_parenthesis_right, - '*' to R.string.show_special_intro_asterisk, - ':' to R.string.show_special_intro_colon, - ';' to R.string.show_special_intro_semicolon, - '\'' to R.string.show_special_intro_stress, - '+' to R.string.show_math_plus, - '-' to R.string.show_math_minus, - '·' to R.string.show_math_dot_mult, - '✕' to R.string.show_math_cross_mult, - '/' to R.string.show_math_division_fraction, - '÷' to R.string.show_math_division, - '=' to R.string.show_math_equality - ) - return if (specialCaptions.containsKey(symbol.char)) specialCaptions[symbol.char] else null -} +val Context.captionRules by rules( + { + val specialCaptions = mapOf( + '.' to R.string.show_special_intro_dot, + ',' to R.string.show_special_intro_comma, + Hyphen.c to R.string.show_special_intro_hyphen, + '!' to R.string.show_special_intro_exclamation, + '?' to R.string.show_special_intro_question, + LeftQuotation.c to R.string.show_special_intro_quotation_left, + RightQuotation.c to R.string.show_special_intro_quotation_right, + '(' to R.string.show_special_intro_parenthesis_left, + ')' to R.string.show_special_intro_parenthesis_right, + '*' to R.string.show_special_intro_asterisk, + ':' to R.string.show_special_intro_colon, + ';' to R.string.show_special_intro_semicolon, + '\'' to R.string.show_special_intro_stress, + '+' to R.string.show_math_plus, + '-' to R.string.show_math_minus, + DotMul.c to R.string.show_math_dot_mult, + CrossMul.c to R.string.show_math_cross_mult, + '/' to R.string.show_math_division_fraction, + Div.c to R.string.show_math_division, + '=' to R.string.show_math_equality + ).mapValues { + getString(it.value) + } + return@rules { s: Symbol -> + specialCaptions.containsKey(s.char) + } to { s: Symbol -> + specialCaptions.getValue(s.char) + } + }, -fun getCaptionTitleId(symbol: Symbol): Int { - val specialCaptionId = getSpecialCaptionId(symbol) - if (specialCaptionId != null) { - return specialCaptionId - } - return when (symbol.type) { - SymbolType.ru -> R.string.letter_caption_ru - SymbolType.greek -> R.string.letter_caption_greek - SymbolType.latin -> R.string.letter_caption_latin - SymbolType.digit -> R.string.letter_caption_digit - SymbolType.special -> R.string.letter_caption_special - else -> R.string.empty_string + { + val specialCaptions = mapOf( + SymbolType.ru to R.string.letter_caption_ru, + SymbolType.greek to R.string.letter_caption_greek, + SymbolType.latin to R.string.letter_caption_latin, + SymbolType.digit to R.string.letter_caption_digit, + SymbolType.special to R.string.letter_caption_special + ).mapValues { + getString(it.value) + } + return@rules { s: Symbol -> + specialCaptions.containsKey(s.type) + } to { s: Symbol -> + specialCaptions.getValue(s.type) + } + }, + + { + { _: Symbol -> true } to { _: Symbol -> "" } } -} +) val Context.inputMarkerPrintRules by rules( { @@ -341,149 +516,3 @@ val Context.showMarkerPrintRules by rules( MarkerType.NumberSign::equals to { _: MarkerType -> s } } ) - -private val ruSymbols by symbols(SymbolType.ru) { - // UTF-16: 0410-042F - symbol(char = 'А', brailleDots = BrailleDots(F, E, E, E, E, E)) - symbol(char = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E)) - symbol(char = 'В', brailleDots = BrailleDots(E, F, E, F, F, F)) - symbol(char = 'Г', brailleDots = BrailleDots(F, F, E, F, F, E)) - symbol(char = 'Д', brailleDots = BrailleDots(F, E, E, F, F, E)) - symbol(char = 'Е', brailleDots = BrailleDots(F, E, E, E, F, E)) - symbol(char = 'Ё', brailleDots = BrailleDots(F, E, E, E, E, F)) - symbol(char = 'Ж', brailleDots = BrailleDots(E, F, E, F, F, E)) - symbol(char = 'З', brailleDots = BrailleDots(F, E, F, E, F, F)) - symbol(char = 'И', brailleDots = BrailleDots(E, F, E, F, E, E)) - symbol(char = 'Й', brailleDots = BrailleDots(F, F, F, F, E, F)) - symbol(char = 'К', brailleDots = BrailleDots(F, E, F, E, E, E)) - symbol(char = 'Л', brailleDots = BrailleDots(F, F, F, E, E, E)) - symbol(char = 'М', brailleDots = BrailleDots(F, E, F, F, E, E)) - symbol(char = 'Н', brailleDots = BrailleDots(F, E, F, F, F, E)) - symbol(char = 'О', brailleDots = BrailleDots(F, E, F, E, F, E)) - symbol(char = 'П', brailleDots = BrailleDots(F, F, F, F, E, E)) - symbol(char = 'Р', brailleDots = BrailleDots(F, F, F, E, F, E)) - symbol(char = 'С', brailleDots = BrailleDots(E, F, F, F, E, E)) - symbol(char = 'Т', brailleDots = BrailleDots(E, F, F, F, F, E)) - symbol(char = 'У', brailleDots = BrailleDots(F, E, F, E, E, F)) - symbol(char = 'Ф', brailleDots = BrailleDots(F, F, E, F, E, E)) - symbol(char = 'Х', brailleDots = BrailleDots(F, F, E, E, F, E)) - symbol(char = 'Ц', brailleDots = BrailleDots(F, E, E, F, E, E)) - symbol(char = 'Ч', brailleDots = BrailleDots(F, F, F, F, F, E)) - symbol(char = 'Ш', brailleDots = BrailleDots(F, E, E, E, F, F)) - symbol(char = 'Щ', brailleDots = BrailleDots(F, E, F, F, E, F)) - symbol(char = 'Ъ', brailleDots = BrailleDots(F, F, F, E, F, F)) - symbol(char = 'Ы', brailleDots = BrailleDots(E, F, F, F, E, F)) - symbol(char = 'Ь', brailleDots = BrailleDots(E, F, F, F, F, F)) - symbol(char = 'Э', brailleDots = BrailleDots(E, F, E, F, E, F)) - symbol(char = 'Ю', brailleDots = BrailleDots(F, F, E, E, F, F)) - symbol(char = 'Я', brailleDots = BrailleDots(F, F, E, F, E, F)) -} -private val punctuationSigns by symbols(SymbolType.special) { - symbol(char = ',', brailleDots = BrailleDots(E, F, E, E, E, E)) // Comma - symbol(char = '—', brailleDots = BrailleDots(E, E, F, E, E, F)) // Hyphen - symbol(char = '.', brailleDots = BrailleDots(E, F, E, E, F, F)) // Dot - symbol(char = '!', brailleDots = BrailleDots(E, F, F, E, F, E)) // Exclamation mark - symbol(char = '?', brailleDots = BrailleDots(E, F, E, E, E, F)) // Question mark - symbol(char = '«', brailleDots = BrailleDots(E, F, F, E, E, F)) // Left quotation mark - symbol(char = '»', brailleDots = BrailleDots(E, E, F, E, F, F)) // Right quotation mark - symbol(char = '(', brailleDots = BrailleDots(F, F, E, E, E, F)) // Left parenthesis - symbol(char = ')', brailleDots = BrailleDots(E, E, F, F, F, E)) // Right parenthesis - symbol(char = '*', brailleDots = BrailleDots(E, E, F, E, F, E)) // Asterisk - symbol(char = ':', brailleDots = BrailleDots(E, F, E, E, F, E)) // Colon - symbol(char = ';', brailleDots = BrailleDots(E, F, F, E, E, E)) // Semicolon - symbol(char = '\'', brailleDots = BrailleDots(E, E, E, F, E, E)) // Stress -} - -private val mathSigns by symbols(SymbolType.math) { - symbol(char = '+', brailleDots = BrailleDots(E, F, F, E, F, E)) // Plus - symbol(char = '-', brailleDots = BrailleDots(E, E, F, E, E, F)) // Minus - symbol(char = '·', brailleDots = BrailleDots(E, E, F, E, E, E)) // Dot multiplication - symbol(char = '✕', brailleDots = BrailleDots(E, F, F, E, E, F)) // Cross multiplication - symbol(char = '/', brailleDots = BrailleDots(E, E, F, E, F, F)) // Division (fraction) - symbol(char = '÷', brailleDots = BrailleDots(E, F, E, E, F, F)) // Division - symbol(char = '=', brailleDots = BrailleDots(E, F, F, E, F, F)) // Equality -} - -private val uebDigits by symbols(SymbolType.digit) { - // UTF-16: 0030-0039 - symbol(char = '0', brailleDots = BrailleDots(E, F, E, F, F, E)) - symbol(char = '1', brailleDots = BrailleDots(F, E, E, E, E, E)) - symbol(char = '2', brailleDots = BrailleDots(F, F, E, E, E, E)) - symbol(char = '3', brailleDots = BrailleDots(F, E, E, F, E, E)) - symbol(char = '4', brailleDots = BrailleDots(F, E, E, F, F, E)) - symbol(char = '5', brailleDots = BrailleDots(F, E, E, E, F, E)) - symbol(char = '6', brailleDots = BrailleDots(F, F, E, F, E, E)) - symbol(char = '7', brailleDots = BrailleDots(F, F, E, F, F, E)) - symbol(char = '8', brailleDots = BrailleDots(F, F, E, E, F, E)) - symbol(char = '9', brailleDots = BrailleDots(E, F, E, F, E, E)) -} - -private val latinLetters by symbols(SymbolType.latin) { - // UTF-16: 0041-005A - symbol(char = 'A', brailleDots = BrailleDots(F, E, E, E, E, E)) - symbol(char = 'B', brailleDots = BrailleDots(F, F, E, E, E, E)) - symbol(char = 'C', brailleDots = BrailleDots(F, E, E, F, E, E)) - symbol(char = 'D', brailleDots = BrailleDots(F, E, E, F, F, E)) - symbol(char = 'E', brailleDots = BrailleDots(F, E, E, E, F, E)) - symbol(char = 'F', brailleDots = BrailleDots(F, F, E, F, E, E)) - symbol(char = 'G', brailleDots = BrailleDots(F, F, E, F, F, E)) - symbol(char = 'H', brailleDots = BrailleDots(F, F, E, E, F, E)) - symbol(char = 'I', brailleDots = BrailleDots(E, F, E, F, E, E)) - symbol(char = 'J', brailleDots = BrailleDots(E, F, E, F, F, E)) - symbol(char = 'K', brailleDots = BrailleDots(F, E, F, E, E, E)) - symbol(char = 'L', brailleDots = BrailleDots(F, F, F, E, E, E)) - symbol(char = 'M', brailleDots = BrailleDots(F, E, F, F, E, E)) - symbol(char = 'N', brailleDots = BrailleDots(F, E, F, F, F, E)) - symbol(char = 'O', brailleDots = BrailleDots(F, E, F, E, F, E)) - symbol(char = 'P', brailleDots = BrailleDots(F, F, F, F, E, E)) - symbol(char = 'Q', brailleDots = BrailleDots(F, F, F, F, F, E)) - symbol(char = 'R', brailleDots = BrailleDots(F, F, F, E, F, E)) - symbol(char = 'S', brailleDots = BrailleDots(E, F, F, F, E, E)) - symbol(char = 'T', brailleDots = BrailleDots(E, F, F, F, F, E)) - symbol(char = 'U', brailleDots = BrailleDots(F, E, F, E, E, F)) - symbol(char = 'V', brailleDots = BrailleDots(F, F, F, E, E, F)) - symbol(char = 'W', brailleDots = BrailleDots(E, F, E, F, F, F)) - symbol(char = 'X', brailleDots = BrailleDots(F, E, F, F, E, F)) - symbol(char = 'Y', brailleDots = BrailleDots(F, E, F, F, F, F)) - symbol(char = 'Z', brailleDots = BrailleDots(F, E, F, E, F, F)) -} - -private val greekLetters by symbols(SymbolType.greek) { - // Note: A - Alpha (Unicode char 0391); A - English (0041); А - Russian (0410) - // You may check the code by copying and pasting at https://r12a.github.io/app-conversion/ - // Capital greek letters in UTF-16: 0391-03A9 - symbol(char = 'Α', brailleDots = BrailleDots(F, E, E, E, E, E)) - symbol(char = 'Β', brailleDots = BrailleDots(F, F, E, E, E, E)) - symbol(char = 'Γ', brailleDots = BrailleDots(F, F, E, F, F, E)) - symbol(char = 'Δ', brailleDots = BrailleDots(F, E, E, F, F, E)) - symbol(char = 'Ε', brailleDots = BrailleDots(F, E, E, E, F, E)) - symbol(char = 'Ζ', brailleDots = BrailleDots(F, E, F, E, F, F)) - symbol(char = 'Η', brailleDots = BrailleDots(E, F, E, F, F, E)) - symbol(char = 'Θ', brailleDots = BrailleDots(F, F, E, E, F, E)) - symbol(char = 'Ι', brailleDots = BrailleDots(E, F, E, F, E, E)) - symbol(char = 'Κ', brailleDots = BrailleDots(F, E, F, E, E, E)) - symbol(char = 'Λ', brailleDots = BrailleDots(F, F, F, E, E, E)) - symbol(char = 'Μ', brailleDots = BrailleDots(F, E, F, F, E, E)) - symbol(char = 'Ν', brailleDots = BrailleDots(F, E, F, F, F, E)) - symbol(char = 'Ξ', brailleDots = BrailleDots(F, E, F, F, E, F)) - symbol(char = 'Ο', brailleDots = BrailleDots(F, E, F, E, F, E)) - symbol(char = 'Π', brailleDots = BrailleDots(F, F, F, F, E, E)) - symbol(char = 'Ρ', brailleDots = BrailleDots(F, F, F, E, F, E)) - symbol(char = 'Σ', brailleDots = BrailleDots(E, F, F, F, E, E)) - symbol(char = 'Τ', brailleDots = BrailleDots(E, F, F, F, F, E)) - symbol(char = 'Υ', brailleDots = BrailleDots(F, E, F, E, E, F)) - symbol(char = 'Φ', brailleDots = BrailleDots(F, F, E, F, E, E)) - symbol(char = 'Χ', brailleDots = BrailleDots(F, E, E, F, E, E)) - symbol(char = 'Ψ', brailleDots = BrailleDots(F, E, F, F, F, F)) - symbol(char = 'Ω', brailleDots = BrailleDots(E, F, E, F, F, F)) -} - -private val ms by markers { - marker(MarkerType.GreekCapital, BrailleDots(E, E, E, F, F, F)) - marker(MarkerType.LatinCapital, BrailleDots(E, E, E, F, E, F)) - marker(MarkerType.LatinSmall, BrailleDots(E, E, E, E, E, F)) - marker(MarkerType.RussianCapital, BrailleDots(E, E, E, F, F, E)) - marker(MarkerType.BoldFont, BrailleDots(F, F, E, F, F, F)) - marker(MarkerType.ItalicFont, BrailleDots(E, E, E, F, F, F)) - marker(MarkerType.NumberSign, BrailleDots(E, E, F, F, F, F)) -} diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt index 7980c68d..b6de0f3d 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/browser/SymbolViewFragment.kt @@ -8,11 +8,12 @@ import com.github.braillesystems.learnbraille.R import com.github.braillesystems.learnbraille.data.entities.Material import com.github.braillesystems.learnbraille.data.entities.Symbol import com.github.braillesystems.learnbraille.databinding.FragmentSymbolViewBinding -import com.github.braillesystems.learnbraille.res.getCaptionTitleId +import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp import com.github.braillesystems.learnbraille.ui.views.display import com.github.braillesystems.learnbraille.ui.views.dotsState import com.github.braillesystems.learnbraille.utils.getFragmentStringArg +import com.github.braillesystems.learnbraille.utils.getValue import com.github.braillesystems.learnbraille.utils.parse class SymbolViewFragment : AbstractFragmentWithHelp(R.string.browser_symbol_view_help) { @@ -34,7 +35,7 @@ class SymbolViewFragment : AbstractFragmentWithHelp(R.string.browser_symbol_view require(m.data is Symbol) binding.letter.text = m.data.char.toString() - binding.letterCaptionTextView.text = getString(getCaptionTitleId(m.data)) + binding.letterCaption.text = captionRules.getValue(m.data) binding.brailleDots.dotsState.display(m.data.brailleDots) }.root diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt index e61acd4a..4ad4f91c 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardFragment.kt @@ -13,6 +13,7 @@ import com.github.braillesystems.learnbraille.data.entities.MarkerSymbol import com.github.braillesystems.learnbraille.data.entities.Symbol import com.github.braillesystems.learnbraille.data.repository.PreferenceRepository import com.github.braillesystems.learnbraille.databinding.FragmentCardBinding +import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.res.deckTagToName import com.github.braillesystems.learnbraille.res.inputMarkerPrintRules import com.github.braillesystems.learnbraille.ui.* @@ -24,7 +25,6 @@ import com.github.braillesystems.learnbraille.ui.views.brailleDots import com.github.braillesystems.learnbraille.ui.views.dotsState import com.github.braillesystems.learnbraille.ui.views.subscribe import com.github.braillesystems.learnbraille.utils.* -import kotlinx.android.synthetic.main.fragment_card.* import org.koin.android.ext.android.inject import org.koin.core.parameter.parametersOf import timber.log.Timber @@ -105,11 +105,13 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) { binding.letter.visibility = View.VISIBLE binding.markerDescription.visibility = View.GONE binding.letter.text = it.char.toString() + binding.letterCaption.text = captionRules.getValue(it) } is MarkerSymbol -> { binding.letter.visibility = View.GONE binding.markerDescription.visibility = View.VISIBLE binding.markerDescription.text = contextNotNull.inputMarkerPrintRules[it.type] + binding.letterCaption.text = "" } } }) @@ -160,13 +162,6 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) { } ) - viewModel.symbolCaptionId.observe( - viewLifecycleOwner, - Observer { - letter_caption_text_view.text = it?.let { it1 -> getString(it1) } - } - ) - viewModel.deckTag.observe( viewLifecycleOwner, Observer { tag -> diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardViewModel.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardViewModel.kt index b560a508..f5dfe5d9 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardViewModel.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/practice/CardViewModel.kt @@ -5,7 +5,6 @@ import androidx.lifecycle.* import com.github.braillesystems.learnbraille.data.entities.* import com.github.braillesystems.learnbraille.data.repository.MutableActionsRepository import com.github.braillesystems.learnbraille.data.repository.MutablePracticeRepository -import com.github.braillesystems.learnbraille.res.getCaptionTitleId import com.github.braillesystems.learnbraille.ui.screens.DotsChecker import com.github.braillesystems.learnbraille.ui.screens.MutableDotsChecker import com.github.braillesystems.learnbraille.utils.retryN @@ -44,10 +43,6 @@ class CardViewModel( private val _symbol = MutableLiveData() val symbol: LiveData get() = _symbol - // not string! https://medium.com/androiddevelopers/locale-changes-and-the-androidviewmodel-antipattern-84eb677660d9 - private val _symbolCaptionId = MutableLiveData() - val symbolCaptionId: LiveData get() = _symbolCaptionId - private val _deckTag = MutableLiveData() val deckTag: LiveData get() = _deckTag @@ -116,7 +111,6 @@ class CardViewModel( material.data.let { _symbol.value = it - if (it is Symbol) _symbolCaptionId.value = getCaptionTitleId(it) expectedDots = when (it) { is Symbol -> it.brailleDots is MarkerSymbol -> it.brailleDots diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/InputSymbolFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/InputSymbolFragment.kt index ae1d480c..dccb83d1 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/InputSymbolFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/InputSymbolFragment.kt @@ -13,7 +13,7 @@ import com.github.braillesystems.learnbraille.data.entities.BrailleDots import com.github.braillesystems.learnbraille.data.entities.Input import com.github.braillesystems.learnbraille.data.entities.Symbol import com.github.braillesystems.learnbraille.databinding.FragmentLessonsInputSymbolBinding -import com.github.braillesystems.learnbraille.res.getCaptionTitleId +import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.ui.* import com.github.braillesystems.learnbraille.ui.screens.observeCheckedOnFly import com.github.braillesystems.learnbraille.ui.screens.observeEventHint @@ -23,10 +23,7 @@ import com.github.braillesystems.learnbraille.ui.screens.theory.getStepArg import com.github.braillesystems.learnbraille.ui.screens.theory.toNextStep import com.github.braillesystems.learnbraille.ui.screens.theory.toPrevStep import com.github.braillesystems.learnbraille.ui.views.* -import com.github.braillesystems.learnbraille.utils.announce -import com.github.braillesystems.learnbraille.utils.application -import com.github.braillesystems.learnbraille.utils.checkedAnnounce -import com.github.braillesystems.learnbraille.utils.checkedBuzz +import com.github.braillesystems.learnbraille.utils.* import timber.log.Timber class InputSymbolFragment : AbstractStepFragment(R.string.lessons_help_input_symbol) { @@ -57,7 +54,7 @@ class InputSymbolFragment : AbstractStepFragment(R.string.lessons_help_input_sym require(step.data.material.data is Symbol) val symbol = step.data.material.data letter.text = symbol.char.toString() - letterCaptionTextView.text = getString(getCaptionTitleId(symbol)) + letterCaption.text = captionRules.getValue(symbol) brailleDots.dotsState.display(symbol.brailleDots) checkedAnnounce(printStringNotNullLogged(symbol.char, PrintMode.INPUT)) diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/ShowSymbolFragment.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/ShowSymbolFragment.kt index 2d9ac87b..caa8cdf1 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/ShowSymbolFragment.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/screens/theory/steps/ShowSymbolFragment.kt @@ -8,13 +8,14 @@ import com.github.braillesystems.learnbraille.R import com.github.braillesystems.learnbraille.data.entities.Show import com.github.braillesystems.learnbraille.data.entities.Symbol import com.github.braillesystems.learnbraille.databinding.FragmentLessonsShowSymbolBinding -import com.github.braillesystems.learnbraille.res.getCaptionTitleId +import com.github.braillesystems.learnbraille.res.captionRules import com.github.braillesystems.learnbraille.ui.PrintMode import com.github.braillesystems.learnbraille.ui.printStringNotNullLogged import com.github.braillesystems.learnbraille.ui.screens.theory.getStepArg import com.github.braillesystems.learnbraille.ui.views.display import com.github.braillesystems.learnbraille.ui.views.dotsState import com.github.braillesystems.learnbraille.utils.checkedAnnounce +import com.github.braillesystems.learnbraille.utils.getValue import timber.log.Timber class ShowSymbolFragment : AbstractStepFragment(R.string.lessons_help_show_symbol) { @@ -36,10 +37,10 @@ class ShowSymbolFragment : AbstractStepFragment(R.string.lessons_help_show_symbo require(step.data is Show) initialize(step, prevButton, nextButton) - step.data.material.apply{ + step.data.material.apply { require(data is Symbol) letter.text = data.char.toString() - letterCaptionTextView.text = getString(getCaptionTitleId(data)) + letterCaption.text = captionRules.getValue(data) brailleDots.dotsState.display(data.brailleDots) checkedAnnounce(printStringNotNullLogged(data.char, PrintMode.SHOW)) } diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt b/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt index f249cfa9..305afe1e 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/ui/views/BrailleDotsView.kt @@ -19,7 +19,7 @@ import org.koin.core.KoinComponent import org.koin.core.inject import timber.log.Timber -class BrailleDotView : CheckBox { +class BrailleDotView : androidx.appcompat.widget.AppCompatCheckBox { constructor(context: Context) : super(context) diff --git a/app/src/main/java/com/github/braillesystems/learnbraille/utils/_Kotlin.kt b/app/src/main/java/com/github/braillesystems/learnbraille/utils/_Kotlin.kt index 649e63a9..f2044211 100644 --- a/app/src/main/java/com/github/braillesystems/learnbraille/utils/_Kotlin.kt +++ b/app/src/main/java/com/github/braillesystems/learnbraille/utils/_Kotlin.kt @@ -57,6 +57,8 @@ fun Rules.match(key: T): R? = matchF(key)?.invoke(key) operator fun Rules.get(x: T): R? = match(x) +fun Rules.getValue(x: T): R = match(x) ?: error("No such rule for $x") + /** * It is very useful to choose android text resource depending on some condition. * (In that case prevent lambda of capturing context that will be invalid next time fragment entered, diff --git a/app/src/main/res/layout/fragment_card.xml b/app/src/main/res/layout/fragment_card.xml index 987c5a59..0c56d976 100644 --- a/app/src/main/res/layout/fragment_card.xml +++ b/app/src/main/res/layout/fragment_card.xml @@ -17,8 +17,8 @@ tools:context=".ui.screens.practice.CardFragment"> diff --git a/app/src/main/res/layout/fragment_lessons_input_symbol.xml b/app/src/main/res/layout/fragment_lessons_input_symbol.xml index a15992a1..6ae2ee9b 100644 --- a/app/src/main/res/layout/fragment_lessons_input_symbol.xml +++ b/app/src/main/res/layout/fragment_lessons_input_symbol.xml @@ -15,8 +15,8 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/fragment_lessons_show_symbol.xml b/app/src/main/res/layout/fragment_lessons_show_symbol.xml index c5c81bf0..c8d91fea 100644 --- a/app/src/main/res/layout/fragment_lessons_show_symbol.xml +++ b/app/src/main/res/layout/fragment_lessons_show_symbol.xml @@ -8,8 +8,8 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/layout/fragment_symbol_view.xml b/app/src/main/res/layout/fragment_symbol_view.xml index f67ae979..dfc66f87 100644 --- a/app/src/main/res/layout/fragment_symbol_view.xml +++ b/app/src/main/res/layout/fragment_symbol_view.xml @@ -8,8 +8,8 @@ android:layout_height="match_parent"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6b16e670..1ff9f2e6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,7 +112,6 @@ Латинская буква Цифра Специальный символ - diff --git a/build.gradle b/build.gradle index 16a30646..44d79739 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"