Remember the last lesson run, with a quick-launch button
This commit is contained in:
parent
297ab32f84
commit
5e8ce0cdcc
6 changed files with 32 additions and 14 deletions
1
TODO
1
TODO
|
@ -1,5 +1,4 @@
|
|||
Basic:
|
||||
* Remember last lesson
|
||||
|
||||
Polish:
|
||||
* Better user input
|
||||
|
|
|
@ -6,7 +6,7 @@ object KochLessonDefinitions {
|
|||
val Lessons : MutableList<KochLesson> = ArrayList()
|
||||
|
||||
init {
|
||||
for (i in 1 until LessonOrder.length) {
|
||||
for (i in 0 until LessonOrder.length - 1) {
|
||||
Lessons.add(
|
||||
KochLesson(
|
||||
i
|
||||
|
@ -17,21 +17,20 @@ object KochLessonDefinitions {
|
|||
|
||||
data class KochLesson(val lessonIndex : Int) {
|
||||
override fun toString() : String {
|
||||
// The zeroth lesson doesn't exist, since it would only contain a single character //TODO raise exception?
|
||||
|
||||
if(lessonIndex == 1) {
|
||||
if(lessonIndex == 0) {
|
||||
// The first lesson is a little special, as it introduces two letters:
|
||||
return LessonOrder.substring(0, 1) + " and " + LessonOrder.substring(1, 2)
|
||||
}
|
||||
return LessonOrder.substring(lessonIndex , lessonIndex + 1)
|
||||
return LessonOrder.substring(lessonIndex + 1 , lessonIndex + 2)
|
||||
}
|
||||
|
||||
// Get the lesson number, for display in the UI
|
||||
fun indexForHumans() : Int {
|
||||
return lessonIndex
|
||||
return lessonIndex + 1
|
||||
}
|
||||
|
||||
fun getAlphabet() : String {
|
||||
return LessonOrder.substring(0, lessonIndex + 1)
|
||||
return LessonOrder.substring(0, lessonIndex + 2)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package es.eoinrul.ecwt
|
|||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import es.eoinrul.ecwt.R
|
||||
|
@ -21,18 +22,23 @@ class LevelSelectActivity : AppCompatActivity(),
|
|||
mLevelSelectView = findViewById<RecyclerView>(R.id.levelSelection_view).apply {
|
||||
setHasFixedSize(true)
|
||||
layoutManager = mLevelSelectLayoutManager
|
||||
//adapter = mLevelSelectViewAdapter
|
||||
}
|
||||
}
|
||||
|
||||
override fun onListFragmentInteraction(lesson: KochLessonDefinitions.KochLesson?) {
|
||||
if(lesson != null) {
|
||||
// Remember the last lesson that was run
|
||||
var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
val lastLessonPrefKey = getString(R.string.setting_last_lesson_key)
|
||||
sharedPreferences.edit().putInt(lastLessonPrefKey, lesson.lessonIndex).apply()
|
||||
}
|
||||
|
||||
val intent = Intent(this, TrainingActivity::class.java).apply {
|
||||
putExtra(TRAINING_ALPHABET, lesson?.getAlphabet())
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
private lateinit var mLevelSelectView : RecyclerView
|
||||
private lateinit var mLevelSelectLayoutManager : RecyclerView.LayoutManager
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.preference.PreferenceManager
|
||||
import es.eoinrul.ecwt.R
|
||||
|
||||
/**
|
||||
|
@ -37,6 +38,11 @@ class TrainingLevelFragment : Fragment() {
|
|||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_training_level_list, container, false)
|
||||
|
||||
// Get the last lesson index out of the preferences, so we can show an item to launch it
|
||||
var lastLessonPref = getString(R.string.setting_last_lesson_key)
|
||||
var sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
var lastLessonIndex = sharedPreferences.getInt(lastLessonPref, 0)
|
||||
|
||||
// Set the adapter
|
||||
if (view is RecyclerView) {
|
||||
with(view) {
|
||||
|
@ -46,7 +52,8 @@ class TrainingLevelFragment : Fragment() {
|
|||
}
|
||||
adapter = TrainingLevelRecyclerViewAdapter(
|
||||
KochLessonDefinitions.Lessons,
|
||||
listener
|
||||
listener,
|
||||
lastLessonIndex
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.preference.PreferenceManager
|
||||
import es.eoinrul.ecwt.R
|
||||
|
||||
|
||||
|
@ -14,11 +15,13 @@ import kotlinx.android.synthetic.main.fragment_training_level.view.*
|
|||
|
||||
class TrainingLevelRecyclerViewAdapter(
|
||||
private val mLessons: List<KochLessonDefinitions.KochLesson>,
|
||||
private val mListener: OnListFragmentInteractionListener?
|
||||
private val mListener: OnListFragmentInteractionListener?,
|
||||
private val mLastLessonIndex : Int
|
||||
) : RecyclerView.Adapter<TrainingLevelRecyclerViewAdapter.ViewHolder>() {
|
||||
|
||||
private val mOnClickListener: View.OnClickListener
|
||||
|
||||
|
||||
init {
|
||||
mOnClickListener = View.OnClickListener { v ->
|
||||
val item = v.tag as KochLessonDefinitions.KochLesson
|
||||
|
@ -35,7 +38,8 @@ class TrainingLevelRecyclerViewAdapter(
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val lesson = mLessons[position]
|
||||
val lessonIndex = if(position == 0) mLastLessonIndex else position - 1
|
||||
val lesson = mLessons[lessonIndex]
|
||||
holder.mIdView.text = "Lesson " + lesson.indexForHumans().toString()
|
||||
holder.mContentView.text = lesson.toString()
|
||||
|
||||
|
@ -45,7 +49,7 @@ class TrainingLevelRecyclerViewAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = mLessons.size
|
||||
override fun getItemCount(): Int = mLessons.size + 1 // +1 for the "Last lesson" button
|
||||
|
||||
inner class ViewHolder(val mView: View) : RecyclerView.ViewHolder(mView) {
|
||||
val mIdView: TextView = mView.item_number
|
||||
|
|
|
@ -15,10 +15,13 @@
|
|||
<string name="setting_tone_frequency_label">Tone Frequency</string>
|
||||
<string name="setting_wpm_label">Words per Minute</string>
|
||||
<string name="setting_effective_wpm_label">Effective Words per Minute</string>
|
||||
|
||||
<string name="setting_tone_key">sender_tone</string>
|
||||
<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="training_results_summary">Score: %d%%\nMistakes: %d</string>
|
||||
<string name="training_results_error">Error: No input?</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue