use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method setCellSelectionBackground.
private void setCellSelectionBackground(MessageObject message, ChatMessageCell messageCell, int idx, boolean animated) {
MessageObject.GroupedMessages groupedMessages = getValidGroupedMessage(message);
if (groupedMessages != null) {
boolean hasUnselected = false;
for (int a = 0; a < groupedMessages.messages.size(); a++) {
if (selectedMessagesIds[idx].indexOfKey(groupedMessages.messages.get(a).getId()) < 0) {
hasUnselected = true;
break;
}
}
if (!hasUnselected) {
groupedMessages = null;
}
}
messageCell.setDrawSelectionBackground(groupedMessages == null);
messageCell.setChecked(true, groupedMessages == null, animated);
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method onConfigurationChanged.
@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
fixLayout();
if (visibleDialog instanceof DatePickerDialog) {
visibleDialog.dismiss();
}
closeMenu();
if (!AndroidUtilities.isTablet()) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
return;
}
MessageObject message = MediaController.getInstance().getPlayingMessageObject();
if (message != null && message.isVideo()) {
PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
getFileLoader().setLoadingVideoForPlayer(message.getDocument(), false);
MediaController.getInstance().cleanupPlayer(true, true, false, true);
if (PhotoViewer.getInstance().openPhoto(message, message.type != 0 ? dialog_id : 0, message.type != 0 ? mergeDialogId : 0, photoViewerProvider, false)) {
PhotoViewer.getInstance().setParentChatActivity(ChatActivity.this);
}
hideHints(false);
MediaController.getInstance().resetGoingToShowMessageObject();
}
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isOpenedFullScreenVideo()) {
PhotoViewer.getInstance().injectVideoPlayerToMediaController();
PhotoViewer.getInstance().closePhoto(false, true);
}
}
}
use of org.telegram.messenger.MessageObject 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.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method addToSelectedMessages.
private void addToSelectedMessages(MessageObject messageObject, boolean outside, boolean last) {
int prevCantForwardCount = cantForwardMessagesCount;
if (messageObject != null) {
if (threadMessageObjects != null && threadMessageObjects.contains(messageObject)) {
return;
}
int index = messageObject.getDialogId() == dialog_id ? 0 : 1;
if (outside && messageObject.getGroupId() != 0) {
boolean hasUnselected = false;
MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId());
if (groupedMessages != null) {
int lastNum = 0;
for (int a = 0; a < groupedMessages.messages.size(); a++) {
MessageObject message = groupedMessages.messages.get(a);
if (selectedMessagesIds[index].indexOfKey(message.getId()) < 0) {
hasUnselected = true;
lastNum = a;
}
}
for (int a = 0; a < groupedMessages.messages.size(); a++) {
MessageObject message = groupedMessages.messages.get(a);
if (hasUnselected) {
if (selectedMessagesIds[index].indexOfKey(message.getId()) < 0) {
addToSelectedMessages(message, false, a == lastNum);
}
} else {
addToSelectedMessages(message, false, a == groupedMessages.messages.size() - 1);
}
if (!TextUtils.isEmpty(message.caption)) {
showTextSelectionHint(messageObject);
}
}
}
return;
}
if (selectedMessagesIds[index].indexOfKey(messageObject.getId()) >= 0) {
selectedMessagesIds[index].remove(messageObject.getId());
if (reportType < 0) {
if ((messageObject.type == 0 || messageObject.isAnimatedEmoji() || messageObject.caption != null) && !(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) {
selectedMessagesCanCopyIds[index].remove(messageObject.getId());
}
if (!messageObject.isAnimatedEmoji() && (messageObject.isSticker() || messageObject.isAnimatedSticker()) && MessageObject.isStickerHasSet(messageObject.getDocument())) {
selectedMessagesCanStarIds[index].remove(messageObject.getId());
}
if (messageObject.canEditMessage(currentChat)) {
canEditMessagesCount--;
}
if (!messageObject.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat)) {
cantDeleteMessagesCount--;
}
boolean noforwards = getMessagesController().isChatNoForwards(currentChat);
if (chatMode == MODE_SCHEDULED || !messageObject.canForwardMessage() || noforwards) {
cantForwardMessagesCount--;
} else {
canForwardMessagesCount--;
}
if (messageObject.isMusic() && !noforwards) {
canSaveMusicCount--;
} else if (messageObject.isDocument() && !noforwards) {
canSaveDocumentsCount--;
} else {
cantSaveMessagesCount--;
}
}
} else {
if (selectedMessagesIds[0].size() + selectedMessagesIds[1].size() >= 100) {
AndroidUtilities.shakeView(selectedMessagesCountTextView, 2, 0);
Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null) {
vibrator.vibrate(200);
}
return;
}
selectedMessagesIds[index].put(messageObject.getId(), messageObject);
if (reportType < 0) {
if ((messageObject.type == 0 || messageObject.isAnimatedEmoji() || messageObject.caption != null) && !(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) {
selectedMessagesCanCopyIds[index].put(messageObject.getId(), messageObject);
}
if (!messageObject.isAnimatedEmoji() && (messageObject.isSticker() || messageObject.isAnimatedSticker()) && MessageObject.isStickerHasSet(messageObject.getDocument())) {
selectedMessagesCanStarIds[index].put(messageObject.getId(), messageObject);
}
if (messageObject.canEditMessage(currentChat)) {
canEditMessagesCount++;
}
if (!messageObject.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat)) {
cantDeleteMessagesCount++;
}
boolean noforwards = getMessagesController().isChatNoForwards(currentChat);
if (chatMode == MODE_SCHEDULED || !messageObject.canForwardMessage() || noforwards) {
cantForwardMessagesCount++;
} else {
canForwardMessagesCount++;
}
if (messageObject.isMusic() && !noforwards) {
canSaveMusicCount++;
} else if (messageObject.isDocument() && !noforwards) {
canSaveDocumentsCount++;
} else {
cantSaveMessagesCount++;
}
if (outside) {
showTextSelectionHint(messageObject);
}
}
}
}
if (forwardButtonAnimation != null) {
forwardButtonAnimation.cancel();
forwardButtonAnimation = null;
}
if (last && actionBar.isActionModeShowed() && reportType < 0) {
int selectedCount = selectedMessagesIds[0].size() + selectedMessagesIds[1].size();
if (selectedCount == 0) {
hideActionMode();
updatePinnedMessageView(true);
} else {
ActionBarMenuItem saveItem = actionBar.createActionMode().getItem(save_to);
ActionBarMenuItem copyItem = actionBar.createActionMode().getItem(copy);
ActionBarMenuItem starItem = actionBar.createActionMode().getItem(star);
ActionBarMenuItem editItem = actionBar.createActionMode().getItem(edit);
ActionBarMenuItem forwardItem = actionBar.createActionMode().getItem(forward);
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || hasSelectedNoforwardsMessage();
if (prevCantForwardCount == 0 && cantForwardMessagesCount != 0 || prevCantForwardCount != 0 && cantForwardMessagesCount == 0) {
forwardButtonAnimation = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
if (forwardItem != null) {
forwardItem.setEnabled(cantForwardMessagesCount == 0 || noforwards);
animators.add(ObjectAnimator.ofFloat(forwardItem, View.ALPHA, cantForwardMessagesCount == 0 ? 1.0f : 0.5f));
if (noforwards && forwardItem.getBackground() != null) {
forwardItem.setBackground(null);
} else if (forwardItem.getBackground() == null) {
forwardItem.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 5));
}
}
if (forwardButton != null) {
forwardButton.setEnabled(cantForwardMessagesCount == 0 || noforwards);
if (noforwards && forwardButton.getBackground() != null) {
forwardButton.setBackground(null);
} else if (forwardButton.getBackground() == null) {
forwardButton.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
}
animators.add(ObjectAnimator.ofFloat(forwardButton, View.ALPHA, cantForwardMessagesCount == 0 ? 1.0f : 0.5f));
}
forwardButtonAnimation.playTogether(animators);
forwardButtonAnimation.setDuration(100);
forwardButtonAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
forwardButtonAnimation = null;
}
});
forwardButtonAnimation.start();
} else {
if (forwardItem != null) {
forwardItem.setEnabled(cantForwardMessagesCount == 0 || noforwards);
forwardItem.setAlpha(cantForwardMessagesCount == 0 ? 1.0f : 0.5f);
if (noforwards) {
if (forwardItem.getBackground() != null)
forwardButton.setBackground(null);
} else if (forwardItem.getBackground() == null) {
forwardItem.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
}
}
if (forwardButton != null) {
forwardButton.setEnabled(cantForwardMessagesCount == 0 || noforwards);
if (noforwards) {
if (forwardButton.getBackground() != null)
forwardButton.setBackground(null);
} else if (forwardButton.getBackground() == null) {
forwardButton.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
}
forwardButton.setAlpha(cantForwardMessagesCount == 0 ? 1.0f : 0.5f);
}
}
if (saveItem != null) {
saveItem.setVisibility(((canSaveMusicCount > 0 && canSaveDocumentsCount == 0) || (canSaveMusicCount == 0 && canSaveDocumentsCount > 0)) && cantSaveMessagesCount == 0 ? View.VISIBLE : View.GONE);
saveItem.setContentDescription(canSaveMusicCount > 0 ? LocaleController.getString("SaveToMusic", R.string.SaveToMusic) : LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
}
int copyVisible = copyItem.getVisibility();
int starVisible = starItem.getVisibility();
copyItem.setVisibility(!noforwards && selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() != 0 ? View.VISIBLE : View.GONE);
starItem.setVisibility(getMediaDataController().canAddStickerToFavorites() && (selectedMessagesCanStarIds[0].size() + selectedMessagesCanStarIds[1].size()) == selectedCount ? View.VISIBLE : View.GONE);
int newCopyVisible = copyItem.getVisibility();
int newStarVisible = starItem.getVisibility();
actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
hasUnfavedSelected = false;
for (int a = 0; a < 2; a++) {
for (int b = 0; b < selectedMessagesCanStarIds[a].size(); b++) {
MessageObject msg = selectedMessagesCanStarIds[a].valueAt(b);
if (!getMediaDataController().isStickerInFavorites(msg.getDocument())) {
hasUnfavedSelected = true;
break;
}
}
if (hasUnfavedSelected) {
break;
}
}
starItem.setIcon(hasUnfavedSelected ? R.drawable.msg_fave : R.drawable.msg_unfave);
final int newEditVisibility = canEditMessagesCount == 1 && selectedCount == 1 ? View.VISIBLE : View.GONE;
if (replyButton != null) {
boolean allowChatActions = true;
if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() == View.VISIBLE || currentChat != null && (ChatObject.isNotInChat(currentChat) && !isThreadChat() || ChatObject.isChannel(currentChat) && !ChatObject.canPost(currentChat) && !currentChat.megagroup || !ChatObject.canSendMessages(currentChat))) {
allowChatActions = false;
}
int newVisibility;
if (chatMode == MODE_SCHEDULED || !allowChatActions || selectedMessagesIds[0].size() != 0 && selectedMessagesIds[1].size() != 0) {
newVisibility = View.GONE;
} else if (selectedCount == 1) {
newVisibility = View.VISIBLE;
} else {
newVisibility = View.VISIBLE;
long lastGroupId = 0;
for (int a = 0; a < 2; a++) {
for (int b = 0, N = selectedMessagesIds[a].size(); b < N; b++) {
MessageObject message = selectedMessagesIds[a].valueAt(b);
long groupId = message.getGroupId();
if (groupId == 0 || lastGroupId != 0 && lastGroupId != groupId) {
newVisibility = View.GONE;
break;
}
lastGroupId = groupId;
}
if (newVisibility == View.GONE) {
break;
}
}
}
if (threadMessageObjects != null && newVisibility == View.VISIBLE) {
for (int b = 0, N = selectedMessagesIds[0].size(); b < N; b++) {
MessageObject message = selectedMessagesIds[0].valueAt(b);
if (threadMessageObjects.contains(message)) {
newVisibility = View.GONE;
}
}
}
if (replyButton.getVisibility() != newVisibility) {
if (replyButtonAnimation != null) {
replyButtonAnimation.cancel();
}
replyButtonAnimation = new AnimatorSet();
if (newVisibility == View.VISIBLE) {
replyButton.setVisibility(newVisibility);
replyButtonAnimation.playTogether(ObjectAnimator.ofFloat(replyButton, View.ALPHA, 1.0f), ObjectAnimator.ofFloat(replyButton, View.SCALE_Y, 1.0f));
} else {
replyButtonAnimation.playTogether(ObjectAnimator.ofFloat(replyButton, View.ALPHA, 0.0f), ObjectAnimator.ofFloat(replyButton, View.SCALE_Y, 0.0f));
}
replyButtonAnimation.setDuration(100);
int newVisibilityFinal = newVisibility;
replyButtonAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
if (newVisibilityFinal == View.GONE) {
replyButton.setVisibility(View.GONE);
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
replyButtonAnimation = null;
}
}
});
replyButtonAnimation.start();
}
}
if (editItem != null) {
if (copyVisible != newCopyVisible || starVisible != newStarVisible) {
if (newEditVisibility == View.VISIBLE) {
editItem.setAlpha(1.0f);
editItem.setScaleX(1.0f);
} else {
editItem.setAlpha(0.0f);
editItem.setScaleX(0.0f);
}
editItem.setVisibility(newEditVisibility);
} else if (editItem.getVisibility() != newEditVisibility) {
if (editButtonAnimation != null) {
editButtonAnimation.cancel();
}
editButtonAnimation = new AnimatorSet();
editItem.setPivotX(AndroidUtilities.dp(54));
editItem.setPivotX(AndroidUtilities.dp(54));
if (newEditVisibility == View.VISIBLE) {
editItem.setVisibility(newEditVisibility);
editButtonAnimation.playTogether(ObjectAnimator.ofFloat(editItem, View.ALPHA, 1.0f), ObjectAnimator.ofFloat(editItem, View.SCALE_X, 1.0f));
} else {
editButtonAnimation.playTogether(ObjectAnimator.ofFloat(editItem, View.ALPHA, 0.0f), ObjectAnimator.ofFloat(editItem, View.SCALE_X, 0.0f));
}
editButtonAnimation.setDuration(100);
editButtonAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (editButtonAnimation != null && editButtonAnimation.equals(animation)) {
if (newEditVisibility == View.GONE) {
editItem.setVisibility(View.GONE);
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
if (editButtonAnimation != null && editButtonAnimation.equals(animation)) {
editButtonAnimation = null;
}
}
});
editButtonAnimation.start();
}
}
}
}
}
use of org.telegram.messenger.MessageObject 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);
}
});
}
Aggregations