admin
2021-12-22 0a1336cd2b95126d66d6f3126cb48a446cdbfad1
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package com.hanju.video.app.ui.media;
 
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ScrollView;
 
import com.hanju.video.app.R;
import com.hanju.video.app.entity.video.PushEpisode;
import com.hanju.video.app.entity.video.VideoInfo;
import com.hanju.video.app.entity.video.VideoResource;
import com.hanju.video.app.entity.ad.ExpressAdContainer;
import com.hanju.video.app.util.video.VideoUtil;
import com.hanju.video.app.util.ad.AdUtil;
import com.hanju.video.app.util.ad.ExpressAdManager;
import com.hanju.lib.library.RetainViewFragment;
import com.hanju.lib.library.util.common.DimenUtils;
import com.umeng.analytics.MobclickAgent;
 
import java.util.List;
 
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import de.greenrobot.event.EventBus;
 
/**
 * 播放详情--选集页面
 */
public class VideoEpisodeFragment extends RetainViewFragment implements
        OnClickListener {
 
    private static VideoInfo mVideoInfo;
 
    private int mPlayingPosition;
 
    private ViewPager vp_episode;
 
    private ScrollView sv_detail;
 
    private EpisodePagerAdapter mEpisodePagerAdapter;
 
    private FrameLayout fl_native_ad_1;
 
    public static boolean isShowMore = false;// 是否显示更多
    public static int page_varietyshow = 0;// 综艺节目的分页
    int maxDescripLine = 2;
 
 
    final String TAG = "VideoEpisodeFragment";
 
    public static VideoEpisodeFragment newInstance(VideoInfo videoInfo,
                                                   int playingPostion) {
        VideoEpisodeFragment videoEpisodeFragment = new VideoEpisodeFragment();
        Bundle args = new Bundle();
        args.putSerializable("video_info", videoInfo);
        args.putInt("playing_position", playingPostion);
        videoEpisodeFragment.setArguments(args);
        return videoEpisodeFragment;
    }
 
 
    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
        @Override
        public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDraw(c, parent, state);
        }
 
        @Override
        public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
            super.onDrawOver(c, parent, state);
        }
 
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
            int index = parent.getChildAdapterPosition(view);
            int total = parent.getAdapter().getItemCount();
            if (index % 2 == 0) {
                outRect.left = 0; //第一列左边贴边
                outRect.right = DimenUtils.dipToPixels(5, view.getContext());
            } else {
                outRect.right = 0; //第一列左边贴边
                outRect.left = DimenUtils.dipToPixels(5, view.getContext());
            }
 
            if (index - 1 > 0) {
                outRect.top = DimenUtils.dipToPixels(5, view.getContext());
            } else
                outRect.top = 0;
 
            if (total % 2 == 0) {
                if (total > 2 && (index < total - 2))
                    outRect.bottom = DimenUtils.dipToPixels(5, view.getContext());
                else
                    outRect.bottom = 0;
            } else {
                if (total > 2 && (index < total - 1))
                    outRect.bottom = DimenUtils.dipToPixels(5, view.getContext());
                else
                    outRect.bottom = 0;
            }
        }
    };
 
    @Override
    public int getContentResource() {
        return R.layout.video_episode_fragment;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView");
        sv_detail = contentView.findViewById(R.id.sv_detail);
        mVideoInfo = (VideoInfo) getArguments().getSerializable("video_info");
        mPlayingPosition = getArguments().getInt("playing_position");
 
        vp_episode = contentView.findViewById(R.id.vp_episode);
 
 
        fl_native_ad_1 = contentView
                .findViewById(R.id.fl_native_ad_1);
 
        contentView.findViewById(R.id.ll_container).setFocusable(true);
        contentView.findViewById(R.id.ll_container).setFocusableInTouchMode(true);
 
 
        if (mVideoInfo == null)
            return;
 
        VideoResource videoResource = VideoUtil.getSelectedResource(mVideoInfo.getResourceList());
        mEpisodePagerAdapter = new EpisodePagerAdapter(
                getChildFragmentManager(), mVideoInfo, videoResource != null ? videoResource.getId() : null, mPlayingPosition);
        //
        vp_episode.setAdapter(mEpisodePagerAdapter);
        // 指示当前播放页---hxh
 
        vp_episode.post(new Runnable() {
 
            @Override
            public void run() {
                int page = (mPlayingPosition + 1) % 20 == 0 ? (mPlayingPosition + 1) / 20
                        : (mPlayingPosition + 1) / 20 + 1;
                if (page < 1)
                    return;
                vp_episode.setCurrentItem(page - 1);
                try {
                    mEpisodePagerAdapter.notifyDataSetChanged();
                } catch (Exception e) {
 
                }
            }
        });
    }
 
    private Runnable adRunnable = new Runnable() {
        @Override
        public void run() {
            loadAD2();
        }
    };
 
    @Override
    public void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
    }
 
    @Override
    public void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
        isShowMore = false;
        page_varietyshow = 0;
    }
 
    public void onEventMainThread(VideoInfo info) {
//        Log.i("result", "收到来源点击产生的列表EventBus-------------1,电视剧的长度为:" + mVideoInfo.getVideoDetailList().size());
        int playingPosition = 0;
        if (mPlayingPosition != playingPosition) {
            mPlayingPosition = playingPosition;
        }
 
        VideoResource videoResource = VideoUtil.getSelectedResource(info.getResourceList());
        mEpisodePagerAdapter = new EpisodePagerAdapter(
                getChildFragmentManager(), info, videoResource != null ? videoResource.getId() : null, mPlayingPosition);
        vp_episode.setAdapter(mEpisodePagerAdapter);
    }
 
    public void onEventMainThread(PushEpisode info) {
        if (mVideoInfo == null)
            return;
//        Log.i("result", "收到来源点击产生的列表EventBus-------------1,电视剧的长度为:" + mVideoInfo.getVideoDetailList().size());
        if (mVideoInfo.getShowType() == 1) {// 综艺 如果是综艺的话就分页加载
            if (info.getEpisodeNum() > 10) {
                page_varietyshow = info.getEpisodeNum() / 10 + 1;
                isShowMore = true;
            }
        } else {
            if (info.getEpisodeNum() > 12) {
                isShowMore = true;
            }
        }
        mEpisodePagerAdapter.setPlayingPosition(info.getEpisodeNum());
    }
 
    boolean isExpand;
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
 
        }
    }
 
    /**
     * 广点通原生广告
     */
    // 加载播放页第二条广告
    private void loadAD2() {
        ExpressAdManager expressAdManager = null;
        try {
            expressAdManager = new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (expressAdManager == null)
            return;
 
        expressAdManager.loadVideoDetailRelativeVideoBottomAd(new ExpressAdManager.IAdLoadListener() {
            @Override
            public void onSuccess(List<ExpressAdContainer> adList) {
                if (adList != null && adList.size() > 0)
                    ExpressAdManager.renderAd(getActivity(), adList.get(0), new ExpressAdManager.IAdRenderListener() {
                        @Override
                        public void onRenderSuccess(List<ExpressAdContainer> adList) {
                            ExpressAdManager.fillAd(adList.get(0), fl_native_ad_1);
                        }
 
                        @Override
                        public void onRenderFail(List<ExpressAdContainer> adList) {
 
                        }
                    }, new ExpressAdManager.IAdEventListener() {
 
                        @Override
                        public void closeAd(ExpressAdContainer ad) {
                            fl_native_ad_1.removeAllViews();
                        }
                    });
 
            }
        });
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}