<commit_before>package sk.henrichg.phoneprofiles;

import android.app.Fragment;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

public class ActivateProfileListAdapter extends BaseAdapter
{

    private List<Profile> profileList;
    private Fragment fragment;
    private DataWrapper dataWrapper;

    public ActivateProfileListAdapter(Fragment f, List<Profile> pl, DataWrapper dataWrapper)
    {
        fragment = f;
        profileList = pl;
        this.dataWrapper = dataWrapper;
    }

    public void release()
    {
        fragment = null;
        profileList = null;
    }

    public int getCount()
    {
        return profileList.size();
    }

    public Object getItem(int position)
    {
        return profileList.get(position);
    }

    public long getItemId(int position)
    {
        return position;
    }

    public int getItemId(Profile profile)
    {
        for (int i = 0; i < profileList.size(); i++)
        {
            if (profileList.get(i)._id == profile._id)
                return i;
        }
        return -1;
    }

    public void setList(List<Profile> pl)
    {
        profileList = pl;
        notifyDataSetChanged();
    }

    public void addItem(Profile profile)
    {
        int maxPOrder = 0;
        int pOrder;
        for (Profile p : profileList)
        {
            pOrder = p._porder;
            if (pOrder > maxPOrder) maxPOrder = pOrder;
        }
        profile._porder = maxPOrder+1;
        profileList.add(profile);
        notifyDataSetChanged();
    }

    public void updateItem(Profile profile)
    {
        notifyDataSetChanged();
    }

    public void deleteItem(Profile profile)
    {
        profileList.remove(profile);
        notifyDataSetChanged();
    }

    public void changeItemOrder(int from, int to)
    {
        Profile profile = profileList.get(from);
        profileList.remove(from);
        profileList.add(to, profile);
        for (int i = 0; i < profileList.size(); i++)
        {
            profileList.get(i)._porder = i+1;
        }
        notifyDataSetChanged();
    }

    public Profile getActivatedProfile()
    {
        for (Profile p : profileList)
        {
            if (p._checked)
            {
                return p;
            }
        }

        return null;
    }

    public void notifyDataSetChanged(boolean refreshIcons) {
        if (refreshIcons) {
            for (Profile profile : profileList) {
                dataWrapper.refreshProfileIcon(profile, false, 0);
            }
        }
        notifyDataSetChanged();
    }

    static class ViewHolder {
          RelativeLayout listItemRoot;
          ImageView profileIcon;
          TextView profileName;
          ImageView profileIndicator;
          int position;
        }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;

        View vi = convertView;
        if (convertView == null)
        {
            holder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(fragment.getActivity());
            if (!GlobalData.applicationActivatorGridLayout)
            {
                if (GlobalData.applicationActivatorPrefIndicator)
                    vi = inflater.inflate(R.layout.activate_profile_list_item, parent, false);
                else
                    vi = inflater.inflate(R.layout.activate_profile_list_item_no_indicator, parent, false);
                holder.listItemRoot = (RelativeLayout)vi.findViewById(R.id.act_prof_list_item_root);
                holder.profileName = (TextView)vi.findViewById(R.id.act_prof_list_item_profile_name);
                holder.profileIcon = (ImageView)vi.findViewById(R.id.act_prof_list_item_profile_icon);
                if (GlobalData.applicationActivatorPrefIndicator)
                    holder.profileIndicator = (ImageView)vi.findViewById(R.id.act_prof_list_profile_pref_indicator);
            }
            else
            {
                vi = inflater.inflate(R.layout.activate_profile_grid_item, parent, false);
                holder.listItemRoot = (RelativeLayout)vi.findViewById(R.id.act_prof_list_item_root);
                holder.profileName = (TextView)vi.findViewById(R.id.act_prof_list_item_profile_name);
                holder.profileIcon = (ImageView)vi.findViewById(R.id.act_prof_list_item_profile_icon);
            }
            vi.setTag(holder);        
        }
        else
        {
            holder = (ViewHolder)vi.getTag();
        }

        Profile profile = profileList.get(position);

        if (profile._checked && (!GlobalData.applicationActivatorHeader))
        {
            if (GlobalData.applicationTheme.equals("material"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card);
            else
            if (GlobalData.applicationTheme.equals("dark"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card_dark);
            else
            if (GlobalData.applicationTheme.equals("dlight"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card);
            holder.profileName.setTypeface(null, Typeface.BOLD);
        }
        else
        {
            if (GlobalData.applicationTheme.equals("material"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card);
            else
            if (GlobalData.applicationTheme.equals("dark"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card_dark);
            else
            if (GlobalData.applicationTheme.equals("dlight"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card);
            holder.profileName.setTypeface(null, Typeface.NORMAL);
        }

        String profileName = profile.getProfileNameWithDuration();<commit_msg>Fixed bug<commit_after>package sk.henrichg.phoneprofiles;

import android.app.Fragment;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

public class ActivateProfileListAdapter extends BaseAdapter
{

    private List<Profile> profileList;
    private Fragment fragment;
    private DataWrapper dataWrapper;

    public ActivateProfileListAdapter(Fragment f, List<Profile> pl, DataWrapper dataWrapper)
    {
        fragment = f;
        profileList = pl;
        this.dataWrapper = dataWrapper;
    }

    public void release()
    {
        fragment = null;
        profileList = null;
    }

    public int getCount()
    {
        return profileList.size();
    }

    public Object getItem(int position)
    {
        return profileList.get(position);
    }

    public long getItemId(int position)
    {
        return position;
    }

    public int getItemId(Profile profile)
    {
        for (int i = 0; i < profileList.size(); i++)
        {
            if (profileList.get(i)._id == profile._id)
                return i;
        }
        return -1;
    }

    public void setList(List<Profile> pl)
    {
        profileList = pl;
        notifyDataSetChanged();
    }

    public void addItem(Profile profile)
    {
        int maxPOrder = 0;
        int pOrder;
        for (Profile p : profileList)
        {
            pOrder = p._porder;
            if (pOrder > maxPOrder) maxPOrder = pOrder;
        }
        profile._porder = maxPOrder+1;
        profileList.add(profile);
        notifyDataSetChanged();
    }

    public void updateItem(Profile profile)
    {
        notifyDataSetChanged();
    }

    public void deleteItem(Profile profile)
    {
        profileList.remove(profile);
        notifyDataSetChanged();
    }

    public void changeItemOrder(int from, int to)
    {
        Profile profile = profileList.get(from);
        profileList.remove(from);
        profileList.add(to, profile);
        for (int i = 0; i < profileList.size(); i++)
        {
            profileList.get(i)._porder = i+1;
        }
        notifyDataSetChanged();
    }

    public Profile getActivatedProfile()
    {
        for (Profile p : profileList)
        {
            if (p._checked)
            {
                return p;
            }
        }

        return null;
    }

    public void notifyDataSetChanged(boolean refreshIcons) {
        if (refreshIcons) {
            for (Profile profile : profileList) {
                dataWrapper.refreshProfileIcon(profile, false, 0);
            }
        }
        notifyDataSetChanged();
    }

    static class ViewHolder {
          RelativeLayout listItemRoot;
          ImageView profileIcon;
          TextView profileName;
          ImageView profileIndicator;
          int position;
        }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;

        View vi = convertView;
        if (convertView == null)
        {
            holder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(fragment.getActivity());
            if (!GlobalData.applicationActivatorGridLayout)
            {
                if (GlobalData.applicationActivatorPrefIndicator)
                    vi = inflater.inflate(R.layout.activate_profile_list_item, parent, false);
                else
                    vi = inflater.inflate(R.layout.activate_profile_list_item_no_indicator, parent, false);
                holder.listItemRoot = (RelativeLayout)vi.findViewById(R.id.act_prof_list_item_root);
                holder.profileName = (TextView)vi.findViewById(R.id.act_prof_list_item_profile_name);
                holder.profileIcon = (ImageView)vi.findViewById(R.id.act_prof_list_item_profile_icon);
                if (GlobalData.applicationActivatorPrefIndicator)
                    holder.profileIndicator = (ImageView)vi.findViewById(R.id.act_prof_list_profile_pref_indicator);
            }
            else
            {
                vi = inflater.inflate(R.layout.activate_profile_grid_item, parent, false);
                holder.listItemRoot = (RelativeLayout)vi.findViewById(R.id.act_prof_list_item_root);
                holder.profileName = (TextView)vi.findViewById(R.id.act_prof_list_item_profile_name);
                holder.profileIcon = (ImageView)vi.findViewById(R.id.act_prof_list_item_profile_icon);
            }
            vi.setTag(holder);        
        }
        else
        {
            holder = (ViewHolder)vi.getTag();
        }

        Profile profile = profileList.get(position);

        if (profile._checked && (!GlobalData.applicationActivatorHeader))
        {
            if (GlobalData.applicationTheme.equals("material"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card_dlight);
            else
            if (GlobalData.applicationTheme.equals("dark"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card_dark);
            else
            if (GlobalData.applicationTheme.equals("dlight"))
                holder.listItemRoot.setBackgroundResource(R.drawable.header_card_dlight);
            holder.profileName.setTypeface(null, Typeface.BOLD);
        }
        else
        {
            if (GlobalData.applicationTheme.equals("material"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card);
            else
            if (GlobalData.applicationTheme.equals("dark"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card_dark);
            else
            if (GlobalData.applicationTheme.equals("dlight"))
                holder.listItemRoot.setBackgroundResource(R.drawable.card);
            holder.profileName.setTypeface(null, Typeface.NORMAL);
        }

        String profileName = profile.getProfileNameWithDuration();
{'fraction_non_alphanumeric': 0.08872427983539094, 'fraction_numerical': 0.0011522633744855968, 'mean_word_length': 2.0997448979591837, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '6991473', 'n_tokens_mistral': 3310, 'n_tokens_neox': 3183, 'n_words': 582}