🐳 Adds dockerfile

This commit is contained in:
Daniel Svitan
2025-05-18 12:28:37 +02:00
parent d1ddd7be3b
commit c124754c96
7 changed files with 110 additions and 10 deletions

View File

@@ -38,6 +38,7 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.svitan.antifed.ui.theme.AntiFedTheme
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.http.HttpStatusCode
import kotlinx.coroutines.delay
@@ -56,6 +57,12 @@ class AuthActivity : ComponentActivity() {
var checkingUrl by remember { mutableStateOf(false) }
var isServerUrlOk by remember { mutableStateOf(false) }
var needToCheckToken by remember { mutableStateOf(false) }
var checkingToken by remember { mutableStateOf(false) }
var isTokenOk by remember { mutableStateOf(false) }
var auths by remember { mutableStateOf(listOf<AuthDTO>()) }
val prefs = LocalContext.current.getSharedPreferences(
stringResource(R.string.settings_prefs_key),
MODE_PRIVATE
@@ -68,7 +75,7 @@ class AuthActivity : ComponentActivity() {
fun serverUrlMatches(): Boolean {
var re = Regex(
"(?:http[s]?:\\/\\/.)?(?:www\\.)?[-a-zA-Z0-9@%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b(?:[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)",
"""https?://[a-zA-Z0-9\\.]+\\.[a-zA-Z0-9]+""",
RegexOption.DOT_MATCHES_ALL
)
return re.containsMatchIn(serverUrl)
@@ -89,7 +96,6 @@ class AuthActivity : ComponentActivity() {
delay(1000)
checkingUrl = true
val response = client.get(serverUrl)
checkingUrl = false
@@ -101,11 +107,34 @@ class AuthActivity : ComponentActivity() {
}
}
LaunchedEffect(token) {
if (!needToCheckToken) return@LaunchedEffect
else isTokenOk = false
if (!isServerUrlOk) return@LaunchedEffect
if (token.isBlank()) return@LaunchedEffect
delay(1000)
checkingToken = true
val response = client.get("$serverUrl/auth")
if (response.status != HttpStatusCode.OK) {
checkingToken = false
needToCheckToken = false
isTokenOk = false
return@LaunchedEffect
}
auths = response.body<List<AuthDTO>>()
checkingToken = false
needToCheckToken = false
isTokenOk = true
}
Scaffold(
topBar = {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
),
title = {
@@ -159,13 +188,19 @@ class AuthActivity : ComponentActivity() {
TextField(
value = token,
onValueChange = { token = it },
onValueChange = {
needToCheckToken = true
token = it
},
label = { Text(stringResource(R.string.token)) },
singleLine = true,
isError = token.isBlank(),
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password)
)
Spacer(modifier = Modifier.height(12.dp))
Text("auths: $auths")
}
}
}

View File

@@ -90,7 +90,6 @@ class MainActivity : ComponentActivity() {
topBar = {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary
),
title = {