<commit_before>package com.harrymt.productivitymapping;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.ui.IconGenerator;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

import android.support.v4.app.ListFragment;

public class MapFragment extends Fragment {

    private ListFragment mList;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_map, container, false);
        loadZonesToListView();
        return v;
    }

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

    // Reload all zones from the DB again
    private void loadZonesToListView() {

        // TODO add empty list item to zones that says no zones, go create one.
        // Set a custom list adapter for a list of locations
        ArrayList<Zone> zs = getZones();
        Zone[] zones;
        // Convert to array
        zones = new Zone[zs.size()]; int i = 0;for (Zone z : zs) { zones[i] = z; i++;}

        mList = (ListFragment) getChildFragmentManager().findFragmentById(R.id.list);
        mList.setListAdapter(new MapAdapter(getActivity(), zones));
        // Set a RecyclerListener to clean up MapView from ListView
        mList.getListView().setRecyclerListener(mRecycleListener);
    }

    /**
     * Adapter that displays a name and {@link com.google.android.gms.maps.MapView} for each item.
     * The layout is defined in <code>lite_list_demo_row.xml</code>. It contains a MapView
     * that is programatically initialised in
     * {@link #getView(int, android.view.View, android.view.ViewGroup)}
     */
    private class MapAdapter extends ArrayAdapter<Zone> {

        private final HashSet<MapView> mMaps = new HashSet<>();

        public MapAdapter(Context context, Zone[] locations) {
            super(context, R.layout.list_map_row, R.id.tvZoneName, locations);
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            ViewHolder holder;

            // Check if a view can be reused, otherwise inflate a layout and set up the view holder
            if (row == null) {
                // Inflate view from layout file
                row = getActivity().getLayoutInflater().inflate(R.layout.list_map_row, null);

                // Set up holder and assign it to the View
                holder = new ViewHolder();
                holder.mapView = (MapView) row.findViewById(R.id.lite_listrow_map);
                holder.name = (TextView) row.findViewById(R.id.tvZoneName);
                holder.appsToBlock = (TextView) row.findViewById(R.id.tvZoneAppsToBlock);
                holder.keywords = (TextView) row.findViewById(R.id.tvZoneKeywords);
                holder.editZone = (Button) row.findViewById(R.id.btnEditZone);
                holder.deleteZone = (Button) row.findViewById(R.id.btnDeleteZone);


                // Set holder as tag for row for more efficient access.
                row.setTag(holder);

                // Initialise the MapView
                holder.initializeMapView();

                // Keep track of MapView
                mMaps.add(holder.mapView);
            } else {
                // View has already been initialised, get its holder
                holder = (ViewHolder) row.getTag();
            }

            // Get the NamedLocation for this zone and attach it to the MapView
            Zone zone = getItem(position);
            holder.mapView.setTag(zone);

            // Ensure the map has been initialised by the on map ready callback in ViewHolder.
            // If it is not ready yet, it will be initialised with the NamedLocation set as its tag
            // when the callback is received.
            if (holder.map != null) {
                // The map is already ready to be used
                setMapLocation(holder.map, zone);
            }

            // Set the text label for this zone
            holder.name.setText(zone.name);

            holder.appsToBlock.setText("Apps blocked: " + (zone.blockingAppsAsStr() == "" ? "none" : zone.blockingAppsAsStr()));
            holder.keywords.setText("Keywords set: " + (zone.keywordsAsStr() == "" ? "none" : zone.keywordsAsStr()));

            // setup on click for edit zone button
            holder.editZone.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Get the zone object, saved in the tag!
                    ViewHolder vh = (ViewHolder) ((View) v.getParent().getParent()).getTag();
                    Zone z = (Zone) vh.mapView.getTag();

                    // start set zone activity, for this current zone
                    Intent editZoneActivityIntent = new Intent(getActivity(), ZoneEditActivity.class);
                    editZoneActivityIntent.putExtra("zone", z);
                    getActivity().startActivityForResult(editZoneActivityIntent, REQUEST_CODE_EDIT_ZONE);
                }
            });


            // setup on click for edit zone button
            holder.deleteZone.setOnClickListener(new View.OnClickListener() {

                @Override<commit_msg>Fixed typo with displaying wrong zone array<commit_after>package com.harrymt.productivitymapping;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.ui.IconGenerator;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

import android.support.v4.app.ListFragment;

public class MapFragment extends Fragment {

    private ListFragment mList;

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_map, container, false);
        loadZonesToListView();
        return v;
    }

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

    // Reload all zones from the DB again
    private void loadZonesToListView() {

        // TODO add empty list item to zones that says no zones, go create one.
        // Set a custom list adapter for a list of locations
        ArrayList<Zone> zs = getZones();
        Zone[] zones;
        // Convert to array
        zones = new Zone[zs.size()]; int i = 0;for (Zone z : zs) { zones[i] = z; i++;}

        mList = (ListFragment) getChildFragmentManager().findFragmentById(R.id.list);
        mList.setListAdapter(new MapAdapter(getActivity(), zones));
        // Set a RecyclerListener to clean up MapView from ListView
        mList.getListView().setRecyclerListener(mRecycleListener);
    }

    /**
     * Adapter that displays a name and {@link com.google.android.gms.maps.MapView} for each item.
     * The layout is defined in <code>lite_list_demo_row.xml</code>. It contains a MapView
     * that is programatically initialised in
     * {@link #getView(int, android.view.View, android.view.ViewGroup)}
     */
    private class MapAdapter extends ArrayAdapter<Zone> {

        private final HashSet<MapView> mMaps = new HashSet<>();

        public MapAdapter(Context context, Zone[] locations) {
            super(context, R.layout.list_map_row, R.id.tvZoneName, locations);
        }


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            ViewHolder holder;

            // Check if a view can be reused, otherwise inflate a layout and set up the view holder
            if (row == null) {
                // Inflate view from layout file
                row = getActivity().getLayoutInflater().inflate(R.layout.list_map_row, null);

                // Set up holder and assign it to the View
                holder = new ViewHolder();
                holder.mapView = (MapView) row.findViewById(R.id.lite_listrow_map);
                holder.name = (TextView) row.findViewById(R.id.tvZoneName);
                holder.appsToBlock = (TextView) row.findViewById(R.id.tvZoneAppsToBlock);
                holder.keywords = (TextView) row.findViewById(R.id.tvZoneKeywords);
                holder.editZone = (Button) row.findViewById(R.id.btnEditZone);
                holder.deleteZone = (Button) row.findViewById(R.id.btnDeleteZone);


                // Set holder as tag for row for more efficient access.
                row.setTag(holder);

                // Initialise the MapView
                holder.initializeMapView();

                // Keep track of MapView
                mMaps.add(holder.mapView);
            } else {
                // View has already been initialised, get its holder
                holder = (ViewHolder) row.getTag();
            }

            // Get the NamedLocation for this zone and attach it to the MapView
            Zone zone = getItem(position);
            holder.mapView.setTag(zone);

            // Ensure the map has been initialised by the on map ready callback in ViewHolder.
            // If it is not ready yet, it will be initialised with the NamedLocation set as its tag
            // when the callback is received.
            if (holder.map != null) {
                // The map is already ready to be used
                setMapLocation(holder.map, zone);
            }

            // Set the text label for this zone
            holder.name.setText(zone.name);

            String apps = ""; for(String app : zone.blockingApps) { apps += app + ", "; }
            String keywords = ""; for(String word : zone.keywords) { keywords += word + ", "; }

            holder.appsToBlock.setText("Apps blocked: " + (zone.blockingApps.length == 0 ? "none" : apps));
            holder.keywords.setText("Keywords set: " + (zone.keywords.length ==0 ? "none" : keywords));

            // setup on click for edit zone button
            holder.editZone.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Get the zone object, saved in the tag!
                    ViewHolder vh = (ViewHolder) ((View) v.getParent().getParent()).getTag();
                    Zone z = (Zone) vh.mapView.getTag();

                    // start set zone activity, for this current zone
                    Intent editZoneActivityIntent = new Intent(getActivity(), ZoneEditActivity.class);
                    editZoneActivityIntent.putExtra("zone", z);
                    getActivity().startActivityForResult(editZoneActivityIntent, REQUEST_CODE_EDIT_ZONE);
                }
            });


            // setup on click for edit zone button
            holder.deleteZone.setOnClickListener(new View.OnClickListener() {

                @Override
{'fraction_non_alphanumeric': 0.0975, 'fraction_numerical': 0.000625, 'mean_word_length': 2.382034346103038, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7391766', 'n_tokens_mistral': 3529, 'n_tokens_neox': 3335, 'n_words': 935}