<commit_before>package org.tndata.android.compass.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import org.tndata.android.compass.R;
import org.tndata.android.compass.model.CustomAction;

import java.util.List;


/**
 * Created by isma on 2/1/16.
 */
public class CustomActionAdapter extends RecyclerView.Adapter<CustomActionAdapter.ActionHolder>{
    private Context mContext;
    private CustomActionAdapterListener mListener;
    private List<CustomAction> mCustomActions;

    private String mNewActionTitle;


    public CustomActionAdapter(Context context, CustomActionAdapterListener listener,
                               List<CustomAction> customActions){
        mContext = context;
        mListener = listener;
        mCustomActions = customActions;
    }


    @Override
    public ActionHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater inflater = LayoutInflater.from(mContext);
        return new ActionHolder(inflater.inflate(R.layout.item_custom_action, parent, false));
    }

    @Override
    public void onBindViewHolder(ActionHolder holder, int position){
        if (position < mCustomActions.size()){
            holder.mTitle.setText(mCustomActions.get(position).getTitle());
            holder.mAction.setText("Remove");
        }
        else{
            holder.mTitle.setText(mNewActionTitle);
            holder.mAction.setText("Add");
        }
        holder.enable();
    }

    @Override
    public int getItemCount(){
        return mCustomActions.size()+1;
    }

    public void addCustomAction(CustomAction customAction){
        mCustomActions.add(customAction);
        notifyItemInserted(mCustomActions.size() - 1);
        notifyItemChanged(mCustomActions.size());
    }


    class ActionHolder extends RecyclerView.ViewHolder implements View.OnClickListener, TextWatcher{
        private TextView mTitle;
        private Button mAction;


        public ActionHolder(View rootView){
            super(rootView);

            mTitle = (TextView)rootView.findViewById(R.id.custom_action_title);
            mAction = (Button)rootView.findViewById(R.id.custom_action_action);
            mAction.setOnClickListener(this);
        }

        @Override
        public void onClick(View v){
            if (getAdapterPosition() < mCustomActions.size()){
                CustomAction customAction = mCustomActions.remove(getAdapterPosition());
                notifyItemRemoved(getAdapterPosition());
                mListener.onRemoveClicked(customAction);
            }
            else{
                mAction.setEnabled(false);
                mListener.onAddClicked(new CustomAction(mTitle.getText().toString().trim()));
                mNewActionTitle = "";
            }
        }

        public void enable(){
            mAction.setEnabled(true);
        }

        public void recordTitle(boolean enabled){
            mTitle.removeTextChangedListener(this);
            if (enabled){
                mTitle.addTextChangedListener(this);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after){
            //Unused
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count){
            mNewActionTitle = s.toString();
        }

        @Override
        public void afterTextChanged(Editable s){
            //Unused
        }
    }


    public interface CustomActionAdapterListener{
        void onAddClicked(CustomAction customAction);
        void onRemoveClicked(CustomAction customAction);
    }
}
<commit_msg>Bugfix<commit_after>package org.tndata.android.compass.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import org.tndata.android.compass.R;
import org.tndata.android.compass.model.CustomAction;

import java.util.List;


/**
 * Created by isma on 2/1/16.
 */
public class CustomActionAdapter extends RecyclerView.Adapter<CustomActionAdapter.ActionHolder>{
    private Context mContext;
    private CustomActionAdapterListener mListener;
    private List<CustomAction> mCustomActions;

    private String mNewActionTitle;


    public CustomActionAdapter(Context context, CustomActionAdapterListener listener,
                               List<CustomAction> customActions){
        mContext = context;
        mListener = listener;
        mCustomActions = customActions;
    }


    @Override
    public ActionHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater inflater = LayoutInflater.from(mContext);
        return new ActionHolder(inflater.inflate(R.layout.item_custom_action, parent, false));
    }

    @Override
    public void onBindViewHolder(ActionHolder holder, int position){
        if (position < mCustomActions.size()){
            holder.mTitle.setText(mCustomActions.get(position).getTitle());
            holder.mAction.setText("Remove");
            holder.recordTitle(false);
        }
        else{
            holder.mTitle.setText(mNewActionTitle);
            holder.mAction.setText("Add");
            holder.recordTitle(true);
        }
        holder.enable();
    }

    @Override
    public int getItemCount(){
        return mCustomActions.size()+1;
    }

    public void addCustomAction(CustomAction customAction){
        mCustomActions.add(customAction);
        notifyItemInserted(mCustomActions.size() - 1);
        notifyItemChanged(mCustomActions.size());
    }


    class ActionHolder extends RecyclerView.ViewHolder implements View.OnClickListener, TextWatcher{
        private TextView mTitle;
        private Button mAction;


        public ActionHolder(View rootView){
            super(rootView);

            mTitle = (TextView)rootView.findViewById(R.id.custom_action_title);
            mAction = (Button)rootView.findViewById(R.id.custom_action_action);
            mAction.setOnClickListener(this);
        }

        @Override
        public void onClick(View v){
            if (getAdapterPosition() < mCustomActions.size()){
                CustomAction customAction = mCustomActions.remove(getAdapterPosition());
                notifyItemRemoved(getAdapterPosition());
                mListener.onRemoveClicked(customAction);
            }
            else{
                mAction.setEnabled(false);
                mListener.onAddClicked(new CustomAction(mTitle.getText().toString().trim()));
                mNewActionTitle = "";
            }
        }

        public void enable(){
            mAction.setEnabled(true);
        }

        public void recordTitle(boolean enabled){
            mTitle.removeTextChangedListener(this);
            if (enabled){
                mTitle.addTextChangedListener(this);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after){
            //Unused
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count){
            mNewActionTitle = s.toString();
        }

        @Override
        public void afterTextChanged(Editable s){
            //Unused
        }
    }


    public interface CustomActionAdapterListener{
        void onAddClicked(CustomAction customAction);
        void onRemoveClicked(CustomAction customAction);
    }
}

{'fraction_non_alphanumeric': 0.08808553971486761, 'fraction_numerical': 0.0017820773930753565, 'mean_word_length': 2.547178329571106, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '5529520', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1965, 'n_words': 398}