Commit df14831a by likorn

Selected values are saved in SharedPreferences

parent f00fff82
package com.example.quickmax
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
......@@ -10,14 +11,18 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() {
private var secToSolve: Int = 4
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
secToSolve = retrieveSecondsToSolve()
seek_bar.setMinStartValue(secToSolve.toFloat()).apply()
seek_bar.setOnSeekbarChangeListener {
n -> seek_bar_value.text = resources.getString(R.string.time_to_solve, n.toString())
secToSolve = n.toInt()
}
seek_bar.setMinStartValue(4f).apply()
card_2_digits.setOnClickListener(cardOnClickListener)
card_3_digits.setOnClickListener(cardOnClickListener)
......@@ -26,7 +31,8 @@ class MainActivity: AppCompatActivity() {
private val cardOnClickListener = View.OnClickListener { card ->
val numDigits = ((card as CardView).getChildAt(0) as TextView).text.toString().toInt()
val secToSolve = seek_bar.selectedMinValue.toInt()
saveSelectedValues()
val intent = Intent(this, TaskActivity::class.java).also { i ->
i.putExtra("num_digits", numDigits)
......@@ -34,4 +40,15 @@ class MainActivity: AppCompatActivity() {
}
startActivity(intent)
}
private fun saveSelectedValues() {
val editor = getSharedPreferences("my_prefs", Context.MODE_PRIVATE).edit()
editor.putInt("sec_to_solve", secToSolve)
editor.apply()
}
private fun retrieveSecondsToSolve(): Int {
val prefs = getSharedPreferences("my_prefs", Context.MODE_PRIVATE)
return prefs.getInt("sec_to_solve", 4)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment