Search in sources :

Example 6 with MessagesController

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

the class ReactedHeaderView method onAttachedToWindow.

@Override
protected void onAttachedToWindow() {
    super.onAttachedToWindow();
    if (!isLoaded) {
        MessagesController ctrl = MessagesController.getInstance(currentAccount);
        TLRPC.Chat chat = ctrl.getChat(message.getChatId());
        TLRPC.ChatFull chatInfo = ctrl.getChatFull(message.getChatId());
        boolean showSeen = chat != null && message.isOutOwner() && message.isSent() && !message.isEditing() && !message.isSending() && !message.isSendError() && !message.isContentUnread() && !message.isUnread() && (ConnectionsManager.getInstance(currentAccount).getCurrentTime() - message.messageOwner.date < 7 * 86400) && (ChatObject.isMegagroup(chat) || !ChatObject.isChannel(chat)) && chatInfo != null && chatInfo.participants_count <= MessagesController.getInstance(currentAccount).chatReadMarkSizeThreshold && !(message.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByRequest);
        if (showSeen) {
            TLRPC.TL_messages_getMessageReadParticipants req = new TLRPC.TL_messages_getMessageReadParticipants();
            req.msg_id = message.getId();
            req.peer = MessagesController.getInstance(currentAccount).getInputPeer(message.getDialogId());
            long fromId = message.messageOwner.from_id != null ? message.messageOwner.from_id.user_id : 0;
            ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
                if (response instanceof TLRPC.Vector) {
                    List<Long> usersToRequest = new ArrayList<>();
                    TLRPC.Vector v = (TLRPC.Vector) response;
                    for (Object obj : v.objects) {
                        if (obj instanceof Long) {
                            long l = (long) obj;
                            if (fromId != l)
                                usersToRequest.add(l);
                        }
                    }
                    usersToRequest.add(fromId);
                    List<TLRPC.User> usersRes = new ArrayList<>();
                    Runnable callback = () -> {
                        seenUsers.addAll(usersRes);
                        for (TLRPC.User u : usersRes) {
                            boolean hasSame = false;
                            for (int i = 0; i < users.size(); i++) {
                                if (users.get(i).id == u.id) {
                                    hasSame = true;
                                    break;
                                }
                            }
                            if (!hasSame) {
                                users.add(u);
                            }
                        }
                        if (seenCallback != null)
                            seenCallback.accept(usersRes);
                        loadReactions();
                    };
                    if (ChatObject.isChannel(chat)) {
                        TLRPC.TL_channels_getParticipants usersReq = new TLRPC.TL_channels_getParticipants();
                        usersReq.limit = MessagesController.getInstance(currentAccount).chatReadMarkSizeThreshold;
                        usersReq.offset = 0;
                        usersReq.filter = new TLRPC.TL_channelParticipantsRecent();
                        usersReq.channel = MessagesController.getInstance(currentAccount).getInputChannel(chat.id);
                        ConnectionsManager.getInstance(currentAccount).sendRequest(usersReq, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
                            if (response1 != null) {
                                TLRPC.TL_channels_channelParticipants users = (TLRPC.TL_channels_channelParticipants) response1;
                                for (int i = 0; i < users.users.size(); i++) {
                                    TLRPC.User user = users.users.get(i);
                                    MessagesController.getInstance(currentAccount).putUser(user, false);
                                    if (!user.self && usersToRequest.contains(user.id))
                                        usersRes.add(user);
                                }
                            }
                            callback.run();
                        }));
                    } else {
                        TLRPC.TL_messages_getFullChat usersReq = new TLRPC.TL_messages_getFullChat();
                        usersReq.chat_id = chat.id;
                        ConnectionsManager.getInstance(currentAccount).sendRequest(usersReq, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
                            if (response1 != null) {
                                TLRPC.TL_messages_chatFull chatFull = (TLRPC.TL_messages_chatFull) response1;
                                for (int i = 0; i < chatFull.users.size(); i++) {
                                    TLRPC.User user = chatFull.users.get(i);
                                    MessagesController.getInstance(currentAccount).putUser(user, false);
                                    if (!user.self && usersToRequest.contains(user.id))
                                        usersRes.add(user);
                                }
                            }
                            callback.run();
                        }));
                    }
                }
            }, ConnectionsManager.RequestFlagInvokeAfter);
        } else
            loadReactions();
    }
}
Also used : MessagesController(org.telegram.messenger.MessagesController) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) MessageObject(org.telegram.messenger.MessageObject) ChatObject(org.telegram.messenger.ChatObject)

Example 7 with MessagesController

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

the class ReactedHeaderView method loadReactions.

private void loadReactions() {
    MessagesController ctrl = MessagesController.getInstance(currentAccount);
    TLRPC.TL_messages_getMessageReactionsList getList = new TLRPC.TL_messages_getMessageReactionsList();
    getList.peer = ctrl.getInputPeer(dialogId);
    getList.id = message.getId();
    getList.limit = 3;
    ConnectionsManager.getInstance(currentAccount).sendRequest(getList, (response, error) -> {
        if (response instanceof TLRPC.TL_messages_messageReactionsList) {
            TLRPC.TL_messages_messageReactionsList list = (TLRPC.TL_messages_messageReactionsList) response;
            int c = list.count;
            post(() -> {
                String str;
                if (seenUsers.isEmpty() || seenUsers.size() < c) {
                    str = LocaleController.formatPluralString("ReactionsCount", c);
                } else {
                    String countStr;
                    if (c == seenUsers.size()) {
                        countStr = String.valueOf(c);
                    } else {
                        countStr = c + "/" + seenUsers.size();
                    }
                    str = String.format(LocaleController.getPluralString("Reacted", c), countStr);
                }
                titleView.setText(str);
                boolean showIcon = true;
                if (message.messageOwner.reactions != null && message.messageOwner.reactions.results.size() == 1 && !list.reactions.isEmpty()) {
                    for (TLRPC.TL_availableReaction r : MediaDataController.getInstance(currentAccount).getReactionsList()) {
                        if (r.reaction.equals(list.reactions.get(0).reaction)) {
                            reactView.setImage(ImageLocation.getForDocument(r.static_icon), "50_50", "webp", null, r);
                            reactView.setVisibility(VISIBLE);
                            reactView.setAlpha(0);
                            reactView.animate().alpha(1f).start();
                            iconView.setVisibility(GONE);
                            showIcon = false;
                            break;
                        }
                    }
                }
                if (showIcon) {
                    iconView.setVisibility(VISIBLE);
                    iconView.setAlpha(0f);
                    iconView.animate().alpha(1f).start();
                }
                for (TLRPC.User u : list.users) {
                    if (message.messageOwner.from_id != null && u.id != message.messageOwner.from_id.user_id) {
                        boolean hasSame = false;
                        for (int i = 0; i < users.size(); i++) {
                            if (users.get(i).id == u.id) {
                                hasSame = true;
                                break;
                            }
                        }
                        if (!hasSame) {
                            users.add(u);
                        }
                    }
                }
                updateView();
            });
        }
    }, ConnectionsManager.RequestFlagInvokeAfter);
}
Also used : MessagesController(org.telegram.messenger.MessagesController) TLRPC(org.telegram.tgnet.TLRPC)

Example 8 with MessagesController

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

the class DialogsActivity method loadDialogs.

public static void loadDialogs(AccountInstance accountInstance) {
    int currentAccount = accountInstance.getCurrentAccount();
    if (!dialogsLoaded[currentAccount]) {
        MessagesController messagesController = accountInstance.getMessagesController();
        messagesController.loadGlobalNotificationsSettings();
        messagesController.loadDialogs(0, 0, 100, true);
        messagesController.loadHintDialogs();
        messagesController.loadUserInfo(accountInstance.getUserConfig().getCurrentUser(), false, 0);
        accountInstance.getContactsController().checkInviteText();
        accountInstance.getMediaDataController().loadRecents(MediaDataController.TYPE_FAVE, false, true, false);
        accountInstance.getMediaDataController().loadRecents(MediaDataController.TYPE_GREETINGS, false, true, false);
        accountInstance.getMediaDataController().checkFeaturedStickers();
        accountInstance.getMediaDataController().checkReactions();
        for (String emoji : messagesController.diceEmojies) {
            accountInstance.getMediaDataController().loadStickersByEmojiOrName(emoji, true, true);
        }
        dialogsLoaded[currentAccount] = true;
    }
}
Also used : MessagesController(org.telegram.messenger.MessagesController) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 9 with MessagesController

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

the class ChatActivity method updatePinnedMessageView.

private void updatePinnedMessageView(boolean animated, int animateToNext) {
    if (pinnedMessageView == null || chatMode != 0 || inMenuMode) {
        return;
    }
    int pinned_msg_id;
    boolean changed = false;
    MessageObject pinnedMessageObject;
    if (isThreadChat()) {
        if (!threadMessageVisible) {
            pinnedMessageObject = threadMessageObject;
            pinned_msg_id = threadMessageId;
        } else {
            pinnedMessageObject = null;
            pinned_msg_id = 0;
        }
    } else if (currentPinnedMessageId != 0 && !pinnedMessageIds.isEmpty()) {
        pinnedMessageObject = pinnedMessageObjects.get(currentPinnedMessageId);
        if (pinnedMessageObject == null) {
            pinnedMessageObject = messagesDict[0].get(currentPinnedMessageId);
        }
        pinned_msg_id = currentPinnedMessageId;
    } else {
        pinnedMessageObject = null;
        pinned_msg_id = 0;
    }
    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
    if (threadMessageObject == null && (chatInfo == null && userInfo == null || pinned_msg_id == 0 || !pinnedMessageIds.isEmpty() && pinnedMessageIds.get(0) == preferences.getInt("pin_" + dialog_id, 0)) || reportType >= 0 || actionBar != null && (actionBar.isActionModeShowed() || actionBar.isSearchFieldVisible())) {
        changed = hidePinnedMessageView(animated);
    } else {
        updatePinnedListButton(animated);
        if (pinnedMessageObject != null) {
            if (pinnedMessageView.getTag() != null) {
                pinnedMessageView.setTag(null);
                changed = true;
                if (pinnedMessageViewAnimator != null) {
                    pinnedMessageViewAnimator.cancel();
                    pinnedMessageViewAnimator = null;
                }
                if (animated) {
                    ValueAnimator animator = ValueAnimator.ofFloat(pinnedMessageEnterOffset, 0);
                    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                        int position = -1;

                        @Override
                        public void onAnimationUpdate(ValueAnimator animation) {
                            pinnedMessageEnterOffset = (float) animation.getAnimatedValue();
                            invalidateChatListViewTopPadding();
                            invalidateMessagesVisiblePart();
                        }
                    });
                    pinnedMessageView.setVisibility(View.VISIBLE);
                    pinnedMessageViewAnimator = new AnimatorSet();
                    pinnedMessageViewAnimator.playTogether(animator);
                    pinnedMessageViewAnimator.setDuration(200);
                    pinnedMessageViewAnimator.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
                                pinnedMessageViewAnimator = null;
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            if (pinnedMessageViewAnimator != null && pinnedMessageViewAnimator.equals(animation)) {
                                pinnedMessageViewAnimator = null;
                            }
                        }
                    });
                    pinnedMessageViewAnimator.start();
                } else {
                    pinnedMessageEnterOffset = 0;
                    invalidateChatListViewTopPadding();
                    invalidateMessagesVisiblePart();
                    pinnedMessageView.setVisibility(View.VISIBLE);
                }
            }
            for (int a = 0; a < pinnedNextAnimation.length; a++) {
                if (pinnedNextAnimation[a] != null) {
                    pinnedNextAnimation[a].cancel();
                    pinnedNextAnimation[a] = null;
                }
            }
            setPinnedTextTranslationX = false;
            SimpleTextView nameTextView = pinnedNameTextView[animateToNext != 0 && loadedPinnedMessagesCount == 2 ? 1 : 0];
            SimpleTextView messageTextView = pinnedMessageTextView[animateToNext != 0 ? 1 : 0];
            FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) pinnedNameTextView[0].getLayoutParams();
            FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) pinnedNameTextView[1].getLayoutParams();
            FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) pinnedCounterTextView.getLayoutParams();
            FrameLayout.LayoutParams layoutParams4 = (FrameLayout.LayoutParams) pinnedMessageTextView[0].getLayoutParams();
            FrameLayout.LayoutParams layoutParams5 = (FrameLayout.LayoutParams) pinnedMessageTextView[1].getLayoutParams();
            int cacheType = 1;
            int size = 0;
            TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs2, AndroidUtilities.dp(320));
            TLRPC.PhotoSize thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs2, AndroidUtilities.dp(40));
            TLObject photoSizeObject = pinnedMessageObject.photoThumbsObject2;
            if (photoSize == null) {
                if (pinnedMessageObject.mediaExists) {
                    photoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs, AndroidUtilities.getPhotoSize());
                    if (photoSize != null) {
                        size = photoSize.size;
                    }
                    cacheType = 0;
                } else {
                    photoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs, AndroidUtilities.dp(320));
                }
                thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(pinnedMessageObject.photoThumbs, AndroidUtilities.dp(40));
                photoSizeObject = pinnedMessageObject.photoThumbsObject;
            }
            if (photoSize == thumbPhotoSize) {
                thumbPhotoSize = null;
            }
            boolean noImage;
            int prevMargin = layoutParams1.leftMargin;
            if (noImage = (photoSize == null || photoSize instanceof TLRPC.TL_photoSizeEmpty || photoSize.location instanceof TLRPC.TL_fileLocationUnavailable || pinnedMessageObject.isAnyKindOfSticker() || pinnedMessageObject.isSecretMedia())) {
                pinnedImageLocation = null;
                pinnedImageLocationObject = null;
                if (animateToNext == 0) {
                    pinnedMessageImageView[0].setImageBitmap(null);
                    pinnedMessageImageView[0].setVisibility(View.INVISIBLE);
                }
                layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = layoutParams4.leftMargin = layoutParams5.leftMargin = AndroidUtilities.dp(18);
            } else {
                if (pinnedMessageObject.isRoundVideo()) {
                    pinnedMessageImageView[1].setRoundRadius(AndroidUtilities.dp(16));
                } else {
                    pinnedMessageImageView[1].setRoundRadius(AndroidUtilities.dp(2));
                }
                pinnedImageSize = size;
                pinnedImageCacheType = cacheType;
                pinnedImageLocation = photoSize;
                pinnedImageThumbLocation = thumbPhotoSize;
                pinnedImageLocationObject = photoSizeObject;
                pinnedMessageImageView[1].setImage(ImageLocation.getForObject(pinnedImageLocation, photoSizeObject), "50_50", ImageLocation.getForObject(thumbPhotoSize, photoSizeObject), "50_50_b", null, size, cacheType, pinnedMessageObject);
                pinnedMessageImageView[1].setVisibility(View.VISIBLE);
                if (animateToNext != 0) {
                    pinnedMessageImageView[1].setAlpha(0.0f);
                }
                layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = layoutParams4.leftMargin = layoutParams5.leftMargin = AndroidUtilities.dp(55);
            }
            pinnedNameTextView[0].setLayoutParams(layoutParams1);
            pinnedNameTextView[1].setLayoutParams(layoutParams2);
            pinnedCounterTextView.setLayoutParams(layoutParams3);
            pinnedMessageTextView[0].setLayoutParams(layoutParams4);
            pinnedMessageTextView[1].setLayoutParams(layoutParams5);
            if (threadMessageId != 0) {
                MessagesController messagesController = getMessagesController();
                TLRPC.MessageFwdHeader fwd_from = threadMessageObject.messageOwner.fwd_from;
                TLRPC.User user = null;
                TLRPC.Chat chat = null;
                if (fwd_from != null && fwd_from.saved_from_peer != null) {
                    if (fwd_from.saved_from_peer.user_id != 0) {
                        if (fwd_from.from_id instanceof TLRPC.TL_peerUser) {
                            user = messagesController.getUser(fwd_from.from_id.user_id);
                        } else {
                            user = messagesController.getUser(fwd_from.saved_from_peer.user_id);
                        }
                    } else if (fwd_from.saved_from_peer.channel_id != 0) {
                        if (threadMessageObject.isSavedFromMegagroup() && fwd_from.from_id instanceof TLRPC.TL_peerUser) {
                            user = messagesController.getUser(fwd_from.from_id.user_id);
                        } else {
                            chat = messagesController.getChat(fwd_from.saved_from_peer.channel_id);
                        }
                    } else if (fwd_from.saved_from_peer.chat_id != 0) {
                        if (fwd_from.from_id instanceof TLRPC.TL_peerUser) {
                            user = messagesController.getUser(fwd_from.from_id.user_id);
                        } else if (fwd_from.from_id instanceof TLRPC.TL_peerChat) {
                            chat = messagesController.getChat(fwd_from.from_id.chat_id);
                        } else if (fwd_from.from_id instanceof TLRPC.TL_peerChannel) {
                            chat = messagesController.getChat(fwd_from.from_id.channel_id);
                        } else {
                            chat = messagesController.getChat(fwd_from.saved_from_peer.chat_id);
                        }
                    }
                } else if (threadMessageObject.isFromUser()) {
                    user = messagesController.getUser(threadMessageObject.messageOwner.from_id.user_id);
                } else if (threadMessageObject.messageOwner.from_id instanceof TLRPC.TL_peerChannel) {
                    chat = messagesController.getChat(threadMessageObject.messageOwner.from_id.channel_id);
                } else if (threadMessageObject.messageOwner.from_id instanceof TLRPC.TL_peerChat) {
                    chat = messagesController.getChat(threadMessageObject.messageOwner.from_id.chat_id);
                } else if (threadMessageObject.messageOwner.post) {
                    chat = messagesController.getChat(threadMessageObject.messageOwner.peer_id.channel_id);
                }
                if (user != null) {
                    nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
                } else if (chat != null) {
                    nameTextView.setText(chat.title);
                }
            } else {
                if (currentPinnedMessageIndex[0] == 0 || loadedPinnedMessagesCount != 2) {
                    nameTextView.setText(LocaleController.getString("PinnedMessage", R.string.PinnedMessage));
                } else {
                    nameTextView.setText(LocaleController.getString("PreviousPinnedMessage", R.string.PreviousPinnedMessage));
                }
                if (currentPinnedMessageIndex[0] != 0) {
                    int total = getPinnedMessagesCount();
                    pinnedCounterTextView.setNumber(Math.min(total - 1, Math.max(1, total - currentPinnedMessageIndex[0])), animated && pinnedCounterTextView.getTag() == null);
                }
            }
            CharSequence pinnedText = null;
            if (pinnedMessageObject.type == 14) {
                pinnedText = String.format("%s - %s", pinnedMessageObject.getMusicAuthor(), pinnedMessageObject.getMusicTitle());
            } else if (pinnedMessageObject.type == MessageObject.TYPE_POLL) {
                TLRPC.TL_messageMediaPoll poll = (TLRPC.TL_messageMediaPoll) pinnedMessageObject.messageOwner.media;
                String mess = poll.poll.question;
                if (mess.length() > 150) {
                    mess = mess.substring(0, 150);
                }
                mess = mess.replace('\n', ' ');
                pinnedText = mess;
            } else if (pinnedMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                pinnedText = Emoji.replaceEmoji(pinnedMessageObject.messageOwner.media.game.title, messageTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
            } else if (!TextUtils.isEmpty(pinnedMessageObject.caption)) {
                String mess = pinnedMessageObject.caption.toString();
                if (mess.length() > 150) {
                    mess = mess.substring(0, 150);
                }
                mess = mess.replace('\n', ' ');
                pinnedText = Emoji.replaceEmoji(mess, messageTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
            } else if (pinnedMessageObject.messageText != null) {
                String mess = pinnedMessageObject.messageText.toString();
                if (mess.length() > 150) {
                    mess = mess.substring(0, 150);
                }
                mess = mess.replace('\n', ' ');
                pinnedText = Emoji.replaceEmoji(mess, messageTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
            }
            if (pinnedText != null) {
                if (pinnedText instanceof Spannable)
                    MediaDataController.addTextStyleRuns(pinnedMessageObject, (Spannable) pinnedText);
                messageTextView.setText(pinnedText);
            }
            if (animateToNext != 0) {
                pinnedNextAnimation[0] = new AnimatorSet();
                pinnedNextAnimation[1] = new AnimatorSet();
                ArrayList<Animator> animators = new ArrayList<>();
                ArrayList<Animator> animators2 = new ArrayList<>();
                messageTextView.setVisibility(View.VISIBLE);
                nameTextView.setVisibility(View.VISIBLE);
                if (loadedPinnedMessagesCount == 2 || currentPinnedMessageIndex[0] == 0) {
                    if (pinnedCounterTextView.getTag() == null) {
                        animators.add(ObjectAnimator.ofFloat(pinnedCounterTextView, View.ALPHA, 1.0f, 0.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedCounterTextView, View.TRANSLATION_Y, 0.0f, -AndroidUtilities.dp(4)));
                        pinnedCounterTextView.setTag(1);
                    }
                } else {
                    if (pinnedCounterTextView.getTag() != null) {
                        pinnedCounterTextView.setVisibility(View.VISIBLE);
                        pinnedCounterTextView.setAlpha(0.0f);
                        animators.add(ObjectAnimator.ofFloat(pinnedCounterTextView, View.ALPHA, 0.0f, 1.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedCounterTextView, View.TRANSLATION_Y, -AndroidUtilities.dp(4), 0));
                        pinnedCounterTextView.setTag(null);
                    }
                }
                if (loadedPinnedMessagesCount == 2 && !TextUtils.equals(nameTextView.getText(), pinnedNameTextView[0].getText())) {
                    nameTextView.setAlpha(0);
                    animators.add(ObjectAnimator.ofFloat(nameTextView, View.ALPHA, 0.0f, 1.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedNameTextView[0], View.ALPHA, 1.0f, 0.0f));
                    animators.add(ObjectAnimator.ofFloat(nameTextView, View.TRANSLATION_Y, AndroidUtilities.dp(animateToNext == 2 ? 4 : -4), 0.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedNameTextView[0], View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(animateToNext == 2 ? -4 : 4)));
                } else {
                    if (nameTextView != pinnedNameTextView[0]) {
                        nameTextView.setAlpha(1.0f);
                        pinnedNameTextView[0].setAlpha(0.0f);
                        nameTextView.setTranslationY(0.0f);
                        pinnedNameTextView[0].setTranslationY(0.0f);
                    } else {
                        nameTextView.setAlpha(1.0f);
                        nameTextView.setTranslationY(0.0f);
                        pinnedNameTextView[1].setTranslationY(0.0f);
                        pinnedNameTextView[1].setAlpha(0.0f);
                    }
                }
                boolean animateText;
                if (!TextUtils.equals(messageTextView.getText(), pinnedMessageTextView[0].getText())) {
                    messageTextView.setAlpha(0);
                    animators.add(ObjectAnimator.ofFloat(messageTextView, View.ALPHA, 0.0f, 1.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedMessageTextView[0], View.ALPHA, 1.0f, 0.0f));
                    if (animateText = forceScrollToFirst && loadedPinnedMessagesCount > 5) {
                        animators2.add(ObjectAnimator.ofFloat(messageTextView, View.TRANSLATION_Y, AndroidUtilities.dp(4), AndroidUtilities.dp(-2)));
                    } else {
                        animators.add(ObjectAnimator.ofFloat(messageTextView, View.TRANSLATION_Y, AndroidUtilities.dp(animateToNext == 2 ? 4 : -4), 0.0f));
                    }
                    animators.add(ObjectAnimator.ofFloat(pinnedMessageTextView[0], View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(animateToNext == 2 ? -4 : 4)));
                } else {
                    animateText = false;
                    messageTextView.setAlpha(1.0f);
                    pinnedMessageTextView[0].setAlpha(0.0f);
                    messageTextView.setTranslationY(0.0f);
                    pinnedMessageTextView[0].setTranslationY(0.0f);
                }
                BackupImageView animateImage;
                if (layoutParams1.leftMargin != prevMargin) {
                    animateImage = null;
                    setPinnedTextTranslationX = true;
                    int diff = prevMargin - layoutParams1.leftMargin;
                    animators.add(ObjectAnimator.ofFloat(pinnedMessageTextView[0], View.TRANSLATION_X, diff, 0.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedMessageTextView[1], View.TRANSLATION_X, diff, 0.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedNameTextView[0], View.TRANSLATION_X, diff, 0.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedNameTextView[1], View.TRANSLATION_X, diff, 0.0f));
                    animators.add(ObjectAnimator.ofFloat(pinnedCounterTextView, View.TRANSLATION_X, pinnedCounterTextViewX + diff, pinnedCounterTextViewX));
                    if (diff > 0) {
                        pinnedMessageImageView[0].setAlpha(1f);
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[0], View.ALPHA, 1.0f, 0.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[0], View.SCALE_X, 1.0f, 0.7f));
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[0], View.SCALE_Y, 1.0f, 0.7f));
                    } else {
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.ALPHA, 0.0f, 1.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.SCALE_X, 0.7f, 1.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.SCALE_Y, 0.7f, 1.0f));
                    }
                } else {
                    setPinnedTextTranslationX = false;
                    messageTextView.setTranslationX(0);
                    pinnedMessageTextView[0].setTranslationX(0);
                    nameTextView.setTranslationX(0);
                    pinnedNameTextView[0].setTranslationX(0);
                    pinnedCounterTextView.setTranslationX(pinnedCounterTextViewX);
                    pinnedMessageImageView[1].setAlpha(1.0f);
                    if (!noImage) {
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.ALPHA, 0.0f, 1.0f));
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[0], View.ALPHA, 1.0f, 0.0f));
                        if (forceScrollToFirst && loadedPinnedMessagesCount > 5) {
                            animateImage = pinnedMessageImageView[1];
                            animators2.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.TRANSLATION_Y, AndroidUtilities.dp(3), AndroidUtilities.dp(-2)));
                        } else {
                            animateImage = null;
                            animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[1], View.TRANSLATION_Y, AndroidUtilities.dp(animateToNext == 2 ? 3 : -3), 0.0f));
                        }
                        animators.add(ObjectAnimator.ofFloat(pinnedMessageImageView[0], View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(animateToNext == 2 ? -3 : 3)));
                    } else {
                        animateImage = null;
                    }
                }
                pinnedNextAnimation[1].addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        pinnedNextAnimation[1] = null;
                        pinnedMessageImageView[1].setTranslationY(0);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (animation.equals(pinnedNextAnimation[1])) {
                            if (animateText || animateImage != null) {
                                pinnedNextAnimation[1] = new AnimatorSet();
                                pinnedNextAnimation[1].setInterpolator(CubicBezierInterpolator.EASE_OUT);
                                pinnedNextAnimation[1].setDuration(180);
                                ArrayList<Animator> animators1 = new ArrayList<>();
                                if (animateText) {
                                    animators1.add(ObjectAnimator.ofFloat(messageTextView, View.TRANSLATION_Y, 0.0f));
                                }
                                if (animateImage != null) {
                                    animators1.add(ObjectAnimator.ofFloat(animateImage, View.TRANSLATION_Y, 0.0f));
                                }
                                pinnedNextAnimation[1].addListener(new AnimatorListenerAdapter() {

                                    @Override
                                    public void onAnimationEnd(Animator animation) {
                                        if (animateText) {
                                            messageTextView.setTranslationY(0.0f);
                                        }
                                        if (animateImage != null) {
                                            animateImage.setTranslationY(0.0f);
                                        }
                                        pinnedNextAnimation[1] = null;
                                    }
                                });
                                pinnedNextAnimation[1].playTogether(animators1);
                                pinnedNextAnimation[1].start();
                            } else {
                                pinnedNextAnimation[1] = null;
                            }
                        }
                    }
                });
                pinnedNextAnimation[1].setDuration(180);
                if (forceScrollToFirst && loadedPinnedMessagesCount > 5) {
                    pinnedNextAnimation[1].setInterpolator(CubicBezierInterpolator.EASE_OUT);
                }
                pinnedNextAnimation[1].playTogether(animators2);
                pinnedNextAnimation[0].playTogether(animators);
                pinnedNextAnimation[0].addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (pinnedCounterTextView.getTag() != null) {
                            pinnedCounterTextView.setVisibility(View.INVISIBLE);
                            int total = getPinnedMessagesCount();
                            pinnedCounterTextView.setNumber(Math.min(total - 1, Math.max(1, total - currentPinnedMessageIndex[0])), false);
                        } else {
                            pinnedCounterTextView.setAlpha(1.0f);
                        }
                        pinnedCounterTextView.setTranslationY(0.0f);
                        pinnedMessageTextView[0].setTranslationX(0);
                        pinnedMessageTextView[1].setTranslationX(0);
                        pinnedCounterTextView.setTranslationX(pinnedCounterTextViewX);
                        if (!animateText) {
                            messageTextView.setTranslationY(0.0f);
                        }
                        nameTextView.setTranslationY(0.0f);
                        pinnedNameTextView[0].setTranslationX(0);
                        pinnedNameTextView[1].setTranslationX(0);
                        pinnedMessageImageView[1].setAlpha(1.0f);
                        pinnedMessageImageView[1].setScaleX(1f);
                        pinnedMessageImageView[1].setScaleY(1f);
                        pinnedMessageImageView[0].setAlpha(1.0f);
                        pinnedMessageImageView[0].setScaleX(1f);
                        pinnedMessageImageView[0].setScaleY(1f);
                        pinnedMessageTextView[1] = pinnedMessageTextView[0];
                        pinnedMessageTextView[0] = messageTextView;
                        pinnedMessageTextView[1].setVisibility(View.INVISIBLE);
                        if (nameTextView != pinnedNameTextView[0]) {
                            pinnedNameTextView[1] = pinnedNameTextView[0];
                            pinnedNameTextView[0] = nameTextView;
                            pinnedNameTextView[1].setVisibility(View.INVISIBLE);
                        }
                        if (noImage) {
                            pinnedMessageImageView[1].setImageBitmap(null);
                            pinnedMessageImageView[1].setVisibility(View.INVISIBLE);
                        }
                        BackupImageView backupImageView = pinnedMessageImageView[1];
                        pinnedMessageImageView[1] = pinnedMessageImageView[0];
                        pinnedMessageImageView[0] = backupImageView;
                        pinnedMessageImageView[1].setAlpha(1.0f);
                        pinnedMessageImageView[1].setScaleX(1f);
                        pinnedMessageImageView[1].setScaleY(1f);
                        pinnedMessageImageView[1].setVisibility(View.INVISIBLE);
                        pinnedNextAnimation[0] = null;
                        setPinnedTextTranslationX = false;
                    }
                });
                pinnedNextAnimation[0].setDuration(180);
                if (!setPinnedTextTranslationX) {
                    pinnedNextAnimation[0].start();
                    pinnedNextAnimation[1].start();
                }
            } else {
                if (loadedPinnedMessagesCount == 2 || currentPinnedMessageIndex[0] == 0) {
                    if (pinnedCounterTextView.getTag() == null) {
                        pinnedCounterTextView.setAlpha(0.0f);
                        pinnedCounterTextView.setVisibility(View.INVISIBLE);
                        pinnedCounterTextView.setTag(1);
                    }
                } else {
                    if (pinnedCounterTextView.getTag() != null) {
                        pinnedCounterTextView.setVisibility(View.VISIBLE);
                        pinnedCounterTextView.setAlpha(1.0f);
                        pinnedCounterTextView.setTag(null);
                    }
                }
                pinnedCounterTextView.setTranslationY(0.0f);
                pinnedCounterTextView.setTranslationX(pinnedCounterTextViewX);
                pinnedCounterTextView.setAlpha(loadedPinnedMessagesCount == 2 || currentPinnedMessageIndex[0] == 0 ? 0.0f : 1.0f);
                messageTextView.setVisibility(View.VISIBLE);
                messageTextView.setAlpha(1.0f);
                messageTextView.setTranslationX(0);
                messageTextView.setTranslationY(0);
                nameTextView.setVisibility(View.VISIBLE);
                nameTextView.setAlpha(1.0f);
                nameTextView.setTranslationX(0);
                nameTextView.setTranslationY(0);
                pinnedMessageTextView[1].setVisibility(View.INVISIBLE);
                pinnedMessageTextView[1].setTranslationX(0);
                pinnedMessageTextView[1].setTranslationY(0);
                pinnedNameTextView[1].setVisibility(View.INVISIBLE);
                pinnedNameTextView[1].setTranslationX(0);
                pinnedNameTextView[1].setTranslationY(0);
                pinnedMessageImageView[0].setVisibility(View.INVISIBLE);
                BackupImageView backupImageView = pinnedMessageImageView[1];
                pinnedMessageImageView[1] = pinnedMessageImageView[0];
                pinnedMessageImageView[0] = backupImageView;
                pinnedMessageImageView[0].setAlpha(1.0f);
                pinnedMessageImageView[0].setScaleX(1f);
                pinnedMessageImageView[0].setScaleY(1f);
                pinnedMessageImageView[0].setTranslationY(0);
                pinnedMessageImageView[1].setAlpha(1.0f);
                pinnedMessageImageView[1].setScaleX(1f);
                pinnedMessageImageView[1].setScaleY(1f);
                pinnedMessageImageView[1].setTranslationY(0);
            }
            if (isThreadChat()) {
                pinnedLineView.set(0, 1, false);
            } else {
                int position = Collections.binarySearch(pinnedMessageIds, currentPinnedMessageId, Comparator.reverseOrder());
                pinnedLineView.set(pinnedMessageIds.size() - 1 - position, pinnedMessageIds.size(), animated);
            }
        } else {
            pinnedCounterTextView.setVisibility(loadedPinnedMessagesCount == 2 || currentPinnedMessageIndex[0] == 0 ? View.INVISIBLE : View.VISIBLE);
            pinnedCounterTextView.setAlpha(loadedPinnedMessagesCount == 2 || currentPinnedMessageIndex[0] == 0 ? 0.0f : 1.0f);
            pinnedImageLocation = null;
            pinnedImageLocationObject = null;
            changed = hidePinnedMessageView(animated);
            if (loadingPinnedMessages.indexOfKey(pinned_msg_id) < 0) {
                loadingPinnedMessages.put(pinned_msg_id, true);
                ArrayList<Integer> ids = new ArrayList<>();
                ids.add(pinned_msg_id);
                getMediaDataController().loadPinnedMessages(dialog_id, ChatObject.isChannel(currentChat) ? currentChat.id : 0, ids, true);
            }
        }
    }
    if (changed) {
        checkListViewPaddings();
    }
}
Also used : MessagesController(org.telegram.messenger.MessagesController) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) SpannableString(android.text.SpannableString) ValueAnimator(android.animation.ValueAnimator) TLRPC(org.telegram.tgnet.TLRPC) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) BackupImageView(org.telegram.ui.Components.BackupImageView) SharedPreferences(android.content.SharedPreferences) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) Animator(android.animation.Animator) ChatListItemAnimator(androidx.recyclerview.widget.ChatListItemAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) TLObject(org.telegram.tgnet.TLObject) ChatBlurredFrameLayout(org.telegram.ui.Components.ChatBlurredFrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) FrameLayout(android.widget.FrameLayout) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) MessageObject(org.telegram.messenger.MessageObject) Spannable(android.text.Spannable)

Example 10 with MessagesController

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

the class DialogsActivity method didReceivedNotification.

@SuppressWarnings("unchecked")
@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.dialogsNeedReload) {
        if (viewPages == null || dialogsListFrozen) {
            return;
        }
        MessagesController messagesController = AccountInstance.getInstance(currentAccount).getMessagesController();
        ArrayList<TLRPC.Dialog> dialogs = messagesController.getDialogs(folderId);
        for (int a = 0; a < viewPages.length; a++) {
            if (viewPages[a].getVisibility() != View.VISIBLE) {
                continue;
            }
            int oldItemCount = viewPages[a].dialogsAdapter.getCurrentCount();
            if (viewPages[a].dialogsType == 0 && hasHiddenArchive() && viewPages[a].listView.getChildCount() == 0) {
                LinearLayoutManager layoutManager = (LinearLayoutManager) viewPages[a].listView.getLayoutManager();
                layoutManager.scrollToPositionWithOffset(1, 0);
            }
            if (viewPages[a].dialogsAdapter.isDataSetChanged() || args.length > 0) {
                viewPages[a].dialogsAdapter.updateHasHints();
                int newItemCount = viewPages[a].dialogsAdapter.getItemCount();
                if (newItemCount == 1 && oldItemCount == 1 && viewPages[a].dialogsAdapter.getItemViewType(0) == 5) {
                    if (viewPages[a].dialogsAdapter.lastDialogsEmptyType != viewPages[a].dialogsAdapter.dialogsEmptyType()) {
                        viewPages[a].dialogsAdapter.notifyItemChanged(0);
                    }
                } else {
                    viewPages[a].dialogsAdapter.notifyDataSetChanged();
                    if (newItemCount > oldItemCount && initialDialogsType != 11 && initialDialogsType != 12 && initialDialogsType != 13) {
                        viewPages[a].recyclerItemsEnterAnimator.showItemsAnimated(oldItemCount);
                    }
                }
            } else {
                updateVisibleRows(MessagesController.UPDATE_MASK_NEW_MESSAGE);
                int newItemCount = viewPages[a].dialogsAdapter.getItemCount();
                if (newItemCount > oldItemCount && initialDialogsType != 11 && initialDialogsType != 12 && initialDialogsType != 13) {
                    viewPages[a].recyclerItemsEnterAnimator.showItemsAnimated(oldItemCount);
                }
            }
            try {
                viewPages[a].listView.setEmptyView(folderId == 0 ? viewPages[a].progressView : null);
            } catch (Exception e) {
                FileLog.e(e);
            }
            checkListLoad(viewPages[a]);
        }
        if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE) {
            filterTabsView.checkTabsCounter();
        }
    } else if (id == NotificationCenter.dialogsUnreadCounterChanged) {
        if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE) {
            filterTabsView.notifyTabCounterChanged(Integer.MAX_VALUE);
        }
    } else if (id == NotificationCenter.dialogsUnreadReactionsCounterChanged) {
        updateVisibleRows(0);
    } else if (id == NotificationCenter.emojiLoaded) {
        updateVisibleRows(0);
        if (filterTabsView != null) {
            filterTabsView.getTabsContainer().invalidateViews();
        }
    } else if (id == NotificationCenter.closeSearchByActiveAction) {
        if (actionBar != null) {
            actionBar.closeSearchField();
        }
    } else if (id == NotificationCenter.proxySettingsChanged) {
        updateProxyButton(false);
    } else if (id == NotificationCenter.updateInterfaces) {
        Integer mask = (Integer) args[0];
        updateVisibleRows(mask);
        if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
            filterTabsView.checkTabsCounter();
        }
        if (viewPages != null) {
            for (int a = 0; a < viewPages.length; a++) {
                if ((mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
                    viewPages[a].dialogsAdapter.sortOnlineContacts(true);
                }
            }
        }
    } else if (id == NotificationCenter.appDidLogout) {
        dialogsLoaded[currentAccount] = false;
    } else if (id == NotificationCenter.encryptedChatUpdated) {
        updateVisibleRows(0);
    } else if (id == NotificationCenter.contactsDidLoad) {
        if (viewPages == null || dialogsListFrozen) {
            return;
        }
        boolean updateVisibleRows = false;
        for (int a = 0; a < viewPages.length; a++) {
            if (viewPages[a].isDefaultDialogType() && getMessagesController().getDialogs(folderId).size() <= 10) {
                viewPages[a].dialogsAdapter.notifyDataSetChanged();
            } else {
                updateVisibleRows = true;
            }
        }
        if (updateVisibleRows) {
            updateVisibleRows(0);
        }
    } else if (id == NotificationCenter.openedChatChanged) {
        if (viewPages == null) {
            return;
        }
        for (int a = 0; a < viewPages.length; a++) {
            if (viewPages[a].isDefaultDialogType() && AndroidUtilities.isTablet()) {
                boolean close = (Boolean) args[1];
                long dialog_id = (Long) args[0];
                if (close) {
                    if (dialog_id == openedDialogId) {
                        openedDialogId = 0;
                    }
                } else {
                    openedDialogId = dialog_id;
                }
                viewPages[a].dialogsAdapter.setOpenedDialogId(openedDialogId);
            }
        }
        updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
    } else if (id == NotificationCenter.notificationsSettingsUpdated) {
        updateVisibleRows(0);
    } else if (id == NotificationCenter.messageReceivedByAck || id == NotificationCenter.messageReceivedByServer || id == NotificationCenter.messageSendError) {
        updateVisibleRows(MessagesController.UPDATE_MASK_SEND_STATE);
    } else if (id == NotificationCenter.didSetPasscode) {
        updatePasscodeButton();
    } else if (id == NotificationCenter.needReloadRecentDialogsSearch) {
        if (searchViewPager != null && searchViewPager.dialogsSearchAdapter != null) {
            searchViewPager.dialogsSearchAdapter.loadRecentSearch();
        }
    } else if (id == NotificationCenter.replyMessagesDidLoad) {
        updateVisibleRows(MessagesController.UPDATE_MASK_MESSAGE_TEXT);
    } else if (id == NotificationCenter.reloadHints) {
        if (searchViewPager != null && searchViewPager.dialogsSearchAdapter != null) {
            searchViewPager.dialogsSearchAdapter.notifyDataSetChanged();
        }
    } else if (id == NotificationCenter.didUpdateConnectionState) {
        int state = AccountInstance.getInstance(account).getConnectionsManager().getConnectionState();
        if (currentConnectionState != state) {
            currentConnectionState = state;
            updateProxyButton(true);
        }
    } else if (id == NotificationCenter.needDeleteDialog) {
        if (fragmentView == null || isPaused) {
            return;
        }
        long dialogId = (Long) args[0];
        TLRPC.User user = (TLRPC.User) args[1];
        TLRPC.Chat chat = (TLRPC.Chat) args[2];
        boolean revoke = (Boolean) args[3];
        Runnable deleteRunnable = () -> {
            if (chat != null) {
                if (ChatObject.isNotInChat(chat)) {
                    getMessagesController().deleteDialog(dialogId, 0, revoke);
                } else {
                    getMessagesController().deleteParticipantFromChat(-dialogId, getMessagesController().getUser(getUserConfig().getClientUserId()), null, null, revoke, revoke);
                }
            } else {
                getMessagesController().deleteDialog(dialogId, 0, revoke);
                if (user != null && user.bot) {
                    getMessagesController().blockPeer(user.id);
                }
            }
            getMessagesController().checkIfFolderEmpty(folderId);
        };
        if (undoView[0] != null) {
            getUndoView().showWithAction(dialogId, UndoView.ACTION_DELETE, deleteRunnable);
        } else {
            deleteRunnable.run();
        }
    } else if (id == NotificationCenter.folderBecomeEmpty) {
        int fid = (Integer) args[0];
        if (folderId == fid && folderId != 0) {
            finishFragment();
        }
    } else if (id == NotificationCenter.dialogFiltersUpdated) {
        updateFilterTabs(true, true);
    } else if (id == NotificationCenter.filterSettingsUpdated) {
        showFiltersHint();
    } else if (id == NotificationCenter.newSuggestionsAvailable) {
        showNextSupportedSuggestion();
    } else if (id == NotificationCenter.messagesDeleted) {
        if (searchIsShowed && searchViewPager != null) {
            ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
            long channelId = (Long) args[1];
            searchViewPager.messagesDeleted(channelId, markAsDeletedMessages);
        }
    } else if (id == NotificationCenter.didClearDatabase) {
        if (viewPages != null) {
            for (int a = 0; a < viewPages.length; a++) {
                viewPages[a].dialogsAdapter.didDatabaseCleared();
            }
        }
    } else if (id == NotificationCenter.appUpdateAvailable) {
        updateMenuButton(true);
    } else if (id == NotificationCenter.fileLoaded || id == NotificationCenter.fileLoadFailed || id == NotificationCenter.fileLoadProgressChanged) {
        String name = (String) args[0];
        if (SharedConfig.isAppUpdateAvailable()) {
            String fileName = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
            if (fileName.equals(name)) {
                updateMenuButton(true);
            }
        }
    } else if (id == NotificationCenter.onDatabaseMigration) {
        boolean startMigration = (boolean) args[0];
        if (fragmentView != null) {
            if (startMigration) {
                if (databaseMigrationHint == null) {
                    databaseMigrationHint = new DatabaseMigrationHint(fragmentView.getContext(), currentAccount);
                    databaseMigrationHint.setAlpha(0f);
                    ((ContentView) fragmentView).addView(databaseMigrationHint);
                    databaseMigrationHint.animate().alpha(1).setDuration(300).setStartDelay(1000).start();
                }
                databaseMigrationHint.setTag(1);
            } else {
                if (databaseMigrationHint != null && databaseMigrationHint.getTag() != null) {
                    View localView = databaseMigrationHint;
                    localView.animate().setListener(null).cancel();
                    localView.animate().setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (localView.getParent() != null) {
                                ((ViewGroup) localView.getParent()).removeView(localView);
                            }
                            databaseMigrationHint = null;
                        }
                    }).alpha(0f).setStartDelay(0).setDuration(150).start();
                    databaseMigrationHint.setTag(null);
                }
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ImageView(android.widget.ImageView) FilterTabsView(org.telegram.ui.Components.FilterTabsView) UndoView(org.telegram.ui.Components.UndoView) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ScrollView(android.widget.ScrollView) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) NumberTextView(org.telegram.ui.Components.NumberTextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) StateListAnimator(android.animation.StateListAnimator) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) DialogsItemAnimator(org.telegram.ui.Components.DialogsItemAnimator) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter)

Aggregations

MessagesController (org.telegram.messenger.MessagesController)20 TLRPC (org.telegram.tgnet.TLRPC)18 ArrayList (java.util.ArrayList)10 Paint (android.graphics.Paint)9 SuppressLint (android.annotation.SuppressLint)7 TextPaint (android.text.TextPaint)7 MessageObject (org.telegram.messenger.MessageObject)7 TLObject (org.telegram.tgnet.TLObject)6 View (android.view.View)5 ChatObject (org.telegram.messenger.ChatObject)5 UserObject (org.telegram.messenger.UserObject)5 Animator (android.animation.Animator)4 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)4 ValueAnimator (android.animation.ValueAnimator)4 Context (android.content.Context)4 SharedPreferences (android.content.SharedPreferences)4 Build (android.os.Build)4 TextUtils (android.text.TextUtils)4 ViewGroup (android.view.ViewGroup)4 TextView (android.widget.TextView)4