<commit_before>package vocabletrainer.heinecke.aron.vocabletrainer.Activities.lib;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

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

import vocabletrainer.heinecke.aron.vocabletrainer.R;
import vocabletrainer.heinecke.aron.vocabletrainer.lib.Storage.Entry;
import vocabletrainer.heinecke.aron.vocabletrainer.lib.Storage.Table;

import static vocabletrainer.heinecke.aron.vocabletrainer.lib.Database.ID_RESERVED_SKIP;

/**
 * BaseAdapter for entry list views
 */
public class EntryListAdapter extends BaseAdapter {

    private static final String TAG = "EntryListAdapter";
    private List<Entry> dataItems = null;
    private List<Entry> deleted;
    private Activity activity;
    private LayoutInflater inflater;
    private Entry header;

    /**
     * Creates a new entry list adapter
     *
     * @param activity
     * @param items
     */
    public EntryListAdapter(Activity activity, List<Entry> items, Context context) {
        super();
        this.activity = activity;
        this.dataItems = items;
        header = new Entry(context.getString(R.string.Editor_Default_Column_A),
                context.getString(R.string.Editor_Default_Column_B),
                context.getString(R.string.Editor_Default_Tip),
                ID_RESERVED_SKIP, new Table(ID_RESERVED_SKIP), -2L);
        dataItems.add(0, header);
        deleted = new ArrayList<>();
        inflater = activity.getLayoutInflater();
    }

    /**
     * Set table data (Column Names)
     *
     * @param tbl
     */
    public void setTableData(Table tbl) {
        header.setAWord(tbl.getNameA());
        header.setBWord(tbl.getNameB());
        this.notifyDataSetChanged();
        Log.d("EntryListAdapter", "setTableData");
    }

    @Override
    public int getCount() {
        return dataItems.size();
    }

    @Override
    public Object getItem(int position) {
        return dataItems.get(position);
        // -1 required as onItemClicked counts from 1 but the list starts a 0
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final ViewHolder holder;
        final Entry item = dataItems.get(position);

        if (convertView == null) {
            holder = new ViewHolder();


            convertView = inflater.inflate(R.layout.entry_list_view, null);

            holder.colA = (TextView) convertView.findViewById(R.id.entryFirstText);
            holder.colB = (TextView) convertView.findViewById(R.id.entrySecondText);
            holder.colTipp = (TextView) convertView.findViewById(R.id.entryThirdText);
            holder.originTypeface = holder.colA.getTypeface().getStyle();

            convertView.setTag(holder);
            convertView.setTag(R.id.entryFirstText, holder.colA);
            convertView.setTag(R.id.entrySecondText, holder.colB);
            convertView.setTag(R.id.entryThirdText, holder.colTipp);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        boolean bold = item.getId() == ID_RESERVED_SKIP;
        holder.colA.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);
        holder.colB.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);
        holder.colTipp.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);

        holder.colA.setText(item.getAWord());
        holder.colB.setText(item.getBWord());
        holder.colTipp.setText(item.getTip());

        return convertView;
    }

    /**
     * Returns a list of deleted entries
     *
     * @return
     */
    public List<Entry> getDeleted() {
        return deleted;
    }

    /**
     * Set entry as deleted
     *
     * @param entry
     */
    public void setDeleted(Entry entry) {
        entry.setDelete(true);
        dataItems.remove(entry);
        deleted.add(entry);
        notifyDataSetChanged();
    }<commit_msg>fix for KitKat with missing Typeface appcrash<commit_after>package vocabletrainer.heinecke.aron.vocabletrainer.Activities.lib;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

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

import vocabletrainer.heinecke.aron.vocabletrainer.R;
import vocabletrainer.heinecke.aron.vocabletrainer.lib.Storage.Entry;
import vocabletrainer.heinecke.aron.vocabletrainer.lib.Storage.Table;

import static vocabletrainer.heinecke.aron.vocabletrainer.lib.Database.ID_RESERVED_SKIP;

/**
 * BaseAdapter for entry list views
 */
public class EntryListAdapter extends BaseAdapter {

    private static final int ANDROID_WORKAROUND_STYLE = -1;
    private static final String TAG = "EntryListAdapter";
    private List<Entry> dataItems = null;
    private List<Entry> deleted;
    private Activity activity;
    private LayoutInflater inflater;
    private Entry header;

    /**
     * Creates a new entry list adapter
     *
     * @param activity
     * @param items
     */
    public EntryListAdapter(Activity activity, List<Entry> items, Context context) {
        super();
        this.activity = activity;
        this.dataItems = items;
        header = new Entry(context.getString(R.string.Editor_Default_Column_A),
                context.getString(R.string.Editor_Default_Column_B),
                context.getString(R.string.Editor_Default_Tip),
                ID_RESERVED_SKIP, new Table(ID_RESERVED_SKIP), -2L);
        dataItems.add(0, header);
        deleted = new ArrayList<>();
        inflater = activity.getLayoutInflater();
    }

    /**
     * Set table data (Column Names)
     *
     * @param tbl
     */
    public void setTableData(Table tbl) {
        header.setAWord(tbl.getNameA());
        header.setBWord(tbl.getNameB());
        this.notifyDataSetChanged();
        Log.d("EntryListAdapter", "setTableData");
    }

    @Override
    public int getCount() {
        return dataItems.size();
    }

    @Override
    public Object getItem(int position) {
        return dataItems.get(position);
        // -1 required as onItemClicked counts from 1 but the list starts a 0
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final ViewHolder holder;
        final Entry item = dataItems.get(position);

        if (convertView == null) {
            holder = new ViewHolder();


            convertView = inflater.inflate(R.layout.entry_list_view, null);

            holder.colA = (TextView) convertView.findViewById(R.id.entryFirstText);
            holder.colB = (TextView) convertView.findViewById(R.id.entrySecondText);
            holder.colTipp = (TextView) convertView.findViewById(R.id.entryThirdText);
            if(holder.colA.getTypeface() == null){
                holder.originTypeface = ANDROID_WORKAROUND_STYLE;
            }else {
                holder.originTypeface = holder.colA.getTypeface().getStyle();
            }

            convertView.setTag(holder);
            convertView.setTag(R.id.entryFirstText, holder.colA);
            convertView.setTag(R.id.entrySecondText, holder.colB);
            convertView.setTag(R.id.entryThirdText, holder.colTipp);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        boolean bold = item.getId() == ID_RESERVED_SKIP;
        if(holder.originTypeface == ANDROID_WORKAROUND_STYLE){
            holder.colA.setTypeface(null, bold ? Typeface.BOLD : Typeface.NORMAL);
            holder.colB.setTypeface(null, bold ? Typeface.BOLD : Typeface.NORMAL);
            holder.colTipp.setTypeface(null, bold ? Typeface.BOLD : Typeface.NORMAL);
        }else {
            holder.colA.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);
            holder.colB.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);
            holder.colTipp.setTypeface(null, bold ? Typeface.BOLD : holder.originTypeface);
        }

        holder.colA.setText(item.getAWord());
        holder.colB.setText(item.getBWord());
        holder.colTipp.setText(item.getTip());

        return convertView;
    }

    /**
     * Returns a list of deleted entries
     *
     * @return
     */
    public List<Entry> getDeleted() {
        return deleted;
    }

    /**
     * Set entry as deleted
     *
     * @param entry
     */
    public void setDeleted(Entry entry) {
        entry.setDelete(true);
        dataItems.remove(entry);
        deleted.add(entry);
        notifyDataSetChanged();
    }
{'fraction_non_alphanumeric': 0.10378604446401056, 'fraction_numerical': 0.001430772617213295, 'mean_word_length': 2.687905844155844, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3756453', 'n_tokens_mistral': 2696, 'n_tokens_neox': 2629, 'n_words': 528}