Skip to content

Commit

Permalink
Update InstructionView with BannerMilestone only when callback is rec…
Browse files Browse the repository at this point in the history
…eived
  • Loading branch information
danesfeder committed May 29, 2018
1 parent c88fbaa commit f26ef50
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,33 @@

public class BannerInstructionModel extends InstructionModel {

private BannerInstructionMilestone milestone;
private BannerText primaryBannerText;
private BannerText secondaryBannerText;

public BannerInstructionModel(Context context, BannerInstructionMilestone milestone,
RouteProgress progress, Locale locale, @NavigationUnitType.UnitType int unitType) {
super(context, progress, locale, unitType);
this.milestone = milestone;
primaryBannerText = milestone.getBannerInstructions().primary();
secondaryBannerText = milestone.getBannerInstructions().secondary();
}

@Override
BannerText getPrimaryBannerText() {
return milestone.getBannerInstructions().primary();
return primaryBannerText;
}

@Override
BannerText getSecondaryBannerText() {
return milestone.getBannerInstructions().secondary();
return secondaryBannerText;
}

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

@Override
String getManeuverModifier() {
return primaryBannerText.modifier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ InstructionStepResources getStepResources() {
return stepResources;
}

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

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

RouteProgress getProgress() {
return progress;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public InstructionView(Context context, @Nullable AttributeSet attrs) {

public InstructionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
initialize();
}

/**
Expand All @@ -132,10 +132,10 @@ public InstructionView(Context context, @Nullable AttributeSet attrs, int defSty
protected void onFinishInflate() {
super.onFinishInflate();
bind();
initBackground();
initTurnLaneRecyclerView();
initDirectionsRecyclerView();
initAnimations();
initializeBackground();
initializeTurnLaneRecyclerView();
initializeDirectionsRecyclerView();
initializeAnimations();
}

@Override
Expand Down Expand Up @@ -177,16 +177,15 @@ public void subscribe(NavigationViewModel navigationViewModel) {
@Override
public void onChanged(@Nullable InstructionModel model) {
if (model != null) {
updateViews(model);
updateTextInstruction(model);
updateInstructionData(model);
}
}
});
navigationViewModel.bannerInstructionModel.observe(owner, new Observer<BannerInstructionModel>() {
@Override
public void onChanged(@Nullable BannerInstructionModel bannerInstructionModel) {
if (bannerInstructionModel != null) {
updateTextInstruction(bannerInstructionModel);
updateBannerData(bannerInstructionModel);
}
}
});
Expand All @@ -205,9 +204,7 @@ public void onChanged(@Nullable Boolean isOffRoute) {
}
}
});

// ViewModel set - click listeners can be set now
initClickListeners();
initializeClickListeners();
}

/**
Expand All @@ -221,19 +218,17 @@ public void onChanged(@Nullable Boolean isOffRoute) {
public void update(RouteProgress routeProgress) {
if (routeProgress != null && !isRerouting) {
InstructionModel model = new InstructionModel(getContext(), routeProgress, locale, unitType);
updateViews(model);
updateTextInstruction(model);
updateInstructionData(model);
updateBannerData(model);
}
}

private void updateViews(InstructionModel model) {
updateManeuverView(model);
private void updateInstructionData(InstructionModel model) {
updateDistanceText(model);
updateInstructionList(model);
updateTurnLanes(model);
updateThenStep(model);
if (newStep(model.getProgress())) {
// Pre-fetch the image URLs for the upcoming step
LegStep upComingStep = model.getProgress().currentLegProgress().upComingStep();
ImageCoordinator.getInstance().prefetchImageCache(upComingStep);
}
Expand Down Expand Up @@ -348,7 +343,7 @@ public void setUnitType(@NavigationUnitType.UnitType int unitType) {
/**
* Inflates this layout needed for this view and initializes the locale as the device locale.
*/
private void init() {
private void initialize() {
locale = LocaleUtils.getDeviceLocale(getContext());
inflate(getContext(), R.layout.instruction_view_layout, this);
}
Expand All @@ -375,14 +370,14 @@ private void bind() {
instructionLayoutText = findViewById(R.id.instructionLayoutText);
instructionListLayout = findViewById(R.id.instructionListLayout);
rvInstructions = findViewById(R.id.rvInstructions);
initInstructionAutoSize();
initializeInstructionAutoSize();
}

/**
* For API 21 and lower, manually set the drawable tint based on the colors
* set in the given navigation theme (light or dark).
*/
private void initBackground() {
private void initializeBackground() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
int navigationViewPrimaryColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewPrimary);
Expand Down Expand Up @@ -498,19 +493,17 @@ public void run() {
* Called after we bind the views, this will allow the step instruction {@link TextView}
* to automatically re-size based on the length of the text.
*/
private void initInstructionAutoSize() {
private void initializeInstructionAutoSize() {
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingPrimaryText,
26, 30, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingSecondaryText,
20, 26, 1, TypedValue.COMPLEX_UNIT_SP);
TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(upcomingDistanceText,
16, 20, 1, TypedValue.COMPLEX_UNIT_SP);
}

/**
* Sets up the {@link RecyclerView} that is used to display the turn lanes.
*/
private void initTurnLaneRecyclerView() {
private void initializeTurnLaneRecyclerView() {
turnLaneAdapter = new TurnLaneAdapter();
rvTurnLanes.setAdapter(turnLaneAdapter);
rvTurnLanes.setHasFixedSize(true);
Expand All @@ -521,7 +514,7 @@ private void initTurnLaneRecyclerView() {
/**
* Sets up the {@link RecyclerView} that is used to display the list of instructions.
*/
private void initDirectionsRecyclerView() {
private void initializeDirectionsRecyclerView() {
instructionListAdapter = new InstructionListAdapter();
rvInstructions.setAdapter(instructionListAdapter);
rvInstructions.setHasFixedSize(true);
Expand All @@ -532,7 +525,7 @@ private void initDirectionsRecyclerView() {
/**
* Initializes all animations needed to show / hide views.
*/
private void initAnimations() {
private void initializeAnimations() {
Context context = getContext();
rerouteSlideDownTop = AnimationUtils.loadAnimation(context, R.anim.slide_down_top);
rerouteSlideUpTop = AnimationUtils.loadAnimation(context, R.anim.slide_up_top);
Expand All @@ -559,11 +552,11 @@ private void addBottomSheetListener() {
}
}

private void initClickListeners() {
private void initializeClickListeners() {
if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
initLandscapeListListener();
initializeLandscapeListListener();
} else {
initPortraitListListener();
initializePortraitListListener();
}
alertView.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -594,7 +587,7 @@ public void onClick(View view) {
* For portrait orientation, attach the listener to the whole layout
* and use custom animations to hide and show the instructions /sound layout
*/
private void initPortraitListListener() {
private void initializePortraitListListener() {
instructionLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View instructionView) {
Expand All @@ -612,7 +605,7 @@ public void onClick(View instructionView) {
* For landscape orientation, the click listener is attached to
* the instruction text layout and the constraints are adjusted before animating
*/
private void initLandscapeListListener() {
private void initializeLandscapeListListener() {
instructionLayoutText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View instructionLayoutText) {
Expand All @@ -633,8 +626,8 @@ public void onClick(View instructionLayoutText) {
* @param model provides maneuver modifier / type
*/
private void updateManeuverView(InstructionModel model) {
String maneuverViewType = model.getStepResources().getManeuverViewType();
String maneuverViewModifier = model.getStepResources().getManeuverViewModifier();
String maneuverViewType = model.getManeuverType();
String maneuverViewModifier = model.getManeuverModifier();
upcomingManeuverView.setManeuverTypeAndModifier(maneuverViewType, maneuverViewModifier);
if (model.getRoundaboutAngle() != null) {
upcomingManeuverView.setRoundaboutAngle(model.getRoundaboutAngle());
Expand Down Expand Up @@ -682,7 +675,8 @@ private void distanceText(InstructionModel model) {
*
* @param model provides instruction text
*/
private void updateTextInstruction(InstructionModel model) {
private void updateBannerData(InstructionModel model) {
updateManeuverView(model);
if (model.getPrimaryBannerText() != null) {
createInstructionLoader(upcomingPrimaryText, model.getPrimaryBannerText()).loadInstruction();
}
Expand Down Expand Up @@ -732,7 +726,7 @@ private boolean newStep(RouteProgress routeProgress) {
*/
private void updateTurnLanes(InstructionModel model) {
List<IntersectionLanes> turnLanes = model.getStepResources().getTurnLanes();
String maneuverViewModifier = model.getStepResources().getManeuverViewModifier();
String maneuverViewModifier = model.getManeuverModifier();
double durationRemaining = model.getProgress().currentLegProgress().currentStepProgress().durationRemaining();

if (shouldShowTurnLanes(turnLanes, maneuverViewModifier, durationRemaining)) {
Expand Down

0 comments on commit f26ef50

Please sign in to comment.