use of org.telegram.ui.Cells.InviteUserCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class InviteContactsActivity method createView.
@Override
public View createView(Context context) {
searching = false;
searchWas = false;
allSpans.clear();
selectedContacts.clear();
currentDeletingSpan = null;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("InviteFriends", R.string.InviteFriends));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
fragmentView = new ViewGroup(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
setMeasuredDimension(width, height);
int maxSize;
if (AndroidUtilities.isTablet() || height > width) {
maxSize = AndroidUtilities.dp(144);
} else {
maxSize = AndroidUtilities.dp(56);
}
int h;
infoTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
counterView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY));
if (infoTextView.getVisibility() == VISIBLE) {
h = infoTextView.getMeasuredHeight();
} else {
h = counterView.getMeasuredHeight();
}
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() - h, MeasureSpec.EXACTLY));
emptyView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height - scrollView.getMeasuredHeight() - AndroidUtilities.dp(72), 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() + AndroidUtilities.dp(72), emptyView.getMeasuredWidth(), scrollView.getMeasuredHeight() + emptyView.getMeasuredHeight());
int y = bottom - top - infoTextView.getMeasuredHeight();
infoTextView.layout(0, y, infoTextView.getMeasuredWidth(), y + infoTextView.getMeasuredHeight());
y = bottom - top - counterView.getMeasuredHeight();
counterView.layout(0, y, counterView.getMeasuredWidth(), y + counterView.getMeasuredHeight());
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == listView || child == emptyView) {
parentLayout.drawHeaderShadow(canvas, scrollView.getMeasuredHeight());
}
return result;
}
};
ViewGroup frameLayout = (ViewGroup) fragmentView;
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.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));
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, 18);
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);
editText.setHintText(LocaleController.getString("SearchFriends", R.string.SearchFriends));
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(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return actionId == EditorInfo.IME_ACTION_DONE && onDonePressed();
}
});*/
editText.setOnKeyListener(new View.OnKeyListener() {
private boolean wasEmpty;
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
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) {
searching = true;
searchWas = true;
adapter.setSearching(true);
adapter.searchDialogs(editText.getText().toString());
listView.setFastScrollVisible(false);
listView.setVerticalScrollBarEnabled(true);
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
} else {
closeSearch();
}
}
});
emptyView = new EmptyTextProgressView(context);
if (ContactsController.getInstance(currentAccount).isLoadingContacts()) {
emptyView.showProgress();
} else {
emptyView.showTextView();
}
emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
frameLayout.addView(emptyView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
listView = new RecyclerListView(context);
listView.setEmptyView(emptyView);
listView.setAdapter(adapter = new InviteAdapter(context));
listView.setLayoutManager(linearLayoutManager);
listView.setVerticalScrollBarEnabled(true);
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? View.SCROLLBAR_POSITION_LEFT : View.SCROLLBAR_POSITION_RIGHT);
listView.addItemDecoration(decoration = new GroupCreateDividerItemDecoration());
frameLayout.addView(listView);
listView.setOnItemClickListener((view, position) -> {
if (position == 0 && !searching) {
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String text = ContactsController.getInstance(currentAccount).getInviteText(0);
intent.putExtra(Intent.EXTRA_TEXT, text);
getParentActivity().startActivityForResult(Intent.createChooser(intent, text), 500);
} catch (Exception e) {
FileLog.e(e);
}
return;
}
if (!(view instanceof InviteUserCell)) {
return;
}
InviteUserCell cell = (InviteUserCell) view;
ContactsController.Contact contact = cell.getContact();
if (contact == null) {
return;
}
boolean exists;
if (exists = selectedContacts.containsKey(contact.key)) {
GroupCreateSpan span = selectedContacts.get(contact.key);
spansContainer.removeSpan(span);
} else {
GroupCreateSpan span = new GroupCreateSpan(editText.getContext(), contact);
spansContainer.addSpan(span);
span.setOnClickListener(InviteContactsActivity.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) {
AndroidUtilities.hideKeyboard(editText);
}
}
});
infoTextView = new TextView(context);
infoTextView.setBackgroundColor(Theme.getColor(Theme.key_contacts_inviteBackground));
infoTextView.setTextColor(Theme.getColor(Theme.key_contacts_inviteText));
infoTextView.setGravity(Gravity.CENTER);
infoTextView.setText(LocaleController.getString("InviteFriendsHelp", R.string.InviteFriendsHelp));
infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
infoTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
infoTextView.setPadding(AndroidUtilities.dp(17), AndroidUtilities.dp(9), AndroidUtilities.dp(17), AndroidUtilities.dp(9));
frameLayout.addView(infoTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM));
counterView = new FrameLayout(context);
counterView.setBackgroundColor(Theme.getColor(Theme.key_contacts_inviteBackground));
counterView.setVisibility(View.INVISIBLE);
frameLayout.addView(counterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
counterView.setOnClickListener(v -> {
try {
StringBuilder builder = new StringBuilder();
int num = 0;
for (int a = 0; a < allSpans.size(); a++) {
ContactsController.Contact contact = allSpans.get(a).getContact();
if (builder.length() != 0) {
builder.append(';');
}
builder.append(contact.phones.get(0));
if (a == 0 && allSpans.size() == 1) {
num = contact.imported;
}
}
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + builder.toString()));
intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(num));
getParentActivity().startActivityForResult(intent, 500);
} catch (Exception e) {
FileLog.e(e);
}
finishFragment();
});
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
counterView.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
counterTextView = new TextView(context);
counterTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
counterTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
counterTextView.setTextColor(Theme.getColor(Theme.key_contacts_inviteBackground));
counterTextView.setGravity(Gravity.CENTER);
counterTextView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(10), Theme.getColor(Theme.key_contacts_inviteText)));
counterTextView.setMinWidth(AndroidUtilities.dp(20));
counterTextView.setPadding(AndroidUtilities.dp(6), 0, AndroidUtilities.dp(6), AndroidUtilities.dp(1));
linearLayout.addView(counterTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 20, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTextColor(Theme.getColor(Theme.key_contacts_inviteText));
textView.setGravity(Gravity.CENTER);
textView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
textView.setText(LocaleController.getString("InviteToTelegram", R.string.InviteToTelegram).toUpperCase());
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
linearLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
updateHint();
adapter.notifyDataSetChanged();
return fragmentView;
}
use of org.telegram.ui.Cells.InviteUserCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class InviteContactsActivity method getThemeDescriptions.
@Override
public ArrayList<ThemeDescription> getThemeDescriptions() {
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
ThemeDescription.ThemeDescriptionDelegate cellDelegate = () -> {
if (listView != null) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof InviteUserCell) {
((InviteUserCell) child).update(0);
}
}
}
};
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector));
themeDescriptions.add(new ThemeDescription(scrollView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_windowBackgroundWhite));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_FASTSCROLL, null, null, null, null, Theme.key_fastScrollActive));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_FASTSCROLL, null, null, null, null, Theme.key_fastScrollInactive));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_FASTSCROLL, null, null, null, null, Theme.key_fastScrollText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[] { View.class }, Theme.dividerPaint, null, null, Theme.key_divider));
themeDescriptions.add(new ThemeDescription(emptyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_emptyListPlaceholder));
themeDescriptions.add(new ThemeDescription(emptyView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle));
themeDescriptions.add(new ThemeDescription(editText, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(editText, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_groupcreate_hintText));
themeDescriptions.add(new ThemeDescription(editText, ThemeDescription.FLAG_CURSORCOLOR, null, null, null, null, Theme.key_groupcreate_cursor));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[] { GroupCreateSectionCell.class }, null, null, null, Theme.key_graySection));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[] { GroupCreateSectionCell.class }, new String[] { "drawable" }, null, null, null, Theme.key_groupcreate_sectionShadow));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[] { GroupCreateSectionCell.class }, new String[] { "textView" }, null, null, null, Theme.key_groupcreate_sectionText));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[] { InviteUserCell.class }, new String[] { "textView" }, null, null, null, Theme.key_groupcreate_sectionText));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[] { InviteUserCell.class }, new String[] { "nameTextView" }, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[] { InviteUserCell.class }, new String[] { "checkBox" }, null, null, null, Theme.key_checkbox));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[] { InviteUserCell.class }, new String[] { "checkBox" }, null, null, null, Theme.key_checkboxCheck));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CHECKTAG, new Class[] { InviteUserCell.class }, new String[] { "statusTextView" }, null, null, null, Theme.key_windowBackgroundWhiteBlueText));
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CHECKTAG, new Class[] { InviteUserCell.class }, new String[] { "statusTextView" }, null, null, null, Theme.key_windowBackgroundWhiteGrayText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[] { InviteUserCell.class }, null, Theme.avatarDrawables, null, Theme.key_avatar_text));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundRed));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundOrange));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundViolet));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundGreen));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundCyan));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundBlue));
themeDescriptions.add(new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundPink));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[] { InviteTextCell.class }, new String[] { "textView" }, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[] { InviteTextCell.class }, new String[] { "imageView" }, null, null, null, Theme.key_windowBackgroundWhiteGrayIcon));
themeDescriptions.add(new ThemeDescription(spansContainer, 0, new Class[] { GroupCreateSpan.class }, null, null, null, Theme.key_groupcreate_spanBackground));
themeDescriptions.add(new ThemeDescription(spansContainer, 0, new Class[] { GroupCreateSpan.class }, null, null, null, Theme.key_groupcreate_spanText));
themeDescriptions.add(new ThemeDescription(spansContainer, 0, new Class[] { GroupCreateSpan.class }, null, null, null, Theme.key_groupcreate_spanDelete));
themeDescriptions.add(new ThemeDescription(spansContainer, 0, new Class[] { GroupCreateSpan.class }, null, null, null, Theme.key_avatar_backgroundBlue));
themeDescriptions.add(new ThemeDescription(infoTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_contacts_inviteText));
themeDescriptions.add(new ThemeDescription(infoTextView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_contacts_inviteBackground));
themeDescriptions.add(new ThemeDescription(counterView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_contacts_inviteBackground));
themeDescriptions.add(new ThemeDescription(counterTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_contacts_inviteBackground));
themeDescriptions.add(new ThemeDescription(textView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_contacts_inviteText));
themeDescriptions.add(new ThemeDescription(counterTextView, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_contacts_inviteText));
return themeDescriptions;
}
use of org.telegram.ui.Cells.InviteUserCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class InviteContactsActivity method checkVisibleRows.
private void checkVisibleRows() {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof InviteUserCell) {
InviteUserCell cell = (InviteUserCell) child;
ContactsController.Contact contact = cell.getContact();
if (contact != null) {
cell.setChecked(selectedContacts.containsKey(contact.key), true);
}
}
}
}
Aggregations