<commit_before>package br.org.funcate.terramobile.view;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

import br.org.funcate.terramobile.R;
import br.org.funcate.terramobile.configuration.ViewContextParameters;
import br.org.funcate.terramobile.controller.activity.MainActivity;
import br.org.funcate.terramobile.controller.activity.MenuMapController;
import br.org.funcate.terramobile.controller.activity.TreeView;
import br.org.funcate.terramobile.model.Project;
import br.org.funcate.terramobile.model.gpkg.objects.GpkgLayer;
import br.org.funcate.terramobile.util.Message;

public class TreeViewAdapter extends BaseExpandableListAdapter implements View.OnClickListener {

    public ArrayList<GpkgLayer> groupItem;
    public ArrayList<ArrayList<GpkgLayer>> ChildItem;
    private final Context context;
    private MenuMapController menuMapController;
    private ArrayList<RadioButton> baseLayerRBList;
    private ArrayList<RadioButton> editableLayerRBList;

    public TreeViewAdapter(Context context, ArrayList<GpkgLayer> grpList, ArrayList<ArrayList<GpkgLayer>> childItem) {
        this.context = context;
        this.groupItem = grpList;
        this.ChildItem = childItem;
        this.menuMapController = new MenuMapController(this.context);
        baseLayerRBList = new ArrayList<RadioButton>();
        editableLayerRBList = new ArrayList<RadioButton>();
    }

    @Override
    public void onClick(View v) {
        exec(v);
        return;
    }

    private void exec(View v) {
        GpkgLayer child = (GpkgLayer) v.getTag();
        try{
            switch (child.getType()){
                case TILES:{// base
                    for (int count = 0; count < baseLayerRBList.size(); count++) {
                        RadioButton radioButton = baseLayerRBList.get(count);
                        radioButton.setChecked(false);
                    }

                    RadioButton rBChildBaseLayer = (RadioButton) v;
                    if (!rBChildBaseLayer.isChecked()) {
                        if(menuMapController.getBaseLayer() != null)
                            this.menuMapController.removeBaseLayer();
                        this.menuMapController.addBaseLayer(child);
                        rBChildBaseLayer.setChecked(true);
                    }
                    break;
                }
                case FEATURES:{// collect

                    if (((CheckBox) v).isChecked()) {
                        this.menuMapController.addVectorLayer(child);
                    } else {
                        this.menuMapController.removeVectorLayer(child);
                    }
                    break;
                }
                case EDITABLE:{// editable (vector)
                    TreeView treeView=((MainActivity) this.context).getTreeView();
                    treeView.setSelectedEditableLayer(child);
                    for (int count = 0; count < editableLayerRBList.size(); count++) {
                        RadioButton radioButton = editableLayerRBList.get(count);
                        radioButton.setChecked(false);
                    }
                    RadioButton rBChildGatheringLayer = (RadioButton) v;
                    if (!rBChildGatheringLayer.isChecked()) {
//                        menuMapController.removeEditableLayer();
//                        menuMapController.addEditableLayer(child);
                        rBChildGatheringLayer.setChecked(true);
                    }
                    break;
                }
                case ONLINE:{// online

                    break;
                }
            }
        } catch (Exception e) {
            Message.showErrorMessage(((MainActivity)context), R.string.error,"Failed on change the layer");
        }
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override<commit_msg>Changed mechanism to control adding and removing editable layers in the treeview.<commit_after>package br.org.funcate.terramobile.view;

import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

import br.org.funcate.terramobile.R;
import br.org.funcate.terramobile.configuration.ViewContextParameters;
import br.org.funcate.terramobile.controller.activity.MainActivity;
import br.org.funcate.terramobile.controller.activity.MenuMapController;
import br.org.funcate.terramobile.controller.activity.TreeView;
import br.org.funcate.terramobile.model.Project;
import br.org.funcate.terramobile.model.gpkg.objects.GpkgLayer;
import br.org.funcate.terramobile.util.Message;

public class TreeViewAdapter extends BaseExpandableListAdapter implements View.OnClickListener {

    public ArrayList<GpkgLayer> groupItem;
    public ArrayList<ArrayList<GpkgLayer>> ChildItem;
    private final Context context;
    private MenuMapController menuMapController;
    private ArrayList<RadioButton> baseLayerRBList;
    private ArrayList<RadioButton> editableLayerRBList;

    public TreeViewAdapter(Context context, ArrayList<GpkgLayer> grpList, ArrayList<ArrayList<GpkgLayer>> childItem) {
        this.context = context;
        this.groupItem = grpList;
        this.ChildItem = childItem;
        this.menuMapController = new MenuMapController(this.context);
        baseLayerRBList = new ArrayList<RadioButton>();
        editableLayerRBList = new ArrayList<RadioButton>();
    }

    @Override
    public void onClick(View v) {
        exec(v);
        return;
    }

    private void exec(View v) {
        GpkgLayer child = (GpkgLayer) v.getTag();
        try{
            switch (child.getType()){
                case TILES:{// base
                    this.unselectAllRadioButtons(baseLayerRBList);

                    RadioButton rBChildBaseLayer = (RadioButton) v;
                    if (!rBChildBaseLayer.isChecked()) {
                        if(menuMapController.getBaseLayer() != null)
                            this.menuMapController.removeBaseLayer();
                        this.menuMapController.addBaseLayer(child);
                        rBChildBaseLayer.setChecked(true);
                    }
                    break;
                }
                case FEATURES:{// collect

                    if (((CheckBox) v).isChecked()) {
                        this.menuMapController.addVectorLayer(child);
                    } else {
                        this.menuMapController.removeVectorLayer(child);
                    }
                    break;
                }
                case EDITABLE:{// editable (vector)
                    TreeView treeView=((MainActivity) this.context).getTreeView();
                    GpkgLayer ed = treeView.getSelectedEditableLayer();
                    if(ed!=null)
                        this.menuMapController.removeEditableLayer(ed);
                    treeView.setSelectedEditableLayer(child);
                    this.unselectAllRadioButtons(editableLayerRBList);

                    RadioButton rBChildGatheringLayer = (RadioButton) v;
                    if (!rBChildGatheringLayer.isChecked()) {
                        this.menuMapController.addEditableLayer(child);
                        rBChildGatheringLayer.setChecked(true);
                    }
                    break;
                }
                case ONLINE:{// online

                    break;
                }
            }
        } catch (Exception e) {
            Message.showErrorMessage(((MainActivity)context), R.string.error,"Failed on change the layer");
        }
    }

    private void unselectAllRadioButtons(ArrayList<RadioButton> radioButtons) {
        for (int i = 0,len=radioButtons.size(); i < len; i++) {
            RadioButton radioButton = radioButtons.get(i);
            radioButton.setChecked(false);
        }
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
{'fraction_non_alphanumeric': 0.08708470348112031, 'fraction_numerical': 0.0005669577049552103, 'mean_word_length': 2.1100141043723553, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 24, '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': '6817429', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2178, 'n_words': 419}