Search in sources :

Example 1 with NearbyPage

use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.

the class NearbyFragment method onStyleLoaded.

@Override
public void onStyleLoaded(@NonNull Style style) {
    if (!isAdded() || mapboxMap == null) {
        return;
    }
    symbolManager = new SymbolManager(mapView, mapboxMap, style);
    symbolManager.setIconAllowOverlap(true);
    symbolManager.setTextAllowOverlap(true);
    symbolManager.addClickListener(symbol -> {
        NearbyPage page = findNearbyPageFromSymbol(symbol);
        if (page != null) {
            onLoadPage(new HistoryEntry(page.getTitle(), HistoryEntry.SOURCE_NEARBY), page.getLocation());
        }
    });
    enableUserLocationMarker();
    if (lastCameraPos != null) {
        mapboxMap.setCameraPosition(lastCameraPos);
    } else {
        goToUserLocationOrPromptPermissions();
    }
    showNearbyPages();
}
Also used : SymbolManager(com.mapbox.mapboxsdk.plugins.annotation.SymbolManager) HistoryEntry(org.wikipedia.history.HistoryEntry) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage)

Example 2 with NearbyPage

use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.

the class NearbyFragment method showNearbyPages.

private void showNearbyPages() {
    if (mapboxMap == null || getActivity() == null) {
        return;
    }
    getActivity().invalidateOptionsMenu();
    symbolManager.delete(currentSymbols);
    currentSymbols.clear();
    List<SymbolOptions> optionsList = new ArrayList<>();
    for (NearbyPage item : currentResults.getList()) {
        if (item.getLocation() != null) {
            optionsList.add(getSymbolOptions(item));
        }
    }
    currentSymbols = symbolManager.create(optionsList);
}
Also used : ArrayList(java.util.ArrayList) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) SymbolOptions(com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)

Example 3 with NearbyPage

use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-wikipedia by wikimedia.

the class NearbyUnitTest method constructNearbyPage.

private NearbyPage constructNearbyPage(@NonNull String title, double lat, double lon) {
    Location location = new Location("");
    location.setLatitude(lat);
    location.setLongitude(lon);
    return new NearbyPage(title, location);
}
Also used : NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location)

Example 4 with NearbyPage

use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-commons by commons-app.

the class NearbyUnitTest method constructNearbyPage.

private NearbyPage constructNearbyPage(@NonNull String title, double lat, double lon) {
    Location location = new Location("");
    location.setLatitude(lat);
    location.setLongitude(lon);
    return new NearbyPage(new PageTitle(title, TEST_WIKI_SITE), location);
}
Also used : PageTitle(org.wikipedia.page.PageTitle) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location)

Example 5 with NearbyPage

use of org.wikipedia.dataclient.mwapi.NearbyPage in project apps-android-commons by commons-app.

the class NearbyUnitTest method testSortWithNullLocations.

@Test
public void testSortWithNullLocations() {
    final Location location = null;
    nearbyPages.add(new NearbyPage(new PageTitle("d", TEST_WIKI_SITE), location));
    nearbyPages.add(new NearbyPage(new PageTitle("e", TEST_WIKI_SITE), location));
    calcDistances(nearbyPages);
    Collections.sort(nearbyPages, new NearbyDistanceComparator());
    assertThat("a", is(nearbyPages.get(0).getTitle().getDisplayText()));
    assertThat("b", is(nearbyPages.get(1).getTitle().getDisplayText()));
    assertThat("c", is(nearbyPages.get(2).getTitle().getDisplayText()));
    // the two null location values come last but in the same order as from the original list:
    assertThat("d", is(nearbyPages.get(3).getTitle().getDisplayText()));
    assertThat("e", is(nearbyPages.get(4).getTitle().getDisplayText()));
}
Also used : PageTitle(org.wikipedia.page.PageTitle) NearbyPage(org.wikipedia.dataclient.mwapi.NearbyPage) Location(android.location.Location) Test(org.junit.Test)

Aggregations

NearbyPage (org.wikipedia.dataclient.mwapi.NearbyPage)9 Location (android.location.Location)6 Test (org.junit.Test)4 PageTitle (org.wikipedia.page.PageTitle)3 SymbolManager (com.mapbox.mapboxsdk.plugins.annotation.SymbolManager)1 SymbolOptions (com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions)1 ArrayList (java.util.ArrayList)1 HistoryEntry (org.wikipedia.history.HistoryEntry)1