feat: add setting sending interval
This commit is contained in:
parent
d6f352be29
commit
7bee8910ec
@ -10,4 +10,5 @@ import splitties.preferences.Preferences
|
|||||||
object SettingsPreferences : Preferences("settings") {
|
object SettingsPreferences : Preferences("settings") {
|
||||||
var username by stringPref("username", "")
|
var username by stringPref("username", "")
|
||||||
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)
|
||||||
}
|
}
|
@ -55,7 +55,7 @@ class LocationForegroundService : Service() {
|
|||||||
val notification = createNotification()
|
val notification = createNotification()
|
||||||
startForeground(1, notification)
|
startForeground(1, notification)
|
||||||
|
|
||||||
locationTracker.startTracking(5000)
|
locationTracker.startTracking(SettingsPreferences.interval * 1000L)
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class LocationForegroundService : Service() {
|
|||||||
private fun createNotification(): Notification {
|
private fun createNotification(): Notification {
|
||||||
return NotificationCompat.Builder(this, "location_channel")
|
return NotificationCompat.Builder(this, "location_channel")
|
||||||
.setContentTitle("Отслеживание местоположения")
|
.setContentTitle("Отслеживание местоположения")
|
||||||
.setContentText("Обновление каждые 5 секунд")
|
.setContentText("Обновление каждые ${SettingsPreferences.interval} секунд")
|
||||||
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
.setSmallIcon(R.drawable.ic_launcher_foreground)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Done
|
import androidx.compose.material.icons.outlined.Done
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
@ -33,6 +34,7 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@ -40,6 +42,7 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -122,6 +125,7 @@ sealed class Screen {
|
|||||||
fun Settings(modifier: Modifier = Modifier, onConfirm: () -> Unit) {
|
fun Settings(modifier: Modifier = Modifier, onConfirm: () -> Unit) {
|
||||||
var username by remember { mutableStateOf(SettingsPreferences.username) }
|
var username by remember { mutableStateOf(SettingsPreferences.username) }
|
||||||
var url by remember { mutableStateOf(SettingsPreferences.url) }
|
var url by remember { mutableStateOf(SettingsPreferences.url) }
|
||||||
|
var interval by remember { mutableIntStateOf(SettingsPreferences.interval) }
|
||||||
var urlIsValid by remember { mutableStateOf(false) }
|
var urlIsValid by remember { mutableStateOf(false) }
|
||||||
var loading by remember { mutableStateOf(false) }
|
var loading by remember { mutableStateOf(false) }
|
||||||
var fineLoc by remember { mutableStateOf(hasPermission(ACCESS_FINE_LOCATION)) }
|
var fineLoc by remember { mutableStateOf(hasPermission(ACCESS_FINE_LOCATION)) }
|
||||||
@ -163,6 +167,17 @@ fun Settings(modifier: Modifier = Modifier, onConfirm: () -> Unit) {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
value = interval.toString(),
|
||||||
|
onValueChange = {
|
||||||
|
val newVal = it.toIntOrNull()
|
||||||
|
if (newVal != null)
|
||||||
|
interval = newVal.coerceIn(1..300)
|
||||||
|
},
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||||
|
label = { Text("Интервал отправки") }
|
||||||
|
)
|
||||||
|
|
||||||
GetPermission(ACCESS_FINE_LOCATION) { fineLoc = true; }
|
GetPermission(ACCESS_FINE_LOCATION) { fineLoc = true; }
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 33)
|
if (Build.VERSION.SDK_INT >= 33)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user