Search in sources :

Example 36 with MessageObject

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

the class StatisticActivity method loadMessages.

private void loadMessages() {
    TLRPC.TL_channels_getMessages req = new TLRPC.TL_channels_getMessages();
    req.id = new ArrayList<>();
    int index = recentPostIdtoIndexMap.get(loadFromId);
    int n = recentPostsAll.size();
    int count = 0;
    for (int i = index; i < n; i++) {
        if (recentPostsAll.get(i).message == null) {
            req.id.add(recentPostsAll.get(i).counters.msg_id);
            count++;
            if (count > 50) {
                break;
            }
        }
    }
    req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chat.id);
    messagesIsLoading = true;
    getConnectionsManager().sendRequest(req, (response, error) -> {
        final ArrayList<MessageObject> messageObjects = new ArrayList<>();
        if (response instanceof TLRPC.messages_Messages) {
            ArrayList<TLRPC.Message> messages = ((TLRPC.messages_Messages) response).messages;
            for (int i = 0; i < messages.size(); i++) {
                messageObjects.add(new MessageObject(currentAccount, messages.get(i), false, true));
            }
            getMessagesStorage().putMessages(messages, false, true, true, 0, false);
        }
        AndroidUtilities.runOnUIThread(() -> {
            messagesIsLoading = false;
            if (messageObjects.isEmpty()) {
                return;
            }
            int size = messageObjects.size();
            for (int i = 0; i < size; i++) {
                MessageObject messageObjectFormCache = messageObjects.get(i);
                int localIndex = recentPostIdtoIndexMap.get(messageObjectFormCache.getId(), -1);
                if (localIndex >= 0 && recentPostsAll.get(localIndex).counters.msg_id == messageObjectFormCache.getId()) {
                    recentPostsAll.get(localIndex).message = messageObjectFormCache;
                }
            }
            recentPostsLoaded.clear();
            size = recentPostsAll.size();
            for (int i = 0; i < size; i++) {
                RecentPostInfo postInfo = recentPostsAll.get(i);
                if (postInfo.message == null) {
                    loadFromId = postInfo.counters.msg_id;
                    break;
                } else {
                    recentPostsLoaded.add(postInfo);
                }
            }
            recyclerListView.setItemAnimator(null);
            diffUtilsCallback.update();
        });
    });
}
Also used : ArrayList(java.util.ArrayList) MessageObject(org.telegram.messenger.MessageObject) TLRPC(org.telegram.tgnet.TLRPC) SuppressLint(android.annotation.SuppressLint)

Example 37 with MessageObject

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

the class PopupNotificationActivity method getButtonsViewForMessage.

private LinearLayout getButtonsViewForMessage(int num, boolean applyOffset) {
    if (popupMessages.size() == 1 && (num < 0 || num >= popupMessages.size())) {
        return null;
    }
    if (num == -1) {
        num = popupMessages.size() - 1;
    } else if (num == popupMessages.size()) {
        num = 0;
    }
    LinearLayout view = null;
    final MessageObject messageObject = popupMessages.get(num);
    int buttonsCount = 0;
    TLRPC.ReplyMarkup markup = messageObject.messageOwner.reply_markup;
    if (messageObject.getDialogId() == 777000 && markup != null) {
        ArrayList<TLRPC.TL_keyboardButtonRow> rows = markup.rows;
        for (int a = 0, size = rows.size(); a < size; a++) {
            TLRPC.TL_keyboardButtonRow row = rows.get(a);
            for (int b = 0, size2 = row.buttons.size(); b < size2; b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                if (button instanceof TLRPC.TL_keyboardButtonCallback) {
                    buttonsCount++;
                }
            }
        }
    }
    final int account = messageObject.currentAccount;
    if (buttonsCount > 0) {
        ArrayList<TLRPC.TL_keyboardButtonRow> rows = markup.rows;
        for (int a = 0, size = rows.size(); a < size; a++) {
            TLRPC.TL_keyboardButtonRow row = rows.get(a);
            for (int b = 0, size2 = row.buttons.size(); b < size2; b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                if (button instanceof TLRPC.TL_keyboardButtonCallback) {
                    if (view == null) {
                        view = new LinearLayout(this);
                        view.setOrientation(LinearLayout.HORIZONTAL);
                        view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                        view.setWeightSum(100);
                        view.setTag("b");
                        view.setOnTouchListener((v, event) -> true);
                    }
                    TextView textView = new TextView(this);
                    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText));
                    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                    textView.setText(button.text.toUpperCase());
                    textView.setTag(button);
                    textView.setGravity(Gravity.CENTER);
                    textView.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    view.addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 100.0f / buttonsCount));
                    textView.setOnClickListener(v -> {
                        TLRPC.KeyboardButton button1 = (TLRPC.KeyboardButton) v.getTag();
                        if (button1 != null) {
                            SendMessagesHelper.getInstance(account).sendNotificationCallback(messageObject.getDialogId(), messageObject.getId(), button1.data);
                        }
                    });
                }
            }
        }
    }
    if (view != null) {
        int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        if (applyOffset) {
            if (num == currentMessageNum) {
                view.setTranslationX(0);
            } else if (num == currentMessageNum - 1) {
                view.setTranslationX(-widht);
            } else if (num == currentMessageNum + 1) {
                view.setTranslationX(widht);
            }
        }
        popupContainer.addView(view, layoutParams);
    }
    return view;
}
Also used : TLRPC(org.telegram.tgnet.TLRPC) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) MessageObject(org.telegram.messenger.MessageObject) LinearLayout(android.widget.LinearLayout)

Example 38 with MessageObject

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

the class SlotsDrawable method setBaseDice.

public boolean setBaseDice(ChatMessageCell messageCell, TLRPC.TL_messages_stickerSet stickerSet) {
    if (nativePtr != 0 || loadingInBackground) {
        return true;
    }
    loadingInBackground = true;
    MessageObject currentMessageObject = messageCell.getMessageObject();
    int account = messageCell.getMessageObject().currentAccount;
    Utilities.globalQueue.postRunnable(() -> {
        if (destroyAfterLoading) {
            AndroidUtilities.runOnUIThread(() -> {
                loadingInBackground = false;
                if (!secondLoadingInBackground && destroyAfterLoading) {
                    recycle();
                }
            });
            return;
        }
        boolean loading = false;
        for (int a = 0; a < nativePtrs.length; a++) {
            if (nativePtrs[a] != 0) {
                continue;
            }
            int num;
            if (a == 0) {
                num = 1;
            } else if (a == 1) {
                num = 8;
            } else if (a == 2) {
                num = 14;
            } else if (a == 3) {
                num = 20;
            } else {
                num = 2;
            }
            TLRPC.Document document = stickerSet.documents.get(num);
            File path = FileLoader.getPathToAttach(document, true);
            String json = readRes(path, 0);
            if (TextUtils.isEmpty(json)) {
                loading = true;
                AndroidUtilities.runOnUIThread(() -> {
                    String fileName = FileLoader.getAttachFileName(document);
                    DownloadController.getInstance(account).addLoadingFileObserver(fileName, currentMessageObject, messageCell);
                    FileLoader.getInstance(account).loadFile(document, stickerSet, 1, 1);
                });
            } else {
                nativePtrs[a] = createWithJson(json, "dice", metaData, null);
                frameCounts[a] = metaData[0];
            }
        }
        if (loading) {
            AndroidUtilities.runOnUIThread(() -> loadingInBackground = false);
            return;
        }
        AndroidUtilities.runOnUIThread(() -> {
            loadingInBackground = false;
            if (!secondLoadingInBackground && destroyAfterLoading) {
                recycle();
                return;
            }
            nativePtr = nativePtrs[0];
            DownloadController.getInstance(account).removeLoadingFileObserver(messageCell);
            timeBetweenFrames = Math.max(16, (int) (1000.0f / metaData[1]));
            scheduleNextGetFrame();
            invalidateInternal();
        });
    });
    return true;
}
Also used : MessageObject(org.telegram.messenger.MessageObject) File(java.io.File) TLRPC(org.telegram.tgnet.TLRPC)

Example 39 with MessageObject

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

the class SlotsDrawable method setDiceNumber.

public boolean setDiceNumber(ChatMessageCell messageCell, int number, TLRPC.TL_messages_stickerSet stickerSet, boolean instant) {
    if (secondNativePtr != 0 || secondLoadingInBackground) {
        return true;
    }
    init(number);
    MessageObject currentMessageObject = messageCell.getMessageObject();
    int account = messageCell.getMessageObject().currentAccount;
    secondLoadingInBackground = true;
    Utilities.globalQueue.postRunnable(() -> {
        if (destroyAfterLoading) {
            AndroidUtilities.runOnUIThread(() -> {
                secondLoadingInBackground = false;
                if (!loadingInBackground && destroyAfterLoading) {
                    recycle();
                }
            });
            return;
        }
        boolean loading = false;
        for (int a = 0; a < secondNativePtrs.length + 2; a++) {
            int num;
            if (a <= 2) {
                if (secondNativePtrs[a] != 0) {
                    continue;
                }
                if (a == 0) {
                    if (left == ReelValue.bar) {
                        num = 5;
                    } else if (left == ReelValue.berries) {
                        num = 6;
                    } else if (left == ReelValue.lemon) {
                        num = 7;
                    } else if (left == ReelValue.seven) {
                        num = 4;
                    } else {
                        num = 3;
                    }
                } else if (a == 1) {
                    if (center == ReelValue.bar) {
                        num = 11;
                    } else if (center == ReelValue.berries) {
                        num = 12;
                    } else if (center == ReelValue.lemon) {
                        num = 13;
                    } else if (center == ReelValue.seven) {
                        num = 10;
                    } else {
                        num = 9;
                    }
                } else {
                    if (right == ReelValue.bar) {
                        num = 17;
                    } else if (right == ReelValue.berries) {
                        num = 18;
                    } else if (right == ReelValue.lemon) {
                        num = 19;
                    } else if (right == ReelValue.seven) {
                        num = 16;
                    } else {
                        num = 15;
                    }
                }
            } else {
                if (nativePtrs[a] != 0) {
                    continue;
                }
                if (a == 3) {
                    num = 1;
                } else {
                    num = 2;
                }
            }
            TLRPC.Document document = stickerSet.documents.get(num);
            File path = FileLoader.getPathToAttach(document, true);
            String json = readRes(path, 0);
            if (TextUtils.isEmpty(json)) {
                loading = true;
                AndroidUtilities.runOnUIThread(() -> {
                    String fileName = FileLoader.getAttachFileName(document);
                    DownloadController.getInstance(account).addLoadingFileObserver(fileName, currentMessageObject, messageCell);
                    FileLoader.getInstance(account).loadFile(document, stickerSet, 1, 1);
                });
            } else {
                if (a <= 2) {
                    secondNativePtrs[a] = createWithJson(json, "dice", metaData, null);
                    secondFrameCounts[a] = metaData[0];
                } else {
                    nativePtrs[a == 3 ? 0 : 4] = createWithJson(json, "dice", metaData, null);
                    frameCounts[a == 3 ? 0 : 4] = metaData[0];
                }
            }
        }
        if (loading) {
            AndroidUtilities.runOnUIThread(() -> secondLoadingInBackground = false);
            return;
        }
        AndroidUtilities.runOnUIThread(() -> {
            if (instant && nextRenderingBitmap == null && renderingBitmap == null && loadFrameTask == null) {
                isDice = 2;
                setLastFrame = true;
            }
            secondLoadingInBackground = false;
            if (!loadingInBackground && destroyAfterLoading) {
                recycle();
                return;
            }
            secondNativePtr = secondNativePtrs[0];
            DownloadController.getInstance(account).removeLoadingFileObserver(messageCell);
            timeBetweenFrames = Math.max(16, (int) (1000.0f / metaData[1]));
            scheduleNextGetFrame();
            invalidateInternal();
        });
    });
    return true;
}
Also used : MessageObject(org.telegram.messenger.MessageObject) File(java.io.File) TLRPC(org.telegram.tgnet.TLRPC)

Example 40 with MessageObject

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

the class PhotoViewer method onPhotoShow.

private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, ImageLocation imageLocation, ImageLocation videoLocation, final ArrayList<MessageObject> messages, final ArrayList<SecureDocument> documents, final List<Object> photos, int index, final PlaceProviderObject object) {
    classGuid = ConnectionsManager.generateClassGuid();
    currentMessageObject = null;
    currentFileLocation = null;
    currentFileLocationVideo = null;
    currentSecureDocument = null;
    currentPathObject = null;
    currentPageBlock = null;
    fromCamera = false;
    currentBotInlineResult = null;
    avatarStartProgress = 0.0f;
    avatarStartTime = 0;
    currentIndex = -1;
    currentFileNames[0] = null;
    currentFileNames[1] = null;
    currentFileNames[2] = null;
    avatarsDialogId = 0;
    canEditAvatar = false;
    totalImagesCount = 0;
    totalImagesCountMerge = 0;
    currentEditMode = 0;
    isFirstLoading = true;
    needSearchImageInArr = false;
    loadingMoreImages = false;
    endReached[0] = false;
    endReached[1] = mergeDialogId == 0;
    opennedFromMedia = false;
    needCaptionLayout = false;
    containerView.setTag(1);
    playerAutoStarted = false;
    isCurrentVideo = false;
    shownControlsByEnd = false;
    imagesArr.clear();
    imagesArrLocations.clear();
    imagesArrLocationsSizes.clear();
    imagesArrLocationsVideo.clear();
    imagesArrMessages.clear();
    avatarsArr.clear();
    secureDocuments.clear();
    imagesArrLocals.clear();
    for (int a = 0; a < 2; a++) {
        imagesByIds[a].clear();
        imagesByIdsTemp[a].clear();
    }
    imagesArrTemp.clear();
    currentAvatarLocation = null;
    containerView.setPadding(0, 0, 0, 0);
    if (currentThumb != null) {
        currentThumb.release();
    }
    if (videoTimelineView != null) {
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            videoTimelineView.setBackground(null);
        } else {
            videoTimelineView.setBackgroundColor(0x7f000000);
        }
    }
    currentThumb = object != null ? object.thumb : null;
    isEvent = object != null && object.isEvent;
    sharedMediaType = MediaDataController.MEDIA_PHOTOVIDEO;
    allMediaItem.setText(LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia));
    setItemVisible(sendItem, false, false);
    setItemVisible(pipItem, false, true);
    cameraItem.setVisibility(View.GONE);
    cameraItem.setTag(null);
    bottomLayout.setVisibility(View.VISIBLE);
    bottomLayout.setTag(1);
    bottomLayout.setTranslationY(0);
    captionTextViewSwitcher.setTranslationY(0);
    bottomButtonsLayout.setVisibility(View.GONE);
    paintButton.setVisibility(View.GONE);
    if (qualityChooseView != null) {
        qualityChooseView.setVisibility(View.INVISIBLE);
        qualityPicker.setVisibility(View.INVISIBLE);
        qualityChooseView.setTag(null);
    }
    if (qualityChooseViewAnimation != null) {
        qualityChooseViewAnimation.cancel();
        qualityChooseViewAnimation = null;
    }
    setDoubleTapEnabled(true);
    allowShare = false;
    slideshowMessageId = 0;
    nameOverride = null;
    dateOverride = 0;
    menuItem.hideSubItem(gallery_menu_showall);
    menuItem.hideSubItem(gallery_menu_showinchat);
    menuItem.hideSubItem(gallery_menu_share);
    menuItem.hideSubItem(gallery_menu_openin);
    menuItem.hideSubItem(gallery_menu_savegif);
    menuItem.hideSubItem(gallery_menu_masks2);
    menuItem.hideSubItem(gallery_menu_edit_avatar);
    menuItem.hideSubItem(gallery_menu_set_as_main);
    menuItem.hideSubItem(gallery_menu_delete);
    menuItem.hideSubItem(gallery_menu_speed);
    speedGap.setVisibility(View.GONE);
    actionBar.setTranslationY(0);
    checkImageView.setAlpha(1.0f);
    checkImageView.setTranslationY(0.0f);
    checkImageView.setVisibility(View.GONE);
    actionBar.setTitleRightMargin(0);
    photosCounterView.setAlpha(1.0f);
    photosCounterView.setTranslationY(0.0f);
    photosCounterView.setVisibility(View.GONE);
    pickerView.setVisibility(View.GONE);
    pickerViewSendButton.setVisibility(View.GONE);
    pickerViewSendButton.setTranslationY(0);
    pickerView.setAlpha(1.0f);
    pickerViewSendButton.setAlpha(1.0f);
    pickerView.setTranslationY(0);
    paintItem.setVisibility(View.GONE);
    paintItem.setTag(null);
    cropItem.setVisibility(View.GONE);
    tuneItem.setVisibility(View.GONE);
    tuneItem.setTag(null);
    timeItem.setVisibility(View.GONE);
    rotateItem.setVisibility(View.GONE);
    mirrorItem.setVisibility(View.GONE);
    pickerView.getLayoutParams().height = LayoutHelper.WRAP_CONTENT;
    docInfoTextView.setVisibility(View.GONE);
    docNameTextView.setVisibility(View.GONE);
    showVideoTimeline(false, false);
    videoAvatarTooltip.setVisibility(View.GONE);
    compressItem.setVisibility(View.GONE);
    captionEditText.setVisibility(View.GONE);
    mentionListView.setVisibility(View.GONE);
    AndroidUtilities.updateViewVisibilityAnimated(muteItem, false, 1f, false);
    actionBar.setSubtitle(null);
    setItemVisible(masksItem, false, true);
    shareItem.setVisibility(View.GONE);
    muteVideo = false;
    muteItem.setImageResource(R.drawable.video_send_unmute);
    editorDoneLayout.setVisibility(View.GONE);
    captionTextViewSwitcher.setTag(null);
    captionTextViewSwitcher.setVisibility(View.INVISIBLE);
    if (photoCropView != null) {
        photoCropView.setVisibility(View.GONE);
    }
    if (photoFilterView != null) {
        photoFilterView.setVisibility(View.GONE);
    }
    for (int a = 0; a < 3; a++) {
        if (photoProgressViews[a] != null) {
            photoProgressViews[a].setBackgroundState(PROGRESS_NONE, false, true);
        }
    }
    if (groupedPhotosListView != null) {
        groupedPhotosListView.reset();
        groupedPhotosListView.setAnimateBackground(!ApplicationLoader.isNetworkOnline());
    }
    if (placeProvider != null && placeProvider.getTotalImageCount() > 0) {
        totalImagesCount = placeProvider.getTotalImageCount();
    }
    if (messageObject != null) {
        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("playback_speed", Activity.MODE_PRIVATE);
        currentVideoSpeed = preferences.getFloat("speed" + messageObject.getDialogId() + "_" + messageObject.getId(), 1.0f);
    } else {
        currentVideoSpeed = 1.0f;
    }
    setMenuItemIcon();
    boolean noforwards = messageObject != null && (MessagesController.getInstance(currentAccount).isChatNoForwards(messageObject.getChatId()) || (messageObject.messageOwner != null && messageObject.messageOwner.noforwards));
    if (messageObject != null && messages == null) {
        if (messageObject.messageOwner != null && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage != null) {
            TLRPC.WebPage webPage = messageObject.messageOwner.media.webpage;
            String siteName = webPage.site_name;
            if (siteName != null) {
                siteName = siteName.toLowerCase();
                if (siteName.equals("instagram") || siteName.equals("twitter") || "telegram_album".equals(webPage.type)) {
                    if (!TextUtils.isEmpty(webPage.author)) {
                        nameOverride = webPage.author;
                    }
                    if (webPage.cached_page instanceof TLRPC.TL_page) {
                        for (int a = 0; a < webPage.cached_page.blocks.size(); a++) {
                            TLRPC.PageBlock block = webPage.cached_page.blocks.get(a);
                            if (block instanceof TLRPC.TL_pageBlockAuthorDate) {
                                dateOverride = ((TLRPC.TL_pageBlockAuthorDate) block).published_date;
                                break;
                            }
                        }
                    }
                    ArrayList<MessageObject> arrayList = messageObject.getWebPagePhotos(null, null);
                    if (!arrayList.isEmpty()) {
                        slideshowMessageId = messageObject.getId();
                        needSearchImageInArr = false;
                        imagesArr.addAll(arrayList);
                        totalImagesCount = imagesArr.size();
                        int idx = imagesArr.indexOf(messageObject);
                        if (idx < 0) {
                            idx = 0;
                        }
                        setImageIndex(idx);
                    }
                }
            }
        }
        if (messageObject.canPreviewDocument()) {
            sharedMediaType = MediaDataController.MEDIA_FILE;
            allMediaItem.setText(LocaleController.getString("ShowAllFiles", R.string.ShowAllFiles));
        } else if (messageObject.isGif()) {
            sharedMediaType = MediaDataController.MEDIA_GIF;
            allMediaItem.setText(LocaleController.getString("ShowAllGIFs", R.string.ShowAllGIFs));
        }
        if (isEmbedVideo) {
            bottomLayout.setTag(null);
            bottomLayout.setVisibility(View.GONE);
        }
        if (slideshowMessageId == 0) {
            imagesArr.add(messageObject);
            if (messageObject.eventId != 0) {
                needSearchImageInArr = false;
            } else if (currentAnimation != null) {
                needSearchImageInArr = false;
                if (messageObject.canForwardMessage() && !noforwards) {
                    setItemVisible(sendItem, true, false);
                }
            } else if (!messageObject.scheduled && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty)) {
                needSearchImageInArr = true;
                imagesByIds[0].put(messageObject.getId(), messageObject);
                if (parentChatActivity == null || !parentChatActivity.isThreadChat()) {
                    menuItem.showSubItem(gallery_menu_showinchat);
                    menuItem.showSubItem(gallery_menu_showall);
                }
                setItemVisible(sendItem, !noforwards, false);
            } else if (isEmbedVideo && messageObject.eventId == 0) {
                setItemVisible(sendItem, true, false);
            }
            setImageIndex(0);
        }
    } else if (documents != null) {
        secureDocuments.addAll(documents);
        setImageIndex(index);
    } else if (fileLocation != null) {
        avatarsDialogId = object != null ? object.dialogId : 0;
        canEditAvatar = object != null && object.canEdit;
        if (imageLocation == null && avatarsDialogId != 0) {
            if (avatarsDialogId > 0) {
                TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(avatarsDialogId);
                imageLocation = ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_BIG);
            } else {
                TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-avatarsDialogId);
                imageLocation = ImageLocation.getForUserOrChat(chat, ImageLocation.TYPE_BIG);
            }
        }
        if (imageLocation == null) {
            return;
        }
        imagesArrLocations.add(imageLocation);
        imagesArrLocationsVideo.add(videoLocation != null ? videoLocation : imageLocation);
        currentAvatarLocation = imageLocation;
        imagesArrLocationsSizes.add(object != null ? object.size : 0);
        imagesArrMessages.add(null);
        avatarsArr.add(new TLRPC.TL_photoEmpty());
        bottomButtonsLayout.setVisibility(!videoPlayerControlVisible ? View.VISIBLE : View.GONE);
        allowShare = true;
        menuItem.hideSubItem(gallery_menu_showall);
        if (bottomButtonsLayout.getVisibility() == View.VISIBLE) {
            menuItem.hideSubItem(gallery_menu_share);
        } else {
            menuItem.showSubItem(gallery_menu_share);
        }
        setImageIndex(0);
    } else if (messages != null) {
        imagesArr.addAll(messages);
        for (int a = 0; a < imagesArr.size(); a++) {
            MessageObject message = imagesArr.get(a);
            imagesByIds[message.getDialogId() == currentDialogId ? 0 : 1].put(message.getId(), message);
        }
        MessageObject openingObject = imagesArr.get(index);
        if (!openingObject.scheduled && (parentChatActivity == null || !parentChatActivity.isThreadChat())) {
            opennedFromMedia = true;
            if (object != null) {
                startOffset = object.starOffset;
            }
            menuItem.showSubItem(gallery_menu_showinchat);
            if (openingObject.canForwardMessage() && !noforwards) {
                setItemVisible(sendItem, true, false);
            }
            if (openingObject.canPreviewDocument()) {
                sharedMediaType = MediaDataController.MEDIA_FILE;
                allMediaItem.setText(LocaleController.getString("ShowAllFiles", R.string.ShowAllFiles));
            } else if (openingObject.isGif()) {
                sharedMediaType = MediaDataController.MEDIA_GIF;
                allMediaItem.setText(LocaleController.getString("ShowAllGIFs", R.string.ShowAllGIFs));
            }
        } else {
            totalImagesCount = imagesArr.size();
        }
        setImageIndex(index);
    } else if (photos != null) {
        if (sendPhotoType == 0 || sendPhotoType == 4 || (sendPhotoType == 2 || sendPhotoType == 5) && photos.size() > 1) {
            checkImageView.setVisibility(View.VISIBLE);
            photosCounterView.setVisibility(View.VISIBLE);
            actionBar.setTitleRightMargin(AndroidUtilities.dp(100));
        }
        if ((sendPhotoType == 2 || sendPhotoType == 5) && placeProvider.canCaptureMorePhotos()) {
            cameraItem.setVisibility(View.VISIBLE);
            cameraItem.setTag(1);
        }
        menuItem.setVisibility(View.GONE);
        imagesArrLocals.addAll(photos);
        Object obj = imagesArrLocals.get(index);
        boolean allowCaption;
        if (obj instanceof MediaController.PhotoEntry) {
            if (sendPhotoType == SELECT_TYPE_QR) {
                cropItem.setVisibility(View.GONE);
                rotateItem.setVisibility(View.GONE);
                mirrorItem.setVisibility(View.GONE);
            } else if (isDocumentsPicker) {
                cropItem.setVisibility(View.GONE);
                rotateItem.setVisibility(View.GONE);
                mirrorItem.setVisibility(View.GONE);
                docInfoTextView.setVisibility(View.VISIBLE);
                docNameTextView.setVisibility(View.VISIBLE);
                pickerView.getLayoutParams().height = AndroidUtilities.dp(84);
            } else if (((MediaController.PhotoEntry) obj).isVideo) {
                cropItem.setVisibility(View.GONE);
                rotateItem.setVisibility(View.GONE);
                mirrorItem.setVisibility(View.GONE);
                bottomLayout.setVisibility(View.VISIBLE);
                bottomLayout.setTag(1);
                bottomLayout.setTranslationY(-AndroidUtilities.dp(48));
            } else {
                cropItem.setVisibility(sendPhotoType != SELECT_TYPE_AVATAR ? View.VISIBLE : View.GONE);
                rotateItem.setVisibility(sendPhotoType != SELECT_TYPE_AVATAR ? View.GONE : View.VISIBLE);
                mirrorItem.setVisibility(sendPhotoType != SELECT_TYPE_AVATAR ? View.GONE : View.VISIBLE);
            }
            allowCaption = !isDocumentsPicker;
        } else if (obj instanceof TLRPC.BotInlineResult) {
            cropItem.setVisibility(View.GONE);
            rotateItem.setVisibility(View.GONE);
            mirrorItem.setVisibility(View.GONE);
            allowCaption = false;
        } else {
            cropItem.setVisibility(obj instanceof MediaController.SearchImage && ((MediaController.SearchImage) obj).type == 0 ? View.VISIBLE : View.GONE);
            rotateItem.setVisibility(View.GONE);
            mirrorItem.setVisibility(View.GONE);
            allowCaption = cropItem.getVisibility() == View.VISIBLE;
        }
        if (parentChatActivity != null) {
            mentionsAdapter.setChatInfo(parentChatActivity.chatInfo);
            mentionsAdapter.setNeedUsernames(parentChatActivity.currentChat != null);
            mentionsAdapter.setNeedBotContext(false);
            needCaptionLayout = allowCaption && (placeProvider == null || placeProvider.allowCaption());
            captionEditText.setVisibility(needCaptionLayout ? View.VISIBLE : View.GONE);
            if (needCaptionLayout) {
                captionEditText.onCreate();
            }
        }
        pickerView.setVisibility(View.VISIBLE);
        pickerViewSendButton.setVisibility(View.VISIBLE);
        pickerViewSendButton.setTranslationY(0);
        pickerViewSendButton.setAlpha(1.0f);
        bottomLayout.setVisibility(View.GONE);
        bottomLayout.setTag(null);
        containerView.setTag(null);
        setImageIndex(index);
        if (sendPhotoType == SELECT_TYPE_AVATAR) {
            paintItem.setVisibility(View.VISIBLE);
            tuneItem.setVisibility(View.VISIBLE);
        } else if (sendPhotoType != 4 && sendPhotoType != 5) {
            paintItem.setVisibility(paintItem.getTag() != null ? View.VISIBLE : View.GONE);
            tuneItem.setVisibility(tuneItem.getTag() != null ? View.VISIBLE : View.GONE);
        } else {
            paintItem.setVisibility(View.GONE);
            tuneItem.setVisibility(View.GONE);
        }
        updateSelectedCount();
    } else {
        setImageIndex(index);
    }
    if (currentAnimation == null && !isEvent) {
        if (currentDialogId != 0 && totalImagesCount == 0 && currentMessageObject != null && !currentMessageObject.scheduled) {
            if (MediaDataController.getMediaType(currentMessageObject.messageOwner) == sharedMediaType) {
                MediaDataController.getInstance(currentAccount).getMediaCount(currentDialogId, sharedMediaType, classGuid, true);
                if (mergeDialogId != 0) {
                    MediaDataController.getInstance(currentAccount).getMediaCount(mergeDialogId, sharedMediaType, classGuid, true);
                }
            }
        } else if (avatarsDialogId != 0) {
            MessagesController.getInstance(currentAccount).loadDialogPhotos(avatarsDialogId, 80, 0, true, classGuid);
        }
    }
    if (currentMessageObject != null && currentMessageObject.isVideo() || currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document)) || pageBlocksAdapter != null && pageBlocksAdapter.isVideo(index)) {
        playerAutoStarted = true;
        onActionClick(false);
    } else if (!imagesArrLocals.isEmpty()) {
        Object entry = imagesArrLocals.get(index);
        CharSequence caption = null;
        TLRPC.User user = parentChatActivity != null ? parentChatActivity.getCurrentUser() : null;
        boolean allowTimeItem = !isDocumentsPicker && parentChatActivity != null && !parentChatActivity.isSecretChat() && !parentChatActivity.isInScheduleMode() && user != null && !user.bot && !UserObject.isUserSelf(user) && !parentChatActivity.isEditingMessageMedia();
        if (placeProvider != null && placeProvider.getEditingMessageObject() != null) {
            allowTimeItem = false;
        }
        if (entry instanceof TLRPC.BotInlineResult) {
            allowTimeItem = false;
        } else if (entry instanceof MediaController.PhotoEntry) {
        } else if (allowTimeItem && entry instanceof MediaController.SearchImage) {
            allowTimeItem = ((MediaController.SearchImage) entry).type == 0;
        }
        if (allowTimeItem) {
            timeItem.setVisibility(View.VISIBLE);
        }
    }
    checkFullscreenButton();
}
Also used : MediaController(org.telegram.messenger.MediaController) SharedPreferences(android.content.SharedPreferences) SpannableString(android.text.SpannableString) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) UserObject(org.telegram.messenger.UserObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) ChatObject(org.telegram.messenger.ChatObject) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

MessageObject (org.telegram.messenger.MessageObject)156 Paint (android.graphics.Paint)107 TLRPC (org.telegram.tgnet.TLRPC)88 SuppressLint (android.annotation.SuppressLint)87 TextPaint (android.text.TextPaint)80 View (android.view.View)59 ArrayList (java.util.ArrayList)59 TextView (android.widget.TextView)53 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)52 RecyclerView (androidx.recyclerview.widget.RecyclerView)50 ImageView (android.widget.ImageView)48 RecyclerListView (org.telegram.ui.Components.RecyclerListView)46 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)39 UndoView (org.telegram.ui.Components.UndoView)36 TextureView (android.view.TextureView)34 File (java.io.File)33 ChatObject (org.telegram.messenger.ChatObject)32 DialogObject (org.telegram.messenger.DialogObject)30 MediaController (org.telegram.messenger.MediaController)30 TLObject (org.telegram.tgnet.TLObject)30