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
be189be0
authored
Sep 28, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Selections are saved during orientation change in the MainActivity
parent
d4831526
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
11 deletions
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
app/src/main/java/com/paktalin/quickmax/MainActivity.kt
View file @
be189be0
...
...
@@ -13,33 +13,52 @@ class MainActivity : AppCompatActivity() {
private
var
secToSolve
:
Int
=
4
private
var
numDigits
:
Int
=
3
private
lateinit
var
checkedCard
:
MaterialCardView
private
lateinit
var
cards
:
List
<
MaterialCardView
>
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
retrieveSharedPrefs
()
seek_bar
.
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
seek_bar
.
setOnSeekbarChangeListener
{
n
->
if
(
savedInstanceState
==
null
)
retrieveSharedPrefs
()
else
restoreInstanceState
(
savedInstanceState
)
checkedCard
.
isChecked
=
true
seek_bar
.
apply
{
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
setOnSeekbarChangeListener
{
n
->
seek_bar_value
.
text
=
resources
.
getString
(
R
.
string
.
time_to_solve
,
n
.
toString
())
secToSolve
=
n
.
toInt
()
}
}
card_2_digits
.
setOnClickListener
(
cardOnClickListener
)
card_3_digits
.
setOnClickListener
(
cardOnClickListener
)
card_4_digits
.
setOnClickListener
(
cardOnClickListener
)
cards
=
listOf
(
card_2_digits
,
card_3_digits
,
card_4_digits
)
cards
.
forEach
{
card
->
card
.
setOnClickListener
(
cardOnClickListener
)
}
btn_play
.
setOnClickListener
(
playClickListener
)
}
private
fun
restoreInstanceState
(
savedInstanceState
:
Bundle
)
{
checkedCard
=
findViewById
(
savedInstanceState
.
getInt
(
"checked_num_id"
))
secToSolve
=
savedInstanceState
.
getInt
(
"sec_to_solve"
)
numDigits
=
savedInstanceState
.
getInt
(
"num_digits"
)
}
override
fun
onSaveInstanceState
(
outState
:
Bundle
)
{
super
.
onSaveInstanceState
(
outState
)
outState
.
putInt
(
"num_digits"
,
numDigits
)
outState
.
putInt
(
"sec_to_solve"
,
secToSolve
)
outState
.
putInt
(
"checked_num_id"
,
checkedCard
.
id
)
}
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
val
cardM
=
card
as
MaterialCardView
if
(!
cardM
.
isChecked
)
{
checkedCard
=
cardM
checkedCard
.
isChecked
=
true
numDigits
=
numDigitsFromCard
(
checkedCard
)
listOf
(
card_2_digits
,
card_3_digits
,
card_4_digits
)
.
forEach
{
c
->
if
(
c
.
id
!=
c
ardM
.
id
)
cards
.
forEach
{
c
->
if
(
c
.
id
!=
c
heckedCard
.
id
)
c
.
isChecked
=
false
}
}
...
...
@@ -64,11 +83,13 @@ class MainActivity : AppCompatActivity() {
private
fun
retrieveSharedPrefs
()
{
val
prefs
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
)
secToSolve
=
prefs
.
getInt
(
"sec_to_solve"
,
4
)
checkedCard
=
findViewById
(
prefs
.
getInt
(
"checked_num_id"
,
checkedCard
=
findViewById
(
prefs
.
getInt
(
"checked_num_id"
,
R
.
id
.
card_3_digits
))
)
)
numDigits
=
numDigitsFromCard
(
checkedCard
)
checkedCard
.
isChecked
=
true
}
private
fun
numDigitsFromCard
(
card
:
MaterialCardView
):
Int
{
...
...
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