Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[22512] show trip lines on map for route results #147

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.skedgo.tripkit.ui.core.module

import com.skedgo.tripkit.ui.tripresult.TripResultListMapContributor
import com.skedgo.tripkit.ui.tripresults.TripResultListFragment
import dagger.Subcomponent

@ActivityScope
@Subcomponent(modules = [RoutesModule::class, LocationStuffModule::class, CameraPositionDataModule::class, TripDetailsModule::class])
interface RoutesComponent {
fun inject(fragment: TripResultListFragment)
fun inject(contributor: TripResultListMapContributor)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import javax.inject.Inject
// FIXME: Create a pure domain model to represent a trip line.
typealias TripLine = List<SegmentsPolyLineOptions>

data class PolylineConfig(
val inActiveColor: Int,
val activeColor: Int,
val activeTripUuid: String? = null
)

open class GetTripLine @Inject internal constructor(
private val getNonTravelledLineForTrip: GetNonTravelledLineForTrip,
private val getTravelledLineForTrip: GetTravelledLineForTrip
Expand All @@ -33,6 +39,10 @@ open class GetTripLine @Inject internal constructor(
)
}

open fun executeForTravelledLine(polylineConfig: PolylineConfig, segments: List<TripSegment>) =
getTravelledLineForTrip.execute(segments).toList().toObservable()
.map { createPolylineListForTravelledLines(polylineConfig, it) }

private fun createPolylineListForNonTravelledLines(nonTravelledLinesToDraw: List<List<LineSegment>>?): List<SegmentsPolyLineOptions> {
val polylineOptionsList = mutableListOf<PolylineOptions>()
if (!nonTravelledLinesToDraw.isNullOrEmpty()) {
Expand Down Expand Up @@ -93,4 +103,45 @@ open class GetTripLine @Inject internal constructor(
SegmentsPolyLineOptions(polylineOptionsList, true)
)
}

private fun createPolylineListForTravelledLines(
config: PolylineConfig,
results: List<List<LineSegment>>?
): List<SegmentsPolyLineOptions> {
val polylineOptionsList = mutableListOf<PolylineOptions>()
if (!results.isNullOrEmpty()) {
val lines = LinkedList<LatLng>()
results.forEachIndexed { index, list ->
list.forEach {
val color: Int
val zIndex: Float
if(config.activeTripUuid != null &&
config.activeTripUuid == it.tripUuid) {
color = config.activeColor
zIndex = 5.0f
} else {
color = config.inActiveColor
zIndex = 2.0f
}

lines.clear()
lines.add(LatLng(it.start.latitude, it.start.longitude))
lines.add(LatLng(it.end.latitude, it.end.longitude))

polylineOptionsList.add(
PolylineOptions()
.addAll(lines)
.color(color)
.width((if (it.color != Color.BLACK) 14 else 15).toFloat())
.zIndex(zIndex)
)
}
}
}
return listOf(
SegmentsPolyLineOptions(
polylineOptionsList, true
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ class TripKitMapFragment : LocationEnhancedMapFragment(), OnInfoWindowClickListe
contributor = newContributor
contributor?.let {
whenSafeToUseMap(Consumer { map: GoogleMap ->
Log.i("mapContributor", "safe to use")
contributor?.safeToUseMap(requireContext(), map)
})
}
Expand Down Expand Up @@ -417,7 +416,11 @@ class TripKitMapFragment : LocationEnhancedMapFragment(), OnInfoWindowClickListe
pinnedOriginLocationOnClickMarker = map?.addMarker(
MarkerOptions()
.position(LatLng(location.lat, location.lon))
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmap(type)))
.icon(
BitmapDescriptorFactory.fromBitmap(
requireContext().getFromAndToMarkerBitmap(type)
)
)
)
} else {

Expand All @@ -429,7 +432,11 @@ class TripKitMapFragment : LocationEnhancedMapFragment(), OnInfoWindowClickListe
pinnedDepartureLocationOnClickMarker = map?.addMarker(
MarkerOptions()
.position(LatLng(location.lat, location.lon))
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmap(type)))
.icon(
BitmapDescriptorFactory.fromBitmap(
requireContext().getFromAndToMarkerBitmap(type)
)
)
)
}

Expand Down Expand Up @@ -764,9 +771,9 @@ class TripKitMapFragment : LocationEnhancedMapFragment(), OnInfoWindowClickListe
}

private fun initFromAndToMarkers(map: GoogleMap) {
val fromBitmap = getMarkerBitmap(0)
val fromBitmap = requireContext().getFromAndToMarkerBitmap(0)

var toBitmap = getMarkerBitmap(1)
val toBitmap = requireContext().getFromAndToMarkerBitmap(1)

fromMarker = map.addMarker(
MarkerOptions()
Expand All @@ -784,36 +791,6 @@ class TripKitMapFragment : LocationEnhancedMapFragment(), OnInfoWindowClickListe

}

//0 = from/origin, 1 = to/destination
fun getMarkerBitmap(type: Int): Bitmap {

val builder = BearingMarkerIconBuilder(requireContext(), null)
.hasBearing(false)
.vehicleIconScale(ModeInfo.MAP_LIST_SIZE_RATIO)
.baseIcon(R.drawable.ic_map_pin_base)
.hasBearingVehicleIcon(false)
.hasTime(false)

return if (type == 0) {
builder.apply {
VehicleDrawables.createLightDrawable(requireContext(), R.drawable.ic_location_on)
?.let {
vehicleIcon(it)
}
pointerIcon(R.drawable.ic_map_pin_departure)
}.build().first

} else {
builder.apply {
VehicleDrawables.createLightDrawable(requireContext(), R.drawable.ic_location_on)
?.let {
vehicleIcon(it)
}
pointerIcon(R.drawable.ic_map_pin_arrival_small)
}.build().first
}
}

private fun setUpCurrentLocationMarkers(markerManager: MarkerManager) {
currentLocationMarkers = markerManager.newCollection("CurrentLocationMarkers")
currentLocationMarkers!!.setInfoWindowAdapter(myLocationWindowAdapter)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.skedgo.tripkit.ui.map.home

import android.content.Context
import android.graphics.Bitmap
import com.skedgo.tripkit.routing.ModeInfo
import com.skedgo.tripkit.routing.VehicleDrawables
import com.skedgo.tripkit.ui.R
import com.skedgo.tripkit.ui.map.BearingMarkerIconBuilder

fun Context.getFromAndToMarkerBitmap(type: Int): Bitmap {

val builder = BearingMarkerIconBuilder(this, null)
.hasBearing(false)
.vehicleIconScale(ModeInfo.MAP_LIST_SIZE_RATIO)
.baseIcon(R.drawable.ic_map_pin_base)
.hasBearingVehicleIcon(false)
.hasTime(false)

return if (type == 0) {
builder.apply {
VehicleDrawables.createLightDrawable(
this@getFromAndToMarkerBitmap,
R.drawable.ic_location_on
)
?.let {
vehicleIcon(it)
}
pointerIcon(R.drawable.ic_map_pin_departure)
}.build().first

} else {
builder.apply {
VehicleDrawables.createLightDrawable(
this@getFromAndToMarkerBitmap,
R.drawable.ic_location_on
)
?.let {
vehicleIcon(it)
}
pointerIcon(R.drawable.ic_map_pin_arrival_small)
}.build().first
}
}
Loading