1
0

Some basic logic

This commit is contained in:
Sweetbread 2025-04-21 17:44:40 +03:00
parent 659d362c87
commit 4c8bfdd051
Signed by: Sweetbread
GPG Key ID: 17A5CB9A7DD85319
6 changed files with 88 additions and 14 deletions

View File

@ -1,3 +1,8 @@
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
@ -63,4 +68,6 @@ dependencies {
implementation(libs.ktor.client.okhttp)
implementation(libs.ktor.client.logging)
implementation(libs.logback.classic)
implementation(libs.splitties.base)
}

View File

@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Created by sweetbread
~ Copyright (c) 2025. All rights reserved.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"

View File

@ -1,3 +1,8 @@
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
package ru.risdeveau.geotracker
import io.ktor.client.*
@ -21,7 +26,7 @@ data class GeoData(
/**
* Function to validate [baseurl]
* Validate [baseurl] and check accessibility to a server
* @return true if baseurl is valid
*/
suspend fun health(baseurl: String): Boolean {
@ -29,4 +34,8 @@ suspend fun health(baseurl: String): Boolean {
return r.status == HttpStatusCode.OK
}
fun sendGeo(baseurl: String, )
/**
* Send data to a server
*/
fun sendGeo(baseurl: String, data: GeoData) {
}

View File

@ -0,0 +1,13 @@
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
package ru.risdeveau.geotracker
import splitties.preferences.Preferences
object SettingsPreferences : Preferences("settings") {
var username by stringPref("username", "anonimous")
var url by stringPref("url", "https://example.com")
}

View File

@ -1,3 +1,8 @@
/*
* Created by sweetbread
* Copyright (c) 2025. All rights reserved.
*/
package ru.risdeveau.geotracker
import android.os.Bundle
@ -7,11 +12,19 @@ import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
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.tooling.preview.Preview
import kotlinx.coroutines.launch
import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
class MainActivity : ComponentActivity() {
@ -21,8 +34,22 @@ class MainActivity : ComponentActivity() {
setContent {
GeoTrackerTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Box(Modifier.padding(innerPadding)) {
Box(
Modifier
.padding(innerPadding)
.fillMaxSize()) {
var loading by remember { mutableStateOf(true) }
if (loading) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
LaunchedEffect(true) {
launch {
if (!health(SettingsPreferences.url)) {
Settings()
}
}
}
}
}
}
}
@ -30,18 +57,28 @@ class MainActivity : ComponentActivity() {
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
sealed class Screen {
object Main : Screen()
object Settings : Screen()
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
GeoTrackerTheme {
Greeting("Android")
fun Settings(modifier: Modifier = Modifier) {
var username by remember { mutableStateOf("") }
var url by remember { mutableStateOf("") }
Box (modifier = modifier) {
OutlinedTextField(
value = username,
onValueChange = { username = it },
label = { Text("Username") }
)
OutlinedTextField(
value = url,
onValueChange = { url = it },
label = { Text("Server URL") }
)
}
}

View File

@ -11,6 +11,7 @@ lifecycleRuntimeKtx = "2.8.7"
activityCompose = "1.10.1"
composeBom = "2024.04.01"
logbackClassic = "1.2.11"
splittiesFunPackAndroidBase = "3.0.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@ -33,6 +34,7 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logbackClassic" }
splitties-base = { module = "com.louiscad.splitties:splitties-fun-pack-android-base", version.ref = "splittiesFunPackAndroidBase" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }