all providers
Este commit está contenido en:
3
.idea/.gitignore
generado
vendido
3
.idea/.gitignore
generado
vendido
@@ -1,3 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
6
.idea/AndroidProjectSystem.xml
generado
6
.idea/AndroidProjectSystem.xml
generado
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="AndroidProjectSystem">
|
|
||||||
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/compiler.xml
generado
6
.idea/compiler.xml
generado
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<bytecodeTargetLevel target="21" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
10
.idea/deploymentTargetSelector.xml
generado
10
.idea/deploymentTargetSelector.xml
generado
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="deploymentTargetSelector">
|
|
||||||
<selectionStates>
|
|
||||||
<SelectionState runConfigName="app">
|
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
|
||||||
</SelectionState>
|
|
||||||
</selectionStates>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
19
.idea/gradle.xml
generado
19
.idea/gradle.xml
generado
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
||||||
<component name="GradleSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<GradleProjectSettings>
|
|
||||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
|
||||||
<option name="modules">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
<option value="$PROJECT_DIR$/app" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
50
.idea/inspectionProfiles/Project_Default.xml
generado
50
.idea/inspectionProfiles/Project_Default.xml
generado
@@ -1,50 +0,0 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
|
||||||
<profile version="1.0">
|
|
||||||
<option name="myName" value="Project Default" />
|
|
||||||
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
|
||||||
<option name="composableFile" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
</profile>
|
|
||||||
</component>
|
|
||||||
10
.idea/migrations.xml
generado
10
.idea/migrations.xml
generado
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectMigrations">
|
|
||||||
<option name="MigrateToGradleLocalJavaHome">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
10
.idea/misc.xml
generado
10
.idea/misc.xml
generado
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectType">
|
|
||||||
<option name="id" value="Android" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
17
.idea/runConfigurations.xml
generado
17
.idea/runConfigurations.xml
generado
@@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
|
||||||
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
|
||||||
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
|
||||||
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
|
||||||
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
|
||||||
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
|
||||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
|
||||||
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generado
6
.idea/vcs.xml
generado
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -7,6 +7,16 @@ import kotlinx.coroutines.delay
|
|||||||
|
|
||||||
class LocationService(private val context: Context) {
|
class LocationService(private val context: Context) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Lista de todos los proveedores de ubicación
|
||||||
|
private val ALL_PROVIDERS = listOf(
|
||||||
|
LocationManager.GPS_PROVIDER,
|
||||||
|
LocationManager.NETWORK_PROVIDER,
|
||||||
|
LocationManager.PASSIVE_PROVIDER,
|
||||||
|
"fused" // FUSED_PROVIDER
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simula obtener la última ubicación conocida que Google tendría guardada
|
* Simula obtener la última ubicación conocida que Google tendría guardada
|
||||||
* Devuelve una ubicación predeterminada o la última simulada
|
* Devuelve una ubicación predeterminada o la última simulada
|
||||||
@@ -18,17 +28,25 @@ class LocationService(private val context: Context) {
|
|||||||
// Primero intentar obtener la ubicación simulada guardada
|
// Primero intentar obtener la ubicación simulada guardada
|
||||||
val mockedLocation = getMockedLocation()
|
val mockedLocation = getMockedLocation()
|
||||||
if (mockedLocation != null) {
|
if (mockedLocation != null) {
|
||||||
|
// Sincronizar la ubicación en todos los proveedores para asegurar consistencia
|
||||||
|
mockLocation(mockedLocation.latitude, mockedLocation.longitude)
|
||||||
|
|
||||||
// Actualizar el timestamp para simular que Google la tiene guardada
|
// Actualizar el timestamp para simular que Google la tiene guardada
|
||||||
return mockedLocation.apply {
|
return getMockedLocation()?.apply {
|
||||||
time = System.currentTimeMillis() - (1000 * 60 * 30) // 30 minutos atrás
|
time = System.currentTimeMillis() - (1000 * 60 * 30) // 30 minutos atrás
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si no hay ubicación simulada, devolver una ubicación predeterminada que Google tendría guardada (Madrid)
|
// Si no hay ubicación simulada, establecer y devolver una ubicación predeterminada (Madrid)
|
||||||
return Location(LocationManager.GPS_PROVIDER).apply {
|
val madridLat = 40.4168
|
||||||
latitude = 40.4168
|
val madridLng = -3.7038
|
||||||
longitude = -3.7038
|
|
||||||
time = System.currentTimeMillis() - (1000 * 60 * 60 * 2) // 2 horas atrás
|
// Guardar Madrid como ubicación predeterminada en todos los proveedores
|
||||||
|
mockLocation(madridLat, madridLng)
|
||||||
|
|
||||||
|
// Devolver la ubicación desde el método que prioriza los proveedores
|
||||||
|
return getMockedLocation()?.apply {
|
||||||
|
time = System.currentTimeMillis() - (1000 * 60 * 60 * 2) // 2 horas atrás para simular que es guardada
|
||||||
accuracy = 15.0f // Menos precisión para simular que es una ubicación guardada
|
accuracy = 15.0f // Menos precisión para simular que es una ubicación guardada
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,16 +62,16 @@ class LocationService(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guarda una ubicación simulada
|
* Guarda una ubicación simulada en todos los proveedores
|
||||||
*/
|
*/
|
||||||
suspend fun mockLocation(latitude: Double, longitude: Double): Boolean {
|
suspend fun mockLocation(latitude: Double, longitude: Double): Boolean {
|
||||||
return try {
|
return try {
|
||||||
val preferences = context.getSharedPreferences(LocationManager.GPS_PROVIDER, Context.MODE_PRIVATE)
|
val timestamp = System.currentTimeMillis()
|
||||||
preferences.edit()
|
|
||||||
.putString("latitude", latitude.toString())
|
// Guardar la ubicación en todos los proveedores
|
||||||
.putString("longitude", longitude.toString())
|
ALL_PROVIDERS.forEach { provider ->
|
||||||
.putLong("timestamp", System.currentTimeMillis())
|
saveLocationForProvider(provider, latitude, longitude, timestamp)
|
||||||
.apply()
|
}
|
||||||
|
|
||||||
// Simular un pequeño delay
|
// Simular un pequeño delay
|
||||||
delay(500)
|
delay(500)
|
||||||
@@ -64,76 +82,209 @@ class LocationService(private val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtiene la ubicación simulada guardada
|
* Guarda una ubicación para un proveedor específico
|
||||||
|
*/
|
||||||
|
private fun saveLocationForProvider(provider: String, latitude: Double, longitude: Double, timestamp: Long) {
|
||||||
|
val preferences = context.getSharedPreferences(provider, Context.MODE_PRIVATE)
|
||||||
|
preferences.edit()
|
||||||
|
.putString("latitude", latitude.toString())
|
||||||
|
.putString("longitude", longitude.toString())
|
||||||
|
.putLong("timestamp", timestamp)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene la ubicación simulada guardada desde cualquier proveedor
|
||||||
|
* Prioriza GPS, luego NETWORK, luego FUSED, finalmente PASSIVE
|
||||||
*/
|
*/
|
||||||
fun getMockedLocation(): Location? {
|
fun getMockedLocation(): Location? {
|
||||||
val preferences = context.getSharedPreferences(LocationManager.GPS_PROVIDER, Context.MODE_PRIVATE)
|
val priorityProviders = listOf(
|
||||||
|
LocationManager.GPS_PROVIDER,
|
||||||
|
LocationManager.NETWORK_PROVIDER,
|
||||||
|
"fused",
|
||||||
|
LocationManager.PASSIVE_PROVIDER
|
||||||
|
)
|
||||||
|
|
||||||
|
for (provider in priorityProviders) {
|
||||||
|
val location = getLocationFromProvider(provider)
|
||||||
|
if (location != null) {
|
||||||
|
return location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene la ubicación guardada para un proveedor específico
|
||||||
|
*/
|
||||||
|
private fun getLocationFromProvider(provider: String): Location? {
|
||||||
|
val preferences = context.getSharedPreferences(provider, Context.MODE_PRIVATE)
|
||||||
val latStr = preferences.getString("latitude", null)
|
val latStr = preferences.getString("latitude", null)
|
||||||
val lngStr = preferences.getString("longitude", null)
|
val lngStr = preferences.getString("longitude", null)
|
||||||
|
|
||||||
return if (latStr != null && lngStr != null) {
|
return if (latStr != null && lngStr != null) {
|
||||||
Location(LocationManager.GPS_PROVIDER).apply {
|
Location(provider).apply {
|
||||||
latitude = latStr.toDouble()
|
latitude = latStr.toDouble()
|
||||||
longitude = lngStr.toDouble()
|
longitude = lngStr.toDouble()
|
||||||
time = preferences.getLong("timestamp", System.currentTimeMillis())
|
time = preferences.getLong("timestamp", System.currentTimeMillis())
|
||||||
accuracy = 5.0f // Simular buena precisión
|
accuracy = when (provider) {
|
||||||
|
LocationManager.GPS_PROVIDER -> 5.0f
|
||||||
|
LocationManager.NETWORK_PROVIDER -> 20.0f
|
||||||
|
"fused" -> 8.0f
|
||||||
|
LocationManager.PASSIVE_PROVIDER -> 15.0f
|
||||||
|
else -> 10.0f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Genera ubicaciones aleatorias cercanas a una ubicación base
|
* Obtiene la ubicación simulada para un proveedor específico
|
||||||
*/
|
*/
|
||||||
fun generateRandomNearbyLocation(baseLatitude: Double, baseLongitude: Double, radiusKm: Double = 1.0): Location {
|
fun getMockedLocationForProvider(provider: String): Location? {
|
||||||
|
return getLocationFromProvider(provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene todas las ubicaciones simuladas por proveedor
|
||||||
|
*/
|
||||||
|
fun getAllMockedLocations(): Map<String, Location?> {
|
||||||
|
return ALL_PROVIDERS.associateWith { provider ->
|
||||||
|
getLocationFromProvider(provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sincroniza la última ubicación conocida en todos los proveedores
|
||||||
|
*/
|
||||||
|
suspend fun syncLocationAcrossProviders(): Boolean {
|
||||||
|
val lastLocation = getMockedLocation()
|
||||||
|
return if (lastLocation != null) {
|
||||||
|
mockLocation(lastLocation.latitude, lastLocation.longitude)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene la lista de ciudades populares disponibles
|
||||||
|
*/
|
||||||
|
fun getAvailablePopularCities(): List<String> {
|
||||||
|
return listOf("Madrid", "Barcelona", "Valencia", "Sevilla", "Bilbao")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene las ubicaciones populares como lista de pares (nombre, Location)
|
||||||
|
*/
|
||||||
|
fun getPopularLocations(): List<Pair<String, Location>> {
|
||||||
|
val popularLocations = mapOf(
|
||||||
|
"Madrid" to Pair(40.4168, -3.7038),
|
||||||
|
"Barcelona" to Pair(41.3851, 2.1734),
|
||||||
|
"Valencia" to Pair(39.4699, -0.3763),
|
||||||
|
"Sevilla" to Pair(37.3886, -5.9823),
|
||||||
|
"Bilbao" to Pair(43.2627, -2.9253)
|
||||||
|
)
|
||||||
|
|
||||||
|
return popularLocations.map { (name, coordinates) ->
|
||||||
|
val location = Location(LocationManager.GPS_PROVIDER).apply {
|
||||||
|
latitude = coordinates.first
|
||||||
|
longitude = coordinates.second
|
||||||
|
time = System.currentTimeMillis()
|
||||||
|
accuracy = 5.0f
|
||||||
|
}
|
||||||
|
Pair(name, location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Genera una ubicación aleatoria cercana a una ubicación base y la guarda en todos los proveedores
|
||||||
|
*/
|
||||||
|
suspend fun generateRandomNearbyLocation(baseLatitude: Double, baseLongitude: Double, radiusKm: Double = 1.0): Location {
|
||||||
val random = kotlin.random.Random
|
val random = kotlin.random.Random
|
||||||
|
|
||||||
// Generar offset aleatorio dentro del radio especificado
|
// Generar offset aleatorio dentro del radio especificado
|
||||||
val offsetLat = (random.nextDouble() - 0.5) * 2 * (radiusKm / 111.0) // 1 grado lat ≈ 111 km
|
val offsetLat = (random.nextDouble() - 0.5) * 2 * (radiusKm / 111.0) // 1 grado lat ≈ 111 km
|
||||||
val offsetLng = (random.nextDouble() - 0.5) * 2 * (radiusKm / (111.0 * kotlin.math.cos(Math.toRadians(baseLatitude))))
|
val offsetLng = (random.nextDouble() - 0.5) * 2 * (radiusKm / (111.0 * kotlin.math.cos(Math.toRadians(baseLatitude))))
|
||||||
|
|
||||||
|
val newLatitude = baseLatitude + offsetLat
|
||||||
|
val newLongitude = baseLongitude + offsetLng
|
||||||
|
|
||||||
|
// Crear la ubicación aleatoria
|
||||||
return Location(LocationManager.GPS_PROVIDER).apply {
|
return Location(LocationManager.GPS_PROVIDER).apply {
|
||||||
latitude = baseLatitude + offsetLat
|
latitude = newLatitude
|
||||||
longitude = baseLongitude + offsetLng
|
longitude = newLongitude
|
||||||
time = System.currentTimeMillis()
|
time = System.currentTimeMillis()
|
||||||
accuracy = random.nextFloat() * 20 + 5 // Precisión entre 5-25 metros
|
accuracy = 5.0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtiene ubicaciones predefinidas populares en España
|
* Verifica que una ubicación esté guardada en todos los proveedores
|
||||||
*/
|
*/
|
||||||
fun getPopularLocations(): List<Pair<String, Location>> {
|
fun verifyLocationInAllProviders(): Map<String, Boolean> {
|
||||||
return listOf(
|
return ALL_PROVIDERS.associateWith { provider ->
|
||||||
"Madrid" to Location(LocationManager.GPS_PROVIDER).apply {
|
getLocationFromProvider(provider) != null
|
||||||
latitude = 40.4168
|
}
|
||||||
longitude = -3.7038
|
}
|
||||||
time = System.currentTimeMillis()
|
|
||||||
accuracy = 10.0f
|
/**
|
||||||
},
|
* Obtiene información detallada de todos los proveedores
|
||||||
"Barcelona" to Location(LocationManager.GPS_PROVIDER).apply {
|
*/
|
||||||
latitude = 41.3851
|
fun getProvidersDebugInfo(): Map<String, String> {
|
||||||
longitude = 2.1734
|
return ALL_PROVIDERS.associateWith { provider ->
|
||||||
time = System.currentTimeMillis()
|
val location = getLocationFromProvider(provider)
|
||||||
accuracy = 10.0f
|
if (location != null) {
|
||||||
},
|
"Lat: ${location.latitude}, Lng: ${location.longitude}, Time: ${location.time}, Accuracy: ${location.accuracy}"
|
||||||
"Valencia" to Location(LocationManager.GPS_PROVIDER).apply {
|
} else {
|
||||||
latitude = 39.4699
|
"No location stored"
|
||||||
longitude = -0.3763
|
|
||||||
time = System.currentTimeMillis()
|
|
||||||
accuracy = 10.0f
|
|
||||||
},
|
|
||||||
"Sevilla" to Location(LocationManager.GPS_PROVIDER).apply {
|
|
||||||
latitude = 37.3886
|
|
||||||
longitude = -5.9823
|
|
||||||
time = System.currentTimeMillis()
|
|
||||||
accuracy = 10.0f
|
|
||||||
},
|
|
||||||
"Bilbao" to Location(LocationManager.GPS_PROVIDER).apply {
|
|
||||||
latitude = 43.2627
|
|
||||||
longitude = -2.9253
|
|
||||||
time = System.currentTimeMillis()
|
|
||||||
accuracy = 10.0f
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Establece una ubicación popular en España y la guarda en todos los proveedores
|
||||||
|
*/
|
||||||
|
suspend fun setPopularLocation(cityName: String): Boolean {
|
||||||
|
val popularLocations = mapOf(
|
||||||
|
"Madrid" to Pair(40.4168, -3.7038),
|
||||||
|
"Barcelona" to Pair(41.3851, 2.1734),
|
||||||
|
"Valencia" to Pair(39.4699, -0.3763),
|
||||||
|
"Sevilla" to Pair(37.3886, -5.9823),
|
||||||
|
"Bilbao" to Pair(43.2627, -2.9253)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val coordinates = popularLocations[cityName]
|
||||||
|
return if (coordinates != null) {
|
||||||
|
mockLocation(coordinates.first, coordinates.second)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtiene la ubicación actual configurada como objeto Location para una ciudad específica
|
||||||
|
*/
|
||||||
|
suspend fun getPopularLocationAsLocation(cityName: String): Location? {
|
||||||
|
val popularLocations = mapOf(
|
||||||
|
"Madrid" to Pair(40.4168, -3.7038),
|
||||||
|
"Barcelona" to Pair(41.3851, 2.1734),
|
||||||
|
"Valencia" to Pair(39.4699, -0.3763),
|
||||||
|
"Sevilla" to Pair(37.3886, -5.9823),
|
||||||
|
"Bilbao" to Pair(43.2627, -2.9253)
|
||||||
|
)
|
||||||
|
|
||||||
|
val coordinates = popularLocations[cityName]
|
||||||
|
return if (coordinates != null) {
|
||||||
|
// Establecer la ubicación en todos los proveedores
|
||||||
|
if (mockLocation(coordinates.first, coordinates.second)) {
|
||||||
|
// Devolver la ubicación desde el método que prioriza los proveedores
|
||||||
|
getMockedLocation()
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,15 +141,21 @@ class LocationViewModel(private val locationService: LocationService) : ViewMode
|
|||||||
2.0 // Radio de 2 km
|
2.0 // Radio de 2 km
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Guardar la ubicación aleatoria en todos los proveedores
|
||||||
val success = locationService.mockLocation(randomLocation.latitude, randomLocation.longitude)
|
val success = locationService.mockLocation(randomLocation.latitude, randomLocation.longitude)
|
||||||
if (success) {
|
if (success) {
|
||||||
val mockedLocation = locationService.getMockedLocation()
|
val mockedLocation = locationService.getMockedLocation()
|
||||||
_uiState.value = _uiState.value.copy(
|
_uiState.value = _uiState.value.copy(
|
||||||
mockedLocation = mockedLocation,
|
mockedLocation = mockedLocation,
|
||||||
currentLocation = randomLocation,
|
currentLocation = mockedLocation, // Usar la ubicación desde el proveedor prioritario
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
error = null
|
error = null
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
_uiState.value = _uiState.value.copy(
|
||||||
|
isLoading = false,
|
||||||
|
error = "Error al guardar ubicación aleatoria"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value = _uiState.value.copy(
|
_uiState.value = _uiState.value.copy(
|
||||||
|
|||||||
Archivo binario no mostrado.
|
Antes Anchura: | Altura: | Tamaño: 1.4 KiB |
Referencia en una nueva incidencia
Block a user