use of org.telegram.ui.Components.VerticalPositionAutoAnimator in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCreateActivity method createView.
@Override
public View createView(Context context) {
searching = false;
searchWas = false;
allSpans.clear();
selectedContacts.clear();
currentDeletingSpan = null;
doneButtonVisible = chatType == ChatObject.CHAT_TYPE_CHANNEL;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (chatType == ChatObject.CHAT_TYPE_CHANNEL) {
actionBar.setTitle(LocaleController.getString("ChannelAddSubscribers", R.string.ChannelAddSubscribers));
} else {
if (addToGroup) {
if (channelId != 0) {
actionBar.setTitle(LocaleController.getString("ChannelAddSubscribers", R.string.ChannelAddSubscribers));
} else {
actionBar.setTitle(LocaleController.getString("GroupAddMembers", R.string.GroupAddMembers));
}
} else if (isAlwaysShare) {
if (chatAddType == 2) {
actionBar.setTitle(LocaleController.getString("FilterAlwaysShow", R.string.FilterAlwaysShow));
} else if (chatAddType == 1) {
actionBar.setTitle(LocaleController.getString("AlwaysAllow", R.string.AlwaysAllow));
} else {
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
}
} else if (isNeverShare) {
if (chatAddType == 2) {
actionBar.setTitle(LocaleController.getString("FilterNeverShow", R.string.FilterNeverShow));
} else if (chatAddType == 1) {
actionBar.setTitle(LocaleController.getString("NeverAllow", R.string.NeverAllow));
} else {
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
}
} else {
actionBar.setTitle(chatType == ChatObject.CHAT_TYPE_CHAT ? LocaleController.getString("NewGroup", R.string.NewGroup) : LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList));
}
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == done_button) {
onDonePressed(true);
}
}
});
fragmentView = new ViewGroup(context) {
private VerticalPositionAutoAnimator verticalPositionAutoAnimator;
@Override
public void onViewAdded(View child) {
if (child == floatingButton && verticalPositionAutoAnimator == null) {
verticalPositionAutoAnimator = VerticalPositionAutoAnimator.attach(child);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (verticalPositionAutoAnimator != null) {
verticalPositionAutoAnimator.ignoreNextLayout();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
if (AndroidUtilities.isTablet() || height > width) {
maxSize = AndroidUtilities.dp(144);
} else {
maxSize = AndroidUtilities.dp(56);
}
scrollView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
listView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
emptyView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight(), MeasureSpec.EXACTLY));
if (floatingButton != null) {
int w = AndroidUtilities.dp(Build.VERSION.SDK_INT >= 21 ? 56 : 60);
floatingButton.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY));
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
scrollView.layout(0, 0, scrollView.getMeasuredWidth(), scrollView.getMeasuredHeight());
listView.layout(0, scrollView.getMeasuredHeight(), listView.getMeasuredWidth(), scrollView.getMeasuredHeight() + listView.getMeasuredHeight());
emptyView.layout(0, scrollView.getMeasuredHeight(), emptyView.getMeasuredWidth(), scrollView.getMeasuredHeight() + emptyView.getMeasuredHeight());
if (floatingButton != null) {
int l = LocaleController.isRTL ? AndroidUtilities.dp(14) : (right - left) - AndroidUtilities.dp(14) - floatingButton.getMeasuredWidth();
int t = bottom - top - AndroidUtilities.dp(14) - floatingButton.getMeasuredHeight();
floatingButton.layout(l, t, l + floatingButton.getMeasuredWidth(), t + floatingButton.getMeasuredHeight());
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
parentLayout.drawHeaderShadow(canvas, Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight));
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
if (child == listView) {
canvas.save();
canvas.clipRect(child.getLeft(), Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight), child.getRight(), child.getBottom());
boolean result = super.drawChild(canvas, child, drawingTime);
canvas.restore();
return result;
} else if (child == scrollView) {
canvas.save();
canvas.clipRect(child.getLeft(), child.getTop(), child.getRight(), Math.min(maxSize, measuredContainerHeight + containerHeight - measuredContainerHeight));
boolean result = super.drawChild(canvas, child, drawingTime);
canvas.restore();
return result;
} else {
return super.drawChild(canvas, child, drawingTime);
}
}
};
ViewGroup frameLayout = (ViewGroup) fragmentView;
frameLayout.setFocusableInTouchMode(true);
frameLayout.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
scrollView = new ScrollView(context) {
@Override
public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
if (ignoreScrollEvent) {
ignoreScrollEvent = false;
return false;
}
rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
rectangle.top += fieldY + AndroidUtilities.dp(20);
rectangle.bottom += fieldY + AndroidUtilities.dp(50);
return super.requestChildRectangleOnScreen(child, rectangle, immediate);
}
};
scrollView.setClipChildren(false);
frameLayout.setClipChildren(false);
scrollView.setVerticalScrollBarEnabled(false);
AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_windowBackgroundWhite));
frameLayout.addView(scrollView);
spansContainer = new SpansContainer(context);
scrollView.addView(spansContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
spansContainer.setOnClickListener(v -> {
editText.clearFocus();
editText.requestFocus();
AndroidUtilities.showKeyboard(editText);
});
editText = new EditTextBoldCursor(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (currentDeletingSpan != null) {
currentDeletingSpan.cancelDeleteAnimation();
currentDeletingSpan = null;
}
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!AndroidUtilities.showKeyboard(this)) {
clearFocus();
requestFocus();
}
}
return super.onTouchEvent(event);
}
};
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
editText.setHintColor(Theme.getColor(Theme.key_groupcreate_hintText));
editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
editText.setCursorColor(Theme.getColor(Theme.key_groupcreate_cursor));
editText.setCursorWidth(1.5f);
editText.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
editText.setSingleLine(true);
editText.setBackgroundDrawable(null);
editText.setVerticalScrollBarEnabled(false);
editText.setHorizontalScrollBarEnabled(false);
editText.setTextIsSelectable(false);
editText.setPadding(0, 0, 0, 0);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
editText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
spansContainer.addView(editText);
updateEditTextHint();
editText.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;
}
});
editText.setOnEditorActionListener((v, actionId, event) -> actionId == EditorInfo.IME_ACTION_DONE && onDonePressed(true));
editText.setOnKeyListener(new View.OnKeyListener() {
private boolean wasEmpty;
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DEL) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
wasEmpty = editText.length() == 0;
} else if (event.getAction() == KeyEvent.ACTION_UP && wasEmpty && !allSpans.isEmpty()) {
spansContainer.removeSpan(allSpans.get(allSpans.size() - 1));
updateHint();
checkVisibleRows();
return true;
}
}
return false;
}
});
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
}
@Override
public void afterTextChanged(Editable editable) {
if (editText.length() != 0) {
if (!adapter.searching) {
searching = true;
searchWas = true;
adapter.setSearching(true);
itemDecoration.setSearching(true);
listView.setFastScrollVisible(false);
listView.setVerticalScrollBarEnabled(true);
}
adapter.searchDialogs(editText.getText().toString());
emptyView.showProgress(true, false);
} else {
closeSearch();
}
}
});
FlickerLoadingView flickerLoadingView = new FlickerLoadingView(context);
flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
flickerLoadingView.showDate(false);
emptyView = new StickerEmptyView(context, flickerLoadingView, StickerEmptyView.STICKER_TYPE_SEARCH);
emptyView.addView(flickerLoadingView);
emptyView.showProgress(true, false);
emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
frameLayout.addView(emptyView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
listView = new RecyclerListView(context);
listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
listView.setEmptyView(emptyView);
listView.setAdapter(adapter = new GroupCreateAdapter(context));
listView.setLayoutManager(linearLayoutManager);
listView.setVerticalScrollBarEnabled(false);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
listView.addItemDecoration(itemDecoration = new GroupCreateDividerItemDecoration());
frameLayout.addView(listView);
listView.setOnItemClickListener((view, position) -> {
if (position == 0 && adapter.inviteViaLink != 0 && !adapter.searching) {
sharedLinkBottomSheet = new PermanentLinkBottomSheet(context, false, this, info, chatId, channelId != 0);
showDialog(sharedLinkBottomSheet);
} else if (view instanceof GroupCreateUserCell) {
GroupCreateUserCell cell = (GroupCreateUserCell) view;
Object object = cell.getObject();
long id;
if (object instanceof TLRPC.User) {
id = ((TLRPC.User) object).id;
} else if (object instanceof TLRPC.Chat) {
id = -((TLRPC.Chat) object).id;
} else {
return;
}
if (ignoreUsers != null && ignoreUsers.indexOfKey(id) >= 0) {
return;
}
boolean exists;
if (exists = selectedContacts.indexOfKey(id) >= 0) {
GroupCreateSpan span = selectedContacts.get(id);
spansContainer.removeSpan(span);
} else {
if (maxCount != 0 && selectedContacts.size() == maxCount) {
return;
}
if (chatType == ChatObject.CHAT_TYPE_CHAT && selectedContacts.size() == getMessagesController().maxGroupCount) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("SoftUserLimitAlert", R.string.SoftUserLimitAlert));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showDialog(builder.create());
return;
}
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
if (addToGroup && user.bot) {
if (channelId == 0 && user.bot_nochats) {
try {
BulletinFactory.of(this).createErrorBulletin(LocaleController.getString("BotCantJoinGroups", R.string.BotCantJoinGroups)).show();
} catch (Exception e) {
FileLog.e(e);
}
return;
}
if (channelId != 0) {
TLRPC.Chat chat = getMessagesController().getChat(channelId);
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
if (ChatObject.canAddAdmins(chat)) {
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(LocaleController.getString("AddBotAsAdmin", R.string.AddBotAsAdmin));
builder.setPositiveButton(LocaleController.getString("MakeAdmin", R.string.MakeAdmin), (dialogInterface, i) -> {
delegate2.needAddBot(user);
if (editText.length() > 0) {
editText.setText(null);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
} else {
builder.setMessage(LocaleController.getString("CantAddBotAsAdmin", R.string.CantAddBotAsAdmin));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
}
showDialog(builder.create());
return;
}
}
getMessagesController().putUser(user, !searching);
} else {
TLRPC.Chat chat = (TLRPC.Chat) object;
getMessagesController().putChat(chat, !searching);
}
GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), object);
spansContainer.addSpan(span);
span.setOnClickListener(GroupCreateActivity.this);
}
updateHint();
if (searching || searchWas) {
AndroidUtilities.showKeyboard(editText);
} else {
cell.setChecked(!exists, true);
}
if (editText.length() > 0) {
editText.setText(null);
}
}
});
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
editText.hideActionMode();
AndroidUtilities.hideKeyboard(editText);
}
}
});
listView.setAnimateEmptyView(true, 0);
floatingButton = new ImageView(context);
floatingButton.setScaleType(ImageView.ScaleType.CENTER);
Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
if (Build.VERSION.SDK_INT < 21) {
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
drawable = combinedDrawable;
}
floatingButton.setBackgroundDrawable(drawable);
floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
if (isNeverShare || isAlwaysShare || addToGroup) {
floatingButton.setImageResource(R.drawable.floating_check);
} else {
BackDrawable backDrawable = new BackDrawable(false);
backDrawable.setArrowRotation(180);
floatingButton.setImageDrawable(backDrawable);
}
if (Build.VERSION.SDK_INT >= 21) {
StateListAnimator animator = new StateListAnimator();
animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, "translationZ", AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
floatingButton.setStateListAnimator(animator);
floatingButton.setOutlineProvider(new ViewOutlineProvider() {
@SuppressLint("NewApi")
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
}
});
}
frameLayout.addView(floatingButton);
floatingButton.setOnClickListener(v -> onDonePressed(true));
if (chatType != ChatObject.CHAT_TYPE_CHANNEL) {
floatingButton.setVisibility(View.INVISIBLE);
floatingButton.setScaleX(0.0f);
floatingButton.setScaleY(0.0f);
floatingButton.setAlpha(0.0f);
}
floatingButton.setContentDescription(LocaleController.getString("Next", R.string.Next));
updateHint();
return fragmentView;
}
Aggregations