Skip to content

Conversation

@devotaaabel
Copy link
Contributor

@devotaaabel devotaaabel commented Apr 25, 2018

#807 I moved the image loading logic from InstructionLoader into the new class InstructionImageLoader to separate concerns, and added AbbreviationCoordinator. Both new classes are accessed by InstructionLoader, which now coordinates the use of both new classes.

@devotaaabel devotaaabel added the ⚠️ DO NOT MERGE PR should not be merged! label Apr 25, 2018
@devotaaabel devotaaabel changed the title Devota abbreviations Dynamic abbreviations in banner instructions Apr 26, 2018
@devotaaabel devotaaabel closed this May 9, 2018
@devotaaabel devotaaabel reopened this May 9, 2018
@devotaaabel devotaaabel self-assigned this May 10, 2018
Copy link
Contributor

@danesfeder danesfeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple nit picks - overall this looks great. Nice work @devotaaabel

this.abbreviations = new HashMap<>();
this.textViewUtils = textViewUtils;
}

This comment was marked as resolved.


int currAbbreviationPriority = 0;
int maxAbbreviationPriority = Collections.max(abbreviations.keySet());
while (!textViewUtils.textFits(textView, bannerText) && (currAbbreviationPriority <= maxAbbreviationPriority)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pull this while out into a private method to make abbreviateBannerText more readable?

We can also extract !textViewUtils.textFits(textView, bannerText) && (currAbbreviationPriority <= maxAbbreviationPriority) into two booleans that better explain what is being checked by the loop.

Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking great. Well done @devotaaabel

Some comments to discuss before merging the PR.

* BannerComponents containing abbreviation information and given a list of BannerComponentNodes,
* constructed by InstructionLoader.
*/
public class AbbreviationCoordinator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to expose this class and its methods publicly?

Classes are private until the opposite is proved.

😂
It's only consumed by InstructionLoader (+ tests) which is in the same package so I guess we could make it package-private. Also the IDE hints you about doing that (constructors).

private Map<Integer, List<Integer>> abbreviations;
private TextViewUtils textViewUtils;

public AbbreviationCoordinator(TextViewUtils textViewUtils) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access can be package-private


/**
* Using the abbreviations HashMap which should already be populated, abbreviates the text in the
* bannerConmponentNodes until the text fits the given TextView.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT Typo *bannerConmponentNodes

*/
public void addPriorityInfo(BannerComponents bannerComponents, int index) {
int abbreviationPriority = bannerComponents.abbreviationPriority();
if (abbreviations.get(Integer.valueOf(abbreviationPriority)) == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary boxing 'Integer.valueOf(abbreviationPriority)'

int maxAbbreviationPriority = Collections.max(abbreviations.keySet());

while (shouldKeepAbbreviating(textView, bannerText, currAbbreviationPriority, maxAbbreviationPriority)) {
List<Integer> indices = abbreviations.get(new Integer(currAbbreviationPriority++));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary boxing 'new Integer(currAbbreviationPriority++)'

private BannerShield shield;
private InstructionLoadedCallback instructionLoadedCallback;

InstructionTarget(TextView textView, Spannable instructionSpannable,

This comment was marked as resolved.

import android.graphics.Paint;
import android.widget.TextView;

public class TextViewUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to expose this class and its method publicly?

Classes are private until the opposite is proved.

😂
It's only consumed by AbbreviationCoordinator (+ tests) so I guess this should live under com.mapbox.services.android.navigation.ui.v5.instruction package.

public class InstructionLoaderTest {

@Test
public void testPriorityInfoIsAdded() {

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.


public class AbbreviationCoordinatorTest extends BaseTest {
@Test
public void textIsAbbreviatedWhenItDoesntFit() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency we should name the tests following the same style (e.g. onResetCamera_trackingIsResumed).
In any case, test prefix is not necessary because it's implicit with the usage of @Test annotation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally is good to structure the tests following the triple A 👀 https://speakerdeck.com/guardiola31337/elegant-unit-testing-mobilization-2016?slide=40 http://wiki.c2.com/?ArrangeActAssert

Here we're including the Act inside the Assert. It'd be great to have them separated and take advantage of giving great names to variables so it's easy to understand what's going on.

AbbreviationCoordinator abbreviationCoordinator = new AbbreviationCoordinator(textViewUtils);
abbreviationCoordinator.addPriorityInfo(bannerComponents, 0);
List<InstructionLoader.BannerComponentNode> bannerComponentNodes = new ArrayList<>();
bannerComponentNodes.add(new AbbreviationCoordinator.AbbreviationNode(bannerComponents, 0));

Should be in the Arrange part.

This applies to other tests included in AbbreviationCoordinatorTest.


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

public class BannerComponentsFaker {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why BannerComponentsFaker needs to be public?

Classes are private until the opposite is proved.

😂
I guess we could make it package-private, it's only consumed by the tests.

@devotaaabel devotaaabel force-pushed the devota-abbreviations branch from 7e0e2c8 to f2b0dd3 Compare May 18, 2018 14:44
@devotaaabel devotaaabel force-pushed the devota-abbreviations branch from f2b0dd3 to 4a8427b Compare May 18, 2018 14:45
Copy link
Contributor

@danesfeder danesfeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢 Awesome work @devotaaabel!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants