Skip to content

Commit

Permalink
Share location from triangulation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Oct 12, 2023
1 parent a489f5b commit 6dffa9e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,12 @@ class LocationBottomSheet : BoundBottomSheetDialogFragment<FragmentLocationBindi
}
}

val locationSenders = mapOf(
ShareAction.Copy to LocationCopy(requireContext()),
ShareAction.QR to LocationQRSender(this),
ShareAction.Maps to LocationGeoSender(requireContext()),
ShareAction.Send to LocationSharesheet(requireContext())
)

binding.locationTitle.rightButton.setOnClickListener {
Share.share(
Share.shareLocation(
this,
getString(R.string.location),
listOf(ShareAction.Copy, ShareAction.QR, ShareAction.Send, ShareAction.Maps)
) {
it?.let {
gps?.location?.let { location ->
locationSenders[it]?.send(location, format)
}
}
}
gps?.location ?: return@setOnClickListener,
format
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,16 +285,10 @@ class NavigatorFragment : BoundFragment<ActivityNavigatorBinding>() {
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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FragmentToolTriangulateBinding>() {

Expand Down Expand Up @@ -106,11 +107,15 @@ class FragmentToolTriangulate : BoundFragment<FragmentToolTriangulateBinding>()
}

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)
}
}

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_tool_triangulate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@
app:chipIconTint="?android:textColorSecondary"
app:iconStartPadding="4dp" />

<com.google.android.material.chip.Chip
android:id="@+id/share_location"
style="@style/Widget.Material3.Chip.Assist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/share_ellipsis"
app:chipIcon="@drawable/ic_share"
app:chipIconSize="@dimen/chip_icon_size"
app:chipIconTint="?android:textColorSecondary"
app:iconStartPadding="4dp" />

<com.google.android.material.chip.Chip
android:id="@+id/update_gps_override"
style="@style/Widget.Material3.Chip.Assist"
Expand Down

0 comments on commit 6dffa9e

Please sign in to comment.