add checkbox and golemio api
This commit is contained in:
@@ -4,11 +4,28 @@ import android.app.Activity
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.widget.Toast
|
||||
import androidx.compose.ui.semantics.getOrNull
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.OkHttpClient
|
||||
import ovh.plrapps.mapcompose.api.moveMarker
|
||||
import java.net.URL
|
||||
|
||||
@Serializable
|
||||
data class HaukResponse(
|
||||
val type: Int,
|
||||
val expire: Long,
|
||||
val serverTime: Double,
|
||||
val interval: Int,
|
||||
val points: List<List<Double?>>,
|
||||
val encrypted: Boolean,
|
||||
val salt: String? = null
|
||||
)
|
||||
|
||||
private val json = Json {
|
||||
coerceInputValues = true // Coerce nulls to default values if applicable
|
||||
ignoreUnknownKeys = true // Ignore fields in JSON not present in the data class
|
||||
}
|
||||
// OkHttpClient for making HTTP requests
|
||||
val httpClient = OkHttpClient.Builder()
|
||||
.build()
|
||||
@@ -35,17 +52,21 @@ private fun fetchHaukPosition(haukUrl: String, callee: Activity) {
|
||||
}
|
||||
|
||||
message = "{" + message.substringAfter("{");
|
||||
val hauk_response = Json.decodeFromString<HaukResponse>(message)
|
||||
val hauk_response = json.decodeFromString<HaukResponse>(message)
|
||||
|
||||
val lat = hauk_response.points.last()?.getOrNull(0)
|
||||
val lon = hauk_response.points.last()?.getOrNull(1)
|
||||
if (lat != null && lon != null) {
|
||||
HaukMainHandler.post {
|
||||
mapState.moveMarker("target_position", x = longitudeToXNormalized(hauk_response.points.last()[1]), y = latitudeToYNormalized(hauk_response.points.last()[0]))
|
||||
mapState.moveMarker("target_position", x = longitudeToXNormalized(lon), y = latitudeToYNormalized(lat))
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(callee, "TARGET LOCATION NOT AVAILABLE", Toast.LENGTH_SHORT).show()
|
||||
}}
|
||||
} catch (e: Exception) {
|
||||
// Post UI update to main thread
|
||||
HaukMainHandler.post {
|
||||
Toast.makeText(callee, e.message ?: "Unknown error", Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(callee, e.message ?: "Unknown error", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user