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);
|
MobclickAgent.onPageStart("播放详情页—小屏播放");
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
MobclickAgent.onPageEnd("播放详情页——小屏播放");
|
}
|
|
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);
|
}
|
}
|