/*
*
* * Copyright 2015 Van Shu
* *
* * 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.mobimvp.cliques.ui.adapter;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.volley.toolbox.ImageLoader;
import com.mobimvp.cliques.AppData;
import com.mobimvp.cliques.R;
import com.mobimvp.cliques.model.Bucket;
import com.mobimvp.cliques.service.RequestManager;
import static com.mobimvp.cliques.util.LogUtils.makeLogTag;
/**
* Created by Van on 2015/2/13.
*/
public class BucketsAdapter extends RecyclerView.Adapter<BucketsAdapter.ViewHolder> {
private static final String TAG = makeLogTag(BucketsAdapter.class);
private Bucket[] mBuckets;
private BitmapDrawable mDefaultAvatarBitmap = (BitmapDrawable) AppData.getContext()
.getResources().getDrawable(R.drawable.default_avatar);
private Context mContext;
public BucketsAdapter(Context context,Bucket[] buckets) {
this.mBuckets = buckets;
this.mContext=context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.buckets_list_item, viewGroup, false);
ViewHolder vh = new ViewHolder(v);
v.setOnClickListener(onClickListener);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mBucketName.setText(mBuckets[position].name);
holder.mBucketDescription.setText(mBuckets[position].description);
holder.mShotCount.setText(mBuckets[position].shotsCount+"shots");
holder.mBucketThumbnailsRequest = RequestManager.loadImage("", RequestManager.getImageListener(holder.mBucketThumb, null, null));
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return mBuckets == null ? 0 : mBuckets.length;
}
private View.OnClickListener onClickListener=new View.OnClickListener(){
@Override
public void onClick(View v) {
}
};
public static class ViewHolder extends RecyclerView.ViewHolder {
public ImageView mBucketThumb;
public TextView mBucketName;
public TextView mBucketDescription;
public TextView mShotCount;
public ImageLoader.ImageContainer mBucketThumbnailsRequest;
public ViewHolder(View v) {
super(v);
mBucketThumb = (ImageView) v.findViewById(R.id.bucket_thumb);
mBucketName = (TextView) v.findViewById(R.id.bucket_name);
mBucketDescription=(TextView) v.findViewById(R.id.bucket_description);
mShotCount=(TextView)v.findViewById(R.id.shot_count);
}
}
}