use of org.telegram.ui.Cells.GraySectionCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ContactsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder) {
switch(holder.getItemViewType()) {
case 0:
UserCell userCell = (UserCell) holder.itemView;
userCell.setAvatarPadding(sortType == 2 || disableSections ? 6 : 58);
ArrayList<TLRPC.TL_contact> arr;
if (sortType == 2) {
arr = onlineContacts;
} else {
HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).usersMutualSectionsDict : ContactsController.getInstance(currentAccount).usersSectionsDict;
ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance(currentAccount).sortedUsersMutualSectionsArray : ContactsController.getInstance(currentAccount).sortedUsersSectionsArray;
arr = usersSectionsDict.get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1)));
}
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(arr.get(position).user_id);
userCell.setData(user, null, null, 0);
if (checkedMap != null) {
userCell.setChecked(checkedMap.indexOfKey(user.id) >= 0, !scrolling);
}
if (ignoreUsers != null) {
if (ignoreUsers.indexOfKey(user.id) >= 0) {
userCell.setAlpha(0.5f);
} else {
userCell.setAlpha(1.0f);
}
}
break;
case 1:
TextCell textCell = (TextCell) holder.itemView;
if (section == 0) {
if (needPhonebook) {
if (position == 0) {
textCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite, false);
} else if (position == 1) {
textCell.setTextAndIcon(LocaleController.getString("AddPeopleNearby", R.string.AddPeopleNearby), R.drawable.menu_location, false);
}
} else if (isAdmin) {
if (isChannel) {
textCell.setTextAndIcon(LocaleController.getString("ChannelInviteViaLink", R.string.ChannelInviteViaLink), R.drawable.profile_link, false);
} else {
textCell.setTextAndIcon(LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink), R.drawable.profile_link, false);
}
} else {
if (position == 0) {
textCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_groups, false);
} else if (position == 1) {
textCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret, false);
} else if (position == 2) {
textCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel), R.drawable.menu_broadcast, false);
}
}
} else {
ContactsController.Contact contact = ContactsController.getInstance(currentAccount).phoneBookContacts.get(position);
if (contact.first_name != null && contact.last_name != null) {
textCell.setText(contact.first_name + " " + contact.last_name, false);
} else if (contact.first_name != null && contact.last_name == null) {
textCell.setText(contact.first_name, false);
} else {
textCell.setText(contact.last_name, false);
}
}
break;
case 2:
GraySectionCell sectionCell = (GraySectionCell) holder.itemView;
if (sortType == 0) {
sectionCell.setText(LocaleController.getString("Contacts", R.string.Contacts));
} else if (sortType == 1) {
sectionCell.setText(LocaleController.getString("SortedByName", R.string.SortedByName));
} else {
sectionCell.setText(LocaleController.getString("SortedByLastSeen", R.string.SortedByLastSeen));
}
break;
}
}
use of org.telegram.ui.Cells.GraySectionCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ContactsAdapter method onCreateViewHolder.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch(viewType) {
case 0:
view = new UserCell(mContext, 58, 1, false);
break;
case 1:
view = new TextCell(mContext);
break;
case 2:
view = new GraySectionCell(mContext);
break;
case 3:
view = new DividerCell(mContext);
view.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72), AndroidUtilities.dp(8), AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28), AndroidUtilities.dp(8));
break;
case 4:
FrameLayout frameLayout = new FrameLayout(mContext) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height;
height = MeasureSpec.getSize(heightMeasureSpec);
if (height == 0) {
height = parent.getMeasuredHeight();
}
if (height == 0) {
height = AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight() - (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
}
int cellHeight = AndroidUtilities.dp(50);
int totalHeight = onlyUsers != 0 ? 0 : cellHeight + AndroidUtilities.dp(30);
if (hasGps) {
totalHeight += cellHeight;
}
if (!isAdmin && !needPhonebook) {
totalHeight += cellHeight;
}
if (totalHeight < height) {
height = height - totalHeight;
} else {
height = 0;
}
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
};
ContactsEmptyView emptyView = new ContactsEmptyView(mContext);
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
view = frameLayout;
break;
case 5:
default:
view = new ShadowSectionCell(mContext);
Drawable drawable = Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow);
CombinedDrawable combinedDrawable = new CombinedDrawable(new ColorDrawable(Theme.getColor(Theme.key_windowBackgroundGray)), drawable);
combinedDrawable.setFullsize(true);
view.setBackgroundDrawable(combinedDrawable);
break;
}
return new RecyclerListView.Holder(view);
}
use of org.telegram.ui.Cells.GraySectionCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class SearchAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
switch(holder.getItemViewType()) {
case 0:
{
TLObject object = (TLObject) getItem(position);
if (object != null) {
long id = 0;
String un = null;
boolean self = false;
if (object instanceof TLRPC.User) {
un = ((TLRPC.User) object).username;
id = ((TLRPC.User) object).id;
self = ((TLRPC.User) object).self;
} else if (object instanceof TLRPC.Chat) {
un = ((TLRPC.Chat) object).username;
id = ((TLRPC.Chat) object).id;
}
CharSequence username = null;
CharSequence name = null;
if (position < searchResult.size()) {
name = searchResultNames.get(position);
if (name != null && un != null && un.length() > 0) {
if (name.toString().startsWith("@" + un)) {
username = name;
name = null;
}
}
} else if (position > searchResult.size() && un != null) {
String foundUserName = searchAdapterHelper.getLastFoundUsername();
if (foundUserName != null && foundUserName.startsWith("@")) {
foundUserName = foundUserName.substring(1);
}
try {
int index;
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
spannableStringBuilder.append("@");
spannableStringBuilder.append(un);
if (foundUserName != null && (index = AndroidUtilities.indexOfIgnoreCase(un, foundUserName)) != -1) {
int len = foundUserName.length();
if (index == 0) {
len++;
} else {
index++;
}
spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
username = spannableStringBuilder;
} catch (Exception e) {
username = un;
FileLog.e(e);
}
}
if (useUserCell) {
UserCell userCell = (UserCell) holder.itemView;
userCell.setData(object, name, username, 0);
if (checkedMap != null) {
userCell.setChecked(checkedMap.indexOfKey(id) >= 0, false);
}
} else {
ProfileSearchCell profileSearchCell = (ProfileSearchCell) holder.itemView;
if (self) {
name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
}
profileSearchCell.setData(object, null, name, username, false, self);
profileSearchCell.useSeparator = (position != getItemCount() - 1 && position != searchResult.size() - 1);
/*if (ignoreUsers != null) {
if (ignoreUsers.containsKey(id)) {
profileSearchCell.drawAlpha = 0.5f;
} else {
profileSearchCell.drawAlpha = 1.0f;
}
}*/
}
}
break;
}
case 1:
{
GraySectionCell cell = (GraySectionCell) holder.itemView;
if (getItem(position) == null) {
cell.setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch));
} else {
cell.setText(LocaleController.getString("PhoneNumberSearch", R.string.PhoneNumberSearch));
}
break;
}
case 2:
{
String str = (String) getItem(position);
TextCell cell = (TextCell) holder.itemView;
cell.setColors(null, Theme.key_windowBackgroundWhiteBlueText2);
cell.setText(LocaleController.formatString("AddContactByPhone", R.string.AddContactByPhone, PhoneFormat.getInstance().format("+" + str)), false);
break;
}
}
}
use of org.telegram.ui.Cells.GraySectionCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsSearchAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
switch(holder.getItemViewType()) {
case 0:
{
ProfileSearchCell cell = (ProfileSearchCell) holder.itemView;
long oldDialogId = cell.getDialogId();
TLRPC.User user = null;
TLRPC.Chat chat = null;
TLRPC.EncryptedChat encryptedChat = null;
CharSequence username = null;
CharSequence name = null;
boolean isRecent = false;
String un = null;
Object obj = getItem(position);
if (obj instanceof TLRPC.User) {
user = (TLRPC.User) obj;
un = user.username;
} else if (obj instanceof TLRPC.Chat) {
chat = MessagesController.getInstance(currentAccount).getChat(((TLRPC.Chat) obj).id);
if (chat == null) {
chat = (TLRPC.Chat) obj;
}
un = chat.username;
} else if (obj instanceof TLRPC.EncryptedChat) {
encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(((TLRPC.EncryptedChat) obj).id);
user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
}
if (isRecentSearchDisplayed()) {
isRecent = true;
cell.useSeparator = position != getItemCount() - 1;
} else {
ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
ArrayList<Object> phoneSearch = searchAdapterHelper.getPhoneSearch();
int localCount = searchResult.size();
int localServerCount = searchAdapterHelper.getLocalServerSearch().size();
int phoneCount = phoneSearch.size();
if (phoneCount > 3 && phoneCollapsed) {
phoneCount = 3;
}
int phoneCount2 = phoneCount;
if (phoneCount > 0 && phoneSearch.get(phoneCount - 1) instanceof String) {
phoneCount2 -= 2;
}
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
if (globalCount > 4 && globalSearchCollapsed) {
globalCount = 4;
}
cell.useSeparator = (position != getItemCount() - 1 && position != localCount + phoneCount2 + localServerCount - 1 && position != localCount + globalCount + phoneCount + localServerCount - 1);
if (position < searchResult.size()) {
name = searchResultNames.get(position);
if (name != null && user != null && user.username != null && user.username.length() > 0) {
if (name.toString().startsWith("@" + user.username)) {
username = name;
name = null;
}
}
} else {
String foundUserName = searchAdapterHelper.getLastFoundUsername();
if (!TextUtils.isEmpty(foundUserName)) {
String nameSearch = null;
int index;
if (user != null) {
nameSearch = ContactsController.formatName(user.first_name, user.last_name);
} else if (chat != null) {
nameSearch = chat.title;
}
if (nameSearch != null && (index = AndroidUtilities.indexOfIgnoreCase(nameSearch, foundUserName)) != -1) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(nameSearch);
spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + foundUserName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
name = spannableStringBuilder;
} else if (un != null) {
if (foundUserName.startsWith("@")) {
foundUserName = foundUserName.substring(1);
}
try {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
spannableStringBuilder.append("@");
spannableStringBuilder.append(un);
if ((index = AndroidUtilities.indexOfIgnoreCase(un, foundUserName)) != -1) {
int len = foundUserName.length();
if (index == 0) {
len++;
} else {
index++;
}
spannableStringBuilder.setSpan(new ForegroundColorSpanThemable(Theme.key_windowBackgroundWhiteBlueText4), index, index + len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
username = spannableStringBuilder;
} catch (Exception e) {
username = un;
FileLog.e(e);
}
}
}
}
cell.setChecked(false, false);
}
boolean savedMessages = false;
if (user != null && user.id == selfUserId) {
name = LocaleController.getString("SavedMessages", R.string.SavedMessages);
username = null;
savedMessages = true;
}
if (chat != null && chat.participants_count != 0) {
String membersString;
if (ChatObject.isChannel(chat) && !chat.megagroup) {
membersString = LocaleController.formatPluralString("Subscribers", chat.participants_count);
} else {
membersString = LocaleController.formatPluralString("Members", chat.participants_count);
}
if (username instanceof SpannableStringBuilder) {
((SpannableStringBuilder) username).append(", ").append(membersString);
} else if (!TextUtils.isEmpty(username)) {
username = TextUtils.concat(username, ", ", membersString);
} else {
username = membersString;
}
}
cell.setData(user != null ? user : chat, encryptedChat, name, username, isRecent, savedMessages);
cell.setChecked(delegate.isSelected(cell.getDialogId()), oldDialogId == cell.getDialogId());
break;
}
case 1:
{
GraySectionCell cell = (GraySectionCell) holder.itemView;
if (isRecentSearchDisplayed()) {
int offset = (!MediaDataController.getInstance(currentAccount).hints.isEmpty() ? 1 : 0);
if (position < offset) {
cell.setText(LocaleController.getString("ChatHints", R.string.ChatHints));
} else {
cell.setText(LocaleController.getString("Recent", R.string.Recent), LocaleController.getString("ClearButton", R.string.ClearButton), v -> {
if (delegate != null) {
delegate.needClearList();
}
});
}
} else if (!searchResultHashtags.isEmpty()) {
cell.setText(LocaleController.getString("Hashtags", R.string.Hashtags), LocaleController.getString("ClearButton", R.string.ClearButton), v -> {
if (delegate != null) {
delegate.needClearList();
}
});
} else {
ArrayList<TLObject> globalSearch = searchAdapterHelper.getGlobalSearch();
int localCount = searchResult.size();
int localServerCount = searchAdapterHelper.getLocalServerSearch().size();
int phoneCount = searchAdapterHelper.getPhoneSearch().size();
if (phoneCount > 3 && phoneCollapsed) {
phoneCount = 3;
}
int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1;
if (globalCount > 4 && globalSearchCollapsed) {
globalCount = 4;
}
int messagesCount = searchResultMessages.isEmpty() ? 0 : searchResultMessages.size() + 1;
position -= localCount + localServerCount;
String title;
boolean showMore = false;
Runnable onClick = null;
if (position >= 0 && position < phoneCount) {
title = LocaleController.getString("PhoneNumberSearch", R.string.PhoneNumberSearch);
if (searchAdapterHelper.getPhoneSearch().size() > 3) {
showMore = phoneCollapsed;
onClick = () -> {
phoneCollapsed = !phoneCollapsed;
notifyDataSetChanged();
};
}
} else {
position -= phoneCount;
if (position >= 0 && position < globalCount) {
title = LocaleController.getString("GlobalSearch", R.string.GlobalSearch);
if (searchAdapterHelper.getGlobalSearch().size() > 3) {
showMore = globalSearchCollapsed;
onClick = () -> {
globalSearchCollapsed = !globalSearchCollapsed;
notifyDataSetChanged();
};
}
} else {
title = LocaleController.getString("SearchMessages", R.string.SearchMessages);
}
}
if (onClick == null) {
cell.setText(title);
} else {
final Runnable finalOnClick = onClick;
cell.setText(title, showMore ? LocaleController.getString("ShowMore", R.string.ShowMore) : LocaleController.getString("ShowLess", R.string.ShowLess), e -> finalOnClick.run());
}
}
break;
}
case 2:
{
DialogCell cell = (DialogCell) holder.itemView;
cell.useSeparator = (position != getItemCount() - 1);
MessageObject messageObject = (MessageObject) getItem(position);
cell.setDialog(messageObject.getDialogId(), messageObject, messageObject.messageOwner.date, false);
break;
}
case 4:
{
HashtagSearchCell cell = (HashtagSearchCell) holder.itemView;
cell.setText(searchResultHashtags.get(position - 1));
cell.setNeedDivider(position != searchResultHashtags.size());
break;
}
case 5:
{
RecyclerListView recyclerListView = (RecyclerListView) holder.itemView;
((CategoryAdapterRecycler) recyclerListView.getAdapter()).setIndex(position / 2);
break;
}
case 6:
{
String str = (String) getItem(position);
TextCell cell = (TextCell) holder.itemView;
cell.setColors(null, Theme.key_windowBackgroundWhiteBlueText2);
cell.setText(LocaleController.formatString("AddContactByPhone", R.string.AddContactByPhone, PhoneFormat.getInstance().format("+" + str)), false);
break;
}
}
}
use of org.telegram.ui.Cells.GraySectionCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsSearchAdapter method onCreateViewHolder.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch(viewType) {
case 0:
view = new ProfileSearchCell(mContext);
break;
case 1:
view = new GraySectionCell(mContext);
break;
case 2:
view = new DialogCell(null, mContext, false, true);
break;
case 3:
FlickerLoadingView flickerLoadingView = new FlickerLoadingView(mContext);
flickerLoadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
flickerLoadingView.setIsSingleCell(true);
view = flickerLoadingView;
break;
case 4:
view = new HashtagSearchCell(mContext);
break;
case 5:
RecyclerListView horizontalListView = new RecyclerListView(mContext) {
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
if (getParent() != null && getParent().getParent() != null) {
getParent().getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1) || canScrollHorizontally(1));
}
return super.onInterceptTouchEvent(e);
}
};
horizontalListView.setSelectorRadius(AndroidUtilities.dp(4));
horizontalListView.setSelectorDrawableColor(Theme.getColor(Theme.key_listSelector));
horizontalListView.setTag(9);
horizontalListView.setItemAnimator(null);
horizontalListView.setLayoutAnimation(null);
LinearLayoutManager layoutManager = new LinearLayoutManager(mContext) {
@Override
public boolean supportsPredictiveItemAnimations() {
return false;
}
};
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
horizontalListView.setLayoutManager(layoutManager);
// horizontalListView.setDisallowInterceptTouchEvents(true);
horizontalListView.setAdapter(new CategoryAdapterRecycler(mContext, currentAccount, false));
horizontalListView.setOnItemClickListener((view1, position) -> {
if (delegate != null) {
delegate.didPressedOnSubDialog((Long) view1.getTag());
}
});
horizontalListView.setOnItemLongClickListener((view12, position) -> {
if (delegate != null) {
delegate.needRemoveHint((Long) view12.getTag());
}
return true;
});
view = horizontalListView;
innerListView = horizontalListView;
break;
case 6:
default:
view = new TextCell(mContext, 16, false);
break;
}
if (viewType == 5) {
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, AndroidUtilities.dp(86)));
} else {
view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
}
return new RecyclerListView.Holder(view);
}
Aggregations