use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class BackButtonMenu method show.
public static ActionBarPopupWindow show(BaseFragment thisFragment, View backButton, long currentDialogId) {
if (thisFragment == null) {
return null;
}
final ActionBarLayout parentLayout = thisFragment.getParentLayout();
final Context context = thisFragment.getParentActivity();
final View fragmentView = thisFragment.getFragmentView();
if (parentLayout == null || context == null || fragmentView == null) {
return null;
}
ArrayList<PulledDialog> dialogs = getStackedHistoryDialogs(thisFragment, currentDialogId);
if (dialogs.size() <= 0) {
return null;
}
ActionBarPopupWindow.ActionBarPopupWindowLayout layout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(context);
android.graphics.Rect backgroundPaddings = new Rect();
Drawable shadowDrawable = thisFragment.getParentActivity().getResources().getDrawable(R.drawable.popup_fixed_alert).mutate();
shadowDrawable.getPadding(backgroundPaddings);
layout.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuBackground));
AtomicReference<ActionBarPopupWindow> scrimPopupWindowRef = new AtomicReference<>();
for (int i = 0; i < dialogs.size(); ++i) {
final PulledDialog pDialog = dialogs.get(i);
final TLRPC.Chat chat = pDialog.chat;
final TLRPC.User user = pDialog.user;
FrameLayout cell = new FrameLayout(context);
cell.setMinimumWidth(AndroidUtilities.dp(200));
BackupImageView imageView = new BackupImageView(context);
imageView.setRoundRadius(AndroidUtilities.dp(32));
cell.addView(imageView, LayoutHelper.createFrameRelatively(32, 32, Gravity.START | Gravity.CENTER_VERTICAL, 13, 0, 0, 0));
TextView titleView = new TextView(context);
titleView.setLines(1);
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
titleView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
titleView.setEllipsize(TextUtils.TruncateAt.END);
cell.addView(titleView, LayoutHelper.createFrameRelatively(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 59, 0, 12, 0));
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setSmallSize(true);
if (chat != null) {
avatarDrawable.setInfo(chat);
imageView.setImage(ImageLocation.getForChat(chat, ImageLocation.TYPE_SMALL), "50_50", avatarDrawable, chat);
titleView.setText(chat.title);
} else if (user != null) {
String name;
if (pDialog.activity == ChatActivity.class && UserObject.isUserSelf(user)) {
name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
imageView.setImageDrawable(avatarDrawable);
} else if (UserObject.isReplyUser(user)) {
name = LocaleController.getString("RepliesTitle", R.string.RepliesTitle);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
imageView.setImageDrawable(avatarDrawable);
} else if (UserObject.isDeleted(user)) {
name = LocaleController.getString("HiddenName", R.string.HiddenName);
avatarDrawable.setInfo(user);
imageView.setImage(ImageLocation.getForUser(user, ImageLocation.TYPE_SMALL), "50_50", avatarDrawable, user);
} else {
name = UserObject.getUserName(user);
avatarDrawable.setInfo(user);
imageView.setImage(ImageLocation.getForUser(user, ImageLocation.TYPE_SMALL), "50_50", avatarDrawable, user);
}
titleView.setText(name);
}
cell.setBackground(Theme.getSelectorDrawable(Theme.getColor(Theme.key_listSelector), false));
cell.setOnClickListener(e2 -> {
if (scrimPopupWindowRef.get() != null) {
scrimPopupWindowRef.getAndSet(null).dismiss();
}
if (pDialog.stackIndex >= 0) {
Long nextFragmentDialogId = null;
if (parentLayout == null || parentLayout.fragmentsStack == null || pDialog.stackIndex >= parentLayout.fragmentsStack.size()) {
nextFragmentDialogId = null;
} else {
BaseFragment nextFragment = parentLayout.fragmentsStack.get(pDialog.stackIndex);
if (nextFragment instanceof ChatActivity) {
nextFragmentDialogId = ((ChatActivity) nextFragment).getDialogId();
} else if (nextFragment instanceof ProfileActivity) {
nextFragmentDialogId = ((ProfileActivity) nextFragment).getDialogId();
}
}
if (nextFragmentDialogId != null && nextFragmentDialogId != pDialog.dialogId) {
for (int j = parentLayout.fragmentsStack.size() - 2; j > pDialog.stackIndex; --j) {
parentLayout.removeFragmentFromStack(j);
}
} else {
if (parentLayout != null && parentLayout.fragmentsStack != null) {
for (int j = parentLayout.fragmentsStack.size() - 2; j > pDialog.stackIndex; --j) {
if (j >= 0 && j < parentLayout.fragmentsStack.size()) {
parentLayout.removeFragmentFromStack(j);
}
}
if (pDialog.stackIndex < parentLayout.fragmentsStack.size()) {
parentLayout.showFragment(pDialog.stackIndex);
parentLayout.closeLastFragment(true);
return;
}
}
}
}
goToPulledDialog(thisFragment, pDialog);
});
layout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
}
ActionBarPopupWindow scrimPopupWindow = new ActionBarPopupWindow(layout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
scrimPopupWindowRef.set(scrimPopupWindow);
scrimPopupWindow.setPauseNotifications(true);
scrimPopupWindow.setDismissAnimationDuration(220);
scrimPopupWindow.setOutsideTouchable(true);
scrimPopupWindow.setClippingEnabled(true);
scrimPopupWindow.setAnimationStyle(R.style.PopupContextAnimation);
scrimPopupWindow.setFocusable(true);
layout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
scrimPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
scrimPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
scrimPopupWindow.getContentView().setFocusableInTouchMode(true);
layout.setFitItems(true);
int popupX = AndroidUtilities.dp(8) - backgroundPaddings.left;
if (AndroidUtilities.isTablet()) {
int[] location = new int[2];
fragmentView.getLocationInWindow(location);
popupX += location[0];
}
int popupY = (int) (backButton.getBottom() - backgroundPaddings.top - AndroidUtilities.dp(8));
scrimPopupWindow.showAtLocation(fragmentView, Gravity.LEFT | Gravity.TOP, popupX, popupY);
try {
fragmentView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
} catch (Exception ignore) {
}
return scrimPopupWindow;
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlert method updateLayout.
@SuppressLint("NewApi")
protected void updateLayout(AttachAlertLayout layout, boolean animated, int dy) {
if (layout == null) {
return;
}
int newOffset = layout.getCurrentItemTop();
if (newOffset == Integer.MAX_VALUE) {
return;
}
boolean show = layout == currentAttachLayout && newOffset <= layout.getButtonsHideOffset();
if (keyboardVisible && animated) {
animated = false;
}
if (show && actionBar.getTag() == null || !show && actionBar.getTag() != null) {
actionBar.setTag(show ? 1 : null);
if (actionBarAnimation != null) {
actionBarAnimation.cancel();
actionBarAnimation = null;
}
boolean needsSearchItem = avatarSearch || currentAttachLayout == photoLayout && !menuShowed && baseFragment instanceof ChatActivity && ((ChatActivity) baseFragment).allowSendGifs();
boolean needMoreItem = avatarPicker != 0 || !menuShowed && currentAttachLayout == photoLayout && mediaEnabled;
if (show) {
if (needsSearchItem) {
searchItem.setVisibility(View.VISIBLE);
}
if (needMoreItem) {
selectedMenuItem.setVisibility(View.VISIBLE);
}
} else if (typeButtonsAvailable) {
buttonsRecyclerView.setVisibility(View.VISIBLE);
}
if (animated) {
actionBarAnimation = new AnimatorSet();
actionBarAnimation.setDuration(180);
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(actionBar, View.ALPHA, show ? 1.0f : 0.0f));
animators.add(ObjectAnimator.ofFloat(actionBarShadow, View.ALPHA, show ? 1.0f : 0.0f));
if (needsSearchItem) {
animators.add(ObjectAnimator.ofFloat(searchItem, View.ALPHA, show ? 1.0f : 0.0f));
}
if (needMoreItem) {
animators.add(ObjectAnimator.ofFloat(selectedMenuItem, View.ALPHA, show ? 1.0f : 0.0f));
}
actionBarAnimation.playTogether(animators);
actionBarAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (actionBarAnimation != null) {
if (show) {
if (typeButtonsAvailable && (currentAttachLayout == null || currentAttachLayout.shouldHideBottomButtons())) {
buttonsRecyclerView.setVisibility(View.INVISIBLE);
}
} else {
searchItem.setVisibility(View.INVISIBLE);
if (avatarPicker != 0 || !menuShowed) {
selectedMenuItem.setVisibility(View.INVISIBLE);
}
}
}
}
@Override
public void onAnimationCancel(Animator animation) {
actionBarAnimation = null;
}
});
actionBarAnimation.start();
} else {
if (show) {
if (typeButtonsAvailable && (currentAttachLayout == null || currentAttachLayout.shouldHideBottomButtons())) {
buttonsRecyclerView.setVisibility(View.INVISIBLE);
}
}
actionBar.setAlpha(show ? 1.0f : 0.0f);
actionBarShadow.setAlpha(show ? 1.0f : 0.0f);
if (needsSearchItem) {
searchItem.setAlpha(show ? 1.0f : 0.0f);
}
if (needMoreItem) {
selectedMenuItem.setAlpha(show ? 1.0f : 0.0f);
}
if (!show) {
searchItem.setVisibility(View.INVISIBLE);
if (avatarPicker != 0 || !menuShowed) {
selectedMenuItem.setVisibility(View.INVISIBLE);
}
}
}
}
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) layout.getLayoutParams();
newOffset += layoutParams.topMargin - AndroidUtilities.dp(11);
int idx = currentAttachLayout == layout ? 0 : 1;
if (scrollOffsetY[idx] != newOffset) {
previousScrollOffsetY = scrollOffsetY[idx];
scrollOffsetY[idx] = newOffset;
updateSelectedPosition(idx);
containerView.invalidate();
} else if (dy != 0) {
previousScrollOffsetY = scrollOffsetY[idx];
}
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlert method updateCountButton.
public void updateCountButton(int animated) {
if (viewChangeAnimator != null) {
return;
}
int count = currentAttachLayout.getSelectedItemsCount();
if (count == 0) {
selectedCountView.setPivotX(0);
selectedCountView.setPivotY(0);
showCommentTextView(false, animated != 0);
} else {
selectedCountView.invalidate();
if (!showCommentTextView(true, animated != 0) && animated != 0) {
selectedCountView.setPivotX(AndroidUtilities.dp(21));
selectedCountView.setPivotY(AndroidUtilities.dp(12));
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(selectedCountView, View.SCALE_X, animated == 1 ? 1.1f : 0.9f, 1.0f), ObjectAnimator.ofFloat(selectedCountView, View.SCALE_Y, animated == 1 ? 1.1f : 0.9f, 1.0f));
animatorSet.setInterpolator(new OvershootInterpolator());
animatorSet.setDuration(180);
animatorSet.start();
} else {
selectedCountView.setPivotX(0);
selectedCountView.setPivotY(0);
}
}
currentAttachLayout.onSelectedItemsCountChanged(count);
if (currentAttachLayout == photoLayout && ((baseFragment instanceof ChatActivity) || avatarPicker != 0) && (count == 0 && menuShowed || (count != 0 || avatarPicker != 0) && !menuShowed)) {
menuShowed = count != 0 || avatarPicker != 0;
if (menuAnimator != null) {
menuAnimator.cancel();
menuAnimator = null;
}
boolean needsSearchItem = actionBar.getTag() != null && baseFragment instanceof ChatActivity && ((ChatActivity) baseFragment).allowSendGifs();
if (menuShowed) {
if (avatarPicker == 0) {
selectedMenuItem.setVisibility(View.VISIBLE);
}
selectedTextView.setVisibility(View.VISIBLE);
} else {
if (actionBar.getTag() != null) {
searchItem.setVisibility(View.VISIBLE);
}
}
if (animated == 0) {
if (actionBar.getTag() == null && avatarPicker == 0) {
selectedMenuItem.setAlpha(menuShowed ? 1.0f : 0.0f);
}
selectedTextView.setAlpha(menuShowed ? 1.0f : 0.0f);
if (needsSearchItem) {
searchItem.setAlpha(menuShowed ? 0.0f : 1.0f);
}
if (menuShowed) {
searchItem.setVisibility(View.INVISIBLE);
}
} else {
menuAnimator = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
if (actionBar.getTag() == null && avatarPicker == 0) {
animators.add(ObjectAnimator.ofFloat(selectedMenuItem, View.ALPHA, menuShowed ? 1.0f : 0.0f));
}
animators.add(ObjectAnimator.ofFloat(selectedTextView, View.ALPHA, menuShowed ? 1.0f : 0.0f));
if (needsSearchItem) {
animators.add(ObjectAnimator.ofFloat(searchItem, View.ALPHA, menuShowed ? 0.0f : 1.0f));
}
menuAnimator.playTogether(animators);
menuAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
menuAnimator = null;
if (!menuShowed) {
if (actionBar.getTag() == null && avatarPicker == 0) {
selectedMenuItem.setVisibility(View.INVISIBLE);
}
selectedTextView.setVisibility(View.INVISIBLE);
} else {
searchItem.setVisibility(View.INVISIBLE);
}
}
});
menuAnimator.setDuration(180);
menuAnimator.start();
}
}
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlert method show.
@Override
public void show() {
super.show();
buttonPressed = false;
if (baseFragment instanceof ChatActivity) {
ChatActivity chatActivity = (ChatActivity) baseFragment;
calcMandatoryInsets = chatActivity.isKeyboardVisible();
}
openTransitionFinished = false;
if (Build.VERSION.SDK_INT >= 30) {
int color = getThemedColor(Theme.key_windowBackgroundGray);
if (AndroidUtilities.computePerceivedBrightness(color) < 0.721) {
getWindow().setNavigationBarColor(color);
}
}
}
use of org.telegram.ui.ChatActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatAttachAlert method openAudioLayout.
private void openAudioLayout(boolean show) {
if (audioLayout == null) {
layouts[3] = audioLayout = new ChatAttachAlertAudioLayout(this, getContext(), resourcesProvider);
audioLayout.setDelegate((audios, caption, notify, scheduleDate) -> ((ChatActivity) baseFragment).sendAudio(audios, caption, notify, scheduleDate));
}
if (baseFragment instanceof ChatActivity) {
ChatActivity chatActivity = (ChatActivity) baseFragment;
TLRPC.Chat currentChat = chatActivity.getCurrentChat();
audioLayout.setMaxSelectedFiles(currentChat != null && !ChatObject.hasAdminRights(currentChat) && currentChat.slowmode_enabled || editingMessageObject != null ? 1 : -1);
}
if (show) {
showLayout(audioLayout);
}
}
Aggregations