1
0

Compare commits

..

No commits in common. "4d86cd06309601c9ea7e565d5ad670a4952d4ad0" and "a3ff36ba67a6d81099abc914c601787f3c34f63d" have entirely different histories.

5 changed files with 17 additions and 62 deletions

View File

@ -17,8 +17,8 @@ android {
applicationId = "ru.risdeveau.geotracker"
minSdk = 24
targetSdk = 35
versionCode = 2
versionName = "1.1"
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -48,11 +48,11 @@ suspend fun health(baseurl: String): Boolean {
suspend fun sendGeo(baseurl: String = SettingsPreferences.url, data: GeoData): Boolean {
try {
val json = JSONObject()
json.put("lon", data.ln)
json.put("lat", data.lt)
json.put("user_name", data.nick)
json.put("ln", data.ln)
json.put("lt", data.lt)
json.put("nick", data.nick)
client.post("$baseurl/api/app") {
client.post("$baseurl/map") {
contentType(ContentType.Application.Json)
setBody(json.toString(2))
}

View File

@ -8,7 +8,6 @@ package ru.risdeveau.geotracker
import splitties.preferences.Preferences
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)
var username by stringPref("username", "anonimous")
var url by stringPref("url", "https://example.com")
}

View File

@ -5,7 +5,6 @@ import android.Manifest.permission.POST_NOTIFICATIONS
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Intent
import android.os.Build
@ -42,14 +41,12 @@ class LocationForegroundService : Service() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d("Service", "onStartCommand")
if (
!(hasPermission(ACCESS_FINE_LOCATION)
if (!(hasPermission(ACCESS_FINE_LOCATION)
&& (
(Build.VERSION.SDK_INT < 33)
|| hasPermission(POST_NOTIFICATIONS)
))
|| intent?.action == ACTION_STOP_SERVICE
) {
)
)) {
stopSelf()
return START_NOT_STICKY
}
@ -58,12 +55,11 @@ class LocationForegroundService : Service() {
val notification = createNotification()
startForeground(1, notification)
locationTracker.startTracking(SettingsPreferences.interval * 1000L)
locationTracker.startTracking(5000)
return START_STICKY
}
override fun onDestroy() {
Log.d("Service", "Destroyed")
locationTracker.stopTracking()
super.onDestroy()
}
@ -73,8 +69,8 @@ class LocationForegroundService : Service() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"location_channel",
"Отправка Местоположения",
NotificationManager.IMPORTANCE_HIGH
"Location Tracking",
NotificationManager.IMPORTANCE_LOW
)
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
manager.createNotificationChannel(channel)
@ -82,36 +78,12 @@ class LocationForegroundService : Service() {
}
private fun createNotification(): Notification {
val stopIntent = Intent(this, LocationForegroundService::class.java).apply {
action = ACTION_STOP_SERVICE
}
val stopPendingIntent = PendingIntent.getService(
this,
0,
stopIntent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
else
PendingIntent.FLAG_UPDATE_CURRENT
)
return NotificationCompat.Builder(this, "location_channel")
.setContentTitle("Отслеживание местоположения")
.setContentText("Обновление каждые ${SettingsPreferences.interval} секунд")
.setSmallIcon(R.drawable.share_location)
.addAction(
R.drawable.cancel,
"Остановить",
stopPendingIntent
)
.setOngoing(true)
.setContentText("Обновление каждые 5 секунд")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.build()
}
override fun onBind(intent: Intent?): IBinder? = null
companion object {
const val ACTION_STOP_SERVICE = "ru.risdeveau.geotracker.STOP_SERVICE"
}
}
}

View File

@ -21,7 +21,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Done
import androidx.compose.material3.Button
@ -34,7 +33,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@ -42,7 +40,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.core.content.ContextCompat
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
@ -92,7 +89,6 @@ class MainActivity : ComponentActivity() {
launch {
screen = if (
health(SettingsPreferences.url)
&& SettingsPreferences.username.isNotBlank()
&& hasPermission(ACCESS_FINE_LOCATION)
&& (
(Build.VERSION.SDK_INT < 33)
@ -125,7 +121,6 @@ sealed class Screen {
fun Settings(modifier: Modifier = Modifier, onConfirm: () -> Unit) {
var username by remember { mutableStateOf(SettingsPreferences.username) }
var url by remember { mutableStateOf(SettingsPreferences.url) }
var interval by remember { mutableIntStateOf(SettingsPreferences.interval) }
var urlIsValid by remember { mutableStateOf(false) }
var loading by remember { mutableStateOf(false) }
var fineLoc by remember { mutableStateOf(hasPermission(ACCESS_FINE_LOCATION)) }
@ -167,17 +162,6 @@ 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; }
if (Build.VERSION.SDK_INT >= 33)