<commit_before>package ru.santaev.clipboardtranslator.ui.adapter;


import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;
import java.util.Random;

import ru.santaev.clipboardtranslator.R;
import ru.santaev.clipboardtranslator.TranslatorApp;
import ru.santaev.clipboardtranslator.databinding.LanguageItemLayoutBinding;
import ru.santaev.clipboardtranslator.databinding.LanguageSectionItemLayoutBinding;
import ru.santaev.clipboardtranslator.model.Language;

public class LanguageAdapter extends RecyclerView.Adapter<LanguageAdapter.ViewHolder>{

    private static final int TYPE_LANG = 0;
    private static final int TYPE_SECTION = 1;

    public interface OnItemClickedListener{
        void onClick(Language translation);
    }

    private List<Language> languages;
    private List<Language> unsupportedLanguages;
    private OnItemClickedListener listener;

    public LanguageAdapter(List<Language> languages, List<Language> unsupportedLanguages) {
        this.languages = languages;
        this.unsupportedLanguages = unsupportedLanguages;
    }

    public List<Language> getLanguages() {
        return languages;
    }

    public void setLanguages(List<Language> languages) {
        this.languages = languages;
    }

    public List<Language> getUnsupportedLanguages() {
        return unsupportedLanguages;
    }

    public void setUnsupportedLanguages(List<Language> unsupportedLanguages) {
        this.unsupportedLanguages = unsupportedLanguages;
    }

    public OnItemClickedListener getListener() {
        return listener;
    }

    public void setListener(OnItemClickedListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemViewType(int position) {
        if (0 == position || languages.size() + 1 == position){
            return TYPE_SECTION;
        } else {
            return TYPE_LANG;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_LANG) {
            LanguageItemLayoutBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                    R.layout.language_item_layout, parent, false);
            return new LanguageViewHolder(binding);
        } else {
            LanguageSectionItemLayoutBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                    R.layout.language_section_item_layout, parent, false);
            return new SectionViewHolder(binding);
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (getItemViewType(position) == TYPE_LANG) {
            LanguageViewHolder viewHolder = (LanguageViewHolder) holder;
            Language language = position < languages.size() + 2
                    ? languages.get(position - 1)
                    : unsupportedLanguages.get(position - languages.size() - 2);

            int[] icons = new int[]{
                    R.drawable.ic_country_russia,
                    R.drawable.ic_country_usa,
                    R.drawable.ic_country_france,
                    R.drawable.ic_country_german,
            };
            viewHolder.binding.text.setText(TranslatorApp.getAppContext().getString(language.getTextRes()));
            viewHolder.binding.icon.setImageResource(icons[new Random().nextInt(icons.length)]);

            viewHolder.binding.getRoot().setOnClickListener(v -> {
                Language langByPos = getLangByPos(position);
                if (listener != null && null != langByPos) {
                    listener.onClick(langByPos);
                }
            });
        } else {
            SectionViewHolder viewHolder = (SectionViewHolder) holder;
            viewHolder.binding.text.setText(0 == position ? "Все языки" : "Неподдерживаемые языки");
            viewHolder.binding.getRoot().setOnClickListener(v -> {});
        }
    }

    private Language getLangByPos(int position){
        if (position == 0 || position == languages.size()){<commit_msg>fixed bug in language adapter<commit_after>package ru.santaev.clipboardtranslator.ui.adapter;


import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;
import java.util.Random;

import ru.santaev.clipboardtranslator.R;
import ru.santaev.clipboardtranslator.TranslatorApp;
import ru.santaev.clipboardtranslator.databinding.LanguageItemLayoutBinding;
import ru.santaev.clipboardtranslator.databinding.LanguageSectionItemLayoutBinding;
import ru.santaev.clipboardtranslator.model.Language;

public class LanguageAdapter extends RecyclerView.Adapter<LanguageAdapter.ViewHolder>{

    private static final int TYPE_LANG = 0;
    private static final int TYPE_SECTION = 1;

    public interface OnItemClickedListener{
        void onClick(Language translation);
    }

    private List<Language> languages;
    private List<Language> unsupportedLanguages;
    private OnItemClickedListener listener;

    public LanguageAdapter(List<Language> languages, List<Language> unsupportedLanguages) {
        this.languages = languages;
        this.unsupportedLanguages = unsupportedLanguages;
    }

    public List<Language> getLanguages() {
        return languages;
    }

    public void setLanguages(List<Language> languages) {
        this.languages = languages;
    }

    public List<Language> getUnsupportedLanguages() {
        return unsupportedLanguages;
    }

    public void setUnsupportedLanguages(List<Language> unsupportedLanguages) {
        this.unsupportedLanguages = unsupportedLanguages;
    }

    public OnItemClickedListener getListener() {
        return listener;
    }

    public void setListener(OnItemClickedListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemViewType(int position) {
        if (0 == position || languages.size() + 1 == position){
            return TYPE_SECTION;
        } else {
            return TYPE_LANG;
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_LANG) {
            LanguageItemLayoutBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                    R.layout.language_item_layout, parent, false);
            return new LanguageViewHolder(binding);
        } else {
            LanguageSectionItemLayoutBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                    R.layout.language_section_item_layout, parent, false);
            return new SectionViewHolder(binding);
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (getItemViewType(position) == TYPE_LANG) {
            LanguageViewHolder viewHolder = (LanguageViewHolder) holder;
            Language language = position < languages.size() + 2
                    ? languages.get(position - 1)
                    : unsupportedLanguages.get(position - languages.size() - 2);

            int[] icons = new int[]{
                    R.drawable.ic_country_russia,
                    R.drawable.ic_country_usa,
                    R.drawable.ic_country_france,
                    R.drawable.ic_country_german,
            };
            viewHolder.binding.text.setText(TranslatorApp.getAppContext().getString(language.getTextRes()));
            viewHolder.binding.icon.setImageResource(icons[new Random().nextInt(icons.length)]);

            viewHolder.binding.getRoot().setOnClickListener(v -> {
                Language langByPos = getLangByPos(position);
                if (listener != null && null != langByPos) {
                    listener.onClick(langByPos);
                }
            });
        } else {
            SectionViewHolder viewHolder = (SectionViewHolder) holder;
            viewHolder.binding.text.setText(0 == position ? "Все языки" : "Неподдерживаемые языки");
            viewHolder.binding.getRoot().setOnClickListener(v -> {});
        }
    }

    private Language getLangByPos(int position){
        if (position == 0 || position == languages.size() + 1){
{'fraction_non_alphanumeric': 0.08884934756820878, 'fraction_numerical': 0.002491103202846975, 'mean_word_length': 2.7858105074090704, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '1697772', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2162, 'n_words': 426}