package com.weikou.beibeivideo.ui.media;
|
|
import android.app.Activity;
|
import android.app.ProgressDialog;
|
import android.content.ContentValues;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.pm.ActivityInfo;
|
import android.content.res.Configuration;
|
import android.database.Cursor;
|
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentTransaction;
|
import android.util.Log;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.transition.Transition;
|
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.SingleToast;
|
import com.lcjian.library.util.SystemCommon;
|
import com.lcjian.library.util.common.AndroidManifestUtil;
|
import com.lcjian.library.util.common.DimenUtils;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.loopj.android.http.JsonHttpResponseHandler;
|
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.AccumulateRule;
|
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.PushEpisode;
|
import com.weikou.beibeivideo.entity.VideoDetailInfo;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.entity.VideoResource;
|
import com.weikou.beibeivideo.entity.video.ChangeVideoEvent;
|
import com.weikou.beibeivideo.ui.BaseActivity;
|
import com.weikou.beibeivideo.ui.ad.PlayVideoPreADFragment;
|
import com.weikou.beibeivideo.ui.common.ShareActivity;
|
import com.weikou.beibeivideo.ui.video.VideoPlayerActivity;
|
import com.weikou.beibeivideo.ui.video.VideoPlayerBrowserActivity;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.JsonUtil;
|
import com.weikou.beibeivideo.util.VideoUtil;
|
import com.weikou.beibeivideo.util.ui.TopStatusSettings;
|
|
import org.apache.http.Header;
|
import org.greenrobot.eventbus.Subscribe;
|
import org.json.JSONArray;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
/**
|
* 视频详情
|
*
|
* @author Administrator
|
*/
|
//
|
public class VideoDetailActivity extends BaseActivity implements
|
OnClickListener {
|
|
private final static String TAG = "VideoDetailActivity";
|
|
// private boolean mLandscape;
|
private VideoInfo videoInfo;
|
|
private ImageView iv_download_failure;
|
private ImageView iv_background;
|
|
private TextView tv_back;
|
|
private String resourceId = "";
|
|
private String detailid = "";
|
private Fragment mIQYVideoPlayerFragment;
|
private ProgressDialog progressDialog;
|
|
private boolean isClick = false;
|
|
private FragmentManager fm = getSupportFragmentManager();
|
|
private PlayVideoPreADFragment mVideoDetailVideoAdFragment;
|
|
private ImageView iv_select_play;
|
|
private FrameLayout fl_ad;
|
|
|
@Override
|
protected void onSaveInstanceState(Bundle outState) {
|
outState.putString("flash exit", "VideoDetailActivity");
|
super.onSaveInstanceState(outState);
|
}
|
|
private void initView() {
|
iv_select_play = findViewById(R.id.iv_select_play);
|
tv_back = findViewById(R.id.iv_back);
|
iv_download_failure = findViewById(R.id.iv_download_failure);
|
|
fl_video_play_background = findViewById(R.id.fl_video_play_background);
|
iv_background = findViewById(R.id.iv_video_play_background);
|
fl_ad = findViewById(R.id.fl_ad);
|
}
|
|
@Override
|
public void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.video_detail_activity);
|
VideoUtil.clearVideoEpisodeList(this);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
|
/**
|
* 广告
|
*/
|
mVideoDetailVideoAdFragment = new PlayVideoPreADFragment();
|
getSupportFragmentManager().beginTransaction().replace(R.id.fl_ad, mVideoDetailVideoAdFragment).commit();
|
|
|
initView();
|
|
|
progressDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
|
progressDialog.setCanceledOnTouchOutside(false);
|
progressDialog.setMessage("正在请求网络...");
|
progressDialog.show();
|
|
|
tv_back.setOnClickListener(this);
|
|
iv_download_failure.setOnClickListener(this);
|
if (getIntent().getSerializableExtra("video_info") != null) {
|
videoInfo = (VideoInfo) getIntent().getSerializableExtra(
|
"video_info");
|
if (videoInfo != null)
|
videoInfo.setVideoDetailList(null);
|
if (getIntent().getBooleanExtra("isFromWatchHistory", false)) {
|
Cursor cursor = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{videoInfo.getId()}, null);
|
cursor.moveToFirst();
|
if (cursor.getCount() > 0) {
|
try {
|
resourceId = cursor.getString(cursor.getColumnIndex(WatchHistoryTable.VIDEO_RESOURCE_ID));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
cursor.close();
|
}
|
} else {
|
videoInfo = new VideoInfo();
|
Bundle bundle = this.getIntent().getExtras();
|
videoInfo.setId(bundle.getString("Id"));
|
videoInfo.setShare(bundle.getString("Share"));
|
videoInfo.setThirdType(bundle.getString("ThirdType"));
|
//后面使用setResouceId
|
resourceId = bundle.getString("ResourceId");
|
detailid = bundle.getString("DetailId");
|
}
|
|
if (videoInfo == null)
|
BeibeiVideoAPI.setVideoError(this,
|
getSharedPreferences("user", Context.MODE_PRIVATE)
|
.getString("uid", ""),
|
"VideoDetailActivity:传入的VideoInfo为空",
|
new JsonHttpResponseHandler() {
|
});
|
if ("1".equals(videoInfo.getShare())) {
|
SharedPreferences preferences = getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
if (!preferences.getBoolean("shared", false)) {
|
Toast.makeText(VideoDetailActivity.this, "该影片需要分享之后才能观看",
|
Toast.LENGTH_LONG).show();
|
startActivity(getIntent().setClass(VideoDetailActivity.this,
|
ShareActivity.class));
|
finish();
|
return;
|
}
|
}
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
(int) SystemCommon.getScreenWidth(this),
|
(int) ((SystemCommon.getScreenWidth(this) * 9) / 16));
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
|
iv_select_play.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View arg0) {
|
if (videoInfo == null) {
|
return;
|
}
|
fl_ad.setVisibility(View.VISIBLE);
|
isClick = true;
|
startPlay();
|
}
|
});
|
iv_background.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (videoInfo == null) {
|
return;
|
}
|
isClick = true;
|
startPlay();
|
}
|
});
|
iv_background.setClickable(false);
|
Fragment videoDetailFragment = fm
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment == null) {
|
videoDetailFragment = new VideoDetailFragment();
|
Bundle bundle = new Bundle();
|
bundle.putInt("playing_position", getIntent().getIntExtra("playing_position", 0));
|
videoDetailFragment.setArguments(bundle);
|
|
fm.beginTransaction()
|
.add(R.id.fragment_video_detail_container,
|
videoDetailFragment, "VideoDetailFragment")
|
.commitAllowingStateLoss();
|
}
|
iNet();
|
|
// if (fl_ad != null)
|
// fl_ad.setVisibility(View.VISIBLE);
|
}
|
|
|
private void loadFullVideoAd() {
|
|
}
|
|
private static FrameLayout fl_video_play_background;
|
|
public static void hideImage() {
|
fl_video_play_background.setVisibility(View.GONE);
|
}
|
|
private int mPosition = 0;
|
|
@Subscribe
|
public void onEventMainThread(Playlocation location) {
|
Log.i(TAG, "onEventMainThread:Playlocation");
|
fl_ad.setVisibility(View.VISIBLE);
|
mPosition = location.getPosition();
|
}
|
|
Fragment mSohuVideoFragment;
|
Fragment mLeTVVideoFragment;
|
Fragment mYoukuPlayerFragment;
|
|
private boolean isFirst = true;
|
|
private void startPlay() {
|
|
iv_select_play.setVisibility(View.GONE);
|
|
if (fl_ad.getVisibility() == View.VISIBLE && BeibeiConstant.AD_TYPE != null && BeibeiConstant.AD_TYPE.isPlayerAd()&&!AndroidManifestUtil.isHuaWeiChannel(getApplicationContext())) {
|
mVideoDetailVideoAdFragment.loadVideoAD(new PlayVideoPreADFragment.IVideoAdListener() {
|
@Override
|
public void finishPlay() {
|
clickPlay();
|
fl_ad.setVisibility(View.GONE);
|
}
|
|
@Override
|
public void startPlay() {
|
|
}
|
|
@Override
|
public void onOtherClick(String name) {
|
|
}
|
|
@Override
|
public void noAd() {
|
clickPlay();
|
fl_ad.setVisibility(View.GONE);
|
}
|
|
});
|
} else {
|
clickPlay();
|
}
|
|
}
|
|
private void clickPlay() {
|
if (playUrl == null) {
|
SingleToast.showToast(VideoDetailActivity.this, "初始化播放路径中,请稍候点击播放!");
|
return;
|
}
|
if (playUrl.getPlayType() != 1) {//测试
|
setViewOrientation();
|
}
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (playUrl.getResource().getId().equalsIgnoreCase(videoInfo.getResourceList().get(i).getId())) {
|
videoInfo.getResourceList().get(i).setChecked(true);
|
} else {
|
videoInfo.getResourceList().get(i).setChecked(false);
|
}
|
}
|
if (playUrl.getResource().getName().contains("爱奇艺")) {
|
if (playUrl != null) {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
} else if (playUrl.getPlayType() == 2) {
|
iv_select_play.setVisibility(View.GONE);
|
iv_background.setClickable(false);
|
mIQYVideoPlayerFragment = fm
|
.findFragmentByTag("IQYVideoFragment");
|
mIQYVideoPlayerFragment = new IQYVideoFragment();
|
Bundle b = new Bundle();
|
b.putSerializable("playUrl", playUrl);
|
mIQYVideoPlayerFragment.setArguments(b);
|
fm.beginTransaction()
|
.replace(R.id.fragment_video_play_container,
|
mIQYVideoPlayerFragment, "IQYVideoFragment")
|
.commitAllowingStateLoss();
|
// EventBus.getDefault().post(playUrl);
|
Toast.makeText(VideoDetailActivity.this, "影片加载中...",
|
Toast.LENGTH_LONG).show();
|
}
|
saveWatchHistory("爱奇艺");
|
}
|
} else if (playUrl.getResource().getName().contains("风行")) {
|
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("风行");
|
}
|
} else {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory(playUrl.getResource().getName());
|
}
|
}
|
}
|
|
private void setViewOrientation() {
|
findViewById(R.id.fl_video_detail).setVisibility(View.GONE);
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
findViewById(R.id.iv_select_play).postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
checkConfiguration(getResources().getConfiguration());
|
}
|
}, 1000);
|
}
|
|
private PlayUrl info;
|
|
@Subscribe
|
public void onEventMainThread(PlayUrl info) {
|
this.info = info;
|
Toast.makeText(this, "播放", Toast.LENGTH_SHORT).show();
|
}
|
|
private SimpleTarget<Drawable> target = new SimpleTarget<Drawable>() {
|
|
@Override
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
iv_background
|
.setImageDrawable(resource);
|
}
|
|
@Override
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
|
}
|
};
|
|
@Override
|
public void onBackPressed() {
|
// if (mLandscape
|
// || this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
// super.onBackPressed();
|
// } else {
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
// }
|
}
|
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (keyCode == KeyEvent.KEYCODE_BACK
|
&& getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
clickBack();
|
return false;
|
} else if (keyCode == KeyEvent.KEYCODE_BACK && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
finish();
|
return true;
|
} else {
|
return super.onKeyDown(keyCode, event);
|
}
|
}
|
|
@Subscribe
|
public void onEventMainThread(AccumulateRule info) {// 播放界面返回替代使用
|
clickBack();
|
}
|
|
private void clickBack() {
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
checkConfiguration(getResources().getConfiguration());
|
findViewById(R.id.fl_video_detail).setVisibility(View.VISIBLE);
|
fl_video_play_background.setVisibility(View.VISIBLE);
|
iv_select_play.setVisibility(View.VISIBLE);
|
try {
|
Glide.with(getApplicationContext()).load(R.drawable.ic_select_play)
|
.into(iv_select_play);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
findViewById(R.id.v_status_bar).setVisibility(View.VISIBLE);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
(int) SystemCommon.getScreenWidth(this),
|
(int) ((SystemCommon.getScreenWidth(this) * 9) / 16));
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
if (playUrl != null && playUrl.getResource().getName().contains("爱奇艺")) {
|
iv_background.setClickable(true);
|
if (mIQYVideoPlayerFragment != null)
|
fm.beginTransaction().remove(mIQYVideoPlayerFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("搜狐")) {
|
iv_background.setClickable(true);
|
if (mSohuVideoFragment != null)
|
fm.beginTransaction().remove(mSohuVideoFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("优酷")) {
|
iv_background.setClickable(true);
|
if (mYoukuPlayerFragment != null)
|
fm.beginTransaction().remove(mYoukuPlayerFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("LeTV")) {
|
iv_background.setClickable(true);
|
if (mLeTVVideoFragment != null)
|
fm.beginTransaction().remove(mLeTVVideoFragment)
|
.commitAllowingStateLoss();
|
}
|
}
|
|
@Override
|
public void onConfigurationChanged(Configuration newConfig) {
|
super.onConfigurationChanged(newConfig);
|
checkConfiguration(newConfig);
|
}
|
|
private void checkConfiguration(Configuration newConfig) {
|
if (newConfig == null)
|
return;
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
// Hide the status bar隐藏状态栏
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
getWindow().setAttributes(attrs);
|
|
Fragment videoDetailFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment != null && !videoDetailFragment.isHidden()) {
|
getSupportFragmentManager().beginTransaction()
|
.hide(videoDetailFragment).commitAllowingStateLoss();
|
}
|
|
if (playUrl != null
|
&& playUrl.getResource().getName().contains("自主")) {
|
Fragment videoPlayerFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoPlayerFragment");
|
if (videoPlayerFragment != null) {
|
}
|
}
|
|
android.view.ViewGroup.LayoutParams layoutParams = findViewById(
|
R.id.fragment_video_play_container).getLayoutParams();
|
layoutParams.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
findViewById(R.id.fragment_video_play_container).requestLayout();
|
} else {
|
// Show the status bar显示状态栏
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
getWindow().setAttributes(attrs);
|
|
Fragment videoDetailFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment != null) {
|
getSupportFragmentManager().beginTransaction()
|
.show(videoDetailFragment).commitAllowingStateLoss();
|
}
|
|
if (playUrl != null
|
&& playUrl.getResource().getName().contains("自主")) {
|
Fragment videoPlayerFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoPlayerFragment");
|
|
}
|
|
FrameLayout layout = (FrameLayout) findViewById(R.id.fragment_video_play_container);
|
if (layout == null)
|
return;
|
android.view.ViewGroup.LayoutParams layoutParams = layout
|
.getLayoutParams();
|
layoutParams.height = (int) (DimenUtils.getScreenWidth(this) * 0.5625f);
|
layout.requestLayout();
|
}
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
EventBus.getDefault().register(this);
|
if (fl_ad.getVisibility() == View.GONE) {
|
iv_select_play.setVisibility(View.VISIBLE);
|
}
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
}
|
|
@Subscribe
|
public void onEventMainThread(ChangeVideoEvent changeVideoEvent) {
|
VideoInfo videoInfo = changeVideoEvent.getVideoInfo();
|
resourceId = "";
|
if (!progressDialog.isShowing()) {
|
progressDialog.show();
|
}
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(), false);
|
}
|
|
@Subscribe
|
public void onEventMainThread(Play info) {
|
Log.i("mResult", "VideoDetailActivity-----onEventMainThread----开始播放");
|
playUrl = info.getPlayUrl();
|
if (videoInfo == null) {
|
return;
|
}
|
try {
|
startPlay();
|
} catch (IndexOutOfBoundsException e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
@Subscribe
|
public void onEventMainThread(VideoInfo info) {
|
videoInfo = info;
|
}
|
|
private void getVideoDetail(final Context context, String videoId,
|
String videoThirdType, final boolean isSetup) {
|
SharedPreferences preferences = context.getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
String loginid = preferences.getString("LoginUid", "");
|
BeibeiVideoAPI.getVideoDetail(context, uid, resourceId, videoId,null, loginid,
|
videoThirdType,"", new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.this, "onStart",
|
// Toast.LENGTH_SHORT).show();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers,
|
String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString,
|
throwable);
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.this, "onFailure",
|
// Toast.LENGTH_SHORT).show();
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.iv_download_failure).setVisibility(
|
View.VISIBLE);
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.this,
|
// "onSuccessPerfect",
|
// Toast.LENGTH_SHORT).show();
|
iv_background.setClickable(true);
|
try {
|
if (((Activity) context).isDestroyed()) {
|
return;
|
}
|
} catch (NoSuchMethodError e) {
|
e.printStackTrace();
|
}
|
if (jsonObject.getBoolean("IsPost")) {
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.VISIBLE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.VISIBLE);
|
findViewById(R.id.iv_download_failure)
|
.setVisibility(View.GONE);
|
if (!isSetup) {
|
update();
|
}
|
|
|
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("IsAttention")));
|
videoInfo.setAttention(attention);
|
}
|
}
|
VideoDetailActivity.this.videoInfo = videoInfo;
|
JSONArray extraData = jsonObject
|
.optJSONArray("Extra");
|
if (extraData != null)
|
videoInfo.setExtraData(extraData.toString());
|
|
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resource = videoInfo.getResourceList().get(i);
|
}
|
}
|
if (VideoUtil.videoEpisodeList == null
|
|| VideoUtil.videoEpisodeList.isEmpty()) {
|
Toast.makeText(VideoDetailActivity.this,
|
"影片已删除", Toast.LENGTH_LONG).show();
|
finish();
|
return;
|
}
|
|
|
Glide.with(getApplicationContext())
|
.load(videoInfo.getPlayPicture()).apply(new RequestOptions().centerCrop()).into(target);
|
if (isSetup) {
|
int position = getIntent().getIntExtra(
|
"playing_position", 0);
|
boolean isFromWatchHistory = getIntent()
|
.getBooleanExtra("isFromWatchHistory",
|
false);// 是否从观看记录点击过来
|
Log.i("mResult", "是否是从观看记录点击进来的:" + isFromWatchHistory);
|
if (isFromWatchHistory || position > 0) {
|
mPosition = getIntent().getIntExtra("playing_position", 0);
|
EventBus.getDefault().post(videoInfo);
|
getUrl(VideoUtil.videoEpisodeList.get(mPosition), isSetup);
|
EventBus.getDefault().post(VideoUtil.videoEpisodeList.get(mPosition));
|
} else {// 不是从观看记录点击过来 --跳到当前播放的集数
|
// position = VideoPlayUrlUtil
|
// .getVideoDetailPosition(context,
|
// videoInfo);
|
EventBus.getDefault().post(videoInfo);
|
if (StringUtils.isEmpty(detailid)) {
|
getUrl(VideoUtil.videoEpisodeList.get(
|
position), isSetup);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(
|
position));
|
} else {
|
if (VideoUtil.videoEpisodeList != null)
|
for (int i = 0; i <VideoUtil.videoEpisodeList.size(); i++) {
|
if (detailid.equalsIgnoreCase(VideoUtil.videoEpisodeList.get(i).getId())) {
|
getUrl(VideoUtil.videoEpisodeList.get(
|
i), false);
|
PushEpisode info = new PushEpisode();
|
info.setEpisodeNum(i);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(
|
i));
|
}
|
}
|
}
|
}
|
} else {
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resource = videoInfo.getResourceList().get(i);
|
}
|
}
|
getUrl(VideoUtil.videoEpisodeList.get(0),
|
isSetup);
|
findViewById(android.R.id.content).postDelayed(
|
new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(
|
videoInfo);
|
EventBus.getDefault()
|
.post(VideoUtil.videoEpisodeList
|
.get(0));
|
}
|
}, 200);
|
}
|
|
} else {
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.iv_download_failure)
|
.setVisibility(View.VISIBLE);
|
}
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
|
fl_ad.setVisibility(View.GONE);
|
|
if (!BeibeiConstant.IS_TEST)
|
//加载视频广告
|
loadFullVideoAd();
|
}
|
});
|
}
|
|
private PlayUrl playUrl;
|
|
private void getUrl(VideoDetailInfo info, final boolean isSetup) {
|
SharedPreferences preferences = getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
BeibeiVideoAPI.getPlayUrl(this, uid, info.getType(), videoInfo.getId(), info.getId(),
|
resource.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"));
|
playUrl = info;
|
if (videoInfo == null) {
|
return;
|
}
|
Log.i(TAG, "getUrl");
|
if (!isSetup || isClick) {
|
fl_ad.setVisibility(View.VISIBLE);
|
startPlay();
|
isClick = false;
|
}
|
}
|
}
|
});
|
}
|
|
private VideoResource resource;
|
|
@Subscribe
|
public void onEventMainThread(VideoResource resource) {
|
this.resource = resource;
|
}
|
|
private void update() {
|
FragmentTransaction transaction = getSupportFragmentManager()
|
.beginTransaction();
|
Fragment videoDetailFragment = new VideoDetailFragment();
|
transaction.replace(R.id.fragment_video_detail_container,
|
videoDetailFragment, "VideoDetailFragment");
|
transaction.commitAllowingStateLoss();
|
checkConfiguration(getResources().getConfiguration());
|
}
|
|
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.iv_download_failure:
|
iNet();
|
break;
|
case R.id.iv_back:
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
clickBack();
|
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
finish();
|
}
|
break;
|
|
default:
|
break;
|
}
|
}
|
|
/**
|
* video网络数据请求
|
*/
|
private void iNet() {
|
if (VideoUtil.videoEpisodeList == null
|
|| VideoUtil.videoEpisodeList.isEmpty()) {
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(),
|
true);
|
} else {
|
findViewById(android.R.id.content).postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(videoInfo);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(
|
getIntent().getIntExtra("playing_position",
|
0)));
|
}
|
}, 200);
|
}
|
}
|
|
private void saveWatchHistory(String from) {
|
if (videoInfo != null) {
|
String videoDetailId = "";
|
if (VideoUtil.videoEpisodeList == null || VideoUtil.videoEpisodeList.size() == 0)
|
return;
|
if (mPosition >= VideoUtil.videoEpisodeList.size()) {
|
videoDetailId = VideoUtil.videoEpisodeList.get(0)
|
.getId();
|
} else {
|
videoDetailId = VideoUtil.videoEpisodeList.get(mPosition)
|
.getId();
|
}
|
String resoureID = "";
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resoureID = videoInfo.getResourceList().get(i).getId();
|
}
|
}
|
Cursor cursor = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_DETAIL_ID + " = ? ",
|
new String[]{videoDetailId}, null);
|
Cursor cursor1 = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{videoInfo.getId()}, null);
|
if (cursor == null || cursor1 == null) {
|
return;
|
}
|
|
long now = System.currentTimeMillis();
|
if (cursor1.getCount() > 0) {
|
getContentResolver().delete(WatchHistoryTable.CONTENT_URI,
|
WatchHistoryTable.VIDEO_ID + " = ? ", new String[]{videoInfo.getId()});
|
}
|
cursor1.close();
|
//添加值至数据库
|
ContentValues values = new ContentValues();
|
values.put(WatchHistoryTable.VIDEO_ID, videoInfo.getId());
|
values.put(WatchHistoryTable.VIDEO_DETAIL_ID, videoDetailId);
|
values.put(WatchHistoryTable.VIDEO_THIRD_TYPE,
|
videoInfo.getThirdType());
|
|
values.put(WatchHistoryTable.VIDEO_DETAIL,
|
JsonUtil.videoGson.toJson(videoInfo));
|
values.put(WatchHistoryTable.WATCH_TIME, 0);
|
values.put(WatchHistoryTable.VIDEO_RESOURCE, from);
|
values.put(WatchHistoryTable.VIDEO_RESOURCE_ID, resoureID);
|
values.put(WatchHistoryTable.UPDATE_TIME, now);
|
values.put(WatchHistoryTable.CREATE_TIME, now);
|
//插入数据库值
|
try {
|
getContentResolver().insert(WatchHistoryTable.CONTENT_URI,
|
values);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
cursor.close();
|
//更新数据库
|
getContentResolver().update(WatchHistoryTable.CONTENT_URI,
|
values, WatchHistoryTable.VIDEO_DETAIL_ID + " = ? ",
|
new String[]{videoDetailId});
|
|
cursor = getContentResolver().query(WatchHistoryTable.CONTENT_URI,
|
new String[]{WatchHistoryTable._ID}, null, null,
|
WatchHistoryTable._ID + " desc");
|
List<Long> longList = new ArrayList<Long>();
|
while (cursor.moveToNext()) {
|
longList.add(cursor.getLong(0));
|
}
|
cursor.close();
|
if (longList.size() > 30) {
|
int count = getContentResolver().delete(
|
WatchHistoryTable.CONTENT_URI,
|
WatchHistoryTable._ID + "<?",
|
new String[]{longList.get(30) + ""});
|
}
|
}
|
}
|
|
@Override
|
protected void onStop() {
|
super.onStop();
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
}
|
}
|