admin
2021-07-15 49982f5a1a305c0cc7da04735e1c604b802d2a22
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
package com.mugua.mgvideo.ui.main;
 
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.view.View;
 
import com.androidquery.AQuery;
import com.lcjian.library.RetainViewFragment;
import com.viewpagerindicator.FoundTabPageIndicator;
import com.yeshi.base.utils.downutil.StringUtils;
import com.yeshi.ec.library_baiducpu.entity.BaiDuCPUType;
import com.yeshi.ec.library_baiducpu.fragment.BaiDuCPUContentFragment;
import com.yeshi.ec.library_baiducpu.fragment.BaiDuShortVideosFragment;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
 
/**
 * 百度资讯
 */
public class BaiDuVideosFragment extends RetainViewFragment {
 
    private ViewPager viewPager;
    private ContentAdapter contentAdapter;
    private List<BaiDuCPUType> itemList = new ArrayList<>();
    private FoundTabPageIndicator indicator;
    private AQuery mAQuery;
 
    public final BaiDuCPUType[] types = new BaiDuCPUType[]{
            new BaiDuCPUType("影视", 1060),
            new BaiDuCPUType("娱乐", 1061),
            new BaiDuCPUType("音乐", 1058),
            new BaiDuCPUType("小品", 1062),
            new BaiDuCPUType("生活", 1066),
//            new BaiDuCPUType("观天下", 1064),
            new BaiDuCPUType("搞笑", 1059),
 
            new BaiDuCPUType("社会", 1063),
    };
 
    public static BaiDuVideosFragment newInstance() {
        BaiDuVideosFragment fragment = new BaiDuVideosFragment();
        return fragment;
    }
 
 
    @Override
    public int getContentResource() {
        return com.yeshi.ec.library_baiducpu.R.layout.fragment_baidu_news_root;
    }
 
    private void initView(View contentView) {
        viewPager = contentView.findViewById(com.yeshi.ec.library_baiducpu.R.id.vp_news);
    }
 
    private String getCacheKey() {
        return StringUtils.MD5("getBaiDuNewsTypeList");
    }
 
    private void initData(View contentView) {
        mAQuery = new AQuery(contentView);
 
    }
 
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        initView(contentView);
        initData(contentView);
        setData();
    }
 
 
    public void setData() {
        List<BaiDuCPUType> list = Arrays.asList(types);
        itemList.clear();
        itemList.addAll(list);
        contentAdapter = new BaiDuVideosFragment.ContentAdapter(
                getChildFragmentManager(), itemList);
        viewPager.setAdapter(contentAdapter);
        ((FoundTabPageIndicator) mAQuery.id(com.yeshi.ec.library_baiducpu.R.id.indicator).getView()).setViewPager(viewPager);
    }
 
    class ContentAdapter extends FragmentStatePagerAdapter {
        private FragmentManager fm;
 
        private List<BaiDuCPUType> mlist;
 
        public ContentAdapter(FragmentManager fm, List<BaiDuCPUType> list) {
            super(fm);
            this.fm = fm;
            this.mlist = list;
        }
 
        @Override
        public Fragment getItem(int position) {
            if (mlist.get(position).getId() == 1085)
                return BaiDuShortVideosFragment.newInstance(mlist.get(position));
            else
                return BaiDuCPUContentFragment.newInstance(mlist.get(position), mlist.get(position).getId() == 1085 ? BaiDuCPUContentFragment.VIEW_TYPE_SMALLVIDEO : BaiDuCPUContentFragment.VIEW_TYPE_VIDEO);
        }
 
        @Override
        public int getCount() {
            return mlist.size();
        }
 
 
        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return mlist.get(position).getName();
        }
    }
 
}