/*
 * Copyright (C) 2012 Brian Muramatsu
 *
 * 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 com.btmura.android.reddit.widget;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.btmura.android.reddit.R;

public class FilterAdapter extends BaseFilterAdapter {

    private final LayoutInflater inflater;
    private final ArrayList<String> names = new ArrayList<String>(6);
    private CharSequence title;

    public FilterAdapter(Context context) {
        inflater = LayoutInflater.from(context);
    }

    @Override
    protected void clear() {
        names.clear();
    }

    @Override
    protected void add(Context context, int resId, int value) {
        names.add(context.getString(resId));
    }

    public int getFilter(int position) {
        return position;
    }

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

    public String getItem(int position) {
        return names.get(position);
    }

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

    public void setTitle(CharSequence title) {
        this.title = title;
        notifyDataSetChanged();
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            v = makeView(parent);
        }

        ViewHolder h = (ViewHolder) v.getTag();
        h.text1.setText(title);
        h.text2.setText(getItem(position));
        return v;
    }

    private View makeView(ViewGroup parent) {
        View v = inflater.inflate(R.layout.filter_row, parent, false);
        ViewHolder h = new ViewHolder();
        h.text1 = (TextView) v.findViewById(R.id.text1);
        h.text2 = (TextView) v.findViewById(R.id.text2);
        v.setTag(h);
        return v;
    }

    static class ViewHolder {
        TextView text1;
        TextView text2;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        TextView tv = (TextView) convertView;
        if (tv == null) {
            tv = (TextView) inflater.inflate(R.layout.account_filter_dropdown_row, parent, false);
        }
        tv.setText(getItem(position));
        return tv;
    }
}

@@ -1772,32 +1772,117 @@
 anged();%0A    %7D%0A%0A
+    static class ViewHolder %7B%0A        TextView text1;%0A        TextView text2;%0A    %7D%0A%0A
     public View 
@@ -2512,93 +2512,8 @@
  %7D%0A%0A
-    static class ViewHolder %7B%0A        TextView text1;%0A        TextView text2;%0A    %7D%0A%0A
     
@@ -2618,32 +2618,16 @@
     
-Text
 View 
-t
 v =
- (TextView)
  con
@@ -2648,17 +2648,16 @@
     if (
-t
 v == nul
@@ -2677,23 +2677,11 @@
     
-t
 v =
- (TextView)
  inf
@@ -2758,16 +2758,77 @@
       %7D%0A
+        TextView tv = (TextView) v.findViewById(R.id.text1);%0A
         
@@ -2873,17 +2873,16 @@
  return 
-t
 v;%0A    %7D

Fix FilterAdapter