diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b39e62eda..28de2db69 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -85,7 +85,7 @@ dependencies { implementation("com.github.kylecorry31:sol:5.6.0") // Andromeda - val andromedaVersion = "2.7.0-beta01" + val andromedaVersion = "2.7.0" implementation("com.github.kylecorry31.andromeda:core:$andromedaVersion") implementation("com.github.kylecorry31.andromeda:fragments:$andromedaVersion") implementation("com.github.kylecorry31.andromeda:forms:$andromedaVersion") diff --git a/app/src/main/java/com/kylecorry/trail_sense/MainActivity.kt b/app/src/main/java/com/kylecorry/trail_sense/MainActivity.kt index e906d5fed..9a40f4314 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/MainActivity.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/MainActivity.kt @@ -20,6 +20,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView import com.kylecorry.andromeda.alerts.Alerts import com.kylecorry.andromeda.alerts.dialog import com.kylecorry.andromeda.core.system.Exceptions +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.system.Package import com.kylecorry.andromeda.core.system.Screen import com.kylecorry.andromeda.core.tryOrNothing @@ -36,7 +37,6 @@ import com.kylecorry.trail_sense.shared.CustomUiUtils import com.kylecorry.trail_sense.shared.ExceptionUtils import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.sensors.SensorService -import com.kylecorry.trail_sense.shared.uri.GeoUri import com.kylecorry.trail_sense.shared.views.ErrorBannerView import com.kylecorry.trail_sense.tools.clinometer.ui.ClinometerFragment import com.kylecorry.trail_sense.tools.flashlight.ui.FragmentToolFlashlight diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/infrastructure/share/BeaconUriEncoder.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/infrastructure/share/BeaconUriEncoder.kt index 871494922..10ff53dec 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/infrastructure/share/BeaconUriEncoder.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/infrastructure/share/BeaconUriEncoder.kt @@ -1,9 +1,10 @@ package com.kylecorry.trail_sense.navigation.beacons.infrastructure.share import android.net.Uri +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.trail_sense.navigation.beacons.domain.Beacon import com.kylecorry.trail_sense.shared.colors.AppColor -import com.kylecorry.trail_sense.shared.uri.GeoUri +import com.kylecorry.trail_sense.shared.from import com.kylecorry.trail_sense.shared.uri.IUriEncoder class BeaconUriEncoder : IUriEncoder { diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/BeaconListFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/BeaconListFragment.kt index c087d9783..b82261d3b 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/BeaconListFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/BeaconListFragment.kt @@ -15,6 +15,7 @@ import androidx.navigation.fragment.findNavController import com.kylecorry.andromeda.alerts.Alerts import com.kylecorry.andromeda.camera.Camera import com.kylecorry.andromeda.core.filterIndices +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.time.Timer import com.kylecorry.andromeda.fragments.BoundFragment import com.kylecorry.andromeda.gpx.GPXData @@ -31,13 +32,9 @@ import com.kylecorry.trail_sense.navigation.beacons.infrastructure.export.Beacon import com.kylecorry.trail_sense.navigation.beacons.infrastructure.export.BeaconGpxImporter import com.kylecorry.trail_sense.navigation.beacons.infrastructure.persistence.BeaconGroupEntity import com.kylecorry.trail_sense.navigation.beacons.infrastructure.persistence.BeaconRepo -import com.kylecorry.trail_sense.shared.CustomUiUtils -import com.kylecorry.trail_sense.shared.FormatService -import com.kylecorry.trail_sense.shared.UserPreferences -import com.kylecorry.trail_sense.shared.alertNoCameraPermission +import com.kylecorry.trail_sense.shared.* import com.kylecorry.trail_sense.shared.io.IOFactory import com.kylecorry.trail_sense.shared.sensors.SensorService -import com.kylecorry.trail_sense.shared.uri.GeoUri import com.kylecorry.trail_sense.tools.qr.infrastructure.BeaconQREncoder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/PlaceBeaconFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/PlaceBeaconFragment.kt index 87f081f28..1f2c457f0 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/PlaceBeaconFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/beacons/ui/PlaceBeaconFragment.kt @@ -12,6 +12,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import com.kylecorry.andromeda.core.capitalizeWords +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.fragments.BoundFragment import com.kylecorry.sol.math.SolMath.roundPlaces import com.kylecorry.sol.science.geology.GeologyService @@ -31,7 +32,6 @@ import com.kylecorry.trail_sense.shared.FormatService import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.colors.AppColor import com.kylecorry.trail_sense.shared.sensors.SensorService -import com.kylecorry.trail_sense.shared.uri.GeoUri import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreateBeaconFromPointCommand.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreateBeaconFromPointCommand.kt index 6c6067c1e..1db08dbdf 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreateBeaconFromPointCommand.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/ui/commands/CreateBeaconFromPointCommand.kt @@ -1,12 +1,12 @@ package com.kylecorry.trail_sense.navigation.paths.ui.commands import android.content.Context +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.sol.math.SolMath.roundPlaces import com.kylecorry.trail_sense.R import com.kylecorry.trail_sense.navigation.paths.domain.Path import com.kylecorry.trail_sense.navigation.paths.domain.PathPoint import com.kylecorry.trail_sense.shared.AppUtils -import com.kylecorry.trail_sense.shared.uri.GeoUri class CreateBeaconFromPointCommand(private val context: Context) : IPathPointCommand { diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt index 04b6c9f4c..886c46124 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/NavigatorFragment.kt @@ -17,6 +17,7 @@ import com.kylecorry.andromeda.camera.Camera import com.kylecorry.andromeda.core.coroutines.ControlledRunner import com.kylecorry.andromeda.core.sensors.Quality import com.kylecorry.andromeda.core.sensors.asLiveData +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.system.Resources import com.kylecorry.andromeda.core.system.Screen import com.kylecorry.andromeda.core.time.Throttle @@ -60,7 +61,6 @@ import com.kylecorry.trail_sense.shared.sensors.CustomGPS import com.kylecorry.trail_sense.shared.sensors.SensorService import com.kylecorry.trail_sense.shared.sensors.overrides.CachedGPS import com.kylecorry.trail_sense.shared.sensors.overrides.OverrideGPS -import com.kylecorry.trail_sense.shared.uri.GeoUri import com.kylecorry.trail_sense.shared.views.UserError import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/AppUtils.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/AppUtils.kt index 4e3435f96..5996ad454 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/AppUtils.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/AppUtils.kt @@ -2,8 +2,8 @@ package com.kylecorry.trail_sense.shared import android.content.Context import androidx.core.content.ContextCompat +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.system.Intents -import com.kylecorry.trail_sense.shared.uri.GeoUri object AppUtils { diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt index bf103a7a6..f534b6c65 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt @@ -4,11 +4,14 @@ import android.widget.SeekBar import androidx.fragment.app.Fragment import com.google.android.material.bottomnavigation.BottomNavigationView import com.kylecorry.andromeda.alerts.Alerts +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.units.PixelCoordinate import com.kylecorry.andromeda.location.IGPS +import com.kylecorry.sol.math.SolMath.roundPlaces import com.kylecorry.sol.math.Vector2 import com.kylecorry.trail_sense.MainActivity import com.kylecorry.trail_sense.R +import com.kylecorry.trail_sense.navigation.beacons.domain.Beacon import com.kylecorry.trail_sense.navigation.paths.domain.PathPoint import com.kylecorry.trail_sense.shared.database.Identifiable @@ -67,4 +70,15 @@ fun SeekBar.setOnProgressChangeListener(listener: (progress: Int, fromUser: Bool } }) +} + +fun GeoUri.Companion.from(beacon: Beacon): GeoUri { + val params = mutableMapOf( + "label" to beacon.name + ) + if (beacon.elevation != null) { + params["ele"] = beacon.elevation.roundPlaces(2).toString() + } + + return GeoUri(beacon.coordinate, null, params) } \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/uri/GeoUri.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/uri/GeoUri.kt deleted file mode 100644 index 342b6c55e..000000000 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/uri/GeoUri.kt +++ /dev/null @@ -1,81 +0,0 @@ -package com.kylecorry.trail_sense.shared.uri - -import android.net.Uri -import android.os.Parcelable -import com.kylecorry.sol.math.SolMath.roundPlaces -import com.kylecorry.sol.units.Coordinate -import com.kylecorry.trail_sense.navigation.beacons.domain.Beacon -import kotlinx.parcelize.Parcelize - -@Parcelize -data class GeoUri( - val coordinate: Coordinate, - val altitude: Float? = null, - val queryParameters: Map = mapOf() -) : Parcelable { - - val uri: Uri = Uri.parse(toString()) - - override fun toString(): String { - val base = "geo:${coordinate.latitude.roundPlaces(6)},${coordinate.longitude.roundPlaces(6)}" - val elevation = if (altitude != null) ",${altitude.roundPlaces(2)}" else "" - val query = if (queryParameters.isEmpty()) { - "" - } else { - "?" + queryParameters.entries.joinToString("&") { - Uri.encode(it.key) + "=" + Uri.encode( - it.value - ) - } - } - - return base + elevation + query - } - - companion object { - - fun from(uri: Uri): GeoUri? { - return parse(uri.toString()) - } - - fun from(beacon: Beacon): GeoUri { - val params = mutableMapOf( - "label" to beacon.name - ) - if (beacon.elevation != null) { - params["ele"] = beacon.elevation.roundPlaces(2).toString() - } - - return GeoUri(beacon.coordinate, null, params) - } - - fun parse(uriString: String): GeoUri? { - val pattern = - "geo:(-?[0-9]*\\.?[0-9]+),(-?[0-9]*\\.?[0-9]+)(?:,(-?[0-9]*\\.?[0-9]+))?(?:\\?(.*))?" - val regex = Regex(pattern) - - val matches = regex.find(uriString) - - if (matches != null) { - val lat = matches.groupValues[1].toDouble() - val lng = matches.groupValues[2].toDouble() - val altitude = matches.groupValues[3].toFloatOrNull() - val query = - matches.groupValues[4].split("&").map { it.split("=").map { Uri.decode(it) } } - - val pairs = query.mapNotNull { - if (it.size == 2) { - it[0] to it[1] - } else { - null - } - } - - return GeoUri(Coordinate(lat, lng), altitude, pairs.toMap()) - } - - return null - } - } - -} \ No newline at end of file diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/uri/LocationUriEncoder.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/uri/LocationUriEncoder.kt index e226a57b7..592b5cf90 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/uri/LocationUriEncoder.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/uri/LocationUriEncoder.kt @@ -1,6 +1,7 @@ package com.kylecorry.trail_sense.shared.uri import android.net.Uri +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.sol.units.Coordinate class LocationUriEncoder : IUriEncoder { diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/maps/ui/ViewMapFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/maps/ui/ViewMapFragment.kt index 9c1a1ac2a..b775cfc8b 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/maps/ui/ViewMapFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/maps/ui/ViewMapFragment.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import com.kylecorry.andromeda.alerts.Alerts import com.kylecorry.andromeda.core.sensors.asLiveData +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.time.Throttle import com.kylecorry.andromeda.fragments.BoundFragment import com.kylecorry.andromeda.preferences.Preferences @@ -30,7 +31,6 @@ import com.kylecorry.trail_sense.shared.FormatService import com.kylecorry.trail_sense.shared.Position import com.kylecorry.trail_sense.shared.getPathPoint import com.kylecorry.trail_sense.shared.sensors.SensorService -import com.kylecorry.trail_sense.shared.uri.GeoUri import com.kylecorry.trail_sense.tools.maps.domain.Map import com.kylecorry.trail_sense.tools.maps.domain.MapCalibrationPoint import com.kylecorry.trail_sense.tools.maps.domain.PercentCoordinate diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/qr/ui/ScanQRFragment.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/qr/ui/ScanQRFragment.kt index 830e6c91b..091f6437a 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/qr/ui/ScanQRFragment.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/qr/ui/ScanQRFragment.kt @@ -16,7 +16,7 @@ import com.kylecorry.andromeda.buzz.HapticFeedbackType import com.kylecorry.andromeda.camera.Camera import com.kylecorry.andromeda.clipboard.Clipboard import com.kylecorry.andromeda.core.bitmap.BitmapUtils.toBitmap -import com.kylecorry.andromeda.core.system.GeoUriParser +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.core.system.Intents import com.kylecorry.andromeda.core.tryOrNothing import com.kylecorry.andromeda.fragments.BoundFragment @@ -282,7 +282,7 @@ class ScanQRFragment : BoundFragment() { } private fun isLocation(text: String): Boolean { - return GeoUriParser.parse(Uri.parse(text)) != null + return GeoUri.from(Uri.parse(text)) != null } private fun isURL(text: String): Boolean { diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/triangulate/ui/FragmentToolTriangulate.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/triangulate/ui/FragmentToolTriangulate.kt index 4ea528f94..f9e6ebee9 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/triangulate/ui/FragmentToolTriangulate.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/triangulate/ui/FragmentToolTriangulate.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import androidx.core.view.isVisible import com.kylecorry.andromeda.alerts.Alerts import com.kylecorry.andromeda.clipboard.Clipboard +import com.kylecorry.andromeda.core.system.GeoUri import com.kylecorry.andromeda.fragments.BoundFragment import com.kylecorry.sol.science.geology.GeologyService import com.kylecorry.sol.units.Bearing @@ -17,7 +18,6 @@ import com.kylecorry.trail_sense.shared.AppUtils import com.kylecorry.trail_sense.shared.FormatService import com.kylecorry.trail_sense.shared.UserPreferences import com.kylecorry.trail_sense.shared.sensors.SensorService -import com.kylecorry.trail_sense.shared.uri.GeoUri class FragmentToolTriangulate : BoundFragment() { diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 528257fde..07e243686 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -392,7 +392,7 @@ + app:argType="com.kylecorry.andromeda.core.system.GeoUri" /> + app:argType="com.kylecorry.andromeda.core.system.GeoUri" />