feat: add statistics
This commit is contained in:
parent
831b6bf491
commit
4e517b87cd
@ -12,3 +12,9 @@ object SettingsPreferences : Preferences("settings") {
|
|||||||
var url by stringPref("url", "https://geo.tmp.codrs.ru")
|
var url by stringPref("url", "https://geo.tmp.codrs.ru")
|
||||||
val interval by IntPref("interval", 15)
|
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)
|
||||||
|
}
|
@ -16,6 +16,7 @@ import kotlinx.coroutines.CoroutineScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
|
||||||
class LocationForegroundService : Service() {
|
class LocationForegroundService : Service() {
|
||||||
@ -36,6 +37,12 @@ class LocationForegroundService : Service() {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StatisticsPreferences.apply {
|
||||||
|
totalSent++
|
||||||
|
sessionSent++
|
||||||
|
lastSent = Instant.now().epochSecond
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ import ru.risdeveau.geotracker.ui.theme.GeoTrackerTheme
|
|||||||
import splitties.experimental.ExperimentalSplittiesApi
|
import splitties.experimental.ExperimentalSplittiesApi
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import splitties.resources.appStr
|
import splitties.resources.appStr
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@ -68,13 +69,29 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
when (screen) {
|
when (screen) {
|
||||||
Screen.Main -> {
|
Screen.Main -> {
|
||||||
|
var totalSent by remember { mutableIntStateOf(0) }
|
||||||
|
var sessionSent by remember { mutableIntStateOf(0) }
|
||||||
|
var lastSent by remember { mutableIntStateOf(0) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
Log.d("Thread", "Starting...")
|
Log.d("Thread", "Starting...")
|
||||||
startLocationService()
|
startLocationService()
|
||||||
|
StatisticsPreferences.sessionSent = 0
|
||||||
Log.d("Thread", "Started")
|
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 -> {
|
Screen.Settings -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user