use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelAdminLogActivity method createView.
@Override
public View createView(Context context) {
if (chatMessageCellsCache.isEmpty()) {
for (int a = 0; a < 8; a++) {
chatMessageCellsCache.add(new ChatMessageCell(context));
}
}
searchWas = false;
hasOwnBackground = true;
Theme.createChatResources(context, false);
actionBar.setAddToContainer(false);
actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
actionBar.setBackButtonDrawable(new BackDrawable(false));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(final int id) {
if (id == -1) {
finishFragment();
}
}
});
avatarContainer = new ChatAvatarContainer(context, null, false);
avatarContainer.setOccupyStatusBar(!AndroidUtilities.isTablet());
actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 56, 0, 40, 0));
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchCollapse() {
searchQuery = "";
avatarContainer.setVisibility(View.VISIBLE);
if (searchWas) {
searchWas = false;
loadMessages(true);
}
/*highlightMessageId = Integer.MAX_VALUE;
updateVisibleRows();
scrollToLastMessage(false);
*/
updateBottomOverlay();
}
@Override
public void onSearchExpand() {
avatarContainer.setVisibility(View.GONE);
updateBottomOverlay();
}
@Override
public void onSearchPressed(EditText editText) {
searchWas = true;
searchQuery = editText.getText().toString();
loadMessages(true);
// updateSearchButtons(0, 0, 0);
}
});
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
avatarContainer.setEnabled(false);
avatarContainer.setTitle(currentChat.title);
avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
avatarContainer.setChatAvatar(currentChat);
fragmentView = new SizeNotifierFrameLayout(context) {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null && messageObject.isRoundVideo() && messageObject.eventId != 0 && messageObject.getDialogId() == -currentChat.id) {
MediaController.getInstance().setTextureView(createTextureView(false), aspectRatioFrameLayout, roundVideoContainer, true);
}
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == actionBar && parentLayout != null) {
parentLayout.drawHeaderShadow(canvas, actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() : 0);
}
return result;
}
@Override
protected boolean isActionBarVisible() {
return actionBar.getVisibility() == VISIBLE;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int allHeight;
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
heightSize -= getPaddingTop();
measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
int actionBarHeight = actionBar.getMeasuredHeight();
if (actionBar.getVisibility() == VISIBLE) {
heightSize -= actionBarHeight;
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child == null || child.getVisibility() == GONE || child == actionBar) {
continue;
}
if (child == chatListView || child == progressView) {
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
int contentHeightSpec = MeasureSpec.makeMeasureSpec(Math.max(AndroidUtilities.dp(10), heightSize - AndroidUtilities.dp(48 + 2)), MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else if (child == emptyViewContainer) {
int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY);
int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
child.measure(contentWidthSpec, contentHeightSpec);
} else {
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
}
}
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
int childLeft;
int childTop;
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = r - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
switch(verticalGravity) {
case Gravity.TOP:
childTop = lp.topMargin + getPaddingTop();
if (child != actionBar && actionBar.getVisibility() == VISIBLE) {
childTop += actionBar.getMeasuredHeight();
}
break;
case Gravity.CENTER_VERTICAL:
childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = (b - t) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
if (child == emptyViewContainer) {
childTop -= AndroidUtilities.dp(24) - (actionBar.getVisibility() == VISIBLE ? actionBar.getMeasuredHeight() / 2 : 0);
} else if (child == actionBar) {
childTop -= getPaddingTop();
} else if (child == backgroundView) {
childTop = 0;
}
child.layout(childLeft, childTop, childLeft + width, childTop + height);
}
updateMessagesVisisblePart();
notifyHeightChanged();
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (AvatarPreviewer.hasVisibleInstance()) {
AvatarPreviewer.getInstance().onTouchEvent(ev);
return true;
}
return super.dispatchTouchEvent(ev);
}
};
contentView = (SizeNotifierFrameLayout) fragmentView;
contentView.setOccupyStatusBar(!AndroidUtilities.isTablet());
contentView.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
emptyViewContainer = new FrameLayout(context);
emptyViewContainer.setVisibility(View.INVISIBLE);
contentView.addView(emptyViewContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
emptyViewContainer.setOnTouchListener((v, event) -> true);
emptyView = new TextView(context);
emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
emptyView.setGravity(Gravity.CENTER);
emptyView.setTextColor(Theme.getColor(Theme.key_chat_serviceText));
emptyView.setBackground(Theme.createServiceDrawable(AndroidUtilities.dp(6), emptyView, contentView));
emptyView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16));
emptyViewContainer.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 16, 0, 16, 0));
chatListView = new RecyclerListView(context) {
@Override
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child instanceof ChatMessageCell) {
ChatMessageCell chatMessageCell = (ChatMessageCell) child;
ImageReceiver imageReceiver = chatMessageCell.getAvatarImage();
if (imageReceiver != null) {
if (chatMessageCell.getMessageObject().deleted) {
imageReceiver.setVisible(false, false);
return result;
}
int top = (int) child.getY();
if (chatMessageCell.drawPinnedBottom()) {
int p;
ViewHolder holder = chatListView.getChildViewHolder(child);
p = holder.getAdapterPosition();
if (p >= 0) {
int nextPosition;
nextPosition = p + 1;
holder = chatListView.findViewHolderForAdapterPosition(nextPosition);
if (holder != null) {
imageReceiver.setVisible(false, false);
return result;
}
}
}
float tx = chatMessageCell.getSlidingOffsetX() + chatMessageCell.getCheckBoxTranslation();
int y = (int) child.getY() + chatMessageCell.getLayoutHeight();
int maxY = chatListView.getMeasuredHeight() - chatListView.getPaddingBottom();
if (y > maxY) {
y = maxY;
}
if (chatMessageCell.drawPinnedTop()) {
int p;
ViewHolder holder = chatListView.getChildViewHolder(child);
p = holder.getAdapterPosition();
if (p >= 0) {
int tries = 0;
while (true) {
if (tries >= 20) {
break;
}
tries++;
int prevPosition;
prevPosition = p - 1;
holder = chatListView.findViewHolderForAdapterPosition(prevPosition);
if (holder != null) {
top = holder.itemView.getTop();
if (holder.itemView instanceof ChatMessageCell) {
chatMessageCell = (ChatMessageCell) holder.itemView;
if (!chatMessageCell.drawPinnedTop()) {
break;
} else {
p = prevPosition;
}
} else {
break;
}
} else {
break;
}
}
}
}
if (y - AndroidUtilities.dp(48) < top) {
y = top + AndroidUtilities.dp(48);
}
if (!chatMessageCell.drawPinnedBottom()) {
int cellBottom = (int) (chatMessageCell.getY() + chatMessageCell.getMeasuredHeight());
if (y > cellBottom) {
y = cellBottom;
}
}
canvas.save();
if (tx != 0) {
canvas.translate(tx, 0);
}
if (chatMessageCell.getCurrentMessagesGroup() != null) {
if (chatMessageCell.getCurrentMessagesGroup().transitionParams.backgroundChangeBounds) {
y -= chatMessageCell.getTranslationY();
}
}
imageReceiver.setImageY(y - AndroidUtilities.dp(44));
if (chatMessageCell.shouldDrawAlphaLayer()) {
imageReceiver.setAlpha(chatMessageCell.getAlpha());
canvas.scale(chatMessageCell.getScaleX(), chatMessageCell.getScaleY(), chatMessageCell.getX() + chatMessageCell.getPivotX(), chatMessageCell.getY() + (chatMessageCell.getHeight() >> 1));
} else {
imageReceiver.setAlpha(1f);
}
imageReceiver.setVisible(true, false);
imageReceiver.draw(canvas);
canvas.restore();
}
}
return result;
}
};
chatListView.setOnItemClickListener((view, position) -> createMenu(view));
chatListView.setTag(1);
chatListView.setVerticalScrollBarEnabled(true);
chatListView.setAdapter(chatAdapter = new ChatActivityAdapter(context));
chatListView.setClipToPadding(false);
chatListView.setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(3));
chatListView.setItemAnimator(chatListItemAnimator = new ChatListItemAnimator(null, chatListView, null) {
int scrollAnimationIndex = -1;
Runnable finishRunnable;
public void onAnimationStart() {
if (scrollAnimationIndex == -1) {
scrollAnimationIndex = getNotificationCenter().setAnimationInProgress(scrollAnimationIndex, null, false);
}
if (finishRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(finishRunnable);
finishRunnable = null;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("admin logs chatItemAnimator disable notifications");
}
}
@Override
protected void onAllAnimationsDone() {
super.onAllAnimationsDone();
if (finishRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(finishRunnable);
}
AndroidUtilities.runOnUIThread(finishRunnable = () -> {
if (scrollAnimationIndex != -1) {
getNotificationCenter().onAnimationFinish(scrollAnimationIndex);
scrollAnimationIndex = -1;
}
if (BuildVars.LOGS_ENABLED) {
FileLog.d("admin logs chatItemAnimator enable notifications");
}
});
}
});
chatListItemAnimator.setReversePositions(true);
chatListView.setLayoutAnimation(null);
chatLayoutManager = new LinearLayoutManager(context) {
@Override
public boolean supportsPredictiveItemAnimations() {
return true;
}
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
LinearSmoothScrollerCustom linearSmoothScroller = new LinearSmoothScrollerCustom(recyclerView.getContext(), LinearSmoothScrollerCustom.POSITION_MIDDLE);
linearSmoothScroller.setTargetPosition(position);
startSmoothScroll(linearSmoothScroller);
}
};
chatLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
chatLayoutManager.setStackFromEnd(true);
chatListView.setLayoutManager(chatLayoutManager);
contentView.addView(chatListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
chatListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
private float totalDy = 0;
private final int scrollValue = AndroidUtilities.dp(100);
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
scrollingFloatingDate = true;
checkTextureViewPosition = true;
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
scrollingFloatingDate = false;
checkTextureViewPosition = false;
hideFloatingDateView(true);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
chatListView.invalidate();
if (dy != 0 && scrollingFloatingDate && !currentFloatingTopIsNotMessage) {
if (floatingDateView.getTag() == null) {
if (floatingDateAnimation != null) {
floatingDateAnimation.cancel();
}
floatingDateView.setTag(1);
floatingDateAnimation = new AnimatorSet();
floatingDateAnimation.setDuration(150);
floatingDateAnimation.playTogether(ObjectAnimator.ofFloat(floatingDateView, "alpha", 1.0f));
floatingDateAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (animation.equals(floatingDateAnimation)) {
floatingDateAnimation = null;
}
}
});
floatingDateAnimation.start();
}
}
checkScrollForLoad(true);
updateMessagesVisisblePart();
}
});
if (scrollToPositionOnRecreate != -1) {
chatLayoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
scrollToPositionOnRecreate = -1;
}
progressView = new FrameLayout(context);
progressView.setVisibility(View.INVISIBLE);
contentView.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
progressView2 = new View(context);
progressView2.setBackground(Theme.createServiceDrawable(AndroidUtilities.dp(18), progressView2, contentView));
progressView.addView(progressView2, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
progressBar = new RadialProgressView(context);
progressBar.setSize(AndroidUtilities.dp(28));
progressBar.setProgressColor(Theme.getColor(Theme.key_chat_serviceText));
progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));
floatingDateView = new ChatActionCell(context);
floatingDateView.setAlpha(0.0f);
floatingDateView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
contentView.addView(floatingDateView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 4, 0, 0));
contentView.addView(actionBar);
bottomOverlayChat = new FrameLayout(context) {
@Override
public void onDraw(Canvas canvas) {
int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
};
bottomOverlayChat.setWillNotDraw(false);
bottomOverlayChat.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(bottomOverlayChat, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
bottomOverlayChat.setOnClickListener(view -> {
if (getParentActivity() == null) {
return;
}
AdminLogFilterAlert adminLogFilterAlert = new AdminLogFilterAlert(getParentActivity(), currentFilter, selectedAdmins, currentChat.megagroup);
adminLogFilterAlert.setCurrentAdmins(admins);
adminLogFilterAlert.setAdminLogFilterAlertDelegate((filter, admins) -> {
currentFilter = filter;
selectedAdmins = admins;
if (currentFilter != null || selectedAdmins != null) {
avatarContainer.setSubtitle(LocaleController.getString("EventLogSelectedEvents", R.string.EventLogSelectedEvents));
} else {
avatarContainer.setSubtitle(LocaleController.getString("EventLogAllEvents", R.string.EventLogAllEvents));
}
loadMessages(true);
});
showDialog(adminLogFilterAlert);
});
bottomOverlayChatText = new TextView(context);
bottomOverlayChatText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
bottomOverlayChatText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
bottomOverlayChatText.setTextColor(Theme.getColor(Theme.key_chat_fieldOverlayText));
bottomOverlayChatText.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS).toUpperCase());
bottomOverlayChat.addView(bottomOverlayChatText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
bottomOverlayImage = new ImageView(context);
bottomOverlayImage.setImageResource(R.drawable.log_info);
bottomOverlayImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_fieldOverlayText), PorterDuff.Mode.MULTIPLY));
bottomOverlayImage.setScaleType(ImageView.ScaleType.CENTER);
bottomOverlayChat.addView(bottomOverlayImage, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 3, 0, 0, 0));
bottomOverlayImage.setContentDescription(LocaleController.getString("BotHelp", R.string.BotHelp));
bottomOverlayImage.setOnClickListener(v -> {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (currentChat.megagroup) {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("EventLogInfoDetail", R.string.EventLogInfoDetail)));
} else {
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("EventLogInfoDetailChannel", R.string.EventLogInfoDetailChannel)));
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setTitle(LocaleController.getString("EventLogInfoTitle", R.string.EventLogInfoTitle));
showDialog(builder.create());
});
searchContainer = new FrameLayout(context) {
@Override
public void onDraw(Canvas canvas) {
int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
};
searchContainer.setWillNotDraw(false);
searchContainer.setVisibility(View.INVISIBLE);
searchContainer.setFocusable(true);
searchContainer.setFocusableInTouchMode(true);
searchContainer.setClickable(true);
searchContainer.setPadding(0, AndroidUtilities.dp(3), 0, 0);
contentView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
/*searchUpButton = new ImageView(context);
searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
searchUpButton.setImageResource(R.drawable.msg_go_up);
searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchUpButton, LayoutHelper.createFrame(48, 48));
searchUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 1);
}
});
searchDownButton = new ImageView(context);
searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
searchDownButton.setImageResource(R.drawable.msg_go_down);
searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP, 48, 0, 0, 0));
searchDownButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MessagesSearchQuery.searchMessagesInChat(null, dialog_id, mergeDialogId, classGuid, 2);
}
});*/
searchCalendarButton = new ImageView(context);
searchCalendarButton.setScaleType(ImageView.ScaleType.CENTER);
searchCalendarButton.setImageResource(R.drawable.msg_calendar);
searchCalendarButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_searchPanelIcons), PorterDuff.Mode.MULTIPLY));
searchContainer.addView(searchCalendarButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP));
searchCalendarButton.setOnClickListener(view -> {
if (getParentActivity() == null) {
return;
}
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
showDialog(AlertsCreator.createCalendarPickerDialog(getParentActivity(), 1375315200000L, param -> loadMessages(true), null).create());
});
searchCountText = new SimpleTextView(context);
searchCountText.setTextColor(Theme.getColor(Theme.key_chat_searchPanelText));
searchCountText.setTextSize(15);
searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
searchContainer.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 108, 0, 0, 0));
chatAdapter.updateRows();
if (loading && messages.isEmpty()) {
AndroidUtilities.updateViewVisibilityAnimated(progressView, true, 0.3f, true);
chatListView.setEmptyView(null);
} else {
AndroidUtilities.updateViewVisibilityAnimated(progressView, false, 0.3f, true);
chatListView.setEmptyView(emptyViewContainer);
}
chatListView.setAnimateEmptyView(true, 1);
undoView = new UndoView(context);
undoView.setAdditionalTranslationY(AndroidUtilities.dp(51));
contentView.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
updateEmptyPlaceholder();
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChangeBioActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("UserBio", R.string.UserBio));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
saveName();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
doneButton.setContentDescription(LocaleController.getString("Done", R.string.Done));
fragmentView = new LinearLayout(context);
LinearLayout linearLayout = (LinearLayout) fragmentView;
linearLayout.setOrientation(LinearLayout.VERTICAL);
fragmentView.setOnTouchListener((v, event) -> true);
FrameLayout fieldContainer = new FrameLayout(context);
linearLayout.addView(fieldContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 20, 0));
firstNameField = new EditTextBoldCursor(context);
firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
firstNameField.setMaxLines(4);
firstNameField.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 24 : 0), 0, AndroidUtilities.dp(LocaleController.isRTL ? 0 : 24), AndroidUtilities.dp(6));
firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
firstNameField.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
firstNameField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
firstNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
InputFilter[] inputFilters = new InputFilter[1];
inputFilters[0] = new CodepointsLengthInputFilter(70) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source != null && source.length() > 0 && TextUtils.indexOf(source, '\n') == source.length() - 1) {
doneButton.performClick();
return "";
}
CharSequence result = super.filter(source, start, end, dest, dstart, dend);
if (result != null && source != null && result.length() != source.length()) {
Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
if (v != null) {
v.vibrate(200);
}
AndroidUtilities.shakeView(checkTextView, 2, 0);
}
return result;
}
};
firstNameField.setFilters(inputFilters);
firstNameField.setMinHeight(AndroidUtilities.dp(36));
firstNameField.setHint(LocaleController.getString("UserBio", R.string.UserBio));
firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
firstNameField.setCursorSize(AndroidUtilities.dp(20));
firstNameField.setCursorWidth(1.5f);
firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
doneButton.performClick();
return true;
}
return false;
});
firstNameField.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) {
checkTextView.setNumber(70 - Character.codePointCount(s, 0, s.length()), true);
}
});
fieldContainer.addView(firstNameField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 4, 0));
checkTextView = new NumberTextView(context);
checkTextView.setCenterAlign(true);
checkTextView.setTextSize(15);
checkTextView.setNumber(70, false);
checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
checkTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
fieldContainer.addView(checkTextView, LayoutHelper.createFrame(20, 20, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT, 0, 4, 4, 0));
helpTextView = new TextView(context);
helpTextView.setFocusable(true);
helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
helpTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
helpTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("UserBioInfo", R.string.UserBioInfo)));
linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 0));
TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(UserConfig.getInstance(currentAccount).getClientUserId());
if (userFull != null && userFull.about != null) {
firstNameField.setText(userFull.about);
firstNameField.setSelection(firstNameField.length());
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class TooManyCommunitiesActivity method createView.
@Override
public View createView(Context context) {
type = arguments.getInt("type", TYPE_JOIN);
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("LimitReached", R.string.LimitReached));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
ActionBarMenuItem searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
boolean expanded = false;
@Override
public void onSearchCollapse() {
super.onSearchCollapse();
if (listView.getVisibility() != View.VISIBLE) {
listView.setVisibility(View.VISIBLE);
listView.setAlpha(0);
}
emptyView.setVisibility(View.GONE);
adapter.notifyDataSetChanged();
listView.animate().alpha(1f).setDuration(150).setListener(null).start();
searchViewContainer.animate().alpha(0f).setDuration(150).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
searchViewContainer.setVisibility(View.GONE);
}
}).start();
expanded = false;
}
@Override
public void onTextChanged(EditText editText) {
String query = editText.getText().toString();
searchAdapter.search(query);
if (!expanded && !TextUtils.isEmpty(query)) {
if (searchViewContainer.getVisibility() != View.VISIBLE) {
searchViewContainer.setVisibility(View.VISIBLE);
searchViewContainer.setAlpha(0);
}
listView.animate().alpha(0).setDuration(150).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
listView.setVisibility(View.GONE);
}
}).start();
searchAdapter.searchResultsSignatures.clear();
searchAdapter.searchResults.clear();
searchAdapter.notifyDataSetChanged();
searchViewContainer.animate().setListener(null).alpha(1f).setDuration(150).start();
expanded = true;
} else if (expanded && TextUtils.isEmpty(query)) {
onSearchCollapse();
}
}
});
searchItem.setContentDescription(LocaleController.getString("Search", R.string.Search));
searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
FrameLayout contentView = new FrameLayout(context);
fragmentView = contentView;
listView = new RecyclerListView(context);
listView.setLayoutManager(new LinearLayoutManager(context));
listView.setAdapter(adapter = new Adapter());
listView.setClipToPadding(false);
listView.setOnItemClickListener(onItemClickListener);
listView.setOnItemLongClickListener(onItemLongClickListener);
searchListView = new RecyclerListView(context);
searchListView.setLayoutManager(new LinearLayoutManager(context));
searchListView.setAdapter(searchAdapter = new SearchAdapter());
searchListView.setOnItemClickListener(onItemClickListener);
searchListView.setOnItemLongClickListener(onItemLongClickListener);
searchListView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
});
emptyView = new EmptyTextProgressView(context);
emptyView.setShowAtCenter(true);
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
emptyView.showTextView();
progressBar = new RadialProgressView(context);
contentView.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
adapter.updateRows();
progressBar.setVisibility(View.GONE);
contentView.addView(listView);
searchViewContainer = new FrameLayout(context);
searchViewContainer.addView(searchListView);
searchViewContainer.addView(emptyView);
searchViewContainer.setVisibility(View.GONE);
contentView.addView(searchViewContainer);
loadInactiveChannels();
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
buttonLayout = new FrameLayout(context) {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0, 0, getMeasuredWidth(), 1, Theme.dividerPaint);
}
};
buttonLayout.setWillNotDraw(false);
buttonTextView = new TextView(context);
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
buttonTextView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
contentView.addView(buttonLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 64, Gravity.BOTTOM));
buttonLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
buttonLayout.addView(buttonTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, 12, 16, 12));
buttonLayout.setVisibility(View.GONE);
buttonTextView.setOnClickListener(v -> {
if (selectedIds.isEmpty()) {
return;
}
TLRPC.User currentUser = getMessagesController().getUser(getUserConfig().getClientUserId());
ArrayList<TLRPC.Chat> chats = new ArrayList<>();
for (int i = 0; i < inactiveChats.size(); i++) {
if (selectedIds.contains(inactiveChats.get(i).id)) {
chats.add(inactiveChats.get(i));
}
}
for (int i = 0; i < chats.size(); i++) {
TLRPC.Chat chat = chats.get(i);
getMessagesController().putChat(chat, false);
getMessagesController().deleteParticipantFromChat(chat.id, currentUser, null);
}
finishFragment();
});
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class TwoStepVerificationActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (otherwiseReloginDays >= 0) {
showSetForcePasswordAlert();
} else {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
ActionBarMenu menu = actionBar.createMenu();
doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
scrollView = new ScrollView(context);
scrollView.setFillViewport(true);
frameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
titleTextView = new TextView(context);
titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
titleTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 38, 0, 0));
passwordEditText = new EditTextBoldCursor(context);
passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
passwordEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
passwordEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
passwordEditText.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
passwordEditText.setMaxLines(1);
passwordEditText.setLines(1);
passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
passwordEditText.setSingleLine(true);
passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
passwordEditText.setTypeface(Typeface.DEFAULT);
passwordEditText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
passwordEditText.setCursorWidth(1.5f);
linearLayout.addView(passwordEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 40, 32, 40, 0));
passwordEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
processDone();
return true;
}
return false;
});
passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
bottomTextView = new TextView(context);
bottomTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
bottomTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
bottomTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
bottomTextView.setText(LocaleController.getString("YourEmailInfo", R.string.YourEmailInfo));
linearLayout.addView(bottomTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 40, 30, 40, 0));
LinearLayout linearLayout2 = new LinearLayout(context);
linearLayout2.setOrientation(LinearLayout.VERTICAL);
linearLayout2.setGravity(Gravity.BOTTOM | Gravity.CENTER_VERTICAL);
linearLayout2.setClipChildren(false);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
bottomButton = new SimpleTextView(context);
bottomButton.setTextSize(14);
bottomButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
bottomButton.setPadding(0, AndroidUtilities.dp(10), 0, 0);
linearLayout2.addView(bottomButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, 40, 0, 40, 14));
bottomButton.setOnClickListener(v -> onPasswordForgot());
cancelResetButton = new TextView(context);
cancelResetButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelResetButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
cancelResetButton.setPadding(0, AndroidUtilities.dp(10), 0, 0);
cancelResetButton.setText(LocaleController.getString("CancelReset", R.string.CancelReset));
cancelResetButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
linearLayout2.addView(cancelResetButton, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, 40, 0, 40, 26));
cancelResetButton.setOnClickListener(v -> cancelPasswordReset());
emptyView = new EmptyTextProgressView(context);
emptyView.showProgress();
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView = new RecyclerListView(context);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setEmptyView(emptyView);
listView.setVerticalScrollBarEnabled(false);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter = new ListAdapter(context));
listView.setOnItemClickListener((view, position) -> {
if (position == setPasswordRow || position == changePasswordRow) {
TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TwoStepVerificationSetupActivity.TYPE_ENTER_FIRST, currentPassword);
fragment.addFragmentToClose(this);
fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, false);
presentFragment(fragment);
} else if (position == setRecoveryEmailRow || position == changeRecoveryEmailRow) {
TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TwoStepVerificationSetupActivity.TYPE_ENTER_EMAIL, currentPassword);
fragment.addFragmentToClose(this);
fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, true);
presentFragment(fragment);
} else if (position == turnPasswordOffRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
String text = LocaleController.getString("TurnPasswordOffQuestion", R.string.TurnPasswordOffQuestion);
if (currentPassword.has_secure_values) {
text += "\n\n" + LocaleController.getString("TurnPasswordOffPassport", R.string.TurnPasswordOffPassport);
}
String title = LocaleController.getString("TurnPasswordOffQuestionTitle", R.string.TurnPasswordOffQuestionTitle);
String buttonText = LocaleController.getString("Disable", R.string.Disable);
builder.setMessage(text);
builder.setTitle(title);
builder.setPositiveButton(buttonText, (dialogInterface, i) -> clearPassword());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
}
});
updateRows();
actionBar.setTitle(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle));
if (delegate != null) {
titleTextView.setText(LocaleController.getString("PleaseEnterCurrentPasswordTransfer", R.string.PleaseEnterCurrentPasswordTransfer));
} else {
titleTextView.setText(LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
}
if (passwordEntered) {
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
fragmentView.setTag(Theme.key_windowBackgroundGray);
} else {
fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
fragmentView.setTag(Theme.key_windowBackgroundWhite);
}
return fragmentView;
}
use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.
the class ProfileActivity method createActionBarMenu.
private void createActionBarMenu(boolean animated) {
if (actionBar == null || otherItem == null) {
return;
}
ActionBarMenu menu = actionBar.createMenu();
otherItem.removeAllSubItems();
animatingItem = null;
editItemVisible = false;
callItemVisible = false;
videoCallItemVisible = false;
canSearchMembers = false;
boolean selfUser = false;
if (userId != 0) {
TLRPC.User user = getMessagesController().getUser(userId);
if (user == null) {
return;
}
if (UserObject.isUserSelf(user)) {
otherItem.addSubItem(edit_name, R.drawable.msg_edit, LocaleController.getString("EditName", R.string.EditName));
selfUser = true;
} else {
if (userInfo != null && userInfo.phone_calls_available) {
callItemVisible = true;
videoCallItemVisible = Build.VERSION.SDK_INT >= 18 && userInfo.video_calls_available;
}
if (isBot || getContactsController().contactsDict.get(userId) == null) {
if (MessagesController.isSupportUser(user)) {
if (userBlocked) {
otherItem.addSubItem(block_contact, R.drawable.msg_block, LocaleController.getString("Unblock", R.string.Unblock));
}
} else {
if (isBot) {
if (!user.bot_nochats) {
otherItem.addSubItem(invite_to_group, R.drawable.msg_addbot, LocaleController.getString("BotInvite", R.string.BotInvite));
}
otherItem.addSubItem(share, R.drawable.msg_share, LocaleController.getString("BotShare", R.string.BotShare));
} else {
otherItem.addSubItem(add_contact, R.drawable.msg_addcontact, LocaleController.getString("AddContact", R.string.AddContact));
}
if (!TextUtils.isEmpty(user.phone)) {
otherItem.addSubItem(share_contact, R.drawable.msg_share, LocaleController.getString("ShareContact", R.string.ShareContact));
}
if (isBot) {
otherItem.addSubItem(block_contact, !userBlocked ? R.drawable.msg_block : R.drawable.msg_retry, !userBlocked ? LocaleController.getString("BotStop", R.string.BotStop) : LocaleController.getString("BotRestart", R.string.BotRestart));
} else {
otherItem.addSubItem(block_contact, !userBlocked ? R.drawable.msg_block : R.drawable.msg_block, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock));
}
}
} else {
if (!TextUtils.isEmpty(user.phone)) {
otherItem.addSubItem(share_contact, R.drawable.msg_share, LocaleController.getString("ShareContact", R.string.ShareContact));
}
otherItem.addSubItem(block_contact, !userBlocked ? R.drawable.msg_block : R.drawable.msg_block, !userBlocked ? LocaleController.getString("BlockContact", R.string.BlockContact) : LocaleController.getString("Unblock", R.string.Unblock));
otherItem.addSubItem(edit_contact, R.drawable.msg_edit, LocaleController.getString("EditContact", R.string.EditContact));
otherItem.addSubItem(delete_contact, R.drawable.msg_delete, LocaleController.getString("DeleteContact", R.string.DeleteContact));
}
if (!UserObject.isDeleted(user) && !isBot && currentEncryptedChat == null && !userBlocked && userId != 333000 && userId != 777000 && userId != 42777) {
otherItem.addSubItem(start_secret_chat, R.drawable.msg_start_secret, LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat));
}
otherItem.addSubItem(add_shortcut, R.drawable.msg_home, LocaleController.getString("AddShortcut", R.string.AddShortcut));
}
} else if (chatId != 0) {
TLRPC.Chat chat = getMessagesController().getChat(chatId);
hasVoiceChatItem = false;
if (ChatObject.isChannel(chat)) {
if (ChatObject.hasAdminRights(chat) || chat.megagroup && ChatObject.canChangeChatInfo(chat)) {
editItemVisible = true;
}
if (chatInfo != null) {
if (ChatObject.canManageCalls(chat) && chatInfo.call == null) {
otherItem.addSubItem(call_item, R.drawable.msg_voicechat, chat.megagroup && !chat.gigagroup ? LocaleController.getString("StartVoipChat", R.string.StartVoipChat) : LocaleController.getString("StartVoipChannel", R.string.StartVoipChannel));
hasVoiceChatItem = true;
}
if (chatInfo.can_view_stats) {
otherItem.addSubItem(statistics, R.drawable.msg_stats, LocaleController.getString("Statistics", R.string.Statistics));
}
ChatObject.Call call = getMessagesController().getGroupCall(chatId, false);
callItemVisible = call != null;
}
if (chat.megagroup) {
canSearchMembers = true;
otherItem.addSubItem(search_members, R.drawable.msg_search, LocaleController.getString("SearchMembers", R.string.SearchMembers));
if (!chat.creator && !chat.left && !chat.kicked) {
otherItem.addSubItem(leave_group, R.drawable.msg_leave, LocaleController.getString("LeaveMegaMenu", R.string.LeaveMegaMenu));
}
} else {
if (!TextUtils.isEmpty(chat.username)) {
otherItem.addSubItem(share, R.drawable.msg_share, LocaleController.getString("BotShare", R.string.BotShare));
}
if (chatInfo != null && chatInfo.linked_chat_id != 0) {
otherItem.addSubItem(view_discussion, R.drawable.msg_discussion, LocaleController.getString("ViewDiscussion", R.string.ViewDiscussion));
}
if (!currentChat.creator && !currentChat.left && !currentChat.kicked) {
otherItem.addSubItem(leave_group, R.drawable.msg_leave, LocaleController.getString("LeaveChannelMenu", R.string.LeaveChannelMenu));
}
}
} else {
if (chatInfo != null) {
if (ChatObject.canManageCalls(chat) && chatInfo.call == null) {
otherItem.addSubItem(call_item, R.drawable.msg_voicechat, LocaleController.getString("StartVoipChat", R.string.StartVoipChat));
hasVoiceChatItem = true;
}
ChatObject.Call call = getMessagesController().getGroupCall(chatId, false);
callItemVisible = call != null;
}
if (ChatObject.canChangeChatInfo(chat)) {
editItemVisible = true;
}
if (!ChatObject.isKickedFromChat(chat) && !ChatObject.isLeftFromChat(chat)) {
canSearchMembers = true;
otherItem.addSubItem(search_members, R.drawable.msg_search, LocaleController.getString("SearchMembers", R.string.SearchMembers));
}
otherItem.addSubItem(leave_group, R.drawable.msg_leave, LocaleController.getString("DeleteAndExit", R.string.DeleteAndExit));
}
otherItem.addSubItem(add_shortcut, R.drawable.msg_home, LocaleController.getString("AddShortcut", R.string.AddShortcut));
}
if (imageUpdater != null) {
otherItem.addSubItem(add_photo, R.drawable.msg_addphoto, LocaleController.getString("AddPhoto", R.string.AddPhoto));
otherItem.addSubItem(set_as_main, R.drawable.menu_private, LocaleController.getString("SetAsMain", R.string.SetAsMain));
otherItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
// otherItem.addSubItem(edit_avatar, R.drawable.photo_paint, LocaleController.getString("EditPhoto", R.string.EditPhoto));
otherItem.addSubItem(delete_avatar, R.drawable.msg_delete, LocaleController.getString("Delete", R.string.Delete));
} else {
otherItem.addSubItem(gallery_menu_save, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
}
if (getMessagesController().isChatNoForwards(currentChat)) {
otherItem.hideSubItem(gallery_menu_save);
}
if (selfUser) {
otherItem.addSubItem(logout, R.drawable.msg_leave, LocaleController.getString("LogOut", R.string.LogOut));
}
if (!isPulledDown) {
otherItem.hideSubItem(gallery_menu_save);
otherItem.hideSubItem(set_as_main);
otherItem.showSubItem(add_photo);
otherItem.hideSubItem(edit_avatar);
otherItem.hideSubItem(delete_avatar);
}
if (!mediaHeaderVisible) {
if (callItemVisible) {
if (callItem.getVisibility() != View.VISIBLE) {
callItem.setVisibility(View.VISIBLE);
if (animated) {
callItem.setAlpha(0);
callItem.animate().alpha(1f).setDuration(150).start();
}
}
} else {
if (callItem.getVisibility() != View.GONE) {
callItem.setVisibility(View.GONE);
}
}
if (videoCallItemVisible) {
if (videoCallItem.getVisibility() != View.VISIBLE) {
videoCallItem.setVisibility(View.VISIBLE);
if (animated) {
videoCallItem.setAlpha(0);
videoCallItem.animate().alpha(1f).setDuration(150).start();
}
}
} else {
if (videoCallItem.getVisibility() != View.GONE) {
videoCallItem.setVisibility(View.GONE);
}
}
if (editItemVisible) {
if (editItem.getVisibility() != View.VISIBLE) {
editItem.setVisibility(View.VISIBLE);
if (animated) {
editItem.setAlpha(0);
editItem.animate().alpha(1f).setDuration(150).start();
}
}
} else {
if (editItem.getVisibility() != View.GONE) {
editItem.setVisibility(View.GONE);
}
}
}
if (avatarsViewPagerIndicatorView != null) {
if (avatarsViewPagerIndicatorView.isIndicatorFullyVisible()) {
if (editItemVisible) {
editItem.setVisibility(View.GONE);
editItem.animate().cancel();
editItem.setAlpha(1f);
}
if (callItemVisible) {
callItem.setVisibility(View.GONE);
callItem.animate().cancel();
callItem.setAlpha(1f);
}
if (videoCallItemVisible) {
videoCallItem.setVisibility(View.GONE);
videoCallItem.animate().cancel();
videoCallItem.setAlpha(1f);
}
}
}
if (sharedMediaLayout != null) {
sharedMediaLayout.getSearchItem().requestLayout();
}
}
Aggregations