<commit_before>/*
 * Copyright (C) 2014 Philippine Android Developers Community
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ph.devcon.android.attendee.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;
import ph.devcon.android.R;
import ph.devcon.android.attendee.db.FTSAttendee;
import ph.devcon.android.util.Util;

/**
 * Created by lope on 10/9/14.
 */
public class AttendeeCursorAdapter extends SimpleCursorAdapter {
    final static String[] columns = new String[]{
            FTSAttendee.COL_FULL_NAME,
            FTSAttendee.COL_POSITION,
            FTSAttendee.COL_COMPANY,
            FTSAttendee.COL_PHOTO_URL,
            FTSAttendee.COL_TECH_PRIMARY,
    };
    // the XML defined views which the data will be bound to
    final static int[] to = new int[]{
            R.id.txt_full_name,
            R.id.txt_job,
            R.id.img_attendee,
            R.id.txt_main_technology,
    };
    protected Context mContext;
    protected Cursor cursor;

    public AttendeeCursorAdapter(Context context, Cursor cursor, int flags) {
        super(context, R.layout.item_attendee, cursor, columns, to, flags);
        mContext = context;
        this.cursor = cursor;
    }

    public AttendeeCursorAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to, int flags) {
        super(context, layout, cursor, from, to, flags);
        mContext = context;
        this.cursor = cursor;
    }

    @Override
    public void changeCursor(Cursor cursor) {
        this.cursor = cursor;
        super.changeCursor(cursor);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_attendee, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        this.cursor.moveToPosition(position);
        String fullName = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_FULL_NAME));
        String companyPosition = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_POSITION));
        String company = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_COMPANY));
        String technologyMain = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_TECH_PRIMARY));
        String imgUrl = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_PHOTO_URL));
        holder.txtName.setText(fullName);
        holder.txtJob.setText(companyPosition + " at " + company);
        holder.txtLanguages.setText(technologyMain);
        if (!Util.isNullOrEmpty(imgUrl)) {
            Picasso.with(mContext).load(imgUrl).placeholder(R.drawable.ic_action_person).into(holder.imgAttendee);
        }
        Util.emptyToGone(holder.txtName, holder.txtJob, holder.txtLanguages);
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.img_attendee)
        ImageView imgAttendee;
        @InjectView(R.id.txt_name)
        TextView txtName;
        @InjectView(R.id.txt_job)
        TextView txtJob;
        @InjectView(R.id.txt_languages)
        TextView txtLanguages;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }<commit_msg>added empty or gone to job title/company<commit_after>/*
 * Copyright (C) 2014 Philippine Android Developers Community
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ph.devcon.android.attendee.adapter;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;
import ph.devcon.android.R;
import ph.devcon.android.attendee.db.FTSAttendee;
import ph.devcon.android.util.Util;

/**
 * Created by lope on 10/9/14.
 */
public class AttendeeCursorAdapter extends SimpleCursorAdapter {
    final static String[] columns = new String[]{
            FTSAttendee.COL_FULL_NAME,
            FTSAttendee.COL_POSITION,
            FTSAttendee.COL_COMPANY,
            FTSAttendee.COL_PHOTO_URL,
            FTSAttendee.COL_TECH_PRIMARY,
    };
    // the XML defined views which the data will be bound to
    final static int[] to = new int[]{
            R.id.txt_full_name,
            R.id.txt_job,
            R.id.img_attendee,
            R.id.txt_main_technology,
    };
    protected Context mContext;
    protected Cursor cursor;

    public AttendeeCursorAdapter(Context context, Cursor cursor, int flags) {
        super(context, R.layout.item_attendee, cursor, columns, to, flags);
        mContext = context;
        this.cursor = cursor;
    }

    public AttendeeCursorAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to, int flags) {
        super(context, layout, cursor, from, to, flags);
        mContext = context;
        this.cursor = cursor;
    }

    @Override
    public void changeCursor(Cursor cursor) {
        this.cursor = cursor;
        super.changeCursor(cursor);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_attendee, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        this.cursor.moveToPosition(position);
        String fullName = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_FULL_NAME));
        String companyPosition = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_POSITION));
        String company = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_COMPANY));
        String technologyMain = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_TECH_PRIMARY));
        String imgUrl = this.cursor.getString(this.cursor.getColumnIndex(FTSAttendee.COL_PHOTO_URL));
        holder.txtName.setText(fullName);
        holder.txtJob.setText(getJobLabel(company, companyPosition));
        holder.txtLanguages.setText(technologyMain);
        if (!Util.isNullOrEmpty(imgUrl)) {
            Picasso.with(mContext).load(imgUrl).placeholder(R.drawable.ic_action_person).into(holder.imgAttendee);
        }
        Util.emptyToGone(holder.txtName, holder.txtJob, holder.txtLanguages);
        return convertView;
    }

    private String getJobLabel(String company, String companyPosition) {
        String label = "";
        if (Util.isNullOrEmpty(company) || Util.isNullOrEmpty(companyPosition)) {
            if (!Util.isNullOrEmpty(company)) {
                label = company;
            } else if (!Util.isNullOrEmpty(companyPosition)) {
                label = companyPosition;
            }
        } else {
            label = companyPosition + " at " + company;
        }
        return label;
    }

    static class ViewHolder {
        @InjectView(R.id.img_attendee)
        ImageView imgAttendee;
        @InjectView(R.id.txt_name)
        TextView txtName;
        @InjectView(R.id.txt_job)
        TextView txtJob;
        @InjectView(R.id.txt_languages)
        TextView txtLanguages;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
{'fraction_non_alphanumeric': 0.09325634600719032, 'fraction_numerical': 0.0028325525656389583, 'mean_word_length': 2.9965171963430564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5220364', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2620, 'n_words': 610}