Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
quick_max
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
53e74182
authored
Sep 28, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring
parent
87a902a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
View file @
53e74182
...
...
@@ -18,16 +18,19 @@ class MainActivity : AppCompatActivity() {
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
// restore data
if
(
savedInstanceState
==
null
)
retrieveSharedPrefs
()
else
restoreInstanceState
(
savedInstanceState
)
// set up cards
cards
=
mapOf
(
2
to
card_2_digits
,
3
to
card_3_digits
,
4
to
card_4_digits
)
cards
.
values
.
forEach
{
card
->
card
.
setOnClickListener
{
card
.
isChecked
=
true
}
card
.
setOnCheckedChangeListener
(
checkedChangeListener
)
card
.
setOnCheckedChangeListener
{
card
,
isChecked
->
updateCards
(
card
,
isChecked
)
}
}
cards
.
getValue
(
numDigits
).
isChecked
=
true
// set up seek bar
seek_bar
.
apply
{
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
setOnSeekbarChangeListener
{
n
->
...
...
@@ -36,7 +39,8 @@ class MainActivity : AppCompatActivity() {
}
}
btn_play
.
setOnClickListener
(
playClickListener
)
// set up button play
btn_play
.
setOnClickListener
{
startTaskActivity
()
}
}
private
fun
restoreInstanceState
(
savedInstanceState
:
Bundle
)
{
...
...
@@ -50,7 +54,7 @@ class MainActivity : AppCompatActivity() {
outState
.
putInt
(
"sec_to_solve"
,
secToSolve
)
}
private
val
checkedChangeListener
=
MaterialCardView
.
OnCheckedChangeListener
{
card
,
isChecked
->
private
fun
updateCards
(
card
:
MaterialCardView
,
isChecked
:
Boolean
)
{
if
(
isChecked
&&
card
!=
cards
.
getValue
(
numDigits
))
{
numDigits
=
getTextView
(
card
).
text
.
toString
().
toInt
()
cards
.
values
.
forEach
{
c
->
...
...
@@ -59,24 +63,20 @@ class MainActivity : AppCompatActivity() {
}
}
private
val
playClickListener
=
View
.
OnClickListener
{
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
).
also
{
i
->
i
.
putExtra
(
"num_digits"
,
numDigits
)
i
.
putExtra
(
"sec_to_solve"
,
secToSolve
)
}
private
fun
startTaskActivity
()
{
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
)
.
apply
{
putExtra
(
"num_digits"
,
numDigits
)
}
.
apply
{
putExtra
(
"sec_to_solve"
,
secToSolve
)
}
startActivity
(
intent
)
}
override
fun
onStop
()
{
super
.
onStop
()
saveSelectedValues
()
}
private
fun
saveSelectedValues
()
{
val
editor
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
).
edit
()
editor
.
putInt
(
"sec_to_solve"
,
secToSolve
)
editor
.
putInt
(
"num_digits"
,
numDigits
)
editor
.
apply
()
// save to shared preferences
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
).
edit
()
.
apply
{
putInt
(
"sec_to_solve"
,
secToSolve
)
}
.
apply
{
putInt
(
"num_digits"
,
numDigits
)
}
.
apply
()
}
private
fun
retrieveSharedPrefs
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment