1
0
Fork 0

Start on implementing lesson training

This commit is contained in:
Eoin Mcloughlin 2020-05-15 19:19:36 +01:00
parent 84cc9f5516
commit 4da92cafe0
5 changed files with 75 additions and 2 deletions

View file

@ -9,7 +9,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".LevelSelectActivity" android:parentActivityName=".MainActivity"></activity>
<activity android:name=".TrainingActivity" android:parentActivityName=".LevelSelectActivity"></activity>
<activity
android:name=".LevelSelectActivity"
android:parentActivityName=".MainActivity" />
<activity
android:name=".SounderActivity"
android:parentActivityName=".MainActivity"

View file

@ -29,5 +29,9 @@ object KochLessonDefinitions {
fun indexForHumans() : Int {
return lessonIndex
}
fun getAlphabet() : String {
return LessonOrder.substring(0, lessonIndex + 1)
}
}
}

View file

@ -1,11 +1,14 @@
package es.eoinrul.ecwt
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import es.eoinrul.ecwt.R
const val TRAINING_ALPHABET = "es.eoinrul.ecwt.TRAINING_ALPHABET"
class LevelSelectActivity : AppCompatActivity(),
TrainingLevelFragment.OnListFragmentInteractionListener {
@ -23,7 +26,10 @@ class LevelSelectActivity : AppCompatActivity(),
}
override fun onListFragmentInteraction(lesson: KochLessonDefinitions.KochLesson?) {
TODO("Not yet implemented")
val intent = Intent(this, TrainingActivity::class.java).apply {
putExtra(TRAINING_ALPHABET, lesson?.getAlphabet())
}
startActivity(intent);
}

View file

@ -0,0 +1,51 @@
package es.eoinrul.ecwt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.preference.PreferenceManager
import kotlin.random.Random
class TrainingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_traning)
initSoundPlayer()
val alphabet = intent.getStringExtra(TRAINING_ALPHABET);
startLesson(alphabet!!) //TODO Only after user input is ready
}
private fun initSoundPlayer() {
val generatorSettings = DitDahGeneratorSettings()
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
generatorSettings.toneFrequency = sharedPreferences.getInt("sender_tone", generatorSettings.toneFrequency)
mSoundPlayer = DitDahSoundStream(generatorSettings)
}
private fun startLesson(alphabet : String) {
val generatorSettings = DitDahGeneratorSettings()
val lessonLengthInMinutes = 1 // TODO These should be configurable from the settings window
val wordSize = 5
val numberOfWords = generatorSettings.farnsworthWordsPerMinute * lessonLengthInMinutes
var lessonText = String()
var rng = Random.Default
for(i in 0 until numberOfWords) {
for(c in 0 until wordSize) {
val randomLetterIndex = rng.nextInt(0, alphabet.length)
lessonText += alphabet.substring(randomLetterIndex, randomLetterIndex + 1)
}
lessonText += " "
}
mSoundPlayer.enqueue(StringToSoundSequence(lessonText))
}
private lateinit var mSoundPlayer : DitDahSoundStream
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="es.eoinrul.ecwt.TrainingActivity">
</androidx.constraintlayout.widget.ConstraintLayout>