Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.github.braillesystems.learnbraille.data.entities.MarkerSymbol
import com.github.braillesystems.learnbraille.data.entities.Material
import com.github.braillesystems.learnbraille.databinding.FragmentMarkerViewBinding
import com.github.braillesystems.learnbraille.res.showMarkerPrintRules
import com.github.braillesystems.learnbraille.ui.dotsMode
import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp
import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo
import com.github.braillesystems.learnbraille.ui.screens.FragmentBinding
Expand Down Expand Up @@ -47,12 +46,9 @@ class MarkerViewFragment : AbstractFragmentWithHelp(R.string.browser_marker_view
val text = showMarkerPrintRules.getValue(m.data.type)
infoTextView.text = text
checkedAnnounce(text)

brailleDots.dotsState.display(m.data.brailleDots)
checkedToast(dotsMode(brailleDots.mode))
flipButton.setOnClickListener {
brailleDots.reflect().display(m.data.brailleDots)
checkedToast(dotsMode(brailleDots.mode))
}

}.root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.braillesystems.learnbraille.ui.screens.browser

import android.animation.ObjectAnimator
import android.animation.TypeEvaluator
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
Expand All @@ -10,15 +12,17 @@ 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.captionRules
import com.github.braillesystems.learnbraille.ui.dotsMode
import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp
import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo
import com.github.braillesystems.learnbraille.ui.screens.FragmentBinding
import com.github.braillesystems.learnbraille.ui.showPrint
import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode
import com.github.braillesystems.learnbraille.ui.views.display
import com.github.braillesystems.learnbraille.ui.views.dotsState
import com.github.braillesystems.learnbraille.utils.*
import com.github.braillesystems.learnbraille.utils.checkedAnnounce
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) {

Expand Down Expand Up @@ -48,10 +52,8 @@ class SymbolViewFragment : AbstractFragmentWithHelp(R.string.browser_symbol_view
checkedAnnounce(showPrint(m.data))

brailleDots.dotsState.display(m.data.brailleDots)
checkedToast(dotsMode(brailleDots.mode))
flipButton.setOnClickListener {
brailleDots.reflect().display(m.data.brailleDots)
checkedToast(dotsMode(brailleDots.mode))
}

}.root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Vibrator
import android.view.*
import android.widget.Button
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
Expand All @@ -16,16 +17,20 @@ 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.*
import com.github.braillesystems.learnbraille.utils.announceCorrect
import com.github.braillesystems.learnbraille.utils.announceIncorrect
import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainer
import com.github.braillesystems.learnbraille.ui.brailletrainer.BrailleTrainerSignalHandler
import com.github.braillesystems.learnbraille.ui.inputPrint
import com.github.braillesystems.learnbraille.ui.screens.*
import com.github.braillesystems.learnbraille.ui.showHintToast
import com.github.braillesystems.learnbraille.ui.views.*
import com.github.braillesystems.learnbraille.utils.*
import org.koin.android.ext.android.inject
import org.koin.core.parameter.parametersOf
import timber.log.Timber


class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) {

// This value can change during ViewModel lifetime (ViewModelProvider does not call
Expand Down Expand Up @@ -86,7 +91,6 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) {
binding.flipButton.setOnClickListener {
dotsState = binding.brailleDots.reflect().apply {
dotsState.subscribe(viewModel)
checkedToast(dotsMode(binding.brailleDots.mode))
if (viewModel.state == DotsChecker.State.HINT) {
viewModel.expectedDots?.let { display(it) }
}
Expand Down Expand Up @@ -114,16 +118,25 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) {
viewModel.observeCheckedOnFly(
viewLifecycleOwner, { dotsState }, buzzer,
block = { title = title(viewModel) },
softBlock = ::showCorrectToast
softBlock = {
announceCorrect()
val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorBackground) }
val colorTo = context?.let { ContextCompat.getColor(it, R.color.lightGreen) }
animateView(binding.constraintLayout, colorFrom, colorTo)
}
)

viewModel.observeEventIncorrect(
viewLifecycleOwner, { dotsState }, buzzer
) {
viewModel.symbol.value
?.let { showIncorrectToast(inputPrint(it)) }
?.let { announceIncorrect(inputPrint(it)) }
?: checkedToast(getString(R.string.input_loading))
title = title(viewModel)

val colorFrom = context?.let { ContextCompat.getColor(it, R.color.colorBackground) }
val colorTo = context?.let { ContextCompat.getColor(it, R.color.lightRed) }
animateView(binding.constraintLayout, colorFrom, colorTo)
}

viewModel.observeEventHint(
Expand Down Expand Up @@ -158,10 +171,7 @@ class CardFragment : AbstractFragmentWithHelp(R.string.practice_help) {
getString(R.string.practice_deck_name_disabled_template)
}
toast(
template.format(
deckTagToName.getValue(tag),
dotsMode(binding.brailleDots.mode)
)
template.format(deckTagToName.getValue(tag))
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.widget.TextView
import com.github.braillesystems.learnbraille.COURSE
import com.github.braillesystems.learnbraille.R
import com.github.braillesystems.learnbraille.data.entities.Step
import com.github.braillesystems.learnbraille.ui.dotsMode
import com.github.braillesystems.learnbraille.ui.screens.AbstractFragmentWithHelp
import com.github.braillesystems.learnbraille.ui.screens.BrailleDotsInfo
import com.github.braillesystems.learnbraille.ui.screens.FragmentBinding
Expand All @@ -18,7 +17,6 @@ import com.github.braillesystems.learnbraille.ui.screens.theory.getStepArg
import com.github.braillesystems.learnbraille.ui.screens.theory.toCurrentStep
import com.github.braillesystems.learnbraille.ui.screens.theory.toNextStep
import com.github.braillesystems.learnbraille.ui.screens.theory.toPrevStep
import com.github.braillesystems.learnbraille.utils.checkedToast
import com.github.braillesystems.learnbraille.utils.navigate
import com.github.braillesystems.learnbraille.utils.title

Expand Down Expand Up @@ -83,12 +81,6 @@ abstract class AbstractStepFragment(helpMsgId: HelpMsgId) : AbstractFragmentWith

protected open fun iniStepHelper() = Unit

protected fun toastDotsMode() {
binding.brailleDotsInfo?.view?.mode?.let {
checkedToast(dotsMode(it))
}
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(
if (preferenceRepository.extendedAccessibilityEnabled) R.menu.steps_menu_hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ abstract class AbstractInputStepFragment(helpMsgId: HelpMsgId) : AbstractStepFra

val buzzer: Vibrator? = activity?.getSystemService()

toastDotsMode()
stepBinding.flipButton?.setOnClickListener {
dotsState = stepBinding.brailleDotsInfo!!.view.reflect().apply {
subscribe(View.OnClickListener {
viewModel.onSoftCheck()
userTouchedDots = true
})
toastDotsMode()
if (viewModel.state == DotsChecker.State.HINT) {
display(expectedDots)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ abstract class AbstractShowStepFragment(helpMsgId: HelpMsgId) : AbstractStepFrag
require(data is BaseShow)
stepBinding.brailleDotsInfo?.view?.dotsState?.display(data.brailleDots)
?: error("Show step should have braille dots")
toastDotsMode()
stepBinding.flipButton?.setOnClickListener {
stepBinding.brailleDotsInfo?.view?.reflect()?.display(data.brailleDots)
toastDotsMode()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import com.github.braillesystems.learnbraille.data.entities.spelling
import com.github.braillesystems.learnbraille.data.repository.PreferenceRepository
import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode.Reading
import com.github.braillesystems.learnbraille.ui.views.BrailleDotsViewMode.Writing
import com.github.braillesystems.learnbraille.utils.chainify
import com.github.braillesystems.learnbraille.utils.forEach
import com.github.braillesystems.learnbraille.utils.unreachable
import com.github.braillesystems.learnbraille.utils.*
import kotlinx.android.synthetic.main.braille_dots_view.view.*
import org.koin.core.KoinComponent
import org.koin.core.inject
Expand Down Expand Up @@ -96,18 +94,19 @@ class BrailleDotsView : ConstraintLayout, KoinComponent {
reflectChecks()
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
setBackgroundMode(mode)
} else {
Timber.w("Unable to set braille dots background due to low API level")
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
setTraversalMode(mode)
} else {
Timber.w("API level < 22, unable co control accessibility traversal order")
}

context.announce(
when (mode) {
Writing -> context.getString(R.string.braille_dots_mode_writing)
Reading -> context.getString(R.string.braille_dots_mode_reading)
}
)

this.mode = mode
}

Expand All @@ -117,27 +116,27 @@ class BrailleDotsView : ConstraintLayout, KoinComponent {
}

private fun setDescriptionMode(mode: BrailleDotsViewMode) {
when (mode) {
Writing -> forEach(
dotButton4 to R.string.braille_dot_1,
dotButton5 to R.string.braille_dot_2,
dotButton6 to R.string.braille_dot_3,
dotButton1 to R.string.braille_dot_4,
dotButton2 to R.string.braille_dot_5,
dotButton3 to R.string.braille_dot_6
) { (dotButton, id) ->
dotButton.contentDescription = context.getString(id)
}
Reading -> forEach(
dotButton1 to R.string.braille_dot_1,
dotButton2 to R.string.braille_dot_2,
dotButton3 to R.string.braille_dot_3,
dotButton4 to R.string.braille_dot_4,
dotButton5 to R.string.braille_dot_5,
dotButton6 to R.string.braille_dot_6
) { (dotButton, id) ->
dotButton.contentDescription = context.getString(id)
}
val dotsMapping = when (mode) {
Writing -> listOf(
Triple(dotButton4, R.string.braille_dot_1, R.string.braille_dot_1_text),
Triple(dotButton5, R.string.braille_dot_2, R.string.braille_dot_2_text),
Triple(dotButton6, R.string.braille_dot_3, R.string.braille_dot_3_text),
Triple(dotButton1, R.string.braille_dot_4, R.string.braille_dot_4_text),
Triple(dotButton2, R.string.braille_dot_5, R.string.braille_dot_5_text),
Triple(dotButton3, R.string.braille_dot_6, R.string.braille_dot_6_text)
)
Reading -> listOf(
Triple(dotButton1, R.string.braille_dot_1, R.string.braille_dot_1_text),
Triple(dotButton2, R.string.braille_dot_2, R.string.braille_dot_2_text),
Triple(dotButton3, R.string.braille_dot_3, R.string.braille_dot_3_text),
Triple(dotButton4, R.string.braille_dot_4, R.string.braille_dot_4_text),
Triple(dotButton5, R.string.braille_dot_5, R.string.braille_dot_5_text),
Triple(dotButton6, R.string.braille_dot_6, R.string.braille_dot_6_text)
)
}
dotsMapping.forEach { (dotButton, desc_id, caption_id) ->
dotButton.contentDescription = context.getString(desc_id)
dotButton.text = context.getString(caption_id)
}
}

Expand Down Expand Up @@ -179,14 +178,6 @@ class BrailleDotsView : ConstraintLayout, KoinComponent {
next.accessibilityTraversalAfter = prev.id
}
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private fun setBackgroundMode(mode: BrailleDotsViewMode) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing looked good to me. I think it is still useful

background = when (mode) {
Writing -> context.getDrawable(R.drawable.right_border)
Reading -> context.getDrawable(R.drawable.left_border)
}
}
}

val BrailleDotsView.dotsState: BrailleDotsState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.github.braillesystems.learnbraille.utils

import android.animation.ArgbEvaluator
import android.animation.ObjectAnimator
import android.content.Context
import android.os.Vibrator
import android.view.View
import android.view.accessibility.AccessibilityEvent
import android.widget.Toast
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import com.github.braillesystems.learnbraille.LearnBrailleApplication
import com.github.braillesystems.learnbraille.R
Expand Down Expand Up @@ -68,6 +72,10 @@ fun Fragment.checkedAnnounce(
announce(announcement)
}

fun Fragment.announceCorrect() = announce(getString(R.string.input_correct))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is Messages.kt file for such kind of things


fun Fragment.announceIncorrect(hint: String = "") =
announce("${getString(R.string.input_incorrect)} $hint")

val Fragment.actionBar: ActionBar?
get() = (activity as AppCompatActivity).supportActionBar
Expand All @@ -88,6 +96,14 @@ fun Fragment.updateTitle(title: String) {
this.title = title
}

fun animateView(obj: View?, colorFrom: Int?, colorTo: Int?) {
val duration = 1000

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rathe be const val DURATION = 1000L

ObjectAnimator
.ofObject(obj, "backgroundColor", ArgbEvaluator(), colorFrom, colorTo, colorFrom)
.setDuration(duration.toLong())
.start()
}


fun <T> stringify(s: SerializationStrategy<T>, obj: T) = Json.stringify(s, obj)
fun <T> parse(d: DeserializationStrategy<T>, s: String) = Json.parse(d, s)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/checked_round_checkbox.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#263238" />
<solid android:color="@color/colorPrimary" />
<size
android:width="@dimen/braille_dot_size"
android:height="@dimen/braille_dot_size" />
Expand Down
18 changes: 0 additions & 18 deletions app/src/main/res/drawable/left_border.xml

This file was deleted.

18 changes: 0 additions & 18 deletions app/src/main/res/drawable/right_border.xml

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/main/res/drawable/round_checkbox.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/checked_round_checkbox" android:state_checked="true" />
<item android:drawable="@drawable/checked_round_checkbox" android:state_pressed="true" />
<item android:drawable="@drawable/unchecked_round_checkbox" android:state_pressed="false" />
<item android:color="@color/colorBackground" android:drawable="@drawable/checked_round_checkbox" android:state_checked="true" />
<item android:color="@color/colorBackground" android:drawable="@drawable/checked_round_checkbox" android:state_pressed="true" />
<item android:color="@color/colorPrimary" android:drawable="@drawable/unchecked_round_checkbox" android:state_pressed="false" />
</selector>
Loading