/*
 * Copyright 2014 MMAUG (Myanmar Android User Group)
 *
 * 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 org.mmaug.bf101.adapter;

import android.app.Activity;
import android.content.Context;
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.TextView;
import butterknife.ButterKnife;
import butterknife.InjectView;
import java.util.ArrayList;
import java.util.List;
import org.mmaug.bf101.R;
import org.mmaug.bf101.model.Shop;

/**
 * This file is created by Nyan Lynn Htut
 * for BF101 on 6/8/2014.
 */

public class ShopListAdapter extends BaseAdapter {

  private final Context mContext;
  private List<Shop> shops;

  public ShopListAdapter(Context context, ArrayList<Shop> shops) {
    this.mContext = context;
    this.shops = shops;
  }

  @Override
  public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    LayoutInflater mInflater =
        (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (view != null) {
      holder = (ViewHolder) view.getTag();
    } else {
      view = mInflater.inflate(R.layout.shop_list_item, parent, false);
      holder = new ViewHolder(view);
      view.setTag(holder);
    }
    Shop model = getItem(position);
    holder.name.setText(model.name);
    int padding = (int) mContext.getResources().getDimension(R.dimen.featured);
    holder.featuredHeader.setPadding(padding, padding, padding, padding);
    Typeface font = Typeface.createFromAsset(mContext.getAssets(), "fonts/zawgyi.ttf");
    holder.name.setTypeface(font);
    holder.address.setText(model.address);
    holder.address.setTypeface(font);
    if (model.newshop) {
      holder.newshop.setVisibility(View.VISIBLE);
    }
    return view;
  }

  @Override
  public int getCount() {
    return shops.size();
  }

  @Override
  public Shop getItem(int position) {
    return shops.get(position);
  }

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

  static class ViewHolder {
    @InjectView(R.id.shop_name) TextView name;
    @InjectView(R.id.shop_address) TextView address;
    @InjectView(R.id.new_shop) TextView newshop;
    @InjectView(R.id.FeaturedHeader) ImageView featuredHeader;

    public ViewHolder(View view) {
      ButterKnife.inject(this, view);
    }
  }
}

@@ -2024,82 +2024,8 @@
 d);%0A
-    holder.featuredHeader.setPadding(padding, padding, padding, padding);%0A
     
@@ -2740,71 +2740,8 @@
 hop;
-%0A    @InjectView(R.id.FeaturedHeader) ImageView featuredHeader;
 %0A%0A  

remove unused variable