-
Notifications
You must be signed in to change notification settings - Fork 319
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
Update InstructionView with BannerMilestone only with callback #969
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say
This PR ensures we only update the
InstructionView
when the milestone listener is fired and not with every update which is what was happening previously.
What do you mean?
Removing updateManeuverView
from
Lines 176 to 183 in ee41dd3
navigationViewModel.instructionModel.observe(owner, new Observer<InstructionModel>() { | |
@Override | |
public void onChanged(@Nullable InstructionModel model) { | |
if (model != null) { | |
updateInstructionData(model); | |
} | |
} | |
}); |
Also added some nit picks/questions.
@@ -207,7 +206,7 @@ public void onChanged(@Nullable Boolean isOffRoute) { | |||
}); | |||
|
|||
// ViewModel set - click listeners can be set now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT unnecessary comment
@@ -559,11 +554,11 @@ private void addBottomSheetListener() { | |||
} | |||
} | |||
|
|||
private void initClickListeners() { | |||
private void initializeClickListeners() { | |||
if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about extracting an explaining variable here and simplify the expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #973
@@ -221,19 +220,17 @@ public void onChanged(@Nullable Boolean isOffRoute) { | |||
public void update(RouteProgress routeProgress) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we exposing this using @SuppressWarnings("UnusedDeclaration")
? 🤔
No usages found in All Places
Could you clarify how this would be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is used when InstructionView
is used without a NavigationViewModel
. If you wanted to inflate the view separate of NavigationView
, you would use this API with a ProgressChangeListener
to provide it data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Thanks for clarifying 👍
@@ -682,7 +677,8 @@ private void distanceText(InstructionModel model) { | |||
* | |||
* @param model provides instruction text | |||
*/ | |||
private void updateTextInstruction(InstructionModel model) { | |||
private void updateBannerData(InstructionModel model) { | |||
updateManeuverView(model); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should extract this call from here and make it explicit wherever we call updateBannerData
. At a first glance updateBannerData
and updateManeuverView
seem completely different things to me. Could you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ManeuverView
renders the arrow based on the String
maneuver type + modifier data. This is provided in the InstructionModel
- maybe updateManeuverViewData
would be more clear here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the ManeuverView
is part of the Banner, right? In terms of View
s (overall layout), could you clarify what's the Instruction, Banner, Maneuver, etc.? I think it's confusing to me because I don't have the big picture of how it's all glued together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ee41dd3
to
f26ef50
Compare
@Guardiola31337 yeah there are two different models that populate the |
@@ -11,21 +11,33 @@ | |||
|
|||
public class BannerInstructionModel extends InstructionModel { | |||
|
|||
private BannerInstructionMilestone milestone; | |||
private BannerText primaryBannerText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. This field is already declared in its parent InstructionModel
.
@@ -11,21 +11,33 @@ | |||
|
|||
public class BannerInstructionModel extends InstructionModel { | |||
|
|||
private BannerInstructionMilestone milestone; | |||
private BannerText primaryBannerText; | |||
private BannerText secondaryBannerText; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
|
||
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. This method no needs to be overridden, it's already declared in its parent InstructionModel
.
} | ||
|
||
@Override | ||
BannerText getPrimaryBannerText() { | ||
return milestone.getBannerInstructions().primary(); | ||
return primaryBannerText; | ||
} | ||
|
||
@Override | ||
BannerText getSecondaryBannerText() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here ☝️
f26ef50
to
bd7b430
Compare
@Guardiola31337 anything else needed to address here? |
bd7b430
to
f874b55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Guardiola31337 anything else needed to address here?
One last minor comment not blocking the PR. Great job @danesfeder 👏
@@ -222,13 +221,12 @@ public void onChanged(@Nullable Boolean isOffRoute) { | |||
public void update(RouteProgress routeProgress) { | |||
if (routeProgress != null && !isRerouting) { | |||
InstructionModel model = new InstructionModel(getContext(), routeProgress, language, unitType); | |||
updateViews(model); | |||
updateTextInstruction(model); | |||
updateDataFromInstructionModel(model); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment - what about updateDataFromInstruction(model)
and updateDataFromBannerInstruction(model)
? I think it'd be better for consistency and it reads well. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Guardiola31337 yeah I like that naming a lot better, thanks 💯
f874b55
to
f74183d
Compare
Noticed this while testing:
This PR ensures we only update the
InstructionView
when the milestone listener is fired and not with every update which is what was happening previously.I also added the maneuver type and modifier from the
BannerText
object as well.