Search in sources :

Example 91 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class LaunchActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
        Theme.checkAutoNightThemeConditions();
    }
    checkWasMutedByAdmin(true);
    // FileLog.d("UI resume time = " + (SystemClock.elapsedRealtime() - ApplicationLoader.startTime));
    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 4096);
    MediaController.getInstance().setFeedbackView(actionBarLayout, true);
    ApplicationLoader.mainInterfacePaused = false;
    showLanguageAlert(false);
    Utilities.stageQueue.postRunnable(() -> {
        ApplicationLoader.mainInterfacePausedStageQueue = false;
        ApplicationLoader.mainInterfacePausedStageQueueTime = System.currentTimeMillis();
    });
    checkFreeDiscSpace();
    MediaController.checkGallery();
    onPasscodeResume();
    if (passcodeView == null || passcodeView.getVisibility() != View.VISIBLE) {
        actionBarLayout.onResume();
        if (AndroidUtilities.isTablet()) {
            rightActionBarLayout.onResume();
            layersActionBarLayout.onResume();
        }
    } else {
        actionBarLayout.dismissDialogs();
        if (AndroidUtilities.isTablet()) {
            rightActionBarLayout.dismissDialogs();
            layersActionBarLayout.dismissDialogs();
        }
        passcodeView.onResume();
    }
    ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
    updateCurrentConnectionState(currentAccount);
    if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
        PhotoViewer.getInstance().onResume();
    }
    PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
    if (pipRoundVideoView != null && MediaController.getInstance().isMessagePaused()) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (messageObject != null) {
            MediaController.getInstance().seekToProgress(messageObject, messageObject.audioProgress);
        }
    }
    if (UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService != null) {
        showTosActivity(UserConfig.selectedAccount, UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService);
    } else if (SharedConfig.pendingAppUpdate != null && SharedConfig.pendingAppUpdate.can_not_skip) {
        showUpdateActivity(UserConfig.selectedAccount, SharedConfig.pendingAppUpdate, true);
    }
    checkAppUpdate(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        ApplicationLoader.canDrawOverlays = Settings.canDrawOverlays(this);
    }
    if (VoIPFragment.getInstance() != null) {
        VoIPFragment.onResume();
    }
}
Also used : PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) MessageObject(org.telegram.messenger.MessageObject)

Example 92 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class LaunchActivity method runCommentRequest.

private int runCommentRequest(int intentAccount, AlertDialog progressDialog, Integer messageId, Integer commentId, Integer threadId, TLRPC.Chat chat) {
    if (chat == null) {
        return 0;
    }
    TLRPC.TL_messages_getDiscussionMessage req = new TLRPC.TL_messages_getDiscussionMessage();
    req.peer = MessagesController.getInputPeer(chat);
    req.msg_id = commentId != null ? messageId : threadId;
    return ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        boolean chatOpened = false;
        if (response instanceof TLRPC.TL_messages_discussionMessage) {
            TLRPC.TL_messages_discussionMessage res = (TLRPC.TL_messages_discussionMessage) response;
            MessagesController.getInstance(intentAccount).putUsers(res.users, false);
            MessagesController.getInstance(intentAccount).putChats(res.chats, false);
            ArrayList<MessageObject> arrayList = new ArrayList<>();
            for (int a = 0, N = res.messages.size(); a < N; a++) {
                arrayList.add(new MessageObject(UserConfig.selectedAccount, res.messages.get(a), true, true));
            }
            if (!arrayList.isEmpty()) {
                Bundle args = new Bundle();
                args.putLong("chat_id", -arrayList.get(0).getDialogId());
                args.putInt("message_id", Math.max(1, messageId));
                ChatActivity chatActivity = new ChatActivity(args);
                chatActivity.setThreadMessages(arrayList, chat, req.msg_id, res.read_inbox_max_id, res.read_outbox_max_id);
                if (commentId != null) {
                    chatActivity.setHighlightMessageId(commentId);
                } else if (threadId != null) {
                    chatActivity.setHighlightMessageId(messageId);
                }
                presentFragment(chatActivity);
                chatOpened = true;
            }
        }
        if (!chatOpened) {
            try {
                if (!mainFragmentsStack.isEmpty()) {
                    BulletinFactory.of(mainFragmentsStack.get(mainFragmentsStack.size() - 1)).createErrorBulletin(LocaleController.getString("ChannelPostDeleted", R.string.ChannelPostDeleted)).show();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        try {
            progressDialog.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
    }));
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) MessageObject(org.telegram.messenger.MessageObject) TLRPC(org.telegram.tgnet.TLRPC) ParseException(java.text.ParseException)

Example 93 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class FilteredSearchView method search.

public void search(long dialogId, long minDate, long maxDate, FiltersView.MediaFilterData currentSearchFilter, boolean includeFolder, String query, boolean clearOldResults) {
    String currentSearchFilterQueryString = String.format(Locale.ENGLISH, "%d%d%d%d%s%s", dialogId, minDate, maxDate, currentSearchFilter == null ? -1 : currentSearchFilter.filterType, query, includeFolder);
    boolean filterAndQueryIsSame = lastSearchFilterQueryString != null && lastSearchFilterQueryString.equals(currentSearchFilterQueryString);
    boolean forceClear = !filterAndQueryIsSame && clearOldResults;
    this.currentSearchFilter = currentSearchFilter;
    this.currentSearchDialogId = dialogId;
    this.currentSearchMinDate = minDate;
    this.currentSearchMaxDate = maxDate;
    this.currentSearchString = query;
    this.currentIncludeFolder = includeFolder;
    if (searchRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(searchRunnable);
    }
    AndroidUtilities.cancelRunOnUIThread(clearCurrentResultsRunnable);
    if (filterAndQueryIsSame && clearOldResults) {
        return;
    }
    if (forceClear || currentSearchFilter == null && dialogId == 0 && minDate == 0 && maxDate == 0) {
        messages.clear();
        sections.clear();
        sectionArrays.clear();
        isLoading = true;
        emptyView.setVisibility(View.VISIBLE);
        if (adapter != null) {
            adapter.notifyDataSetChanged();
        }
        requestIndex++;
        firstLoading = true;
        if (recyclerListView.getPinnedHeader() != null) {
            recyclerListView.getPinnedHeader().setAlpha(0);
        }
        localTipChats.clear();
        localTipDates.clear();
        if (!forceClear) {
            return;
        }
    } else if (clearOldResults && !messages.isEmpty()) {
        return;
    }
    isLoading = true;
    if (adapter != null) {
        adapter.notifyDataSetChanged();
    }
    if (!filterAndQueryIsSame) {
        clearCurrentResultsRunnable.run();
        emptyView.showProgress(true, !clearOldResults);
    }
    if (TextUtils.isEmpty(query)) {
        localTipDates.clear();
        localTipChats.clear();
        if (delegate != null) {
            delegate.updateFiltersView(false, null, null, false);
        }
    }
    requestIndex++;
    final int requestId = requestIndex;
    int currentAccount = UserConfig.selectedAccount;
    AndroidUtilities.runOnUIThread(searchRunnable = () -> {
        TLObject request;
        ArrayList<Object> resultArray = null;
        if (dialogId != 0) {
            final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
            req.q = query;
            req.limit = 20;
            req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
            req.peer = AccountInstance.getInstance(currentAccount).getMessagesController().getInputPeer(dialogId);
            if (minDate > 0) {
                req.min_date = (int) (minDate / 1000);
            }
            if (maxDate > 0) {
                req.max_date = (int) (maxDate / 1000);
            }
            if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
                MessageObject lastMessage = messages.get(messages.size() - 1);
                req.offset_id = lastMessage.getId();
            } else {
                req.offset_id = 0;
            }
            request = req;
        } else {
            if (!TextUtils.isEmpty(query)) {
                resultArray = new ArrayList<>();
                ArrayList<CharSequence> resultArrayNames = new ArrayList<>();
                ArrayList<TLRPC.User> encUsers = new ArrayList<>();
                MessagesStorage.getInstance(currentAccount).localSearch(0, query, resultArray, resultArrayNames, encUsers, includeFolder ? 1 : 0);
            }
            final TLRPC.TL_messages_searchGlobal req = new TLRPC.TL_messages_searchGlobal();
            req.limit = 20;
            req.q = query;
            req.filter = currentSearchFilter == null ? new TLRPC.TL_inputMessagesFilterEmpty() : currentSearchFilter.filter;
            if (minDate > 0) {
                req.min_date = (int) (minDate / 1000);
            }
            if (maxDate > 0) {
                req.max_date = (int) (maxDate / 1000);
            }
            if (filterAndQueryIsSame && query.equals(lastMessagesSearchString) && !messages.isEmpty()) {
                MessageObject lastMessage = messages.get(messages.size() - 1);
                req.offset_id = lastMessage.getId();
                req.offset_rate = nextSearchRate;
                long id = MessageObject.getPeerId(lastMessage.messageOwner.peer_id);
                req.offset_peer = MessagesController.getInstance(currentAccount).getInputPeer(id);
            } else {
                req.offset_rate = 0;
                req.offset_id = 0;
                req.offset_peer = new TLRPC.TL_inputPeerEmpty();
            }
            req.flags |= 1;
            req.folder_id = includeFolder ? 1 : 0;
            request = req;
        }
        lastMessagesSearchString = query;
        lastSearchFilterQueryString = currentSearchFilterQueryString;
        ArrayList<Object> finalResultArray = resultArray;
        final ArrayList<FiltersView.DateData> dateData = new ArrayList<>();
        FiltersView.fillTipDates(lastMessagesSearchString, dateData);
        ConnectionsManager.getInstance(currentAccount).sendRequest(request, (response, error) -> {
            ArrayList<MessageObject> messageObjects = new ArrayList<>();
            if (error == null) {
                TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                int n = res.messages.size();
                for (int i = 0; i < n; i++) {
                    MessageObject messageObject = new MessageObject(currentAccount, res.messages.get(i), false, true);
                    messageObject.setQuery(query);
                    messageObjects.add(messageObject);
                }
            }
            AndroidUtilities.runOnUIThread(() -> {
                if (requestId != requestIndex) {
                    return;
                }
                isLoading = false;
                if (error != null) {
                    emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                    emptyView.subtitle.setVisibility(View.VISIBLE);
                    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
                    emptyView.showProgress(false, true);
                    return;
                }
                emptyView.showProgress(false);
                TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                nextSearchRate = res.next_rate;
                MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
                MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                MessagesController.getInstance(currentAccount).putChats(res.chats, false);
                if (!filterAndQueryIsSame) {
                    messages.clear();
                    messagesById.clear();
                    sections.clear();
                    sectionArrays.clear();
                }
                totalCount = res.count;
                currentDataQuery = query;
                int n = messageObjects.size();
                for (int i = 0; i < n; i++) {
                    MessageObject messageObject = messageObjects.get(i);
                    ArrayList<MessageObject> messageObjectsByDate = sectionArrays.get(messageObject.monthKey);
                    if (messageObjectsByDate == null) {
                        messageObjectsByDate = new ArrayList<>();
                        sectionArrays.put(messageObject.monthKey, messageObjectsByDate);
                        sections.add(messageObject.monthKey);
                    }
                    messageObjectsByDate.add(messageObject);
                    messages.add(messageObject);
                    messagesById.put(messageObject.getId(), messageObject);
                    if (PhotoViewer.getInstance().isVisible()) {
                        PhotoViewer.getInstance().addPhoto(messageObject, photoViewerClassGuid);
                    }
                }
                if (messages.size() > totalCount) {
                    totalCount = messages.size();
                }
                endReached = messages.size() >= totalCount;
                if (messages.isEmpty()) {
                    if (currentSearchFilter != null) {
                        if (TextUtils.isEmpty(currentDataQuery) && dialogId == 0 && minDate == 0) {
                            emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle", R.string.SearchEmptyViewTitle));
                            String str;
                            if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleFiles", R.string.SearchEmptyViewFilteredSubtitleFiles);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMedia", R.string.SearchEmptyViewFilteredSubtitleMedia);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleLinks", R.string.SearchEmptyViewFilteredSubtitleLinks);
                            } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC) {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleMusic", R.string.SearchEmptyViewFilteredSubtitleMusic);
                            } else {
                                str = LocaleController.getString("SearchEmptyViewFilteredSubtitleVoice", R.string.SearchEmptyViewFilteredSubtitleVoice);
                            }
                            emptyView.subtitle.setVisibility(View.VISIBLE);
                            emptyView.subtitle.setText(str);
                        } else {
                            emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                            emptyView.subtitle.setVisibility(View.VISIBLE);
                            emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
                        }
                    } else {
                        emptyView.title.setText(LocaleController.getString("SearchEmptyViewTitle2", R.string.SearchEmptyViewTitle2));
                        emptyView.subtitle.setVisibility(View.GONE);
                    }
                }
                if (currentSearchFilter != null) {
                    switch(currentSearchFilter.filterType) {
                        case FiltersView.FILTER_TYPE_MEDIA:
                            if (TextUtils.isEmpty(currentDataQuery)) {
                                adapter = sharedPhotoVideoAdapter;
                            } else {
                                adapter = dialogsAdapter;
                            }
                            break;
                        case FiltersView.FILTER_TYPE_FILES:
                            adapter = sharedDocumentsAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_LINKS:
                            adapter = sharedLinksAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_MUSIC:
                            adapter = sharedAudioAdapter;
                            break;
                        case FiltersView.FILTER_TYPE_VOICE:
                            adapter = sharedVoiceAdapter;
                            break;
                    }
                } else {
                    adapter = dialogsAdapter;
                }
                if (recyclerListView.getAdapter() != adapter) {
                    recyclerListView.setAdapter(adapter);
                }
                if (!filterAndQueryIsSame) {
                    localTipChats.clear();
                    if (finalResultArray != null) {
                        localTipChats.addAll(finalResultArray);
                    }
                    if (query.length() >= 3 && (LocaleController.getString("SavedMessages", R.string.SavedMessages).toLowerCase().startsWith(query) || "saved messages".startsWith(query))) {
                        boolean found = false;
                        for (int i = 0; i < localTipChats.size(); i++) {
                            if (localTipChats.get(i) instanceof TLRPC.User)
                                if (UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser().id == ((TLRPC.User) localTipChats.get(i)).id) {
                                    found = true;
                                    break;
                                }
                        }
                        if (!found) {
                            localTipChats.add(0, UserConfig.getInstance(UserConfig.selectedAccount).getCurrentUser());
                        }
                    }
                    localTipDates.clear();
                    localTipDates.addAll(dateData);
                    localTipArchive = false;
                    if (query.length() >= 3 && (LocaleController.getString("ArchiveSearchFilter", R.string.ArchiveSearchFilter).toLowerCase().startsWith(query) || "archive".startsWith(query))) {
                        localTipArchive = true;
                    }
                    if (delegate != null) {
                        delegate.updateFiltersView(TextUtils.isEmpty(currentDataQuery), localTipChats, localTipDates, localTipArchive);
                    }
                }
                firstLoading = false;
                View progressView = null;
                int progressViewPosition = -1;
                for (int i = 0; i < n; i++) {
                    View child = recyclerListView.getChildAt(i);
                    if (child instanceof FlickerLoadingView) {
                        progressView = child;
                        progressViewPosition = recyclerListView.getChildAdapterPosition(child);
                    }
                }
                final View finalProgressView = progressView;
                if (progressView != null) {
                    recyclerListView.removeView(progressView);
                }
                if ((loadingView.getVisibility() == View.VISIBLE && recyclerListView.getChildCount() == 0) || (recyclerListView.getAdapter() != sharedPhotoVideoAdapter && progressView != null)) {
                    int finalProgressViewPosition = progressViewPosition;
                    getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

                        @Override
                        public boolean onPreDraw() {
                            getViewTreeObserver().removeOnPreDrawListener(this);
                            int n = recyclerListView.getChildCount();
                            AnimatorSet animatorSet = new AnimatorSet();
                            for (int i = 0; i < n; i++) {
                                View child = recyclerListView.getChildAt(i);
                                if (finalProgressView != null) {
                                    if (recyclerListView.getChildAdapterPosition(child) < finalProgressViewPosition) {
                                        continue;
                                    }
                                }
                                child.setAlpha(0);
                                int s = Math.min(recyclerListView.getMeasuredHeight(), Math.max(0, child.getTop()));
                                int delay = (int) ((s / (float) recyclerListView.getMeasuredHeight()) * 100);
                                ObjectAnimator a = ObjectAnimator.ofFloat(child, View.ALPHA, 0, 1f);
                                a.setStartDelay(delay);
                                a.setDuration(200);
                                animatorSet.playTogether(a);
                            }
                            animatorSet.addListener(new AnimatorListenerAdapter() {

                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    NotificationCenter.getInstance(currentAccount).onAnimationFinish(animationIndex);
                                }
                            });
                            animationIndex = NotificationCenter.getInstance(currentAccount).setAnimationInProgress(animationIndex, null);
                            animatorSet.start();
                            if (finalProgressView != null && finalProgressView.getParent() == null) {
                                recyclerListView.addView(finalProgressView);
                                RecyclerView.LayoutManager layoutManager = recyclerListView.getLayoutManager();
                                if (layoutManager != null) {
                                    layoutManager.ignoreView(finalProgressView);
                                    Animator animator = ObjectAnimator.ofFloat(finalProgressView, ALPHA, finalProgressView.getAlpha(), 0);
                                    animator.addListener(new AnimatorListenerAdapter() {

                                        @Override
                                        public void onAnimationEnd(Animator animation) {
                                            finalProgressView.setAlpha(1f);
                                            layoutManager.stopIgnoringView(finalProgressView);
                                            recyclerListView.removeView(finalProgressView);
                                        }
                                    });
                                    animator.start();
                                }
                            }
                            return true;
                        }
                    });
                }
                adapter.notifyDataSetChanged();
            });
        });
    }, (filterAndQueryIsSame && !messages.isEmpty()) ? 0 : 350);
    if (currentSearchFilter == null) {
        loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MEDIA) {
        if (!TextUtils.isEmpty(currentSearchString)) {
            loadingView.setViewType(FlickerLoadingView.DIALOG_TYPE);
        } else {
            loadingView.setViewType(FlickerLoadingView.PHOTOS_TYPE);
        }
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_FILES) {
        loadingView.setViewType(FlickerLoadingView.FILES_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_MUSIC || currentSearchFilter.filterType == FiltersView.FILTER_TYPE_VOICE) {
        loadingView.setViewType(FlickerLoadingView.AUDIO_TYPE);
    } else if (currentSearchFilter.filterType == FiltersView.FILTER_TYPE_LINKS) {
        loadingView.setViewType(FlickerLoadingView.LINKS_TYPE);
    }
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) FiltersView(org.telegram.ui.Adapters.FiltersView) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) ApplicationLoader(org.telegram.messenger.ApplicationLoader) SharedPhotoVideoCell(org.telegram.ui.Cells.SharedPhotoVideoCell) Locale(java.util.Locale) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) SharedMediaSectionCell(org.telegram.ui.Cells.SharedMediaSectionCell) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) Context(android.content.Context) ColoredImageSpan(org.telegram.ui.Components.ColoredImageSpan) Theme(org.telegram.ui.ActionBar.Theme) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) TLObject(org.telegram.tgnet.TLObject) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) Build(android.os.Build) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) SearchViewPager(org.telegram.ui.Components.SearchViewPager) Browser(org.telegram.messenger.browser.Browser) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) BackupImageView(org.telegram.ui.Components.BackupImageView) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) Gravity(android.view.Gravity) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) ImageReceiver(org.telegram.messenger.ImageReceiver) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LoadingCell(org.telegram.ui.Cells.LoadingCell) ArrayList(java.util.ArrayList) FiltersView(org.telegram.ui.Adapters.FiltersView) AnimatorSet(android.animation.AnimatorSet) TLRPC(org.telegram.tgnet.TLRPC) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) ObjectAnimator(android.animation.ObjectAnimator) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TLObject(org.telegram.tgnet.TLObject) RecyclerView(androidx.recyclerview.widget.RecyclerView) MessageObject(org.telegram.messenger.MessageObject)

Example 94 with MessageObject

use of org.telegram.messenger.MessageObject 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)

Example 95 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class FilteredSearchView method messagesDeleted.

public void messagesDeleted(long channelId, ArrayList<Integer> markAsDeletedMessages) {
    boolean changed = false;
    for (int j = 0; j < messages.size(); j++) {
        MessageObject messageObject = messages.get(j);
        long dialogId = messageObject.getDialogId();
        int currentChannelId = dialogId < 0 && ChatObject.isChannel((int) -dialogId, UserConfig.selectedAccount) ? (int) -dialogId : 0;
        if (currentChannelId == channelId) {
            for (int i = 0; i < markAsDeletedMessages.size(); i++) {
                if (messageObject.getId() == markAsDeletedMessages.get(i)) {
                    changed = true;
                    messages.remove(j);
                    messagesById.remove(messageObject.getId());
                    ArrayList<MessageObject> section = sectionArrays.get(messageObject.monthKey);
                    section.remove(messageObject);
                    if (section.size() == 0) {
                        sections.remove(messageObject.monthKey);
                        sectionArrays.remove(messageObject.monthKey);
                    }
                    j--;
                    totalCount--;
                }
            }
        }
    }
    if (changed && adapter != null) {
        adapter.notifyDataSetChanged();
    }
}
Also used : MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint)

Aggregations

MessageObject (org.telegram.messenger.MessageObject)156 Paint (android.graphics.Paint)107 TLRPC (org.telegram.tgnet.TLRPC)88 SuppressLint (android.annotation.SuppressLint)87 TextPaint (android.text.TextPaint)80 View (android.view.View)59 ArrayList (java.util.ArrayList)59 TextView (android.widget.TextView)53 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)52 RecyclerView (androidx.recyclerview.widget.RecyclerView)50 ImageView (android.widget.ImageView)48 RecyclerListView (org.telegram.ui.Components.RecyclerListView)46 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)39 UndoView (org.telegram.ui.Components.UndoView)36 TextureView (android.view.TextureView)34 File (java.io.File)33 ChatObject (org.telegram.messenger.ChatObject)32 DialogObject (org.telegram.messenger.DialogObject)30 MediaController (org.telegram.messenger.MediaController)30 TLObject (org.telegram.tgnet.TLObject)30