Search in sources :

Example 1 with SharedPhotoVideoCell2

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

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

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

the class SharedMediaLayout method saveScrollPosition.

private void saveScrollPosition() {
    for (int k = 0; k < mediaPages.length; k++) {
        RecyclerListView listView = mediaPages[k].listView;
        if (listView != null) {
            int messageId = 0;
            int offset = 0;
            for (int i = 0; i < listView.getChildCount(); i++) {
                View child = listView.getChildAt(i);
                if (child instanceof SharedPhotoVideoCell2) {
                    SharedPhotoVideoCell2 cell = (SharedPhotoVideoCell2) child;
                    messageId = cell.getMessageId();
                    offset = cell.getTop();
                }
                if (child instanceof SharedDocumentCell) {
                    SharedDocumentCell cell = (SharedDocumentCell) child;
                    messageId = cell.getMessage().getId();
                }
                if (child instanceof SharedAudioCell) {
                    SharedAudioCell cell = (SharedAudioCell) child;
                    messageId = cell.getMessage().getId();
                }
                if (messageId != 0) {
                    break;
                }
            }
            if (messageId != 0) {
                int index = -1;
                if (mediaPages[k].selectedType < 0 || mediaPages[k].selectedType >= sharedMediaData.length) {
                    continue;
                }
                for (int i = 0; i < sharedMediaData[mediaPages[k].selectedType].messages.size(); i++) {
                    if (messageId == sharedMediaData[mediaPages[k].selectedType].messages.get(i).getId()) {
                        index = i;
                        break;
                    }
                }
                int position = sharedMediaData[mediaPages[k].selectedType].startOffset + index;
                if (index >= 0) {
                    ((LinearLayoutManager) listView.getLayoutManager()).scrollToPositionWithOffset(position, offset);
                    if (photoVideoChangeColumnsAnimation) {
                        mediaPages[k].animationSupportingLayoutManager.scrollToPositionWithOffset(position, offset);
                    }
                }
            }
        }
    }
}
Also used : SharedPhotoVideoCell2(org.telegram.ui.Cells.SharedPhotoVideoCell2) SharedAudioCell(org.telegram.ui.Cells.SharedAudioCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) 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)

Aggregations

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