Search in sources :

Example 1 with MentionCell

use of org.telegram.ui.Cells.MentionCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class MentionsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    int type = holder.getItemViewType();
    if (type == 4) {
        StickerCell stickerCell = (StickerCell) holder.itemView;
        StickerResult result = stickers.get(position);
        stickerCell.setSticker(result.sticker, result.parent);
        stickerCell.setClearsInputField(true);
    } else if (type == 3) {
        TextView textView = (TextView) holder.itemView;
        TLRPC.Chat chat = parentFragment.getCurrentChat();
        if (chat != null) {
            if (!ChatObject.hasAdminRights(chat) && chat.default_banned_rights != null && chat.default_banned_rights.send_inline) {
                textView.setText(LocaleController.getString("GlobalAttachInlineRestricted", R.string.GlobalAttachInlineRestricted));
            } else if (AndroidUtilities.isBannedForever(chat.banned_rights)) {
                textView.setText(LocaleController.getString("AttachInlineRestrictedForever", R.string.AttachInlineRestrictedForever));
            } else {
                textView.setText(LocaleController.formatString("AttachInlineRestricted", R.string.AttachInlineRestricted, LocaleController.formatDateForBan(chat.banned_rights.until_date)));
            }
        }
    } else if (searchResultBotContext != null) {
        boolean hasTop = searchResultBotContextSwitch != null;
        if (holder.getItemViewType() == 2) {
            if (hasTop) {
                ((BotSwitchCell) holder.itemView).setText(searchResultBotContextSwitch.text);
            }
        } else {
            if (hasTop) {
                position--;
            }
            ((ContextLinkCell) holder.itemView).setLink(searchResultBotContext.get(position), foundContextBot, contextMedia, position != searchResultBotContext.size() - 1, hasTop && position == 0, "gif".equals(searchingContextUsername));
        }
    } else {
        if (searchResultUsernames != null) {
            TLObject object = searchResultUsernames.get(position);
            if (object instanceof TLRPC.User) {
                ((MentionCell) holder.itemView).setUser((TLRPC.User) object);
            } else if (object instanceof TLRPC.Chat) {
                ((MentionCell) holder.itemView).setChat((TLRPC.Chat) object);
            }
        } else if (searchResultHashtags != null) {
            ((MentionCell) holder.itemView).setText(searchResultHashtags.get(position));
        } else if (searchResultSuggestions != null) {
            ((MentionCell) holder.itemView).setEmojiSuggestion(searchResultSuggestions.get(position));
        } else if (searchResultCommands != null) {
            ((MentionCell) holder.itemView).setBotCommand(searchResultCommands.get(position), searchResultCommandsHelp.get(position), searchResultCommandsUsers != null ? searchResultCommandsUsers.get(position) : null);
        }
    }
}
Also used : ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) TLRPC(org.telegram.tgnet.TLRPC) StickerCell(org.telegram.ui.Cells.StickerCell) MentionCell(org.telegram.ui.Cells.MentionCell) TLObject(org.telegram.tgnet.TLObject) TextView(android.widget.TextView) BotSwitchCell(org.telegram.ui.Cells.BotSwitchCell)

Example 2 with MentionCell

use of org.telegram.ui.Cells.MentionCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class MentionsAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view;
    switch(viewType) {
        case 0:
            view = new MentionCell(mContext);
            ((MentionCell) view).setIsDarkTheme(isDarkTheme);
            break;
        case 1:
            view = new ContextLinkCell(mContext);
            ((ContextLinkCell) view).setDelegate(cell -> delegate.onContextClick(cell.getResult()));
            break;
        case 2:
            view = new BotSwitchCell(mContext);
            break;
        case 3:
            TextView textView = new TextView(mContext);
            textView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            textView.setTextColor(getThemedColor(Theme.key_windowBackgroundWhiteGrayText2));
            view = textView;
            break;
        case 4:
        default:
            view = new StickerCell(mContext);
            break;
    }
    return new RecyclerListView.Holder(view);
}
Also used : StickerCell(org.telegram.ui.Cells.StickerCell) MentionCell(org.telegram.ui.Cells.MentionCell) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) TextView(android.widget.TextView) BotSwitchCell(org.telegram.ui.Cells.BotSwitchCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) EmojiView(org.telegram.ui.Components.EmojiView) RecyclerListView(org.telegram.ui.Components.RecyclerListView)

Aggregations

TextView (android.widget.TextView)2 BotSwitchCell (org.telegram.ui.Cells.BotSwitchCell)2 ContextLinkCell (org.telegram.ui.Cells.ContextLinkCell)2 MentionCell (org.telegram.ui.Cells.MentionCell)2 StickerCell (org.telegram.ui.Cells.StickerCell)2 View (android.view.View)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 TLObject (org.telegram.tgnet.TLObject)1 TLRPC (org.telegram.tgnet.TLRPC)1 EmojiView (org.telegram.ui.Components.EmojiView)1 RecyclerListView (org.telegram.ui.Components.RecyclerListView)1