Skip to content

Commit

Permalink
Merge pull request #188 from braille-systems/release/1.0.0
Browse files Browse the repository at this point in the history
7.11 Release/1.0.0
  • Loading branch information
zuevval committed May 22, 2020
2 parents f201fd8 + ce5134c commit 44d1108
Show file tree
Hide file tree
Showing 119 changed files with 1,575 additions and 685 deletions.
10 changes: 8 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ android {
applicationId "com.github.braillesystems.learnbraille"
minSdkVersion 19
targetSdkVersion 29
versionCode 2
versionName "0.6.1"
versionCode 5
versionName "1.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled = true
Expand Down Expand Up @@ -98,3 +98,9 @@ dependencies {
//Settings
implementation 'androidx.preference:preference:1.1.1'
}

android {
lintOptions {
disable 'MissingTranslation'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.braillesystems.learnbraille.data.dsl.*
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.DeckTags
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
Expand All @@ -18,13 +19,13 @@ private val content by materials {
}

private val ruSymbols by symbols(symbolType = "ru") {
symbol(symbol = 'А', brailleDots = BrailleDots(F, E, E, E, E, E))
symbol(symbol = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E))
symbol(char = 'А', brailleDots = BrailleDots(F, E, E, E, E, E))
symbol(char = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E))
// ...
}

private val enSymbols by symbols(symbolType = "en") {
symbol(symbol = 'Z', brailleDots = BrailleDots(F, F, F, E, E, E))
symbol(char = 'Z', brailleDots = BrailleDots(F, F, F, E, E, E))
// ...
}

Expand Down Expand Up @@ -71,6 +72,7 @@ private val prepopulationData by data(
deck("En letters") {
it is Symbol && it.type == "en"
}
deck(DeckTags.all) { true }
// ...
}
}
Expand Down Expand Up @@ -127,18 +129,22 @@ private val users = listOf(
User(0, "default3", "")
)
private val mats = listOf(
Material(1, Symbol(symbol = 'А', brailleDots = BrailleDots(F, E, E, E, E, E), type = "ru")),
Material(2, Symbol(symbol = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E), type = "ru")),
Material(3, Symbol(symbol = 'Z', brailleDots = BrailleDots(F, F, F, E, E, E), type = "en"))
Material(1, Symbol(char = 'А', brailleDots = BrailleDots(F, E, E, E, E, E), type = "ru")),
Material(2, Symbol(char = 'Б', brailleDots = BrailleDots(F, F, E, E, E, E), type = "ru")),
Material(3, Symbol(char = 'Z', brailleDots = BrailleDots(F, F, F, E, E, E), type = "en"))
)
private val decks = listOf(
Deck(1, "Ru letters"),
Deck(2, "En letters")
Deck(2, "Ru letters"),
Deck(3, "En letters"),
Deck(1, DeckTags.all)
)
private val cards = listOf(
Card(2, 1),
Card(2, 2),
Card(3, 3),
Card(1, 1),
Card(1, 2),
Card(2, 3)
Card(1, 3)
)
private val courses = listOf(
Course(1, "Best course", "The best"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LearnBrailleDatabaseTest {
private val materials = listOf(
Material(
1, Symbol(
symbol = 'А',
char = 'А',
brailleDots = BrailleDots(F, E, E, E, E, E),
type = SymbolType.ru
)
Expand All @@ -43,7 +43,7 @@ class LearnBrailleDatabaseTest {
private val decks = listOf(
Deck(
id = 1,
name = "Ru letters"
tag = "Ru letters"
)
)
private val cards = listOf(
Expand Down Expand Up @@ -170,7 +170,7 @@ class LearnBrailleDatabaseTest {

@Test
fun testDecks() = runBlocking {
assertEquals("Ru letters", db.deckDao.getDeck(1)!!.name)
assertEquals("Ru letters", db.deckDao.getDeck(1)!!.tag)
}

@Test
Expand Down
14 changes: 8 additions & 6 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.github.braillesystems.learnbraille">

<!--<uses-permission android:name="android.permission.RECORD_AUDIO" />--> <!--TODO-->
<!--TODO-->
<!--<uses-permission android:name="android.permission.RECORD_AUDIO" />-->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.github.braillesystems.learnbraille.LearnBrailleApplication"
android:allowBackup="false"
android:icon="@mipmap/icon_beta"
android:icon="@mipmap/icon_univ"
android:label="@string/app_name"
android:roundIcon="@mipmap/icon_beta_round"
android:roundIcon="@mipmap/icon_univ_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.github.braillesystems.learnbraille.ui.screens.MainActivity">
Expand All @@ -20,9 +21,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.github.braillesystems.learnbraille.ui.brailletrainer.UsbService"
android:enabled="true"></service>
<!-- TODO-->
<!-- <service-->
<!-- android:name="com.github.braillesystems.learnbraille.ui.brailletrainer.UsbService"-->
<!-- android:enabled="true"></service>-->
</application>

</manifest>
Binary file added android/app/src/main/icon_univ-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class LearnBrailleApplication : Application() {

val koinModule = module {
single { LearnBrailleDatabase.buildDatabase(this@LearnBrailleApplication) }
factory<PracticeRepository> {
PracticeRepositoryImpl(get<LearnBrailleDatabase>().materialDao)
}
factory<PreferenceRepository> {
PreferenceRepositoryImpl(
this@LearnBrailleApplication,
Expand All @@ -35,11 +32,25 @@ class LearnBrailleApplication : Application() {
get<LearnBrailleDatabase>().userDao
)
}
factory<PracticeRepository> {
val db = get<LearnBrailleDatabase>()
PracticeRepositoryImpl(
this@LearnBrailleApplication,
db.deckDao, db.cardDao, get()
)
}
factory<MutablePracticeRepository> {
val db = get<LearnBrailleDatabase>()
PracticeRepositoryImpl(
this@LearnBrailleApplication,
db.deckDao, db.cardDao, get()
)
}
factory<TheoryRepository> {
get<LearnBrailleDatabase>().run {
TheoryRepositoryImpl(
lessonDao, stepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao, knownMaterialDao,
get()
)
}
Expand All @@ -48,7 +59,7 @@ class LearnBrailleApplication : Application() {
get<LearnBrailleDatabase>().run {
TheoryRepositoryImpl(
lessonDao, stepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao,
currentStepDao, lastCourseStepDao, lastLessonStepDao, knownMaterialDao,
get()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.sqlite.db.SupportSQLiteDatabase
import com.github.braillesystems.learnbraille.data.entities.*
import com.github.braillesystems.learnbraille.res.knownMaterials
import com.github.braillesystems.learnbraille.res.prepopulationData
import com.github.braillesystems.learnbraille.utils.scope
import kotlinx.coroutines.Job
Expand All @@ -24,7 +25,7 @@ import timber.log.Timber
Course::class, Lesson::class, Step::class, StepAnnotation::class, StepHasAnnotation::class,
CurrentStep::class, LastCourseStep::class, LastLessonStep::class
],
version = 14,
version = 16,
exportSchema = false
)
@TypeConverters(
Expand All @@ -50,18 +51,16 @@ abstract class LearnBrailleDatabase : RoomDatabase(), KoinComponent {
abstract val lastCourseStepDao: LastCourseStepDao
abstract val lastLessonStepDao: LastLessonStepDao

private lateinit var forcePrepopulationJob: Job

@Volatile
private var prepopulationFinished = true
private lateinit var forcePrepopulationJob: Job

fun init(): LearnBrailleDatabase = this.also {
forcePrepopulationJob = scope().launch {
// Expect to have at list one user in prepopulation list
if (userDao.getUser(1) != null) {
Timber.i("DB has been already initialized")
} else {
Timber.i("DB is not been initialized yet")
prepopulationFinished = false
}
}
Expand All @@ -77,7 +76,7 @@ abstract class LearnBrailleDatabase : RoomDatabase(), KoinComponent {
)
}

companion object : KoinComponent {
companion object {

const val name = "learn_braille_database"

Expand All @@ -87,7 +86,7 @@ abstract class LearnBrailleDatabase : RoomDatabase(), KoinComponent {
LearnBrailleDatabase::class.java,
name
)
.addCallback(object : Callback() {
.addCallback(object : Callback(), KoinComponent {

@SuppressLint("SyntheticAccessor")
override fun onCreate(db: SupportSQLiteDatabase) {
Expand All @@ -103,7 +102,7 @@ abstract class LearnBrailleDatabase : RoomDatabase(), KoinComponent {
}

private fun prepopulate() {
Timber.i("Prepopulate")
Timber.i("Prepopulate DB")
get<LearnBrailleDatabase>().apply {
prepopulationData.use {
scope().launch {
Expand All @@ -118,7 +117,8 @@ abstract class LearnBrailleDatabase : RoomDatabase(), KoinComponent {
stepDao.insert(steps)
stepAnnotationDao.insert(stepAnnotations)
stepHasAnnotationDao.insert(stepHasAnnotations)
// TODO insert minimum amount of letters to known
// TODO apply for multiple users
knownMaterialDao.insert(knownMaterials.map { it.copy(userId = 1) })

Timber.i("Finnish database prepopulation")
prepopulationFinished = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.braillesystems.learnbraille.data.dsl

import com.github.braillesystems.learnbraille.data.entities.*
import com.github.braillesystems.learnbraille.res.DeckTags
import com.github.braillesystems.learnbraille.utils.side
import kotlin.reflect.KProperty


const val DEFAULT_ID = -1L
const val ALL_CARDS_DECK_ID = 1L

typealias StepAnnotationName = String
typealias StepWithAnnotations = Pair<Step, List<StepAnnotationName>>
Expand Down Expand Up @@ -137,14 +139,16 @@ class DataBuilder(
fun decks(block: DecksBuilder.() -> Unit) =
DecksBuilder(block).side {
it.deckToPredicate.forEach { (deck, p) ->
val deckId = decks.size + 1L
_decks += deck.copy(id = deckId)

materials
.filter { material -> p(material.data) }
.forEach { material ->
_cards += Card(deckId, material.id)
val deckId =
if (deck.tag == DeckTags.all) ALL_CARDS_DECK_ID
else decks.size + 2L
val deckMaterials = materials.filter { material -> p(material.data) }
if (deckMaterials.isNotEmpty()) {
_decks += deck.copy(id = deckId)
_cards += deckMaterials.map { material ->
Card(deckId, material.id)
}
}
}
}
}
Expand All @@ -161,8 +165,8 @@ class DecksBuilder(block: DecksBuilder.() -> Unit) {
block()
}

fun deck(name: String, description: String = "", entryCriterion: (MaterialData) -> Boolean) {
val deck = Deck(DEFAULT_ID, name, description)
fun deck(tag: String, entryCriterion: (MaterialData) -> Boolean) {
val deck = Deck(DEFAULT_ID, tag)
_deckToPredicate[deck] = entryCriterion
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.braillesystems.learnbraille.data.dsl

import com.github.braillesystems.learnbraille.data.entities.BrailleDots
import com.github.braillesystems.learnbraille.data.entities.KnownMaterial
import com.github.braillesystems.learnbraille.data.entities.Material
import com.github.braillesystems.learnbraille.data.entities.Symbol
import com.github.braillesystems.learnbraille.res.content
import kotlin.reflect.KProperty


Expand Down Expand Up @@ -30,10 +32,10 @@ class MaterialsBuilder(block: MaterialsBuilder.() -> Unit) {
_materials = materials.mapIndexed { index, material ->
material.copy(id = index + 1L).apply {
if (data is Symbol) {
require(!_symbols.contains(data.symbol)) {
"Symbol (symbol = ${data.symbol}, type = ${data.type}) already exists"
require(!_symbols.contains(data.char)) {
"Symbol (symbol = ${data.char}, type = ${data.type}) already exists"
}
_symbols[data.symbol] = this
_symbols[data.char] = this
}
}
}.toMutableList()
Expand Down Expand Up @@ -69,7 +71,24 @@ class SymbolsBuilder(private val symbolType: String, block: SymbolsBuilder.() ->

operator fun get(symbol: Char): Symbol? = _map[symbol]

fun symbol(symbol: Char, brailleDots: BrailleDots) {
_map[symbol] = Symbol(symbol, brailleDots, symbolType)
fun symbol(char: Char, brailleDots: BrailleDots) {
@Suppress("NAME_SHADOWING") val char = char.toUpperCase()
_map[char] = Symbol(char, brailleDots, symbolType)
}
}


class known(vararg chars: Char) {

private val cs = chars.map(Char::toUpperCase)
private var knownMaterials: List<KnownMaterial>? = null

operator fun getValue(thisRef: Any?, property: KProperty<*>): List<KnownMaterial> {
require(property.name == "knownMaterials") {
"Property should have name knownMaterials to be used by database"
}
return knownMaterials ?: cs.map {
KnownMaterial(DEFAULT_ID, content.symbols.getValue(it).id)
}.also { knownMaterials = it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,29 @@ interface CardDao {

@Insert(onConflict = OnConflictStrategy.ABORT)
suspend fun insert(cards: List<Card>)

@Query(
"""
select materials.* from decks
inner join cards on decks.id = cards.deck_id
inner join materials on materials.id = cards.material_id
where decks.id = :deckId
order by RANDOM() limit 1
"""
)
suspend fun getRandomMaterialFromDeck(deckId: Long): Material?

@Query(
"""
select m.* from cards as c
inner join materials as m on m.id = c.material_id
where c.deck_id = :deckId
and exists (
select * from known_materials as km
where km.user_id = :userId and km.material_id = m.id
)
order by RANDOM() limit 1
"""
)
suspend fun getRandomKnownMaterialFromDeck(userId: Long, deckId: Long): Material?
}
Loading

0 comments on commit 44d1108

Please sign in to comment.