Search in sources :

Example 16 with DialogCell

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

the class MessagesSearchAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder.getItemViewType() == 0) {
        DialogCell cell = (DialogCell) holder.itemView;
        cell.useSeparator = true;
        MessageObject messageObject = (MessageObject) getItem(position);
        cell.setDialog(messageObject.getDialogId(), messageObject, messageObject.messageOwner.date, true);
    }
}
Also used : DialogCell(org.telegram.ui.Cells.DialogCell) MessageObject(org.telegram.messenger.MessageObject)

Example 17 with DialogCell

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

the class DialogsAdapter method onViewAttachedToWindow.

@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    if (holder.itemView instanceof DialogCell) {
        DialogCell dialogCell = (DialogCell) holder.itemView;
        dialogCell.onReorderStateChanged(isReordering, false);
        int position = fixPosition(holder.getAdapterPosition());
        dialogCell.setDialogIndex(position);
        dialogCell.checkCurrentDialogIndex(dialogsListFrozen);
        dialogCell.setChecked(selectedDialogs.contains(dialogCell.getDialogId()), false);
    }
}
Also used : DialogCell(org.telegram.ui.Cells.DialogCell)

Example 18 with DialogCell

use of org.telegram.ui.Cells.DialogCell 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;
            }
    }
}
Also used : Context(android.content.Context) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) Spanned(android.text.Spanned) Theme(org.telegram.ui.ActionBar.Theme) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TextCell(org.telegram.ui.Cells.TextCell) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) TLObject(org.telegram.tgnet.TLObject) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) View(android.view.View) MessageObject(org.telegram.messenger.MessageObject) MediaDataController(org.telegram.messenger.MediaDataController) RecyclerView(androidx.recyclerview.widget.RecyclerView) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) Utilities(org.telegram.messenger.Utilities) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) FilteredSearchView(org.telegram.ui.FilteredSearchView) R(org.telegram.messenger.R) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TextUtils(android.text.TextUtils) SQLitePreparedStatement(org.telegram.SQLite.SQLitePreparedStatement) FileLog(org.telegram.messenger.FileLog) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) UserConfig(org.telegram.messenger.UserConfig) UserObject(org.telegram.messenger.UserObject) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SQLiteCursor(org.telegram.SQLite.SQLiteCursor) ChatObject(org.telegram.messenger.ChatObject) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) ArrayList(java.util.ArrayList) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TLRPC(org.telegram.tgnet.TLRPC) TextCell(org.telegram.ui.Cells.TextCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) DialogCell(org.telegram.ui.Cells.DialogCell) ForegroundColorSpanThemable(org.telegram.ui.Components.ForegroundColorSpanThemable) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) TLObject(org.telegram.tgnet.TLObject) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) MessageObject(org.telegram.messenger.MessageObject) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 19 with DialogCell

use of org.telegram.ui.Cells.DialogCell 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);
}
Also used : GraySectionCell(org.telegram.ui.Cells.GraySectionCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) FilteredSearchView(org.telegram.ui.FilteredSearchView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) MotionEvent(android.view.MotionEvent) TextCell(org.telegram.ui.Cells.TextCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) RecyclerView(androidx.recyclerview.widget.RecyclerView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView)

Example 20 with DialogCell

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

the class FilteredSearchView method onItemClick.

private void onItemClick(int index, View view, MessageObject message, int a) {
    if (message == null) {
        return;
    }
    if (uiCallback.actionModeShowing()) {
        uiCallback.toggleItemSelection(message, view, a);
        return;
    }
    if (view instanceof DialogCell) {
        uiCallback.goToMessage(message);
        return;
    }
    if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
        PhotoViewer.getInstance().setParentActivity(parentActivity);
        PhotoViewer.getInstance().openPhoto(messages, index, 0, 0, provider);
        photoViewerClassGuid = PhotoViewer.getInstance().getClassGuid();
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC || currentSearchFilter.filterType == FiltersView.FILTER_TYPE_VOICE) {
        if (view instanceof SharedAudioCell) {
            ((SharedAudioCell) view).didPressedButton();
        }
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
        if (view instanceof SharedDocumentCell) {
            SharedDocumentCell cell = (SharedDocumentCell) view;
            TLRPC.Document document = message.getDocument();
            if (cell.isLoaded()) {
                if (message.canPreviewDocument()) {
                    PhotoViewer.getInstance().setParentActivity(parentActivity);
                    index = messages.indexOf(message);
                    if (index < 0) {
                        ArrayList<MessageObject> documents = new ArrayList<>();
                        documents.add(message);
                        PhotoViewer.getInstance().setParentActivity(parentActivity);
                        PhotoViewer.getInstance().openPhoto(documents, 0, 0, 0, provider);
                        photoViewerClassGuid = PhotoViewer.getInstance().getClassGuid();
                    } else {
                        PhotoViewer.getInstance().setParentActivity(parentActivity);
                        PhotoViewer.getInstance().openPhoto(messages, index, 0, 0, provider);
                        photoViewerClassGuid = PhotoViewer.getInstance().getClassGuid();
                    }
                    return;
                }
                AndroidUtilities.openDocument(message, parentActivity, parentFragment);
            } else if (!cell.isLoading()) {
                MessageObject messageObject = cell.getMessage();
                AccountInstance.getInstance(UserConfig.selectedAccount).getFileLoader().loadFile(document, messageObject, 0, 0);
                cell.updateFileExistIcon(true);
            } else {
                AccountInstance.getInstance(UserConfig.selectedAccount).getFileLoader().cancelLoadFile(document);
                cell.updateFileExistIcon(true);
            }
        }
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
        try {
            TLRPC.WebPage webPage = message.messageOwner.media != null ? message.messageOwner.media.webpage : null;
            String link = null;
            if (webPage != null && !(webPage instanceof TLRPC.TL_webPageEmpty)) {
                if (webPage.cached_page != null) {
                    ArticleViewer.getInstance().setParentActivity(parentActivity, parentFragment);
                    ArticleViewer.getInstance().open(message);
                    return;
                } else if (webPage.embed_url != null && webPage.embed_url.length() != 0) {
                    openWebView(webPage, message);
                    return;
                } else {
                    link = webPage.url;
                }
            }
            if (link == null) {
                link = ((SharedLinkCell) view).getLink(0);
            }
            if (link != null) {
                openUrl(link);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) TLRPC(org.telegram.tgnet.TLRPC) DialogCell(org.telegram.ui.Cells.DialogCell) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) MessageObject(org.telegram.messenger.MessageObject) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell)

Aggregations

DialogCell (org.telegram.ui.Cells.DialogCell)22 View (android.view.View)19 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 RecyclerListView (org.telegram.ui.Components.RecyclerListView)11 TextView (android.widget.TextView)8 FlickerLoadingView (org.telegram.ui.Components.FlickerLoadingView)8 ImageView (android.widget.ImageView)7 ArrayList (java.util.ArrayList)7 TLRPC (org.telegram.tgnet.TLRPC)7 HintDialogCell (org.telegram.ui.Cells.HintDialogCell)7 SuppressLint (android.annotation.SuppressLint)6 Paint (android.graphics.Paint)6 TextPaint (android.text.TextPaint)6 FiltersView (org.telegram.ui.Adapters.FiltersView)6 ProfileSearchCell (org.telegram.ui.Cells.ProfileSearchCell)6 Theme (org.telegram.ui.ActionBar.Theme)5 BackupImageView (org.telegram.ui.Components.BackupImageView)5 ChatActivityEnterView (org.telegram.ui.Components.ChatActivityEnterView)5 FragmentContextView (org.telegram.ui.Components.FragmentContextView)5 NumberTextView (org.telegram.ui.Components.NumberTextView)5