🐛 Fixes checking token at backend
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package dev.svitan.antifed
|
||||
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.engine.android.Android
|
||||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
||||
import io.ktor.client.engine.cio.CIO
|
||||
import io.ktor.serialization.kotlinx.json.json
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
val client = HttpClient(Android) {
|
||||
val client = HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json()
|
||||
}
|
||||
|
||||
@@ -1,22 +1,46 @@
|
||||
package dev.svitan.antifed
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material.icons.filled.Visibility
|
||||
import androidx.compose.material.icons.filled.VisibilityOff
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.content.edit
|
||||
@@ -40,6 +64,7 @@ class AuthActivity : ComponentActivity() {
|
||||
|
||||
var serverUrl by remember { mutableStateOf("") }
|
||||
var token by remember { mutableStateOf("") }
|
||||
var showToken by remember { mutableStateOf(false) }
|
||||
|
||||
var authId by remember { mutableStateOf("") }
|
||||
var authIndex by remember { mutableIntStateOf(-1) }
|
||||
@@ -116,12 +141,13 @@ class AuthActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
if (response.status == HttpStatusCode.OK) {
|
||||
auths = response.body()
|
||||
auths = response.body<List<AuthDTO>>()
|
||||
authIndex = auths.indexOfFirst { it.id == authId }
|
||||
isTokenOk = true
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
} catch (e: Exception) {
|
||||
isTokenOk = false
|
||||
Log.e("AuthActivity", "Error checking token", e)
|
||||
}
|
||||
|
||||
checkingToken = false
|
||||
@@ -134,7 +160,7 @@ class AuthActivity : ComponentActivity() {
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { finish() }) {
|
||||
Icon(
|
||||
( Icons.AutoMirrored.Outlined.ArrowBack,
|
||||
(Icons.AutoMirrored.Outlined.ArrowBack),
|
||||
contentDescription = stringResource(R.string.go_back)
|
||||
)
|
||||
}
|
||||
@@ -189,17 +215,39 @@ class AuthActivity : ComponentActivity() {
|
||||
singleLine = true,
|
||||
enabled = isServerUrlOk,
|
||||
isError = !isTokenOk && token.isNotBlank(),
|
||||
visualTransformation = PasswordVisualTransformation(),
|
||||
visualTransformation = (if (showToken) {
|
||||
VisualTransformation.None
|
||||
} else {
|
||||
PasswordVisualTransformation()
|
||||
}),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Password
|
||||
),
|
||||
trailingIcon = {
|
||||
if (checkingToken) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(24.dp)
|
||||
modifier = Modifier.size(36.dp)
|
||||
)
|
||||
}
|
||||
})
|
||||
Icon(
|
||||
if (showToken) {
|
||||
Icons.Default.VisibilityOff
|
||||
} else {
|
||||
Icons.Default.Visibility
|
||||
},
|
||||
contentDescription = stringResource(
|
||||
if (showToken) {
|
||||
R.string.hide_token
|
||||
} else {
|
||||
R.string.show_token
|
||||
}
|
||||
),
|
||||
modifier = Modifier
|
||||
.align(Alignment.End)
|
||||
.clickable { showToken = !showToken }
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
|
||||
|
||||
@@ -8,4 +8,6 @@
|
||||
<string name="token">Token</string>
|
||||
<string name="create_auth">Vytvoriť novú auth</string>
|
||||
<string name="bio">Biometrika</string>
|
||||
<string name="show_token">Ukázať token</string>
|
||||
<string name="hide_token">Skryť token</string>
|
||||
</resources>
|
||||
@@ -13,6 +13,8 @@
|
||||
<string name="auth_key" translatable="false">auth_id</string>
|
||||
<string name="create_auth">Create new auth</string>
|
||||
<string name="bio">Biometrics</string>
|
||||
<string name="show_token">Show token</string>
|
||||
<string name="hide_token">Hide token</string>
|
||||
<!-- Strings used for fragments for navigation -->
|
||||
|
||||
</resources>
|
||||
Reference in New Issue
Block a user