Search in sources :

Example 36 with ChatActivity

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

the class ChatAttachAlertPollLayout method onMenuItemClick.

@Override
void onMenuItemClick(int id) {
    if (id == done_button) {
        if (quizPoll && parentAlert.doneItem.getAlpha() != 1.0f) {
            int checksCount = 0;
            for (int a = 0; a < answersChecks.length; a++) {
                if (!TextUtils.isEmpty(getFixedString(answers[a])) && answersChecks[a]) {
                    checksCount++;
                }
            }
            if (checksCount <= 0) {
                showQuizHint();
            }
            return;
        }
        TLRPC.TL_messageMediaPoll poll = new TLRPC.TL_messageMediaPoll();
        poll.poll = new TLRPC.TL_poll();
        poll.poll.multiple_choice = multipleChoise;
        poll.poll.quiz = quizPoll;
        poll.poll.public_voters = !anonymousPoll;
        poll.poll.question = getFixedString(questionString).toString();
        SerializedData serializedData = new SerializedData(10);
        for (int a = 0; a < answers.length; a++) {
            if (TextUtils.isEmpty(getFixedString(answers[a]))) {
                continue;
            }
            TLRPC.TL_pollAnswer answer = new TLRPC.TL_pollAnswer();
            answer.text = getFixedString(answers[a]).toString();
            answer.option = new byte[1];
            answer.option[0] = (byte) (48 + poll.poll.answers.size());
            poll.poll.answers.add(answer);
            if ((multipleChoise || quizPoll) && answersChecks[a]) {
                serializedData.writeByte(answer.option[0]);
            }
        }
        HashMap<String, String> params = new HashMap<>();
        params.put("answers", Utilities.bytesToHex(serializedData.toByteArray()));
        poll.results = new TLRPC.TL_pollResults();
        CharSequence solution = getFixedString(solutionString);
        if (solution != null) {
            poll.results.solution = solution.toString();
            CharSequence[] message = new CharSequence[] { solution };
            ArrayList<TLRPC.MessageEntity> entities = MediaDataController.getInstance(parentAlert.currentAccount).getEntities(message, true);
            if (entities != null && !entities.isEmpty()) {
                poll.results.solution_entities = entities;
            }
            if (!TextUtils.isEmpty(poll.results.solution)) {
                poll.results.flags |= 16;
            }
        }
        ChatActivity chatActivity = (ChatActivity) parentAlert.baseFragment;
        if (chatActivity.isInScheduleMode()) {
            AlertsCreator.createScheduleDatePickerDialog(chatActivity.getParentActivity(), chatActivity.getDialogId(), (notify, scheduleDate) -> {
                delegate.sendPoll(poll, params, notify, scheduleDate);
                parentAlert.dismiss();
            });
        } else {
            delegate.sendPoll(poll, params, true, 0);
            parentAlert.dismiss();
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) HashMap(java.util.HashMap) SerializedData(org.telegram.tgnet.SerializedData) TLRPC(org.telegram.tgnet.TLRPC)

Example 37 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method updateCheckedPhotoIndices.

private void updateCheckedPhotoIndices() {
    if (!(parentAlert.baseFragment instanceof ChatActivity)) {
        return;
    }
    int count = gridView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = gridView.getChildAt(a);
        if (view instanceof PhotoAttachPhotoCell) {
            PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
            MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition((Integer) cell.getTag());
            if (photoEntry != null) {
                cell.setNum(selectedPhotosOrder.indexOf(photoEntry.imageId));
            }
        }
    }
    count = cameraPhotoRecyclerView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = cameraPhotoRecyclerView.getChildAt(a);
        if (view instanceof PhotoAttachPhotoCell) {
            PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
            MediaController.PhotoEntry photoEntry = getPhotoEntryAtPosition((Integer) cell.getTag());
            if (photoEntry != null) {
                cell.setNum(selectedPhotosOrder.indexOf(photoEntry.imageId));
            }
        }
    }
}
Also used : PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) CameraView(org.telegram.messenger.camera.CameraView) Paint(android.graphics.Paint)

Example 38 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method openPhotoViewer.

private void openPhotoViewer(MediaController.PhotoEntry entry, final boolean sameTakePictureOrientation, boolean external) {
    if (entry != null) {
        cameraPhotos.add(entry);
        selectedPhotos.put(entry.imageId, entry);
        selectedPhotosOrder.add(entry.imageId);
        parentAlert.updateCountButton(0);
        adapter.notifyDataSetChanged();
        cameraAttachAdapter.notifyDataSetChanged();
    }
    if (entry != null && !external && cameraPhotos.size() > 1) {
        updatePhotosCounter(false);
        if (cameraView != null) {
            zoomControlView.setZoom(0.0f, false);
            cameraZoom = 0.0f;
            cameraView.setZoom(0.0f);
            CameraController.getInstance().startPreview(cameraView.getCameraSession());
        }
        return;
    }
    if (cameraPhotos.isEmpty()) {
        return;
    }
    cancelTakingPhotos = true;
    PhotoViewer.getInstance().setParentActivity(parentAlert.baseFragment.getParentActivity(), resourcesProvider);
    PhotoViewer.getInstance().setParentAlert(parentAlert);
    PhotoViewer.getInstance().setMaxSelectedPhotos(parentAlert.maxSelectedPhotos, parentAlert.allowOrder);
    ChatActivity chatActivity;
    int type;
    if (parentAlert.avatarPicker != 0) {
        type = PhotoViewer.SELECT_TYPE_AVATAR;
        chatActivity = null;
    } else if (parentAlert.baseFragment instanceof ChatActivity) {
        chatActivity = (ChatActivity) parentAlert.baseFragment;
        type = 2;
    } else {
        chatActivity = null;
        type = 5;
    }
    ArrayList<Object> arrayList;
    int index;
    if (parentAlert.avatarPicker != 0) {
        arrayList = new ArrayList<>();
        arrayList.add(entry);
        index = 0;
    } else {
        arrayList = getAllPhotosArray();
        index = cameraPhotos.size() - 1;
    }
    PhotoViewer.getInstance().openPhotoForSelect(arrayList, index, type, false, new BasePhotoProvider() {

        @Override
        public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
            return null;
        }

        @Override
        public boolean cancelButtonPressed() {
            if (cameraOpened && cameraView != null) {
                AndroidUtilities.runOnUIThread(() -> {
                    if (cameraView != null && !parentAlert.isDismissed() && Build.VERSION.SDK_INT >= 21) {
                        cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
                    }
                }, 1000);
                zoomControlView.setZoom(0.0f, false);
                cameraZoom = 0.0f;
                cameraView.setZoom(0.0f);
                CameraController.getInstance().startPreview(cameraView.getCameraSession());
            }
            if (cancelTakingPhotos && cameraPhotos.size() == 1) {
                for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
                    MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(a);
                    new File(photoEntry.path).delete();
                    if (photoEntry.imagePath != null) {
                        new File(photoEntry.imagePath).delete();
                    }
                    if (photoEntry.thumbPath != null) {
                        new File(photoEntry.thumbPath).delete();
                    }
                }
                cameraPhotos.clear();
                selectedPhotosOrder.clear();
                selectedPhotos.clear();
                counterTextView.setVisibility(View.INVISIBLE);
                cameraPhotoRecyclerView.setVisibility(View.GONE);
                adapter.notifyDataSetChanged();
                cameraAttachAdapter.notifyDataSetChanged();
                parentAlert.updateCountButton(0);
            }
            return true;
        }

        @Override
        public void needAddMorePhotos() {
            cancelTakingPhotos = false;
            if (mediaFromExternalCamera) {
                parentAlert.delegate.didPressedButton(0, true, true, 0, false);
                return;
            }
            if (!cameraOpened) {
                openCamera(false);
            }
            counterTextView.setVisibility(View.VISIBLE);
            cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
            counterTextView.setAlpha(1.0f);
            updatePhotosCounter(false);
        }

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
            if (cameraPhotos.isEmpty() || parentAlert.baseFragment == null) {
                return;
            }
            if (videoEditedInfo != null && index >= 0 && index < cameraPhotos.size()) {
                MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) cameraPhotos.get(index);
                photoEntry.editedInfo = videoEditedInfo;
            }
            if (!(parentAlert.baseFragment instanceof ChatActivity) || !((ChatActivity) parentAlert.baseFragment).isSecretChat()) {
                for (int a = 0, size = cameraPhotos.size(); a < size; a++) {
                    AndroidUtilities.addMediaToGallery(((MediaController.PhotoEntry) cameraPhotos.get(a)).path);
                }
            }
            parentAlert.applyCaption();
            closeCamera(false);
            parentAlert.delegate.didPressedButton(forceDocument ? 4 : 8, true, notify, scheduleDate, forceDocument);
            cameraPhotos.clear();
            selectedPhotosOrder.clear();
            selectedPhotos.clear();
            adapter.notifyDataSetChanged();
            cameraAttachAdapter.notifyDataSetChanged();
            parentAlert.dismiss();
        }

        @Override
        public boolean scaleToFill() {
            if (parentAlert.baseFragment == null || parentAlert.baseFragment.getParentActivity() == null) {
                return false;
            }
            int locked = Settings.System.getInt(parentAlert.baseFragment.getParentActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0);
            return sameTakePictureOrientation || locked == 1;
        }

        @Override
        public void willHidePhotoViewer() {
            int count = gridView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = gridView.getChildAt(a);
                if (view instanceof PhotoAttachPhotoCell) {
                    PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
                    cell.showImage();
                    cell.showCheck(true);
                }
            }
        }

        @Override
        public boolean canScrollAway() {
            return false;
        }

        @Override
        public boolean canCaptureMorePhotos() {
            return parentAlert.maxSelectedPhotos != 1;
        }
    }, chatActivity);
}
Also used : MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) CameraView(org.telegram.messenger.camera.CameraView) Paint(android.graphics.Paint) TLRPC(org.telegram.tgnet.TLRPC) PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) MessageObject(org.telegram.messenger.MessageObject) ChatObject(org.telegram.messenger.ChatObject) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MessageObject(org.telegram.messenger.MessageObject) File(java.io.File)

Example 39 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method onInit.

@Override
void onInit(boolean hasMedia) {
    mediaEnabled = hasMedia;
    if (cameraView != null) {
        cameraView.setAlpha(mediaEnabled ? 1.0f : 0.2f);
        cameraView.setEnabled(mediaEnabled);
    }
    if (cameraIcon != null) {
        cameraIcon.setAlpha(mediaEnabled ? 1.0f : 0.2f);
        cameraIcon.setEnabled(mediaEnabled);
    }
    if (parentAlert.baseFragment instanceof ChatActivity && parentAlert.avatarPicker == 0) {
        galleryAlbumEntry = MediaController.allMediaAlbumEntry;
        if (mediaEnabled) {
            progressView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
        } else {
            TLRPC.Chat chat = ((ChatActivity) parentAlert.baseFragment).getCurrentChat();
            if (ChatObject.isActionBannedByDefault(chat, ChatObject.ACTION_SEND_MEDIA)) {
                progressView.setText(LocaleController.getString("GlobalAttachMediaRestricted", R.string.GlobalAttachMediaRestricted));
            } else if (AndroidUtilities.isBannedForever(chat.banned_rights)) {
                progressView.setText(LocaleController.formatString("AttachMediaRestrictedForever", R.string.AttachMediaRestrictedForever));
            } else {
                progressView.setText(LocaleController.formatString("AttachMediaRestricted", R.string.AttachMediaRestricted, LocaleController.formatDateForBan(chat.banned_rights.until_date)));
            }
        }
    } else {
        if (parentAlert.avatarPicker == 2) {
            galleryAlbumEntry = MediaController.allMediaAlbumEntry;
        } else {
            galleryAlbumEntry = MediaController.allPhotosAlbumEntry;
        }
    }
    if (Build.VERSION.SDK_INT >= 23) {
        noGalleryPermissions = parentAlert.baseFragment.getParentActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED;
    }
    if (galleryAlbumEntry != null) {
        for (int a = 0; a < Math.min(100, galleryAlbumEntry.photos.size()); a++) {
            MediaController.PhotoEntry photoEntry = galleryAlbumEntry.photos.get(a);
            photoEntry.reset();
        }
    }
    clearSelectedPhotos();
    updatePhotosCounter(false);
    cameraPhotoLayoutManager.scrollToPositionWithOffset(0, 1000000);
    layoutManager.scrollToPositionWithOffset(0, 1000000);
    dropDown.setText(LocaleController.getString("ChatGallery", R.string.ChatGallery));
    selectedAlbumEntry = galleryAlbumEntry;
    if (selectedAlbumEntry != null) {
        loading = false;
        if (progressView != null) {
            progressView.showTextView();
        }
    }
    updateAlbumsDropDown();
}
Also used : MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) TLRPC(org.telegram.tgnet.TLRPC) Paint(android.graphics.Paint)

Example 40 with ChatActivity

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

the class ChatAttachAlert method openDocumentsLayout.

private void openDocumentsLayout(boolean show) {
    if (documentLayout == null) {
        layouts[4] = documentLayout = new ChatAttachAlertDocumentLayout(this, getContext(), false, resourcesProvider);
        documentLayout.setDelegate(new ChatAttachAlertDocumentLayout.DocumentSelectActivityDelegate() {

            @Override
            public void didSelectFiles(ArrayList<String> files, String caption, ArrayList<MessageObject> fmessages, boolean notify, int scheduleDate) {
                if (baseFragment instanceof ChatActivity) {
                    ((ChatActivity) baseFragment).didSelectFiles(files, caption, fmessages, notify, scheduleDate);
                } else if (baseFragment instanceof PassportActivity) {
                    ((PassportActivity) baseFragment).didSelectFiles(files, caption, notify, scheduleDate);
                }
            }

            @Override
            public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate) {
                if (baseFragment instanceof ChatActivity) {
                    ((ChatActivity) baseFragment).didSelectPhotos(photos, notify, scheduleDate);
                } else if (baseFragment instanceof PassportActivity) {
                    ((PassportActivity) baseFragment).didSelectPhotos(photos, notify, scheduleDate);
                }
            }

            @Override
            public void startDocumentSelectActivity() {
                if (baseFragment instanceof ChatActivity) {
                    ((ChatActivity) baseFragment).startDocumentSelectActivity();
                } else if (baseFragment instanceof PassportActivity) {
                    ((PassportActivity) baseFragment).startDocumentSelectActivity();
                }
            }

            @Override
            public void startMusicSelectActivity() {
                openAudioLayout(true);
            }
        });
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat currentChat = chatActivity.getCurrentChat();
        documentLayout.setMaxSelectedFiles(currentChat != null && !ChatObject.hasAdminRights(currentChat) && currentChat.slowmode_enabled || editingMessageObject != null ? 1 : -1);
    } else {
        documentLayout.setMaxSelectedFiles(maxSelectedPhotos);
        documentLayout.setCanSelectOnlyImageFiles(true);
    }
    if (show) {
        showLayout(documentLayout);
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) PassportActivity(org.telegram.ui.PassportActivity) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

ChatActivity (org.telegram.ui.ChatActivity)41 Paint (android.graphics.Paint)22 TLRPC (org.telegram.tgnet.TLRPC)21 TextView (android.widget.TextView)13 ArrayList (java.util.ArrayList)13 Animator (android.animation.Animator)12 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)12 View (android.view.View)12 TextPaint (android.text.TextPaint)11 AnimatorSet (android.animation.AnimatorSet)10 ObjectAnimator (android.animation.ObjectAnimator)10 ImageView (android.widget.ImageView)10 MessageObject (org.telegram.messenger.MessageObject)10 Bundle (android.os.Bundle)9 ChatObject (org.telegram.messenger.ChatObject)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)8 ValueAnimator (android.animation.ValueAnimator)7 SuppressLint (android.annotation.SuppressLint)7 FrameLayout (android.widget.FrameLayout)6