Skip to content

Commit b6a0fde

Browse files
author
Devota Aabel
committed
Updated InstructionLoader APIs to be public and to take in a BannerText object instead of a list of BannerComponents
1 parent 4ed2634 commit b6a0fde

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,39 @@
2525
* If a shield URL is found, {@link Picasso} is used to load the image. Then, once the image is loaded,
2626
* a new {@link ImageSpan} is created and set to the appropriate position of the {@link Spannable}/
2727
*/
28-
class InstructionLoader {
28+
public class InstructionLoader {
2929
private ImageCoordinator imageCoordinator;
3030
private AbbreviationCoordinator abbreviationCoordinator;
3131
private TextView textView;
3232
private List<BannerComponentNode> bannerComponentNodes;
3333

34-
InstructionLoader(TextView textView, @NonNull List<BannerComponents> bannerComponents) {
35-
this(textView, bannerComponents, ImageCoordinator.getInstance(), new AbbreviationCoordinator());
34+
/**
35+
* Creates an InstructionLoader which can handle highway shields and also takes into account
36+
* abbreviations.
37+
*
38+
* @param textView to populate with instruction
39+
* @param bannerText containing components to populate into textView
40+
*/
41+
public InstructionLoader(TextView textView, BannerText bannerText) {
42+
this(textView, bannerText, ImageCoordinator.getInstance(), new AbbreviationCoordinator());
3643
}
3744

38-
InstructionLoader(TextView textView, @NonNull List<BannerComponents> bannerComponents,
45+
InstructionLoader(TextView textView, @NonNull BannerText bannerText,
3946
ImageCoordinator imageCoordinator, AbbreviationCoordinator abbreviationCoordinator) {
4047
this.abbreviationCoordinator = abbreviationCoordinator;
4148
this.textView = textView;
4249
bannerComponentNodes = new ArrayList<>();
4350
this.imageCoordinator = imageCoordinator;
4451

45-
bannerComponentNodes = parseBannerComponents(bannerComponents);
52+
bannerComponentNodes = parseBannerComponents(bannerText.components());
4653
}
4754

4855
/**
4956
* Takes the given components from the {@link BannerText} and creates
5057
* a new {@link Spannable} with text / {@link ImageSpan}s which is loaded
5158
* into the given {@link TextView}.
5259
*/
53-
void loadInstruction() {
60+
public void loadInstruction() {
5461
setText(textView, bannerComponentNodes);
5562
loadImages(textView, bannerComponentNodes);
5663
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ private void distanceText(InstructionModel model) {
598598

599599
private InstructionLoader createInstructionLoader(TextView textView, BannerText bannerText) {
600600
if (hasComponents(bannerText)) {
601-
return new InstructionLoader(textView, bannerText.components());
601+
return new InstructionLoader(textView, bannerText);
602602
} else {
603603
return null;
604604
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.widget.TextView;
44

55
import com.mapbox.api.directions.v5.models.BannerComponents;
6+
import com.mapbox.api.directions.v5.models.BannerText;
67

78
import org.junit.Test;
89

@@ -27,8 +28,10 @@ public void onInstructionLoaderCreated_priorityInfoIsAdded() {
2728
.build();
2829
List<BannerComponents> bannerComponentsList = new ArrayList<>();
2930
bannerComponentsList.add(bannerComponents);
31+
BannerText bannerText = mock(BannerText.class);
32+
when(bannerText.components()).thenReturn(bannerComponentsList);
3033

31-
new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
34+
new InstructionLoader(textView, bannerText, imageCoordinator, abbreviationCoordinator);
3235

3336
verify(abbreviationCoordinator).addPriorityInfo(bannerComponents, 0);
3437
}
@@ -43,8 +46,10 @@ public void onInstructionLoaderCreated_shieldInfoIsAdded() {
4346
.build();
4447
List<BannerComponents> bannerComponentsList = new ArrayList<>();
4548
bannerComponentsList.add(bannerComponents);
49+
BannerText bannerText = mock(BannerText.class);
50+
when(bannerText.components()).thenReturn(bannerComponentsList);
4651

47-
new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
52+
new InstructionLoader(textView, bannerText, imageCoordinator, abbreviationCoordinator);
4853

4954
verify(imageCoordinator).addShieldInfo(bannerComponents, 0);
5055
}
@@ -62,7 +67,10 @@ public void onLoadInstruction_textIsAbbreviated() {
6267
bannerComponentsList.add(bannerComponents);
6368
String abbreviatedText = "abbreviated text";
6469
when(abbreviationCoordinator.abbreviateBannerText(any(List.class), any(TextView.class))).thenReturn(abbreviatedText);
65-
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
70+
BannerText bannerText = mock(BannerText.class);
71+
when(bannerText.components()).thenReturn(bannerComponentsList);
72+
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerText, imageCoordinator,
73+
abbreviationCoordinator);
6674

6775
instructionLoader.loadInstruction();
6876

@@ -81,7 +89,10 @@ public void onLoadInstruction_imagesAreLoaded() {
8189
bannerComponentsList.add(bannerComponents);
8290
String abbreviatedText = "abbreviated text";
8391
when(abbreviationCoordinator.abbreviateBannerText(any(List.class), any(TextView.class))).thenReturn(abbreviatedText);
84-
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
92+
BannerText bannerText = mock(BannerText.class);
93+
when(bannerText.components()).thenReturn(bannerComponentsList);
94+
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerText, imageCoordinator,
95+
abbreviationCoordinator);
8596

8697
instructionLoader.loadInstruction();
8798

0 commit comments

Comments
 (0)