admin
2025-02-26 daea6f9a47aae244b5fa02b5c790519934711760
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.weikou.beibeivideo.ui.media;
 
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.lcjian.library.RetainViewFragment;
import com.lcjian.library.dialog.DialogUtil;
import com.lcjian.library.util.ManifestDataUtil;
import com.lcjian.library.util.SingleToast;
import com.lcjian.library.util.common.AndroidManifestUtil;
import com.lcjian.library.util.common.DimenUtils;
import com.lcjian.library.util.common.StringUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMWeb;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.BeibeiVideoApplication;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.db.WatchHistoryTable;
import com.weikou.beibeivideo.entity.Follow;
import com.weikou.beibeivideo.entity.Play;
import com.weikou.beibeivideo.entity.PlayUrl;
import com.weikou.beibeivideo.entity.Playlocation;
import com.weikou.beibeivideo.entity.VideoDetailInfo;
import com.weikou.beibeivideo.entity.VideoInfo;
import com.weikou.beibeivideo.entity.VideoResource;
import com.weikou.beibeivideo.entity.ad.AdPositionEnum;
import com.weikou.beibeivideo.entity.ad.ExpressAdContainer;
import com.weikou.beibeivideo.entity.video.FunshionPlayInfo;
import com.weikou.beibeivideo.ui.dialog.VideoResourceListDialog;
import com.weikou.beibeivideo.ui.login.LoginActivity;
import com.weikou.beibeivideo.ui.video.EpisodeNewAdapter;
import com.weikou.beibeivideo.util.JsonUtil;
import com.weikou.beibeivideo.util.UserUtil;
import com.weikou.beibeivideo.util.VideoUtil;
import com.weikou.beibeivideo.util.ad.AdUtil;
import com.weikou.beibeivideo.util.ad.ExpressAdManager;
 
import org.apache.http.Header;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONArray;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
/**
 * 节目选集列表,可设置电视剧6列;电影,综艺1列
 */
public class EpisodeFragment extends RetainViewFragment implements View.OnClickListener {
    private int mStart;
    private int mEnd;
    private int mPlayingPosition;
    private VideoInfo mVideoInfo = null;
    private RecyclerView rv_episode;
 
    private LinearLayout fl_report;
    private ImageView iv_favourite;
 
    private ImageView iv_moive_img;
 
    private TextView tv_star_name, tv_update_time, tv_cancle_follow, tv_video_resource, tv_title, tv_score, tv_play_num;
 
    private LinearLayout ll_add_attention;
 
    private FrameLayout fl_native_ad1;
 
    private EpisodeNewAdapter episodeAdapter;
 
    final String TAG = "EpisodeFragment";
 
    private boolean episodeLoading = false;//剧集是否正在加载更多
 
    private boolean episodeHasMore = true;//是否还有更多的剧集
 
    private int episodePage = 2;//当前页
 
    //默认页大小为100
    private int pageSize = 100;
 
    private String fromName = null;
 
    public static DisplayImageOptions option = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.from_other)
            .showImageOnFail(R.drawable.from_other)
            .showImageOnLoading(R.drawable.from_other)
            .resetViewBeforeLoading(false) // default
            .cacheInMemory(true) // default
            .cacheOnDisk(true) // default
            .considerExifParams(false) // default
            .imageScaleType(ImageScaleType.EXACTLY) // default
            .bitmapConfig(Bitmap.Config.ARGB_8888) // default
            .handler(new Handler()) // default
            .build();
 
    public static EpisodeFragment newInstance(VideoInfo videoInfo,
                                              int playingPosition, int pageSize, int start, int end, String from) {
        EpisodeFragment episodeFragment = new EpisodeFragment();
        Bundle args = new Bundle();
        args.putSerializable("video_info", videoInfo);
        args.putInt("playing_position", playingPosition);
        args.putInt("start", start);
        args.putInt("end", end);
        args.putInt("pageSize", pageSize);
        args.putString("from", from);
        episodeFragment.setArguments(args);
        return episodeFragment;
    }
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_episode;
    }
 
 
    private void setVideoInfo() {
        if (mVideoInfo == null)
            return;
        tv_title.setText(mVideoInfo.getName());
        if (!StringUtils.isBlank(mVideoInfo.getScore())) {
            tv_score.setText("评分:" + mVideoInfo.getScore());
            tv_score.setVisibility(View.VISIBLE);
        } else {
            tv_score.setVisibility(View.GONE);
        }
        tv_play_num.setText("播放:" + VideoUtil.getWatchCountShortName(mVideoInfo.getWatchCount()));
    }
 
    public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
        private int space;
 
        public SpacesItemDecoration(int space) {
            this.space = space;
        }
 
        @Override
        public void getItemOffsets(Rect outRect, View view,
                                   RecyclerView parent, RecyclerView.State state) {
            int position = parent.getChildAdapterPosition(view);
            outRect.left = space;
            if (mVideoInfo != null && position == VideoUtil.videoEpisodeList.size() - 1)
                outRect.right = space;
        }
    }
 
    private void loadEpisode() {
 
        int type = 0;
 
        if (mVideoInfo.getShowType() == 1) {
            // 综艺或者电影
            type = EpisodeNewAdapter.TYPE_ZONGYI;
 
        } else if (mVideoInfo.getShowType() == 2) {
            // 电视剧动漫
            type = EpisodeNewAdapter.TYPE_DIANSHIJU;
        }
        episodeAdapter = new EpisodeNewAdapter(getContext(), mVideoInfo, type, mPlayingPosition, new EpisodeNewAdapter.ISelectVideoEpisodeListener() {
            @Override
            public void onClick(int position, VideoDetailInfo detailInfo) {
                setEpisodeSelected(position);
                getUrl(detailInfo);
            }
        });
        LinearLayoutManager ms = new LinearLayoutManager(getContext());
        ms.setOrientation(LinearLayoutManager.HORIZONTAL);
        rv_episode.setHasFixedSize(true);
        rv_episode.setNestedScrollingEnabled(false);
        if (rv_episode.getLayoutManager() == null)
            rv_episode.setLayoutManager(ms);
 
        if (rv_episode.getItemDecorationCount() == 0)
            rv_episode.addItemDecoration(new SpacesItemDecoration(DimenUtils.dip2px(getContext(), 10)));
    }
 
 
    //设置选中状态
    private void setEpisodeSelected(int position) {
        mPlayingPosition = position;
        episodeAdapter.setPlayingPosition(mPlayingPosition);
        refresh();
        Playlocation playlocation = new Playlocation();
        playlocation.setPosition(position);
        EventBus.getDefault().post(playlocation);
    }
 
    private void setFollowData(boolean attention) {
        tv_cancle_follow.setBackgroundResource(R.drawable.shape_video_detail_follow_btn);
        tv_cancle_follow.setTextColor(getResources().getColor(R.color.video_detail_follow_text_color));
        if (attention) {
            tv_cancle_follow.setText("已关注");
            tv_cancle_follow.setCompoundDrawables(null, null, null, null);
        } else {
            tv_cancle_follow.setText("关注");
            Drawable drawable = getResources().getDrawable(R.drawable.ic_follow_add_w);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            tv_cancle_follow.setCompoundDrawables(drawable, null, null, null);
        }
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Log.i(TAG, "onCreateView");
        Bundle bundle = getArguments();
        mVideoInfo = (VideoInfo) bundle
                .getSerializable("video_info");
        fromName = bundle
                .getString("from", "");
 
        mPlayingPosition = bundle.getInt("playing_position");
        pageSize = bundle.getInt("pageSize", 100);
        mStart = bundle.getInt("start");
        mEnd = bundle.getInt("end");
 
        if (bundle != null)
            bundle.clear();
 
        //防止没有内容崩溃
        if (mVideoInfo == null)
            return;
 
        tv_video_resource = contentView.findViewById(R.id.tv_video_resource);
        ll_add_attention = contentView.findViewById(R.id.ll_add_attention);
        ll_add_attention.setBackgroundResource(R.drawable.shape_video_detail_follow_bg);
        tv_title = contentView.findViewById(R.id.tv_title);
        tv_score = contentView.findViewById(R.id.tv_score);
        tv_play_num = contentView.findViewById(R.id.tv_play_num);
 
 
        if (mVideoInfo.getAttention() == null) {
            ll_add_attention.setVisibility(View.GONE);
        } else {
            ll_add_attention.setVisibility(View.VISIBLE);
            iv_moive_img = contentView.findViewById(R.id.iv_moive_img);
            tv_star_name = contentView.findViewById(R.id.tv_star_name);
            tv_update_time = contentView.findViewById(R.id.tv_update_time);
            tv_cancle_follow = contentView.findViewById(R.id.tv_cancle_follow);
            try {
                Glide.with(getActivity().getApplicationContext()).load(mVideoInfo.getAttention().getMoviePicture())
                        .apply(new RequestOptions().centerCrop().placeholder(R.drawable.ic_default).error(R.drawable.ic_default))
                        .into(iv_moive_img);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            tv_star_name.setText(mVideoInfo.getAttention().getMovieName() + "");
            tv_update_time.setText(mVideoInfo.getAttention().getUpdateInfo() + "");
            setFollowData(mVideoInfo.getAttention().isAttention());
 
            tv_cancle_follow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
                    String uid = sp.getString("uid", "");
                    String loginid = sp.getString("LoginUid", "");
                    if (StringUtils.isEmpty(loginid)) {
                        Toast.makeText(ll_add_attention.getContext(), "登录成功后才能进行关注!", Toast.LENGTH_LONG).show();
                        UserUtil.toLogin(ll_add_attention.getContext());
                        return;
                    }
                    if (mVideoInfo.getAttention().isAttention()) {//取消关注
                        cancleAttention(uid, loginid);
                    } else {//关注
                        addAttention(uid, loginid);
                    }
                }
            });
        }
 
        setVideoInfo();
 
        fl_native_ad1 = contentView
                .findViewById(R.id.fl_native_ad_1);
        rv_episode = contentView.findViewById(R.id.rv_episode);
 
        contentView.findViewById(R.id.iv_share).setOnClickListener(this);
        contentView.findViewById(R.id.iv_offline_cache).setOnClickListener(this);
        fl_report = contentView.findViewById(R.id.fl_report);
        iv_favourite = contentView.findViewById(R.id.iv_add_to_favourite);
        fl_report.setOnClickListener(this);
        iv_favourite.setOnClickListener(this);
        loadEpisode();
        refresh();
        isCollect();
        loadAD1();
        setFrom(mVideoInfo);
        if (VideoUtil.videoEpisodeList != null && VideoUtil.videoEpisodeList.size() > 1) {
            rv_episode.setVisibility(View.VISIBLE);
        } else
            rv_episode.setVisibility(View.GONE);
 
        //
        rv_episode.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                int first = manager.findFirstVisibleItemPosition();
                int last = manager.findLastVisibleItemPosition();
                int total = manager.getItemCount();
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    if (mVideoInfo == null)
                        return;
                    if (!episodeLoading && episodeHasMore && last == total - 1) {//加载更多
                        VideoResource checkedResource = null;
                        for (VideoResource vr : mVideoInfo.getResourceList()) {
                            checkedResource = vr;
                            break;
                        }
                        if (checkedResource != null) {
                            loadMoreEpisode(mVideoInfo.getId(), checkedResource.getId(), episodePage, pageSize);
                        }
                    }
                }
            }
 
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, final int dy) {
                super.onScrolled(recyclerView, dx, dy);
            }
        });
 
 
        EventBus.getDefault().register(this);
    }
 
    @Subscribe
    public void onEventMainThread(Playlocation playlocation) {
        mPlayingPosition = playlocation.getPosition();
//        loadEpisode();
        refresh();
    }
 
    @Subscribe
    public void onEventMainThread(FunshionPlayInfo info) {
        Log.i(TAG, "风行选集:" + info.getPosition());
        mPlayingPosition = info.getPosition();
        episodeAdapter.setPlayingPosition(mPlayingPosition);
        refresh();
        rv_episode.scrollToPosition(mPlayingPosition);
    }
 
    private void addAttention(String uid, String loginId) {
        BeibeiVideoAPI.addAttention(ll_add_attention.getContext(), uid, loginId, mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optBoolean("IsPost")) {
                    SingleToast.showToast(ll_add_attention.getContext(), "添加关注成功!");
                    mVideoInfo.getAttention().setAttention(true);
                    setFollowData(mVideoInfo.getAttention().isAttention());
 
                }
            }
        });
    }
 
    private void cancleAttention(String uid, String loginId) {
        BeibeiVideoAPI.cancelAttention(ll_add_attention.getContext(), uid, loginId, mVideoInfo.getId(), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optBoolean("IsPost")) {
                    SingleToast.showToast(ll_add_attention.getContext(), "取消关注成功!");
                    mVideoInfo.getAttention().setAttention(false);
                    setFollowData(mVideoInfo.getAttention().isAttention());
                }
            }
        });
    }
 
    @Override
    public void onResume() {
        Log.i(TAG, "onResume:");
        super.onResume();
    }
 
    @Override
    public void onDestroyView() {
        Log.i(TAG, "onDestroyView:");
        super.onDestroyView();
 
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
 
    @Override
    public void onPause() {
        Log.i(TAG, "onPause");
        super.onPause();
    }
 
    private void getUrl(VideoDetailInfo info) {
        SharedPreferences preferences = getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        BeibeiVideoAPI.getPlayUrl(getContext(), uid, info.getType(), mVideoInfo.getId(),
                info.getId(), selectedUrl.getId(), info.geteId(),
                new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
 
                            VideoResource resource = JsonUtil.videoGson.fromJson(
                                    jsonObject.getJSONObject("Data")
                                            .getJSONObject("Resource")
                                            .toString(),
                                    new TypeToken<VideoResource>() {
                                    }.getType());
                            PlayUrl info = new PlayUrl();
                            info.setResource(resource);
                            info.setPlayType(Integer.parseInt(jsonObject
                                    .getJSONObject("Data")
                                    .optString("PlayType")));
                            info.setUrl(jsonObject.getJSONObject("Data")
                                    .optString("Url"));
                            info.setParams(jsonObject.getJSONObject("Data")
                                    .optString("Params"));
                            info.setAid(jsonObject.getJSONObject("Data")
                                    .optString("Aid"));
                            info.setVid(jsonObject.getJSONObject("Data")
                                    .optString("Vid"));
                            info.setCode(jsonObject.getJSONObject("Data")
                                    .optString("Code"));
                            Play play = new Play();
                            play.setPlayUrl(info);
                            EventBus.getDefault().post(play);
                        }
                    }
 
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString, throwable);
 
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        if (pd != null && pd.isShowing())
                            pd.dismiss();
                    }
                });
    }
 
    public boolean isPlaying() {
        return mStart <= mPlayingPosition && mPlayingPosition < mEnd;
    }
 
    /**
     * 刷新adapter
     */
    public void refresh() {
        if (rv_episode.getAdapter() != null)
            rv_episode.getAdapter().notifyDataSetChanged();
        else
            rv_episode.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.i(TAG, "refresh");
                    rv_episode.setAdapter(episodeAdapter);
                    if (mPlayingPosition > 4)
                        rv_episode.scrollToPosition(mPlayingPosition);
                }
            }, 500);
 
 
    }
 
    // 加载播放页第一条广告,先设置加载上下文环境和条件
    private void loadAD1() {
        //vivo无广告
        if ("vivo".equalsIgnoreCase(AndroidManifestUtil.getChannel(getContext()))) {
            return;
        }
        if( AndroidManifestUtil.isHuaWeiChannel(getContext())){
            return;
        }
 
 
        if (AdUtil.getAdType(getContext(), AdPositionEnum.splash) == null) {
            return;
        }
 
        AdUtil.AD_TYPE adType = AdUtil.AD_TYPE.gdt2;
        if(AndroidManifestUtil.isOppoChannel(getContext())){
            adType = null;
        }
        new ExpressAdManager(adType , getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() {
            @Override
            public void onSuccess(List<ExpressAdContainer> adList) {
                if (adList != null && adList.size() > 0) {
                    fl_native_ad1.setVisibility(View.VISIBLE);
                    final ExpressAdContainer ad = adList.get(0);
                    if (getActivity() == null)
                        return;
 
                    ExpressAdManager.renderAd(getActivity(), adList.get(0), new ExpressAdManager.IAdRenderListener() {
                        @Override
                        public void onRenderSuccess(List<ExpressAdContainer> adList) {
                            ExpressAdManager.fillAd(adList.get(0), fl_native_ad1);
                        }
 
                        @Override
                        public void onRenderFail(List<ExpressAdContainer> adList) {
 
                        }
                    }, new ExpressAdManager.IAdEventListener() {
                        @Override
                        public void closeAd(ExpressAdContainer ad) {
                            fl_native_ad1.removeAllViews();
                        }
                    });
 
                } else {
                    //加载穿山甲
                    new ExpressAdManager(AndroidManifestUtil.isHuaWeiChannel(getContext())? AdUtil.AD_TYPE.hw :AdUtil.AD_TYPE.csj, getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() {
                        @Override
                        public void onSuccess(List<ExpressAdContainer> adList) {
                            if (adList != null && adList.size() > 0) {
                                ExpressAdManager.renderAndFillAd(getActivity(), adList.get(0), fl_native_ad1, new ExpressAdManager.IAdEventListener() {
                                    @Override
                                    public void closeAd(ExpressAdContainer ad) {
                                        fl_native_ad1.removeAllViews();
                                    }
                                });
                            } else {
                                fl_native_ad1.setVisibility(View.GONE);
                            }
                        }
                    });
                }
            }
        });
    }
 
 
    @Override
    public void onClick(View v) {
        SharedPreferences preferences = getContext()
                .getSharedPreferences("user", Context.MODE_PRIVATE);
        switch (v.getId()) {
            case R.id.iv_add_to_favourite:
                final String loginUid = preferences.getString("LoginUid", "");
                if (StringUtils.isEmpty(loginUid)) {
                    SingleToast.showToast(ll_add_attention.getContext(), "登录后才能收藏");
                    UserUtil.toLogin(ll_add_attention.getContext());
                    break;
                }
                String uid = preferences.getString("uid", "");
                BeibeiVideoAPI.isCollect(getContext(), uid, mVideoInfo.getId(),
                        mVideoInfo.getThirdType(),
                        new BasicTextHttpResponseHandler() {
 
                            @Override
                            public void onSuccessPerfect(int statusCode,
                                                         Header[] headers, JSONObject jsonObject)
                                    throws Exception {
                                if (jsonObject.getBoolean("IsPost")) {
                                    getScoreCollect(loginUid, "0", mVideoInfo.getThirdType());
                                } else {
                                    getScoreCollect(loginUid, "1", mVideoInfo.getThirdType());
                                }
                            }
                        });
                break;
            case R.id.fl_report:
 
                if (selectedUrl == null || selectedUrl.getPicture() == null) {
 
                } else {
                    DialogUtil.show(resourceListDialog);
                }
 
                break;
            case R.id.iv_offline_cache:
                Toast.makeText(ll_add_attention.getContext(), "暂时无法缓存!", Toast.LENGTH_SHORT).show();
                break;
            case R.id.iv_share:
                String shareContent = getShareContent();
                UMWeb web = new UMWeb(getShareUrl());
                String shareTitle = getResources().getString(R.string.app_name);
                web.setTitle(shareTitle);
                web.setDescription(shareContent);
                new ShareAction(getActivity()).withText(shareContent).withMedia(web)
                        .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
                        .setCallback(shareListener).open();
        }
    }
 
    UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
 
        }
 
        @Override
        public void onResult(SHARE_MEDIA share_media) {
            Toast.makeText(iv_favourite.getContext(), "分享成功!", Toast.LENGTH_LONG).show();
        }
 
        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {
            if (!UMShareAPI.get(ll_add_attention.getContext()).isInstall(getActivity(), share_media)) {
                Toast.makeText(iv_favourite.getContext(), share_media == SHARE_MEDIA.QQ ? "没有安装QQ" : "没有安装微信", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(iv_favourite.getContext(), "分享出错!", Toast.LENGTH_LONG).show();
            }
        }
 
        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            Toast.makeText(iv_favourite.getContext(), "分享取消!", Toast.LENGTH_LONG).show();
        }
    };
 
    private String getShareContent() {
        return "我在" + iv_favourite.getContext().getResources().getString(R.string.app_name)
                + "看了《" + mVideoInfo.getName()
                + "》影片,非常不错,大家一起来看吧!" + getShareUrl();
    }
 
    private String getShareUrl() {
        SharedPreferences preferences = iv_favourite.getContext().getSharedPreferences("user",
                Context.MODE_PRIVATE);
        return preferences.getString("share_url", "http://yy.umgotv.com");
    }
 
    List<VideoResource> urlList;
    VideoResource selectedUrl = null;
 
    @Subscribe
    public void onEventMainThread(VideoInfo videoInfo) {
        mVideoInfo = videoInfo;
        if (VideoUtil.videoEpisodeList != null && VideoUtil.videoEpisodeList.size() > 1) {
            rv_episode.setVisibility(View.VISIBLE);
        } else
            rv_episode.setVisibility(View.GONE);
        setFrom(videoInfo);
        iv_favourite.setEnabled(true);
        fl_report.setEnabled(true);
        rv_episode.setAdapter(episodeAdapter);
 
    }
 
    private void setFrom(VideoInfo info) {
        if (urlList == null)
            urlList = new ArrayList<VideoResource>();
        urlList.clear();
        for (int i = 0; i < info.getResourceList().size(); i++) {
            if (info.getResourceList().get(i).isChecked()) {
                selectedUrl = info.getResourceList().get(i);
            }
        }
        EventBus.getDefault().post(selectedUrl);
        iv_favourite.postDelayed(new Runnable() {
 
            @Override
            public void run() {
                EventBus.getDefault().post(selectedUrl);
            }
        }, 1000);
        urlList.addAll(info.getResourceList());
        initResource();
    }
 
    private ProgressDialog pd;
 
    private void setResource(String resource) {
        SpannableString st = new SpannableString(resource);
        st.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.video_detail_resource_text_color)), 3, resource.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tv_video_resource.setText(st);
    }
 
    VideoResourceListDialog resourceListDialog;
 
    private void initResource() {
 
        if (mVideoInfo.getResourceList() != null
                && mVideoInfo.getResourceList().size() > 0) {
            tv_video_resource.setVisibility(View.VISIBLE);
            String resource = "";
            if (selectedUrl == null || selectedUrl.getPicture() == null) {
                resource = "来源:其他";
            } else {
                resource = "来源:" + selectedUrl.getName();
            }
            setResource(resource);
 
            if (resourceListDialog != null)
                DialogUtil.dismiss(resourceListDialog);
 
            resourceListDialog = new VideoResourceListDialog.Builder(getActivity()).setCloseListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DialogUtil.dismiss(resourceListDialog);
                }
            }).setItemClickListener(new VideoResourceListDialog.ItemClickListener() {
                @Override
                public void onClick(int position, VideoResource videoResource) {
                    DialogUtil.dismiss(resourceListDialog);
                    if (selectedUrl.getId() != urlList.get(position).getId()) {
                        pd = new ProgressDialog(ll_add_attention.getContext());
                        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 设置进度条的形式为圆形转动的进度条
                        pd.setCancelable(true);// 设置是否可以通过点击Back键取消
                        pd.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
                        pd.setMessage("网络加载中·······");
                        pd.show();
                        getVideoDetail(mVideoInfo.getId(), urlList
                                .get(position).getId(), mVideoInfo
                                .getThirdType(), true, fromName);
                    }
                    selectedUrl = urlList.get(position);
                    if (selectedUrl == null || selectedUrl.getPicture() == null) {
                        setResource("来源:其他");
                    } else {
                        setResource("来源:" + selectedUrl.getName());
                    }
                }
            }).setVideoResources(mVideoInfo.getResourceList()).create();
 
        } else {
            tv_video_resource.setVisibility(View.GONE);
        }
 
    }
 
 
    private void getVideoDetail(String videoId, final String resourceId,
                                String videoThirdType, final boolean isSetup, final String from) {
        SharedPreferences preferences = getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        String loginid = preferences.getString("LoginUid", "");
        BeibeiVideoAPI.getVideoDetail(getContext(), uid, resourceId, videoId, null, loginid,
                videoThirdType, from, new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onStart() {
                        super.onStart();
                    }
 
                    @Override
                    public void onFailure(int statusCode, Header[] headers,
                                          String responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString,
                                throwable);
 
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        if (pd != null && pd.isShowing())
                            pd.dismiss();
                    }
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        try {
                            if (getActivity().isDestroyed()) {
                                return;
                            }
                        } catch (NoSuchMethodError e) {
                            e.printStackTrace();
                        }
                        if (jsonObject.getBoolean("IsPost")) {
 
 
                            final VideoInfo videoInfo = JsonUtil.videoGson
                                    .fromJson(jsonObject.getJSONObject("Data")
                                                    .toString(),
                                            new TypeToken<VideoInfo>() {
                                            }.getType());
                            if (videoInfo != null) {
 
                                VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, videoInfo.getVideoDetailList(), false);
 
                            }
                            // 附加字段
                            if (jsonObject.optJSONObject("Extra1") != null) {
                                if (jsonObject.optJSONObject("Extra1").optJSONObject("Attention") != null) {
                                    JSONObject obj = jsonObject.optJSONObject("Extra1").optJSONObject("Attention");
                                    Follow attention = new Follow();
                                    attention.setMovieName(obj.optString("Name"));
                                    attention.setMoviePicture(obj.optString("Picture"));
                                    attention.setUpdateInfo(obj.optString("UpdateInfo"));
                                    attention.setAttention(Boolean.parseBoolean(obj.optString("Name")));
                                    videoInfo.setAttention(attention);
                                }
                            }
                            JSONArray extraData = jsonObject
                                    .optJSONArray("Extra");
                            if (extraData != null)
                                videoInfo.setExtraData(extraData.toString());
 
                            if (VideoUtil.videoEpisodeList == null
                                    || VideoUtil.videoEpisodeList.isEmpty()) {
                                Toast.makeText(getContext(), "影片已删除",
                                        Toast.LENGTH_LONG).show();
                                getActivity().finish();
                                return;
                            }
 
                            if (rv_episode.getAdapter() != null)
                                rv_episode.getAdapter().notifyDataSetChanged();
                            // videoInfo.setSave(jsonObject.getJSONObject("Data").optBoolean("Save"));
                            if (isSetup) {
                                VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, videoInfo.getVideoDetailList(), false);
 
                                EventBus.getDefault().post(videoInfo);
                                int position = 0;
//                                boolean isFromWatchHistory = false;
//                                isFromWatchHistory = getArguments().getBoolean("isFromWatchHistory", false);// 是否从观看记录点击过来
                                Cursor cursor = rv_episode.getContext().getContentResolver().query(
                                        WatchHistoryTable.CONTENT_URI, null,
                                        WatchHistoryTable.VIDEO_ID + " = ? ",
                                        new String[]{videoInfo.getId()}, null);
//                                Cursor cursor = getActivity().getConentResolver().query(WatchHistoryTable.CONTENT_URI, null, WatchHistoryTable.VIDEO_ID + " = ? ", new String[]{videoInfo.getId()}, null);
                                cursor.moveToFirst();
                                String cResoureId = cursor.getString(cursor.getColumnIndex(WatchHistoryTable.VIDEO_RESOURCE_ID));
                                cursor.close();
                                if (resourceId.equalsIgnoreCase(cResoureId) && getActivity() != null) {
                                    position = getActivity().getIntent().getIntExtra(
                                            "playing_position", 0);
                                }
//                                if (isFromWatchHistory) {
                                getUrl(VideoUtil.videoEpisodeList.get(position));
                                EventBus.getDefault()
                                        .post(VideoUtil.videoEpisodeList
                                                .get(position));
//                                } else {// 不是从观看记录点击过来 --跳到当前播放的集数
//                                    getUrl(videoInfo.getVideoDetailList().get(position));
//                                    EventBus.getDefault().post(
//                                            videoInfo.getVideoDetailList().get(
//                                                    position));
//                                }
                            } else {
                                iv_favourite.postDelayed(new Runnable() {
 
                                    @Override
                                    public void run() {
                                        EventBus.getDefault().post(videoInfo);
                                        EventBus.getDefault().post(
                                                VideoUtil.videoEpisodeList
                                                        .get(0));
                                    }
                                }, 200);
                            }
                        }
                    }
                });
    }
 
    /**
     * 收藏
     *
     * @param type
     * @param thirdType
     */
    private void getScoreCollect(String loginUid, final String type, String thirdType) {
        SharedPreferences preferences = getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        BeibeiVideoAPI.getScoreCollect(getContext(), uid, loginUid, mVideoInfo.getId(),
                thirdType, type, new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            if (type.equals("1")) {
                                SingleToast.showToast(getContext(), "收藏成功");
                            } else {
                                SingleToast.showToast(getContext(), "取消收藏成功");
                            }
                        } else {
                            if (type.equals("1")) {
                                SingleToast.showToast(getContext(), "收藏失败");
                            } else {
                                SingleToast.showToast(getContext(), "取消收藏失败");
                            }
                        }
                        isCollect();
                    }
                });
    }
 
    private void isCollect() {
        SharedPreferences preferences = iv_favourite.getContext().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        BeibeiVideoAPI.isCollect(iv_favourite.getContext(), uid, mVideoInfo.getId(),
                mVideoInfo.getThirdType(), new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            iv_favourite.setImageResource(R.drawable.ic_video_detail_favourite2);
                        } else {
                            iv_favourite.setImageResource(R.drawable.ic_video_detail_favourite1);
                        }
                    }
                });
    }
 
    /**
     * 加载更多剧集
     *
     * @param videoId
     * @param resourceId
     */
    private synchronized void loadMoreEpisode(String videoId, String resourceId, int page, int pageSize) {
        BeibeiVideoAPI.getVideoEpisodeList(ll_add_attention.getContext(), UserUtil.getUid(getContext()), resourceId, videoId, page, pageSize, new
 
                BasicTextHttpResponseHandler() {
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws
                            Exception {
                        if (jsonObject.optBoolean("IsPost")) {
                            JSONObject data = jsonObject.optJSONObject("Data");
                            episodeHasMore = data.optBoolean("hasMore");
                            JSONArray array = data.optJSONArray("list");
                            if (array != null && array.length() > 0) {//
 
                                List<VideoDetailInfo> list = JsonUtil.videoGson.fromJson(array.toString(), new TypeToken<List<VideoDetailInfo>>() {
                                }.getType());
                                if (list != null && list.size() > 0) {
                                    episodePage++;
                                    VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, list, true);
                                    rv_episode.getAdapter().notifyDataSetChanged();
                                }
                            }
                        }
                    }
 
                    @Override
                    public void onStart() {
                        super.onStart();
                        episodeLoading = true;
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        episodeLoading = false;
                    }
                });
    }
 
 
    @Override
    public void onStop() {
        super.onStop();
        Log.i(TAG, "onStop");
    }
 
}