From 9fcd0c35fc0a0afe6e8bbb4e6265bb3425e524bb Mon Sep 17 00:00:00 2001 From: Daniel Hogan Date: Fri, 23 Jun 2017 12:45:54 -0700 Subject: [PATCH] add transit arrival/departure times (#818) --- .../mapzen/erasermap/view/InstructionGroup.kt | 7 ++++++- .../view/MultiModalDirectionListAdapter.kt | 16 +++++++++++++--- app/src/main/res/values/strings.xml | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/InstructionGroup.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/InstructionGroup.kt index b868d8e7..04bb1ea8 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/InstructionGroup.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/InstructionGroup.kt @@ -8,6 +8,7 @@ import android.text.style.StyleSpan import com.mapzen.erasermap.R import com.mapzen.valhalla.Instruction import com.mapzen.valhalla.TransitInfo +import com.mapzen.valhalla.TransitStop import com.mapzen.valhalla.TravelMode import com.mapzen.valhalla.TravelType import java.util.ArrayList @@ -70,12 +71,16 @@ class InstructionGroup(val travelType: TravelType, val travelMode: TravelMode, return numberOfStops } - fun transitInstructionSpannable(instruction: Instruction): SpannableString? { + fun transitInstructionSpannable(context: Context, instruction: Instruction): SpannableString? { if (transitInstruction == null) { var turnInstruction = instruction.getHumanTurnInstruction() val pattern = Pattern.compile("\\([0-9]+ stops\\)") val matcher = pattern.matcher(turnInstruction) turnInstruction = matcher.replaceAll("") + val transitStops = instruction.getTransitInfo()?.getTransitStops() as ArrayList + val departureTime = transitStops[0].getDepartureDateTime().substring(11, 16) + turnInstruction += " " + turnInstruction += context.getString(R.string.transit_time, departureTime) val spannableString = SpannableString(turnInstruction) val transitInfo = instruction.getTransitInfo() as TransitInfo val shortnameLoc = spannableString.indexOf(transitInfo.getShortName(), 0, true) diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/MultiModalDirectionListAdapter.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/MultiModalDirectionListAdapter.kt index 8cd9ad91..828f7416 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/MultiModalDirectionListAdapter.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/MultiModalDirectionListAdapter.kt @@ -266,7 +266,7 @@ class MultiModalDirectionListAdapter(val context: Context, val instructionGroupe holder.startingStationName.text = instructionGroup.firstStationName(context, instruction) holder.travelTypeIcon.setImageResource(multiModalHelper.getTransitIcon( instruction.getTravelType())) - holder.instructionText.text = instructionGroup.transitInstructionSpannable(instruction) + holder.instructionText.text = instructionGroup.transitInstructionSpannable(context, instruction) holder.distanceTimeText.text = instructionGroup.numberOfStops(context, instruction) holder.timeView.timeInMinutes = TimeUnit.SECONDS.toMinutes( instructionGroup.totalTime.toLong()).toInt() @@ -311,7 +311,12 @@ class MultiModalDirectionListAdapter(val context: Context, val instructionGroupe lp.bottomMargin = 0 } } - holder.endingStationName.text = transitStops[transitStops.size-1].getName() + val arrivalTime = transitStops[transitStops.size-1].getArrivalDateTime().substring(11, 16) + val builder = StringBuilder() + builder.append(transitStops[transitStops.size-1].getName()) + builder.append(" ") + builder.append(context.getString(R.string.transit_time, arrivalTime)) + holder.endingStationName.text = builder } fun setTransitStationNamesContainer(holder: TransitViewHolder, listItem: ListRowItem, @@ -332,7 +337,12 @@ class MultiModalDirectionListAdapter(val context: Context, val instructionGroupe stationRow = View.inflate(context, R.layout.transit_station_row, null) } val stationName = stationRow?.findViewById(R.id.station_name) as TextView - stationName.text = transitStops[i].getName() + val departureTime = transitStops[i].getDepartureDateTime().substring(11, 16) + val builder = StringBuilder() + builder.append(transitStops[i].getName()) + builder.append(" ") + builder.append(context.getString(R.string.transit_time, departureTime)) + stationName.text = builder holder.stationNamesContainer.addView(stationRow) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ede9e99..98339fb0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,6 +48,7 @@ , stops + (%s) Station No route found Try a different mode?