/*
* This file is part of Popcorn Time.
*
* Popcorn Time is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Popcorn Time is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Popcorn Time. If not, see <http://www.gnu.org/licenses/>.
*/
package pct.droid.base.adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
import butterknife.Bind;
import butterknife.ButterKnife;
import pct.droid.base.adapters.models.Option;
public class FileArrayAdapter extends ArrayAdapter<Option> {
private LayoutInflater mLayoutInflater;
private int id;
private List<Option> mItems;
public FileArrayAdapter(Context context, int textViewResourceId, List<Option> items) {
super(context, textViewResourceId, items);
id = textViewResourceId;
mItems = items;
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public Option getItem(int i) {
return mItems.get(i);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mLayoutInflater.inflate(id, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Option option = mItems.get(position);
if (option != null) {
holder.text1.setText(option.getName());
holder.text2.setText(option.getData());
}
return convertView;
}
class ViewHolder {
@Bind(android.R.id.text1)
TextView text1;
@Bind(android.R.id.text2)
TextView text2;
public ViewHolder(View v) {
ButterKnife.bind(this, v);
}
}
}