Search in sources :

Example 11 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method updateAlbumsDropDown.

private void updateAlbumsDropDown() {
    dropDownContainer.removeAllSubItems();
    if (mediaEnabled) {
        ArrayList<MediaController.AlbumEntry> albums;
        if (parentAlert.baseFragment instanceof ChatActivity || parentAlert.avatarPicker == 2) {
            albums = MediaController.allMediaAlbums;
        } else {
            albums = MediaController.allPhotoAlbums;
        }
        dropDownAlbums = new ArrayList<>(albums);
        Collections.sort(dropDownAlbums, (o1, o2) -> {
            if (o1.bucketId == 0 && o2.bucketId != 0) {
                return -1;
            } else if (o1.bucketId != 0 && o2.bucketId == 0) {
                return 1;
            }
            int index1 = albums.indexOf(o1);
            int index2 = albums.indexOf(o2);
            if (index1 > index2) {
                return 1;
            } else if (index1 < index2) {
                return -1;
            } else {
                return 0;
            }
        });
    } else {
        dropDownAlbums = new ArrayList<>();
    }
    if (dropDownAlbums.isEmpty()) {
        dropDown.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    } else {
        dropDown.setCompoundDrawablesWithIntrinsicBounds(null, null, dropDownDrawable, null);
        for (int a = 0, N = dropDownAlbums.size(); a < N; a++) {
            dropDownContainer.addSubItem(10 + a, dropDownAlbums.get(a).bucketName);
        }
    }
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) Paint(android.graphics.Paint)

Example 12 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method openCamera.

private void openCamera(boolean animated) {
    if (cameraView == null || cameraInitAnimation != null || !cameraView.isInitied() || parentAlert.isDismissed()) {
        return;
    }
    if (parentAlert.avatarPicker == 2 || parentAlert.baseFragment instanceof ChatActivity) {
        tooltipTextView.setVisibility(VISIBLE);
    } else {
        tooltipTextView.setVisibility(GONE);
    }
    if (cameraPhotos.isEmpty()) {
        counterTextView.setVisibility(View.INVISIBLE);
        cameraPhotoRecyclerView.setVisibility(View.GONE);
    } else {
        counterTextView.setVisibility(View.VISIBLE);
        cameraPhotoRecyclerView.setVisibility(View.VISIBLE);
    }
    if (parentAlert.commentTextView.isKeyboardVisible() && isFocusable()) {
        parentAlert.commentTextView.closeKeyboard();
    }
    zoomControlView.setVisibility(View.VISIBLE);
    zoomControlView.setAlpha(0.0f);
    cameraPanel.setVisibility(View.VISIBLE);
    cameraPanel.setTag(null);
    animateCameraValues[0] = 0;
    animateCameraValues[1] = itemSize;
    animateCameraValues[2] = itemSize;
    additionCloseCameraY = 0;
    cameraExpanded = true;
    cameraView.setFpsLimit(-1);
    if (animated) {
        setCameraOpenProgress(0);
        cameraAnimationInProgress = true;
        animationIndex = NotificationCenter.getInstance(parentAlert.currentAccount).setAnimationInProgress(animationIndex, null);
        ArrayList<Animator> animators = new ArrayList<>();
        animators.add(ObjectAnimator.ofFloat(this, "cameraOpenProgress", 0.0f, 1.0f));
        animators.add(ObjectAnimator.ofFloat(cameraPanel, View.ALPHA, 1.0f));
        animators.add(ObjectAnimator.ofFloat(counterTextView, View.ALPHA, 1.0f));
        animators.add(ObjectAnimator.ofFloat(cameraPhotoRecyclerView, View.ALPHA, 1.0f));
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                animators.add(ObjectAnimator.ofFloat(flashModeButton[a], View.ALPHA, 1.0f));
                break;
            }
        }
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);
        animatorSet.setDuration(350);
        animatorSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animator) {
                NotificationCenter.getInstance(parentAlert.currentAccount).onAnimationFinish(animationIndex);
                cameraAnimationInProgress = false;
                if (Build.VERSION.SDK_INT >= 21 && cameraView != null) {
                    cameraView.invalidateOutline();
                } else if (cameraView != null) {
                    cameraView.invalidate();
                }
                if (cameraOpened) {
                    parentAlert.delegate.onCameraOpened();
                }
                if (Build.VERSION.SDK_INT >= 21 && cameraView != null) {
                    cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
                }
            }
        });
        animatorSet.start();
    } else {
        setCameraOpenProgress(1.0f);
        cameraPanel.setAlpha(1.0f);
        counterTextView.setAlpha(1.0f);
        cameraPhotoRecyclerView.setAlpha(1.0f);
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                flashModeButton[a].setAlpha(1.0f);
                break;
            }
        }
        parentAlert.delegate.onCameraOpened();
        if (Build.VERSION.SDK_INT >= 21) {
            cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
        }
    }
    cameraOpened = true;
    cameraView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    if (Build.VERSION.SDK_INT >= 19) {
        gridView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    }
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ChatActivity(org.telegram.ui.ChatActivity) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) Paint(android.graphics.Paint)

Example 13 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method onMenuItemClick.

@Override
void onMenuItemClick(int id) {
    if (id == group || id == compress) {
        if (parentAlert.maxSelectedPhotos > 0 && selectedPhotosOrder.size() > 1 && parentAlert.baseFragment instanceof ChatActivity) {
            ChatActivity chatActivity = (ChatActivity) parentAlert.baseFragment;
            TLRPC.Chat chat = chatActivity.getCurrentChat();
            if (chat != null && !ChatObject.hasAdminRights(chat) && chat.slowmode_enabled) {
                AlertsCreator.createSimpleAlert(getContext(), LocaleController.getString("Slowmode", R.string.Slowmode), LocaleController.getString("SlowmodeSendError", R.string.SlowmodeSendError), resourcesProvider).show();
                return;
            }
        }
    }
    if (id == group) {
        if (parentAlert.editingMessageObject == null && parentAlert.baseFragment instanceof ChatActivity && ((ChatActivity) parentAlert.baseFragment).isInScheduleMode()) {
            AlertsCreator.createScheduleDatePickerDialog(getContext(), ((ChatActivity) parentAlert.baseFragment).getDialogId(), (notify, scheduleDate) -> {
                parentAlert.applyCaption();
                parentAlert.delegate.didPressedButton(7, false, notify, scheduleDate, false);
            }, resourcesProvider);
        } else {
            parentAlert.applyCaption();
            parentAlert.delegate.didPressedButton(7, false, true, 0, false);
        }
    } else if (id == compress) {
        if (parentAlert.editingMessageObject == null && parentAlert.baseFragment instanceof ChatActivity && ((ChatActivity) parentAlert.baseFragment).isInScheduleMode()) {
            AlertsCreator.createScheduleDatePickerDialog(getContext(), ((ChatActivity) parentAlert.baseFragment).getDialogId(), (notify, scheduleDate) -> {
                parentAlert.applyCaption();
                parentAlert.delegate.didPressedButton(4, true, notify, scheduleDate, false);
            }, resourcesProvider);
        } else {
            parentAlert.applyCaption();
            parentAlert.delegate.didPressedButton(4, true, true, 0, false);
        }
    } else if (id == open_in) {
        try {
            if (parentAlert.baseFragment instanceof ChatActivity || parentAlert.avatarPicker == 2) {
                Intent videoPickerIntent = new Intent();
                videoPickerIntent.setType("video/*");
                videoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
                videoPickerIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, FileLoader.MAX_FILE_SIZE);
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                Intent chooserIntent = Intent.createChooser(photoPickerIntent, null);
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { videoPickerIntent });
                if (parentAlert.avatarPicker != 0) {
                    parentAlert.baseFragment.startActivityForResult(chooserIntent, 14);
                } else {
                    parentAlert.baseFragment.startActivityForResult(chooserIntent, 1);
                }
            } else {
                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                photoPickerIntent.setType("image/*");
                if (parentAlert.avatarPicker != 0) {
                    parentAlert.baseFragment.startActivityForResult(photoPickerIntent, 14);
                } else {
                    parentAlert.baseFragment.startActivityForResult(photoPickerIntent, 1);
                }
            }
            parentAlert.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else if (id >= 10) {
        selectedAlbumEntry = dropDownAlbums.get(id - 10);
        if (selectedAlbumEntry == galleryAlbumEntry) {
            dropDown.setText(LocaleController.getString("ChatGallery", R.string.ChatGallery));
        } else {
            dropDown.setText(selectedAlbumEntry.bucketName);
        }
        adapter.notifyDataSetChanged();
        cameraAttachAdapter.notifyDataSetChanged();
        layoutManager.scrollToPositionWithOffset(0, -gridView.getPaddingTop() + AndroidUtilities.dp(7));
    }
}
Also used : Rect(android.graphics.Rect) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) Keep(androidx.annotation.Keep) ApplicationLoader(org.telegram.messenger.ApplicationLoader) MediaStore(android.provider.MediaStore) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Canvas(android.graphics.Canvas) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) RecyclerView(androidx.recyclerview.widget.RecyclerView) Utilities(org.telegram.messenger.Utilities) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ExifInterface(androidx.exifinterface.media.ExifInterface) FileLoader(org.telegram.messenger.FileLoader) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) Path(android.graphics.Path) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) MediaMetadataRetriever(android.media.MediaMetadataRetriever) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PhotoAttachPermissionCell(org.telegram.ui.Cells.PhotoAttachPermissionCell) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) PhotoViewer(org.telegram.ui.PhotoViewer) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) PhotoAttachCameraCell(org.telegram.ui.Cells.PhotoAttachCameraCell) R(org.telegram.messenger.R) PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) TextureView(android.view.TextureView) FileLog(org.telegram.messenger.FileLog) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) CameraView(org.telegram.messenger.camera.CameraView) Bitmap(android.graphics.Bitmap) LinearSmoothScroller(androidx.recyclerview.widget.LinearSmoothScroller) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) ImageReceiver(org.telegram.messenger.ImageReceiver) CameraController(org.telegram.messenger.camera.CameraController) Collections(java.util.Collections) ValueAnimator(android.animation.ValueAnimator) Camera(android.hardware.Camera) ChatActivity(org.telegram.ui.ChatActivity) Intent(android.content.Intent) TLRPC(org.telegram.tgnet.TLRPC)

Example 14 with ChatActivity

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

the class ChatAttachAlertPhotoLayout method didReceivedNotification.

@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.albumsDidLoad) {
        if (adapter != null) {
            if (parentAlert.baseFragment instanceof ChatActivity || parentAlert.avatarPicker == 2) {
                galleryAlbumEntry = MediaController.allMediaAlbumEntry;
            } else {
                galleryAlbumEntry = MediaController.allPhotosAlbumEntry;
            }
            if (selectedAlbumEntry == null) {
                selectedAlbumEntry = galleryAlbumEntry;
            } else {
                for (int a = 0; a < MediaController.allMediaAlbums.size(); a++) {
                    MediaController.AlbumEntry entry = MediaController.allMediaAlbums.get(a);
                    if (entry.bucketId == selectedAlbumEntry.bucketId && entry.videoOnly == selectedAlbumEntry.videoOnly) {
                        selectedAlbumEntry = entry;
                        break;
                    }
                }
            }
            loading = false;
            progressView.showTextView();
            adapter.notifyDataSetChanged();
            cameraAttachAdapter.notifyDataSetChanged();
            if (!selectedPhotosOrder.isEmpty() && galleryAlbumEntry != null) {
                for (int a = 0, N = selectedPhotosOrder.size(); a < N; a++) {
                    Integer imageId = (Integer) selectedPhotosOrder.get(a);
                    Object currentEntry = selectedPhotos.get(imageId);
                    MediaController.PhotoEntry entry = galleryAlbumEntry.photosByIds.get(imageId);
                    if (entry != null) {
                        if (currentEntry instanceof MediaController.PhotoEntry) {
                            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) currentEntry;
                            entry.copyFrom(photoEntry);
                        }
                        selectedPhotos.put(imageId, entry);
                    }
                }
            }
            updateAlbumsDropDown();
        }
    } else if (id == NotificationCenter.cameraInitied) {
        checkCamera(false);
    }
}
Also used : MediaController(org.telegram.messenger.MediaController) ChatActivity(org.telegram.ui.ChatActivity) MessageObject(org.telegram.messenger.MessageObject) ChatObject(org.telegram.messenger.ChatObject) Paint(android.graphics.Paint)

Example 15 with ChatActivity

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

the class ChatAttachAlert method sendPressed.

private void sendPressed(boolean notify, int scheduleDate) {
    if (buttonPressed) {
        return;
    }
    if (baseFragment instanceof ChatActivity) {
        ChatActivity chatActivity = (ChatActivity) baseFragment;
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (user != null || ChatObject.isChannel(chat) && chat.megagroup || !ChatObject.isChannel(chat)) {
            MessagesController.getNotificationsSettings(currentAccount).edit().putBoolean("silent_" + chatActivity.getDialogId(), !notify).commit();
        }
    }
    applyCaption();
    buttonPressed = true;
    delegate.didPressedButton(7, true, notify, scheduleDate, false);
}
Also used : ChatActivity(org.telegram.ui.ChatActivity) TLRPC(org.telegram.tgnet.TLRPC)

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