Преглед на файлове

视频播放提醒添加

huyuguo преди 5 години
родител
ревизия
7a25d1ff6a

+ 77 - 82
app/src/main/java/com/electric/chargingpile/activity/ChatContentListActivity.java

25
import com.electric.chargingpile.application.MainApplication;
25
import com.electric.chargingpile.application.MainApplication;
26
import com.electric.chargingpile.data.ChatBeanLab;
26
import com.electric.chargingpile.data.ChatBeanLab;
27
import com.electric.chargingpile.data.ChatRecommendBean;
27
import com.electric.chargingpile.data.ChatRecommendBean;
28
import com.electric.chargingpile.manager.PreferenceManager;
29
import com.electric.chargingpile.manager.ProfileManager;
28
import com.electric.chargingpile.util.DensityUtil;
30
import com.electric.chargingpile.util.DensityUtil;
29
import com.electric.chargingpile.util.ImageDisplayUtils;
31
import com.electric.chargingpile.util.ImageDisplayUtils;
30
import com.electric.chargingpile.util.ScreenUtils;
32
import com.electric.chargingpile.util.ScreenUtils;
58
    public static boolean isFirstPlay;
60
    public static boolean isFirstPlay;
59
    private boolean makeSureNetworkForVideo = false;
61
    private boolean makeSureNetworkForVideo = false;
60
    private ChatContentAdapter chatContentAdapter;
62
    private ChatContentAdapter chatContentAdapter;
63
    private boolean isFirstShowNetworkDialog = true;
61
64
62
    @Override
65
    @Override
63
    protected void onCreate(Bundle savedInstanceState) {
66
    protected void onCreate(Bundle savedInstanceState) {
122
    }
125
    }
123
126
124
    private void play(final int position) {
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
        ChatRecommendBean bean = null;
129
        ChatRecommendBean bean = null;
127
        if (from.equals(FROM_CHAT_HOME)) {
130
        if (from.equals(FROM_CHAT_HOME)) {
128
            bean = ChatBeanLab.get(ChatContentListActivity.this).beansExceptTopic().get(position);
131
            bean = ChatBeanLab.get(ChatContentListActivity.this).beansExceptTopic().get(position);
131
            return;
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
                    chatContentFragment.play();
147
                    chatContentFragment.play();
138
                } else {
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
        private static final String ARG_FROM = "from";
201
        private static final String ARG_FROM = "from";
205
        private VideoPlayer videoPlayer;
202
        private VideoPlayer videoPlayer;
206
        private ImageView videoIcon;
203
        private ImageView videoIcon;
207
        private ProgressBar progressBar;
208
        private ChatRecommendBean bean;
204
        private ChatRecommendBean bean;
209
        private ImageView playIcon;
205
        private ImageView playIcon;
210
206
247
            videoPlayer = rootView.findViewById(R.id.videoPlayer);
243
            videoPlayer = rootView.findViewById(R.id.videoPlayer);
248
            videoPlayer.setUp(bean.videoUrl, true, "");
244
            videoPlayer.setUp(bean.videoUrl, true, "");
249
            videoIcon = rootView.findViewById(R.id.videoIcon);
245
            videoIcon = rootView.findViewById(R.id.videoIcon);
250
            progressBar = rootView.findViewById(R.id.progressBar);
251
            playIcon = rootView.findViewById(R.id.playIcon);
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
            if (bean.coverImgH != 0 && bean.coverImgW != 0 && bean.coverImgW > bean.coverImgH) {
249
            if (bean.coverImgH != 0 && bean.coverImgW != 0 && bean.coverImgW > bean.coverImgH) {
256
                int navHeight = DensityUtil.dip2px(getContext(), 44);
250
                int navHeight = DensityUtil.dip2px(getContext(), 44);
259
                params.height = videoRealHeight;
253
                params.height = videoRealHeight;
260
                params.bottomToBottom = -1;
254
                params.bottomToBottom = -1;
261
                params.topMargin = statusBarHeight + navHeight + DensityUtil.dip2px(getContext(), 60);
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
            videoPlayer.setVideoAllCallBack(new VideoAllCallBack() {
277
            videoPlayer.setVideoAllCallBack(new VideoAllCallBack() {
279
                @Override
278
                @Override
280
                public void onAutoComplete(String s, Object... objects) {
279
                public void onAutoComplete(String s, Object... objects) {
281
                    if (MainApplication.autoPlayVideo) {
280
                    if (ProfileManager.getInstance().getMakeSureNetworkForView(getContext())) {
282
                        videoPlayer.startPlayLogic();
281
                        videoPlayer.startPlayLogic();
283
                    }
282
                    }
284
                }
283
                }
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
            ImageView thumbImageView = new ImageView(getContext());
378
            ImageView thumbImageView = new ImageView(getContext());
398
            thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
379
            thumbImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
399
//            thumbImageView.setImageResource(R.drawable.app_publish_video_icon);
400
            ImageDisplayUtils.dispalyImg(getContext(), bean.coverImgUrl, thumbImageView);
380
            ImageDisplayUtils.dispalyImg(getContext(), bean.coverImgUrl, thumbImageView);
401
            videoPlayer.setThumbImageView(thumbImageView);
381
            videoPlayer.setThumbImageView(thumbImageView);
402
382
403
            rootView.findViewById(R.id.videoPlayerCover).setOnClickListener(new View.OnClickListener() {
383
            rootView.findViewById(R.id.videoPlayerCover).setOnClickListener(new View.OnClickListener() {
404
                @Override
384
                @Override
405
                public void onClick(View view) {
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
                    } else {
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
        public void play() {
418
        public void play() {
425
            if (videoPlayer == null) {
419
            if (videoPlayer == null) {
426
                return;
420
                return;
427
            }
421
            }
422
428
            playIcon.setVisibility(View.GONE);
423
            playIcon.setVisibility(View.GONE);
429
            int currentStatue = videoPlayer.getCurrentState();
424
            int currentStatue = videoPlayer.getCurrentState();
430
            if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {
425
            if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {

+ 0 - 1
app/src/main/java/com/electric/chargingpile/application/MainApplication.java

127
    public static boolean haveActivity = false;
127
    public static boolean haveActivity = false;
128
    public static String ad_major = "";
128
    public static String ad_major = "";
129
    private String mCurrentCity = "";
129
    private String mCurrentCity = "";
130
    public static boolean autoPlayVideo = false;
131

130

132

131

133
    @SuppressLint("MissingPermission")
132
    @SuppressLint("MissingPermission")

+ 16 - 0
app/src/main/java/com/electric/chargingpile/manager/ProfileManager.java

1
package com.electric.chargingpile.manager;
1
package com.electric.chargingpile.manager;
2

2

3
import android.content.Context;
3
import android.content.Context;
4
import android.util.Log;
4

5

5
public class ProfileManager {
6
public class ProfileManager {
6

7

62
    private static final String KEY_ADD_COME_FIRST = "key_add_come_first";
63
    private static final String KEY_ADD_COME_FIRST = "key_add_come_first";
63
    private static final String KEY_CLICKED_USER_PUBLISH_TOPIC = "key_clicked_user_publish_topic";
64
    private static final String KEY_CLICKED_USER_PUBLISH_TOPIC = "key_clicked_user_publish_topic";
64
    private static final String KEY_CLICKED_USER_PUBLISH_ROLE = "key_clicked_user_publish_role";
65
    private static final String KEY_CLICKED_USER_PUBLISH_ROLE = "key_clicked_user_publish_role";
66
    private static final String KEY_MAKE_SURE_NETWORK_FOR_VIDEO = "key_make_sure_network_for_video";
65

67

66
    private static ProfileManager instance;
68
    private static ProfileManager instance;
67

69

511
                "");
513
                "");
512
    }
514
    }
513

515

516
    public boolean getMakeSureNetworkForView(Context context) {
517
        long currentTimeMillis = System.currentTimeMillis();
518
        long savedTimeMillis = PreferenceManager.getInstance(context).getLong(KEY_MAKE_SURE_NETWORK_FOR_VIDEO, 0);
519
        if (currentTimeMillis - savedTimeMillis > 86400000) {
520
            return false;
521
        } else {
522
            return true;
523
        }
524
    }
525

526
    public void setMakeSureNetworkForView(Context context) {
527
        PreferenceManager.getInstance(context).putLong(KEY_MAKE_SURE_NETWORK_FOR_VIDEO, System.currentTimeMillis());
528
    }
529

514
    public String getClickedUserPublishTopic(Context context) {
530
    public String getClickedUserPublishTopic(Context context) {
515
        return PreferenceManager.getInstance(context).getString(KEY_CLICKED_USER_PUBLISH_TOPIC,
531
        return PreferenceManager.getInstance(context).getString(KEY_CLICKED_USER_PUBLISH_TOPIC,
516
                "");
532
                "");

+ 37 - 25
app/src/main/res/layout/fragment_chat_content_video.xml

10
        android:id="@+id/videoPlayer"
10
        android:id="@+id/videoPlayer"
11
        android:layout_width="match_parent"
11
        android:layout_width="match_parent"
12
        android:layout_height="match_parent"
12
        android:layout_height="match_parent"
13
        app:layout_constraintTop_toTopOf="parent"
14
        app:layout_constraintEnd_toEndOf="parent"
15
        app:layout_constraintBottom_toBottomOf="parent"
13
        app:layout_constraintBottom_toBottomOf="parent"
16
        app:layout_constraintStart_toStartOf="parent">
17
    </com.electric.chargingpile.video.VideoPlayer>
14
        app:layout_constraintEnd_toEndOf="parent"
15
        app:layout_constraintStart_toStartOf="parent"
16
        app:layout_constraintTop_toTopOf="parent"></com.electric.chargingpile.video.VideoPlayer>
17
18
    <ImageView
19
        android:background="#424242"
20
        android:layout_width="match_parent"
21
        android:layout_height="1.5dp"
22
        app:layout_constraintBottom_toBottomOf="@+id/videoPlayer" />
18
23
19
    <ImageView
24
    <ImageView
20
        android:id="@+id/playIcon"
25
        android:id="@+id/playIcon"
34
        app:layout_constraintBottom_toBottomOf="parent"
39
        app:layout_constraintBottom_toBottomOf="parent"
35
        app:layout_constraintLeft_toLeftOf="parent"
40
        app:layout_constraintLeft_toLeftOf="parent"
36
        app:layout_constraintRight_toRightOf="parent"
41
        app:layout_constraintRight_toRightOf="parent"
37
        app:layout_constraintTop_toTopOf="parent">
38
    </android.support.constraint.ConstraintLayout>
39
40
    <ProgressBar
41
        android:id="@+id/progressBar"
42
        android:visibility="gone"
43
        style="@android:style/Widget.ProgressBar.Horizontal"
44
        android:layout_width="match_parent"
45
        android:layout_height="1dp"
46
        android:max="100"
47
        tools:progress="50"
48
        android:progressDrawable="@drawable/video_player_progressbar"
49
        app:layout_constraintBottom_toTopOf="parent"
50
        app:layout_constraintEnd_toEndOf="parent"
51
        app:layout_constraintStart_toStartOf="parent"
52
        tools:layout_height="10dp"
53
        tools:secondaryProgress="10" />
42
        app:layout_constraintTop_toTopOf="parent"></android.support.constraint.ConstraintLayout>
54
43
55
    <ImageView
56
        android:id="@+id/testImg"
57
        android:background="#0000ee"
44
    <android.support.constraint.ConstraintLayout
45
        android:id="@+id/navBar"
58
        android:layout_width="match_parent"
46
        android:layout_width="match_parent"
47
        android:layout_height="44dp"
48
        android:layout_marginTop="20dp"
59
        app:layout_constraintLeft_toLeftOf="parent"
49
        app:layout_constraintLeft_toLeftOf="parent"
50
        app:layout_constraintRight_toRightOf="parent"
60
        app:layout_constraintTop_toTopOf="parent"
51
        app:layout_constraintTop_toTopOf="parent"
61
        android:layout_height="5dp" />
52
        tools:background="#DC7633">
53
54
        <ImageView
55
            android:id="@+id/backIcon"
56
            android:layout_width="wrap_content"
57
            android:layout_height="match_parent"
58
            android:paddingLeft="20dp"
59
            android:paddingRight="20dp"
60
            android:src="@drawable/app_white_back_icon"
61
            app:layout_constraintLeft_toLeftOf="parent" />
62
63
        <ImageView
64
            android:id="@+id/moreIcon"
65
            android:layout_width="wrap_content"
66
            android:layout_height="match_parent"
67
            android:paddingLeft="20dp"
68
            android:paddingRight="20dp"
69
            android:src="@drawable/app_header_more_icon"
70
            app:layout_constraintRight_toRightOf="parent" />
71
72
    </android.support.constraint.ConstraintLayout>
73
62
</android.support.constraint.ConstraintLayout>
74
</android.support.constraint.ConstraintLayout>