Skip to content

Commit f41f0fa

Browse files
author
Devota Aabel
committed
Changed outdated abstract class to interface and fixed instructionView issues
1 parent a44030f commit f41f0fa

File tree

8 files changed

+32
-29
lines changed

8 files changed

+32
-29
lines changed

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/AbbreviationVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import com.mapbox.api.directions.v5.models.BannerComponents;
44
import com.mapbox.core.utils.TextUtils;
55

6-
class AbbreviationVerifier extends NodeVerifier {
6+
class AbbreviationVerifier implements NodeVerifier {
77
@Override
8-
boolean isNodeType(BannerComponents bannerComponents) {
8+
public boolean isNodeType(BannerComponents bannerComponents) {
99
return hasAbbreviation(bannerComponents);
1010
}
1111

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/ExitSignVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import com.mapbox.api.directions.v5.models.BannerComponents;
44

5-
class ExitSignVerifier extends NodeVerifier {
5+
class ExitSignVerifier implements NodeVerifier {
66

77
@Override
8-
boolean isNodeType(BannerComponents bannerComponents) {
8+
public boolean isNodeType(BannerComponents bannerComponents) {
99
return bannerComponents.type().equals("exit") || bannerComponents.type().equals("exit-number");
1010
}
1111
}

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/ImageVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import com.mapbox.api.directions.v5.models.BannerComponents;
66

7-
class ImageVerifier extends NodeVerifier {
7+
class ImageVerifier implements NodeVerifier {
88

99
@Override
10-
boolean isNodeType(BannerComponents bannerComponents) {
10+
public boolean isNodeType(BannerComponents bannerComponents) {
1111
return hasImageUrl(bannerComponents);
1212
}
1313

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/InstructionView.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,17 @@ public boolean isShowingInstructionList() {
314314
public void hideInstructionList() {
315315
rvInstructions.stopScroll();
316316
beginDelayedTransition();
317-
int orientation = getContext().getResources().getConfiguration().orientation;
318-
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
317+
if (isLandscape()) {
319318
updateLandscapeConstraintsTo(R.layout.instruction_layout);
320319
}
321320
instructionListLayout.setVisibility(GONE);
322321
onInstructionListVisibilityChanged(false);
323322
}
324323

324+
private boolean isLandscape() {
325+
return getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
326+
}
327+
325328
/**
326329
* Show the instruction list.
327330
* <p>
@@ -332,8 +335,7 @@ public void showInstructionList() {
332335
onInstructionListVisibilityChanged(true);
333336
instructionLayout.requestFocus();
334337
beginDelayedListTransition();
335-
int orientation = getContext().getResources().getConfiguration().orientation;
336-
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
338+
if (isLandscape()) {
337339
updateLandscapeConstraintsTo(R.layout.instruction_layout_alt);
338340
}
339341
instructionListLayout.setVisibility(VISIBLE);
@@ -435,7 +437,7 @@ private void initializeBackground() {
435437
int navigationViewListBackgroundColor = ThemeSwitcher.retrieveThemeColor(getContext(),
436438
R.attr.navigationViewListBackground);
437439
// Instruction Layout landscape - banner background
438-
if (getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
440+
if (isLandscape()) {
439441
View instructionLayoutManeuver = findViewById(R.id.instructionManeuverLayout);
440442
Drawable maneuverBackground = DrawableCompat.wrap(instructionLayoutManeuver.getBackground()).mutate();
441443
DrawableCompat.setTint(maneuverBackground, navigationViewBannerBackgroundColor);
@@ -525,9 +527,7 @@ private void showButtons() {
525527
}
526528

527529
private void initializeStepListClickListener() {
528-
int deviceOrientation = getContext().getResources().getConfiguration().orientation;
529-
boolean isOrientationLandscape = deviceOrientation == Configuration.ORIENTATION_LANDSCAPE;
530-
if (isOrientationLandscape) {
530+
if (isLandscape()) {
531531
initializeLandscapeListListener();
532532
} else {
533533
initializePortraitListListener();
@@ -710,8 +710,7 @@ private FragmentManager obtainSupportFragmentManager() {
710710
* @param percentBias to be set to the text layout
711711
*/
712712
private void adjustBannerTextVerticalBias(float percentBias) {
713-
int orientation = getContext().getResources().getConfiguration().orientation;
714-
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
713+
if (!isLandscape()) {
715714
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) instructionLayoutText.getLayoutParams();
716715
params.verticalBias = percentBias;
717716
instructionLayoutText.setLayoutParams(params);
@@ -748,6 +747,8 @@ private void updateDataFromInstruction(InstructionModel model) {
748747
* Sets new instruction text if found.
749748
*/
750749
private void updateDataFromBannerText(@NonNull BannerText primaryBannerText, BannerText secondaryBannerText) {
750+
updatePrimaryTextLandscapeWidthParam(isLandscape(), LinearLayout.LayoutParams.MATCH_PARENT);
751+
751752
if (secondaryBannerText == null) {
752753
loadPrimary(primaryBannerText);
753754
return;
@@ -766,17 +767,19 @@ private void loadPrimaryAndSecondary(BannerText primaryBannerText, BannerText se
766767
upcomingPrimaryText.setMaxLines(1);
767768
upcomingSecondaryText.setVisibility(VISIBLE);
768769
adjustBannerTextVerticalBias(0.65f);
769-
770-
upcomingPrimaryText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
771-
LinearLayout.LayoutParams.WRAP_CONTENT));
772770
loadTextWith(primaryBannerText, upcomingPrimaryText);
773-
upcomingPrimaryText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
774-
LinearLayout.LayoutParams.WRAP_CONTENT));
775-
776771

772+
updatePrimaryTextLandscapeWidthParam(isLandscape(), LinearLayout.LayoutParams.WRAP_CONTENT);
777773
loadTextWith(secondaryBannerText, upcomingSecondaryText);
778774
}
779775

776+
private void updatePrimaryTextLandscapeWidthParam(boolean isLandscape, int widthParam) {
777+
if (isLandscape) {
778+
upcomingPrimaryText.setLayoutParams(new LinearLayout.LayoutParams(widthParam,
779+
LinearLayout.LayoutParams.WRAP_CONTENT));
780+
}
781+
}
782+
780783
private void loadTextWith(BannerText bannerText, TextView textView) {
781784
InstructionLoader instructionLoader = createInstructionLoader(textView, bannerText);
782785
if (instructionLoader != null) {

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/NodeVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
import com.mapbox.api.directions.v5.models.BannerComponents;
44

5-
abstract class NodeVerifier {
6-
abstract boolean isNodeType(BannerComponents bannerComponents);
5+
interface NodeVerifier {
6+
boolean isNodeType(BannerComponents bannerComponents);
77
}

libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/instruction/TextVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import com.mapbox.api.directions.v5.models.BannerComponents;
44

5-
class TextVerifier extends NodeVerifier {
5+
class TextVerifier implements NodeVerifier {
66
@Override
7-
boolean isNodeType(BannerComponents bannerComponents) {
7+
public boolean isNodeType(BannerComponents bannerComponents) {
88
return bannerComponents.text() != null && !bannerComponents.text().isEmpty();
99
}
1010
}

libandroid-navigation-ui/src/main/res/layout-land/instruction_content_layout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<TextView
5656
android:id="@+id/stepPrimaryText"
57-
android:layout_width="wrap_content"
57+
android:layout_width="match_parent"
5858
android:layout_height="wrap_content"
5959
android:ellipsize="end"
6060
android:gravity="center_vertical"

libandroid-navigation-ui/src/test/java/com/mapbox/services/android/navigation/ui/v5/instruction/BannerComponentTreeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ class TestNode extends BannerComponentNode {
6060
}
6161
}
6262

63-
class TestVerifier extends NodeVerifier {
63+
class TestVerifier implements NodeVerifier {
6464

6565
@Override
66-
boolean isNodeType(BannerComponents bannerComponents) {
66+
public boolean isNodeType(BannerComponents bannerComponents) {
6767
return true;
6868
}
6969
}

0 commit comments

Comments
 (0)