|
@ -25,6 +25,8 @@ import com.electric.chargingpile.R;
|
25
|
25
|
import com.electric.chargingpile.application.MainApplication;
|
26
|
26
|
import com.electric.chargingpile.data.ChatBeanLab;
|
27
|
27
|
import com.electric.chargingpile.data.ChatRecommendBean;
|
|
28
|
import com.electric.chargingpile.manager.PreferenceManager;
|
|
29
|
import com.electric.chargingpile.manager.ProfileManager;
|
28
|
30
|
import com.electric.chargingpile.util.DensityUtil;
|
29
|
31
|
import com.electric.chargingpile.util.ImageDisplayUtils;
|
30
|
32
|
import com.electric.chargingpile.util.ScreenUtils;
|
|
@ -58,6 +60,7 @@ public class ChatContentListActivity extends AppCompatActivity {
|
58
|
60
|
public static boolean isFirstPlay;
|
59
|
61
|
private boolean makeSureNetworkForVideo = false;
|
60
|
62
|
private ChatContentAdapter chatContentAdapter;
|
|
63
|
private boolean isFirstShowNetworkDialog = true;
|
61
|
64
|
|
62
|
65
|
@Override
|
63
|
66
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@ -122,7 +125,7 @@ public class ChatContentListActivity extends AppCompatActivity {
|
122
|
125
|
}
|
123
|
126
|
|
124
|
127
|
private void play(final int position) {
|
125
|
|
ChatContentFragment chatContentFragment = (ChatContentFragment) chatContentAdapter.map.get(position + "");
|
|
128
|
final ChatContentFragment chatContentFragment = (ChatContentFragment) chatContentAdapter.map.get(position + "");
|
126
|
129
|
ChatRecommendBean bean = null;
|
127
|
130
|
if (from.equals(FROM_CHAT_HOME)) {
|
128
|
131
|
bean = ChatBeanLab.get(ChatContentListActivity.this).beansExceptTopic().get(position);
|
|
@ -131,41 +134,35 @@ public class ChatContentListActivity extends AppCompatActivity {
|
131
|
134
|
return;
|
132
|
135
|
}
|
133
|
136
|
|
134
|
|
if (makeSureNetworkForVideo) {
|
135
|
|
if (bean.targetType == ChatRecommendBean.TARGET_TYPE_VIDEO) {
|
136
|
|
if (MainApplication.autoPlayVideo) {
|
|
137
|
if (bean.targetType != ChatRecommendBean.TARGET_TYPE_VIDEO) {
|
|
138
|
return;
|
|
139
|
}
|
|
140
|
|
|
141
|
NetworkUtils.NetworkType networkType = NetworkUtils.getNetworkType();
|
|
142
|
switch (networkType) {
|
|
143
|
case NETWORK_2G:
|
|
144
|
case NETWORK_3G:
|
|
145
|
case NETWORK_WIFI:
|
|
146
|
if (ProfileManager.getInstance().getMakeSureNetworkForView(ChatContentListActivity.this)) {
|
137
|
147
|
chatContentFragment.play();
|
138
|
148
|
} else {
|
139
|
|
GSYVideoADManager.onPause();
|
140
|
|
GSYVideoManager.onPause();
|
|
149
|
if (isFirstShowNetworkDialog) {
|
|
150
|
isFirstShowNetworkDialog = false;
|
|
151
|
new AlertDialog(ChatContentListActivity.this).builder()
|
|
152
|
.setMsg("目前正在移动网络下,是否播放")
|
|
153
|
.setPositiveButton("继续播放", new View.OnClickListener() {
|
|
154
|
@Override
|
|
155
|
public void onClick(View view) {
|
|
156
|
ProfileManager.getInstance().setMakeSureNetworkForView(ChatContentListActivity.this);
|
|
157
|
chatContentFragment.play();
|
|
158
|
}
|
|
159
|
}).setNegativeButton("暂停播放", null).show();
|
|
160
|
}
|
141
|
161
|
}
|
142
|
|
} else {
|
143
|
|
GSYVideoADManager.onPause();
|
144
|
|
GSYVideoManager.onPause();
|
145
|
|
}
|
146
|
|
} else {
|
147
|
|
makeSureNetworkForVideo = true;
|
148
|
|
NetworkUtils.NetworkType networkType = NetworkUtils.getNetworkType();
|
149
|
|
switch (networkType) {
|
150
|
|
case NETWORK_2G:
|
151
|
|
case NETWORK_3G:
|
152
|
|
case NETWORK_4G:
|
153
|
|
MainApplication.autoPlayVideo = false;
|
154
|
|
break;
|
155
|
|
default:
|
156
|
|
MainApplication.autoPlayVideo = false;
|
157
|
|
break;
|
158
|
|
}
|
159
|
|
new AlertDialog(ChatContentListActivity.this).builder()
|
160
|
|
.setMsg("目前正在移动网络下,是否播放")
|
161
|
|
.setPositiveButton("继续播放", new View.OnClickListener() {
|
162
|
|
@Override
|
163
|
|
public void onClick(View view) {
|
164
|
|
MainApplication.autoPlayVideo = true;
|
165
|
|
play(position);
|
166
|
|
}
|
167
|
|
}).setNegativeButton("暂停播放", null).show();
|
168
|
|
|
|
162
|
break;
|
|
163
|
default:
|
|
164
|
chatContentFragment.play();
|
|
165
|
break;
|
169
|
166
|
}
|
170
|
167
|
}
|
171
|
168
|
|
|
@ -204,7 +201,6 @@ public class ChatContentListActivity extends AppCompatActivity {
|
204
|
201
|
private static final String ARG_FROM = "from";
|
205
|
202
|
private VideoPlayer videoPlayer;
|
206
|
203
|
private ImageView videoIcon;
|
207
|
|
private ProgressBar progressBar;
|
208
|
204
|
private ChatRecommendBean bean;
|
209
|
205
|
private ImageView playIcon;
|
210
|
206
|
|
|
@ -247,10 +243,8 @@ public class ChatContentListActivity extends AppCompatActivity {
|
247
|
243
|
videoPlayer = rootView.findViewById(R.id.videoPlayer);
|
248
|
244
|
videoPlayer.setUp(bean.videoUrl, true, "");
|
249
|
245
|
videoIcon = rootView.findViewById(R.id.videoIcon);
|
250
|
|
progressBar = rootView.findViewById(R.id.progressBar);
|
251
|
246
|
playIcon = rootView.findViewById(R.id.playIcon);
|
252
|
|
ImageView testImg = rootView.findViewById(R.id.testImg);
|
253
|
|
|
|
247
|
ConstraintLayout navBar = rootView.findViewById(R.id.navBar);
|
254
|
248
|
|
255
|
249
|
if (bean.coverImgH != 0 && bean.coverImgW != 0 && bean.coverImgW > bean.coverImgH) {
|
256
|
250
|
int navHeight = DensityUtil.dip2px(getContext(), 44);
|
|
@ -259,26 +253,31 @@ public class ChatContentListActivity extends AppCompatActivity {
|
259
|
253
|
params.height = videoRealHeight;
|
260
|
254
|
params.bottomToBottom = -1;
|
261
|
255
|
params.topMargin = statusBarHeight + navHeight + DensityUtil.dip2px(getContext(), 60);
|
262
|
|
|
263
|
|
// if (bean.topicId == 0) {
|
264
|
|
// int space = screenHeight - DensityUtil.dip2px(getContext(), 152) - statusBarHeight - navHeight;
|
265
|
|
// if (space > videoRealHeight) {
|
266
|
|
// params.topMargin = statusBarHeight + navHeight + (space - videoRealHeight) / 2;
|
267
|
|
// params.bottomMargin = DensityUtil.dip2px(getContext(), 152) + navHeight + (space - videoRealHeight) / 2;
|
268
|
|
// }
|
269
|
|
// } else {
|
270
|
|
// int space = screenHeight - DensityUtil.dip2px(getContext(), 192) - statusBarHeight - navHeight;
|
271
|
|
// if (space > videoRealHeight) {
|
272
|
|
// params.topMargin = statusBarHeight + navHeight + navHeight + (space - videoRealHeight) / 2;
|
273
|
|
// params.bottomMargin = DensityUtil.dip2px(getContext(), 192) + navHeight + (space - videoRealHeight) / 2;
|
274
|
|
// }
|
275
|
|
// }
|
|
256
|
videoPlayer.setLayoutParams(params);
|
276
|
257
|
}
|
277
|
258
|
|
|
259
|
ConstraintLayout.LayoutParams navBarParams = (ConstraintLayout.LayoutParams) navBar.getLayoutParams();
|
|
260
|
navBarParams.topMargin = statusBarHeight;
|
|
261
|
navBar.setLayoutParams(navBarParams);
|
|
262
|
|
|
263
|
rootView.findViewById(R.id.backIcon).setOnClickListener(new View.OnClickListener() {
|
|
264
|
@Override
|
|
265
|
public void onClick(View view) {
|
|
266
|
getActivity().finish();
|
|
267
|
}
|
|
268
|
});
|
|
269
|
|
|
270
|
rootView.findViewById(R.id.moreIcon).setOnClickListener(new View.OnClickListener() {
|
|
271
|
@Override
|
|
272
|
public void onClick(View view) {
|
|
273
|
ToastUtil.showToast(getContext(), "more ", Toast.LENGTH_SHORT);
|
|
274
|
}
|
|
275
|
});
|
|
276
|
|
278
|
277
|
videoPlayer.setVideoAllCallBack(new VideoAllCallBack() {
|
279
|
278
|
@Override
|
280
|
279
|
public void onAutoComplete(String s, Object... objects) {
|
281
|
|
if (MainApplication.autoPlayVideo) {
|
|
280
|
if (ProfileManager.getInstance().getMakeSureNetworkForView(getContext())) {
|
282
|
281
|
videoPlayer.startPlayLogic();
|
283
|
282
|
}
|
284
|
283
|
}
|
|
@ -376,55 +375,51 @@ public class ChatContentListActivity extends AppCompatActivity {
|
376
|
375
|
}
|
377
|
376
|
});
|
378
|
377
|
|
379
|
|
|
380
|
|
/**
|
381
|
|
* i 视频播放百分比
|
382
|
|
* i2 视频缓存长度
|
383
|
|
* i3 视频总长度
|
384
|
|
*/
|
385
|
|
videoPlayer.setGSYVideoProgressListener(new GSYVideoProgressListener() {
|
386
|
|
@Override
|
387
|
|
public void onProgress(int i, int i1, int i2, int i3) {
|
388
|
|
// if (i == 1) {
|
389
|
|
// videoPlayer.onVideoPause();
|
390
|
|
// }
|
391
|
|
// Log.d(TAG, "onProgress: " + i + ",i1:" + i1 + ",i2:" + i2 + ",i3:" + i3);
|
392
|
|
|
393
|
|
progressBar.setSecondaryProgress(i);
|
394
|
|
}
|
395
|
|
});
|
396
|
|
|
397
|
378
|
ImageView thumbImageView = new ImageView(getContext());
|
398
|
379
|
thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
399
|
|
// thumbImageView.setImageResource(R.drawable.app_publish_video_icon);
|
400
|
380
|
ImageDisplayUtils.dispalyImg(getContext(), bean.coverImgUrl, thumbImageView);
|
401
|
381
|
videoPlayer.setThumbImageView(thumbImageView);
|
402
|
382
|
|
403
|
383
|
rootView.findViewById(R.id.videoPlayerCover).setOnClickListener(new View.OnClickListener() {
|
404
|
384
|
@Override
|
405
|
385
|
public void onClick(View view) {
|
406
|
|
int currentStatue = videoPlayer.getCurrentState();
|
407
|
|
if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {
|
408
|
|
playIcon.setVisibility(View.VISIBLE);
|
409
|
|
videoPlayer.onVideoPause();
|
410
|
|
} else if (currentStatue == GSYVideoView.CURRENT_STATE_PAUSE) {
|
411
|
|
playIcon.setVisibility(View.GONE);
|
412
|
|
videoPlayer.onVideoResume(false);
|
|
386
|
if (ProfileManager.getInstance().getMakeSureNetworkForView(getContext())) {
|
|
387
|
playOrPause();
|
413
|
388
|
} else {
|
414
|
|
playIcon.setVisibility(View.GONE);
|
415
|
|
videoPlayer.startPlayLogic();
|
|
389
|
|
416
|
390
|
}
|
|
391
|
new AlertDialog(getContext()).builder()
|
|
392
|
.setMsg("目前正在移动网络下,是否播放")
|
|
393
|
.setPositiveButton("继续播放", new View.OnClickListener() {
|
|
394
|
@Override
|
|
395
|
public void onClick(View view) {
|
|
396
|
ProfileManager.getInstance().setMakeSureNetworkForView(getContext());
|
|
397
|
playOrPause();
|
|
398
|
}
|
|
399
|
}).setNegativeButton("暂停播放", null).show();
|
417
|
400
|
}
|
418
|
401
|
});
|
|
402
|
}
|
419
|
403
|
|
420
|
|
// TextView positionTextView = rootView.findViewById(R.id.position);
|
421
|
|
// positionTextView.setText(bean.title);
|
|
404
|
private void playOrPause() {
|
|
405
|
int currentStatue = videoPlayer.getCurrentState();
|
|
406
|
if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {
|
|
407
|
playIcon.setVisibility(View.VISIBLE);
|
|
408
|
videoPlayer.onVideoPause();
|
|
409
|
} else if (currentStatue == GSYVideoView.CURRENT_STATE_PAUSE) {
|
|
410
|
playIcon.setVisibility(View.GONE);
|
|
411
|
videoPlayer.onVideoResume(false);
|
|
412
|
} else {
|
|
413
|
playIcon.setVisibility(View.GONE);
|
|
414
|
videoPlayer.startPlayLogic();
|
|
415
|
}
|
422
|
416
|
}
|
423
|
417
|
|
424
|
418
|
public void play() {
|
425
|
419
|
if (videoPlayer == null) {
|
426
|
420
|
return;
|
427
|
421
|
}
|
|
422
|
|
428
|
423
|
playIcon.setVisibility(View.GONE);
|
429
|
424
|
int currentStatue = videoPlayer.getCurrentState();
|
430
|
425
|
if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {
|