admin
2022-01-07 8dfe5354073b700af45d5cb472dd5f003e6f3f25
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package com.ysvideo.zhibo.app.ui.video;
 
import android.graphics.Canvas;
import android.graphics.Color;
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.androidquery.AQuery;
import com.ysvideo.zhibo.app.R;
import com.ysvideo.zhibo.app.entity.ad.ExpressAdContainer;
import com.ysvideo.zhibo.app.entity.video.PushEpisode;
import com.ysvideo.zhibo.app.entity.video.VideoInfo;
import com.ysvideo.zhibo.app.entity.video.VideoResource;
import com.ysvideo.zhibo.app.ui.video.adapter.EpisodePagerAdapter;
import com.ysvideo.zhibo.app.util.ad.ExpressAdManager;
import com.ysvideo.zhibo.app.util.video.VideoUtil;
import com.ysvideo.zhibo.lib.common.RetainViewFragment;
import com.ysvideo.zhibo.lib.common.util.common.DimenUtils;
import com.ysvideo.zhibo.library_ad.AdUtil;
 
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 EpisodePagerAdapter mEpisodePagerAdapter;
 
    private FrameLayout fl_native_ad_1;
 
    public static boolean isShowMore = false;// 是否显示更多
    public static int page_varietyshow = 0;// 综艺节目的分页
    int maxDescripLine = 2;
 
    private AQuery mAQuery;
 
 
    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.fragment_video_episode;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Log.d(TAG, "onCreateView");
        mAQuery = new AQuery(contentView);
        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.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
 
            }
 
            @Override
            public void onPageSelected(int position) {
                setSelected(position);
            }
 
            @Override
            public void onPageScrollStateChanged(int state) {
 
            }
        });
 
        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) {
 
                }
            }
        });
 
        mAQuery.id(R.id.fl_desc).clicked(new OnClickListener() {
            @Override
            public void onClick(View v) {
                vp_episode.setCurrentItem(1);
            }
        });
 
        mAQuery.id(R.id.fl_episode).clicked(new OnClickListener() {
            @Override
            public void onClick(View v) {
                vp_episode.setCurrentItem(0);
            }
        });
 
        setSelected(0);
    }
 
    private void setSelected(int index) {
 
        mAQuery.id(R.id.fl_desc).backgroundColor(Color.WHITE);
        mAQuery.id(R.id.tv_desc).textColor(Color.parseColor("#FF999999"));
        mAQuery.id(R.id.v_desc).visibility(View.GONE);
 
        mAQuery.id(R.id.fl_episode).backgroundColor(Color.WHITE);
        mAQuery.id(R.id.tv_episode).textColor(Color.parseColor("#FF999999"));
        mAQuery.id(R.id.v_episode).visibility(View.GONE);
 
 
        if (index == 0) {
            mAQuery.id(R.id.fl_episode).backgroundColor(Color.parseColor("#FFEFF9FF"));
            mAQuery.id(R.id.tv_episode).textColor(getResources().getColor(R.color.theme));
            mAQuery.id(R.id.v_episode).visibility(View.VISIBLE);
        } else {
            mAQuery.id(R.id.fl_desc).backgroundColor(Color.parseColor("#FFEFF9FF"));
            mAQuery.id(R.id.tv_desc).textColor(getResources().getColor(R.color.theme));
            mAQuery.id(R.id.v_desc).visibility(View.VISIBLE);
        }
 
 
    }
 
    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(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();
    }
}