Add settings to control the lesson length
This commit is contained in:
parent
c59f347e09
commit
751c659862
3 changed files with 39 additions and 5 deletions
|
@ -77,19 +77,28 @@ class TrainingActivity : AppCompatActivity(),
|
|||
|
||||
val generatorSettings = DitDahGeneratorSettings()
|
||||
|
||||
val lessonLengthInMinutes = 1 // TODO These should be configurable from the settings window
|
||||
val wordSize = 5
|
||||
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val lessonLengthInMinutes = sharedPreferences.getInt(getString(R.string.setting_koch_lesson_length_key), 1)
|
||||
var minWordSize = 5
|
||||
var maxWordSize = 5
|
||||
if(sharedPreferences.getBoolean(getString(R.string.setting_koch_lesson_vary_word_size_key), false)) {
|
||||
minWordSize = 2
|
||||
maxWordSize = 6
|
||||
}
|
||||
|
||||
var sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val quickTestingSwitchEnabled = sharedPrefs.getBoolean("switch_preference_1", false)
|
||||
val numberOfWords = if(!quickTestingSwitchEnabled) {
|
||||
// This is only an approximation
|
||||
generatorSettings.farnsworthWordsPerMinute * lessonLengthInMinutes
|
||||
} else { 2 } // This is just for quicker testing; remove eventually
|
||||
|
||||
var lessonText = String()
|
||||
var rng = Random.Default
|
||||
for(i in 0 until numberOfWords) {
|
||||
for(c in 0 until wordSize) {
|
||||
val thisWordSize = rng.nextInt(minWordSize, maxWordSize + 1)
|
||||
for(c in 0 until thisWordSize) {
|
||||
val randomLetterIndex = rng.nextInt(0, mAlphabet.length)
|
||||
lessonText += mAlphabet.substring(randomLetterIndex, randomLetterIndex + 1)
|
||||
}
|
||||
|
|
|
@ -20,8 +20,15 @@
|
|||
<string name="setting_wpm_key">sender_wpm</string>
|
||||
<string name="setting_effective_wpm_key">sender_effective_wpm</string>
|
||||
<string name="setting_last_lesson_key">last_lesson_index</string>
|
||||
<string name="setting_koch_lesson_length_key">koch_lesson_length</string>
|
||||
<string name="setting_koch_lesson_vary_word_size_key">koch_lesson_vary_word_size</string>
|
||||
|
||||
<string name="training_results_summary">Score: %d%%\nMistakes: %d</string>
|
||||
<string name="training_results_error">Error: No input?</string>
|
||||
|
||||
<string name="settings_sender_heading">Sender</string>
|
||||
<string name="settings_koch_heading">Koch Lessons</string>
|
||||
<string name="setting_koch_lesson_length_label">Minutes per session</string>
|
||||
<string name="setting_koch_lesson_vary_label">Variable group length</string>
|
||||
<string name="setting_koch_lesson_vary_off">Always groups of 5</string>
|
||||
<string name="setting_koch_lesson_vary_on">Groups between 2 and 6 characters</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<PreferenceCategory app:title="Sender">
|
||||
<PreferenceCategory app:title="@string/settings_sender_heading">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="switch_preference_1"
|
||||
|
@ -39,5 +39,23 @@
|
|||
app:title="@string/setting_effective_wpm_label" />
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/settings_koch_heading">
|
||||
<SeekBarPreference
|
||||
android:defaultValue="600"
|
||||
android:max="10"
|
||||
app:defaultValue="1"
|
||||
app:key="@string/setting_koch_lesson_length_key"
|
||||
app:min="1"
|
||||
app:showSeekBarValue="true"
|
||||
app:title="@string/setting_koch_lesson_length_label" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/setting_koch_lesson_vary_word_size_key"
|
||||
android:summaryOff="@string/setting_koch_lesson_vary_off"
|
||||
android:summaryOn="@string/setting_koch_lesson_vary_on"
|
||||
android:title="@string/setting_koch_lesson_vary_label" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Reference in a new issue