🐛 Fixes checking token at backend

This commit is contained in:
2026-04-16 15:51:56 +02:00
parent 67b5b6ac6c
commit af47d92cbc
7 changed files with 71 additions and 13 deletions
+3 -1
View File
@@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
} }
android { android {
@@ -48,12 +49,13 @@ dependencies {
implementation(libs.androidx.ui.graphics) implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview) implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3) implementation(libs.androidx.material3)
implementation(libs.androidx.compose.material.icons.extended)
implementation(libs.androidx.appcompat) implementation(libs.androidx.appcompat)
implementation(libs.material) implementation(libs.material)
implementation(libs.androidx.activity) implementation(libs.androidx.activity)
implementation(libs.ktor.client.core) implementation(libs.ktor.client.core)
implementation(libs.ktor.client.android)
implementation(libs.ktor.client.content.negotiation) implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.client.cio)
implementation(libs.ktor.serialization.kotlinx.json) implementation(libs.ktor.serialization.kotlinx.json)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.junit)
@@ -1,12 +1,12 @@
package dev.svitan.antifed package dev.svitan.antifed
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.engine.android.Android
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.engine.cio.CIO
import io.ktor.serialization.kotlinx.json.json import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
val client = HttpClient(Android) { val client = HttpClient(CIO) {
install(ContentNegotiation) { install(ContentNegotiation) {
json() json()
} }
@@ -1,22 +1,46 @@
package dev.svitan.antifed package dev.svitan.antifed
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge 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.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ArrowBack import androidx.compose.material.icons.automirrored.outlined.ArrowBack
import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.* import androidx.compose.material.icons.filled.Visibility
import androidx.compose.runtime.* 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.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.core.content.edit import androidx.core.content.edit
@@ -40,6 +64,7 @@ class AuthActivity : ComponentActivity() {
var serverUrl by remember { mutableStateOf("") } var serverUrl by remember { mutableStateOf("") }
var token by remember { mutableStateOf("") } var token by remember { mutableStateOf("") }
var showToken by remember { mutableStateOf(false) }
var authId by remember { mutableStateOf("") } var authId by remember { mutableStateOf("") }
var authIndex by remember { mutableIntStateOf(-1) } var authIndex by remember { mutableIntStateOf(-1) }
@@ -116,12 +141,13 @@ class AuthActivity : ComponentActivity() {
} }
if (response.status == HttpStatusCode.OK) { if (response.status == HttpStatusCode.OK) {
auths = response.body() auths = response.body<List<AuthDTO>>()
authIndex = auths.indexOfFirst { it.id == authId } authIndex = auths.indexOfFirst { it.id == authId }
isTokenOk = true isTokenOk = true
} }
} catch (_: Exception) { } catch (e: Exception) {
isTokenOk = false isTokenOk = false
Log.e("AuthActivity", "Error checking token", e)
} }
checkingToken = false checkingToken = false
@@ -134,7 +160,7 @@ class AuthActivity : ComponentActivity() {
navigationIcon = { navigationIcon = {
IconButton(onClick = { finish() }) { IconButton(onClick = { finish() }) {
Icon( Icon(
( Icons.AutoMirrored.Outlined.ArrowBack, (Icons.AutoMirrored.Outlined.ArrowBack),
contentDescription = stringResource(R.string.go_back) contentDescription = stringResource(R.string.go_back)
) )
} }
@@ -189,17 +215,39 @@ class AuthActivity : ComponentActivity() {
singleLine = true, singleLine = true,
enabled = isServerUrlOk, enabled = isServerUrlOk,
isError = !isTokenOk && token.isNotBlank(), isError = !isTokenOk && token.isNotBlank(),
visualTransformation = PasswordVisualTransformation(), visualTransformation = (if (showToken) {
VisualTransformation.None
} else {
PasswordVisualTransformation()
}),
keyboardOptions = KeyboardOptions( keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Password keyboardType = KeyboardType.Password
), ),
trailingIcon = { trailingIcon = {
if (checkingToken) { if (checkingToken) {
CircularProgressIndicator( 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)) Spacer(modifier = Modifier.height(12.dp))
@@ -8,4 +8,6 @@
<string name="token">Token</string> <string name="token">Token</string>
<string name="create_auth">Vytvoriť novú auth</string> <string name="create_auth">Vytvoriť novú auth</string>
<string name="bio">Biometrika</string> <string name="bio">Biometrika</string>
<string name="show_token">Ukázať token</string>
<string name="hide_token">Skryť token</string>
</resources> </resources>
@@ -13,6 +13,8 @@
<string name="auth_key" translatable="false">auth_id</string> <string name="auth_key" translatable="false">auth_id</string>
<string name="create_auth">Create new auth</string> <string name="create_auth">Create new auth</string>
<string name="bio">Biometrics</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 --> <!-- Strings used for fragments for navigation -->
</resources> </resources>
+1
View File
@@ -3,4 +3,5 @@ plugins {
alias(libs.plugins.android.application) apply false alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.kotlin.serialization) apply false
} }
+3
View File
@@ -18,6 +18,7 @@ ktorClientContentNegotiation = "3.1.3"
ktorSerializationKotlinxJson = "3.1.3" ktorSerializationKotlinxJson = "3.1.3"
[libraries] [libraries]
androidx-compose-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version = "1.16.0" } androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version = "1.16.0" }
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version = "1.2.1" } androidx-junit = { group = "androidx.test.ext", name = "junit", version = "1.2.1" }
@@ -33,6 +34,7 @@ androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-man
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp" }
material = { group = "com.google.android.material", name = "material", version = "1.12.0" } material = { group = "com.google.android.material", name = "material", version = "1.12.0" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktorClientCore" } ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktorClientCore" }
@@ -45,4 +47,5 @@ ktor-serialization-kotlinx-json = { group = "io.ktor", name = "ktor-serializatio
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }