diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/infrastructure/Navigator.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/infrastructure/Navigator.kt index 97a9c8a2a..0af35d977 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/infrastructure/Navigator.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/infrastructure/Navigator.kt @@ -29,8 +29,8 @@ class Navigator private constructor(context: Context) { val destination = destinationId.map { it?.let { service.getBeacon(it) } } - fun navigateTo(location: Coordinate, owner: BeaconOwner = BeaconOwner.User) { - val beacon = Beacon.temporary(location, visible = false, owner = owner) + fun navigateTo(location: Coordinate, name: String = "", owner: BeaconOwner = BeaconOwner.User) { + val beacon = Beacon.temporary(location, name = name, visible = false, owner = owner) CoroutineScope(Dispatchers.IO).launch { val id = service.add(beacon) navigateTo(id) diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/LocationBottomSheet.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/LocationBottomSheet.kt index 7aa000b65..43d0e2111 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/LocationBottomSheet.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/ui/LocationBottomSheet.kt @@ -71,25 +71,12 @@ class LocationBottomSheet : BoundBottomSheetDialogFragment - locationSenders[it]?.send(location, format) - } - } - } + gps?.location ?: return@setOnClickListener, + format + ) } } 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 d15fcf724..50f8a7640 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 @@ -68,6 +68,7 @@ import com.kylecorry.trail_sense.shared.permissions.alertNoCameraPermission import com.kylecorry.trail_sense.shared.permissions.requestCamera import com.kylecorry.trail_sense.shared.preferences.PreferencesSubsystem import com.kylecorry.trail_sense.shared.sensors.SensorService +import com.kylecorry.trail_sense.shared.sharing.Share import com.kylecorry.trail_sense.tools.maps.infrastructure.layers.ILayerManager import com.kylecorry.trail_sense.tools.maps.infrastructure.layers.MultiLayerManager import com.kylecorry.trail_sense.tools.maps.infrastructure.layers.MyAccuracyLayerManager @@ -284,16 +285,10 @@ class NavigatorFragment : BoundFragment() { observe(speedometer) { } binding.navigationTitle.subtitle.setOnLongClickListener { - // TODO: Show custom share sheet instead - Pickers.menu(it, R.menu.location_share_menu) { menuItem -> - val sender = when (menuItem) { - R.id.action_send -> LocationSharesheet(requireContext()) - R.id.action_maps -> LocationGeoSender(requireContext()) - else -> LocationCopy(requireContext()) - } - sender.send(gps.location) - true - } + Share.shareLocation( + this, + gps.location + ) true } diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/sharing/Share.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/sharing/Share.kt index a9d62fd24..a89242e9c 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/sharing/Share.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/sharing/Share.kt @@ -1,11 +1,42 @@ package com.kylecorry.trail_sense.shared.sharing import androidx.fragment.app.Fragment +import com.kylecorry.andromeda.core.units.CoordinateFormat import com.kylecorry.andromeda.fragments.show +import com.kylecorry.sol.units.Coordinate import com.kylecorry.trail_sense.R +import com.kylecorry.trail_sense.navigation.infrastructure.share.LocationCopy +import com.kylecorry.trail_sense.navigation.infrastructure.share.LocationGeoSender +import com.kylecorry.trail_sense.navigation.infrastructure.share.LocationQRSender +import com.kylecorry.trail_sense.navigation.infrastructure.share.LocationSharesheet +import com.kylecorry.trail_sense.shared.UserPreferences object Share { + fun shareLocation( + fragment: Fragment, + location: Coordinate, + format: CoordinateFormat = UserPreferences(fragment.requireContext()).navigation.coordinateFormat, + title: String = fragment.getString(R.string.location) + ) { + val locationSenders = mapOf( + ShareAction.Copy to LocationCopy(fragment.requireContext()), + ShareAction.QR to LocationQRSender(fragment), + ShareAction.Maps to LocationGeoSender(fragment.requireContext()), + ShareAction.Send to LocationSharesheet(fragment.requireContext()) + ) + + share( + fragment, + title, + listOf(ShareAction.Copy, ShareAction.QR, ShareAction.Send, ShareAction.Maps) + ) { + it?.let { + locationSenders[it]?.send(location, format) + } + } + } + fun share( fragment: Fragment, title: String, 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 6defea1cd..684a25993 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 @@ -47,6 +47,7 @@ import com.kylecorry.trail_sense.shared.extensions.from import com.kylecorry.trail_sense.shared.extensions.onIO import com.kylecorry.trail_sense.shared.navigation.NavControllerAppNavigation import com.kylecorry.trail_sense.shared.preferences.PreferencesSubsystem +import com.kylecorry.trail_sense.shared.sharing.Share class FragmentToolTriangulate : BoundFragment() { @@ -106,11 +107,15 @@ class FragmentToolTriangulate : BoundFragment() } binding.navigate.setOnClickListener { - inBackground { - location?.let { - navigator.navigateTo(it, BeaconOwner.Triangulate) - appNavigation.navigate(R.id.action_navigation) - } + location?.let { + navigator.navigateTo(it, getString(R.string.location), BeaconOwner.Triangulate) + appNavigation.navigate(R.id.action_navigation) + } + } + + binding.shareLocation.setOnClickListener { + location?.let { + Share.shareLocation(this, it) } } diff --git a/app/src/main/res/layout/fragment_tool_triangulate.xml b/app/src/main/res/layout/fragment_tool_triangulate.xml index f10fb5037..fbc3e1d77 100644 --- a/app/src/main/res/layout/fragment_tool_triangulate.xml +++ b/app/src/main/res/layout/fragment_tool_triangulate.xml @@ -233,6 +233,17 @@ app:chipIconTint="?android:textColorSecondary" app:iconStartPadding="4dp" /> + +