use of org.telegram.ui.Components.SlideChooseView in project Telegram-FOSS by Telegram-FOSS-Team.
the class LinkEditActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
if (type == CREATE_TYPE) {
actionBar.setTitle(LocaleController.getString("NewLink", R.string.NewLink));
} else if (type == EDIT_TYPE) {
actionBar.setTitle(LocaleController.getString("EditLink", R.string.EditLink));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
AndroidUtilities.hideKeyboard(usesEditText);
}
}
});
createTextView = new TextView(context);
createTextView.setEllipsize(TextUtils.TruncateAt.END);
createTextView.setGravity(Gravity.CENTER_VERTICAL);
createTextView.setOnClickListener(this::onCreateClicked);
createTextView.setSingleLine();
if (type == CREATE_TYPE) {
createTextView.setText(LocaleController.getString("CreateLinkHeader", R.string.CreateLinkHeader));
} else if (type == EDIT_TYPE) {
createTextView.setText(LocaleController.getString("SaveLinkHeader", R.string.SaveLinkHeader));
}
createTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultTitle));
createTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f);
createTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
createTextView.setPadding(AndroidUtilities.dp(18), AndroidUtilities.dp(8), AndroidUtilities.dp(18), AndroidUtilities.dp(8));
int topSpace = actionBar.getOccupyStatusBar() ? (AndroidUtilities.statusBarHeight / AndroidUtilities.dp(2)) : 0;
actionBar.addView(createTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 0, topSpace, 0, 0));
scrollView = new ScrollView(context);
SizeNotifierFrameLayout contentView = new SizeNotifierFrameLayout(context) {
int oldKeyboardHeight;
@Override
protected AdjustPanLayoutHelper createAdjustPanLayoutHelper() {
AdjustPanLayoutHelper panLayoutHelper = new AdjustPanLayoutHelper(this) {
@Override
protected void onTransitionStart(boolean keyboardVisible, int contentHeight) {
super.onTransitionStart(keyboardVisible, contentHeight);
scrollView.getLayoutParams().height = contentHeight;
}
@Override
protected void onTransitionEnd() {
super.onTransitionEnd();
scrollView.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
scrollView.requestLayout();
}
@Override
protected void onPanTranslationUpdate(float y, float progress, boolean keyboardVisible) {
super.onPanTranslationUpdate(y, progress, keyboardVisible);
setTranslationY(0);
}
@Override
protected boolean heightAnimationEnabled() {
return !finished;
}
};
panLayoutHelper.setCheckHierarchyHeight(true);
return panLayoutHelper;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
adjustPanLayoutHelper.onAttach();
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
adjustPanLayoutHelper.onDetach();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
measureKeyboardHeight();
boolean isNeedScrollToEnd = usesEditText.isCursorVisible() || nameEditText.isCursorVisible();
if (oldKeyboardHeight != keyboardHeight && keyboardHeight > AndroidUtilities.dp(20) && isNeedScrollToEnd) {
scrollToEnd = true;
invalidate();
} else if (scrollView.getScrollY() == 0 && !isNeedScrollToEnd) {
scrollToStart = true;
invalidate();
}
if (keyboardHeight != 0 && keyboardHeight < AndroidUtilities.dp(20)) {
usesEditText.clearFocus();
nameEditText.clearFocus();
}
oldKeyboardHeight = keyboardHeight;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int scrollY = scrollView.getScrollY();
super.onLayout(changed, l, t, r, b);
if (scrollY != scrollView.getScrollY() && !scrollToEnd) {
scrollView.setTranslationY(scrollView.getScrollY() - scrollY);
scrollView.animate().cancel();
scrollView.animate().translationY(0).setDuration(AdjustPanLayoutHelper.keyboardDuration).setInterpolator(AdjustPanLayoutHelper.keyboardInterpolator).start();
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (scrollToEnd) {
scrollToEnd = false;
scrollView.smoothScrollTo(0, Math.max(0, scrollView.getChildAt(0).getMeasuredHeight() - scrollView.getMeasuredHeight()));
} else if (scrollToStart) {
scrollToStart = false;
scrollView.smoothScrollTo(0, 0);
}
}
};
fragmentView = contentView;
LinearLayout linearLayout = new LinearLayout(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int elementsHeight = 0;
int h = MeasureSpec.getSize(heightMeasureSpec);
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
if (child != buttonTextView && child.getVisibility() != View.GONE) {
elementsHeight += child.getMeasuredHeight();
}
}
int topMargin;
int buttonH = AndroidUtilities.dp(48) + AndroidUtilities.dp(24) + AndroidUtilities.dp(16);
if (elementsHeight >= h - buttonH) {
topMargin = AndroidUtilities.dp(24);
} else {
topMargin = AndroidUtilities.dp(24) + (h - buttonH) - elementsHeight;
}
if (((LayoutParams) buttonTextView.getLayoutParams()).topMargin != topMargin) {
int oldMargin = ((LayoutParams) buttonTextView.getLayoutParams()).topMargin;
((LayoutParams) buttonTextView.getLayoutParams()).topMargin = topMargin;
if (!firstLayout) {
buttonTextView.setTranslationY(oldMargin - topMargin);
buttonTextView.animate().translationY(0).setDuration(AdjustPanLayoutHelper.keyboardDuration).setInterpolator(AdjustPanLayoutHelper.keyboardInterpolator).start();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
firstLayout = false;
}
};
LayoutTransition transition = new LayoutTransition();
transition.setDuration(100);
linearLayout.setLayoutTransition(transition);
linearLayout.setOrientation(LinearLayout.VERTICAL);
scrollView.addView(linearLayout);
buttonTextView = new TextView(context);
buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
buttonTextView.setGravity(Gravity.CENTER);
buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
if (type == CREATE_TYPE) {
buttonTextView.setText(LocaleController.getString("CreateLink", R.string.CreateLink));
} else if (type == EDIT_TYPE) {
buttonTextView.setText(LocaleController.getString("SaveLink", R.string.SaveLink));
}
approveCell = new TextCheckCell(context) {
@Override
protected void onDraw(Canvas canvas) {
canvas.save();
canvas.clipRect(0, 0, getWidth(), getHeight());
super.onDraw(canvas);
canvas.restore();
}
};
approveCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundUnchecked));
approveCell.setColors(Theme.key_windowBackgroundCheckText, Theme.key_switchTrackBlue, Theme.key_switchTrackBlueChecked, Theme.key_switchTrackBlueThumb, Theme.key_switchTrackBlueThumbChecked);
approveCell.setDrawCheckRipple(true);
approveCell.setHeight(56);
approveCell.setTag(Theme.key_windowBackgroundUnchecked);
approveCell.setTextAndCheck(LocaleController.getString("ApproveNewMembers", R.string.ApproveNewMembers), false, false);
approveCell.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
approveCell.setOnClickListener(view -> {
TextCheckCell cell = (TextCheckCell) view;
boolean newIsChecked = !cell.isChecked();
cell.setBackgroundColorAnimated(newIsChecked, Theme.getColor(newIsChecked ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked));
cell.setChecked(newIsChecked);
setUsesVisible(!newIsChecked);
firstLayout = true;
});
linearLayout.addView(approveCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 56));
TextInfoPrivacyCell hintCell = new TextInfoPrivacyCell(context);
hintCell.setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
hintCell.setText(LocaleController.getString("ApproveNewMembersDescription", R.string.ApproveNewMembersDescription));
linearLayout.addView(hintCell);
timeHeaderCell = new HeaderCell(context);
timeHeaderCell.setText(LocaleController.getString("LimitByPeriod", R.string.LimitByPeriod));
linearLayout.addView(timeHeaderCell);
timeChooseView = new SlideChooseView(context);
linearLayout.addView(timeChooseView);
timeEditText = new TextView(context);
timeEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
timeEditText.setGravity(Gravity.CENTER_VERTICAL);
timeEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
timeEditText.setHint(LocaleController.getString("TimeLimitHint", R.string.TimeLimitHint));
timeEditText.setOnClickListener(view -> AlertsCreator.createDatePickerDialog(context, -1, (notify, scheduleDate) -> chooseDate(scheduleDate)));
timeChooseView.setCallback(index -> {
if (index < dispalyedDates.size()) {
long date = dispalyedDates.get(index) + getConnectionsManager().getCurrentTime();
timeEditText.setText(LocaleController.formatDateAudio(date, false));
} else {
timeEditText.setText("");
}
});
resetDates();
linearLayout.addView(timeEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
divider = new TextInfoPrivacyCell(context);
divider.setText(LocaleController.getString("TimeLimitHelp", R.string.TimeLimitHelp));
linearLayout.addView(divider);
usesHeaderCell = new HeaderCell(context);
usesHeaderCell.setText(LocaleController.getString("LimitNumberOfUses", R.string.LimitNumberOfUses));
linearLayout.addView(usesHeaderCell);
usesChooseView = new SlideChooseView(context);
usesChooseView.setCallback(index -> {
usesEditText.clearFocus();
ignoreSet = true;
if (index < dispalyedUses.size()) {
usesEditText.setText(dispalyedUses.get(index).toString());
} else {
usesEditText.setText("");
}
ignoreSet = false;
});
resetUses();
linearLayout.addView(usesChooseView);
usesEditText = new EditText(context) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
setCursorVisible(true);
}
return super.onTouchEvent(event);
}
};
usesEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
usesEditText.setGravity(Gravity.CENTER_VERTICAL);
usesEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
usesEditText.setHint(LocaleController.getString("UsesLimitHint", R.string.UsesLimitHint));
usesEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
usesEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
usesEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (ignoreSet) {
return;
}
if (editable.toString().equals("0")) {
usesEditText.setText("");
return;
}
int customUses;
try {
customUses = Integer.parseInt(editable.toString());
} catch (NumberFormatException exception) {
resetUses();
return;
}
if (customUses > 100000) {
resetUses();
} else {
chooseUses(customUses);
}
}
});
linearLayout.addView(usesEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
dividerUses = new TextInfoPrivacyCell(context);
dividerUses.setText(LocaleController.getString("UsesLimitHelp", R.string.UsesLimitHelp));
linearLayout.addView(dividerUses);
nameEditText = new EditText(context) {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
setCursorVisible(true);
}
return super.onTouchEvent(event);
}
};
nameEditText.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) {
SpannableStringBuilder builder = new SpannableStringBuilder(s);
Emoji.replaceEmoji(builder, nameEditText.getPaint().getFontMetricsInt(), (int) nameEditText.getPaint().getTextSize(), false);
int selection = nameEditText.getSelectionStart();
nameEditText.removeTextChangedListener(this);
nameEditText.setText(builder);
if (selection >= 0) {
nameEditText.setSelection(selection);
}
nameEditText.addTextChangedListener(this);
}
});
nameEditText.setCursorVisible(false);
nameEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
nameEditText.setGravity(Gravity.CENTER_VERTICAL);
nameEditText.setHint(LocaleController.getString("LinkNameHint", R.string.LinkNameHint));
nameEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
nameEditText.setLines(1);
nameEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
nameEditText.setSingleLine();
nameEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
nameEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
linearLayout.addView(nameEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
dividerName = new TextInfoPrivacyCell(context);
dividerName.setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
dividerName.setText(LocaleController.getString("LinkNameHelp", R.string.LinkNameHelp));
linearLayout.addView(dividerName);
if (type == EDIT_TYPE) {
revokeLink = new TextSettingsCell(context);
revokeLink.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
revokeLink.setText(LocaleController.getString("RevokeLink", R.string.RevokeLink), false);
revokeLink.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText5));
revokeLink.setOnClickListener(view -> {
AlertDialog.Builder builder2 = new AlertDialog.Builder(getParentActivity());
builder2.setMessage(LocaleController.getString("RevokeAlert", R.string.RevokeAlert));
builder2.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink));
builder2.setPositiveButton(LocaleController.getString("RevokeButton", R.string.RevokeButton), (dialogInterface2, i2) -> {
callback.revokeLink(inviteToEdit);
finishFragment();
});
builder2.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
showDialog(builder2.create());
});
linearLayout.addView(revokeLink);
}
contentView.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
linearLayout.addView(buttonTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM, 16, 15, 16, 16));
timeHeaderCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
timeChooseView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
timeEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
usesHeaderCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
usesChooseView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
usesEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
nameEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
contentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
buttonTextView.setOnClickListener(this::onCreateClicked);
buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
dividerUses.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
divider.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
usesEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
usesEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
timeEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
timeEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
usesEditText.setCursorVisible(false);
setInviteToEdit(inviteToEdit);
contentView.setClipChildren(false);
scrollView.setClipChildren(false);
linearLayout.setClipChildren(false);
return contentView;
}
Aggregations