admin
2024-01-26 c2d382d99ca506932985d1843d4371d6ed0203ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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);
    }
}