use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method getPlaceForPhoto.
private PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, boolean needPreview, boolean onlyIfVisible) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
ImageReceiver imageReceiver = null;
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
if (messageObject != null) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject message = cell.getMessageObject();
if (message != null && message.getId() == messageObject.getId()) {
imageReceiver = cell.getPhotoImage();
}
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
MessageObject message = cell.getMessageObject();
if (message != null) {
if (messageObject != null) {
if (message.getId() == messageObject.getId()) {
imageReceiver = cell.getPhotoImage();
}
} else if (fileLocation != null && message.photoThumbs != null) {
for (int b = 0; b < message.photoThumbs.size(); b++) {
TLRPC.PhotoSize photoSize = message.photoThumbs.get(b);
if (photoSize.location != null && photoSize.location.volume_id == fileLocation.volume_id && photoSize.location.local_id == fileLocation.local_id) {
imageReceiver = cell.getPhotoImage();
break;
}
}
}
}
}
if (imageReceiver != null) {
if (onlyIfVisible && view.getY() + imageReceiver.getImageY2() < chatListViewPaddingTop - AndroidUtilities.dp(4)) {
return null;
}
int[] coords = new int[2];
view.getLocationInWindow(coords);
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
object.viewX = coords[0];
object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
object.parentView = chatListView;
object.animatingImageView = !SharedConfig.smoothKeyboard && pagedownButton != null && pagedownButton.getTag() != null && view instanceof ChatMessageCell ? animatingImageView : null;
object.imageReceiver = imageReceiver;
if (needPreview) {
object.thumb = imageReceiver.getBitmapSafe();
}
object.radius = imageReceiver.getRoundRadius();
if (view instanceof ChatActionCell && currentChat != null) {
object.dialogId = -currentChat.id;
}
object.clipTopAddition = (int) (chatListViewPaddingTop - chatListViewPaddingVisibleOffset - AndroidUtilities.dp(4));
return object;
}
}
return null;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method getHeightForMessage.
private int getHeightForMessage(MessageObject object) {
if (dummyMessageCell == null) {
dummyMessageCell = new ChatMessageCell(getParentActivity(), true, themeDelegate);
}
dummyMessageCell.isChat = currentChat != null || UserObject.isUserSelf(currentUser);
dummyMessageCell.isBot = currentUser != null && currentUser.bot;
dummyMessageCell.isMegagroup = ChatObject.isChannel(currentChat) && currentChat.megagroup;
return dummyMessageCell.computeHeight(object, groupedMessagesMap.get(object.getGroupId()));
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method startMultiselect.
private void startMultiselect(int position) {
int indexOfMessage = position - chatAdapter.messagesStartRow;
if (indexOfMessage < 0 || indexOfMessage >= messages.size()) {
return;
}
MessageObject messageObject = messages.get(indexOfMessage);
final boolean unselect = selectedMessagesIds[0].get(messageObject.getId(), null) == null && selectedMessagesIds[1].get(messageObject.getId(), null) == null;
SparseArray<MessageObject> alreadySelectedMessagesIds = new SparseArray<>();
for (int i = 0; i < selectedMessagesIds[0].size(); i++) {
alreadySelectedMessagesIds.put(selectedMessagesIds[0].keyAt(i), selectedMessagesIds[0].valueAt(i));
}
for (int i = 0; i < selectedMessagesIds[1].size(); i++) {
alreadySelectedMessagesIds.put(selectedMessagesIds[1].keyAt(i), selectedMessagesIds[1].valueAt(i));
}
chatListView.startMultiselect(position, false, new RecyclerListView.onMultiSelectionChanged() {
boolean limitReached;
@Override
public void onSelectionChanged(int position, boolean selected, float x, float y) {
int i = position - chatAdapter.messagesStartRow;
if (unselect) {
selected = !selected;
}
if (i >= 0 && i < messages.size()) {
MessageObject messageObject = messages.get(i);
if (selected && (selectedMessagesIds[0].indexOfKey(messageObject.getId()) >= 0 || selectedMessagesIds[1].indexOfKey(messageObject.getId()) >= 0)) {
return;
}
if (!selected && selectedMessagesIds[0].indexOfKey(messageObject.getId()) < 0 && selectedMessagesIds[1].indexOfKey(messageObject.getId()) < 0) {
return;
}
if (messageObject.contentType == 0) {
if (selected && selectedMessagesIds[0].size() + selectedMessagesIds[1].size() >= 100) {
limitReached = true;
} else {
limitReached = false;
}
RecyclerView.ViewHolder holder = chatListView.findViewHolderForAdapterPosition(position);
if (holder != null && holder.itemView instanceof ChatMessageCell) {
processRowSelect(holder.itemView, false, x, y);
} else {
addToSelectedMessages(messageObject, false);
updateActionModeTitle();
updateVisibleRows();
}
}
}
}
@Override
public boolean canSelect(int position) {
int i = position - chatAdapter.messagesStartRow;
if (i >= 0 && i < messages.size()) {
MessageObject messageObject = messages.get(i);
if (messageObject.contentType == 0) {
if (!unselect && alreadySelectedMessagesIds.get(messageObject.getId(), null) == null) {
return true;
}
if (unselect && alreadySelectedMessagesIds.get(messageObject.getId(), null) != null) {
return true;
}
}
}
return false;
}
@Override
public int checkPosition(int position, boolean selectionTop) {
int i = position - chatAdapter.messagesStartRow;
if (i >= 0 && i < messages.size()) {
MessageObject messageObject = messages.get(i);
if (messageObject.contentType == 0 && messageObject.hasValidGroupId()) {
MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId());
if (groupedMessages != null) {
MessageObject messageObject1 = groupedMessages.messages.get(selectionTop ? 0 : groupedMessages.messages.size() - 1);
return chatAdapter.messagesStartRow + messages.indexOf(messageObject1);
}
}
}
return position;
}
@Override
public boolean limitReached() {
return limitReached;
}
@Override
public void getPaddings(int[] paddings) {
paddings[0] = (int) chatListViewPaddingTop;
paddings[1] = 0;
}
@Override
public void scrollBy(int dy) {
chatListView.scrollBy(0, dy);
}
});
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method updateMessagesVisiblePart.
public void updateMessagesVisiblePart(boolean inLayout) {
if (chatListView == null) {
return;
}
int count = chatListView.getChildCount();
int height = chatListView.getMeasuredHeight();
int minPositionHolder = Integer.MAX_VALUE;
int minPositionDateHolder = Integer.MAX_VALUE;
View minDateChild = null;
View minChild = null;
View minMessageChild = null;
boolean foundTextureViewMessage = false;
boolean previousThreadMessageVisible = threadMessageVisible;
int previousPinnedMessageId = currentPinnedMessageId;
int maxVisibleId = Integer.MIN_VALUE;
MessageObject maxVisibleMessageObject = null;
threadMessageVisible = firstLoading;
Integer currentReadMaxId = null;
int threadId = threadMessageId;
if (threadId != 0 && currentChat != null) {
currentReadMaxId = replyMaxReadId;
} else {
currentReadMaxId = getMessagesController().dialogs_read_inbox_max.get(dialog_id_Long);
}
if (currentReadMaxId == null) {
currentReadMaxId = 0;
}
int maxPositiveUnreadId = Integer.MIN_VALUE;
int maxNegativeUnreadId = Integer.MAX_VALUE;
int maxUnreadDate = Integer.MIN_VALUE;
int recyclerChatViewHeight = (contentView.getHeightWithKeyboard() - (inPreviewMode ? 0 : AndroidUtilities.dp(48)) - chatListView.getTop());
pollsToCheck.clear();
float clipTop = chatListViewPaddingTop;
long currentTime = System.currentTimeMillis();
int maxAdapterPosition = -1;
int minAdapterPosition = -1;
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
MessageObject messageObject = null;
int adapterPosition = chatListView.getChildAdapterPosition(view);
if (adapterPosition >= 0) {
if (adapterPosition > maxAdapterPosition || maxAdapterPosition == -1) {
maxAdapterPosition = adapterPosition;
}
if (adapterPosition < minAdapterPosition || minAdapterPosition == -1) {
minAdapterPosition = adapterPosition;
}
}
int top = (int) view.getY();
int bottom = top + view.getMeasuredHeight();
ChatMessageCell messageCell = null;
if (view instanceof ChatMessageCell) {
messageCell = (ChatMessageCell) view;
}
if (messageCell != null) {
messageCell.isBlurred = view.getY() < clipTop || view.getY() + view.getMeasuredHeight() > AndroidUtilities.dp(203);
}
if (bottom <= clipTop - chatListViewPaddingVisibleOffset || top > chatListView.getMeasuredHeight()) {
continue;
}
int viewTop = top >= 0 ? 0 : -top;
int viewBottom = view.getMeasuredHeight();
if (viewBottom > height) {
viewBottom = viewTop + height;
}
int keyboardOffset = contentView.getKeyboardHeight();
if (keyboardOffset < AndroidUtilities.dp(20) && chatActivityEnterView.isPopupShowing() || chatActivityEnterView.pannelAniamationInProgress()) {
keyboardOffset = chatActivityEnterView.getEmojiPadding();
}
if (messageCell != null) {
messageObject = messageCell.getMessageObject();
if (messageObject.getDialogId() == dialog_id && messageObject.getId() > maxVisibleId) {
maxVisibleId = messageObject.getId();
maxVisibleMessageObject = messageObject;
}
messageCell.setVisiblePart(viewTop, viewBottom - viewTop, recyclerChatViewHeight, keyboardOffset, view.getY() + (isKeyboardVisible() ? chatListView.getTop() : actionBar.getMeasuredHeight()) - contentView.getBackgroundTranslationY(), contentView.getMeasuredWidth(), contentView.getBackgroundSizeY());
markSponsoredAsRead(messageObject);
if (!threadMessageVisible && threadMessageObject != null && messageObject == threadMessageObject && messageCell.getBottom() > chatListViewPaddingTop) {
threadMessageVisible = true;
}
if (videoPlayerContainer != null && (messageObject.isVideo() || messageObject.isRoundVideo()) && MediaController.getInstance().isPlayingMessage(messageObject)) {
ImageReceiver imageReceiver = messageCell.getPhotoImage();
if (top + imageReceiver.getImageY2() < 0) {
foundTextureViewMessage = false;
} else {
videoPlayerContainer.setTranslationX(imageReceiver.getImageX() + messageCell.getX());
float translationY = messageCell.getY() + imageReceiver.getImageY() + chatListView.getY() - videoPlayerContainer.getTop();
videoPlayerContainer.setTranslationY(translationY);
fragmentView.invalidate();
videoPlayerContainer.invalidate();
foundTextureViewMessage = true;
}
}
if (startFromVideoTimestamp >= 0 && fragmentOpened && !chatListView.isFastScrollAnimationRunning() && startFromVideoMessageId == messageObject.getId() && (messageObject.isVideo() || messageObject.isRoundVideo() || messageObject.isVoice() || messageObject.isMusic())) {
messageObject.forceSeekTo = startFromVideoTimestamp / (float) messageObject.getDuration();
MessageObject finalMessage = messageObject;
AndroidUtilities.runOnUIThread(() -> {
if (finalMessage.isVideo()) {
openPhotoViewerForMessage(null, finalMessage);
} else {
MediaController.getInstance().playMessage(finalMessage);
}
}, 40);
startFromVideoTimestamp = -1;
}
if (fragmentOpened && openAnimationEnded && (chatListItemAnimator == null || !chatListItemAnimator.isRunning()) && messageCell.checkUnreadReactions(clipTop, chatListView.getMeasuredHeight() - blurredViewBottomOffset)) {
reactionsMentionCount--;
getMessagesStorage().markMessageReactionsAsRead(getDialogId(), messageCell.getMessageObject().getId(), true);
if (reactionsMentionCount <= 0) {
getMessagesController().markReactionsAsRead(dialog_id);
}
if (reactionsMentionCount >= 0) {
TLRPC.TL_messagePeerReaction reaction = messageCell.getMessageObject().getRandomUnreadReaction();
if (reaction != null) {
ReactionsEffectOverlay.show(ChatActivity.this, null, messageCell, 0, 0, reaction.reaction, currentAccount, reaction.big ? ReactionsEffectOverlay.LONG_ANIMATION : ReactionsEffectOverlay.SHORT_ANIMATION);
ReactionsEffectOverlay.startAnimation();
}
messageCell.markReactionsAsRead();
} else {
reactionsMentionCount = 0;
}
updateReactionsMentionButton(true);
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getDialogId() == dialog_id && messageObject.getId() > maxVisibleId) {
maxVisibleId = Math.max(maxVisibleId, messageObject.getId());
}
cell.setVisiblePart(view.getY() + (isKeyboardVisible() ? chatListView.getTop() : actionBar.getMeasuredHeight()) - contentView.getBackgroundTranslationY(), contentView.getBackgroundSizeY());
} else if (view instanceof BotHelpCell) {
view.invalidate();
}
if (chatMode != MODE_SCHEDULED && messageObject != null) {
int id = messageObject.getId();
if (!isThreadChat() && (!messageObject.isOut() && messageObject.isUnread() || messageObject.messageOwner.from_scheduled && id > currentReadMaxId) || id > 0 && isThreadChat() && id > currentReadMaxId && id > replyMaxReadId) {
if (id > 0) {
maxPositiveUnreadId = Math.max(maxPositiveUnreadId, messageObject.getId());
}
if (id < 0 && !isThreadChat()) {
maxNegativeUnreadId = Math.min(maxNegativeUnreadId, messageObject.getId());
}
maxUnreadDate = Math.max(maxUnreadDate, messageObject.messageOwner.date);
}
if (messageObject.type == MessageObject.TYPE_POLL && messageObject.getId() > 0) {
pollsToCheck.add(messageObject);
}
}
if (bottom <= clipTop) {
if (view instanceof ChatActionCell && messageObject.isDateObject) {
view.setAlpha(0);
}
continue;
}
int position = view.getBottom();
if (position < minPositionHolder) {
minPositionHolder = position;
if (view instanceof ChatMessageCell || view instanceof ChatActionCell) {
minMessageChild = view;
}
minChild = view;
}
if (chatListItemAnimator == null || (!chatListItemAnimator.willRemoved(view) && !chatListItemAnimator.willAddedFromAlpha(view))) {
if (view instanceof ChatActionCell && messageObject.isDateObject) {
if (view.getAlpha() != 1.0f) {
view.setAlpha(1.0f);
}
if (position < minPositionDateHolder) {
minPositionDateHolder = position;
minDateChild = view;
}
}
}
}
currentPinnedMessageId = 0;
if (!pinnedMessageIds.isEmpty()) {
if (maxVisibleId == Integer.MIN_VALUE) {
if (startLoadFromMessageId != 0) {
maxVisibleId = startLoadFromMessageId;
} else if (!pinnedMessageIds.isEmpty()) {
maxVisibleId = pinnedMessageIds.get(0) + 1;
}
} else if (maxVisibleId < 0) {
int idx = messages.indexOf(maxVisibleMessageObject);
if (idx >= 0) {
for (int a = idx - 1; a >= 0; a--) {
MessageObject object = messages.get(a);
if (object.getId() > 0) {
maxVisibleId = object.getId();
break;
}
}
if (maxVisibleId < 0) {
for (int a = idx + 1, N = messages.size(); a < N; a++) {
MessageObject object = messages.get(a);
if (object.getId() > 0) {
maxVisibleId = object.getId();
break;
}
}
}
}
}
currentPinnedMessageId = findClosest(pinnedMessageIds, forceNextPinnedMessageId != 0 ? forceNextPinnedMessageId : maxVisibleId, currentPinnedMessageIndex);
if (!inMenuMode && !loadingPinnedMessagesList && !pinnedEndReached && !pinnedMessageIds.isEmpty() && currentPinnedMessageIndex[0] > pinnedMessageIds.size() - 2) {
getMediaDataController().loadPinnedMessages(dialog_id, pinnedMessageIds.get(pinnedMessageIds.size() - 1), 0);
loadingPinnedMessagesList = true;
}
}
getMessagesController().addToPollsQueue(dialog_id, pollsToCheck);
if (maxAdapterPosition >= 0 && minAdapterPosition >= 0) {
int from = minAdapterPosition - chatAdapter.messagesStartRow - 10;
int to = maxAdapterPosition - chatAdapter.messagesStartRow + 10;
if (from < 0) {
from = 0;
}
if (to > messages.size()) {
to = messages.size();
}
reactionsToCheck.clear();
for (int i = from; i < to; i++) {
MessageObject messageObject = messages.get(i);
if (threadMessageObject != messageObject && messageObject.getId() > 0 && messageObject.messageOwner.action == null && (currentTime - messageObject.reactionsLastCheckTime) > 15000L) {
messageObject.reactionsLastCheckTime = currentTime;
reactionsToCheck.add(messageObject);
}
}
getMessagesController().loadReactionsForMessages(dialog_id, reactionsToCheck);
}
if (videoPlayerContainer != null) {
if (!foundTextureViewMessage) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null) {
if (checkTextureViewPosition && messageObject.isVideo()) {
MediaController.getInstance().cleanupPlayer(true, true);
} else {
videoPlayerContainer.setTranslationY(-AndroidUtilities.roundPlayingMessageSize - 100);
fragmentView.invalidate();
if ((messageObject.isRoundVideo() || messageObject.isVideo()) && messageObject.eventId == 0 && checkTextureViewPosition && !chatListView.isFastScrollAnimationRunning()) {
MediaController.getInstance().setCurrentVideoVisible(false);
}
}
}
} else {
MediaController.getInstance().setCurrentVideoVisible(true);
}
}
if (minMessageChild != null) {
MessageObject messageObject;
if (minMessageChild instanceof ChatMessageCell) {
messageObject = ((ChatMessageCell) minMessageChild).getMessageObject();
} else {
messageObject = ((ChatActionCell) minMessageChild).getMessageObject();
}
floatingDateView.setCustomDate(messageObject.messageOwner.date, chatMode == MODE_SCHEDULED, true);
}
currentFloatingDateOnScreen = false;
currentFloatingTopIsNotMessage = !(minChild instanceof ChatMessageCell || minChild instanceof ChatActionCell);
if (minDateChild != null) {
boolean showFloatingView = false;
if (minDateChild.getY() > clipTop || currentFloatingTopIsNotMessage) {
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
if (chatListView.getChildAdapterPosition(minDateChild) == chatAdapter.messagesStartRow + messages.size() - 1) {
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
if (floatingDateAnimation != null) {
floatingDateAnimation.cancel();
floatingDateAnimation = null;
}
floatingDateView.setTag(null);
floatingDateView.setAlpha(0);
currentFloatingDateOnScreen = false;
} else {
hideFloatingDateView(!currentFloatingTopIsNotMessage);
}
} else {
if (minDateChild.getAlpha() != 0.0f) {
minDateChild.setAlpha(0.0f);
}
showFloatingView = true;
}
float offset = minDateChild.getY() + minDateChild.getMeasuredHeight() - clipTop;
if (offset > floatingDateView.getMeasuredHeight() && offset < floatingDateView.getMeasuredHeight() * 2) {
if (chatListView.getChildAdapterPosition(minDateChild) == chatAdapter.messagesStartRow + messages.size() - 1) {
showFloatingView = false;
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
if (floatingDateAnimation != null) {
floatingDateAnimation.cancel();
floatingDateAnimation = null;
}
floatingDateView.setTag(null);
floatingDateView.setAlpha(0);
} else {
floatingDateViewOffset = -floatingDateView.getMeasuredHeight() * 2 + offset;
}
} else {
floatingDateViewOffset = 0;
}
if (showFloatingView) {
if (floatingDateAnimation != null) {
floatingDateAnimation.cancel();
floatingDateAnimation = null;
}
if (floatingDateView.getTag() == null) {
floatingDateView.setTag(1);
}
if (floatingDateView.getAlpha() != 1.0f) {
floatingDateView.setAlpha(1.0f);
}
currentFloatingDateOnScreen = true;
}
} else {
hideFloatingDateView(true);
floatingDateViewOffset = 0;
}
if (isThreadChat()) {
if (previousThreadMessageVisible != threadMessageVisible) {
updatePinnedMessageView(openAnimationStartTime != 0 && SystemClock.elapsedRealtime() >= openAnimationStartTime + 150);
}
} else {
if (currentPinnedMessageId != 0) {
MessageObject object = pinnedMessageObjects.get(currentPinnedMessageId);
if (object == null) {
object = messagesDict[0].get(currentPinnedMessageId);
}
if (object == null) {
if (loadingPinnedMessages.indexOfKey(currentPinnedMessageId) < 0) {
loadingPinnedMessages.put(currentPinnedMessageId, true);
ArrayList<Integer> ids = new ArrayList<>();
ids.add(currentPinnedMessageId);
getMediaDataController().loadPinnedMessages(dialog_id, ChatObject.isChannel(currentChat) ? currentChat.id : 0, ids, true);
}
currentPinnedMessageId = previousPinnedMessageId;
}
} else if (previousPinnedMessageId != 0 && !pinnedMessageIds.isEmpty()) {
currentPinnedMessageId = previousPinnedMessageId;
}
boolean animated = (fromPullingDownTransition && fragmentView.getVisibility() == View.VISIBLE) || (openAnimationStartTime != 0 && SystemClock.elapsedRealtime() >= openAnimationStartTime + 150);
if (previousPinnedMessageId != currentPinnedMessageId) {
int animateToNext;
if (previousPinnedMessageId == 0) {
animateToNext = 0;
} else if (previousPinnedMessageId > currentPinnedMessageId) {
animateToNext = 1;
} else {
animateToNext = 2;
}
updatePinnedMessageView(animated, animateToNext);
} else {
updatePinnedListButton(animated);
}
}
if (floatingDateView != null) {
floatingDateView.setTranslationY(chatListView.getTranslationY() + chatListViewPaddingTop + floatingDateViewOffset - AndroidUtilities.dp(4));
}
invalidateChatListViewTopPadding();
if (!firstLoading && !paused && !inPreviewMode && chatMode == 0 && !getMessagesController().ignoreSetOnline) {
int scheduledRead = 0;
if ((maxPositiveUnreadId != Integer.MIN_VALUE || maxNegativeUnreadId != Integer.MAX_VALUE)) {
int counterDecrement = 0;
for (int a = 0; a < messages.size(); a++) {
MessageObject messageObject = messages.get(a);
int id = messageObject.getId();
if (maxPositiveUnreadId != Integer.MIN_VALUE) {
if (id > 0 && id <= maxPositiveUnreadId && (messageObject.messageOwner.from_scheduled && id > currentReadMaxId || messageObject.isUnread() && !messageObject.isOut())) {
if (messageObject.messageOwner.from_scheduled) {
scheduledRead++;
} else {
messageObject.setIsRead();
}
counterDecrement++;
}
}
if (maxNegativeUnreadId != Integer.MAX_VALUE) {
if (id < 0 && id >= maxNegativeUnreadId && messageObject.isUnread()) {
messageObject.setIsRead();
counterDecrement++;
}
}
}
if (forwardEndReached[0] && maxPositiveUnreadId == minMessageId[0] || maxNegativeUnreadId == minMessageId[0]) {
newUnreadMessageCount = 0;
} else {
newUnreadMessageCount -= counterDecrement;
if (newUnreadMessageCount < 0) {
newUnreadMessageCount = 0;
}
}
if (inLayout) {
AndroidUtilities.runOnUIThread(this::inlineUpdate1);
} else {
inlineUpdate1();
}
getMessagesController().markDialogAsRead(dialog_id, maxPositiveUnreadId, maxNegativeUnreadId, maxUnreadDate, false, threadId, counterDecrement, maxPositiveUnreadId == minMessageId[0] || maxNegativeUnreadId == minMessageId[0], scheduledRead);
firstUnreadSent = true;
} else if (!firstUnreadSent && currentEncryptedChat == null) {
if (chatLayoutManager.findFirstVisibleItemPosition() == 0) {
newUnreadMessageCount = 0;
if (inLayout) {
AndroidUtilities.runOnUIThread(this::inlineUpdate2);
} else {
inlineUpdate2();
}
getMessagesController().markDialogAsRead(dialog_id, minMessageId[0], minMessageId[0], maxDate[0], false, threadId, 0, true, scheduledRead);
firstUnreadSent = true;
}
}
if (threadId != 0 && maxPositiveUnreadId > 0 && replyMaxReadId != maxPositiveUnreadId) {
replyMaxReadId = maxPositiveUnreadId;
getMessagesStorage().updateRepliesMaxReadId(replyOriginalChat.id, replyOriginalMessageId, replyMaxReadId, true);
getNotificationCenter().postNotificationName(NotificationCenter.commentsRead, replyOriginalChat.id, replyOriginalMessageId, replyMaxReadId);
}
}
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method updateVisibleRows.
private void updateVisibleRows() {
if (chatListView == null) {
return;
}
int lastVisibleItem = RecyclerView.NO_POSITION;
int top = 0;
if (!wasManualScroll && unreadMessageObject != null) {
int n = chatListView.getChildCount();
for (int i = 0; i < n; i++) {
View child = chatListView.getChildAt(i);
if (child instanceof ChatMessageCell && ((ChatMessageCell) child).getMessageObject() == unreadMessageObject) {
int unreadMessageIndex = messages.indexOf(unreadMessageObject);
if (unreadMessageIndex >= 0) {
lastVisibleItem = chatAdapter.messagesStartRow + messages.indexOf(unreadMessageObject);
top = chatListView.getMeasuredHeight() - child.getBottom() - chatListView.getPaddingBottom();
}
break;
}
}
}
int count = chatListView.getChildCount();
MessageObject editingMessageObject = chatActivityEnterView != null ? chatActivityEnterView.getEditingMessageObject() : null;
long linkedChatId = chatInfo != null ? chatInfo.linked_chat_id : 0;
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject = cell.getMessageObject();
boolean disableSelection = false;
boolean selected = false;
if (actionBar.isActionModeShowed() || reportType >= 0) {
cell.setCheckBoxVisible(threadMessageObjects == null || !threadMessageObjects.contains(messageObject), true);
int idx = messageObject.getDialogId() == dialog_id ? 0 : 1;
if (selectedMessagesIds[idx].indexOfKey(messageObject.getId()) >= 0) {
setCellSelectionBackground(messageObject, cell, idx, true);
selected = true;
} else {
cell.setDrawSelectionBackground(false);
cell.setChecked(false, false, true);
}
disableSelection = true;
} else {
cell.setDrawSelectionBackground(false);
cell.setCheckBoxVisible(false, true);
cell.setChecked(false, false, true);
}
if (!cell.getMessageObject().deleted || cell.linkedChatId != linkedChatId) {
cell.setIsUpdating(true);
cell.linkedChatId = chatInfo != null ? chatInfo.linked_chat_id : 0;
cell.setMessageObject(cell.getMessageObject(), cell.getCurrentMessagesGroup(), cell.isPinnedBottom(), cell.isPinnedTop());
cell.setIsUpdating(false);
}
if (cell != scrimView) {
cell.setCheckPressed(!disableSelection, disableSelection && selected);
}
cell.setHighlighted(highlightMessageId != Integer.MAX_VALUE && messageObject != null && messageObject.getId() == highlightMessageId);
if (highlightMessageId != Integer.MAX_VALUE) {
startMessageUnselect();
}
if (searchContainer != null && searchContainer.getVisibility() == View.VISIBLE && getMediaDataController().isMessageFound(messageObject.getId(), messageObject.getDialogId() == mergeDialogId) && getMediaDataController().getLastSearchQuery() != null) {
cell.setHighlightedText(getMediaDataController().getLastSearchQuery());
} else {
cell.setHighlightedText(null);
}
cell.setSpoilersSuppressed(chatListView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE);
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
cell.setMessageObject(cell.getMessageObject());
cell.setSpoilersSuppressed(chatListView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE);
}
}
if (lastVisibleItem != RecyclerView.NO_POSITION) {
// chatLayoutManager.scrollToPositionWithOffset(lastVisibleItem, top);
}
}
Aggregations