Some basic logic
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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") }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user