/* * * * 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.content.Intent; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.android.volley.toolbox.ImageLoader; import com.mobimvp.cliques.R; import com.mobimvp.cliques.model.Follower; import com.mobimvp.cliques.service.RequestManager; import com.mobimvp.cliques.ui.ProfileActivity; /** * Created by Van on 2015/2/15. */ public class FollowerAdapter extends RecyclerView.Adapter<FollowerAdapter.ViewHolder> { private Follower.FollowerRequestData[] mFollowers; private Context mContext; public static final int TYPE_FOLLOWER=0x00000001; public static final int TYPE_FOLLOWEE=0x00000002; private int mType=0; public FollowerAdapter(Context context,Follower.FollowerRequestData[] followers,int type){ this.mContext=context; this.mFollowers=followers; this.mType=type; } @Override public FollowerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.followers_list_item, viewGroup, false); ViewHolder vh = new ViewHolder(v); return vh; } @Override public void onBindViewHolder(FollowerAdapter.ViewHolder holder, int position) { if(mType==TYPE_FOLLOWER){ holder.mName.setText(mFollowers[position].follower.name); holder.mUserAvatarRequest = RequestManager.loadImage(mFollowers[position].follower.avatarUrl, RequestManager.getImageListener(holder.mUserAvatar, null, null)); }else if(mType==TYPE_FOLLOWEE){ holder.mName.setText(mFollowers[position].followee.name); holder.mUserAvatarRequest = RequestManager.loadImage(mFollowers[position].followee.avatarUrl, RequestManager.getImageListener(holder.mUserAvatar, null, null)); } } @Override public int getItemCount() { return mFollowers.length; } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ public ImageView mUserAvatar; public TextView mName; public ImageLoader.ImageContainer mUserAvatarRequest; public ViewHolder(View v) { super(v); mUserAvatar = (ImageView) v.findViewById(R.id.user_avatar); mName = (TextView) v.findViewById(R.id.name); v.setOnClickListener(this); } /** * Called when a view has been clicked. * * @param v The view that was clicked. */ @Override public void onClick(View v) { Intent intent=new Intent(mContext, ProfileActivity.class); if(mType==TYPE_FOLLOWER){ intent.putExtra("userId",mFollowers[getPosition()].follower.id); }else if(mType==TYPE_FOLLOWEE){ intent.putExtra("userId",mFollowers[getPosition()].followee.id); } mContext.startActivity(intent); } } }