Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -28,6 +28,7 @@
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand All @@ -36,6 +37,7 @@
@Ignore public class PlaceAutocompleteFragmentTest {

private static final String ACCESS_TOKEN = "pk.XXX";
private static final Integer HISTORY_COUNT = 5;

private PlaceAutocompleteFragment placeAutocompleteFragment;

Expand All @@ -53,6 +55,7 @@ public void init() {

// For style test
builder.backgroundColor(Color.BLUE);
builder.historyCount(HISTORY_COUNT);
builder.hint("foobar");

placeAutocompleteFragment = PlaceAutocompleteFragment.newInstance(
Expand All @@ -68,6 +71,11 @@ public void newInstance_doesPutAccessTokenInBundle() throws Exception {
assertThat(placeAutocompleteFragment.getAccessToken(), equalTo(ACCESS_TOKEN));
}

@Test
public void styleView_setHistoryCountIsCorrect() throws Exception {
assertThat(placeAutocompleteFragment.getHistoryCount(), equalTo(HISTORY_COUNT));
}

@Test
public void onCreateView_doesInflateCorrectModeView() throws Exception {
onView(withId(R.id.cardView)).check(matches(isDisplayed()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public abstract class PlaceOptions implements Parcelable {
*/
public abstract int limit();

/**
* Limit the number of results returned. The default is the maximum number of
* historical searches already saved by the Places plugin.
*
* @return the number of past search results returned by the geocoder
* @since 0.9.0
*/
@Nullable
public abstract Integer historyCount();

/**
* Limit results to a bounding box. Options are in the format {@code minX,minY,maxX,maxY}.
*
Expand Down Expand Up @@ -245,6 +255,15 @@ public Builder geocodingTypes(@NonNull @GeocodingTypeCriteria String... geocodin
*/
public abstract Builder limit(@IntRange(from = 1, to = 10) int limit);

/**
* Limit the number of past search results shown.
*
* @param historyCount the number of past historical searches shown before a search starts.
* @return this builder instance for chaining options together
* @since 0.9.0
*/
public abstract Builder historyCount(@Nullable @IntRange(from = 0) Integer historyCount);

/**
* Limit results to a bounding box.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class PlaceAutocompleteFragment extends Fragment implements ResultClickCa
private SearchView searchView;
private View dropShadowView;
private String accessToken;
private Integer historyCount;
private View rootView;
private int mode;

Expand Down Expand Up @@ -204,8 +205,15 @@ private void bindViews() {
void updateSearchHistoryView(@Nullable List<SearchHistoryEntity> searchHistoryEntities) {
searchHistoryView.getResultsList().clear();
if (searchHistoryEntities != null) {
for (SearchHistoryEntity entity : searchHistoryEntities) {
searchHistoryView.getResultsList().add(entity.getCarmenFeature());
if (placeOptions.historyCount() != null) {
historyCount = placeOptions.historyCount();
for (int x = 0; x < historyCount; x++) {
searchHistoryView.getResultsList().add(searchHistoryEntities.get(x).getCarmenFeature());
}
} else {
for (SearchHistoryEntity entity : searchHistoryEntities) {
searchHistoryView.getResultsList().add(entity.getCarmenFeature());
}
}
}
searchHistoryView.notifyDataSetChanged();
Expand Down Expand Up @@ -269,4 +277,8 @@ public void onChanged(@Nullable List<SearchHistoryEntity> searchHistoryEntities)
public String getAccessToken() {
return accessToken;
}

public Integer getHistoryCount() {
return historyCount;
}
}