move fun stuff in login activity to another file
no clutter yano amirite
This commit is contained in:
parent
a7f0e5da8c
commit
fff16ca0fb
2 changed files with 145 additions and 121 deletions
|
@ -16,7 +16,6 @@ import androidx.compose.animation.core.spring
|
||||||
import androidx.compose.animation.core.updateTransition
|
import androidx.compose.animation.core.updateTransition
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
@ -24,14 +23,11 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.imePadding
|
import androidx.compose.foundation.layout.imePadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Checkbox
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.LocalTextStyle
|
import androidx.compose.material3.LocalTextStyle
|
||||||
|
@ -44,14 +40,12 @@ import androidx.compose.runtime.collectAsState
|
||||||
import androidx.compose.runtime.derivedStateOf
|
import androidx.compose.runtime.derivedStateOf
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.draw.rotate
|
import androidx.compose.ui.draw.rotate
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
@ -69,7 +63,6 @@ import eu.m724.vastapp.vastai.data.User
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.chromium.net.CronetEngine
|
import org.chromium.net.CronetEngine
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.random.Random
|
|
||||||
|
|
||||||
class LoginActivity : ComponentActivity() {
|
class LoginActivity : ComponentActivity() {
|
||||||
private lateinit var dashboardLauncher: ActivityResultLauncher<Intent>
|
private lateinit var dashboardLauncher: ActivityResultLauncher<Intent>
|
||||||
|
@ -215,118 +208,5 @@ fun rainbowTextStyle(): TextStyle {
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AdvancedOptions() { // TODO put this in viewmodel
|
fun AdvancedOptions() { // TODO put this in viewmodel
|
||||||
|
FunGame()
|
||||||
var checked by rememberSaveable { mutableStateOf(true) }
|
|
||||||
var clicks by rememberSaveable { mutableIntStateOf(0) }
|
|
||||||
var checkboxLabel by rememberSaveable { mutableIntStateOf(R.string.login_checkbox) }
|
|
||||||
var mathPassing by rememberSaveable { mutableStateOf(true) }
|
|
||||||
|
|
||||||
val clickMessages = mapOf(
|
|
||||||
20 to R.string.login_checkbox_20
|
|
||||||
)
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 12.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(id = R.string.no_options))
|
|
||||||
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Checkbox(
|
|
||||||
enabled = mathPassing,
|
|
||||||
checked = mathPassing && checked,
|
|
||||||
onCheckedChange = {
|
|
||||||
checked = it
|
|
||||||
clicks++
|
|
||||||
|
|
||||||
if (clicks in clickMessages) {
|
|
||||||
checkboxLabel = clickMessages[clicks]!!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Text(text = stringResource(id = checkboxLabel))
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimatedVisibility(visible = mathPassing) {
|
|
||||||
MathProblem(onFail = {
|
|
||||||
mathPassing = false
|
|
||||||
checkboxLabel = R.string.login_checkbox_angry
|
|
||||||
}, onPass = {
|
|
||||||
checked = !checked
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MathProblem(onFail: () -> Unit, onPass: () -> Unit) {
|
|
||||||
var solved by rememberSaveable { mutableStateOf(false) }
|
|
||||||
|
|
||||||
val n1 = Random.nextInt(-10, 20)
|
|
||||||
val n2 = Random.nextInt(-10, 20)
|
|
||||||
val plus = Random.nextBoolean()
|
|
||||||
val correct = Random.nextInt(0, 3)
|
|
||||||
val solution = if (plus) n1 + n2 else n1 - n2
|
|
||||||
val solutions = mutableListOf(solution, solution, solution)
|
|
||||||
|
|
||||||
if (correct != 0) solutions[0] += Random.nextInt(5, 11)
|
|
||||||
if (correct != 1) solutions[1] -= Random.nextInt(1, 3)
|
|
||||||
if (correct != 2) solutions[2] -= Random.nextInt(5, 11)
|
|
||||||
|
|
||||||
if (solved) {
|
|
||||||
MathProblem(onFail, onPass)
|
|
||||||
} else {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
|
||||||
) {
|
|
||||||
MathProblemLabel(n1 = n1, n2 = n2, sign = if (plus) "+" else "-")
|
|
||||||
NumberButton(onClick = {
|
|
||||||
if (correct == 0) {
|
|
||||||
solved = true
|
|
||||||
onPass()
|
|
||||||
} else {
|
|
||||||
onFail()
|
|
||||||
}
|
|
||||||
}, number = solutions[0])
|
|
||||||
NumberButton(onClick = {
|
|
||||||
if (correct == 1) {
|
|
||||||
solved = true
|
|
||||||
onPass()
|
|
||||||
} else {
|
|
||||||
onFail()
|
|
||||||
}
|
|
||||||
}, number = solutions[1])
|
|
||||||
NumberButton(onClick = {
|
|
||||||
if (correct == 2) {
|
|
||||||
solved = true
|
|
||||||
onPass()
|
|
||||||
} else {
|
|
||||||
onFail()
|
|
||||||
}
|
|
||||||
}, number = solutions[2])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MathProblemLabel(n1: Int, n2: Int, sign: String) {
|
|
||||||
Text("$n1 $sign $n2 =")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun NumberButton(onClick: () -> Unit, number: Int) {
|
|
||||||
Button(
|
|
||||||
modifier = Modifier
|
|
||||||
.clip(CircleShape)
|
|
||||||
.size(30.dp),
|
|
||||||
contentPadding = PaddingValues(0.dp),
|
|
||||||
onClick = onClick
|
|
||||||
) {
|
|
||||||
Text(number.toString())
|
|
||||||
}
|
|
||||||
}
|
}
|
144
app/src/main/java/eu/m724/vastapp/activity/login/MathGame.kt
Normal file
144
app/src/main/java/eu/m724/vastapp/activity/login/MathGame.kt
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
package eu.m724.vastapp.activity.login
|
||||||
|
|
||||||
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Checkbox
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import eu.m724.vastapp.R
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FunGame() {
|
||||||
|
var checked by rememberSaveable { mutableStateOf(true) }
|
||||||
|
var clicks by rememberSaveable { mutableIntStateOf(0) }
|
||||||
|
var checkboxLabel by rememberSaveable { mutableIntStateOf(R.string.login_checkbox) }
|
||||||
|
var mathPassing by rememberSaveable { mutableStateOf(true) }
|
||||||
|
|
||||||
|
val clickMessages = mapOf(
|
||||||
|
20 to R.string.login_checkbox_20
|
||||||
|
)
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 12.dp)
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(id = R.string.no_options))
|
||||||
|
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Checkbox(
|
||||||
|
enabled = mathPassing,
|
||||||
|
checked = mathPassing && checked,
|
||||||
|
onCheckedChange = {
|
||||||
|
checked = it
|
||||||
|
clicks++
|
||||||
|
|
||||||
|
if (clicks in clickMessages) {
|
||||||
|
checkboxLabel = clickMessages[clicks]!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
Text(text = stringResource(id = checkboxLabel))
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(visible = mathPassing) {
|
||||||
|
MathProblem(onFail = {
|
||||||
|
mathPassing = false
|
||||||
|
checkboxLabel = R.string.login_checkbox_angry
|
||||||
|
}, onPass = {
|
||||||
|
checked = !checked
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MathProblem(onFail: () -> Unit, onPass: () -> Unit) {
|
||||||
|
var solved by rememberSaveable { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val n1 = Random.nextInt(-10, 20)
|
||||||
|
val n2 = Random.nextInt(-10, 20)
|
||||||
|
val plus = Random.nextBoolean()
|
||||||
|
val correct = Random.nextInt(0, 3)
|
||||||
|
val solution = if (plus) n1 + n2 else n1 - n2
|
||||||
|
val solutions = mutableListOf(solution, solution, solution)
|
||||||
|
|
||||||
|
if (correct != 0) solutions[0] += Random.nextInt(5, 11)
|
||||||
|
if (correct != 1) solutions[1] -= Random.nextInt(1, 3)
|
||||||
|
if (correct != 2) solutions[2] -= Random.nextInt(5, 11)
|
||||||
|
|
||||||
|
if (solved) {
|
||||||
|
MathProblem(onFail, onPass)
|
||||||
|
} else {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
|
) {
|
||||||
|
MathProblemLabel(n1 = n1, n2 = n2, sign = if (plus) "+" else "-")
|
||||||
|
NumberButton(onClick = {
|
||||||
|
if (correct == 0) {
|
||||||
|
solved = true
|
||||||
|
onPass()
|
||||||
|
} else {
|
||||||
|
onFail()
|
||||||
|
}
|
||||||
|
}, number = solutions[0])
|
||||||
|
NumberButton(onClick = {
|
||||||
|
if (correct == 1) {
|
||||||
|
solved = true
|
||||||
|
onPass()
|
||||||
|
} else {
|
||||||
|
onFail()
|
||||||
|
}
|
||||||
|
}, number = solutions[1])
|
||||||
|
NumberButton(onClick = {
|
||||||
|
if (correct == 2) {
|
||||||
|
solved = true
|
||||||
|
onPass()
|
||||||
|
} else {
|
||||||
|
onFail()
|
||||||
|
}
|
||||||
|
}, number = solutions[2])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MathProblemLabel(n1: Int, n2: Int, sign: String) {
|
||||||
|
Text("$n1 $sign $n2 =")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NumberButton(onClick: () -> Unit, number: Int) {
|
||||||
|
Button(
|
||||||
|
modifier = Modifier
|
||||||
|
.clip(CircleShape)
|
||||||
|
.size(30.dp),
|
||||||
|
contentPadding = PaddingValues(0.dp),
|
||||||
|
onClick = onClick
|
||||||
|
) {
|
||||||
|
Text(number.toString())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue