package com.weikou.beibeivideo.ui.category;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.view.animation.Animation;
|
import android.view.animation.ScaleAnimation;
|
import android.widget.BaseAdapter;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.lcjian.library.util.glide.GlideCircleTransform;
|
import com.weikou.beibeivideo.R;
|
import com.weikou.beibeivideo.entity.VideoType;
|
import com.weikou.beibeivideo.ui.common.VideosLiveActivity;
|
import com.weikou.beibeivideo.ui.mine.BrowserActivity;
|
|
import java.util.List;
|
|
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
|
|
public class CategoryAdapter extends BaseAdapter {
|
|
private List<VideoType> mCategories;
|
|
Context context;
|
|
public CategoryAdapter(List<VideoType> categories, Context context) {
|
super();
|
this.mCategories = categories;
|
this.context = context;
|
}
|
|
@Override
|
public int getCount() {
|
return mCategories == null ? 0
|
: (mCategories.size() % 3 == 0 ? mCategories.size()
|
: mCategories.size() + 1);
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return mCategories.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
@Override
|
public View getView(int position, View convertView, ViewGroup parent) {
|
if (convertView == null) {
|
convertView = LayoutInflater.from(parent.getContext()).inflate(
|
R.layout.category_item, parent, false);
|
}
|
final ImageView iv_category_icon = convertView
|
.findViewById(R.id.iv_category_icon);
|
TextView tv_category_name = convertView
|
.findViewById(R.id.tv_category_name);
|
VideoType category = null;
|
if (position < mCategories.size()) {
|
category = (VideoType) getItem(position);
|
try {
|
Glide.with(context).load(category.getIcon()).transform(new GlideCircleTransform(context)).transition(withCrossFade())
|
.placeholder(R.color.page_content_bg_color).error(R.color.page_content_bg_color).into(iv_category_icon);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
tv_category_name.setText(category.getName());
|
} else {
|
iv_category_icon.setVisibility(View.INVISIBLE);
|
tv_category_name.setVisibility(View.INVISIBLE);
|
convertView.setBackgroundColor(parent.getResources().getColor(
|
R.color.page_content_bg_color));
|
}
|
final VideoType cate1 = category;
|
convertView.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View v) {
|
// showAnimation(iv_category_icon, cate1);
|
if (cate1 == null || StringUtils.isEmpty(cate1.getId()))
|
return;
|
if (cate1.getId().contains("1111")) {
|
Intent intent = new Intent(v.getContext(), VideosLiveActivity.class);
|
intent.putExtra("video_type", cate1.getId());
|
intent.putExtra("title", cate1.getName());
|
v.getContext().startActivity(intent);
|
} else if (cate1.getId().contains("22222")) {
|
Intent intent = new Intent(v.getContext(), BrowserActivity.class);
|
intent.putExtra("url", cate1.getCategoryType());
|
v.getContext().startActivity(intent);
|
} else {
|
Intent intent = new Intent(context, MVideosActivity.class);// category包中的mvideosActivity.class
|
intent.putExtra("video_type", cate1);
|
intent.putExtra("type_name", cate1.getName());
|
// intent.putExtra("title", category.getName());
|
v.getContext().startActivity(intent);
|
}
|
}
|
|
});
|
return convertView;
|
}
|
|
private final class DisplayNextView implements Animation.AnimationListener {
|
ImageView iv;
|
VideoType category;
|
|
public DisplayNextView(ImageView iv, VideoType category) {
|
this.iv = iv;
|
this.category = category;
|
}
|
|
public void onAnimationStart(Animation animation) {
|
}
|
|
// 动画结束
|
public void onAnimationEnd(Animation animation) {
|
// iv.post(new SwapViews(iv));
|
if (category == null) {
|
return;
|
}
|
if (category.getId().contains("1111")) {
|
Intent intent = new Intent(context, VideosLiveActivity.class);
|
intent.putExtra("video_type", category.getId());
|
intent.putExtra("title", category.getName());
|
context.startActivity(intent);
|
} else {
|
Intent intent = new Intent(context, MVideosActivity.class);// category包中的mvideosActivity.class
|
intent.putExtra("video_type", category);
|
intent.putExtra("type_name", category.getName());
|
// intent.putExtra("title", category.getName());
|
context.startActivity(intent);
|
}
|
}
|
|
public void onAnimationRepeat(Animation animation) {
|
}
|
}
|
|
/*
|
* 动画
|
*/
|
private void showAnimation(ImageView iv, VideoType category) {
|
Animation animation = null;
|
animation = new ScaleAnimation(1.0f, 0.5f, 1.0f, 0.5f,
|
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
0.5f);
|
animation.setDuration(200);
|
animation.setAnimationListener(new DisplayNextView(iv, category));
|
iv.startAnimation(animation);
|
}
|
}
|