Search in sources :

Example 1 with VideoPlayerRewinder

use of org.telegram.messenger.video.VideoPlayerRewinder in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatMessageCell method onLongPress.

@Override
protected boolean onLongPress() {
    if (isRoundVideo && isPlayingRound && MediaController.getInstance().isPlayingMessage(currentMessageObject)) {
        float touchRadius = (lastTouchX - photoImage.getCenterX()) * (lastTouchX - photoImage.getCenterX()) + (lastTouchY - photoImage.getCenterY()) * (lastTouchY - photoImage.getCenterY());
        float r1 = (photoImage.getImageWidth() / 2f) * (photoImage.getImageWidth() / 2f);
        if (touchRadius < r1 && (lastTouchX > photoImage.getCenterX() + photoImage.getImageWidth() / 4f || lastTouchX < photoImage.getCenterX() - photoImage.getImageWidth() / 4f)) {
            boolean forward = lastTouchX > photoImage.getCenterX();
            if (videoPlayerRewinder == null) {
                videoForwardDrawable = new VideoForwardDrawable(true);
                videoPlayerRewinder = new VideoPlayerRewinder() {

                    @Override
                    protected void onRewindCanceled() {
                        onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0));
                        videoForwardDrawable.setShowing(false);
                    }

                    @Override
                    protected void updateRewindProgressUi(long timeDiff, float progress, boolean rewindByBackSeek) {
                        videoForwardDrawable.setTime(Math.abs(timeDiff));
                        if (rewindByBackSeek) {
                            currentMessageObject.audioProgress = progress;
                            updatePlayingMessageProgress();
                        }
                    }

                    @Override
                    protected void onRewindStart(boolean rewindForward) {
                        videoForwardDrawable.setDelegate(new VideoForwardDrawable.VideoForwardDrawableDelegate() {

                            @Override
                            public void onAnimationEnd() {
                            }

                            @Override
                            public void invalidate() {
                                ChatMessageCell.this.invalidate();
                            }
                        });
                        videoForwardDrawable.setOneShootAnimation(false);
                        videoForwardDrawable.setLeftSide(!rewindForward);
                        videoForwardDrawable.setShowing(true);
                        invalidate();
                    }
                };
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            videoPlayerRewinder.startRewind(MediaController.getInstance().getVideoPlayer(), forward, MediaController.getInstance().getPlaybackSpeed(false));
            return false;
        }
    }
    if (pressedLink instanceof URLSpanMono) {
        delegate.didPressUrl(this, pressedLink, true);
        return true;
    } else if (pressedLink instanceof URLSpanNoUnderline) {
        URLSpanNoUnderline url = (URLSpanNoUnderline) pressedLink;
        if (ChatActivity.isClickableLink(url.getURL()) || url.getURL().startsWith("/")) {
            delegate.didPressUrl(this, pressedLink, true);
            return true;
        }
    } else if (pressedLink instanceof URLSpan) {
        delegate.didPressUrl(this, pressedLink, true);
        return true;
    }
    resetPressedLink(-1);
    if (buttonPressed != 0 || miniButtonPressed != 0 || videoButtonPressed != 0 || pressedBotButton != -1) {
        buttonPressed = 0;
        miniButtonPressed = 0;
        videoButtonPressed = 0;
        pressedBotButton = -1;
        invalidate();
    }
    linkPreviewPressed = false;
    sideButtonPressed = false;
    imagePressed = false;
    timePressed = false;
    gamePreviewPressed = false;
    if (pressedVoteButton != -1 || pollHintPressed || psaHintPressed || instantPressed || otherPressed || commentButtonPressed) {
        instantPressed = instantButtonPressed = commentButtonPressed = false;
        pressedVoteButton = -1;
        pollHintPressed = false;
        psaHintPressed = false;
        otherPressed = false;
        if (Build.VERSION.SDK_INT >= 21) {
            for (int a = 0; a < selectorDrawable.length; a++) {
                if (selectorDrawable[a] != null) {
                    selectorDrawable[a].setState(StateSet.NOTHING);
                }
            }
        }
        invalidate();
    }
    if (delegate != null) {
        boolean handled = false;
        if (avatarPressed) {
            if (currentUser != null) {
                if (currentUser.id != 0) {
                    handled = delegate.didLongPressUserAvatar(this, currentUser, lastTouchX, lastTouchY);
                }
            } else if (currentChat != null) {
                final int id;
                if (currentMessageObject.messageOwner.fwd_from != null) {
                    if ((currentMessageObject.messageOwner.fwd_from.flags & 16) != 0) {
                        id = currentMessageObject.messageOwner.fwd_from.saved_from_msg_id;
                    } else {
                        id = currentMessageObject.messageOwner.fwd_from.channel_post;
                    }
                } else {
                    id = 0;
                }
                handled = delegate.didLongPressChannelAvatar(this, currentChat, id, lastTouchX, lastTouchY);
            }
        }
        if (!handled) {
            delegate.didLongPress(this, lastTouchX, lastTouchY);
        }
    }
    return true;
}
Also used : URLSpanMono(org.telegram.ui.Components.URLSpanMono) VideoPlayerRewinder(org.telegram.messenger.video.VideoPlayerRewinder) VideoForwardDrawable(org.telegram.ui.Components.VideoForwardDrawable) URLSpan(android.text.style.URLSpan) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(org.telegram.ui.Components.Point)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 URLSpan (android.text.style.URLSpan)1 VideoPlayerRewinder (org.telegram.messenger.video.VideoPlayerRewinder)1 Point (org.telegram.ui.Components.Point)1 URLSpanMono (org.telegram.ui.Components.URLSpanMono)1 URLSpanNoUnderline (org.telegram.ui.Components.URLSpanNoUnderline)1 VideoForwardDrawable (org.telegram.ui.Components.VideoForwardDrawable)1