Search in sources :

Example 1 with SharedLinkCell

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

the class SharedMediaLayout method onItemClick.

private void onItemClick(int index, View view, MessageObject message, int a, int selectedMode) {
    if (message == null || photoVideoChangeColumnsAnimation) {
        return;
    }
    if (isActionModeShowed) {
        int loadIndex = message.getDialogId() == dialog_id ? 0 : 1;
        if (selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0) {
            selectedFiles[loadIndex].remove(message.getId());
            if (!message.canDeleteMessage(false, null)) {
                cantDeleteMessagesCount--;
            }
        } else {
            if (selectedFiles[0].size() + selectedFiles[1].size() >= 100) {
                return;
            }
            selectedFiles[loadIndex].put(message.getId(), message);
            if (!message.canDeleteMessage(false, null)) {
                cantDeleteMessagesCount++;
            }
        }
        if (selectedFiles[0].size() == 0 && selectedFiles[1].size() == 0) {
            showActionMode(false);
        } else {
            selectedMessagesCountTextView.setNumber(selectedFiles[0].size() + selectedFiles[1].size(), true);
            deleteItem.setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
            if (gotoItem != null) {
                gotoItem.setVisibility(selectedFiles[0].size() == 1 ? View.VISIBLE : View.GONE);
            }
        }
        scrolling = false;
        if (view instanceof SharedDocumentCell) {
            ((SharedDocumentCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        } else if (view instanceof SharedPhotoVideoCell) {
            ((SharedPhotoVideoCell) view).setChecked(a, selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        } else if (view instanceof SharedLinkCell) {
            ((SharedLinkCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        } else if (view instanceof SharedAudioCell) {
            ((SharedAudioCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        } else if (view instanceof ContextLinkCell) {
            ((ContextLinkCell) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        } else if (view instanceof SharedPhotoVideoCell2) {
            ((SharedPhotoVideoCell2) view).setChecked(selectedFiles[loadIndex].indexOfKey(message.getId()) >= 0, true);
        }
    } else {
        if (selectedMode == 0) {
            int i = index - sharedMediaData[selectedMode].startOffset;
            if (i >= 0 && i < sharedMediaData[selectedMode].messages.size()) {
                PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
                PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, i, dialog_id, mergeDialogId, provider);
            }
        } else if (selectedMode == 2 || selectedMode == 4) {
            if (view instanceof SharedAudioCell) {
                ((SharedAudioCell) view).didPressedButton();
            }
        } else if (selectedMode == 5) {
            PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
            index = sharedMediaData[selectedMode].messages.indexOf(message);
            if (index < 0) {
                ArrayList<MessageObject> documents = new ArrayList<>();
                documents.add(message);
                PhotoViewer.getInstance().openPhoto(documents, 0, 0, 0, provider);
            } else {
                PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, provider);
            }
        } else if (selectedMode == 1) {
            if (view instanceof SharedDocumentCell) {
                SharedDocumentCell cell = (SharedDocumentCell) view;
                TLRPC.Document document = message.getDocument();
                if (cell.isLoaded()) {
                    if (message.canPreviewDocument()) {
                        PhotoViewer.getInstance().setParentActivity(profileActivity.getParentActivity());
                        index = sharedMediaData[selectedMode].messages.indexOf(message);
                        if (index < 0) {
                            ArrayList<MessageObject> documents = new ArrayList<>();
                            documents.add(message);
                            PhotoViewer.getInstance().openPhoto(documents, 0, 0, 0, provider);
                        } else {
                            PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, provider);
                        }
                        return;
                    }
                    AndroidUtilities.openDocument(message, profileActivity.getParentActivity(), profileActivity);
                } else if (!cell.isLoading()) {
                    MessageObject messageObject = cell.getMessage();
                    profileActivity.getFileLoader().loadFile(document, messageObject, 0, 0);
                    cell.updateFileExistIcon(true);
                } else {
                    profileActivity.getFileLoader().cancelLoadFile(document);
                    cell.updateFileExistIcon(true);
                }
            }
        } else if (selectedMode == 3) {
            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(profileActivity.getParentActivity(), profileActivity);
                        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);
            }
        }
    }
    updateForwardItem();
}
Also used : ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) TLRPC(org.telegram.tgnet.TLRPC) SharedPhotoVideoCell2(org.telegram.ui.Cells.SharedPhotoVideoCell2) SharedPhotoVideoCell(org.telegram.ui.Cells.SharedPhotoVideoCell) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) MessageObject(org.telegram.messenger.MessageObject) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell)

Example 2 with SharedLinkCell

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

the class SharedMediaLayout method onItemLongClick.

private boolean onItemLongClick(MessageObject item, View view, int a) {
    if (isActionModeShowed || profileActivity.getParentActivity() == null || item == null) {
        return false;
    }
    AndroidUtilities.hideKeyboard(profileActivity.getParentActivity().getCurrentFocus());
    selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
    if (!item.canDeleteMessage(false, null)) {
        cantDeleteMessagesCount++;
    }
    deleteItem.setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
    if (gotoItem != null) {
        gotoItem.setVisibility(View.VISIBLE);
    }
    selectedMessagesCountTextView.setNumber(1, false);
    AnimatorSet animatorSet = new AnimatorSet();
    ArrayList<Animator> animators = new ArrayList<>();
    for (int i = 0; i < actionModeViews.size(); i++) {
        View view2 = actionModeViews.get(i);
        AndroidUtilities.clearDrawableAnimation(view2);
        animators.add(ObjectAnimator.ofFloat(view2, View.SCALE_Y, 0.1f, 1.0f));
    }
    animatorSet.playTogether(animators);
    animatorSet.setDuration(250);
    animatorSet.start();
    scrolling = false;
    if (view instanceof SharedDocumentCell) {
        ((SharedDocumentCell) view).setChecked(true, true);
    } else if (view instanceof SharedPhotoVideoCell) {
        ((SharedPhotoVideoCell) view).setChecked(a, true, true);
    } else if (view instanceof SharedLinkCell) {
        ((SharedLinkCell) view).setChecked(true, true);
    } else if (view instanceof SharedAudioCell) {
        ((SharedAudioCell) view).setChecked(true, true);
    } else if (view instanceof ContextLinkCell) {
        ((ContextLinkCell) view).setChecked(true, true);
    } else if (view instanceof SharedPhotoVideoCell2) {
        ((SharedPhotoVideoCell2) view).setChecked(true, true);
    }
    if (!isActionModeShowed) {
        showActionMode(true);
    }
    updateForwardItem();
    return true;
}
Also used : ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SharedPhotoVideoCell2(org.telegram.ui.Cells.SharedPhotoVideoCell2) SharedPhotoVideoCell(org.telegram.ui.Cells.SharedPhotoVideoCell) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ArrayList(java.util.ArrayList) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Paint(android.graphics.Paint) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) SharedLinkCell(org.telegram.ui.Cells.SharedLinkCell)

Example 3 with SharedLinkCell

use of org.telegram.ui.Cells.SharedLinkCell 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

ArrayList (java.util.ArrayList)3 SharedAudioCell (org.telegram.ui.Cells.SharedAudioCell)3 SharedDocumentCell (org.telegram.ui.Cells.SharedDocumentCell)3 SharedLinkCell (org.telegram.ui.Cells.SharedLinkCell)3 Paint (android.graphics.Paint)2 MessageObject (org.telegram.messenger.MessageObject)2 TLRPC (org.telegram.tgnet.TLRPC)2 ContextLinkCell (org.telegram.ui.Cells.ContextLinkCell)2 SharedPhotoVideoCell (org.telegram.ui.Cells.SharedPhotoVideoCell)2 SharedPhotoVideoCell2 (org.telegram.ui.Cells.SharedPhotoVideoCell2)2 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 DialogCell (org.telegram.ui.Cells.DialogCell)1