<commit_before>package org.wikipedia.nearby;

import org.wikipedia.R;
import org.wikipedia.Site;
import org.wikipedia.WikipediaApp;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageActivity;
import org.wikipedia.page.PageTitle;
import org.wikipedia.util.FeedbackUtil;
import org.wikipedia.util.PermissionUtil;
import org.wikipedia.util.log.L;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Sprite;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.views.MapView;

import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.PointF;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import static org.wikipedia.util.DimenUtil.getContentTopOffsetPx;

/**
 * Displays a list of nearby pages.
 */
public class NearbyFragment extends Fragment {
    private static final String NEARBY_LAST_RESULT = "lastRes";
    private static final String NEARBY_CURRENT_LOCATION = "currentLoc";
    private static final int GO_TO_LOCATION_PERMISSION_REQUEST = 50;

    private final List<Marker> mMarkerList = new ArrayList<>();

    private MapView mapView;

    private Sprite markerIconPassive;

    private Site site;
    private NearbyResult lastResult;
    @Nullable private Location currentLocation;

    private boolean firstLocationLock = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        site = WikipediaApp.getInstance().getPrimarySite();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_nearby, container, false);
        rootView.setPadding(0, getContentTopOffsetPx(getActivity()), 0, 0);

        mapView = (MapView) rootView.findViewById(R.id.mapview);
        mapView.setAccessToken(getString(R.string.mapbox_public_token));
        markerIconPassive = mapView.getSpriteFactory().fromResource(R.drawable.ic_map_marker);

        // TODO: pass savedInstanceState into mapView.onCreate once the MapView starts managing
        // runtime permissions in a better way. This way, the MapView will start uninitialized
        // so that we get a chance to query for runtime permissions before enabling the user's
        // location in the MapView.
        mapView.onCreate(null);

        rootView.findViewById(R.id.user_location_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkLocationPermissionsToGoToUserLocation();
            }
        });

        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);

        if (lastResult != null) {
            showNearbyPages(lastResult);
        } else if (savedInstanceState != null) {
            currentLocation = savedInstanceState.getParcelable(NEARBY_CURRENT_LOCATION);
            if (currentLocation != null) {
                lastResult = savedInstanceState.getParcelable(NEARBY_LAST_RESULT);
                showNearbyPages(lastResult);
            }
        }

        setRefreshingState(true);
        initializeMap();
        checkLocationPermissionsToGoToUserLocation();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
        if (lastResult != null) {
            outState.putParcelable(NEARBY_CURRENT_LOCATION, currentLocation);
            outState.putParcelable(NEARBY_LAST_RESULT, lastResult);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        mapView.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
        mapView.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

    private void initializeMap() {
        mapView.setStyleUrl("asset://mapstyle.json");
        mapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);

        mapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(@Nullable Location location) {
                makeUseOfNewLocation(location);
                if (!firstLocationLock) {
                    goToUserLocation();
                    firstLocationLock = true;
                }
            }
        });

        mapView.setOnScrollListener(new MapView.OnScrollListener() {
            @Override
            public void onScroll() {
                fetchNearbyPages();
            }
        });

        mapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(@NonNull Marker marker) {
                NearbyPage page = findNearbyPageFromMarker(marker);
                if (page != null) {
                    PageTitle title = new PageTitle(page.getTitle(), site, page.getThumblUrl());<commit_msg>Hide MapBox logo in Nearby.<commit_after>package org.wikipedia.nearby;

import org.wikipedia.R;
import org.wikipedia.Site;
import org.wikipedia.WikipediaApp;
import org.wikipedia.history.HistoryEntry;
import org.wikipedia.page.PageActivity;
import org.wikipedia.page.PageTitle;
import org.wikipedia.util.FeedbackUtil;
import org.wikipedia.util.PermissionUtil;
import org.wikipedia.util.log.L;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Sprite;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngZoom;
import com.mapbox.mapboxsdk.views.MapView;

import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.PointF;
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import static org.wikipedia.util.DimenUtil.getContentTopOffsetPx;

/**
 * Displays a list of nearby pages.
 */
public class NearbyFragment extends Fragment {
    private static final String NEARBY_LAST_RESULT = "lastRes";
    private static final String NEARBY_CURRENT_LOCATION = "currentLoc";
    private static final int GO_TO_LOCATION_PERMISSION_REQUEST = 50;

    private final List<Marker> mMarkerList = new ArrayList<>();

    private MapView mapView;

    private Sprite markerIconPassive;

    private Site site;
    private NearbyResult lastResult;
    @Nullable private Location currentLocation;

    private boolean firstLocationLock = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        site = WikipediaApp.getInstance().getPrimarySite();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_nearby, container, false);
        rootView.setPadding(0, getContentTopOffsetPx(getActivity()), 0, 0);

        mapView = (MapView) rootView.findViewById(R.id.mapview);
        mapView.setAccessToken(getString(R.string.mapbox_public_token));
        markerIconPassive = mapView.getSpriteFactory().fromResource(R.drawable.ic_map_marker);

        // TODO: pass savedInstanceState into mapView.onCreate once the MapView starts managing
        // runtime permissions in a better way. This way, the MapView will start uninitialized
        // so that we get a chance to query for runtime permissions before enabling the user's
        // location in the MapView.
        mapView.onCreate(null);

        rootView.findViewById(R.id.user_location_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkLocationPermissionsToGoToUserLocation();
            }
        });

        return rootView;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setHasOptionsMenu(true);

        if (lastResult != null) {
            showNearbyPages(lastResult);
        } else if (savedInstanceState != null) {
            currentLocation = savedInstanceState.getParcelable(NEARBY_CURRENT_LOCATION);
            if (currentLocation != null) {
                lastResult = savedInstanceState.getParcelable(NEARBY_LAST_RESULT);
                showNearbyPages(lastResult);
            }
        }

        setRefreshingState(true);
        initializeMap();
        checkLocationPermissionsToGoToUserLocation();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
        if (lastResult != null) {
            outState.putParcelable(NEARBY_CURRENT_LOCATION, currentLocation);
            outState.putParcelable(NEARBY_LAST_RESULT, lastResult);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        mapView.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
        mapView.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mapView.onLowMemory();
    }

    private void initializeMap() {
        mapView.setStyleUrl("asset://mapstyle.json");
        mapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE);
        mapView.setLogoVisibility(View.GONE);
        mapView.setAttributionVisibility(View.GONE);

        mapView.setOnMyLocationChangeListener(new MapView.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(@Nullable Location location) {
                makeUseOfNewLocation(location);
                if (!firstLocationLock) {
                    goToUserLocation();
                    firstLocationLock = true;
                }
            }
        });

        mapView.setOnScrollListener(new MapView.OnScrollListener() {
            @Override
            public void onScroll() {
                fetchNearbyPages();
            }
        });

        mapView.setOnMarkerClickListener(new MapView.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(@NonNull Marker marker) {
                NearbyPage page = findNearbyPageFromMarker(marker);
                if (page != null) {
                    PageTitle title = new PageTitle(page.getTitle(), site, page.getThumblUrl());
{'fraction_non_alphanumeric': 0.08845107575632677, 'fraction_numerical': 0.001154068090017311, 'mean_word_length': 2.9160748870238864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '675094', 'n_tokens_mistral': 3340, 'n_tokens_neox': 3206, 'n_words': 659}