Search in sources :

Example 1 with SharedDocumentCell

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

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

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

the class PhotoPickerActivity method updateCheckedPhotoIndices.

private void updateCheckedPhotoIndices() {
    if (!allowIndices) {
        return;
    }
    int count = listView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = listView.getChildAt(a);
        if (view instanceof PhotoAttachPhotoCell) {
            PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
            Integer index = (Integer) view.getTag();
            if (selectedAlbum != null) {
                MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
                cell.setNum(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.imageId) : -1);
            } else {
                MediaController.SearchImage photoEntry = searchResult.get(index);
                cell.setNum(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.id) : -1);
            }
        } else if (view instanceof SharedDocumentCell) {
            Integer index = (Integer) view.getTag();
            MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
            SharedDocumentCell cell = (SharedDocumentCell) view;
            cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId) != 0, false);
        }
    }
}
Also used : PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) MediaController(org.telegram.messenger.MediaController) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) TextView(android.widget.TextView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) BackupImageView(org.telegram.ui.Components.BackupImageView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell)

Example 4 with SharedDocumentCell

use of org.telegram.ui.Cells.SharedDocumentCell 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 5 with SharedDocumentCell

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

SharedDocumentCell (org.telegram.ui.Cells.SharedDocumentCell)6 Paint (android.graphics.Paint)4 SharedAudioCell (org.telegram.ui.Cells.SharedAudioCell)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 ArrayList (java.util.ArrayList)3 SharedLinkCell (org.telegram.ui.Cells.SharedLinkCell)3 SharedPhotoVideoCell2 (org.telegram.ui.Cells.SharedPhotoVideoCell2)3 MediaController (org.telegram.messenger.MediaController)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 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1