Search in sources :

Example 16 with ChatActivity

use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (isLocation) {
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.liveLocationsChanged);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.liveLocationsCacheChanged);
        if (additionalContextView != null) {
            additionalContextView.checkVisibility();
        }
        checkLiveLocation(true);
    } else {
        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingDidReset);
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingDidStart);
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.groupCallUpdated);
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.groupCallTypingsUpdated);
            NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.historyImportProgressChanged);
        }
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.messagePlayingSpeedChanged);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didStartedCall);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didEndCall);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.webRtcSpeakerAmplitudeEvent);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.webRtcMicAmplitudeEvent);
        NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.groupCallVisibilityChanged);
        if (additionalContextView != null) {
            additionalContextView.checkVisibility();
        }
        if (VoIPService.getSharedInstance() != null && !VoIPService.getSharedInstance().isHangingUp() && VoIPService.getSharedInstance().getCallState() != VoIPService.STATE_WAITING_INCOMING && !GroupCallPip.isShowing()) {
            checkCall(true);
        } else if (fragment instanceof ChatActivity && fragment.getSendMessagesHelper().getImportingHistory(((ChatActivity) fragment).getDialogId()) != null && !isPlayingVoice()) {
            checkImport(true);
        } else if (fragment instanceof ChatActivity && ((ChatActivity) fragment).getGroupCall() != null && ((ChatActivity) fragment).getGroupCall().shouldShowPanel() && !GroupCallPip.isShowing() && !isPlayingVoice()) {
            checkCall(true);
        } else {
            checkCall(true);
            checkPlayer(true);
            updatePlaybackButton();
        }
    }
    if (currentStyle == 3 || currentStyle == 1) {
        Theme.getFragmentContextViewWavesDrawable().addParent(this);
        if (VoIPService.getSharedInstance() != null) {
            VoIPService.getSharedInstance().registerStateListener(this);
        }
        boolean newMuted = VoIPService.getSharedInstance() != null && VoIPService.getSharedInstance().isMicMute();
        if (isMuted != newMuted) {
            isMuted = newMuted;
            muteDrawable.setCustomEndFrame(isMuted ? 15 : 29);
            muteDrawable.setCurrentFrame(muteDrawable.getCustomEndFrame() - 1, false, true);
            muteButton.invalidate();
        }
    } else if (currentStyle == 4) {
        if (!scheduleRunnableScheduled) {
            scheduleRunnableScheduled = true;
            updateScheduleTimeRunnable.run();
        }
    }
    if (visible && topPadding == 0) {
        updatePaddings();
        setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
    }
    speakerAmplitude = 0;
    micAmplitude = 0;
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 17 with ChatActivity

use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method checkImport.

public void checkImport(boolean create) {
    if (!(fragment instanceof ChatActivity) || visible && (currentStyle == 1 || currentStyle == 3)) {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    SendMessagesHelper.ImportingHistory importingHistory = chatActivity.getSendMessagesHelper().getImportingHistory(chatActivity.getDialogId());
    View fragmentView = fragment.getFragmentView();
    if (!create && fragmentView != null) {
        if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
            create = true;
        }
    }
    Dialog dialog = chatActivity.getVisibleDialog();
    if ((isPlayingVoice() || chatActivity.shouldShowImport() || dialog instanceof ImportingAlert && !((ImportingAlert) dialog).isDismissed()) && importingHistory != null) {
        importingHistory = null;
    }
    if (importingHistory == null) {
        if (visible && (create && currentStyle == -1 || currentStyle == 5)) {
            visible = false;
            if (create) {
                if (getVisibility() != GONE) {
                    setVisibility(GONE);
                }
                setTopPadding(0);
            } else {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                final int currentAccount = account;
                animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
                animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
                animatorSet.setDuration(220);
                animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            setVisibility(GONE);
                            animatorSet = null;
                            if (checkCallAfterAnimation) {
                                checkCall(false);
                            } else if (checkPlayerAfterAnimation) {
                                checkPlayer(false);
                            } else if (checkImportAfterAnimation) {
                                checkImport(false);
                            }
                            checkCallAfterAnimation = false;
                            checkPlayerAfterAnimation = false;
                            checkImportAfterAnimation = false;
                        }
                    }
                });
                animatorSet.start();
            }
        } else if (currentStyle == -1 || currentStyle == 5) {
            visible = false;
            setVisibility(GONE);
        }
    } else {
        if (currentStyle != 5 && animatorSet != null && !create) {
            checkImportAfterAnimation = true;
            return;
        }
        int prevStyle = currentStyle;
        updateStyle(5);
        if (create && topPadding == 0) {
            updatePaddings();
            setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
            if (delegate != null) {
                delegate.onAnimation(true, true);
                delegate.onAnimation(false, true);
            }
        }
        if (!visible) {
            if (!create) {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                animationIndex = NotificationCenter.getInstance(account).setAnimationInProgress(animationIndex, null);
                animatorSet = new AnimatorSet();
                if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE) {
                    ((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight() + additionalContextView.getStyleHeight());
                } else {
                    ((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight());
                }
                if (delegate != null) {
                    delegate.onAnimation(true, true);
                }
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        NotificationCenter.getInstance(account).onAnimationFinish(animationIndex);
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            if (delegate != null) {
                                delegate.onAnimation(false, true);
                            }
                            animatorSet = null;
                            if (checkCallAfterAnimation) {
                                checkCall(false);
                            } else if (checkPlayerAfterAnimation) {
                                checkPlayer(false);
                            } else if (checkImportAfterAnimation) {
                                checkImport(false);
                            }
                            checkCallAfterAnimation = false;
                            checkPlayerAfterAnimation = false;
                            checkImportAfterAnimation = false;
                        }
                    }
                });
                animatorSet.start();
            }
            visible = true;
            setVisibility(VISIBLE);
        }
        if (currentProgress != importingHistory.uploadProgress) {
            currentProgress = importingHistory.uploadProgress;
            titleTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("ImportUploading", R.string.ImportUploading, importingHistory.uploadProgress)), false);
        }
    }
}
Also used : SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ChatActivity(org.telegram.ui.ChatActivity) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 18 with ChatActivity

use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method checkCall.

public void checkCall(boolean create) {
    VoIPService voIPService = VoIPService.getSharedInstance();
    if (visible && currentStyle == 5 && (voIPService == null || voIPService.isHangingUp())) {
        return;
    }
    View fragmentView = fragment.getFragmentView();
    if (!create && fragmentView != null) {
        if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
            create = true;
        }
    }
    boolean callAvailable;
    boolean groupActive;
    if (GroupCallPip.isShowing()) {
        callAvailable = false;
        groupActive = false;
    } else {
        callAvailable = !GroupCallActivity.groupCallUiVisible && supportsCalls && voIPService != null && !voIPService.isHangingUp();
        if (voIPService != null && voIPService.groupCall != null && voIPService.groupCall.call instanceof TLRPC.TL_groupCallDiscarded) {
            callAvailable = false;
        }
        groupActive = false;
        if (!isPlayingVoice() && !GroupCallActivity.groupCallUiVisible && supportsCalls && !callAvailable && fragment instanceof ChatActivity) {
            ChatObject.Call call = ((ChatActivity) fragment).getGroupCall();
            if (call != null && call.shouldShowPanel()) {
                callAvailable = true;
                groupActive = true;
            }
        }
    }
    if (!callAvailable) {
        if (visible && (create && currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1)) {
            visible = false;
            if (create) {
                if (getVisibility() != GONE) {
                    setVisibility(GONE);
                }
                setTopPadding(0);
            } else {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                final int currentAccount = account;
                animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
                animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
                animatorSet.setDuration(220);
                animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            setVisibility(GONE);
                            animatorSet = null;
                            if (checkCallAfterAnimation) {
                                checkCall(false);
                            } else if (checkPlayerAfterAnimation) {
                                checkPlayer(false);
                            } else if (checkImportAfterAnimation) {
                                checkImport(false);
                            }
                            checkCallAfterAnimation = false;
                            checkPlayerAfterAnimation = false;
                            checkImportAfterAnimation = false;
                        }
                    }
                });
                animatorSet.start();
            }
        } else if (visible && (currentStyle == -1 || currentStyle == 4 || currentStyle == 3 || currentStyle == 1)) {
            visible = false;
            setVisibility(GONE);
        }
        if (create && fragment instanceof ChatActivity && ((ChatActivity) fragment).openedWithLivestream() && !GroupCallPip.isShowing()) {
            BulletinFactory.of(fragment).createSimpleBulletin(R.raw.linkbroken, LocaleController.getString("InviteExpired", R.string.InviteExpired)).show();
        }
    } else {
        int newStyle;
        if (groupActive) {
            newStyle = 4;
        } else if (voIPService.groupCall != null) {
            newStyle = 3;
        } else {
            newStyle = 1;
        }
        if (newStyle != currentStyle && animatorSet != null && !create) {
            checkCallAfterAnimation = true;
            return;
        }
        if (newStyle != currentStyle && visible && !create) {
            if (animatorSet != null) {
                animatorSet.cancel();
                animatorSet = null;
            }
            final int currentAccount = account;
            animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
            animatorSet = new AnimatorSet();
            animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
            animatorSet.setDuration(220);
            animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
            animatorSet.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                    if (animatorSet != null && animatorSet.equals(animation)) {
                        visible = false;
                        animatorSet = null;
                        checkCall(false);
                    }
                }
            });
            animatorSet.start();
            return;
        }
        if (groupActive) {
            boolean updateAnimated = currentStyle == 4 && visible;
            updateStyle(4);
            ChatObject.Call call = ((ChatActivity) fragment).getGroupCall();
            TLRPC.Chat chat = ((ChatActivity) fragment).getCurrentChat();
            if (call.isScheduled()) {
                if (gradientPaint == null) {
                    gradientTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
                    gradientTextPaint.setColor(0xffffffff);
                    gradientTextPaint.setTextSize(AndroidUtilities.dp(14));
                    gradientTextPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                    gradientPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                    gradientPaint.setColor(0xffffffff);
                    matrix = new Matrix();
                }
                joinButton.setVisibility(GONE);
                if (!TextUtils.isEmpty(call.call.title)) {
                    titleTextView.setText(call.call.title, false);
                } else {
                    if (ChatObject.isChannelOrGiga(chat)) {
                        titleTextView.setText(LocaleController.getString("VoipChannelScheduledVoiceChat", R.string.VoipChannelScheduledVoiceChat), false);
                    } else {
                        titleTextView.setText(LocaleController.getString("VoipGroupScheduledVoiceChat", R.string.VoipGroupScheduledVoiceChat), false);
                    }
                }
                subtitleTextView.setText(LocaleController.formatStartsTime(call.call.schedule_date, 4), false);
                if (!scheduleRunnableScheduled) {
                    scheduleRunnableScheduled = true;
                    updateScheduleTimeRunnable.run();
                }
            } else {
                timeLayout = null;
                joinButton.setVisibility(VISIBLE);
                if (ChatObject.isChannelOrGiga(chat)) {
                    titleTextView.setText(LocaleController.getString("VoipChannelVoiceChat", R.string.VoipChannelVoiceChat), false);
                } else {
                    titleTextView.setText(LocaleController.getString("VoipGroupVoiceChat", R.string.VoipGroupVoiceChat), false);
                }
                if (call.call.participants_count == 0) {
                    subtitleTextView.setText(LocaleController.getString("MembersTalkingNobody", R.string.MembersTalkingNobody), false);
                } else {
                    subtitleTextView.setText(LocaleController.formatPluralString("Participants", call.call.participants_count), false);
                }
                frameLayout.invalidate();
            }
            updateAvatars(avatars.avatarsDarawable.wasDraw && updateAnimated);
        } else {
            if (voIPService != null && voIPService.groupCall != null) {
                updateAvatars(currentStyle == 3);
                updateStyle(3);
            } else {
                updateAvatars(currentStyle == 1);
                updateStyle(1);
            }
        }
        if (!visible) {
            if (!create) {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                animatorSet = new AnimatorSet();
                if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE) {
                    ((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight() + additionalContextView.getStyleHeight());
                } else {
                    ((LayoutParams) getLayoutParams()).topMargin = -AndroidUtilities.dp(getStyleHeight());
                }
                final int currentAccount = account;
                animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, new int[] { NotificationCenter.messagesDidLoad });
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
                animatorSet.setDuration(220);
                animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            animatorSet = null;
                        }
                        if (checkCallAfterAnimation) {
                            checkCall(false);
                        } else if (checkPlayerAfterAnimation) {
                            checkPlayer(false);
                        } else if (checkImportAfterAnimation) {
                            checkImport(false);
                        }
                        checkCallAfterAnimation = false;
                        checkPlayerAfterAnimation = false;
                        checkImportAfterAnimation = false;
                    }
                });
                animatorSet.start();
            } else {
                updatePaddings();
                setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
            }
            visible = true;
            setVisibility(VISIBLE);
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) ChatObject(org.telegram.messenger.ChatObject) AnimatorSet(android.animation.AnimatorSet) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TLRPC(org.telegram.tgnet.TLRPC) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) Matrix(android.graphics.Matrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) VoIPService(org.telegram.messenger.voip.VoIPService)

Example 19 with ChatActivity

use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method checkLocationString.

private void checkLocationString() {
    if (!(fragment instanceof ChatActivity) || titleTextView == null) {
        return;
    }
    ChatActivity chatActivity = (ChatActivity) fragment;
    long dialogId = chatActivity.getDialogId();
    int currentAccount = chatActivity.getCurrentAccount();
    ArrayList<TLRPC.Message> messages = LocationController.getInstance(currentAccount).locationsCache.get(dialogId);
    if (!firstLocationsLoaded) {
        LocationController.getInstance(currentAccount).loadLiveLocations(dialogId);
        firstLocationsLoaded = true;
    }
    int locationSharingCount = 0;
    TLRPC.User notYouUser = null;
    if (messages != null) {
        long currentUserId = UserConfig.getInstance(currentAccount).getClientUserId();
        int date = ConnectionsManager.getInstance(currentAccount).getCurrentTime();
        for (int a = 0; a < messages.size(); a++) {
            TLRPC.Message message = messages.get(a);
            if (message.media == null) {
                continue;
            }
            if (message.date + message.media.period > date) {
                long fromId = MessageObject.getFromChatId(message);
                if (notYouUser == null && fromId != currentUserId) {
                    notYouUser = MessagesController.getInstance(currentAccount).getUser(fromId);
                }
                locationSharingCount++;
            }
        }
    }
    if (lastLocationSharingCount == locationSharingCount) {
        return;
    }
    lastLocationSharingCount = locationSharingCount;
    String liveLocation = LocaleController.getString("LiveLocationContext", R.string.LiveLocationContext);
    String fullString;
    if (locationSharingCount == 0) {
        fullString = liveLocation;
    } else {
        int otherSharingCount = locationSharingCount - 1;
        if (LocationController.getInstance(currentAccount).isSharingLocation(dialogId)) {
            if (otherSharingCount != 0) {
                if (otherSharingCount == 1 && notYouUser != null) {
                    fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.formatString("SharingYouAndOtherName", R.string.SharingYouAndOtherName, UserObject.getFirstName(notYouUser)));
                } else {
                    fullString = String.format("%1$s - %2$s %3$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName), LocaleController.formatPluralString("AndOther", otherSharingCount));
                }
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, LocaleController.getString("ChatYourSelfName", R.string.ChatYourSelfName));
            }
        } else {
            if (otherSharingCount != 0) {
                fullString = String.format("%1$s - %2$s %3$s", liveLocation, UserObject.getFirstName(notYouUser), LocaleController.formatPluralString("AndOther", otherSharingCount));
            } else {
                fullString = String.format("%1$s - %2$s", liveLocation, UserObject.getFirstName(notYouUser));
            }
        }
    }
    if (fullString.equals(lastString)) {
        return;
    }
    lastString = fullString;
    int start = fullString.indexOf(liveLocation);
    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
    for (int i = 0; i < 2; i++) {
        TextView textView = i == 0 ? titleTextView.getTextView() : titleTextView.getNextTextView();
        if (textView == null) {
            continue;
        }
        textView.setEllipsize(TextUtils.TruncateAt.END);
    }
    if (start >= 0) {
        TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, getThemedColor(Theme.key_inappPlayerPerformer));
        stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    }
    titleTextView.setText(stringBuilder, false);
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 20 with ChatActivity

use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.

the class FragmentContextView method checkLiveLocation.

private void checkLiveLocation(boolean create) {
    View fragmentView = fragment.getFragmentView();
    if (!create && fragmentView != null) {
        if (fragmentView.getParent() == null || ((View) fragmentView.getParent()).getVisibility() != VISIBLE) {
            create = true;
        }
    }
    boolean show;
    if (fragment instanceof DialogsActivity) {
        show = LocationController.getLocationsCount() != 0;
    } else {
        show = LocationController.getInstance(fragment.getCurrentAccount()).isSharingLocation(((ChatActivity) fragment).getDialogId());
    }
    if (!show) {
        lastLocationSharingCount = -1;
        AndroidUtilities.cancelRunOnUIThread(checkLocationRunnable);
        if (visible) {
            visible = false;
            if (create) {
                if (getVisibility() != GONE) {
                    setVisibility(GONE);
                }
                setTopPadding(0);
            } else {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", 0));
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            setVisibility(GONE);
                            animatorSet = null;
                        }
                    }
                });
                animatorSet.start();
            }
        }
    } else {
        updateStyle(2);
        playButton.setImageDrawable(new ShareLocationDrawable(getContext(), 1));
        if (create && topPadding == 0) {
            setTopPadding(AndroidUtilities.dp2(getStyleHeight()));
        }
        if (!visible) {
            if (!create) {
                if (animatorSet != null) {
                    animatorSet.cancel();
                    animatorSet = null;
                }
                animatorSet = new AnimatorSet();
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, "topPadding", AndroidUtilities.dp2(getStyleHeight())));
                animatorSet.setDuration(200);
                animatorSet.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (animatorSet != null && animatorSet.equals(animation)) {
                            animatorSet = null;
                        }
                    }
                });
                animatorSet.start();
            }
            visible = true;
            setVisibility(VISIBLE);
        }
        if (fragment instanceof DialogsActivity) {
            String liveLocation = LocaleController.getString("LiveLocationContext", R.string.LiveLocationContext);
            String param;
            String str;
            ArrayList<LocationController.SharingLocationInfo> infos = new ArrayList<>();
            for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
                infos.addAll(LocationController.getInstance(a).sharingLocationsUI);
            }
            if (infos.size() == 1) {
                LocationController.SharingLocationInfo info = infos.get(0);
                long dialogId = info.messageObject.getDialogId();
                if (DialogObject.isUserDialog(dialogId)) {
                    TLRPC.User user = MessagesController.getInstance(info.messageObject.currentAccount).getUser(dialogId);
                    param = UserObject.getFirstName(user);
                    str = LocaleController.getString("AttachLiveLocationIsSharing", R.string.AttachLiveLocationIsSharing);
                } else {
                    TLRPC.Chat chat = MessagesController.getInstance(info.messageObject.currentAccount).getChat(-dialogId);
                    if (chat != null) {
                        param = chat.title;
                    } else {
                        param = "";
                    }
                    str = LocaleController.getString("AttachLiveLocationIsSharingChat", R.string.AttachLiveLocationIsSharingChat);
                }
            } else {
                param = LocaleController.formatPluralString("Chats", infos.size());
                str = LocaleController.getString("AttachLiveLocationIsSharingChats", R.string.AttachLiveLocationIsSharingChats);
            }
            String fullString = String.format(str, liveLocation, param);
            int start = fullString.indexOf(liveLocation);
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder(fullString);
            for (int i = 0; i < 2; i++) {
                TextView textView = i == 0 ? titleTextView.getTextView() : titleTextView.getNextTextView();
                if (textView == null) {
                    continue;
                }
                textView.setEllipsize(TextUtils.TruncateAt.END);
            }
            TypefaceSpan span = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, getThemedColor(Theme.key_inappPlayerPerformer));
            stringBuilder.setSpan(span, start, start + liveLocation.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            titleTextView.setText(stringBuilder, false);
        } else {
            checkLocationRunnable.run();
            checkLocationString();
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) LocationController(org.telegram.messenger.LocationController) DialogsActivity(org.telegram.ui.DialogsActivity) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

ChatActivity (org.telegram.ui.ChatActivity)41 Paint (android.graphics.Paint)22 TLRPC (org.telegram.tgnet.TLRPC)21 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 Animator (android.animation.Animator)12 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 View (android.view.View)12 TextPaint (android.text.TextPaint)11 AnimatorSet (android.animation.AnimatorSet)10 ObjectAnimator (android.animation.ObjectAnimator)10 ImageView (android.widget.ImageView)10 MessageObject (org.telegram.messenger.MessageObject)10 Bundle (android.os.Bundle)9 ChatObject (org.telegram.messenger.ChatObject)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)8 ValueAnimator (android.animation.ValueAnimator)7 SuppressLint (android.annotation.SuppressLint)7 FrameLayout (android.widget.FrameLayout)6