Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,39 @@
* If a shield URL is found, {@link Picasso} is used to load the image. Then, once the image is loaded,
* a new {@link ImageSpan} is created and set to the appropriate position of the {@link Spannable}/
*/
class InstructionLoader {
public class InstructionLoader {
private ImageCoordinator imageCoordinator;
private AbbreviationCoordinator abbreviationCoordinator;
private TextView textView;
private List<BannerComponentNode> bannerComponentNodes;

InstructionLoader(TextView textView, @NonNull List<BannerComponents> bannerComponents) {
this(textView, bannerComponents, ImageCoordinator.getInstance(), new AbbreviationCoordinator());
/**
* Creates an InstructionLoader which can handle highway shields and also takes into account
* abbreviations.
*
* @param textView to populate with instruction
* @param bannerText containing components to populate into textView
*/
public InstructionLoader(TextView textView, BannerText bannerText) {
this(textView, bannerText, ImageCoordinator.getInstance(), new AbbreviationCoordinator());
}

InstructionLoader(TextView textView, @NonNull List<BannerComponents> bannerComponents,
InstructionLoader(TextView textView, @NonNull BannerText bannerText,
ImageCoordinator imageCoordinator, AbbreviationCoordinator abbreviationCoordinator) {
this.abbreviationCoordinator = abbreviationCoordinator;
this.textView = textView;
bannerComponentNodes = new ArrayList<>();
this.imageCoordinator = imageCoordinator;

bannerComponentNodes = parseBannerComponents(bannerComponents);
bannerComponentNodes = parseBannerComponents(bannerText.components());
}

/**
* Takes the given components from the {@link BannerText} and creates
* a new {@link Spannable} with text / {@link ImageSpan}s which is loaded
* into the given {@link TextView}.
*/
void loadInstruction() {
public void loadInstruction() {
setText(textView, bannerComponentNodes);
loadImages(textView, bannerComponentNodes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private void distanceText(InstructionModel model) {

private InstructionLoader createInstructionLoader(TextView textView, BannerText bannerText) {
if (hasComponents(bannerText)) {
return new InstructionLoader(textView, bannerText.components());
return new InstructionLoader(textView, bannerText);
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.widget.TextView;

import com.mapbox.api.directions.v5.models.BannerComponents;
import com.mapbox.api.directions.v5.models.BannerText;

import org.junit.Test;

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

new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
new InstructionLoader(textView, bannerText, imageCoordinator, abbreviationCoordinator);

verify(abbreviationCoordinator).addPriorityInfo(bannerComponents, 0);
}
Expand All @@ -43,8 +46,10 @@ public void onInstructionLoaderCreated_shieldInfoIsAdded() {
.build();
List<BannerComponents> bannerComponentsList = new ArrayList<>();
bannerComponentsList.add(bannerComponents);
BannerText bannerText = mock(BannerText.class);
when(bannerText.components()).thenReturn(bannerComponentsList);

new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
new InstructionLoader(textView, bannerText, imageCoordinator, abbreviationCoordinator);

verify(imageCoordinator).addShieldInfo(bannerComponents, 0);
}
Expand All @@ -62,7 +67,10 @@ public void onLoadInstruction_textIsAbbreviated() {
bannerComponentsList.add(bannerComponents);
String abbreviatedText = "abbreviated text";
when(abbreviationCoordinator.abbreviateBannerText(any(List.class), any(TextView.class))).thenReturn(abbreviatedText);
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
BannerText bannerText = mock(BannerText.class);
when(bannerText.components()).thenReturn(bannerComponentsList);
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerText, imageCoordinator,
abbreviationCoordinator);

instructionLoader.loadInstruction();

Expand All @@ -81,7 +89,10 @@ public void onLoadInstruction_imagesAreLoaded() {
bannerComponentsList.add(bannerComponents);
String abbreviatedText = "abbreviated text";
when(abbreviationCoordinator.abbreviateBannerText(any(List.class), any(TextView.class))).thenReturn(abbreviatedText);
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerComponentsList, imageCoordinator, abbreviationCoordinator);
BannerText bannerText = mock(BannerText.class);
when(bannerText.components()).thenReturn(bannerComponentsList);
InstructionLoader instructionLoader = new InstructionLoader(textView, bannerText, imageCoordinator,
abbreviationCoordinator);

instructionLoader.loadInstruction();

Expand Down