use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelAdminLogActivity method updateMessagesVisisblePart.
private void updateMessagesVisisblePart() {
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;
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell messageCell = (ChatMessageCell) view;
int top = messageCell.getTop();
int bottom = messageCell.getBottom();
int viewTop = top >= 0 ? 0 : -top;
int viewBottom = messageCell.getMeasuredHeight();
if (viewBottom > height) {
viewBottom = viewTop + height;
}
messageCell.setVisiblePart(viewTop, viewBottom - viewTop, contentView.getHeightWithKeyboard() - AndroidUtilities.dp(48) - chatListView.getTop(), 0, view.getY() + actionBar.getMeasuredHeight() - contentView.getBackgroundTranslationY(), contentView.getMeasuredWidth(), contentView.getBackgroundSizeY());
MessageObject messageObject = messageCell.getMessageObject();
if (roundVideoContainer != null && messageObject.isRoundVideo() && MediaController.getInstance().isPlayingMessage(messageObject)) {
ImageReceiver imageReceiver = messageCell.getPhotoImage();
roundVideoContainer.setTranslationX(imageReceiver.getImageX());
roundVideoContainer.setTranslationY(fragmentView.getPaddingTop() + top + imageReceiver.getImageY());
fragmentView.invalidate();
roundVideoContainer.invalidate();
foundTextureViewMessage = true;
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
cell.setVisiblePart(view.getY() + actionBar.getMeasuredHeight() - contentView.getBackgroundTranslationY(), contentView.getBackgroundSizeY());
}
if (view.getBottom() <= chatListView.getPaddingTop()) {
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 && ((ChatActionCell) view).getMessageObject().isDateObject) {
if (view.getAlpha() != 1.0f) {
view.setAlpha(1.0f);
}
if (position < minPositionDateHolder) {
minPositionDateHolder = position;
minDateChild = view;
}
}
}
}
if (roundVideoContainer != null) {
if (!foundTextureViewMessage) {
roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
fragmentView.invalidate();
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isRoundVideo() && checkTextureViewPosition) {
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, false, true);
}
currentFloatingDateOnScreen = false;
currentFloatingTopIsNotMessage = !(minChild instanceof ChatMessageCell || minChild instanceof ChatActionCell);
if (minDateChild != null) {
if (minDateChild.getTop() > chatListView.getPaddingTop() || currentFloatingTopIsNotMessage) {
if (minDateChild.getAlpha() != 1.0f) {
minDateChild.setAlpha(1.0f);
}
hideFloatingDateView(!currentFloatingTopIsNotMessage);
} else {
if (minDateChild.getAlpha() != 0.0f) {
minDateChild.setAlpha(0.0f);
}
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;
}
int offset = minDateChild.getBottom() - chatListView.getPaddingTop();
if (offset > floatingDateView.getMeasuredHeight() && offset < floatingDateView.getMeasuredHeight() * 2) {
floatingDateView.setTranslationY(-floatingDateView.getMeasuredHeight() * 2 + offset);
} else {
floatingDateView.setTranslationY(0);
}
} else {
hideFloatingDateView(true);
floatingDateView.setTranslationY(0);
}
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelAdminLogActivity method createView.
@Override
public View createView(Context context) {
if (chatMessageCellsCache.isEmpty()) {
for (int a = 0; a < 8; a++) {
chatMessageCellsCache.add(new ChatMessageCell(context));
}
}
searchWas = false;
hasOwnBackground = true;
Theme.createChatResources(context, false);
actionBar.setAddToContainer(false);
actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
actionBar.setBackButtonDrawable(new BackDrawable(false));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
if (id == -1) {
finishFragment();
}
}
});
avatarContainer = new ChatAvatarContainer(context, null, false);
avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet());
actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchCollapse() {
searchQuery = "";
avatarContainer.setVisibility(View.VISIBLE);
if (searchWas) {
searchWas = false;
loadMessages(true);
}
/*highlightMessageId = Integer.MAX_VALUE;
updateVisibleRows();
scrollToLastMessage(false);
*/
updateBottomOverlay();
}
@Override
public void onSearchExpand() {
avatarContainer.setVisibility(View.GONE);
updateBottomOverlay();
}
@Override
public void onSearchPressed(EditText editText) {
searchWas = true;
searchQuery = editText.getText().toString();
loadMessages(true);
// updateSearchButtons(0, 0, 0);
}
});
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
avatarContainer.setEnabled(false);
avatarContainer.setTitle(currentChat.title);
avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
avatarContainer.setChatAvatar(currentChat);
fragmentView = new SizeNotifierFrameLayout(context) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0 && messageObject.getDialogId() == -currentChat.id) {
MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout, roundVideoContainer, true);
}
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == actionBar && parentLayout != null) {
parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
}
return result;
}
@Override
protected boolean isActionBarVisible() {
return actionBar.getVisibility() == VISIBLE;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int allHeight;
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
heightSize -= getPaddingTop();
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int actionBarHeight = actionBar.getMeasuredHeight();
if (actionBar.getVisibility() == VISIBLE) {
heightSize -= actionBarHeight;
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
if (child == chatListView || child == progressView) {
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
int contentHeightSpec = MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)), MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else if (child == emptyViewContainer) {
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
if (child != actionBar && actionBar.getVisibility() == VISIBLE) {
childTop += actionBar.getMeasuredHeight();
}
break;
case Gravity.CENTER_VERTICAL:
childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = (b - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (child == emptyViewContainer) {
childTop -= AndroidUtilities.dp(24) - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0);
} else if (child == actionBar) {
childTop -= getPaddingTop();
} else if (child == backgroundView) {
childTop = 0;
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
updateMessagesVisisblePart();
notifyHeightChanged();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (AvatarPreviewer.hasVisibleInstance()) {
AvatarPreviewer.getInstance().onTouchEvent(ev);
return true;
}
return super.dispatchTouchEvent(ev);
}
};
contentView = (SizeNotifierFrameLayout) fragmentView;
contentView.setOccupyStatusBar(!AndroidUtilities.isTablet());
contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
emptyViewContainer = new FrameLayout(context);
emptyViewContainer.setVisibility(View.INVISIBLE);
contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
emptyViewContainer.setOnTouchListener((v, event) -> true);
emptyView = new TextView(context);
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
emptyView.setGravity(Gravity.CENTER);
emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText));
emptyView.setBackground(Theme.createServiceDrawable(AndroidUtilities.dp(6), emptyView, contentView));
emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16));
emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0));
chatListView = new RecyclerListView(context) {
@Override
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child instanceof ChatMessageCell) {
ChatMessageCell chatMessageCell = (ChatMessageCell) child;
ImageReceiver imageReceiver = chatMessageCell.getAvatarImage();
if (imageReceiver != null) {
if (chatMessageCell.getMessageObject().deleted) {
imageReceiver.setVisible(false, false);
return result;
}
int top = (int) child.getY();
if (chatMessageCell.drawPinnedBottom()) {
int p;
ViewHolder holder = chatListView.getChildViewHolder(child);
p = holder.getAdapterPosition();
if (p >= 0) {
int nextPosition;
nextPosition = p + 1;
holder = chatListView.findViewHolderForAdapterPosition(nextPosition);
if (holder != null) {
imageReceiver.setVisible(false, false);
return result;
}
}
}
float tx = chatMessageCell.getSlidingOffsetX() + chatMessageCell.getCheckBoxTranslation();
int y = (int) child.getY() + chatMessageCell.getLayoutHeight();
int maxY = chatListView.getMeasuredHeight() - chatListView.getPaddingBottom();
if (y > maxY) {
y = maxY;
}
if (chatMessageCell.drawPinnedTop()) {
int p;
ViewHolder holder = chatListView.getChildViewHolder(child);
p = holder.getAdapterPosition();
if (p >= 0) {
int tries = 0;
while (true) {
if (tries >= 20) {
break;
}
tries++;
int prevPosition;
prevPosition = p - 1;
holder = chatListView.findViewHolderForAdapterPosition(prevPosition);
if (holder != null) {
top = holder.itemView.getTop();
if (holder.itemView instanceof ChatMessageCell) {
chatMessageCell = (ChatMessageCell) holder.itemView;
if (!chatMessageCell.drawPinnedTop()) {
break;
} else {
p = prevPosition;
}
} else {
break;
}
} else {
break;
}
}
}
}
if (y - AndroidUtilities.dp(48) < top) {
y = top + AndroidUtilities.dp(48);
}
if (!chatMessageCell.drawPinnedBottom()) {
int cellBottom = (int) (chatMessageCell.getY() + chatMessageCell.getMeasuredHeight());
if (y > cellBottom) {
y = cellBottom;
}
}
canvas.save();
if (tx != 0) {
canvas.translate(tx, 0);
}
if (chatMessageCell.getCurrentMessagesGroup() != null) {
if (chatMessageCell.getCurrentMessagesGroup().transitionParams.backgroundChangeBounds) {
y -= chatMessageCell.getTranslationY();
}
}
imageReceiver.setImageY(y - AndroidUtilities.dp(44));
if (chatMessageCell.shouldDrawAlphaLayer()) {
imageReceiver.setAlpha(chatMessageCell.getAlpha());
canvas.scale(chatMessageCell.getScaleX(), chatMessageCell.getScaleY(), chatMessageCell.getX() + chatMessageCell.getPivotX(), chatMessageCell.getY() + (chatMessageCell.getHeight() >> 1));
} else {
imageReceiver.setAlpha(1f);
}
imageReceiver.setVisible(true, false);
imageReceiver.draw(canvas);
canvas.restore();
}
}
return result;
}
};
chatListView.setOnItemClickListener((view, position) -> createMenu(view));
chatListView.setTag(1);
chatListView.setVerticalScrollBarEnabled(true);
chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
chatListView.setClipToPadding(false);
chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
chatListView.setItemAnimator(chatListItemAnimator = new ChatListItemAnimator(null, chatListView, null) {
int scrollAnimationIndex = -1;
Runnable finishRunnable;
public void onAnimationStart() {
if (scrollAnimationIndex == -1) {
scrollAnimationIndex = getNotificationCenter().setAnimationInProgress(scrollAnimationIndex, null, false);
}
if (finishRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(finishRunnable);
finishRunnable = null;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("admin logs chatItemAnimator disable notifications");
}
}
@Override
protected void onAllAnimationsDone() {
super.onAllAnimationsDone();
if (finishRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(finishRunnable);
}
AndroidUtilities.runOnUIThread(finishRunnable = () -> {
if (scrollAnimationIndex != -1) {
getNotificationCenter().onAnimationFinish(scrollAnimationIndex);
scrollAnimationIndex = -1;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("admin logs chatItemAnimator enable notifications");
}
});
}
});
chatListItemAnimator.setReversePositions(true);
chatListView.setLayoutAnimation(null);
chatLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean supportsPredictiveItemAnimations() {
return true;
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScrollerCustom linearSmoothScroller = new LinearSmoothScrollerCustom(recyclerView.getContext(), LinearSmoothScrollerCustom.POSITION_MIDDLE);
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
};
chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
chatLayoutManager.setStackFromEnd(true);
chatListView.setLayoutManager(chatLayoutManager);
contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
private float totalDy = 0;
private final int scrollValue = AndroidUtilities.dp(100);
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
scrollingFloatingDate = true;
checkTextureViewPosition = true;
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
scrollingFloatingDate = false;
checkTextureViewPosition = false;
hideFloatingDateView(true);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
chatListView.invalidate();
if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) {
if (floatingDateView.getTag() == null) {
if (floatingDateAnimation != null) {
floatingDateAnimation.cancel();
}
floatingDateView.setTag(1);
floatingDateAnimation = new AnimatorSet();
floatingDateAnimation.setDuration(150);
floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f));
floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation.equals(floatingDateAnimation)) {
floatingDateAnimation = null;
}
}
});
floatingDateAnimation.start();
}
}
checkScrollForLoad(true);
updateMessagesVisisblePart();
}
});
if (scrollToPositionOnRecreate != -1) {
chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
scrollToPositionOnRecreate = -1;
}
progressView = new FrameLayout(context);
progressView.setVisibility(View.INVISIBLE);
contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
progressView2 = new View(context);
progressView2.setBackground(Theme.createServiceDrawable(AndroidUtilities.dp(18), progressView2, contentView));
progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
progressBar = new RadialProgressView(context);
progressBar.setSize(AndroidUtilities.dp(28));
progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText));
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
floatingDateView = new ChatActionCell(context);
floatingDateView.setAlpha(0.0f);
floatingDateView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0));
contentView.addView(actionBar);
bottomOverlayChat = new FrameLayout(context) {
@Override
public void onDraw(Canvas canvas) {
int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
};
bottomOverlayChat.setWillNotDraw(false);
bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
bottomOverlayChat.setOnClickListener(view -> {
if (getParentActivity() == null) {
return;
}
AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter, selectedAdmins, currentChat.megagroup);
adminLogFilterAlert.setCurrentAdmins(admins);
adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> {
currentFilter = filter;
selectedAdmins = admins;
if (currentFilter != null || selectedAdmins != null) {
avatarContainer.setSubtitle(LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents));
} else {
avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
}
loadMessages(true);
});
showDialog(adminLogFilterAlert);
});
bottomOverlayChatText = new TextView(context);
bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase());
bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
bottomOverlayImage = new ImageView(context);
bottomOverlayImage.setImageResource(R.drawable.log_info);
bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText), PorterDuff.Mode.MULTIPLY));
bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER);
bottomOverlayChat.addView(bottomOverlayImage, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0));
bottomOverlayImage.setContentDescription(LocaleController.getString("BotHelp", R.string.BotHelp));
bottomOverlayImage.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (currentChat.megagroup) {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail)));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel)));
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle));
showDialog(builder.create());
});
searchContainer = new FrameLayout(context) {
@Override
public void onDraw(Canvas canvas) {
int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
};
searchContainer.setWillNotDraw(false);
searchContainer.setVisibility(View.INVISIBLE);
searchContainer.setFocusable(true);
searchContainer.setFocusableInTouchMode(true);
searchContainer.setClickable(true);
searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
/*searchUpButton = new ImageView(context);
searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
searchUpButton.setImageResource(R.drawable.msg_go_up);
searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
searchUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
}
});
searchDownButton = new ImageView(context);
searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
searchDownButton.setImageResource(R.drawable.msg_go_down);
searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
searchDownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
}
});*/
searchCalendarButton = new ImageView(context);
searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER);
searchCalendarButton.setImageResource(R.drawable.msg_calendar);
searchCalendarButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchCalendarButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
searchCalendarButton.setOnClickListener(view -> {
if (getParentActivity() == null) {
return;
}
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
showDialog(AlertsCreator.createCalendarPickerDialog(getParentActivity(), 1375315200000L, param -> loadMessages(true), null).create());
});
searchCountText = new SimpleTextView(context);
searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText));
searchCountText.setTextSize(15);
searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));
chatAdapter.updateRows();
if (loading && messages.isEmpty()) {
AndroidUtilities.updateViewVisibilityAnimated(progressView, true, 0.3f, true);
chatListView.setEmptyView(null);
} else {
AndroidUtilities.updateViewVisibilityAnimated(progressView, false, 0.3f, true);
chatListView.setEmptyView(emptyViewContainer);
}
chatListView.setAnimateEmptyView(true, 1);
undoView = new UndoView(context);
undoView.setAdditionalTranslationY(AndroidUtilities.dp(51));
contentView.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
updateEmptyPlaceholder();
return fragmentView;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class RecyclerAnimationScrollHelper method scrollToPosition.
public void scrollToPosition(int position, int offset, final boolean bottom, boolean smooth) {
if (recyclerView.fastScrollAnimationRunning || (recyclerView.getItemAnimator() != null && recyclerView.getItemAnimator().isRunning())) {
return;
}
if (!smooth || scrollDirection == SCROLL_DIRECTION_UNSET) {
layoutManager.scrollToPositionWithOffset(position, offset, bottom);
return;
}
int n = recyclerView.getChildCount();
if (n == 0 || !MessagesController.getGlobalMainSettings().getBoolean("view_animations", true)) {
layoutManager.scrollToPositionWithOffset(position, offset, bottom);
return;
}
boolean scrollDown = scrollDirection == SCROLL_DIRECTION_DOWN;
recyclerView.setScrollEnabled(false);
final ArrayList<View> oldViews = new ArrayList<>();
positionToOldView.clear();
RecyclerView.Adapter adapter = recyclerView.getAdapter();
oldStableIds.clear();
for (int i = 0; i < n; i++) {
View child = recyclerView.getChildAt(i);
oldViews.add(child);
int childPosition = layoutManager.getPosition(child);
positionToOldView.put(childPosition, child);
if (adapter != null && adapter.hasStableIds()) {
long itemId = ((RecyclerView.LayoutParams) child.getLayoutParams()).mViewHolder.getItemId();
oldStableIds.put(itemId, child);
}
if (child instanceof ChatMessageCell) {
((ChatMessageCell) child).setAnimationRunning(true, true);
}
}
recyclerView.prepareForFastScroll();
AnimatableAdapter animatableAdapter = null;
if (adapter instanceof AnimatableAdapter) {
animatableAdapter = (AnimatableAdapter) adapter;
}
layoutManager.scrollToPositionWithOffset(position, offset, bottom);
if (adapter != null)
adapter.notifyDataSetChanged();
AnimatableAdapter finalAnimatableAdapter = animatableAdapter;
recyclerView.stopScroll();
recyclerView.setVerticalScrollBarEnabled(false);
if (animationCallback != null)
animationCallback.onStartAnimation();
recyclerView.fastScrollAnimationRunning = true;
if (finalAnimatableAdapter != null)
finalAnimatableAdapter.onAnimationStart();
recyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int l, int t, int r, int b, int ol, int ot, int or, int ob) {
final ArrayList<View> incomingViews = new ArrayList<>();
recyclerView.stopScroll();
int n = recyclerView.getChildCount();
int top = 0;
int bottom = 0;
int scrollDiff = 0;
boolean hasSameViews = false;
for (int i = 0; i < n; i++) {
View child = recyclerView.getChildAt(i);
incomingViews.add(child);
if (child.getTop() < top)
top = child.getTop();
if (child.getBottom() > bottom)
bottom = child.getBottom();
if (child instanceof ChatMessageCell) {
((ChatMessageCell) child).setAnimationRunning(true, false);
}
if (adapter != null && adapter.hasStableIds()) {
long stableId = adapter.getItemId(recyclerView.getChildAdapterPosition(child));
if (oldStableIds.containsKey(stableId)) {
View view = oldStableIds.get(stableId);
if (view != null) {
hasSameViews = true;
if (view instanceof ChatMessageCell) {
((ChatMessageCell) view).setAnimationRunning(false, false);
}
oldViews.remove(view);
if (animationCallback != null) {
animationCallback.recycleView(view);
}
int dif = child.getTop() - view.getTop();
if (dif != 0) {
scrollDiff = dif;
}
}
}
}
}
oldStableIds.clear();
int oldH = 0;
int oldT = Integer.MAX_VALUE;
for (View view : oldViews) {
int bot = view.getBottom();
int topl = view.getTop();
if (bot > oldH)
oldH = bot;
if (topl < oldT)
oldT = topl;
if (view.getParent() == null) {
recyclerView.addView(view);
layoutManager.ignoreView(view);
}
if (view instanceof ChatMessageCell) {
((ChatMessageCell) view).setAnimationRunning(true, true);
}
}
if (oldT == Integer.MAX_VALUE) {
oldT = 0;
}
final int scrollLength;
if (oldViews.isEmpty()) {
scrollLength = Math.abs(scrollDiff);
} else {
int finalHeight = scrollDown ? oldH : recyclerView.getHeight() - oldT;
scrollLength = finalHeight + (scrollDown ? -top : bottom - recyclerView.getHeight());
}
if (animator != null) {
animator.removeAllListeners();
animator.cancel();
}
animator = ValueAnimator.ofFloat(0, 1f);
animator.addUpdateListener(animation -> {
float value = ((float) animation.getAnimatedValue());
int size = oldViews.size();
for (int i = 0; i < size; i++) {
View view = oldViews.get(i);
float viewTop = view.getY();
float viewBottom = view.getY() + view.getMeasuredHeight();
if (viewBottom < 0 || viewTop > recyclerView.getMeasuredHeight()) {
continue;
}
if (scrollDown) {
view.setTranslationY(-scrollLength * value);
} else {
view.setTranslationY(scrollLength * value);
}
}
size = incomingViews.size();
for (int i = 0; i < size; i++) {
View view = incomingViews.get(i);
if (scrollDown) {
view.setTranslationY((scrollLength) * (1f - value));
} else {
view.setTranslationY(-(scrollLength) * (1f - value));
}
}
recyclerView.invalidate();
if (scrollListener != null)
scrollListener.onScroll();
});
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animator == null) {
return;
}
recyclerView.fastScrollAnimationRunning = false;
for (View view : oldViews) {
if (view instanceof ChatMessageCell) {
((ChatMessageCell) view).setAnimationRunning(false, true);
}
view.setTranslationY(0);
layoutManager.stopIgnoringView(view);
recyclerView.removeView(view);
if (animationCallback != null) {
animationCallback.recycleView(view);
}
}
recyclerView.setScrollEnabled(true);
recyclerView.setVerticalScrollBarEnabled(true);
if (BuildVars.DEBUG_VERSION) {
if (recyclerView.mChildHelper.getChildCount() != recyclerView.getChildCount()) {
throw new RuntimeException("views count in child helper must be quals views count in recycler view");
}
if (recyclerView.mChildHelper.getHiddenChildCount() != 0) {
throw new RuntimeException("hidden child count must be 0");
}
}
int n = recyclerView.getChildCount();
for (int i = 0; i < n; i++) {
View child = recyclerView.getChildAt(i);
if (child instanceof ChatMessageCell) {
((ChatMessageCell) child).setAnimationRunning(false, false);
}
child.setTranslationY(0);
}
for (View v : incomingViews) {
if (v instanceof ChatMessageCell) {
((ChatMessageCell) v).setAnimationRunning(false, false);
}
v.setTranslationY(0);
}
if (finalAnimatableAdapter != null) {
finalAnimatableAdapter.onAnimationEnd();
}
if (animationCallback != null) {
animationCallback.onEndAnimation();
}
positionToOldView.clear();
animator = null;
}
});
recyclerView.removeOnLayoutChangeListener(this);
long duration;
if (hasSameViews) {
duration = 600;
} else {
duration = (long) (((scrollLength / (float) recyclerView.getMeasuredHeight()) + 1f) * 200L);
if (duration < 300) {
duration = 300;
}
duration = Math.min(duration, 1300);
}
animator.setDuration(duration);
animator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
animator.start();
}
});
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeActivity method setFontSize.
private boolean setFontSize(int size) {
if (size != SharedConfig.fontSize) {
SharedConfig.fontSize = size;
SharedPreferences preferences = MessagesController.getGlobalMainSettings();
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("fons_size", SharedConfig.fontSize);
editor.commit();
Theme.chat_msgTextPaint.setTextSize(AndroidUtilities.dp(SharedConfig.fontSize));
RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(textSizeRow);
if (holder != null && holder.itemView instanceof TextSizeCell) {
TextSizeCell cell = (TextSizeCell) holder.itemView;
ChatMessageCell[] cells = cell.messagesCell.getCells();
for (int a = 0; a < cells.length; a++) {
cells[a].getMessageObject().resetLayout();
cells[a].requestLayout();
}
}
updateMenuItem();
return true;
}
return false;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method selectReaction.
private void selectReaction(MessageObject primaryMessage, ReactionsContainerLayout reactionsLayout, float x, float y, TLRPC.TL_availableReaction reaction, boolean fromDoubleTap, boolean bigEmoji) {
ReactionsEffectOverlay.removeCurrent(false);
boolean added = primaryMessage.selectReaction(reaction.reaction, bigEmoji, fromDoubleTap);
int messageIdForCell = primaryMessage.getId();
if (groupedMessagesMap.get(primaryMessage.getGroupId()) != null) {
int flags = primaryMessage.shouldDrawReactionsInLayout() ? MessageObject.POSITION_FLAG_BOTTOM | MessageObject.POSITION_FLAG_LEFT : MessageObject.POSITION_FLAG_BOTTOM | MessageObject.POSITION_FLAG_RIGHT;
MessageObject messageObject = groupedMessagesMap.get(primaryMessage.getGroupId()).findMessageWithFlags(flags);
if (messageObject != null) {
messageIdForCell = messageObject.getId();
}
}
int finalMessageIdForCell = messageIdForCell;
if (added && !fromDoubleTap) {
ChatMessageCell cell = findMessageCell(finalMessageIdForCell, true);
ReactionsEffectOverlay.show(ChatActivity.this, reactionsLayout, cell, x, y, reaction.reaction, currentAccount, reactionsLayout != null ? (bigEmoji ? ReactionsEffectOverlay.LONG_ANIMATION : ReactionsEffectOverlay.ONLY_MOVE_ANIMATION) : ReactionsEffectOverlay.SHORT_ANIMATION);
}
getSendMessagesHelper().sendReaction(primaryMessage, added ? reaction.reaction : null, bigEmoji, ChatActivity.this, updateReactionRunnable = new Runnable() {
@Override
public void run() {
if (updateReactionRunnable != null) {
updateReactionRunnable = null;
if (fromDoubleTap) {
doOnIdle(() -> {
AndroidUtilities.runOnUIThread(() -> {
ChatMessageCell cell = findMessageCell(finalMessageIdForCell, true);
if (added) {
ReactionsEffectOverlay.show(ChatActivity.this, reactionsLayout, cell, x, y, reaction.reaction, currentAccount, ReactionsEffectOverlay.SHORT_ANIMATION);
ReactionsEffectOverlay.startAnimation();
}
}, 50);
});
} else {
updateMessageAnimated(primaryMessage, true);
ReactionsEffectOverlay.startAnimation();
}
closeMenu();
}
}
});
if (fromDoubleTap) {
updateMessageAnimated(primaryMessage, true);
updateReactionRunnable.run();
}
AndroidUtilities.runOnUIThread(updateReactionRunnable, 50);
}
Aggregations