1
0

feat: add statistics

This commit is contained in:
Sweetbread 2025-05-23 11:58:19 +03:00
parent 831b6bf491
commit 4e517b87cd
Signed by: Sweetbread
GPG Key ID: 17A5CB9A7DD85319
3 changed files with 31 additions and 1 deletions

View File

@ -11,4 +11,10 @@ object SettingsPreferences : Preferences("settings") {
var username by stringPref("username", "")
var url by stringPref("url", "https://geo.tmp.codrs.ru")
val interval by IntPref("interval", 15)
}
object StatisticsPreferences : Preferences("statistics") {
var totalSent by IntPref("total_sent", 0)
var sessionSent by IntPref("session_sent", 0)
var lastSent by LongPref("last_sent", 0)
}

View File

@ -16,6 +16,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.time.Instant
class LocationForegroundService : Service() {
@ -36,6 +37,12 @@ class LocationForegroundService : Service() {
)
)
}
StatisticsPreferences.apply {
totalSent++
sessionSent++
lastSent = Instant.now().epochSecond
}
}
}

View File

@ -50,6 +50,7 @@ import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
import splitties.experimental.ExperimentalSplittiesApi
import splitties.init.appCtx
import splitties.resources.appStr
import java.time.Instant
class MainActivity : ComponentActivity() {
@ -68,13 +69,29 @@ class MainActivity : ComponentActivity() {
when (screen) {
Screen.Main -> {
var totalSent by remember { mutableIntStateOf(0) }
var sessionSent by remember { mutableIntStateOf(0) }
var lastSent by remember { mutableIntStateOf(0) }
LaunchedEffect(Unit) {
Log.d("Thread", "Starting...")
startLocationService()
StatisticsPreferences.sessionSent = 0
Log.d("Thread", "Started")
while (true) {
totalSent = StatisticsPreferences.totalSent
sessionSent = StatisticsPreferences.sessionSent
lastSent = (Instant.now().epochSecond - StatisticsPreferences.lastSent).toInt()
delay(1000)
}
}
Text("Hello world")
Column(Modifier.align(Alignment.Center)) {
Text("Всего отправлено: $totalSent")
Text("Отправлено за эту сессию: $sessionSent")
Text("В последний раз было отпавлено $lastSent секунд назад")
}
}
Screen.Settings -> {