use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class PrivacyControlActivity method createView.
@Override
public View createView(Context context) {
if (rulesType == PRIVACY_RULES_TYPE_FORWARDS) {
messageCell = new MessageCell(context);
}
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (rulesType == PRIVACY_RULES_TYPE_PHONE) {
actionBar.setTitle(LocaleController.getString("PrivacyPhone", R.string.PrivacyPhone));
} else if (rulesType == PRIVACY_RULES_TYPE_FORWARDS) {
actionBar.setTitle(LocaleController.getString("PrivacyForwards", R.string.PrivacyForwards));
} else if (rulesType == PRIVACY_RULES_TYPE_PHOTO) {
actionBar.setTitle(LocaleController.getString("PrivacyProfilePhoto", R.string.PrivacyProfilePhoto));
} else if (rulesType == PRIVACY_RULES_TYPE_P2P) {
actionBar.setTitle(LocaleController.getString("PrivacyP2P", R.string.PrivacyP2P));
} else if (rulesType == PRIVACY_RULES_TYPE_CALLS) {
actionBar.setTitle(LocaleController.getString("Calls", R.string.Calls));
} else if (rulesType == PRIVACY_RULES_TYPE_INVITE) {
actionBar.setTitle(LocaleController.getString("GroupsAndChannels", R.string.GroupsAndChannels));
} else {
actionBar.setTitle(LocaleController.getString("PrivacyLastSeen", R.string.PrivacyLastSeen));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
boolean hasChanges = hasChanges();
doneButton.setAlpha(hasChanges ? 1.0f : 0.0f);
doneButton.setScaleX(hasChanges ? 1.0f : 0.0f);
doneButton.setScaleY(hasChanges ? 1.0f : 0.0f);
doneButton.setEnabled(hasChanges);
listAdapter = new ListAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
listView = new RecyclerListView(context);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setVerticalScrollBarEnabled(false);
((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener((view, position) -> {
if (position == nobodyRow || position == everybodyRow || position == myContactsRow) {
int newType;
if (position == nobodyRow) {
newType = TYPE_NOBODY;
} else if (position == everybodyRow) {
newType = TYPE_EVERYBODY;
} else {
newType = TYPE_CONTACTS;
}
if (newType == currentType) {
return;
}
currentType = newType;
updateDoneButton();
updateRows(true);
} else if (position == phoneContactsRow || position == phoneEverybodyRow) {
int newType;
if (position == phoneEverybodyRow) {
newType = 0;
} else {
newType = 1;
}
if (newType == currentSubType) {
return;
}
currentSubType = newType;
updateDoneButton();
updateRows(true);
} else if (position == neverShareRow || position == alwaysShareRow) {
ArrayList<Long> createFromArray;
if (position == neverShareRow) {
createFromArray = currentMinus;
} else {
createFromArray = currentPlus;
}
if (createFromArray.isEmpty()) {
Bundle args = new Bundle();
args.putBoolean(position == neverShareRow ? "isNeverShare" : "isAlwaysShare", true);
args.putInt("chatAddType", rulesType != PRIVACY_RULES_TYPE_LASTSEEN ? 1 : 0);
GroupCreateActivity fragment = new GroupCreateActivity(args);
fragment.setDelegate(ids -> {
if (position == neverShareRow) {
currentMinus = ids;
for (int a = 0; a < currentMinus.size(); a++) {
currentPlus.remove(currentMinus.get(a));
}
} else {
currentPlus = ids;
for (int a = 0; a < currentPlus.size(); a++) {
currentMinus.remove(currentPlus.get(a));
}
}
updateDoneButton();
listAdapter.notifyDataSetChanged();
});
presentFragment(fragment);
} else {
PrivacyUsersActivity fragment = new PrivacyUsersActivity(PrivacyUsersActivity.TYPE_PRIVACY, createFromArray, rulesType != PRIVACY_RULES_TYPE_LASTSEEN, position == alwaysShareRow);
fragment.setDelegate((ids, added) -> {
if (position == neverShareRow) {
currentMinus = ids;
if (added) {
for (int a = 0; a < currentMinus.size(); a++) {
currentPlus.remove(currentMinus.get(a));
}
}
} else {
currentPlus = ids;
if (added) {
for (int a = 0; a < currentPlus.size(); a++) {
currentMinus.remove(currentPlus.get(a));
}
}
}
updateDoneButton();
listAdapter.notifyDataSetChanged();
});
presentFragment(fragment);
}
} else if (position == p2pRow) {
presentFragment(new PrivacyControlActivity(ContactsController.PRIVACY_RULES_TYPE_P2P));
}
});
setMessageText();
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ProfileActivity method onCustomTransitionAnimation.
@Override
protected AnimatorSet onCustomTransitionAnimation(final boolean isOpen, final Runnable callback) {
if (playProfileAnimation != 0 && allowProfileAnimation && !isPulledDown) {
if (timeItem != null) {
timeItem.setAlpha(1.0f);
}
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.setDuration(playProfileAnimation == 2 ? 250 : 180);
listView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
ActionBarMenu menu = actionBar.createMenu();
if (menu.getItem(10) == null) {
if (animatingItem == null) {
animatingItem = menu.addItem(10, R.drawable.ic_ab_other);
}
}
if (isOpen) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) onlineTextView[1].getLayoutParams();
layoutParams.rightMargin = (int) (-21 * AndroidUtilities.density + AndroidUtilities.dp(8));
onlineTextView[1].setLayoutParams(layoutParams);
if (playProfileAnimation != 2) {
int width = (int) Math.ceil(AndroidUtilities.displaySize.x - AndroidUtilities.dp(118 + 8) + 21 * AndroidUtilities.density);
float width2 = nameTextView[1].getPaint().measureText(nameTextView[1].getText().toString()) * 1.12f + nameTextView[1].getSideDrawablesSize();
layoutParams = (FrameLayout.LayoutParams) nameTextView[1].getLayoutParams();
if (width < width2) {
layoutParams.width = (int) Math.ceil(width / 1.12f);
} else {
layoutParams.width = LayoutHelper.WRAP_CONTENT;
}
nameTextView[1].setLayoutParams(layoutParams);
initialAnimationExtraHeight = AndroidUtilities.dp(88f);
} else {
layoutParams = (FrameLayout.LayoutParams) nameTextView[1].getLayoutParams();
layoutParams.width = (int) ((AndroidUtilities.displaySize.x - AndroidUtilities.dp(32)) / 1.67f);
nameTextView[1].setLayoutParams(layoutParams);
}
fragmentView.setBackgroundColor(0);
setAnimationProgress(0);
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 0.0f, 1.0f));
if (writeButton != null && writeButton.getTag() == null) {
writeButton.setScaleX(0.2f);
writeButton.setScaleY(0.2f);
writeButton.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(writeButton, View.SCALE_X, 1.0f));
animators.add(ObjectAnimator.ofFloat(writeButton, View.SCALE_Y, 1.0f));
animators.add(ObjectAnimator.ofFloat(writeButton, View.ALPHA, 1.0f));
}
if (playProfileAnimation == 2) {
avatarColor = AndroidUtilities.calcBitmapColor(avatarImage.getImageReceiver().getBitmap());
nameTextView[1].setTextColor(Color.WHITE);
onlineTextView[1].setTextColor(Color.argb(179, 255, 255, 255));
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, false);
overlaysView.setOverlaysVisible();
}
for (int a = 0; a < 2; a++) {
nameTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
animators.add(ObjectAnimator.ofFloat(nameTextView[a], View.ALPHA, a == 0 ? 0.0f : 1.0f));
}
if (timeItem.getTag() != null) {
animators.add(ObjectAnimator.ofFloat(timeItem, View.ALPHA, 1.0f, 0.0f));
animators.add(ObjectAnimator.ofFloat(timeItem, View.SCALE_X, 1.0f, 0.0f));
animators.add(ObjectAnimator.ofFloat(timeItem, View.SCALE_Y, 1.0f, 0.0f));
}
if (animatingItem != null) {
animatingItem.setAlpha(1.0f);
animators.add(ObjectAnimator.ofFloat(animatingItem, View.ALPHA, 0.0f));
}
if (callItemVisible && chatId != 0) {
callItem.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(callItem, View.ALPHA, 1.0f));
}
if (videoCallItemVisible) {
videoCallItem.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(videoCallItem, View.ALPHA, 1.0f));
}
if (editItemVisible) {
editItem.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(editItem, View.ALPHA, 1.0f));
}
boolean onlineTextCrosafade = false;
BaseFragment previousFragment = parentLayout.fragmentsStack.size() > 1 ? parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2) : null;
if (previousFragment instanceof ChatActivity) {
ChatAvatarContainer avatarContainer = ((ChatActivity) previousFragment).getAvatarContainer();
if (avatarContainer.getSubtitleTextView().getLeftDrawable() != null) {
transitionOnlineText = avatarContainer.getSubtitleTextView();
avatarContainer2.invalidate();
onlineTextCrosafade = true;
onlineTextView[0].setAlpha(0f);
onlineTextView[1].setAlpha(0f);
animators.add(ObjectAnimator.ofFloat(onlineTextView[1], View.ALPHA, 1.0f));
}
}
if (!onlineTextCrosafade) {
for (int a = 0; a < 2; a++) {
onlineTextView[a].setAlpha(a == 0 ? 1.0f : 0.0f);
animators.add(ObjectAnimator.ofFloat(onlineTextView[a], View.ALPHA, a == 0 ? 0.0f : 1.0f));
}
}
animatorSet.playTogether(animators);
} else {
initialAnimationExtraHeight = extraHeight;
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(this, "animationProgress", 1.0f, 0.0f));
if (writeButton != null) {
animators.add(ObjectAnimator.ofFloat(writeButton, View.SCALE_X, 0.2f));
animators.add(ObjectAnimator.ofFloat(writeButton, View.SCALE_Y, 0.2f));
animators.add(ObjectAnimator.ofFloat(writeButton, View.ALPHA, 0.0f));
}
for (int a = 0; a < 2; a++) {
animators.add(ObjectAnimator.ofFloat(nameTextView[a], View.ALPHA, a == 0 ? 1.0f : 0.0f));
}
if (timeItem.getTag() != null) {
animators.add(ObjectAnimator.ofFloat(timeItem, View.ALPHA, 0.0f, 1.0f));
animators.add(ObjectAnimator.ofFloat(timeItem, View.SCALE_X, 0.0f, 1.0f));
animators.add(ObjectAnimator.ofFloat(timeItem, View.SCALE_Y, 0.0f, 1.0f));
}
if (animatingItem != null) {
animatingItem.setAlpha(0.0f);
animators.add(ObjectAnimator.ofFloat(animatingItem, View.ALPHA, 1.0f));
}
if (callItemVisible && chatId != 0) {
callItem.setAlpha(1.0f);
animators.add(ObjectAnimator.ofFloat(callItem, View.ALPHA, 0.0f));
}
if (videoCallItemVisible) {
videoCallItem.setAlpha(1.0f);
animators.add(ObjectAnimator.ofFloat(videoCallItem, View.ALPHA, 0.0f));
}
if (editItemVisible) {
editItem.setAlpha(1.0f);
animators.add(ObjectAnimator.ofFloat(editItem, View.ALPHA, 0.0f));
}
boolean crossfadeOnlineText = false;
BaseFragment previousFragment = parentLayout.fragmentsStack.size() > 1 ? parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2) : null;
if (previousFragment instanceof ChatActivity) {
ChatAvatarContainer avatarContainer = ((ChatActivity) previousFragment).getAvatarContainer();
if (avatarContainer.getSubtitleTextView().getLeftDrawable() != null) {
transitionOnlineText = avatarContainer.getSubtitleTextView();
avatarContainer2.invalidate();
crossfadeOnlineText = true;
animators.add(ObjectAnimator.ofFloat(onlineTextView[0], View.ALPHA, 0.0f));
animators.add(ObjectAnimator.ofFloat(onlineTextView[1], View.ALPHA, 0.0f));
}
}
if (!crossfadeOnlineText) {
for (int a = 0; a < 2; a++) {
animators.add(ObjectAnimator.ofFloat(onlineTextView[a], View.ALPHA, a == 0 ? 1.0f : 0.0f));
}
}
animatorSet.playTogether(animators);
}
profileTransitionInProgress = true;
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1f);
valueAnimator.addUpdateListener(valueAnimator1 -> fragmentView.invalidate());
animatorSet.playTogether(valueAnimator);
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
listView.setLayerType(View.LAYER_TYPE_NONE, null);
if (animatingItem != null) {
ActionBarMenu menu = actionBar.createMenu();
menu.clearItems();
animatingItem = null;
}
callback.run();
if (playProfileAnimation == 2) {
playProfileAnimation = 1;
avatarImage.setForegroundAlpha(1.0f);
avatarContainer.setVisibility(View.GONE);
avatarsViewPager.resetCurrentItem();
avatarsViewPager.setVisibility(View.VISIBLE);
}
transitionOnlineText = null;
avatarContainer2.invalidate();
profileTransitionInProgress = false;
fragmentView.invalidate();
}
});
animatorSet.setInterpolator(playProfileAnimation == 2 ? CubicBezierInterpolator.DEFAULT : new DecelerateInterpolator());
AndroidUtilities.runOnUIThread(animatorSet::start, 50);
return animatorSet;
}
return null;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoPickerActivity method createView.
@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
listSort = false;
actionBar.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
actionBar.setTitleColor(Theme.getColor(textKey));
actionBar.setItemsColor(Theme.getColor(textKey), false);
actionBar.setItemsBackgroundColor(Theme.getColor(selectorKey), false);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == 0) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == change_sort) {
listSort = !listSort;
if (listSort) {
listView.setPadding(0, 0, 0, AndroidUtilities.dp(48));
} else {
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
}
listView.stopScroll();
layoutManager.scrollToPositionWithOffset(0, 0);
listAdapter.notifyDataSetChanged();
} else if (id == open_in) {
if (delegate != null) {
delegate.onOpenInPressed();
}
finishFragment();
}
}
});
if (isDocumentsPicker) {
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {
@Override
public void onShowSubMenu() {
showAsListItem.setText(listSort ? LocaleController.getString("ShowAsGrid", R.string.ShowAsGrid) : LocaleController.getString("ShowAsList", R.string.ShowAsList));
showAsListItem.setIcon(listSort ? R.drawable.msg_media : R.drawable.msg_list);
}
@Override
public void onHideSubMenu() {
}
});
showAsListItem = menuItem.addSubItem(change_sort, R.drawable.msg_list, LocaleController.getString("ShowAsList", R.string.ShowAsList));
menuItem.addSubItem(open_in, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
}
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onTextChanged(EditText editText) {
if (editText.getText().length() == 0) {
searchResult.clear();
searchResultKeys.clear();
lastSearchString = null;
imageSearchEndReached = true;
searching = false;
if (imageReqId != 0) {
ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
imageReqId = 0;
}
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
updateSearchInterface();
}
}
@Override
public void onSearchPressed(EditText editText) {
processSearch(editText);
}
});
EditTextBoldCursor editText = searchItem.getSearchField();
editText.setTextColor(Theme.getColor(textKey));
editText.setCursorColor(Theme.getColor(textKey));
editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
}
if (selectedAlbum == null) {
if (type == 0) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == 1) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
private int lastNotifyWidth;
private boolean ignoreLayout;
private int lastItemSize;
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int totalHeight = MeasureSpec.getSize(heightMeasureSpec);
int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
if (AndroidUtilities.isTablet()) {
itemsPerRow = 4;
} else if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
itemsPerRow = 4;
} else {
itemsPerRow = 3;
}
ignoreLayout = true;
itemSize = (availableWidth - AndroidUtilities.dp(6 * 2) - AndroidUtilities.dp(5 * 2)) / itemsPerRow;
if (lastItemSize != itemSize) {
lastItemSize = itemSize;
AndroidUtilities.runOnUIThread(() -> listAdapter.notifyDataSetChanged());
}
if (listSort) {
layoutManager.setSpanCount(1);
} else {
layoutManager.setSpanCount(itemSize * itemsPerRow + AndroidUtilities.dp(5) * (itemsPerRow - 1));
}
ignoreLayout = false;
onMeasureInternal(widthMeasureSpec, MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
}
private void onMeasureInternal(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
int kbHeight = measureKeyboardHeight();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : kbHeight;
if (keyboardSize <= AndroidUtilities.dp(20)) {
if (!AndroidUtilities.isInMultiwindow && commentTextView != null && frameLayout2.getParent() == this) {
heightSize -= commentTextView.getEmojiPadding();
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
}
}
if (kbHeight > AndroidUtilities.dp(20) && commentTextView != null) {
ignoreLayout = true;
commentTextView.hideEmojiView();
ignoreLayout = false;
}
if (SharedConfig.smoothKeyboard && commentTextView != null && commentTextView.isPopupShowing()) {
fragmentView.setTranslationY(0);
listView.setTranslationY(0);
emptyView.setTranslationY(0);
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE) {
continue;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
if (lastNotifyWidth != r - l) {
lastNotifyWidth = r - l;
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
}
final int count = getChildCount();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
int paddingBottom = commentTextView != null && frameLayout2.getParent() == this && keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
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 - l) - width - lp.rightMargin - getPaddingRight();
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin + getPaddingLeft();
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@Override
public void requestLayout() {
if (ignoreLayout) {
return;
}
super.requestLayout();
}
};
sizeNotifierFrameLayout.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
fragmentView = sizeNotifierFrameLayout;
listView = new RecyclerListView(context);
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
listView.setClipToPadding(false);
listView.setHorizontalScrollBarEnabled(false);
listView.setVerticalScrollBarEnabled(false);
listView.setItemAnimator(null);
listView.setLayoutAnimation(null);
listView.setLayoutManager(layoutManager = new GridLayoutManager(context, 4) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
});
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (listAdapter.getItemViewType(position) == 1 || listSort || selectedAlbum == null && TextUtils.isEmpty(lastSearchString)) {
return layoutManager.getSpanCount();
} else {
return itemSize + (position % itemsPerRow != itemsPerRow - 1 ? AndroidUtilities.dp(5) : 0);
}
}
});
sizeNotifierFrameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
listView.setAdapter(listAdapter = new ListAdapter(context));
listView.setGlowColor(Theme.getColor(dialogBackgroundKey));
listView.setOnItemClickListener((view, position) -> {
if (selectedAlbum == null && searchResult.isEmpty()) {
if (position < recentSearches.size()) {
String text = recentSearches.get(position);
if (searchDelegate != null) {
searchDelegate.shouldSearchText(text);
} else {
searchItem.getSearchField().setText(text);
searchItem.getSearchField().setSelection(text.length());
processSearch(searchItem.getSearchField());
}
} else if (position == recentSearches.size() + 1) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("ClearSearchAlertTitle", R.string.ClearSearchAlertTitle));
builder.setMessage(LocaleController.getString("ClearSearchAlert", R.string.ClearSearchAlert));
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> {
if (searchDelegate != null) {
searchDelegate.shouldClearRecentSearch();
} else {
clearRecentSearch();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
showDialog(dialog);
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
return;
}
return;
}
ArrayList<Object> arrayList;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
arrayList = (ArrayList) searchResult;
}
if (position < 0 || position >= arrayList.size()) {
return;
}
if (searchItem != null) {
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
}
if (listSort) {
onListItemClick(view, arrayList.get(position));
} else {
int type;
if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR || selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR_VIDEO) {
type = PhotoViewer.SELECT_TYPE_AVATAR;
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_WALLPAPER) {
type = PhotoViewer.SELECT_TYPE_WALLPAPER;
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_QR) {
type = PhotoViewer.SELECT_TYPE_QR;
} else if (chatActivity == null) {
type = 4;
} else {
type = 0;
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, type, isDocumentsPicker, provider, chatActivity);
}
});
if (maxSelectedPhotos != 1) {
listView.setOnItemLongClickListener((view, position) -> {
if (listSort) {
onListItemClick(view, selectedAlbum.photos.get(position));
return true;
} else {
if (view instanceof PhotoAttachPhotoCell) {
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
itemRangeSelector.setIsActive(view, true, position, shouldSelect = !cell.isChecked());
}
}
return false;
});
}
itemRangeSelector = new RecyclerViewItemRangeSelector(new RecyclerViewItemRangeSelector.RecyclerViewItemRangeSelectorDelegate() {
@Override
public int getItemCount() {
return listAdapter.getItemCount();
}
@Override
public void setSelected(View view, int index, boolean selected) {
if (selected != shouldSelect || !(view instanceof PhotoAttachPhotoCell)) {
return;
}
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
cell.callDelegate();
}
@Override
public boolean isSelected(int index) {
Object key;
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
key = photoEntry.imageId;
} else {
MediaController.SearchImage photoEntry = searchResult.get(index);
key = photoEntry.id;
}
return selectedPhotos.containsKey(key);
}
@Override
public boolean isIndexSelectable(int index) {
return listAdapter.getItemViewType(index) == 0;
}
@Override
public void onStartStopSelection(boolean start) {
alertOnlyOnce = start ? 1 : 0;
if (start) {
parentLayout.requestDisallowInterceptTouchEvent(true);
}
listView.hideSelector(true);
}
});
if (maxSelectedPhotos != 1) {
listView.addOnItemTouchListener(itemRangeSelector);
}
emptyView = new EmptyTextProgressView(context);
emptyView.setTextColor(0xff93999d);
emptyView.setProgressBarColor(0xff527da3);
if (selectedAlbum != null) {
emptyView.setShowAtCenter(false);
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
emptyView.setShowAtTop(true);
emptyView.setPadding(0, AndroidUtilities.dp(200), 0, 0);
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
}
sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL ? 0 : 48));
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (selectedAlbum == null) {
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
if (visibleItemCount > 0) {
int totalItemCount = layoutManager.getItemCount();
if (firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
if (!imageSearchEndReached) {
searchImages(type == 1, lastSearchString, nextImagesSearchOffset, true);
}
}
}
}
}
});
if (selectedAlbum == null) {
updateSearchInterface();
}
if (needsBottomLayout) {
shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
shadow.setTranslationY(AndroidUtilities.dp(48));
sizeNotifierFrameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
frameLayout2 = new FrameLayout(context);
frameLayout2.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
frameLayout2.setVisibility(View.INVISIBLE);
frameLayout2.setTranslationY(AndroidUtilities.dp(48));
sizeNotifierFrameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
frameLayout2.setOnTouchListener((v, event) -> true);
if (commentTextView != null) {
commentTextView.onDestroy();
}
commentTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, null, EditTextEmoji.STYLE_DIALOG);
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength);
commentTextView.setFilters(inputFilters);
commentTextView.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
commentTextView.onResume();
EditTextBoldCursor editText = commentTextView.getEditText();
editText.setMaxLines(1);
editText.setSingleLine(true);
frameLayout2.addView(commentTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 84, 0));
if (caption != null) {
commentTextView.setText(caption);
}
commentTextView.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (delegate != null) {
delegate.onCaptionChanged(s);
}
}
});
writeButtonContainer = new FrameLayout(context) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
info.setText(LocaleController.formatPluralString("AccDescrSendPhotos", selectedPhotos.size()));
info.setClassName(Button.class.getName());
info.setLongClickable(true);
info.setClickable(true);
}
};
writeButtonContainer.setFocusable(true);
writeButtonContainer.setFocusableInTouchMode(true);
writeButtonContainer.setVisibility(View.INVISIBLE);
writeButtonContainer.setScaleX(0.2f);
writeButtonContainer.setScaleY(0.2f);
writeButtonContainer.setAlpha(0.0f);
sizeNotifierFrameLayout.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
writeButton = new ImageView(context);
writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_dialogFloatingButton), Theme.getColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, writeButtonDrawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
writeButtonDrawable = combinedDrawable;
}
writeButton.setBackgroundDrawable(writeButtonDrawable);
writeButton.setImageResource(R.drawable.attach_send);
writeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
writeButton.setScaleType(ImageView.ScaleType.CENTER);
if (Build.VERSION.SDK_INT >= 21) {
writeButton.setOutlineProvider(new ViewOutlineProvider() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
writeButtonContainer.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
writeButton.setOnClickListener(v -> {
if (chatActivity != null && chatActivity.isInScheduleMode()) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
} else {
sendSelectedPhotos(true, 0);
}
});
writeButton.setOnLongClickListener(view -> {
if (chatActivity == null || maxSelectedPhotos == 1) {
return false;
}
TLRPC.Chat chat = chatActivity.getCurrentChat();
TLRPC.User user = chatActivity.getCurrentUser();
if (sendPopupLayout == null) {
sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
sendPopupLayout.setAnimationEnabled(false);
sendPopupLayout.setOnTouchListener(new View.OnTouchListener() {
private android.graphics.Rect popupRect = new android.graphics.Rect();
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
v.getHitRect(popupRect);
if (!popupRect.contains((int) event.getX(), (int) event.getY())) {
sendPopupWindow.dismiss();
}
}
}
return false;
}
});
sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
});
sendPopupLayout.setShownFromBotton(false);
itemCells = new ActionBarMenuSubItem[2];
for (int a = 0; a < 2; a++) {
if (a == 0 && !chatActivity.canScheduleMessage() || a == 1 && UserObject.isUserSelf(user)) {
continue;
}
int num = a;
itemCells[a] = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == 1);
if (num == 0) {
if (UserObject.isUserSelf(user)) {
itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
} else {
itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
}
} else {
itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
}
itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
sendPopupLayout.addView(itemCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
itemCells[a].setOnClickListener(v -> {
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
sendPopupWindow.dismiss();
}
if (num == 0) {
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
} else {
sendSelectedPhotos(true, 0);
}
});
}
sendPopupLayout.setupRadialSelectors(Theme.getColor(selectorKey));
sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
sendPopupWindow.setAnimationEnabled(false);
sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
sendPopupWindow.setOutsideTouchable(true);
sendPopupWindow.setClippingEnabled(true);
sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
sendPopupWindow.getContentView().setFocusableInTouchMode(true);
}
sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
sendPopupWindow.setFocusable(true);
int[] location = new int[2];
view.getLocationInWindow(location);
sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(8), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(2));
sendPopupWindow.dimBehind();
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
return false;
});
textPaint.setTextSize(AndroidUtilities.dp(12));
textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
selectedCountView = new View(context) {
@Override
protected void onDraw(Canvas canvas) {
String text = String.format("%d", Math.max(1, selectedPhotosOrder.size()));
int textSize = (int) Math.ceil(textPaint.measureText(text));
int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
int cx = getMeasuredWidth() / 2;
int cy = getMeasuredHeight() / 2;
textPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBoxCheck));
paint.setColor(Theme.getColor(dialogBackgroundKey));
rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
paint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
}
};
selectedCountView.setAlpha(0.0f);
selectedCountView.setScaleX(0.2f);
selectedCountView.setScaleY(0.2f);
sizeNotifierFrameLayout.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
if (selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL) {
commentTextView.setVisibility(View.GONE);
}
}
allowIndices = (selectedAlbum != null || type == 0 || type == 1) && allowOrder;
listView.setEmptyView(emptyView);
updatePhotosButton(0);
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class PhotoPickerSearchActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
actionBar.setTitleColor(Theme.getColor(Theme.key_dialogTextBlack));
actionBar.setItemsColor(Theme.getColor(Theme.key_dialogTextBlack), false);
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_dialogButtonSelector), false);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (AndroidUtilities.isTablet()) {
actionBar.setOccupyStatusBar(false);
}
actionBar.setExtraHeight(AndroidUtilities.dp(44));
actionBar.setAllowOverlayTitle(false);
actionBar.setAddToContainer(false);
actionBar.setClipContent(true);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
hasOwnBackground = true;
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
imagesSearch.getActionBar().openSearchField("", false);
gifsSearch.getActionBar().openSearchField("", false);
searchItem.getSearchField().requestFocus();
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onTextChanged(EditText editText) {
imagesSearch.getActionBar().setSearchFieldText(editText.getText().toString());
gifsSearch.getActionBar().setSearchFieldText(editText.getText().toString());
}
@Override
public void onSearchPressed(EditText editText) {
imagesSearch.getActionBar().onSearchPressed();
gifsSearch.getActionBar().onSearchPressed();
}
});
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
EditTextBoldCursor editText = searchItem.getSearchField();
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
editText.setCursorColor(Theme.getColor(Theme.key_dialogTextBlack));
editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
scrollSlidingTextTabStrip = new ScrollSlidingTextTabStrip(context);
scrollSlidingTextTabStrip.setUseSameWidth(true);
scrollSlidingTextTabStrip.setColors(Theme.key_chat_attachActiveTab, Theme.key_chat_attachActiveTab, Theme.key_chat_attachUnactiveTab, Theme.key_dialogButtonSelector);
actionBar.addView(scrollSlidingTextTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.BOTTOM));
scrollSlidingTextTabStrip.setDelegate(new ScrollSlidingTextTabStrip.ScrollSlidingTabStripDelegate() {
@Override
public void onPageSelected(int id, boolean forward) {
if (viewPages[0].selectedType == id) {
return;
}
swipeBackEnabled = id == scrollSlidingTextTabStrip.getFirstTabId();
viewPages[1].selectedType = id;
viewPages[1].setVisibility(View.VISIBLE);
switchToCurrentSelectedMode(true);
animatingForward = forward;
if (id == 0) {
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else {
searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
@Override
public void onPageScrolled(float progress) {
if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE) {
return;
}
if (animatingForward) {
viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
} else {
viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
}
if (progress == 1) {
ViewPage tempPage = viewPages[0];
viewPages[0] = viewPages[1];
viewPages[1] = tempPage;
viewPages[1].setVisibility(View.GONE);
}
}
});
ViewConfiguration configuration = ViewConfiguration.get(context);
maximumVelocity = configuration.getScaledMaximumFlingVelocity();
SizeNotifierFrameLayout sizeNotifierFrameLayout;
fragmentView = sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
private int startedTrackingPointerId;
private boolean startedTracking;
private boolean maybeStartTracking;
private int startedTrackingX;
private int startedTrackingY;
private VelocityTracker velocityTracker;
private boolean globalIgnoreLayout;
private boolean prepareForMoving(MotionEvent ev, boolean forward) {
int id = scrollSlidingTextTabStrip.getNextPageId(forward);
if (id < 0) {
return false;
}
getParent().requestDisallowInterceptTouchEvent(true);
maybeStartTracking = false;
startedTracking = true;
startedTrackingX = (int) ev.getX();
actionBar.setEnabled(false);
scrollSlidingTextTabStrip.setEnabled(false);
viewPages[1].selectedType = id;
viewPages[1].setVisibility(View.VISIBLE);
animatingForward = forward;
switchToCurrentSelectedMode(true);
if (forward) {
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
} else {
viewPages[1].setTranslationX(-viewPages[0].getMeasuredWidth());
}
return true;
}
@Override
public void forceHasOverlappingRendering(boolean hasOverlappingRendering) {
super.forceHasOverlappingRendering(hasOverlappingRendering);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
if (keyboardSize <= AndroidUtilities.dp(20)) {
if (!AndroidUtilities.isInMultiwindow) {
heightSize -= commentTextView.getEmojiPadding();
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
}
} else {
globalIgnoreLayout = true;
commentTextView.hideEmojiView();
globalIgnoreLayout = false;
}
int actionBarHeight = actionBar.getMeasuredHeight();
globalIgnoreLayout = true;
for (int a = 0; a < viewPages.length; a++) {
if (viewPages[a] == null) {
continue;
}
if (viewPages[a].listView != null) {
viewPages[a].listView.setPadding(AndroidUtilities.dp(4), actionBarHeight + AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
}
}
globalIgnoreLayout = false;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
if (AndroidUtilities.isTablet()) {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
}
} else {
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
}
} 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();
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
setBottomClip(paddingBottom);
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 - l) - width - lp.rightMargin - getPaddingRight();
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin + getPaddingLeft();
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
break;
case Gravity.CENTER_VERTICAL:
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (commentTextView != null && commentTextView.isPopupView(child)) {
if (AndroidUtilities.isTablet()) {
childTop = getMeasuredHeight() - child.getMeasuredHeight();
} else {
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
}
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
notifyHeightChanged();
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (parentLayout != null) {
parentLayout.drawHeaderShadow(canvas, actionBar.getMeasuredHeight() + (int) actionBar.getTranslationY());
}
}
@Override
public void requestLayout() {
if (globalIgnoreLayout) {
return;
}
super.requestLayout();
}
public boolean checkTabsAnimationInProgress() {
if (tabsAnimationInProgress) {
boolean cancel = false;
if (backAnimation) {
if (Math.abs(viewPages[0].getTranslationX()) < 1) {
viewPages[0].setTranslationX(0);
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? 1 : -1));
cancel = true;
}
} else if (Math.abs(viewPages[1].getTranslationX()) < 1) {
viewPages[0].setTranslationX(viewPages[0].getMeasuredWidth() * (animatingForward ? -1 : 1));
viewPages[1].setTranslationX(0);
cancel = true;
}
if (cancel) {
if (tabsAnimation != null) {
tabsAnimation.cancel();
tabsAnimation = null;
}
tabsAnimationInProgress = false;
}
return tabsAnimationInProgress;
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return checkTabsAnimationInProgress() || scrollSlidingTextTabStrip.isAnimatingIndicator() || onTouchEvent(ev);
}
@Override
protected void onDraw(Canvas canvas) {
backgroundPaint.setColor(Theme.getColor(Theme.key_windowBackgroundGray));
canvas.drawRect(0, actionBar.getMeasuredHeight() + actionBar.getTranslationY(), getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!parentLayout.checkTransitionAnimation() && !checkTabsAnimationInProgress()) {
if (ev != null) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.addMovement(ev);
}
if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking && !maybeStartTracking) {
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
velocityTracker.clear();
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
int dx = (int) (ev.getX() - startedTrackingX);
int dy = Math.abs((int) ev.getY() - startedTrackingY);
if (startedTracking && (animatingForward && dx > 0 || !animatingForward && dx < 0)) {
if (!prepareForMoving(ev, dx < 0)) {
maybeStartTracking = true;
startedTracking = false;
viewPages[0].setTranslationX(0);
viewPages[1].setTranslationX(animatingForward ? viewPages[0].getMeasuredWidth() : -viewPages[0].getMeasuredWidth());
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, 0);
}
}
if (maybeStartTracking && !startedTracking) {
float touchSlop = AndroidUtilities.getPixelsInCM(0.3f, true);
if (Math.abs(dx) >= touchSlop && Math.abs(dx) > dy) {
prepareForMoving(ev, dx < 0);
}
} else if (startedTracking) {
viewPages[0].setTranslationX(dx);
if (animatingForward) {
viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() + dx);
} else {
viewPages[1].setTranslationX(dx - viewPages[0].getMeasuredWidth());
}
float scrollProgress = Math.abs(dx) / (float) viewPages[0].getMeasuredWidth();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
}
} else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
float velX;
float velY;
if (ev != null && ev.getAction() != MotionEvent.ACTION_CANCEL) {
velX = velocityTracker.getXVelocity();
velY = velocityTracker.getYVelocity();
if (!startedTracking) {
if (Math.abs(velX) >= 3000 && Math.abs(velX) > Math.abs(velY)) {
prepareForMoving(ev, velX < 0);
}
}
} else {
velX = 0;
velY = 0;
}
if (startedTracking) {
float x = viewPages[0].getX();
tabsAnimation = new AnimatorSet();
backAnimation = Math.abs(x) < viewPages[0].getMeasuredWidth() / 3.0f && (Math.abs(velX) < 3500 || Math.abs(velX) < Math.abs(velY));
float distToMove;
float dx;
if (backAnimation) {
dx = Math.abs(x);
if (animatingForward) {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, viewPages[1].getMeasuredWidth()));
} else {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, 0), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, -viewPages[1].getMeasuredWidth()));
}
} else {
dx = viewPages[0].getMeasuredWidth() - Math.abs(x);
if (animatingForward) {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, -viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
} else {
tabsAnimation.playTogether(ObjectAnimator.ofFloat(viewPages[0], View.TRANSLATION_X, viewPages[0].getMeasuredWidth()), ObjectAnimator.ofFloat(viewPages[1], View.TRANSLATION_X, 0));
}
}
tabsAnimation.setInterpolator(interpolator);
int width = getMeasuredWidth();
int halfWidth = width / 2;
float distanceRatio = Math.min(1.0f, 1.0f * dx / (float) width);
float distance = (float) halfWidth + (float) halfWidth * AndroidUtilities.distanceInfluenceForSnapDuration(distanceRatio);
velX = Math.abs(velX);
int duration;
if (velX > 0) {
duration = 4 * Math.round(1000.0f * Math.abs(distance / velX));
} else {
float pageDelta = dx / getMeasuredWidth();
duration = (int) ((pageDelta + 1.0f) * 100.0f);
}
duration = Math.max(150, Math.min(duration, 600));
tabsAnimation.setDuration(duration);
tabsAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animator) {
tabsAnimation = null;
if (backAnimation) {
viewPages[1].setVisibility(View.GONE);
} else {
ViewPage tempPage = viewPages[0];
viewPages[0] = viewPages[1];
viewPages[1] = tempPage;
viewPages[1].setVisibility(View.GONE);
swipeBackEnabled = viewPages[0].selectedType == scrollSlidingTextTabStrip.getFirstTabId();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[0].selectedType, 1.0f);
}
tabsAnimationInProgress = false;
maybeStartTracking = false;
startedTracking = false;
actionBar.setEnabled(true);
scrollSlidingTextTabStrip.setEnabled(true);
}
});
tabsAnimation.start();
tabsAnimationInProgress = true;
startedTracking = false;
} else {
maybeStartTracking = false;
actionBar.setEnabled(true);
scrollSlidingTextTabStrip.setEnabled(true);
}
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
}
return startedTracking;
}
return false;
}
};
sizeNotifierFrameLayout.setWillNotDraw(false);
imagesSearch.setParentFragment(this);
commentTextView = imagesSearch.commentTextView;
commentTextView.setSizeNotifierLayout(sizeNotifierFrameLayout);
for (int a = 0; a < 4; a++) {
View view;
switch(a) {
case 0:
view = imagesSearch.frameLayout2;
break;
case 1:
view = imagesSearch.writeButtonContainer;
break;
case 2:
view = imagesSearch.selectedCountView;
break;
case 3:
default:
view = imagesSearch.shadow;
break;
}
ViewGroup parent = (ViewGroup) view.getParent();
parent.removeView(view);
}
gifsSearch.setLayoutViews(imagesSearch.frameLayout2, imagesSearch.writeButtonContainer, imagesSearch.selectedCountView, imagesSearch.shadow, imagesSearch.commentTextView);
gifsSearch.setParentFragment(this);
for (int a = 0; a < viewPages.length; a++) {
viewPages[a] = new ViewPage(context) {
@Override
public void setTranslationX(float translationX) {
super.setTranslationX(translationX);
if (tabsAnimationInProgress) {
if (viewPages[0] == this) {
float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
scrollSlidingTextTabStrip.selectTabWithId(viewPages[1].selectedType, scrollProgress);
}
}
}
};
sizeNotifierFrameLayout.addView(viewPages[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
if (a == 0) {
viewPages[a].parentFragment = imagesSearch;
viewPages[a].listView = imagesSearch.getListView();
} else if (a == 1) {
viewPages[a].parentFragment = gifsSearch;
viewPages[a].listView = gifsSearch.getListView();
viewPages[a].setVisibility(View.GONE);
}
viewPages[a].listView.setScrollingTouchSlop(RecyclerView.TOUCH_SLOP_PAGING);
viewPages[a].fragmentView = (FrameLayout) viewPages[a].parentFragment.getFragmentView();
viewPages[a].listView.setClipToPadding(false);
viewPages[a].actionBar = viewPages[a].parentFragment.getActionBar();
viewPages[a].addView(viewPages[a].fragmentView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
viewPages[a].addView(viewPages[a].actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
viewPages[a].actionBar.setVisibility(View.GONE);
RecyclerView.OnScrollListener onScrollListener = viewPages[a].listView.getOnScrollListener();
viewPages[a].listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
onScrollListener.onScrollStateChanged(recyclerView, newState);
if (newState != RecyclerView.SCROLL_STATE_DRAGGING) {
int scrollY = (int) -actionBar.getTranslationY();
int actionBarHeight = ActionBar.getCurrentActionBarHeight();
if (scrollY != 0 && scrollY != actionBarHeight) {
if (scrollY < actionBarHeight / 2) {
viewPages[0].listView.smoothScrollBy(0, -scrollY);
} else {
viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY);
}
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
onScrollListener.onScrolled(recyclerView, dx, dy);
if (recyclerView == viewPages[0].listView) {
float currentTranslation = actionBar.getTranslationY();
float newTranslation = currentTranslation - dy;
if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
newTranslation = -ActionBar.getCurrentActionBarHeight();
} else if (newTranslation > 0) {
newTranslation = 0;
}
if (newTranslation != currentTranslation) {
setScrollY(newTranslation);
}
}
}
});
}
sizeNotifierFrameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
sizeNotifierFrameLayout.addView(imagesSearch.shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
sizeNotifierFrameLayout.addView(imagesSearch.frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
sizeNotifierFrameLayout.addView(imagesSearch.writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
sizeNotifierFrameLayout.addView(imagesSearch.selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
updateTabs();
switchToCurrentSelectedMode(false);
swipeBackEnabled = scrollSlidingTextTabStrip.getCurrentTabId() == scrollSlidingTextTabStrip.getFirstTabId();
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method createMenu.
private void createMenu(View v, boolean single, boolean listView, float x, float y, boolean searchGroup) {
if (actionBar.isActionModeShowed() || reportType >= 0) {
return;
}
MessageObject message;
MessageObject primaryMessage;
if (v instanceof ChatMessageCell) {
message = ((ChatMessageCell) v).getMessageObject();
primaryMessage = ((ChatMessageCell) v).getPrimaryMessageObject();
} else if (v instanceof ChatActionCell) {
message = ((ChatActionCell) v).getMessageObject();
primaryMessage = message;
} else {
primaryMessage = null;
message = null;
}
if (message == null) {
return;
}
final int type = getMessageType(message);
if (single) {
if (message.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
if (message.getReplyMsgId() != 0) {
scrollToMessageId(message.getReplyMsgId(), message.messageOwner.id, true, message.getDialogId() == mergeDialogId ? 1 : 0, false, 0);
} else {
Toast.makeText(getParentActivity(), LocaleController.getString("MessageNotFound", R.string.MessageNotFound), Toast.LENGTH_SHORT).show();
}
return;
} else if (message.messageOwner.action instanceof TLRPC.TL_messageActionSetMessagesTTL) {
if (avatarContainer.openSetTimer()) {
return;
}
} else if (message.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent && message.replyMessageObject != null && message.replyMessageObject.isInvoice()) {
TLRPC.TL_payments_getPaymentReceipt req = new TLRPC.TL_payments_getPaymentReceipt();
req.msg_id = message.getId();
req.peer = getMessagesController().getInputPeer(message.messageOwner.peer_id);
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_payments_paymentReceipt) {
presentFragment(new PaymentFormActivity((TLRPC.TL_payments_paymentReceipt) response));
}
}), ConnectionsManager.RequestFlagFailOnServerErrors);
return;
} else if (message.messageOwner.action instanceof TLRPC.TL_messageActionGroupCall || message.messageOwner.action instanceof TLRPC.TL_messageActionInviteToGroupCall || message.messageOwner.action instanceof TLRPC.TL_messageActionGroupCallScheduled) {
if (getParentActivity() == null) {
return;
}
VoIPService sharedInstance = VoIPService.getSharedInstance();
if (sharedInstance != null) {
if (sharedInstance.groupCall != null && message.messageOwner.action.call.id == sharedInstance.groupCall.call.id) {
if (getParentActivity() instanceof LaunchActivity) {
GroupCallActivity.create((LaunchActivity) getParentActivity(), AccountInstance.getInstance(currentAccount), null, null, false, null);
} else {
Intent intent = new Intent(getParentActivity(), LaunchActivity.class).setAction("voip_chat");
intent.putExtra("currentAccount", VoIPService.getSharedInstance().getAccount());
getParentActivity().startActivity(intent);
}
} else {
createGroupCall = getGroupCall() == null;
VoIPHelper.startCall(currentChat, null, null, createGroupCall, getParentActivity(), ChatActivity.this, getAccountInstance());
}
return;
} else if (fragmentContextView != null && getGroupCall() != null) {
if (VoIPService.getSharedInstance() != null) {
GroupCallActivity.create((LaunchActivity) getParentActivity(), AccountInstance.getInstance(VoIPService.getSharedInstance().getAccount()), null, null, false, null);
} else {
ChatObject.Call call = getGroupCall();
if (call == null) {
return;
}
VoIPHelper.startCall(getMessagesController().getChat(call.chatId), null, null, false, getParentActivity(), ChatActivity.this, getAccountInstance());
}
return;
} else if (ChatObject.canManageCalls(currentChat)) {
VoIPHelper.showGroupCallAlert(ChatActivity.this, currentChat, null, true, getAccountInstance());
return;
}
} else if (message.messageOwner.action instanceof TLRPC.TL_messageActionSetChatTheme) {
showChatThemeBottomSheet();
return;
}
}
if (message.isSponsored() || threadMessageObjects != null && threadMessageObjects.contains(message)) {
single = true;
}
selectedObject = null;
selectedObjectGroup = null;
forwardingMessage = null;
forwardingMessageGroup = null;
selectedObjectToEditCaption = null;
for (int a = 1; a >= 0; a--) {
selectedMessagesCanCopyIds[a].clear();
selectedMessagesCanStarIds[a].clear();
selectedMessagesIds[a].clear();
}
hideActionMode();
updatePinnedMessageView(true);
MessageObject.GroupedMessages groupedMessages;
if (searchGroup) {
groupedMessages = getValidGroupedMessage(message);
} else {
groupedMessages = null;
}
boolean allowChatActions = true;
boolean allowPin;
if (chatMode == MODE_SCHEDULED || isThreadChat()) {
allowPin = false;
} else if (currentChat != null) {
allowPin = message.getDialogId() != mergeDialogId && ChatObject.canPinMessages(currentChat);
} else if (currentEncryptedChat == null) {
if (UserObject.isDeleted(currentUser)) {
allowPin = false;
} else if (userInfo != null) {
allowPin = userInfo.can_pin_message;
} else {
allowPin = false;
}
} else {
allowPin = false;
}
allowPin = allowPin && message.getId() > 0 && (message.messageOwner.action == null || message.messageOwner.action instanceof TLRPC.TL_messageActionEmpty);
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || message.messageOwner.noforwards;
boolean allowUnpin = message.getDialogId() != mergeDialogId && allowPin && (pinnedMessageObjects.containsKey(message.getId()) || groupedMessages != null && !groupedMessages.messages.isEmpty() && pinnedMessageObjects.containsKey(groupedMessages.messages.get(0).getId()));
boolean allowEdit = message.canEditMessage(currentChat) && !chatActivityEnterView.hasAudioToSend() && message.getDialogId() != mergeDialogId;
if (allowEdit && groupedMessages != null) {
int captionsCount = 0;
for (int a = 0, N = groupedMessages.messages.size(); a < N; a++) {
MessageObject messageObject = groupedMessages.messages.get(a);
if (a == 0 || !TextUtils.isEmpty(messageObject.caption)) {
selectedObjectToEditCaption = messageObject;
if (!TextUtils.isEmpty(messageObject.caption)) {
captionsCount++;
}
}
}
allowEdit = captionsCount < 2;
}
if (chatMode == MODE_SCHEDULED || threadMessageObjects != null && threadMessageObjects.contains(message) || message.isSponsored() || type == 1 && message.getDialogId() == mergeDialogId || message.messageOwner.action instanceof TLRPC.TL_messageActionSecureValuesSent || currentEncryptedChat == null && message.getId() < 0 || 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;
}
if (single || type < 2 || type == 20) {
if (getParentActivity() == null) {
return;
}
ArrayList<Integer> icons = new ArrayList<>();
ArrayList<CharSequence> items = new ArrayList<>();
final ArrayList<Integer> options = new ArrayList<>();
CharSequence messageText = null;
if (type >= 0 || type == -1 && single && (message.isSending() || message.isEditing()) && currentEncryptedChat == null) {
selectedObject = message;
selectedObjectGroup = groupedMessages;
// used only in translations
messageText = getMessageCaption(selectedObject, selectedObjectGroup);
if (messageText == null && selectedObject.isPoll()) {
try {
TLRPC.Poll poll = ((TLRPC.TL_messageMediaPoll) selectedObject.messageOwner.media).poll;
StringBuilder pollText = new StringBuilder();
pollText = new StringBuilder(poll.question).append("\n");
for (TLRPC.TL_pollAnswer answer : poll.answers) pollText.append("\n\uD83D\uDD18 ").append(answer.text);
messageText = pollText.toString();
} catch (Exception e) {
}
}
if (messageText == null)
messageText = getMessageContent(selectedObject, 0, false);
if (messageText != null) {
if (isEmoji(messageText.toString()))
// message fully consists of emojis, do not translate
messageText = null;
}
if (type == -1) {
if ((selectedObject.type == 0 || selectedObject.isAnimatedEmoji() || getMessageCaption(selectedObject, selectedObjectGroup) != null) && !noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(OPTION_COPY);
icons.add(R.drawable.msg_copy);
}
items.add(LocaleController.getString("CancelSending", R.string.CancelSending));
options.add(OPTION_CANCEL_SENDING);
icons.add(R.drawable.msg_delete);
} else if (type == 0) {
items.add(LocaleController.getString("Retry", R.string.Retry));
options.add(OPTION_RETRY);
icons.add(R.drawable.msg_retry);
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(OPTION_DELETE);
icons.add(selectedObject.messageOwner.ttl_period != 0 ? R.drawable.msg_delete_auto : R.drawable.msg_delete);
} else if (type == 1) {
if (currentChat != null) {
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(OPTION_REPLY);
icons.add(R.drawable.msg_reply);
}
if (!isThreadChat() && chatMode != MODE_SCHEDULED && message.hasReplies() && currentChat.megagroup && message.canViewThread()) {
items.add(LocaleController.formatPluralString("ViewReplies", message.getRepliesCount()));
options.add(OPTION_VIEW_REPLIES_OR_THREAD);
icons.add(R.drawable.msg_viewreplies);
}
if (allowUnpin) {
items.add(LocaleController.getString("UnpinMessage", R.string.UnpinMessage));
options.add(OPTION_UNPIN);
icons.add(R.drawable.msg_unpin);
} else if (allowPin) {
items.add(LocaleController.getString("PinMessage", R.string.PinMessage));
options.add(OPTION_PIN);
icons.add(R.drawable.msg_pin);
}
if (selectedObject != null && selectedObject.contentType == 0 && (messageText != null && messageText.length() > 0 && !selectedObject.isAnimatedEmoji() && !selectedObject.isDice()) && MessagesController.getGlobalMainSettings().getBoolean("translate_button", false)) {
items.add(LocaleController.getString("TranslateMessage", R.string.TranslateMessage));
options.add(29);
icons.add(R.drawable.msg_translate);
}
if (message.canEditMessage(currentChat)) {
items.add(LocaleController.getString("Edit", R.string.Edit));
options.add(OPTION_EDIT);
icons.add(R.drawable.msg_edit);
}
if (selectedObject.contentType == 0 && !selectedObject.isMediaEmptyWebpage() && selectedObject.getId() > 0 && !selectedObject.isOut() && (currentChat != null || currentUser != null && currentUser.bot)) {
items.add(LocaleController.getString("ReportChat", R.string.ReportChat));
options.add(OPTION_REPORT_CHAT);
icons.add(R.drawable.msg_report);
}
} else {
if (selectedObject.getId() > 0 && allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(OPTION_REPLY);
icons.add(R.drawable.msg_reply);
}
}
if (message.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat) && (threadMessageObjects == null || !threadMessageObjects.contains(message))) {
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(OPTION_DELETE);
icons.add(selectedObject.messageOwner.ttl_period != 0 ? R.drawable.msg_delete_auto : R.drawable.msg_delete);
}
} else if (type == 20) {
items.add(LocaleController.getString("Retry", R.string.Retry));
options.add(OPTION_RETRY);
icons.add(R.drawable.msg_retry);
if (!noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(OPTION_COPY);
icons.add(R.drawable.msg_copy);
}
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(OPTION_DELETE);
icons.add(selectedObject.messageOwner.ttl_period != 0 ? R.drawable.msg_delete_auto : R.drawable.msg_delete);
} else {
if (currentEncryptedChat == null) {
if (chatMode == MODE_SCHEDULED) {
items.add(LocaleController.getString("MessageScheduleSend", R.string.MessageScheduleSend));
options.add(OPTION_SEND_NOW);
icons.add(R.drawable.outline_send);
}
if (selectedObject.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
TLRPC.TL_messageActionPhoneCall call = (TLRPC.TL_messageActionPhoneCall) message.messageOwner.action;
items.add((call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed || call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) && !message.isOutOwner() ? LocaleController.getString("CallBack", R.string.CallBack) : LocaleController.getString("CallAgain", R.string.CallAgain));
options.add(OPTION_CALL_AGAIN);
icons.add(R.drawable.msg_callback);
if (VoIPHelper.canRateCall(call)) {
items.add(LocaleController.getString("CallMessageReportProblem", R.string.CallMessageReportProblem));
options.add(OPTION_RATE_CALL);
icons.add(R.drawable.msg_fave);
}
}
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
icons.add(R.drawable.msg_reply);
}
if ((selectedObject.type == 0 || selectedObject.isDice() || selectedObject.isAnimatedEmoji() || getMessageCaption(selectedObject, selectedObjectGroup) != null) && !noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(3);
icons.add(R.drawable.msg_copy);
}
if (!isThreadChat() && chatMode != MODE_SCHEDULED && currentChat != null && (currentChat.has_link || message.hasReplies()) && currentChat.megagroup && message.canViewThread()) {
if (message.hasReplies()) {
items.add(LocaleController.formatPluralString("ViewReplies", message.getRepliesCount()));
} else {
items.add(LocaleController.getString("ViewThread", R.string.ViewThread));
}
options.add(27);
icons.add(R.drawable.msg_viewreplies);
}
if (!selectedObject.isSponsored() && chatMode != MODE_SCHEDULED && ChatObject.isChannel(currentChat) && selectedObject.getDialogId() != mergeDialogId) {
items.add(LocaleController.getString("CopyLink", R.string.CopyLink));
options.add(22);
icons.add(R.drawable.msg_link);
}
if (type == 2) {
if (chatMode != MODE_SCHEDULED) {
if (selectedObject.type == MessageObject.TYPE_POLL && !message.isPollClosed()) {
if (message.canUnvote()) {
items.add(LocaleController.getString("Unvote", R.string.Unvote));
options.add(25);
icons.add(R.drawable.msg_unvote);
}
if (!message.isForwarded() && (message.isOut() && (!ChatObject.isChannel(currentChat) || currentChat.megagroup) || ChatObject.isChannel(currentChat) && !currentChat.megagroup && (currentChat.creator || currentChat.admin_rights != null && currentChat.admin_rights.edit_messages))) {
if (message.isQuiz()) {
items.add(LocaleController.getString("StopQuiz", R.string.StopQuiz));
} else {
items.add(LocaleController.getString("StopPoll", R.string.StopPoll));
}
options.add(26);
icons.add(R.drawable.msg_pollstop);
}
} else if (selectedObject.isMusic() && !noforwards) {
items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
} else if (selectedObject.isDocument() && !noforwards) {
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
}
}
} else if (type == 3 && !noforwards) {
if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && MessageObject.isNewGifDocument(selectedObject.messageOwner.media.webpage.document)) {
items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
options.add(11);
icons.add(R.drawable.msg_gif);
}
} else if (type == 4) {
if (!noforwards) {
if (selectedObject.isVideo()) {
if (!selectedObject.needDrawBluredPreview()) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
icons.add(R.drawable.msg_gallery);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
}
} else if (selectedObject.isMusic()) {
items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (selectedObject.getDocument() != null) {
if (MessageObject.isNewGifDocument(selectedObject.getDocument())) {
items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
options.add(11);
icons.add(R.drawable.msg_gif);
}
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else {
if (!selectedObject.needDrawBluredPreview()) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
icons.add(R.drawable.msg_gallery);
}
}
}
} else if (type == 5) {
items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
options.add(5);
icons.add(R.drawable.msg_language);
if (!noforwards) {
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
}
} else if (type == 10) {
items.add(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
options.add(5);
icons.add(R.drawable.msg_theme);
if (!noforwards) {
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
}
} else if (type == 6 && !noforwards) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(7);
icons.add(R.drawable.msg_gallery);
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (type == 7) {
if (selectedObject.isMask()) {
items.add(LocaleController.getString("AddToMasks", R.string.AddToMasks));
options.add(9);
icons.add(R.drawable.msg_sticker);
} else {
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
options.add(9);
icons.add(R.drawable.msg_sticker);
TLRPC.Document document = selectedObject.getDocument();
if (!getMediaDataController().isStickerInFavorites(document)) {
if (getMediaDataController().canAddStickerToFavorites() && MessageObject.isStickerHasSet(document)) {
items.add(LocaleController.getString("AddToFavorites", R.string.AddToFavorites));
options.add(20);
icons.add(R.drawable.msg_fave);
}
} else {
items.add(LocaleController.getString("DeleteFromFavorites", R.string.DeleteFromFavorites));
options.add(21);
icons.add(R.drawable.msg_unfave);
}
}
} else if (type == 8) {
long uid = selectedObject.messageOwner.media.user_id;
TLRPC.User user = null;
if (uid != 0) {
user = MessagesController.getInstance(currentAccount).getUser(uid);
}
if (user != null && user.id != getUserConfig().getClientUserId() && getContactsController().contactsDict.get(user.id) == null) {
items.add(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
options.add(15);
icons.add(R.drawable.msg_addcontact);
}
if (!TextUtils.isEmpty(selectedObject.messageOwner.media.phone_number)) {
if (!noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(16);
icons.add(R.drawable.msg_copy);
}
items.add(LocaleController.getString("Call", R.string.Call));
options.add(17);
icons.add(R.drawable.msg_callback);
}
} else if (type == 9) {
TLRPC.Document document = selectedObject.getDocument();
if (!getMediaDataController().isStickerInFavorites(document)) {
if (MessageObject.isStickerHasSet(document)) {
items.add(LocaleController.getString("AddToFavorites", R.string.AddToFavorites));
options.add(20);
icons.add(R.drawable.msg_fave);
}
} else {
items.add(LocaleController.getString("DeleteFromFavorites", R.string.DeleteFromFavorites));
options.add(21);
icons.add(R.drawable.msg_unfave);
}
}
if (!selectedObject.isSponsored() && chatMode != MODE_SCHEDULED && !selectedObject.needDrawBluredPreview() && !selectedObject.isLiveLocation() && selectedObject.type != 16 && !noforwards) {
items.add(LocaleController.getString("Forward", R.string.Forward));
options.add(2);
icons.add(R.drawable.msg_forward);
}
if (allowUnpin) {
items.add(LocaleController.getString("UnpinMessage", R.string.UnpinMessage));
options.add(14);
icons.add(R.drawable.msg_unpin);
} else if (allowPin) {
items.add(LocaleController.getString("PinMessage", R.string.PinMessage));
options.add(13);
icons.add(R.drawable.msg_pin);
}
if (selectedObject != null && selectedObject.contentType == 0 && (messageText != null && messageText.length() > 0 && !selectedObject.isAnimatedEmoji() && !selectedObject.isDice()) && MessagesController.getGlobalMainSettings().getBoolean("translate_button", false)) {
items.add(LocaleController.getString("TranslateMessage", R.string.TranslateMessage));
options.add(29);
icons.add(R.drawable.msg_translate);
}
if (allowEdit) {
items.add(LocaleController.getString("Edit", R.string.Edit));
options.add(12);
icons.add(R.drawable.msg_edit);
}
if (chatMode == MODE_SCHEDULED && selectedObject.canEditMessageScheduleTime(currentChat)) {
items.add(LocaleController.getString("MessageScheduleEditTime", R.string.MessageScheduleEditTime));
options.add(102);
icons.add(R.drawable.msg_schedule);
}
if (chatMode != MODE_SCHEDULED && selectedObject.contentType == 0 && selectedObject.getId() > 0 && !selectedObject.isOut() && (currentChat != null || currentUser != null && currentUser.bot)) {
if (UserObject.isReplyUser(currentUser)) {
items.add(LocaleController.getString("BlockContact", R.string.BlockContact));
options.add(23);
icons.add(R.drawable.msg_block2);
} else {
items.add(LocaleController.getString("ReportChat", R.string.ReportChat));
options.add(23);
icons.add(R.drawable.msg_report);
}
}
if (message.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat) && (threadMessageObjects == null || !threadMessageObjects.contains(message))) {
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
icons.add(selectedObject.messageOwner.ttl_period != 0 ? R.drawable.msg_delete_auto : R.drawable.msg_delete);
}
} else {
if (allowChatActions) {
items.add(LocaleController.getString("Reply", R.string.Reply));
options.add(8);
icons.add(R.drawable.msg_reply);
}
if ((selectedObject.type == 0 || selectedObject.isAnimatedEmoji() || getMessageCaption(selectedObject, selectedObjectGroup) != null) && !noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(3);
icons.add(R.drawable.msg_copy);
}
if (!isThreadChat() && chatMode != MODE_SCHEDULED && currentChat != null && (currentChat.has_link || message.hasReplies()) && currentChat.megagroup && message.canViewThread()) {
if (message.hasReplies()) {
items.add(LocaleController.formatPluralString("ViewReplies", message.getRepliesCount()));
} else {
items.add(LocaleController.getString("ViewThread", R.string.ViewThread));
}
options.add(27);
icons.add(R.drawable.msg_viewreplies);
}
if (type == 4 && !noforwards) {
if (selectedObject.isVideo()) {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
icons.add(R.drawable.msg_gallery);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (selectedObject.isMusic()) {
items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else if (!selectedObject.isVideo() && selectedObject.getDocument() != null) {
items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
options.add(OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC);
icons.add(R.drawable.msg_download);
items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
options.add(6);
icons.add(R.drawable.msg_shareout);
} else {
items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
options.add(4);
icons.add(R.drawable.msg_gallery);
}
} else if (type == 5) {
items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
options.add(5);
icons.add(R.drawable.msg_language);
} else if (type == 10) {
items.add(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
options.add(5);
icons.add(R.drawable.msg_theme);
} else if (type == 7) {
items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
options.add(9);
icons.add(R.drawable.msg_sticker);
} else if (type == 8) {
long uid = selectedObject.messageOwner.media.user_id;
TLRPC.User user = null;
if (uid != 0) {
user = MessagesController.getInstance(currentAccount).getUser(uid);
}
if (user != null && user.id != getUserConfig().getClientUserId() && getContactsController().contactsDict.get(user.id) == null) {
items.add(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
options.add(15);
icons.add(R.drawable.msg_addcontact);
}
if (!TextUtils.isEmpty(selectedObject.messageOwner.media.phone_number)) {
if (!noforwards) {
items.add(LocaleController.getString("Copy", R.string.Copy));
options.add(16);
icons.add(R.drawable.msg_copy);
}
items.add(LocaleController.getString("Call", R.string.Call));
options.add(17);
icons.add(R.drawable.msg_callback);
}
}
items.add(LocaleController.getString("Delete", R.string.Delete));
options.add(1);
icons.add(selectedObject.messageOwner.ttl_period != 0 ? R.drawable.msg_delete_auto : R.drawable.msg_delete);
}
}
}
if (options.isEmpty()) {
return;
}
if (scrimPopupWindow != null) {
closeMenu();
menuDeleteItem = null;
scrimPopupWindowItems = null;
return;
}
final AtomicBoolean waitForLangDetection = new AtomicBoolean(false);
final AtomicReference<Runnable> onLangDetectionDone = new AtomicReference(null);
Rect rect = new Rect();
List<TLRPC.TL_availableReaction> availableReacts = getMediaDataController().getEnabledReactionsList();
boolean isReactionsViewAvailable = !isSecretChat() && !isInScheduleMode() && currentUser == null && message.hasReactions() && (!ChatObject.isChannel(currentChat) || currentChat.megagroup) && !availableReacts.isEmpty() && message.messageOwner.reactions.can_see_list;
boolean isReactionsAvailable;
if (message.isForwardedChannelPost()) {
TLRPC.ChatFull chatInfo = getMessagesController().getChatFull(-message.getFromChatId());
if (chatInfo == null) {
isReactionsAvailable = true;
} else {
isReactionsAvailable = !isSecretChat() && !isInScheduleMode() && message.isReactionsAvailable() && (chatInfo != null && !chatInfo.available_reactions.isEmpty()) && !availableReacts.isEmpty();
}
} else {
isReactionsAvailable = !isSecretChat() && !isInScheduleMode() && message.isReactionsAvailable() && (chatInfo != null && !chatInfo.available_reactions.isEmpty() || (chatInfo == null && !ChatObject.isChannel(currentChat)) || currentUser != null) && !availableReacts.isEmpty();
}
boolean showMessageSeen = !isReactionsViewAvailable && !isInScheduleMode() && currentChat != null && message.isOutOwner() && message.isSent() && !message.isEditing() && !message.isSending() && !message.isSendError() && !message.isContentUnread() && !message.isUnread() && (ConnectionsManager.getInstance(currentAccount).getCurrentTime() - message.messageOwner.date < getMessagesController().chatReadMarkExpirePeriod) && (ChatObject.isMegagroup(currentChat) || !ChatObject.isChannel(currentChat)) && chatInfo != null && chatInfo.participants_count < getMessagesController().chatReadMarkSizeThreshold && !(message.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByRequest) && (v instanceof ChatMessageCell);
int flags = 0;
if (isReactionsViewAvailable || showMessageSeen) {
flags |= ActionBarPopupWindow.ActionBarPopupWindowLayout.FLAG_USE_SWIPEBACK;
}
ActionBarPopupWindow.ActionBarPopupWindowLayout popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity(), R.drawable.popup_fixed_alert, themeDelegate, flags);
popupLayout.setMinimumWidth(AndroidUtilities.dp(200));
Rect backgroundPaddings = new Rect();
Drawable shadowDrawable = getParentActivity().getResources().getDrawable(R.drawable.popup_fixed_alert).mutate();
shadowDrawable.getPadding(backgroundPaddings);
popupLayout.setBackgroundColor(getThemedColor(Theme.key_actionBarDefaultSubmenuBackground));
if (isReactionsViewAvailable) {
ReactedHeaderView reactedView = new ReactedHeaderView(contentView.getContext(), currentAccount, message, dialog_id);
int count = 0;
if (message.messageOwner.reactions != null) {
for (TLRPC.TL_reactionCount r : message.messageOwner.reactions.results) {
count += r.count;
}
}
boolean hasHeader = count > 10;
LinearLayout linearLayout = new LinearLayout(contentView.getContext()) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int size = MeasureSpec.getSize(widthMeasureSpec);
if (size < AndroidUtilities.dp(240)) {
size = AndroidUtilities.dp(240);
}
super.onMeasure(MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY), heightMeasureSpec);
}
};
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new FrameLayout.LayoutParams(AndroidUtilities.dp(200), AndroidUtilities.dp(6 * 48 + (hasHeader ? 44 * 2 + 8 : 44)) + (!hasHeader ? 1 : 0)));
ActionBarMenuSubItem backCell = new ActionBarMenuSubItem(getParentActivity(), true, false, themeDelegate);
backCell.setItemHeight(44);
backCell.setTextAndIcon(LocaleController.getString("Back", R.string.Back), R.drawable.msg_arrow_back);
backCell.getTextView().setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(40), 0, LocaleController.isRTL ? AndroidUtilities.dp(40) : 0, 0);
backCell.setOnClickListener(v1 -> popupLayout.getSwipeBack().closeForeground());
linearLayout.addView(backCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
int[] foregroundIndex = new int[1];
if (hasHeader) {
List<TLRPC.TL_reactionCount> counters = message.messageOwner.reactions.results;
LinearLayout tabsView = new LinearLayout(contentView.getContext());
tabsView.setOrientation(LinearLayout.HORIZONTAL);
ViewPager pager = new ViewPager(contentView.getContext());
HorizontalScrollView tabsScrollView = new HorizontalScrollView(contentView.getContext());
AtomicBoolean suppressTabsScroll = new AtomicBoolean();
int size = counters.size() + 1;
for (int i = 0; i < size; i++) {
ReactionTabHolderView hv = new ReactionTabHolderView(contentView.getContext());
if (i == 0) {
hv.setCounter(count);
} else
hv.setCounter(currentAccount, counters.get(i - 1));
int finalI = i;
hv.setOnClickListener(v1 -> {
int from = pager.getCurrentItem();
if (finalI == from)
return;
ReactionTabHolderView fv = (ReactionTabHolderView) tabsView.getChildAt(from);
suppressTabsScroll.set(true);
pager.setCurrentItem(finalI, true);
float fSX = tabsScrollView.getScrollX(), tSX = hv.getX() - (tabsScrollView.getWidth() - hv.getWidth()) / 2f;
ValueAnimator a = ValueAnimator.ofFloat(0, 1).setDuration(150);
a.setInterpolator(CubicBezierInterpolator.DEFAULT);
a.addUpdateListener(animation -> {
float f = (float) animation.getAnimatedValue();
tabsScrollView.setScrollX((int) (fSX + (tSX - fSX) * f));
fv.setOutlineProgress(1f - f);
hv.setOutlineProgress(f);
});
a.start();
});
tabsView.addView(hv, LayoutHelper.createFrameRelatively(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL, i == 0 ? 6 : 0, 6, 6, 6));
}
tabsScrollView.setHorizontalScrollBarEnabled(false);
tabsScrollView.addView(tabsView);
linearLayout.addView(tabsScrollView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 44));
View divider = new FrameLayout(contentView.getContext());
divider.setBackgroundColor(Theme.getColor(Theme.key_graySection));
linearLayout.addView(divider, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) Theme.dividerPaint.getStrokeWidth()));
int head = AndroidUtilities.dp(44 * 2) + 1;
SparseArray<ReactedUsersListView> cachedViews = new SparseArray<>();
SparseIntArray cachedHeights = new SparseIntArray();
for (int i = 0; i < counters.size() + 1; i++) cachedHeights.put(i, head + AndroidUtilities.dp(ReactedUsersListView.ITEM_HEIGHT_DP * ReactedUsersListView.VISIBLE_ITEMS));
pager.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return counters.size() + 1;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View cached = cachedViews.get(position);
if (cached != null) {
container.addView(cached);
return cached;
}
ReactedUsersListView v = new ReactedUsersListView(container.getContext(), themeDelegate, currentAccount, message, position == 0 ? null : counters.get(position - 1), true).setSeenUsers(reactedView.getSeenUsers()).setOnProfileSelectedListener((view, userId) -> {
Bundle args = new Bundle();
args.putLong("user_id", userId);
ProfileActivity fragment = new ProfileActivity(args);
presentFragment(fragment);
closeMenu();
}).setOnHeightChangedListener((view, newHeight) -> {
cachedHeights.put(position, head + newHeight);
if (pager.getCurrentItem() == position)
popupLayout.getSwipeBack().setNewForegroundHeight(foregroundIndex[0], head + newHeight);
});
if (position == 0)
reactedView.setSeenCallback(v::setSeenUsers);
container.addView(v);
cachedViews.put(position, v);
return v;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
});
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (!suppressTabsScroll.get()) {
float fX = -1, tX = -1;
for (int i = 0; i < tabsView.getChildCount(); i++) {
ReactionTabHolderView ch = (ReactionTabHolderView) tabsView.getChildAt(i);
ch.setOutlineProgress(i == position ? 1f - positionOffset : i == (position + 1) % size ? positionOffset : 0);
if (i == position) {
fX = ch.getX() - (tabsScrollView.getWidth() - ch.getWidth()) / 2f;
}
if (i == position + 1) {
tX = ch.getX() - (tabsScrollView.getWidth() - ch.getWidth()) / 2f;
}
}
if (fX != -1 && tX != -1)
tabsScrollView.setScrollX((int) (fX + (tX - fX) * positionOffset));
}
}
@Override
public void onPageSelected(int position) {
int h = cachedHeights.get(position);
popupLayout.getSwipeBack().setNewForegroundHeight(foregroundIndex[0], h);
}
@Override
public void onPageScrollStateChanged(int state) {
if (state == ViewPager.SCROLL_STATE_IDLE) {
suppressTabsScroll.set(false);
}
}
});
linearLayout.addView(pager, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 0, 1f));
} else {
View gap = new FrameLayout(contentView.getContext());
gap.setBackgroundColor(Theme.getColor(Theme.key_graySection));
linearLayout.addView(gap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 8));
ReactedUsersListView lv = new ReactedUsersListView(contentView.getContext(), themeDelegate, currentAccount, message, null, true).setSeenUsers(reactedView.getSeenUsers()).setOnProfileSelectedListener((view, userId) -> {
Bundle args = new Bundle();
args.putLong("user_id", userId);
ProfileActivity fragment = new ProfileActivity(args);
presentFragment(fragment);
closeMenu();
}).setOnHeightChangedListener((view, newHeight) -> popupLayout.getSwipeBack().setNewForegroundHeight(foregroundIndex[0], AndroidUtilities.dp(44 + 8) + newHeight));
reactedView.setSeenCallback(lv::setSeenUsers);
linearLayout.addView(lv, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 0, 1f));
}
foregroundIndex[0] = popupLayout.addViewToSwipeBack(linearLayout);
reactedView.setOnClickListener(v1 -> {
popupLayout.getSwipeBack().openForeground(foregroundIndex[0]);
});
popupLayout.addView(reactedView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
View gap = new FrameLayout(contentView.getContext());
gap.setBackgroundColor(Theme.getColor(Theme.key_graySection));
popupLayout.addView(gap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 8));
}
MessageSeenView messageSeenView = null;
if (showMessageSeen) {
messageSeenView = new MessageSeenView(contentView.getContext(), currentAccount, message, currentChat);
FrameLayout messageSeenLayout = new FrameLayout(contentView.getContext());
messageSeenLayout.addView(messageSeenView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
MessageSeenView finalMessageSeenView = messageSeenView;
ActionBarMenuSubItem cell = new ActionBarMenuSubItem(getParentActivity(), true, true, themeDelegate);
cell.setItemHeight(44);
cell.setTextAndIcon(LocaleController.getString("Back", R.string.Back), R.drawable.msg_arrow_back);
cell.getTextView().setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(40), 0, LocaleController.isRTL ? AndroidUtilities.dp(40) : 0, 0);
FrameLayout backContainer = new FrameLayout(contentView.getContext());
LinearLayout linearLayout = new LinearLayout(contentView.getContext());
linearLayout.setBackgroundColor(getThemedColor(Theme.key_actionBarDefaultSubmenuBackground));
linearLayout.setOrientation(LinearLayout.VERTICAL);
RecyclerListView listView2 = finalMessageSeenView.createListView();
backContainer.addView(cell);
linearLayout.addView(backContainer);
backContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupLayout.getSwipeBack().closeForeground();
}
});
int[] foregroundIndex = new int[1];
messageSeenView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (scrimPopupWindow == null || finalMessageSeenView.users.isEmpty()) {
return;
}
if (finalMessageSeenView.users.size() == 1) {
TLRPC.User user = finalMessageSeenView.users.get(0);
if (user == null) {
return;
}
Bundle args = new Bundle();
args.putLong("user_id", user.id);
ProfileActivity fragment = new ProfileActivity(args);
presentFragment(fragment);
closeMenu();
return;
}
int totalHeight = contentView.getHeightWithKeyboard();
int availableHeight = totalHeight - scrimPopupY - AndroidUtilities.dp(46 + 16) - (isReactionsAvailable ? AndroidUtilities.dp(52) : 0);
if (SharedConfig.messageSeenHintCount > 0 && contentView.getKeyboardHeight() < AndroidUtilities.dp(20)) {
availableHeight -= AndroidUtilities.dp(52);
Bulletin bulletin = BulletinFactory.of(ChatActivity.this).createErrorBulletin(AndroidUtilities.replaceTags(LocaleController.getString("MessageSeenTooltipMessage", R.string.MessageSeenTooltipMessage)));
bulletin.tag = 1;
bulletin.setDuration(4000);
bulletin.show();
SharedConfig.updateMessageSeenHintCount(SharedConfig.messageSeenHintCount - 1);
} else if (contentView.getKeyboardHeight() > AndroidUtilities.dp(20)) {
availableHeight -= contentView.getKeyboardHeight() / 3f;
}
int listViewTotalHeight = AndroidUtilities.dp(8) + AndroidUtilities.dp(44) * listView2.getAdapter().getItemCount();
if (listViewTotalHeight > availableHeight) {
if (availableHeight > AndroidUtilities.dp(620)) {
listView2.getLayoutParams().height = AndroidUtilities.dp(620);
} else {
listView2.getLayoutParams().height = availableHeight;
}
} else {
listView2.getLayoutParams().height = listViewTotalHeight;
}
linearLayout.getLayoutParams().height = AndroidUtilities.dp(44) + listView2.getLayoutParams().height;
listView2.requestLayout();
linearLayout.requestLayout();
listView2.getAdapter().notifyDataSetChanged();
popupLayout.getSwipeBack().openForeground(foregroundIndex[0]);
}
});
linearLayout.addView(listView2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 320));
listView2.setOnItemClickListener((view1, position) -> {
TLRPC.User user = finalMessageSeenView.users.get(position);
if (user == null) {
return;
}
Bundle args = new Bundle();
args.putLong("user_id", user.id);
ProfileActivity fragment = new ProfileActivity(args);
presentFragment(fragment);
});
foregroundIndex[0] = popupLayout.addViewToSwipeBack(linearLayout);
popupLayout.addView(messageSeenLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 44));
View gap = new FrameLayout(contentView.getContext());
gap.setBackgroundColor(Theme.getColor(Theme.key_graySection));
popupLayout.addView(gap, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 8));
}
if (popupLayout.getSwipeBack() != null) {
popupLayout.getSwipeBack().setOnClickListener(e -> closeMenu());
}
scrimPopupWindowItems = new ActionBarMenuSubItem[items.size() + (selectedObject.isSponsored() ? 1 : 0)];
for (int a = 0, N = items.size(); a < N; a++) {
if (a == 0 && selectedObject.isSponsored()) {
ActionBarMenuSubItem cell = new ActionBarMenuSubItem(getParentActivity(), true, true, themeDelegate);
cell.setTextAndIcon(LocaleController.getString("SponsoredMessageInfo", R.string.SponsoredMessageInfo), R.drawable.menu_info);
cell.setItemHeight(56);
cell.setTag(R.id.width_tag, 240);
cell.setMultiline();
scrimPopupWindowItems[scrimPopupWindowItems.length - 1] = cell;
popupLayout.addView(cell);
cell.setOnClickListener(v1 -> {
if (contentView == null || getParentActivity() == null) {
return;
}
BottomSheet.Builder builder = new BottomSheet.Builder(contentView.getContext());
builder.setCustomView(new SponsoredMessageInfoView(getParentActivity(), themeDelegate));
builder.show();
});
View gap = new View(getParentActivity());
gap.setMinimumWidth(AndroidUtilities.dp(196));
gap.setTag(1000);
gap.setTag(R.id.object_tag, 1);
popupLayout.addView(gap);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) cell.getLayoutParams();
if (LocaleController.isRTL) {
layoutParams.gravity = Gravity.RIGHT;
}
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = AndroidUtilities.dp(6);
gap.setLayoutParams(layoutParams);
}
ActionBarMenuSubItem cell = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == N - 1, themeDelegate);
cell.setMinimumWidth(AndroidUtilities.dp(200));
cell.setTextAndIcon(items.get(a), icons.get(a));
Integer option = options.get(a);
if (option == 1 && selectedObject.messageOwner.ttl_period != 0) {
menuDeleteItem = cell;
updateDeleteItemRunnable.run();
cell.setSubtextColor(getThemedColor(Theme.key_windowBackgroundWhiteGrayText6));
}
scrimPopupWindowItems[a] = cell;
popupLayout.addView(cell);
final int i = a;
cell.setOnClickListener(v1 -> {
if (selectedObject == null || i >= options.size()) {
return;
}
processSelectedOption(options.get(i));
});
if (option == 29) {
// "Translate" button
String toLang = LocaleController.getInstance().getCurrentLocale().getLanguage();
final CharSequence finalMessageText = messageText;
TranslateAlert.OnLinkPress onLinkPress = (link) -> {
didPressMessageUrl(link, false, selectedObject, v instanceof ChatMessageCell ? (ChatMessageCell) v : null);
};
TLRPC.InputPeer inputPeer = getMessagesController().getInputPeer(dialog_id);
int messageId = selectedObject.messageOwner.id;
/*if (LanguageDetector.hasSupport()) {
final String[] fromLang = { null };
cell.setVisibility(View.GONE);
waitForLangDetection.set(true);
LanguageDetector.detectLanguage(
finalMessageText.toString(),
(String lang) -> {
fromLang[0] = lang;
if (fromLang[0] != null && (!fromLang[0].equals(toLang) || fromLang[0].equals("und")) &&
!RestrictedLanguagesSelectActivity.getRestrictedLanguages().contains(fromLang[0])) {
cell.setVisibility(View.VISIBLE);
}
waitForLangDetection.set(false);
if (onLangDetectionDone.get() != null) {
onLangDetectionDone.get().run();
onLangDetectionDone.set(null);
}
},
(Exception e) -> {
FileLog.e("mlkit: failed to detect language in message");
e.printStackTrace();
waitForLangDetection.set(false);
if (onLangDetectionDone.get() != null) {
onLangDetectionDone.get().run();
onLangDetectionDone.set(null);
}
}
);
cell.setOnClickListener(e -> {
if (selectedObject == null || i >= options.size() || getParentActivity() == null) {
return;
}
TranslateAlert alert = TranslateAlert.showAlert(getParentActivity(), this, currentAccount, inputPeer, messageId, fromLang[0], toLang, finalMessageText, noforwards, onLinkPress, () -> dimBehindView(false));
alert.showDim(false);
closeMenu(false);
});
cell.postDelayed(() -> {
if (onLangDetectionDone.get() != null) {
onLangDetectionDone.getAndSet(null).run();
}
}, 250);
} else {*/
cell.setOnClickListener(e -> {
if (selectedObject == null || i >= options.size() || getParentActivity() == null) {
return;
}
TranslateAlert alert = TranslateAlert.showAlert(getParentActivity(), this, currentAccount, inputPeer, messageId, "und", toLang, finalMessageText, noforwards, onLinkPress, () -> dimBehindView(false));
alert.showDim(false);
closeMenu(false);
});
// }
}
}
ChatScrimPopupContainerLayout scrimPopupContainerLayout = new ChatScrimPopupContainerLayout(contentView.getContext()) {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
closeMenu();
}
return super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
boolean b = super.dispatchTouchEvent(ev);
if (ev.getAction() == MotionEvent.ACTION_DOWN && !b) {
closeMenu();
}
return b;
}
};
scrimPopupContainerLayout.setOnTouchListener(new View.OnTouchListener() {
private int[] pos = new int[2];
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
if (scrimPopupWindow != null && scrimPopupWindow.isShowing()) {
View contentView = scrimPopupWindow.getContentView();
contentView.getLocationInWindow(pos);
rect.set(pos[0], pos[1], pos[0] + contentView.getMeasuredWidth(), pos[1] + contentView.getMeasuredHeight());
if (!rect.contains((int) event.getX(), (int) event.getY())) {
closeMenu();
}
}
} else if (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE) {
closeMenu();
}
return false;
}
});
ReactionsContainerLayout reactionsLayout = new ReactionsContainerLayout(contentView.getContext(), currentAccount, getResourceProvider());
if (isReactionsAvailable) {
int pad = 22;
int sPad = 24;
reactionsLayout.setPadding(AndroidUtilities.dp(4) + (LocaleController.isRTL ? 0 : sPad), AndroidUtilities.dp(4), AndroidUtilities.dp(4) + (LocaleController.isRTL ? sPad : 0), AndroidUtilities.dp(pad));
reactionsLayout.setDelegate((rView, reaction, longress) -> {
selectReaction(primaryMessage, reactionsLayout, 0, 0, reaction, false, longress);
});
LinearLayout.LayoutParams params = LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52 + pad, Gravity.RIGHT, 0, 50, 0, -20);
scrimPopupContainerLayout.addView(reactionsLayout, params);
scrimPopupContainerLayout.reactionsLayout = reactionsLayout;
scrimPopupContainerLayout.setClipChildren(false);
reactionsLayout.setMessage(message, chatInfo);
reactionsLayout.setTransitionProgress(0);
if (popupLayout.getSwipeBack() != null) {
popupLayout.getSwipeBack().setOnSwipeBackProgressListener((layout, toProgress, progress) -> {
if (toProgress == 0) {
reactionsLayout.startEnterAnimation();
} else if (toProgress == 1)
reactionsLayout.setAlpha(1f - progress);
});
}
}
boolean showNoForwards = noforwards && message.messageOwner.action == null && message.isSent() && !message.isEditing() && chatMode != MODE_SCHEDULED;
scrimPopupContainerLayout.addView(popupLayout, LayoutHelper.createLinearRelatively(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT, isReactionsAvailable ? 16 : 0, 0, isReactionsAvailable ? 36 : 0, 0));
scrimPopupContainerLayout.popupWindowLayout = popupLayout;
if (showNoForwards) {
popupLayout.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
boolean isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup;
TextView tv = new TextView(contentView.getContext());
tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
tv.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
if (getMessagesController().isChatNoForwards(currentChat)) {
tv.setText(isChannel ? LocaleController.getString("ForwardsRestrictedInfoChannel", R.string.ForwardsRestrictedInfoChannel) : LocaleController.getString("ForwardsRestrictedInfoGroup", R.string.ForwardsRestrictedInfoGroup));
} else {
tv.setText(LocaleController.getString("ForwardsRestrictedInfoBot", R.string.ForwardsRestrictedInfoBot));
}
tv.setMaxWidth(popupLayout.getMeasuredWidth() - AndroidUtilities.dp(38));
Drawable shadowDrawable2 = ContextCompat.getDrawable(contentView.getContext(), R.drawable.popup_fixed_alert).mutate();
shadowDrawable2.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_actionBarDefaultSubmenuBackground), PorterDuff.Mode.MULTIPLY));
FrameLayout fl = new FrameLayout(contentView.getContext());
fl.setBackground(shadowDrawable2);
fl.addView(tv, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 11, 11, 11));
scrimPopupContainerLayout.addView(fl, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT, isReactionsAvailable ? 16 : 0, -8, isReactionsAvailable ? 36 : 0, 0));
}
scrimPopupWindow = new ActionBarPopupWindow(scrimPopupContainerLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT) {
@Override
public void dismiss() {
super.dismiss();
if (scrimPopupWindow != this) {
return;
}
scrimPopupWindow = null;
menuDeleteItem = null;
scrimPopupWindowItems = null;
chatLayoutManager.setCanScrollVertically(true);
if (scrimPopupWindowHideDimOnDismiss) {
dimBehindView(false);
} else {
scrimPopupWindowHideDimOnDismiss = true;
}
if (chatActivityEnterView != null) {
chatActivityEnterView.getEditField().setAllowDrawCursor(true);
}
}
};
scrimPopupWindow.setPauseNotifications(true);
scrimPopupWindow.setDismissAnimationDuration(220);
scrimPopupWindow.setOutsideTouchable(true);
scrimPopupWindow.setClippingEnabled(true);
scrimPopupWindow.setAnimationStyle(R.style.PopupContextAnimation);
scrimPopupWindow.setFocusable(true);
scrimPopupContainerLayout.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);
popupLayout.setFitItems(true);
int popupX = v.getLeft() + (int) x - scrimPopupContainerLayout.getMeasuredWidth() + backgroundPaddings.left - AndroidUtilities.dp(28);
if (popupX < AndroidUtilities.dp(6)) {
popupX = AndroidUtilities.dp(6);
} else if (popupX > chatListView.getMeasuredWidth() - AndroidUtilities.dp(6) - scrimPopupContainerLayout.getMeasuredWidth()) {
popupX = chatListView.getMeasuredWidth() - AndroidUtilities.dp(6) - scrimPopupContainerLayout.getMeasuredWidth();
}
if (AndroidUtilities.isTablet()) {
int[] location = new int[2];
fragmentView.getLocationInWindow(location);
popupX += location[0];
}
int totalHeight = contentView.getHeight();
int height = scrimPopupContainerLayout.getMeasuredHeight() + AndroidUtilities.dp(48);
int keyboardHeight = contentView.measureKeyboardHeight();
if (keyboardHeight > AndroidUtilities.dp(20)) {
totalHeight += keyboardHeight;
}
int popupY;
if (height < totalHeight) {
popupY = (int) (chatListView.getY() + v.getTop() + y);
if (height - backgroundPaddings.top - backgroundPaddings.bottom > AndroidUtilities.dp(240)) {
popupY += AndroidUtilities.dp(240) - height;
}
if (popupY < chatListView.getY() + AndroidUtilities.dp(24)) {
popupY = (int) (chatListView.getY() + AndroidUtilities.dp(24));
} else if (popupY > totalHeight - height - AndroidUtilities.dp(8)) {
popupY = totalHeight - height - AndroidUtilities.dp(8);
}
} else {
popupY = inBubbleMode ? 0 : AndroidUtilities.statusBarHeight;
}
final int finalPopupX = scrimPopupX = popupX;
final int finalPopupY = scrimPopupY = popupY;
Runnable showMenu = () -> {
if (scrimPopupWindow == null || fragmentView == null) {
return;
}
scrimPopupWindow.showAtLocation(chatListView, Gravity.LEFT | Gravity.TOP, finalPopupX, finalPopupY);
if (isReactionsAvailable) {
reactionsLayout.startEnterAnimation();
}
};
if (waitForLangDetection.get()) {
onLangDetectionDone.set(showMenu);
} else {
showMenu.run();
}
chatListView.stopScroll();
chatLayoutManager.setCanScrollVertically(false);
dimBehindView(v, true);
hideHints(false);
if (topUndoView != null) {
topUndoView.hide(true, 1);
}
if (undoView != null) {
undoView.hide(true, 1);
}
if (chatActivityEnterView != null) {
chatActivityEnterView.getEditField().setAllowDrawCursor(false);
}
return;
}
if (chatActivityEnterView != null && (chatActivityEnterView.isRecordingAudioVideo() || chatActivityEnterView.isRecordLocked())) {
return;
}
final ActionBarMenu actionMode = actionBar.createActionMode();
View item = actionMode.getItem(delete);
if (item != null) {
item.setVisibility(View.VISIBLE);
}
bottomMessagesActionContainer.setVisibility(View.VISIBLE);
int translationY = chatActivityEnterView.getMeasuredHeight() - AndroidUtilities.dp(51);
if (chatActivityEnterView.getVisibility() == View.VISIBLE) {
ArrayList<View> views = new ArrayList<>();
views.add(chatActivityEnterView);
if (mentionContainer != null && mentionContainer.getVisibility() == View.VISIBLE) {
views.add(mentionContainer);
}
if (stickersPanel != null && stickersPanel.getVisibility() == View.VISIBLE) {
views.add(stickersPanel);
}
actionBar.showActionMode(true, bottomMessagesActionContainer, null, views.toArray(new View[0]), new boolean[] { false, true, true }, chatListView, translationY);
if (getParentActivity() instanceof LaunchActivity) {
((LaunchActivity) getParentActivity()).hideVisibleActionMode();
}
chatActivityEnterView.getEditField().setAllowDrawCursor(false);
} else if (bottomOverlayChat.getVisibility() == View.VISIBLE) {
actionBar.showActionMode(true, bottomMessagesActionContainer, null, new View[] { bottomOverlayChat }, new boolean[] { true }, chatListView, translationY);
} else {
actionBar.showActionMode(true, bottomMessagesActionContainer, null, null, null, chatListView, translationY);
}
closeMenu();
chatLayoutManager.setCanScrollVertically(true);
updatePinnedMessageView(true);
AnimatorSet animatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
for (int a = 0; a < actionModeViews.size(); a++) {
View view = actionModeViews.get(a);
view.setPivotY(ActionBar.getCurrentActionBarHeight() / 2);
AndroidUtilities.clearDrawableAnimation(view);
animators.add(ObjectAnimator.ofFloat(view, View.SCALE_Y, 0.1f, 1.0f));
}
animatorSet.playTogether(animators);
animatorSet.setDuration(250);
animatorSet.start();
addToSelectedMessages(message, listView);
if (chatActivityEnterView != null) {
chatActivityEnterView.preventInput = true;
}
selectedMessagesCountTextView.setNumber(selectedMessagesIds[0].size() + selectedMessagesIds[1].size(), false);
updateVisibleRows();
if (chatActivityEnterView != null) {
chatActivityEnterView.hideBotCommands();
}
}
Aggregations