Skip to content

Commit

Permalink
Merge pull request #105 from braille-systems/release/0.4.1
Browse files Browse the repository at this point in the history
Release/0.4.1
  • Loading branch information
winter-yuki committed Apr 20, 2020
2 parents 45f521b + 713eff0 commit 64df482
Show file tree
Hide file tree
Showing 28 changed files with 343 additions and 121 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "0.3"
versionName "0.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.braillesystems.learnbraille

import android.app.Application
import android.widget.Toast
import com.github.braillesystems.learnbraille.database.LearnBrailleDatabase
import com.github.braillesystems.learnbraille.database.entities.Language
import com.github.braillesystems.learnbraille.util.scope
Expand Down Expand Up @@ -39,3 +40,5 @@ val language = Language.RU
const val defaultUser = 1L

const val DEBUG = false

const val TOAST_DURATION = Toast.LENGTH_SHORT
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import timber.log.Timber
User::class, Lesson::class, Step::class, Symbol::class,
UserKnowsSymbol::class, UserPassedStep::class, UserLastStep::class
],
version = 4,
version = 5,
exportSchema = false
)
@TypeConverters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,11 @@ val BrailleDots.list: List<BrailleDot>
val BrailleDots.spelling: String
get() = list
.mapIndexed { index, brailleDot ->
if (brailleDot == BrailleDot.F) {
(index + 1).toString()
} else {
null
}
if (brailleDot == E) null
else (index + 1).toString()
}
.filterNotNull()
.joinToString(separator = " ")
.joinToString(separator = ", ")

class BrailleDotsConverters {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun stepDataOf(string: String): StepData = string
}

/**
* Represent step types with information.
* Represents step types with information.
*/
sealed class BaseInfo : StepData()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,3 @@ interface SymbolDao {
@Query("DELETE FROM symbol")
suspend fun deleteAll()
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ val VERY_LAST = Step(
data = LastInfo(
"""Вы дошли до конца курса. Спасибо, что воспользовались нашим обучающим
|приложением! Вы всегда можете вернутся к ранее пройденному материалу и повторить его.
"""
|Продолжение следует!"""
)
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.github.braillesystems.learnbraille.screens

import android.os.Vibrator
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.github.braillesystems.learnbraille.CORRECT_BUZZ_PATTERN
import com.github.braillesystems.learnbraille.INCORRECT_BUZZ_PATTERN
import com.github.braillesystems.learnbraille.R
import com.github.braillesystems.learnbraille.TOAST_DURATION
import com.github.braillesystems.learnbraille.database.entities.BrailleDots
import com.github.braillesystems.learnbraille.database.entities.spelling
import com.github.braillesystems.learnbraille.serial.UsbSerial
import com.github.braillesystems.learnbraille.util.buzz
import com.github.braillesystems.learnbraille.util.side
Expand Down Expand Up @@ -217,3 +222,36 @@ fun DotsChecker.getEventPassHintObserver(
block()
onPassHintComplete()
}

fun Fragment.makeCorrectToast(): Unit =
Toast.makeText(context, getString(R.string.input_correct), TOAST_DURATION).show()

fun Fragment.makeIntroLetterToast(toInput: String?): Unit =
Toast.makeText(
context,
if (toInput == null) getString(R.string.input_loading)
else getString(R.string.input_letter_intro_template).format(toInput),
TOAST_DURATION
).show()

fun Fragment.makeIncorrectToast(): Unit =
Toast.makeText(
context,
getString(R.string.input_incorrect),
TOAST_DURATION
).show()

fun Fragment.makeIncorrectLetterToast(letter: String?): Unit =
Toast.makeText(
context,
if (letter == null) getString(R.string.input_loading)
else getString(R.string.input_letter_incorrect_template).format(letter),
TOAST_DURATION
).show()

fun Fragment.makeHintDotsToast(expectedDots: BrailleDots): Unit =
Toast.makeText(
context,
getString(R.string.input_dots_hint_template).format(expectedDots.spelling),
TOAST_DURATION
).show()
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.braillesystems.learnbraille.screens.help

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
Expand All @@ -25,6 +26,7 @@ class HelpFragment : Fragment() {
).apply {

updateTitle(getString(R.string.help_title))
helpMessage.movementMethod = ScrollingMovementMethod()
helpMessage.text = getFormattedArg(helpMessageArgName)

}.root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.github.braillesystems.learnbraille.screens.lessons

import android.view.View
import android.widget.Toast
import com.github.braillesystems.learnbraille.R
import com.github.braillesystems.learnbraille.database.LearnBrailleDatabase
import com.github.braillesystems.learnbraille.database.entities.BrailleDots
import com.github.braillesystems.learnbraille.database.entities.Step
import com.github.braillesystems.learnbraille.database.entities.spelling
import com.github.braillesystems.learnbraille.screens.HelpMsgId
import com.github.braillesystems.learnbraille.screens.makeCorrectToast
import com.github.braillesystems.learnbraille.screens.makeHintDotsToast
import com.github.braillesystems.learnbraille.screens.makeIncorrectToast
import com.github.braillesystems.learnbraille.views.BrailleDotsState
import com.github.braillesystems.learnbraille.views.spelling
import timber.log.Timber
Expand All @@ -18,6 +18,7 @@ import timber.log.Timber
abstract class AbstractInputLesson(helpMsgId: HelpMsgId) : AbstractLesson(helpMsgId) {

protected var userTouchedDots: Boolean = false
protected lateinit var viewModel: InputViewModel

protected fun getPrevButtonListener(step: Step, userId: Long, database: LearnBrailleDatabase) =
View.OnClickListener {
Expand Down Expand Up @@ -47,11 +48,9 @@ abstract class AbstractInputLesson(helpMsgId: HelpMsgId) : AbstractLesson(helpMs
userId: Long,
database: LearnBrailleDatabase
): () -> Unit = {
Timber.i("Handle correct")
makeCorrectToast()
database.apply {
Timber.i("Handle correct")
Toast.makeText(
context, getString(R.string.msg_correct), Toast.LENGTH_SHORT
).show()
navigateToNextStep(
current = step,
userId = userId,
Expand All @@ -66,37 +65,33 @@ abstract class AbstractInputLesson(helpMsgId: HelpMsgId) : AbstractLesson(helpMs
step: Step,
userId: Long,
database: LearnBrailleDatabase,
dots: BrailleDotsState
dots: BrailleDotsState,
toastMaker: () -> Unit = ::makeIncorrectToast
): () -> Unit = {
database.apply {
Timber.i("Handle incorrect: entered = ${dots.spelling}")
if (userTouchedDots) {
Toast.makeText(
context, getString(R.string.msg_incorrect), Toast.LENGTH_SHORT
).show()
} else {
Timber.i("Handle incorrect: entered = ${dots.spelling}")
if (userTouchedDots) {
toastMaker()
} else {
database.apply {
navigateToNextStep(
current = step,
userId = userId,
stepDao = stepDao,
lastStepDao = userLastStep
) {
Toast.makeText(
context, getString(R.string.msg_incorrect), Toast.LENGTH_SHORT
).show()
toastMaker()
}
}
}
}

protected fun getEventHintObserverBlock(): (BrailleDots) -> Unit = { expectedDots ->
Timber.i("Handle hint")
val toast = getString(R.string.practice_hint_template)
.format(expectedDots.spelling)
Toast.makeText(context, toast, Toast.LENGTH_LONG).show()
makeHintDotsToast(expectedDots)
}

protected fun getEventPassHintObserverBlock(): () -> Unit = {
protected fun getEventPassHintObserverBlock(toastMaker: () -> Unit = {}): () -> Unit = {
Timber.i("Handle pass hint")
toastMaker()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.braillesystems.learnbraille.screens.lessons

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
Expand Down Expand Up @@ -31,6 +32,7 @@ class FirstInfoFragment : AbstractLesson(R.string.lessons_help_info) {
require(step.data is FirstInfo)
titleTextView.text = step.title
infoTextView.text = step.data.text
infoTextView.movementMethod = ScrollingMovementMethod()

getDBInstance().apply {
nextButton.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.braillesystems.learnbraille.screens.lessons

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
Expand Down Expand Up @@ -31,6 +32,7 @@ class InfoFragment : AbstractLesson(R.string.lessons_help_info) {
require(step.data is Info)
titleTextView.text = step.title
infoTextView.text = step.data.text
infoTextView.movementMethod = ScrollingMovementMethod()

getDBInstance().apply {
prevButton.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import timber.log.Timber

class InputDotsFragment : AbstractInputLesson(R.string.lessons_help_input_dots) {

private lateinit var viewModel: InputViewModel
private lateinit var expectedDots: BrailleDots
private lateinit var dots: BrailleDotsState
private var buzzer: Vibrator? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ import com.github.braillesystems.learnbraille.database.entities.InputSymbol
import com.github.braillesystems.learnbraille.database.getDBInstance
import com.github.braillesystems.learnbraille.databinding.FragmentLessonsInputSymbolBinding
import com.github.braillesystems.learnbraille.defaultUser
import com.github.braillesystems.learnbraille.screens.getEventCorrectObserver
import com.github.braillesystems.learnbraille.screens.getEventHintObserver
import com.github.braillesystems.learnbraille.screens.getEventIncorrectObserver
import com.github.braillesystems.learnbraille.screens.getEventPassHintObserver
import com.github.braillesystems.learnbraille.screens.*
import com.github.braillesystems.learnbraille.util.application
import com.github.braillesystems.learnbraille.util.updateTitle
import com.github.braillesystems.learnbraille.views.*
import timber.log.Timber

class InputSymbolFragment : AbstractInputLesson(R.string.lessons_help_input_symbol) {

private lateinit var viewModel: InputViewModel
private lateinit var expectedDots: BrailleDots
private lateinit var dots: BrailleDotsState
private var buzzer: Vibrator? = null
Expand All @@ -50,6 +46,7 @@ class InputSymbolFragment : AbstractInputLesson(R.string.lessons_help_input_symb
titleTextView.text = step.title
letter.text = step.data.symbol.symbol.toString()
brailleDots.dots.display(step.data.symbol.brailleDots)
makeIntroLetterToast(step.data.symbol.symbol.toString())

expectedDots = step.data.symbol.brailleDots
userTouchedDots = false
Expand Down Expand Up @@ -94,7 +91,9 @@ class InputSymbolFragment : AbstractInputLesson(R.string.lessons_help_input_symb
viewLifecycleOwner,
viewModel.getEventIncorrectObserver(
dots, buzzer,
getEventIncorrectObserverBlock(step, defaultUser, database, dots)
getEventIncorrectObserverBlock(step, defaultUser, database, dots) {
makeIncorrectLetterToast(step.data.symbol.symbol.toString())
}
)
)

Expand All @@ -108,7 +107,11 @@ class InputSymbolFragment : AbstractInputLesson(R.string.lessons_help_input_symb

viewModel.eventPassHint.observe(
viewLifecycleOwner,
viewModel.getEventPassHintObserver(dots, getEventPassHintObserverBlock())
viewModel.getEventPassHintObserver(
dots, getEventPassHintObserverBlock {
makeIntroLetterToast(step.data.symbol.symbol.toString())
}
)
)

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

import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
Expand Down Expand Up @@ -31,6 +32,7 @@ class LastInfoFragment : AbstractLesson(R.string.lessons_help_last_info) {
require(step.data is LastInfo)
titleTextView.text = step.title
infoTextView.text = step.data.text
infoTextView.movementMethod = ScrollingMovementMethod()

getDBInstance().run {
prevButton.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.databinding.DataBindingUtil
import androidx.navigation.Navigation
import androidx.navigation.fragment.findNavController
import com.github.braillesystems.learnbraille.R
import com.github.braillesystems.learnbraille.TOAST_DURATION
import com.github.braillesystems.learnbraille.database.LearnBrailleDatabase
import com.github.braillesystems.learnbraille.database.getDBInstance
import com.github.braillesystems.learnbraille.databinding.FragmentMenuBinding
Expand Down Expand Up @@ -44,7 +45,6 @@ class MenuFragment : AbstractFragmentWithHelp(R.string.menu_help) {
).apply {

updateTitle(getString(R.string.menu_actionbar_text))

setHasOptionsMenu(true)

lessonsButton.setOnClickListener(interruptingOnClickListener {
Expand Down Expand Up @@ -84,11 +84,11 @@ class MenuFragment : AbstractFragmentWithHelp(R.string.menu_help) {
if (requestCode == qtResultCode) {
if (resultCode == RESULT_OK) {
val contents = data?.getStringExtra("SCAN_RESULT")
Toast.makeText(context, contents, Toast.LENGTH_SHORT).show()
Toast.makeText(context, contents, TOAST_DURATION).show()
}
if (resultCode == RESULT_CANCELED) {
Toast.makeText(
context, getString(R.string.msg_cancelled), Toast.LENGTH_SHORT
context, getString(R.string.qr_intent_cancelled), TOAST_DURATION
).show()
}
}
Expand All @@ -97,7 +97,7 @@ class MenuFragment : AbstractFragmentWithHelp(R.string.menu_help) {
private fun interruptingOnClickListener(block: (View) -> Unit) = View.OnClickListener {
if (!isDbPrepopulated) {
Toast.makeText(
context, getString(R.string.menu_db_not_initialized_warning), Toast.LENGTH_LONG
context, getString(R.string.menu_db_not_initialized_warning), TOAST_DURATION
).show()
return@OnClickListener
}
Expand Down
Loading

0 comments on commit 64df482

Please sign in to comment.