<commit_before>package org.redcross.openmapkit;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Environment;
import android.widget.Toast;

import com.mapbox.mapboxsdk.tileprovider.tilesource.MBTilesLayer;
import com.mapbox.mapboxsdk.tileprovider.tilesource.WebSourceTileLayer;
import com.mapbox.mapboxsdk.views.MapView;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by <NAME> & <NAME> on 3/17/15.
 *
 * <EMAIL>
 * <EMAIL>
 * * * * * * 
 */
public class Basemap {
    
    private static final String PREVIOUS_BASEMAP = "org.redcross.openmapkit.PREVIOUS_BASEMAP";
    
    private MapActivity mapActivity;
    private MapView mapView;
    private Context context;
    
    private String selectedMBTilesFile;
    
    public Basemap(MapActivity mapActivity) {
        this.mapActivity = mapActivity;
        this.mapView = mapActivity.getMapView();
        this.context = mapActivity.getApplicationContext();

        if (Connectivity.isConnected(context)) {
            addOnlineDataSources();
        } else {
            presentMBTilesOptions();
        }
    }
    
    private void addOnlineDataSources() {
        //create OSM tile layer
        String defaultTilePID = mapActivity.getString(R.string.defaultTileLayerPID);
        String defaultTileURL = mapActivity.getString(R.string.defaultTileLayerURL);
        String defaultTileName = mapActivity.getString(R.string.defaultTileLayerName);
        String defaultTileAttribution = mapActivity.getString(R.string.defaultTileLayerAttribution);

        WebSourceTileLayer ws = new WebSourceTileLayer(defaultTilePID, defaultTileURL);
        ws.setName(defaultTileName).setAttribution(defaultTileAttribution);

        //add OSM tile layer to map
        mapView.setTileSource(ws);
    }
    
    public void presentMBTilesOptions() {
        //shared preferences private to mapActivity
        final SharedPreferences sharedPreferences = mapActivity.getPreferences(Context.MODE_PRIVATE);
        String previousMBTilesChoice = sharedPreferences.getString(PREVIOUS_BASEMAP, null);

        //create an array of all mbtile options
        final ArrayList<String> mbtilesFileNames = new ArrayList<>();

        //when device is connected, HOT OSM Basemap is the first option
        if(Connectivity.isConnected(context)) {
            mbtilesFileNames.add(mapActivity.getString(R.string.hotOSMOptionTitle));
        }<commit_msg>Fixes #34 Dont Troll User with Basemap Choice<commit_after>package org.redcross.openmapkit;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Environment;
import android.widget.Toast;

import com.mapbox.mapboxsdk.tileprovider.tilesource.MBTilesLayer;
import com.mapbox.mapboxsdk.tileprovider.tilesource.WebSourceTileLayer;
import com.mapbox.mapboxsdk.views.MapView;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by <NAME> & <NAME> on 3/17/15.
 *
 * <EMAIL>
 * <EMAIL>
 * * * * * * 
 */
public class Basemap {
    
    private static final String PREVIOUS_BASEMAP = "org.redcross.openmapkit.PREVIOUS_BASEMAP";
    
    private MapActivity mapActivity;
    private MapView mapView;
    private Context context;
    
    private static String selectedMBTilesFile;
    
    public Basemap(MapActivity mapActivity) {
        this.mapActivity = mapActivity;
        this.mapView = mapActivity.getMapView();
        this.context = mapActivity.getApplicationContext();

        if (selectedMBTilesFile != null) {
            addOfflineDataSources(selectedMBTilesFile);
        } else if (Connectivity.isConnected(context)) {
            addOnlineDataSources();
        } else {
            presentMBTilesOptions();
        }
    }
    
    private void addOnlineDataSources() {
        //create OSM tile layer
        String defaultTilePID = mapActivity.getString(R.string.defaultTileLayerPID);
        String defaultTileURL = mapActivity.getString(R.string.defaultTileLayerURL);
        String defaultTileName = mapActivity.getString(R.string.defaultTileLayerName);
        String defaultTileAttribution = mapActivity.getString(R.string.defaultTileLayerAttribution);

        WebSourceTileLayer ws = new WebSourceTileLayer(defaultTilePID, defaultTileURL);
        ws.setName(defaultTileName).setAttribution(defaultTileAttribution);

        selectedMBTilesFile = null;
        
        //add OSM tile layer to map
        mapView.setTileSource(ws);
    }
    
    public void presentMBTilesOptions() {
        //shared preferences private to mapActivity
        final SharedPreferences sharedPreferences = mapActivity.getPreferences(Context.MODE_PRIVATE);
        String previousMBTilesChoice = sharedPreferences.getString(PREVIOUS_BASEMAP, null);

        //create an array of all mbtile options
        final ArrayList<String> mbtilesFileNames = new ArrayList<>();

        //when device is connected, HOT OSM Basemap is the first option
        if(Connectivity.isConnected(context)) {
            mbtilesFileNames.add(mapActivity.getString(R.string.hotOSMOptionTitle));
        }
{'fraction_non_alphanumeric': 0.08565965583173996, 'fraction_numerical': 0.002294455066921606, 'mean_word_length': 3.4368108566581848, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4622868', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1438, 'n_words': 295}