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

[19972] Card by card highlight implementation update #427

Merged
Show file tree
Hide file tree
Changes from all 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,49 +1,61 @@
package com.skedgo.tripkit.a2brouting

import android.graphics.Color
import com.skedgo.tripkit.common.util.PolyUtil
import com.google.maps.android.PolyUtil
import com.google.maps.android.ktx.utils.simplify
import com.skedgo.tripkit.common.util.TripKitLatLng
import io.reactivex.Observable
import com.skedgo.tripkit.routing.TripSegment
import javax.inject.Inject

class GetNonTravelledLineForTrip @Inject constructor() {

fun execute(segments: List<TripSegment>): Observable<List<com.skedgo.tripkit.LineSegment>> {
return Observable.fromCallable { createNonTravelledLinesToDraw(segments) }
.flatMap { Observable.fromIterable(it) }
}
companion object {
const val LAT_LNG_SIMPLIFY_TOLERANCE = 5.0
}

private fun createNonTravelledLinesToDraw(segments: List<TripSegment>?): List<List<com.skedgo.tripkit.LineSegment>> {
return segments.orEmpty()
.filterNot {
it.from == null || it.to == null
}
.map {
val color = if (it.serviceColor == null)
Color.BLACK
else
it.serviceColor!!.color
fun execute(segments: List<TripSegment>): Observable<List<com.skedgo.tripkit.LineSegment>> {
return Observable.fromCallable { createNonTravelledLinesToDraw(segments) }
.flatMap { Observable.fromIterable(it) }
}

val shapes = it.shapes ?: emptyList()
shapes to color
}
.flatMap { (shapes, defaultColor) ->
shapes.filterNot { it.isTravelled }
.filter {
it.encodedWaypoints.isNotEmpty()
}
.map {
val color = if (it.serviceColor == null || it.serviceColor.color == Color.BLACK)
defaultColor
private fun createNonTravelledLinesToDraw(segments: List<TripSegment>?): List<List<com.skedgo.tripkit.LineSegment>> {
return segments.orEmpty()
.filterNot {
it.from == null || it.to == null
}
.map {
val color = if (it.serviceColor == null)
Color.BLACK
else
it.serviceColor.color
PolyUtil.decode(it.encodedWaypoints)
.zipWithNext()
.map { (start, end) ->
com.skedgo.tripkit.LineSegment(start, end, color, "")
it.serviceColor?.color ?: Color.BLACK

val shapes = it.shapes ?: emptyList()
shapes to color
}
.flatMap { (shapes, defaultColor) ->
shapes.filterNot { it.isTravelled }
.filter {
it.encodedWaypoints.isNotEmpty()
}
.map {
val color =
if (it.serviceColor == null || it.serviceColor.color == Color.BLACK)
defaultColor
else
it.serviceColor.color
PolyUtil.decode(it.encodedWaypoints).simplify(LAT_LNG_SIMPLIFY_TOLERANCE)
.zipWithNext()
.map { (start, end) ->
com.skedgo.tripkit.LineSegment(
TripKitLatLng(start.latitude, start.longitude),
TripKitLatLng(end.latitude, end.longitude),
color,
""
)
}
}
}
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.skedgo.tripkit.a2brouting

import android.graphics.Color
import androidx.annotation.ColorInt
import com.google.maps.android.PolyUtil
import com.google.maps.android.ktx.utils.simplify
import com.skedgo.tripkit.common.model.Street
import com.skedgo.tripkit.common.model.TransportMode
import com.skedgo.tripkit.common.util.PolyUtil
import com.skedgo.tripkit.common.util.TripKitLatLng
import com.skedgo.tripkit.routing.RoadTag
import io.reactivex.Observable
Expand All @@ -15,6 +16,10 @@ import javax.inject.Inject

class GetTravelledLineForTrip @Inject constructor() {

companion object {
const val LAT_LNG_SIMPLIFY_TOLERANCE = 5.0
}

fun execute(segments: List<TripSegment>?): Observable<List<com.skedgo.tripkit.LineSegment>> {
return Observable
.fromCallable {
Expand All @@ -41,27 +46,37 @@ class GetTravelledLineForTrip @Inject constructor() {
color
else
it.serviceColor.color
PolyUtil.decode(it.encodedWaypoints)
.orEmpty().zipWithNext()
val decodedWayPoints = PolyUtil.decode(it.encodedWaypoints)
println("tag123, a: ${decodedWayPoints.size}")
val simplified = decodedWayPoints.simplify(LAT_LNG_SIMPLIFY_TOLERANCE)
println("tag123, b: ${simplified.size}")
simplified.zipWithNext()
.map { (start, end) ->
com.skedgo.tripkit.LineSegment(
start, end, color,
TripKitLatLng(start.latitude, start.longitude),
TripKitLatLng(end.latitude, end.longitude),
color,
com.skedgo.tripkit.LineSegment.Tag.SHAPE.toString()
)
}
}
val lineSegmentsFromStreets = segment.streets.orEmpty()
.filter { it.encodedWaypoints() != null }
.flatMap { street ->
PolyUtil.decode(street.encodedWaypoints())
PolyUtil.decode(street.encodedWaypoints()).simplify(
LAT_LNG_SIMPLIFY_TOLERANCE
)
.zipWithNext()
.map { (start, end) ->
var lineColor = (getColorForWheelchairAndBicycle(street, modeId) ?: color)
if(!street.roadTags().isNullOrEmpty()) {
var lineColor =
(getColorForWheelchairAndBicycle(street, modeId) ?: color)
if (!street.roadTags().isNullOrEmpty()) {
lineColor = Color.BLUE
}
com.skedgo.tripkit.LineSegment(
start, end, lineColor,
TripKitLatLng(start.latitude, start.longitude),
TripKitLatLng(end.latitude, end.longitude),
lineColor,
com.skedgo.tripkit.LineSegment.Tag.STREET.toString()
)
}
Expand Down