use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method maybePlayVisibleVideo.
public boolean maybePlayVisibleVideo() {
if (chatListView == null) {
return false;
}
MessageObject playingMessage = MediaController.getInstance().getPlayingMessageObject();
if (playingMessage != null && !playingMessage.isVideo()) {
return false;
}
MessageObject visibleMessage = null;
AnimatedFileDrawable visibleAnimation = null;
if (noSoundHintView != null && noSoundHintView.getTag() != null) {
ChatMessageCell cell = noSoundHintView.getMessageCell();
ImageReceiver imageReceiver = cell.getPhotoImage();
visibleAnimation = imageReceiver.getAnimation();
if (visibleAnimation != null) {
visibleMessage = cell.getMessageObject();
scrollToVideo = cell.getTop() + imageReceiver.getImageY2() > chatListView.getMeasuredHeight();
}
}
if (visibleMessage == null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View child = chatListView.getChildAt(a);
if (!(child instanceof ChatMessageCell)) {
continue;
}
ChatMessageCell messageCell = (ChatMessageCell) child;
MessageObject messageObject = messageCell.getMessageObject();
boolean isRoundVideo = messageObject.isRoundVideo();
if ((!messageObject.isVideo() && !isRoundVideo) || messageObject.videoEditedInfo != null) {
continue;
}
ImageReceiver imageReceiver = messageCell.getPhotoImage();
AnimatedFileDrawable animation = imageReceiver.getAnimation();
if (animation == null) {
continue;
}
float top = child.getTop() + imageReceiver.getImageY();
float bottom = top + imageReceiver.getImageHeight();
if (bottom < 0 || top > chatListView.getMeasuredHeight()) {
continue;
}
if (visibleMessage != null && top < 0) {
break;
}
visibleMessage = messageObject;
visibleAnimation = animation;
scrollToVideo = top < 0 || bottom > chatListView.getMeasuredHeight();
if (top >= 0 && bottom <= chatListView.getMeasuredHeight()) {
break;
}
}
}
if (visibleMessage != null) {
if (MediaController.getInstance().isPlayingMessage(visibleMessage)) {
return false;
}
hideHints(true);
if (visibleMessage.isRoundVideo()) {
boolean result = MediaController.getInstance().playMessage(visibleMessage);
MediaController.getInstance().setVoiceMessagesPlaylist(result ? createVoiceMessagesPlaylist(visibleMessage, false) : null, false);
return result;
} else {
SharedConfig.setNoSoundHintShowed(true);
visibleMessage.audioProgress = visibleAnimation.getCurrentProgress();
visibleMessage.audioProgressMs = visibleAnimation.getCurrentProgressMs();
visibleAnimation.stop();
if (PhotoViewer.isPlayingMessageInPip(visibleMessage)) {
PhotoViewer.getPipInstance().destroyPhotoViewer();
}
return MediaController.getInstance().playMessage(visibleMessage);
}
}
return false;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method onPause.
@Override
public void onPause() {
super.onPause();
if (scrimPopupWindow != null) {
scrimPopupWindow.setPauseNotifications(false);
closeMenu();
}
int replyId = threadMessageId;
getMessagesController().markDialogAsReadNow(dialog_id, replyId);
MediaController.getInstance().stopRaiseToEarSensors(this, true);
paused = true;
wasPaused = true;
if (chatMode == 0) {
getNotificationsController().setOpenedDialogId(0);
}
Bulletin.removeDelegate(this);
getMessagesController().setLastVisibleDialogId(dialog_id, chatMode == MODE_SCHEDULED, false);
CharSequence draftMessage = null;
MessageObject replyMessage = null;
boolean searchWebpage = true;
if (!ignoreAttachOnPause && chatActivityEnterView != null && bottomOverlayChat != null && bottomOverlayChat.getVisibility() != View.VISIBLE) {
chatActivityEnterView.onPause();
replyMessage = replyingMessageObject;
draftMessage = AndroidUtilities.getTrimmedString(chatActivityEnterView.getDraftMessage());
searchWebpage = chatActivityEnterView.isMessageWebPageSearchEnabled();
chatActivityEnterView.setFieldFocused(false);
}
if (chatAttachAlert != null) {
if (!ignoreAttachOnPause) {
chatAttachAlert.onPause();
} else {
ignoreAttachOnPause = false;
}
}
if (contentView != null) {
contentView.onPause();
}
if (chatMode == 0) {
CharSequence[] message = new CharSequence[] { draftMessage };
ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 101);
getMediaDataController().saveDraft(dialog_id, threadMessageId, message[0], entities, replyMessage != null ? replyMessage.messageOwner : null, !searchWebpage);
getMessagesController().cancelTyping(0, dialog_id, threadMessageId);
if (!pausedOnLastMessage && !firstLoading) {
SharedPreferences.Editor editor = MessagesController.getNotificationsSettings(currentAccount).edit();
int messageId = 0;
int offset = 0;
if (chatLayoutManager != null) {
boolean sponsoredMessageFound = false;
for (int i = 0; i < chatListView.getChildCount(); i++) {
if (chatListView.getChildAt(i) instanceof ChatMessageCell && ((ChatMessageCell) chatListView.getChildAt(i)).getMessageObject().isSponsored()) {
sponsoredMessageFound = true;
break;
}
}
int position = chatLayoutManager.findFirstVisibleItemPosition();
if (position != 0 && !sponsoredMessageFound) {
RecyclerListView.Holder holder = (RecyclerListView.Holder) chatListView.findViewHolderForAdapterPosition(position);
if (holder != null) {
int mid = 0;
if (holder.itemView instanceof ChatMessageCell) {
mid = ((ChatMessageCell) holder.itemView).getMessageObject().getId();
} else if (holder.itemView instanceof ChatActionCell) {
mid = ((ChatActionCell) holder.itemView).getMessageObject().getId();
}
if (mid == 0) {
holder = (RecyclerListView.Holder) chatListView.findViewHolderForAdapterPosition(position + 1);
}
boolean ignore = false;
int count = 0;
for (int a = position - 1; a >= chatAdapter.messagesStartRow; a--) {
int num = a - chatAdapter.messagesStartRow;
if (num < 0 || num >= messages.size()) {
continue;
}
MessageObject messageObject = messages.get(num);
if (messageObject.getId() == 0) {
continue;
}
if ((!messageObject.isOut() || messageObject.messageOwner.from_scheduled) && messageObject.isUnread()) {
ignore = true;
messageId = 0;
}
if (count > 2) {
break;
}
count++;
}
if (holder != null && !ignore) {
if (holder.itemView instanceof ChatMessageCell) {
messageId = ((ChatMessageCell) holder.itemView).getMessageObject().getId();
} else if (holder.itemView instanceof ChatActionCell) {
messageId = ((ChatActionCell) holder.itemView).getMessageObject().getId();
}
if (messageId > 0 && currentEncryptedChat == null || messageId < 0 && currentEncryptedChat != null) {
offset = holder.itemView.getBottom() - chatListView.getMeasuredHeight();
if (BuildVars.LOGS_ENABLED) {
FileLog.d("save offset = " + offset + " for mid " + messageId);
}
} else {
messageId = 0;
}
}
}
}
}
if (messageId != 0) {
editor.putInt("diditem" + dialog_id, messageId);
editor.putInt("diditemo" + dialog_id, offset);
} else {
pausedOnLastMessage = true;
editor.remove("diditem" + dialog_id);
editor.remove("diditemo" + dialog_id);
}
editor.commit();
}
if (currentUser != null) {
chatLeaveTime = System.currentTimeMillis();
updateInformationForScreenshotDetector();
}
hideUndoViews();
}
if (chatListItemAnimator != null) {
chatListItemAnimator.endAnimations();
}
if (chatScrollHelper != null) {
chatScrollHelper.cancel();
}
if (AvatarPreviewer.hasVisibleInstance()) {
AvatarPreviewer.getInstance().close();
}
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method setInPreviewMode.
@Override
protected void setInPreviewMode(boolean value) {
super.setInPreviewMode(value);
if (avatarContainer != null) {
avatarContainer.setOccupyStatusBar(!value);
avatarContainer.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, !value ? 56 : (chatMode == MODE_PINNED ? 10 : 0), 0, 40, 0));
}
if (chatActivityEnterView != null) {
chatActivityEnterView.setVisibility(!value ? View.VISIBLE : View.INVISIBLE);
}
if (actionBar != null) {
actionBar.setBackButtonDrawable(!value ? new BackDrawable(false) : null);
if (headerItem != null) {
headerItem.setAlpha(!value ? 1.0f : 0.0f);
}
if (attachItem != null) {
attachItem.setAlpha(!value ? 1.0f : 0.0f);
}
}
if (chatListView != null) {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
MessageObject message = null;
if (view instanceof ChatMessageCell) {
message = ((ChatMessageCell) view).getMessageObject();
} else if (view instanceof ChatActionCell) {
message = ((ChatActionCell) view).getMessageObject();
}
if (message != null && message.messageOwner != null && message.messageOwner.media_unread && message.messageOwner.mentioned) {
if (!message.isVoice() && !message.isRoundVideo()) {
newMentionsCount--;
if (newMentionsCount <= 0) {
newMentionsCount = 0;
hasAllMentionsLocal = true;
showMentionDownButton(false, true);
} else {
mentiondownButtonCounter.setText(String.format("%d", newMentionsCount));
}
getMessagesController().markMentionMessageAsRead(message.getId(), ChatObject.isChannel(currentChat) ? currentChat.id : 0, dialog_id);
message.setContentIsRead();
}
if (view instanceof ChatMessageCell) {
((ChatMessageCell) view).setHighlighted(false);
((ChatMessageCell) view).setHighlightedAnimated();
}
}
}
chatListView.setItemAnimator(null);
}
updateBottomOverlay();
updateSecretStatus();
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method checkSecretMessageForLocation.
private void checkSecretMessageForLocation(MessageObject messageObject) {
if (messageObject.type != 4 || locationAlertShown || SharedConfig.isSecretMapPreviewSet()) {
return;
}
locationAlertShown = true;
AlertsCreator.showSecretLocationAlert(getParentActivity(), currentAccount, () -> {
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject message = cell.getMessageObject();
if (message.type == 4) {
cell.forceResetMessageObject();
}
}
}
}, true, themeDelegate);
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method showNoSoundHint.
private void showNoSoundHint() {
if (scrollingChatListView || SharedConfig.noSoundHintShowed || chatListView == null || getParentActivity() == null || fragmentView == null || noSoundHintView != null && noSoundHintView.getTag() != null) {
return;
}
if (noSoundHintView == null) {
SizeNotifierFrameLayout frameLayout = (SizeNotifierFrameLayout) fragmentView;
int index = frameLayout.indexOfChild(chatActivityEnterView);
if (index == -1) {
return;
}
noSoundHintView = new HintView(getParentActivity(), 0, themeDelegate);
noSoundHintView.setShowingDuration(10000);
frameLayout.addView(noSoundHintView, index + 1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
noSoundHintView.setAlpha(0.0f);
noSoundHintView.setVisibility(View.INVISIBLE);
}
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View child = chatListView.getChildAt(a);
if (!(child instanceof ChatMessageCell)) {
continue;
}
ChatMessageCell messageCell = (ChatMessageCell) child;
MessageObject messageObject = messageCell.getMessageObject();
if (messageObject == null || !messageObject.isVideo()) {
continue;
}
ImageReceiver imageReceiver = messageCell.getPhotoImage();
AnimatedFileDrawable animation = imageReceiver.getAnimation();
if (animation == null || animation.getCurrentProgressMs() < 3000) {
continue;
}
if (noSoundHintView.showForMessageCell(messageCell, true)) {
SharedConfig.setNoSoundHintShowed(true);
break;
}
}
}
Aggregations