admin
2021-10-21 7e2ac66d7c532a5725635fa3913789bb17c1e157
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
package com.yeshi.video.ui;
 
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
 
import com.bumptech.glide.Glide;
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.util.common.StringUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.umeng.analytics.MobclickAgent;
import com.viewpagerindicator.LxyPageIndicator;
import com.yeshi.base.entity.video.Follow;
import com.yeshi.base.entity.video.Play;
import com.yeshi.base.entity.video.PlayUrl;
import com.yeshi.base.entity.video.VideoDetailInfo;
import com.yeshi.base.entity.video.VideoInfo;
import com.yeshi.base.entity.video.VideoResource;
import com.yeshi.base.utils.BeibeiConstant;
import com.yeshi.base.utils.downutil.DownloadUtils;
import com.yeshi.base.utils.http.BasicTextHttpResponseHandler;
import com.yeshi.video.R;
import com.yeshi.video.ui.adapter.VideoDetailAdapter;
import com.yeshi.video.utils.VideoApiUtil;
 
import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
 
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.viewpager.widget.ViewPager;
import de.greenrobot.event.EventBus;
 
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
 
/**
 * 视频详情
 *
 * @author Administrator
 */
public class VideoDetailFragment extends Fragment implements OnClickListener {
 
    private LxyPageIndicator indicator_video_detail;
 
    private ViewPager vp_video_detail;
 
    private FrameLayout fl_add_to_favourite;
 
    private TextView tv_add_to_favourite;
 
    // private LinearLayout fl_report;
 
    private FrameLayout fl_offline_cache;
 
    private TextView tv_offline_cache;
 
    // private ImageView iv_report;
 
    private VideoInfo mVideoInfo;
 
    private int mPlayingPosition;
 
    private VideoDetailAdapter mVideoDetailAdapter;
 
    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();
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.video_detail_fragment, container,
                false);
 
        indicator_video_detail = (LxyPageIndicator) view
                .findViewById(R.id.indicator_video_detail);
        vp_video_detail = (ViewPager) view.findViewById(R.id.vp_video_detail);
        fl_add_to_favourite = (FrameLayout) view
                .findViewById(R.id.fl_add_to_favourite);
        tv_add_to_favourite = (TextView) view
                .findViewById(R.id.tv_add_to_favourite);
        // fl_report = (LinearLayout) view.findViewById(R.id.fl_report);
        // // tv_report = (TextView) view.findViewById(R.id.tv_report);
        // iv_report = (ImageView) view.findViewById(R.id.iv_report);
        fl_offline_cache = (FrameLayout) view
                .findViewById(R.id.fl_offline_cache);
        tv_offline_cache = (TextView) view.findViewById(R.id.tv_offline_cache);
 
        // fl_advertisement = (FrameLayout) view
        // .findViewById(R.id.fl_advertisement);
 
        mVideoDetailAdapter = new VideoDetailAdapter(getChildFragmentManager(),
                null, 0);
        vp_video_detail.setAdapter(mVideoDetailAdapter);
        indicator_video_detail.setViewPager(vp_video_detail);
        fl_add_to_favourite.setOnClickListener(this);
        // fl_report.setOnClickListener(this);
        fl_offline_cache.setOnClickListener(this);
        fl_add_to_favourite.setEnabled(false);
        // fl_report.setEnabled(false);
        fl_offline_cache.setEnabled(false);
        initAdvertisement();// 广点通广告
        return view;
    }
 
    @Override
    public void onClick(View v) {
        final SharedPreferences preferences = getActivity()
                .getSharedPreferences("user", Context.MODE_PRIVATE);
        int id = v.getId();// 点击来源
        if (id == R.id.fl_add_to_favourite) {
            String uid = preferences.getString("uid", "");
            VideoApiUtil.isCollect(getActivity(), uid, mVideoInfo.getId(),
                    mVideoInfo.getThirdType(),
                    new BasicTextHttpResponseHandler() {
 
                        @Override
                        public void onSuccessPerfect(int statusCode,
                                                     Header[] headers, JSONObject jsonObject)
                                throws Exception {
                            if (jsonObject.getBoolean("IsPost")) {
                                getScoreCollect("0", mVideoInfo.getThirdType());
                            } else {
                                getScoreCollect("1", mVideoInfo.getThirdType());
                            }
                        }
                    });
        } else if (id == R.id.fl_offline_cache) {/*
         * boolean downApp = preferences.getBoolean("appdown", false); if
         * (!downApp) { AlertDialog.Builder builder = new
         * AlertDialog.Builder( getActivity()); final AlertDialog dialog =
         * builder .setMessage("第一次缓存需要激活,是否激活?") .setPositiveButton("是",
         * new DialogInterface.OnClickListener() {
         *
         * @Override public void onClick(DialogInterface dia, int which) {
         * tv_offline_cache.post(new Runnable() {
         *
         * @Override public void run() { GdtAppwall.showAppwall(); } });
         *
         * dia.dismiss(); if(timer==null) timer=new Timer();
         * timer.schedule(new TimerTask() {
         *
         * @Override public void run() { SharedPreferences.Editor editor=
         * preferences.edit(); editor.putBoolean("appdown", true);
         * editor.commit(); } }, 15*1000); } }) .setNegativeButton("否", new
         * DialogInterface.OnClickListener() {
         *
         * @Override public void onClick(DialogInterface dialog, int which)
         * { dialog.dismiss(); } }).create(); dialog.show(); } else
         */
            getFragmentManager()
                    .beginTransaction()
                    .setCustomAnimations(R.anim.slide_in_from_bottom,
                            R.anim.slide_out_to_bottom)
                    .add(R.id.fragment_video_episode_container,
                            VideoEpisodeFragment3.newInstance(mVideoInfo))
                    .addToBackStack("VideoEpisodeFragment3")
                    .commitAllowingStateLoss();
        } else if (id == R.id.fl_report) {// if (popupWindow.isShowing()) {
            // // bug:listview 中的isShowing()可以正确获取而到了这里就一直不进入,原因是pop没设置焦点获取
            // popupWindow.dismiss();
            // } else {// 出现在线下,并且居右
            // if (selectedUrl == null || selectedUrl.getPicture() == null) {
            //
            // } else {
            // popupWindow.showAsDropDown(
            // getActivity().findViewById(R.id.view_line),
            // (int) (SystemCommon
            // .getScreenWidth(getActivity()) - popupWindow
            // .getWidth()), 0);
            // Toast.makeText(getActivity(), "点击了来源", Toast.LENGTH_SHORT).show();
            // popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, (int) (SystemCommon
            // .getScreenWidth(getActivity()) - popupWindow.getWidth()), 0);
            // }
            // }
            /*
             * String uid = preferences.getString("uid", "");
             * BeibeiVideoAPI.setVideoError(getActivity(), uid, mVideoInfo
             * .getVideoDetailList().get(mPlayingPosition).getId(), new
             * BasicTextHttpResponseHandler() {
             *
             * @Override public void onSuccessPerfect(int statusCode, Header[]
             * headers, JSONObject jsonObject) throws Exception { if
             * (jsonObject.getBoolean("IsPost")) { Toast.makeText(getActivity(),
             * jsonObject.getString("Data"), Toast.LENGTH_LONG).show(); } } });
             */
        }
    }
 
    private Timer timer = null;
    private PopupWindow popupWindow;
 
    @Override
    public void onResume() {
        super.onResume();
        EventBus.getDefault().register(this);
    }
 
    @Override
    public void onPause() {
        super.onPause();
        EventBus.getDefault().unregister(this);
    }
 
    public void onEventMainThread(ContentValues values) {
        if (DownloadUtils.isOffline(getActivity(), mVideoInfo.getId(),
                mVideoInfo.getVideoDetailList().get(mPlayingPosition).getId())) {
            tv_offline_cache.setCompoundDrawablesWithIntrinsicBounds(
                    R.drawable.ic_offlinecache_highlight, 0, 0, 0);
        } else {
            tv_offline_cache.setCompoundDrawablesWithIntrinsicBounds(
                    R.drawable.selector_offline, 0, 0, 0);
        }
    }
 
    List<VideoResource> urlList;
    VideoResource selectedUrl = null;
 
    private void setFrom(VideoInfo info) {
        if (urlList == null)
            urlList = new ArrayList<>();
        urlList.clear();
        if (info.getResourceList() != null) {
            for (int i = 0; i < info.getResourceList().size(); i++) {
                if (info.getResourceList().get(i).isChecked()) {
                    selectedUrl = info.getResourceList().get(i);
                }
            }
            EventBus.getDefault().post(selectedUrl);
            urlList.addAll(info.getResourceList());
            tv_add_to_favourite.postDelayed(new Runnable() {
                @Override
                public void run() {
                    EventBus.getDefault().post(selectedUrl);
                }
            }, 1000);
        }
 
 
        // initResource();
    }
 
    public void onEventMainThread(VideoInfo videoInfo) {
 
        mVideoInfo = videoInfo;
        setFrom(videoInfo);
        if (mVideoInfo.isCanSave()) {
            fl_offline_cache.setEnabled(true);
            // tv_offline_cache.setText("缓存");
        } else {
            fl_offline_cache.setEnabled(false);
            // tv_offline_cache.setText("无法缓存");
        }
        fl_add_to_favourite.setEnabled(true);
        // fl_report.setEnabled(true);
        mVideoDetailAdapter = new VideoDetailAdapter(getChildFragmentManager(),
                mVideoInfo, mPlayingPosition);
        vp_video_detail.setAdapter(mVideoDetailAdapter);
        indicator_video_detail.setViewPager(vp_video_detail);
        indicator_video_detail.requestLayout();
        // isCollect();
    }
 
    VideoDetailInfo mVideoDetailInfo;
 
    public void onEventMainThread(VideoDetailInfo videoDetailInfo) {
        mVideoDetailInfo = videoDetailInfo;
        int playingPosition = 0;
        for (int i = 0; i < mVideoInfo.getVideoDetailList().size(); i++) {
            if (videoDetailInfo.getTag().equals(
                    mVideoInfo.getVideoDetailList().get(i).getTag())) {
                playingPosition = i;
                break;
            }
        }
        if (mPlayingPosition == 0 || mPlayingPosition != playingPosition) {
            mPlayingPosition = playingPosition;
//            if (DownloadUtils.isOffline(getActivity(), mVideoInfo.getId(),
//                    mVideoInfo.getVideoDetailList().get(mPlayingPosition)
//                            .getId())) {
//                tv_offline_cache.setCompoundDrawablesWithIntrinsicBounds(
//                        R.drawable.ic_offlinecache_highlight, 0, 0, 0);
//            } else {
                tv_offline_cache.setCompoundDrawablesWithIntrinsicBounds(
                        R.drawable.selector_offline, 0, 0, 0);
//            }
            mVideoDetailAdapter.setPlayingPosition(mPlayingPosition);
        }
    }
 
    public void onEventMainThread(VideoPlayerFragment.FavouriteEvent favouriteEvent) {
        // isCollect();
    }
 
    private void getScoreCollect(final String type, String thirdType) {
        SharedPreferences preferences = getActivity().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        VideoApiUtil.getScoreCollect(getActivity(), uid, 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")) {
                                Toast.makeText(getActivity(), "收藏成功",
                                        Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(getActivity(), "取消收藏成功",
                                        Toast.LENGTH_LONG).show();
                            }
                            EventBus.getDefault().post(new VideoPlayerFragment.FavouriteEvent());
                        } else {
                            if (type.equals("1")) {
                                Toast.makeText(getActivity(), "收藏失败",
                                        Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(getActivity(), "取消收藏失败",
                                        Toast.LENGTH_LONG).show();
                            }
                        }
                    }
                });
    }
 
    private void isCollect() {
        SharedPreferences preferences = getActivity().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        VideoApiUtil.isCollect(getActivity(), uid, mVideoInfo.getId(),
                mVideoInfo.getThirdType(), new BasicTextHttpResponseHandler() {
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            tv_add_to_favourite
                                    .setCompoundDrawablesWithIntrinsicBounds(
                                            R.drawable.ic_favourite_highlight,
                                            0, 0, 0);
                            // tv_add_to_favourite
                            // .setText(R.string.remove_from_favourite);
                        } else {
                            tv_add_to_favourite
                                    .setCompoundDrawablesWithIntrinsicBounds(
                                            R.drawable.selector_favourite, 0,
                                            0, 0);
                            // tv_add_to_favourite
                            // .setText(R.string.add_to_favourite);
                        }
                    }
                });
    }
 
    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
 
    /**
     * 广点通广告
     */
    // private static FrameLayout fl_advertisement;
    public static void getAdStatus(boolean isShow) {
        // if (isShow) {
        // fl_advertisement.setVisibility(View.VISIBLE);
        // } else {
        // fl_advertisement.setVisibility(View.GONE);
        // }
    }
 
    private void initAdvertisement() {
        // GDTBanner.initAdvertisement(getActivity(),
        // BeibeiConstant.MOGO_ID_PLAYER_BOTTOM_BANNER, fl_advertisement);
    }
 
    private class ResourceAdapter extends BaseAdapter {
        List<VideoResource> reList;
 
        public ResourceAdapter(List<VideoResource> list) {
            reList = list;
        }
 
        @Override
        public int getCount() {
            return reList.size();
        }
 
        @Override
        public Object getItem(int position) {
            return reList.get(position);
        }
 
        @Override
        public long getItemId(int position) {
            return position;
        }
 
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(getActivity()).inflate(
                    R.layout.item_resource, null);
            ImageView iv = (ImageView) view.findViewById(R.id.iv_resource);
            TextView tv = (TextView) view.findViewById(R.id.tv_resource);
            // if (reList.get(position) == null
            // || reList.get(position).getPicture() == null) {
            // ImageLoader.getInstance().displayImage(
            // "drawable://" + R.drawable.from_other, iv);
            // } else {
            // ImageLoader.getInstance().displayImage(
            // reList.get(position).getPicture(), iv, option);
            // }
            try {
                Glide.with(getActivity().getApplicationContext())
                        .load(reList.get(position).getPicture()
                                .contains("http://") ? reList.get(position)
                                .getPicture() : BeibeiConstant.HOST + "/BuWan/"
                                + reList.get(position).getPicture())
                        .placeholder(R.drawable.from_other)
                        .error(R.drawable.from_other).transition(withCrossFade()).into(iv);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            if (reList.get(position) == null
                    || StringUtils.isEmpty(reList.get(position).getName())) {
                tv.setText("其它");
            } else {
                tv.setText(reList.get(position).getName());
            }
            return view;
        }
    }
 
    ;
 
    private void getVideoDetail(String videoId, String resourceId,
                                String videoThirdType, final boolean isSetup) {
        SharedPreferences preferences = getActivity().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        String loginid = preferences.getString("LoginUid", "");
        VideoApiUtil.getVideoDetail(getActivity(), uid, resourceId, videoId,
                loginid, videoThirdType, 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 onSuccessPerfect(int statusCode,
                                                 Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        try {
                            if (getActivity().isDestroyed()) {
                                return;
                            }
                        } catch (NoSuchMethodError e) {
                            e.printStackTrace();
                        }
                        if (jsonObject.getBoolean("IsPost")) {
                            if (!isSetup) {
                                update();
                            }
                            Gson gson = new GsonBuilder().setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            final VideoInfo videoInfo = gson
                                    .fromJson(jsonObject.getJSONObject("Data")
                                                    .toString(),
                                            new TypeToken<VideoInfo>() {
                                            }.getType());
                            // 附加字段
                            if (jsonObject.optJSONObject("Extra1") != 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 (videoInfo.getVideoDetailList() == null
                                    || videoInfo.getVideoDetailList().isEmpty()) {
                                Toast.makeText(getActivity(), "影片已删除",
                                        Toast.LENGTH_LONG).show();
                                getActivity().finish();
                                return;
                            }
 
                            // videoInfo.setSave(jsonObject.getJSONObject("Data").optBoolean("Save"));
                            if (isSetup) {
                                mVideoInfo.getVideoDetailList().clear();
                                mVideoInfo.setVideoDetailList(videoInfo
                                        .getVideoDetailList());
                                EventBus.getDefault().post(videoInfo);
                                int position = getActivity().getIntent()
                                        .getIntExtra("playing_position", 0);
                                boolean isFromWatchHistory = getActivity()
                                        .getIntent().getBooleanExtra(
                                                "isFromWatchHistory", false);// 是否从观看记录点击过来
                                if (isFromWatchHistory) {
                                    getUrl(videoInfo.getVideoDetailList().get(
                                            getActivity().getIntent()
                                                    .getIntExtra(
                                                            "playing_position",
                                                            0)));
                                    EventBus.getDefault()
                                            .post(videoInfo
                                                    .getVideoDetailList()
                                                    .get(getActivity()
                                                            .getIntent()
                                                            .getIntExtra(
                                                                    "playing_position",
                                                                    0)));
                                } else {// 不是从观看记录点击过来 --跳到当前播放的集数
                                    getUrl(videoInfo.getVideoDetailList().get(
                                            position));
                                    // position = VideoPlayUrlUtil
                                    // .getVideoDetailPosition(context,
                                    // videoInfo);
                                    EventBus.getDefault().post(
                                            videoInfo.getVideoDetailList().get(
                                                    position));
                                }
                            } else {
                                tv_offline_cache.postDelayed(new Runnable() {
 
                                    @Override
                                    public void run() {
                                        EventBus.getDefault().post(videoInfo);
                                        EventBus.getDefault().post(
                                                videoInfo.getVideoDetailList()
                                                        .get(0));
                                    }
                                }, 200);
                            }
                        }
                    }
                });
    }
 
    private void getUrl(VideoDetailInfo info) {
        SharedPreferences preferences = getActivity().getSharedPreferences(
                "user", Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        VideoApiUtil.getPlayUrl(getActivity(), 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")) {
                            Gson gson = new GsonBuilder().setFieldNamingPolicy(
                                    FieldNamingPolicy.UPPER_CAMEL_CASE)
                                    .create();
                            VideoResource resource = gson.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.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);
                    }
                });
    }
 
    private void update() {
        FragmentTransaction transaction = getChildFragmentManager()
                .beginTransaction();
        Fragment videoDetailFragment = new VideoDetailFragment();
        transaction.replace(R.id.fragment_video_detail_container,
                videoDetailFragment, "VideoDetailFragment");
        transaction.commitAllowingStateLoss();
        checkConfiguration(getResources().getConfiguration());
    }
 
    private void checkConfiguration(Configuration newConfig) {
        if (newConfig == null)
            return;
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            // Hide the status bar隐藏状态栏
            WindowManager.LayoutParams attrs = getActivity().getWindow()
                    .getAttributes();
            attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getActivity().getWindow().setAttributes(attrs);
 
            Fragment videoDetailFragment = getChildFragmentManager()
                    .findFragmentByTag("VideoDetailFragment");
            if (videoDetailFragment != null && !videoDetailFragment.isHidden()) {
                getChildFragmentManager().beginTransaction()
                        .hide(videoDetailFragment).commitAllowingStateLoss();
            }
 
        } else {
            // Show the status bar显示状态栏
            WindowManager.LayoutParams attrs = getActivity().getWindow()
                    .getAttributes();
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getActivity().getWindow().setAttributes(attrs);
 
            Fragment videoDetailFragment = getChildFragmentManager()
                    .findFragmentByTag("VideoDetailFragment");
            if (videoDetailFragment != null) {
                getChildFragmentManager().beginTransaction()
                        .show(videoDetailFragment).commitAllowingStateLoss();
            }
        }
    }
 
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
}