-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:braille-systems/learn-braille into dev
- Loading branch information
Showing
6 changed files
with
191 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...c/main/java/com/github/braillesystems/learnbraille/screens/lessons/AbstractInputLesson.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
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.views.BrailleDotsState | ||
import com.github.braillesystems.learnbraille.views.spelling | ||
import timber.log.Timber | ||
|
||
/** | ||
* Set `userTouchedDots` to false in `onCreateView` | ||
*/ | ||
abstract class AbstractInputLesson(helpMsgId: HelpMsgId) : AbstractLesson(helpMsgId) { | ||
|
||
protected var userTouchedDots: Boolean = false | ||
|
||
protected fun getPrevButtonListener(step: Step, userId: Long, database: LearnBrailleDatabase) = | ||
View.OnClickListener { | ||
database.apply { | ||
navigateToPrevStep( | ||
current = step, | ||
userId = userId, | ||
stepDao = stepDao, | ||
lastStepDao = userLastStep | ||
) | ||
} | ||
} | ||
|
||
protected fun getToCurrStepListener(userId: Long, database: LearnBrailleDatabase) = | ||
View.OnClickListener { | ||
database.apply { | ||
navigateToCurrentStep( | ||
userId = userId, | ||
stepDao = stepDao, | ||
lastStepDao = userLastStep | ||
) | ||
} | ||
} | ||
|
||
protected fun getEventCorrectObserverBlock( | ||
step: Step, | ||
userId: Long, | ||
database: LearnBrailleDatabase | ||
): () -> Unit = { | ||
database.apply { | ||
Timber.i("Handle correct") | ||
Toast.makeText( | ||
context, getString(R.string.msg_correct), Toast.LENGTH_SHORT | ||
).show() | ||
navigateToNextStep( | ||
current = step, | ||
userId = userId, | ||
stepDao = stepDao, | ||
lastStepDao = userLastStep, | ||
upsd = userPassedStepDao | ||
) | ||
} | ||
} | ||
|
||
protected fun getEventIncorrectObserverBlock( | ||
step: Step, | ||
userId: Long, | ||
database: LearnBrailleDatabase, | ||
dots: BrailleDotsState | ||
): () -> 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 { | ||
navigateToNextStep( | ||
current = step, | ||
userId = userId, | ||
stepDao = stepDao, | ||
lastStepDao = userLastStep | ||
) { | ||
Toast.makeText( | ||
context, getString(R.string.msg_incorrect), Toast.LENGTH_SHORT | ||
).show() | ||
} | ||
} | ||
} | ||
} | ||
|
||
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() | ||
} | ||
|
||
protected fun getEventPassHintObserverBlock(): () -> Unit = { | ||
Timber.i("Handle pass hint") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.