-
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
Locale distance formatter #668
Changes from 17 commits
6d1a6e1
441759c
9cd072f
4284cab
d6dde29
5728d4d
c86ac35
26ba2b5
bb93d6a
62e1fbd
2feb26b
1c116c5
dd18e3d
8d47efb
701a226
1473409
4e103e1
db1380b
21a5fbe
9d85ef5
95ab03b
98970e5
dbb24e4
60daf6c
80d9f36
1f603fa
d5f80b1
06ad29e
4af1c51
35d8bfa
a706541
c5bd115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,7 @@ private void extractConfiguration(NavigationViewOptions.Builder options) { | |
MapboxNavigationOptions navigationOptions = MapboxNavigationOptions.builder() | ||
.unitType(preferences.getInt(NavigationConstants.NAVIGATION_VIEW_UNIT_TYPE, | ||
NavigationUnitType.TYPE_IMPERIAL)) | ||
.locale(getResources().getConfiguration().locale) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great call here using the configuration locale here instead of |
||
.build(); | ||
options.navigationOptions(navigationOptions); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ | |
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.text.DecimalFormat; | ||
import java.util.Locale; | ||
|
||
/** | ||
* A view that can be used to display upcoming maneuver information and control | ||
|
@@ -70,6 +70,7 @@ | |
public class InstructionView extends RelativeLayout implements FeedbackBottomSheetListener { | ||
|
||
public boolean isMuted; | ||
private final Locale locale; | ||
private ManeuverView upcomingManeuverView; | ||
private TextView upcomingDistanceText; | ||
private TextView upcomingPrimaryText; | ||
|
@@ -93,7 +94,6 @@ public class InstructionView extends RelativeLayout implements FeedbackBottomShe | |
private Animation rerouteSlideUpTop; | ||
private Animation rerouteSlideDownTop; | ||
private AnimationSet fadeInSlowOut; | ||
private DecimalFormat decimalFormat; | ||
private LegStep currentStep; | ||
private NavigationViewModel navigationViewModel; | ||
private boolean isRerouting; | ||
|
@@ -108,6 +108,7 @@ public InstructionView(Context context, @Nullable AttributeSet attrs) { | |
|
||
public InstructionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
locale = context.getResources().getConfiguration().locale; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace with extraction from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danesfeder I was thinking just pass the context to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @devotaaabel yeah that sounds good to me - just need to make sure we aren't calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danesfeder To localize the strings like Eric said we'll need the context, but it shouldn't be an issue anyway |
||
init(); | ||
} | ||
|
||
|
@@ -124,7 +125,6 @@ protected void onFinishInflate() { | |
initBackground(); | ||
initTurnLaneRecyclerView(); | ||
initDirectionsRecyclerView(); | ||
initDecimalFormat(); | ||
initAnimations(); | ||
} | ||
|
||
|
@@ -198,7 +198,7 @@ public void onChanged(@Nullable Boolean isOffRoute) { | |
@SuppressWarnings("UnusedDeclaration") | ||
public void update(RouteProgress routeProgress, @NavigationUnitType.UnitType int unitType) { | ||
if (routeProgress != null && !isRerouting) { | ||
InstructionModel model = new InstructionModel(routeProgress, decimalFormat, unitType); | ||
InstructionModel model = new InstructionModel(routeProgress, locale, unitType); | ||
updateViews(model); | ||
updateTextInstruction(model); | ||
} | ||
|
@@ -487,22 +487,14 @@ private void initTurnLaneRecyclerView() { | |
* Sets up the {@link RecyclerView} that is used to display the list of instructions. | ||
*/ | ||
private void initDirectionsRecyclerView() { | ||
instructionListAdapter = new InstructionListAdapter(); | ||
instructionListAdapter = new InstructionListAdapter(locale); | ||
rvInstructions.setAdapter(instructionListAdapter); | ||
rvInstructions.setHasFixedSize(true); | ||
rvInstructions.setNestedScrollingEnabled(true); | ||
rvInstructions.setItemAnimator(new DefaultItemAnimator()); | ||
rvInstructions.setLayoutManager(new LinearLayoutManager(getContext())); | ||
} | ||
|
||
/** | ||
* Initializes decimal format to be used to populate views with | ||
* distance remaining. | ||
*/ | ||
private void initDecimalFormat() { | ||
decimalFormat = new DecimalFormat(NavigationConstants.DECIMAL_FORMAT); | ||
} | ||
|
||
/** | ||
* Initializes all animations needed to show / hide views. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,12 @@ | |
|
||
import com.mapbox.services.android.navigation.ui.v5.NavigationViewModel; | ||
import com.mapbox.services.android.navigation.ui.v5.R; | ||
import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants; | ||
import com.mapbox.services.android.navigation.v5.navigation.NavigationUnitType; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
|
||
import java.text.DecimalFormat; | ||
import java.util.Locale; | ||
|
||
/** | ||
* A view with {@link android.support.design.widget.BottomSheetBehavior} | ||
|
@@ -32,13 +32,11 @@ | |
public class SummaryBottomSheet extends FrameLayout { | ||
|
||
private static final String EMPTY_STRING = ""; | ||
|
||
private final Locale locale; | ||
private TextView distanceRemainingText; | ||
private TextView timeRemainingText; | ||
private TextView arrivalTimeText; | ||
private ProgressBar rerouteProgressBar; | ||
|
||
private DecimalFormat decimalFormat; | ||
private boolean isRerouting; | ||
|
||
public SummaryBottomSheet(Context context) { | ||
|
@@ -51,6 +49,7 @@ public SummaryBottomSheet(Context context, AttributeSet attrs) { | |
|
||
public SummaryBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
locale = context.getResources().getConfiguration().locale; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here with the |
||
init(); | ||
} | ||
|
||
|
@@ -63,7 +62,6 @@ public SummaryBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) | |
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
bind(); | ||
initDecimalFormat(); | ||
} | ||
|
||
public void subscribe(NavigationViewModel navigationViewModel) { | ||
|
@@ -103,7 +101,7 @@ public void onChanged(@Nullable Boolean isOffRoute) { | |
@SuppressWarnings("UnusedDeclaration") | ||
public void update(RouteProgress routeProgress, @NavigationUnitType.UnitType int unitType) { | ||
if (routeProgress != null && !isRerouting) { | ||
SummaryModel model = new SummaryModel(routeProgress, decimalFormat, unitType); | ||
SummaryModel model = new SummaryModel(routeProgress, locale, unitType); | ||
arrivalTimeText.setText(model.getArrivalTime()); | ||
timeRemainingText.setText(model.getTimeRemaining()); | ||
distanceRemainingText.setText(model.getDistanceRemaining()); | ||
|
@@ -149,14 +147,6 @@ private void bind() { | |
rerouteProgressBar = findViewById(R.id.rerouteProgressBar); | ||
} | ||
|
||
/** | ||
* Initializes decimal format to be used to populate views with | ||
* distance remaining. | ||
*/ | ||
private void initDecimalFormat() { | ||
decimalFormat = new DecimalFormat(NavigationConstants.DECIMAL_FORMAT); | ||
} | ||
|
||
/** | ||
* Clears all {@link View}s. | ||
*/ | ||
|
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.
It'd be cool to get a default unit type based on the local here (if one isn't set in the preferences) with something like https://stackoverflow.com/questions/4898237/using-locale-settings-to-detect-wheter-to-use-imperial-units.
Current catch is the unit type isn't currently nullable in
MapboxNavigationOptions
, so we can switch that to@Nullable
and if someone doesn't set it, we dont set the preference and get the default here when setting the default value for theSharedPreference