Skip to content

Commit

Permalink
Consume Sub BannerText in InstructionView
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Oct 11, 2018
1 parent 226b446 commit 11ed126
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,15 @@ public void onProgressChange(Location location, RouteProgress routeProgress) {
updateLocation(location);

// Update InstructionView data from RouteProgress
instructionView.update(routeProgress);
instructionView.updateDistanceWith(routeProgress);
}

@Override
public void onMilestoneEvent(RouteProgress routeProgress, String instruction, Milestone milestone) {
playAnnouncement(milestone);

// Update InstructionView banner instructions
instructionView.updateBannerInstructionsWith(milestone);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ public BannerInstructionModel(DistanceFormatter distanceFormatter, RouteProgress
super(distanceFormatter, progress);
primaryBannerText = instructions.primary();
secondaryBannerText = instructions.secondary();
subBannerText = instructions.sub();
}

@Override
String getManeuverType() {
String retrievePrimaryManeuverType() {
return primaryBannerText.type();
}

@Override
String getManeuverModifier() {
String retrieveSecondaryManeuverModifier() {
return primaryBannerText.modifier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class InstructionModel {

BannerText primaryBannerText;
BannerText secondaryBannerText;
private BannerText thenBannerText;
BannerText subBannerText;
private Float roundaboutAngle = null;
private InstructionStepResources stepResources;
private RouteProgress progress;
Expand All @@ -25,36 +25,36 @@ public InstructionModel(DistanceFormatter distanceFormatter, RouteProgress progr
buildInstructionModel(distanceFormatter, progress);
}

BannerText getPrimaryBannerText() {
BannerText retrievePrimaryBannerText() {
return primaryBannerText;
}

BannerText getSecondaryBannerText() {
BannerText retrieveSecondaryBannerText() {
return secondaryBannerText;
}

BannerText getThenBannerText() {
return thenBannerText;
BannerText retrieveSubBannerText() {
return subBannerText;
}

@Nullable
Float getRoundaboutAngle() {
Float retrieveRoundaboutAngle() {
return roundaboutAngle;
}

InstructionStepResources getStepResources() {
InstructionStepResources retrieveStepResources() {
return stepResources;
}

String getManeuverType() {
String retrievePrimaryManeuverType() {
return stepResources.getManeuverViewType();
}

String getManeuverModifier() {
String retrieveSecondaryManeuverModifier() {
return stepResources.getManeuverViewModifier();
}

RouteProgress getProgress() {
RouteProgress retrieveProgress() {
return progress;
}

Expand All @@ -73,7 +73,7 @@ private void extractStepInstructions(RouteProgress progress) {
secondaryBannerText = routeUtils.findCurrentBannerText(currentStep, stepDistanceRemaining, false);

if (upComingStep != null) {
thenBannerText = routeUtils.findCurrentBannerText(upComingStep, upComingStep.distance(), true);
subBannerText = routeUtils.findCurrentBannerText(upComingStep, upComingStep.distance(), true);
}

if (primaryBannerText != null && primaryBannerText.degrees() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public class InstructionView extends RelativeLayout implements FeedbackBottomShe
private TextView upcomingDistanceText;
private TextView upcomingPrimaryText;
private TextView upcomingSecondaryText;
private ManeuverView thenManeuverView;
private TextView thenStepText;
private ManeuverView subManeuverView;
private TextView subStepText;
private NavigationAlertView alertView;
private View rerouteLayout;
private View turnLaneLayout;
private View thenStepLayout;
private View subStepLayout;
private RecyclerView rvTurnLanes;
private RecyclerView rvInstructions;
private TurnLaneAdapter turnLaneAdapter;
Expand Down Expand Up @@ -189,8 +189,10 @@ public void onChanged(@Nullable InstructionModel model) {
@Override
public void onChanged(@Nullable BannerInstructionModel model) {
if (model != null) {
updateManeuverView(model.getManeuverType(), model.getManeuverModifier(), model.getRoundaboutAngle());
updateDataFromBannerText(model.getPrimaryBannerText(), model.getSecondaryBannerText());
updateManeuverView(model.retrievePrimaryManeuverType(), model.retrieveSecondaryManeuverModifier(),
model.retrieveRoundaboutAngle());
updateDataFromBannerText(model.retrievePrimaryBannerText(), model.retrieveSecondaryBannerText());
updateSubStep(model.retrieveSubBannerText());
}
}
});
Expand Down Expand Up @@ -227,8 +229,10 @@ public void update(RouteProgress routeProgress) {
if (routeProgress != null && !isRerouting) {
InstructionModel model = new InstructionModel(distanceFormatter, routeProgress);
updateDataFromInstruction(model);
updateManeuverView(model.getManeuverType(), model.getManeuverModifier(), model.getRoundaboutAngle());
updateDataFromBannerText(model.getPrimaryBannerText(), model.getSecondaryBannerText());
updateSubStep(model.retrieveSubBannerText());
updateManeuverView(model.retrievePrimaryManeuverType(), model.retrieveSecondaryManeuverModifier(),
model.retrieveRoundaboutAngle());
updateDataFromBannerText(model.retrievePrimaryBannerText(), model.retrieveSecondaryBannerText());
}
}

Expand Down Expand Up @@ -267,6 +271,7 @@ public void updateBannerInstructionsWith(Milestone milestone) {
BannerText primary = instructions.primary();
updateManeuverView(primary.type(), primary.modifier(), extractRoundaboutDegreesFrom(primary));
updateDataFromBannerText(primary, instructions.secondary());
updateSubStep(instructions.sub());
}
}

Expand Down Expand Up @@ -412,12 +417,12 @@ private void bind() {
upcomingDistanceText = findViewById(R.id.stepDistanceText);
upcomingPrimaryText = findViewById(R.id.stepPrimaryText);
upcomingSecondaryText = findViewById(R.id.stepSecondaryText);
thenManeuverView = findViewById(R.id.thenManeuverView);
thenStepText = findViewById(R.id.thenStepText);
subManeuverView = findViewById(R.id.subManeuverView);
subStepText = findViewById(R.id.subStepText);
alertView = findViewById(R.id.alertView);
rerouteLayout = findViewById(R.id.rerouteLayout);
turnLaneLayout = findViewById(R.id.turnLaneLayout);
thenStepLayout = findViewById(R.id.thenStepLayout);
subStepLayout = findViewById(R.id.subStepLayout);
rvTurnLanes = findViewById(R.id.rvTurnLanes);
instructionLayout = findViewById(R.id.instructionLayout);
instructionLayoutText = findViewById(R.id.instructionLayoutText);
Expand All @@ -444,9 +449,9 @@ private void initializeBackground() {
Drawable maneuverBackground = DrawableCompat.wrap(instructionLayoutManeuver.getBackground()).mutate();
DrawableCompat.setTint(maneuverBackground, navigationViewBannerBackgroundColor);

View thenStepLayout = findViewById(R.id.thenStepLayout);
Drawable thenStepBackground = DrawableCompat.wrap(thenStepLayout.getBackground()).mutate();
DrawableCompat.setTint(thenStepBackground, navigationViewListBackgroundColor);
View subStepLayout = findViewById(R.id.subStepLayout);
Drawable subStepBackground = DrawableCompat.wrap(subStepLayout.getBackground()).mutate();
DrawableCompat.setTint(subStepBackground, navigationViewListBackgroundColor);

View turnLaneLayout = findViewById(R.id.turnLaneLayout);
Drawable turnLaneBackground = DrawableCompat.wrap(turnLaneLayout.getBackground()).mutate();
Expand Down Expand Up @@ -597,9 +602,9 @@ public void onClick(View instructionLayoutText) {
*/
private boolean newDistanceText(InstructionModel model) {
return !upcomingDistanceText.getText().toString().isEmpty()
&& !TextUtils.isEmpty(model.getStepResources().getStepDistanceRemaining())
&& !TextUtils.isEmpty(model.retrieveStepResources().getStepDistanceRemaining())
&& !upcomingDistanceText.getText().toString()
.contentEquals(model.getStepResources().getStepDistanceRemaining().toString());
.contentEquals(model.retrieveStepResources().getStepDistanceRemaining().toString());
}

/**
Expand All @@ -608,7 +613,7 @@ private boolean newDistanceText(InstructionModel model) {
* @param model provides distance text
*/
private void distanceText(InstructionModel model) {
upcomingDistanceText.setText(model.getStepResources().getStepDistanceRemaining());
upcomingDistanceText.setText(model.retrieveStepResources().getStepDistanceRemaining());
}

private InstructionLoader createInstructionLoader(TextView textView, BannerText bannerText) {
Expand Down Expand Up @@ -642,9 +647,9 @@ private boolean newStep(RouteProgress routeProgress) {
* @param model created with new {@link RouteProgress} holding turn lane data
*/
private void updateTurnLanes(InstructionModel model) {
List<IntersectionLanes> turnLanes = model.getStepResources().getTurnLanes();
String maneuverViewModifier = model.getManeuverModifier();
double durationRemaining = model.getProgress().currentLegProgress().currentStepProgress().durationRemaining();
List<IntersectionLanes> turnLanes = model.retrieveStepResources().getTurnLanes();
String maneuverViewModifier = model.retrieveSecondaryManeuverModifier();
double durationRemaining = model.retrieveProgress().currentLegProgress().currentStepProgress().durationRemaining();

if (shouldShowTurnLanes(turnLanes, maneuverViewModifier, durationRemaining)) {
if (turnLaneLayout.getVisibility() == GONE) {
Expand Down Expand Up @@ -683,59 +688,43 @@ private void hideTurnLanes() {
}

/**
* Check if the the then step should be shown.
* Check if the the sub step should be shown.
* If true, update the "then" maneuver and the "then" step text.
* If false, hide the then layout.
*
* @param model to determine if the then step layout should be shown
*/
private void updateThenStep(InstructionModel model) {
if (shouldShowThenStep(model)) {
String thenStepManeuverType = model.getStepResources().getThenStepManeuverType();
String thenStepManeuverModifier = model.getStepResources().getThenStepManeuverModifier();
thenManeuverView.setManeuverTypeAndModifier(thenStepManeuverType, thenStepManeuverModifier);
Float roundaboutAngle = model.getStepResources().getThenStepRoundaboutDegrees();
* @param subText to determine if the then step layout should be shown
*/
private void updateSubStep(BannerText subText) {
if (shouldShowSubStep(subText)) {
String maneuverType = subText.type();
String maneuverModifier = subText.modifier();
subManeuverView.setManeuverTypeAndModifier(maneuverType, maneuverModifier);
Double roundaboutAngle = subText.degrees();
if (roundaboutAngle != null) {
thenManeuverView.setRoundaboutAngle(roundaboutAngle);
subManeuverView.setRoundaboutAngle(roundaboutAngle.floatValue());
}
thenStepText.setText(model.getThenBannerText().text());
subStepText.setText(subText.text());
showThenStepLayout();
} else {
hideThenStepLayout();
}
}

/**
* First, checks if the turn lanes are visible (if they are, don't show then step).
* Second, checks if the upcoming step is less than 15 seconds long.
* This is our cue to show the thenStep.
*
* @param model to check the upcoming step
* @return true if should show, false if not
*/
private boolean shouldShowThenStep(InstructionModel model) {
return turnLaneLayout.getVisibility() != VISIBLE
&& model.getThenBannerText() != null
&& model.getStepResources().shouldShowThenStep();
private boolean shouldShowSubStep(@Nullable BannerText subText) {
return turnLaneLayout.getVisibility() != VISIBLE && subText != null;
}

/**
* Shows then step layout
*/
private void showThenStepLayout() {
if (thenStepLayout.getVisibility() == GONE) {
if (subStepLayout.getVisibility() == GONE) {
beginDelayedTransition();
thenStepLayout.setVisibility(VISIBLE);
subStepLayout.setVisibility(VISIBLE);
}
}

/**
* Hides then step layout
*/
private void hideThenStepLayout() {
if (thenStepLayout.getVisibility() == VISIBLE) {
if (subStepLayout.getVisibility() == VISIBLE) {
beginDelayedTransition();
thenStepLayout.setVisibility(GONE);
subStepLayout.setVisibility(GONE);
}
}

Expand Down Expand Up @@ -783,9 +772,8 @@ private void updateDataFromInstruction(InstructionModel model) {
updateDistanceText(model);
updateInstructionList(model);
updateTurnLanes(model);
updateThenStep(model);
if (newStep(model.getProgress())) {
LegStep upComingStep = model.getProgress().currentLegProgress().upComingStep();
if (newStep(model.retrieveProgress())) {
LegStep upComingStep = model.retrieveProgress().currentLegProgress().upComingStep();
ImageCoordinator.getInstance().prefetchImageCache(upComingStep);
}
}
Expand Down Expand Up @@ -865,7 +853,7 @@ private void updateLandscapeConstraintsTo(int layoutRes) {
* @param model to provide the current steps and unit type
*/
private void updateInstructionList(InstructionModel model) {
RouteProgress routeProgress = model.getProgress();
RouteProgress routeProgress = model.retrieveProgress();
boolean isListShowing = instructionListLayout.getVisibility() == VISIBLE;
instructionListAdapter.updateBannerListWith(routeProgress, isListShowing);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
app:layout_constraintTop_toBottomOf="@+id/instructionLayoutText"/>

<include
android:id="@+id/thenStepLayout"
layout="@layout/then_instruction_layout"
android:id="@+id/subStepLayout"
layout="@layout/sub_instruction_layout"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:elevation="2dp">

<com.mapbox.services.android.navigation.ui.v5.instruction.maneuver.ManeuverView
android:id="@+id/thenManeuverView"
android:id="@+id/subManeuverView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="8dp"
Expand All @@ -20,7 +20,7 @@
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/thenStepText"
android:id="@+id/subStepText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
android:visibility="gone"/>

<include
android:id="@+id/thenStepLayout"
layout="@layout/then_instruction_layout"
android:id="@+id/subStepLayout"
layout="@layout/sub_instruction_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:elevation="2dp">

<com.mapbox.services.android.navigation.ui.v5.instruction.maneuver.ManeuverView
android:id="@+id/thenManeuverView"
android:id="@+id/subManeuverView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_margin="8dp"
Expand All @@ -19,7 +19,7 @@
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/thenStepText"
android:id="@+id/subStepText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
Expand Down

0 comments on commit 11ed126

Please sign in to comment.