Skip to content

Commit

Permalink
add transit arrival/departure times (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Hogan authored and sarahsnow1 committed Jun 23, 2017
1 parent 1e1b083 commit 9fcd0c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<TransitStop>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<string name="comma">,</string>
<string name="stops">stops</string>
<string name="transit_time">(%s)</string>
<string name="station">Station</string>
<string name="no_route_found">No route found</string>
<string name="try_another_mode">Try a different mode?</string>
Expand Down

0 comments on commit 9fcd0c3

Please sign in to comment.