导航菜单

页面标题

页面副标题

Plus 12 v10.13.1.1 - PhotoViewer.java 源代码

正在查看: Plus 12 v10.13.1.1 应用的 PhotoViewer.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.telegram.ui;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Insets;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RenderNode;
import android.graphics.Shader;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.Transition;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.transition.TransitionValues;
import android.util.FloatProperty;
import android.util.Pair;
import android.util.Property;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.SurfaceView;
import android.view.TextureView;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewPropertyAnimator;
import android.view.ViewTreeObserver;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.OverScroller;
import android.widget.Scroller;
import android.widget.SeekBar;
import android.widget.Space;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import androidx.annotation.Keep;
import androidx.collection.ArrayMap;
import androidx.collection.LongSparseArray;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.ColorUtils;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import androidx.core.widget.NestedScrollView;
import androidx.dynamicanimation.animation.DynamicAnimation;
import androidx.dynamicanimation.animation.FloatValueHolder;
import androidx.dynamicanimation.animation.SpringAnimation;
import androidx.dynamicanimation.animation.SpringForce;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScrollerEnd;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.face.FaceDetector;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.telegram.messenger.AccountInstance;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.AnimationNotificationsLocker;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.Bitmaps;
import org.telegram.messenger.BotWebViewVibrationEffect;
import org.telegram.messenger.BringAppForegroundService;
import org.telegram.messenger.BuildVars;
import org.telegram.messenger.ChatObject;
import org.telegram.messenger.DialogObject;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.DownloadController;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.ImageLoader;
import org.telegram.messenger.ImageLocation;
import org.telegram.messenger.ImageReceiver;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MediaController;
import org.telegram.messenger.MediaDataController;
import org.telegram.messenger.MessageObject;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.MessagesStorage;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.PlusUtils;
import org.telegram.messenger.R;
import org.telegram.messenger.SecureDocument;
import org.telegram.messenger.SendMessagesHelper;
import org.telegram.messenger.SharedConfig;
import org.telegram.messenger.TranslateController;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.messenger.VideoEditedInfo;
import org.telegram.messenger.WebFile;
import org.telegram.messenger.camera.Size;
import org.telegram.messenger.translator.BaseTranslationEngine;
import org.telegram.messenger.utils.BitmapsCache;
import org.telegram.messenger.video.VideoPlayerRewinder;
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLObject;
import org.telegram.tgnet.TLRPC;
import org.telegram.tgnet.tl.TL_stories;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.ActionBar.ActionBarMenuSubItem;
import org.telegram.ui.ActionBar.ActionBarPopupWindow;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.ActionBar.BottomSheet;
import org.telegram.ui.ActionBar.PlusSettings;
import org.telegram.ui.ActionBar.SimpleTextView;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Cells.CheckBoxCell;
import org.telegram.ui.Cells.PhotoPickerPhotoCell;
import org.telegram.ui.Cells.TextSelectionHelper;
import org.telegram.ui.ChatActivity;
import org.telegram.ui.ChooseSpeedLayout;
import org.telegram.ui.Components.AlertsCreator;
import org.telegram.ui.Components.AnimatedEmojiSpan;
import org.telegram.ui.Components.AnimatedFileDrawable;
import org.telegram.ui.Components.AnimatedFloat;
import org.telegram.ui.Components.AnimatedTextView;
import org.telegram.ui.Components.AnimationProperties;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.BlurringShader;
import org.telegram.ui.Components.Bulletin;
import org.telegram.ui.Components.BulletinFactory;
import org.telegram.ui.Components.CaptionPhotoViewer;
import org.telegram.ui.Components.ChatAttachAlert;
import org.telegram.ui.Components.CheckBox;
import org.telegram.ui.Components.ClippingImageView;
import org.telegram.ui.Components.CombinedDrawable;
import org.telegram.ui.Components.Crop.CropAreaView;
import org.telegram.ui.Components.Crop.CropTransform;
import org.telegram.ui.Components.CubicBezierInterpolator;
import org.telegram.ui.Components.FilterGLThread;
import org.telegram.ui.Components.FilterShaders;
import org.telegram.ui.Components.FloatSeekBarAccessibilityDelegate;
import org.telegram.ui.Components.Forum.ForumUtilities;
import org.telegram.ui.Components.GestureDetector2;
import org.telegram.ui.Components.GroupedPhotosListView;
import org.telegram.ui.Components.HideViewAfterAnimation;
import org.telegram.ui.Components.ImageUpdater;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.LinkSpanDrawable;
import org.telegram.ui.Components.LoadingDrawable;
import org.telegram.ui.Components.OptionsSpeedIconDrawable;
import org.telegram.ui.Components.Paint.Views.LPhotoPaintView;
import org.telegram.ui.Components.Paint.Views.MaskPaintView;
import org.telegram.ui.Components.Paint.Views.PaintCancelView;
import org.telegram.ui.Components.Paint.Views.PaintDoneView;
import org.telegram.ui.Components.Paint.Views.PaintWeightChooserView;
import org.telegram.ui.Components.Paint.Views.StickerCutOutBtn;
import org.telegram.ui.Components.Paint.Views.StickerMakerBackgroundView;
import org.telegram.ui.Components.Paint.Views.StickerMakerView;
import org.telegram.ui.Components.PaintingOverlay;
import org.telegram.ui.Components.PhotoCropView;
import org.telegram.ui.Components.PhotoFilterView;
import org.telegram.ui.Components.PhotoViewerWebView;
import org.telegram.ui.Components.PickerBottomLayoutViewer;
import org.telegram.ui.Components.PipVideoOverlay;
import org.telegram.ui.Components.PlayPauseDrawable;
import org.telegram.ui.Components.Premium.LimitReachedBottomSheet;
import org.telegram.ui.Components.QuoteSpan;
import org.telegram.ui.Components.RLottieDrawable;
import org.telegram.ui.Components.RadialProgressView;
import org.telegram.ui.Components.Reactions.ReactionsLayoutInBubble;
import org.telegram.ui.Components.RecyclerListView;
import org.telegram.ui.Components.ScaleStateListAnimator;
import org.telegram.ui.Components.ShareAlert;
import org.telegram.ui.Components.SizeNotifierFrameLayoutPhoto;
import org.telegram.ui.Components.SpeedIconDrawable;
import org.telegram.ui.Components.StickersAlert;
import org.telegram.ui.Components.TextViewSwitcher;
import org.telegram.ui.Components.ThanosEffect;
import org.telegram.ui.Components.Tooltip;
import org.telegram.ui.Components.TranslateAlert2;
import org.telegram.ui.Components.URLSpanReplacement;
import org.telegram.ui.Components.UndoView;
import org.telegram.ui.Components.VideoCompressButton;
import org.telegram.ui.Components.VideoEditTextureView;
import org.telegram.ui.Components.VideoForwardDrawable;
import org.telegram.ui.Components.VideoPlayer;
import org.telegram.ui.Components.VideoPlayerSeekBar;
import org.telegram.ui.Components.VideoSeekPreviewImage;
import org.telegram.ui.Components.VideoTimelinePlayView;
import org.telegram.ui.Components.ViewHelper;
import org.telegram.ui.Components.spoilers.SpoilersTextView;
import org.telegram.ui.ContentPreviewViewer;
import org.telegram.ui.PhotoViewer;
import org.telegram.ui.Stories.DarkThemeResourceProvider;
import org.telegram.ui.Stories.recorder.CaptionContainerView;
import org.telegram.ui.Stories.recorder.KeyboardNotifier;
import org.telegram.ui.Stories.recorder.StoryEntry;

@SuppressLint({"WrongConstant"})
public class PhotoViewer implements NotificationCenter.NotificationCenterDelegate, GestureDetector2.OnGestureListener, GestureDetector2.OnDoubleTapListener {

    @SuppressLint({"StaticFieldLeak"})
    public static volatile PhotoViewer Instance;
    public static volatile PhotoViewer PipInstance;
    public static final Property<VideoPlayerControlFrameLayout, Float> VPC_PROGRESS;
    public static DecelerateInterpolator decelerateInterpolator;
    public static Drawable[] progressDrawables;
    public static Paint progressPaint;
    public boolean ALLOW_USE_SURFACE;
    public final Property<View, Float> FLASH_VIEW_VALUE;
    public int aboutToSwitchTo;
    public ActionBar actionBar;
    public AnimatorSet actionBarAnimator;
    public PhotoViewerActionBarContainer actionBarContainer;
    public Map<View, Boolean> actionBarItemsVisibility;
    public boolean actionBarWasShownBeforeByEnd;
    public Context activityContext;
    public ActionBarMenuSubItem allMediaItem;
    public boolean allowOrder;
    public boolean allowShare;
    public boolean allowShowFullscreenButton;
    public float animateToMirror;
    public float animateToRotate;
    public float animateToScale;
    public float animateToX;
    public float animateToY;
    public ClippingImageView animatingImageView;
    public Runnable animationEndRunnable;
    public int animationInProgress;
    public long animationStartTime;
    public float animationValue;
    public float[][] animationValues;
    public boolean applying;
    public AspectRatioFrameLayout aspectRatioFrameLayout;
    public boolean attachedToWindow;
    public long audioFramesSize;
    public float avatarStartProgress;
    public long avatarStartTime;
    public final ArrayList<TLRPC.Photo> avatarsArr;
    public long avatarsDialogId;
    public BackgroundDrawable backgroundDrawable;
    public int barQualityValue;
    public Paint bitmapPaint;
    public volatile int bitrate;
    public Paint blackPaint;
    public final AnimatedFloat blurAlpha;
    public RectF blurBounds;
    public BlurringShader.BlurManager blurManager;
    public LinearGradient bottomFancyShadow;
    public Matrix bottomFancyShadowMatrix;
    public Paint bottomFancyShadowPaint;
    public FrameLayout bottomLayout;
    public LinearLayout btnLayout;
    public boolean canDragDown;
    public boolean canEditAvatar;
    public boolean canZoom;
    public ObjectAnimator captionAnimator;
    public FrameLayout captionContainer;
    public String captionDetectedLanguage;
    public CaptionPhotoViewer captionEdit;
    public FrameLayout captionEditContainer;
    public CharSequence captionForAllMedia;
    public boolean captionHwLayerEnabled;
    public CaptionScrollView captionScrollView;
    public CaptionTextViewSwitcher captionTextViewSwitcher;
    public boolean captionTranslated;
    public long captureFrameAtTime;
    public long captureFrameReadyAtTime;
    public BlurringShader.ThumbBlurer centerBlur;
    public ImageReceiver centerImage;
    public AnimatedFloat[] centerImageInsideBlur;
    public boolean centerImageIsVideo;
    public Matrix centerImageTransform;
    public boolean centerImageTransformLocked;
    public AnimatorSet changeModeAnimation;
    public TextureView changedTextureView;
    public boolean changingPage;
    public boolean changingTextureView;
    public CheckBox checkImageView;
    public ChooseSpeedLayout chooseSpeedLayout;
    public int classGuid;
    public Path clipFancyShadows;
    public float clippingImageProgress;
    public boolean closePhotoAfterSelect;
    public VideoCompressButton compressItem;
    public volatile int compressionsCount;
    public FrameLayoutDrawer containerView;
    public PhotoCountView countView;
    public boolean cropInitied;
    public ImageView cropItem;
    public CropTransform cropTransform;
    public int currentAccount;
    public AnimatedFileDrawable currentAnimation;
    public ImageLocation currentAvatarLocation;
    public Bitmap currentBitmap;
    public TLRPC.BotInlineResult currentBotInlineResult;
    public long currentDialogId;
    public int currentEditMode;
    public ImageLocation currentFileLocation;
    public ImageLocation currentFileLocationVideo;
    public String[] currentFileNames;
    public String currentFilterQuery;
    public ReactionsLayoutInBubble.VisibleReaction currentFilterTag;
    public boolean currentFiltered;
    public String currentImageFaceKey;
    public int currentImageHasFace;
    public String currentImagePath;
    public int currentIndex;
    public AnimatorSet currentListViewAnimation;
    public Runnable currentLoadingVideoRunnable;
    public MessageObject currentMessageObject;
    public TLRPC.PageBlock currentPageBlock;
    public float currentPanTranslationY;
    public String currentPathObject;
    public PlaceProviderObject currentPlaceObject;
    public Uri currentPlayingVideoFile;
    public SecureDocument currentSecureDocument;
    public String currentSubtitle;
    public ImageReceiver.BitmapHolder currentThumb;
    public boolean currentVideoFinishedLoading;
    public float currentVideoSpeed;
    public Utilities.Callback2<String, TLRPC.InputDocument> customStickerHandler;
    public CharSequence customTitle;
    public BlurButton cutOutBtn;
    public MessagesController.DialogPhotos dialogPhotos;
    public boolean disableShowCheck;
    public boolean discardTap;
    public TextView docInfoTextView;
    public TextView docNameTextView;
    public TextView doneButtonFullWidth;
    public boolean doneButtonPressed;
    public boolean dontAutoPlay;
    public boolean dontChangeCaptionPosition;
    public boolean dontResetZoomOnFirstLayout;
    public boolean doubleTap;
    public boolean doubleTapEnabled;
    public float dragY;
    public boolean draggingDown;
    public boolean[] drawPressedDrawable;
    public ActionBarMenuItem editItem;
    public EditState editState;
    public boolean editing;
    public PickerBottomLayoutViewer editorDoneLayout;
    public boolean[] endReached;
    public long endTime;
    public BlurButton eraseBtn;
    public long estimatedDuration;
    public long estimatedSize;
    public ImageView exitFullscreenButton;
    public boolean fancyShadows;
    public boolean firstAnimationDelay;
    public boolean firstFrameRendered;
    public FirstFrameView firstFrameView;
    public AnimatorSet flashAnimator;
    public View flashView;
    public boolean fromCamera;
    public ImageView[] fullscreenButton;
    public int fullscreenedByButton;
    public GestureDetector2 gestureDetector;
    public GroupedPhotosListView groupedPhotosListView;
    public boolean hasCaptionForAllMedia;
    public Runnable hideActionBarRunnable;
    public PlaceProviderObject hideAfterAnimation;
    public UndoView hintView;
    public Rect hitRect;
    public boolean ignoreDidSetImage;
    public RectF imageBounds;
    public Matrix imageBoundsMatrix;
    public float[] imageBoundsPoints;
    public AnimatorSet imageMoveAnimation;
    public final ArrayList<MessageObject> imagesArr;
    public final ArrayList<Object> imagesArrLocals;
    public final ArrayList<ImageLocation> imagesArrLocations;
    public final ArrayList<Long> imagesArrLocationsSizes;
    public final ArrayList<ImageLocation> imagesArrLocationsVideo;
    public final ArrayList<TLRPC.Message> imagesArrMessages;
    public final ArrayList<MessageObject> imagesArrTemp;
    public final SparseArray<MessageObject>[] imagesByIds;
    public final SparseArray<MessageObject>[] imagesByIdsTemp;
    public boolean inBubbleMode;
    public boolean inPreview;
    public VideoPlayer injectingVideoPlayer;
    public SurfaceTexture injectingVideoPlayerSurface;
    public float inlineOutAnimationProgress;
    public final Rect insets;
    public DecelerateInterpolator interpolator;
    public boolean invalidCoords;
    public boolean isActionBarVisible;
    public boolean isCurrentVideo;
    public boolean isDocumentsPicker;
    public boolean isEmbedVideo;
    public boolean isEvent;
    public boolean isFirstLoading;
    public volatile boolean isH264Video;
    public boolean isInline;
    public boolean isPhotosListViewVisible;
    public boolean isPlaying;
    public boolean isStreaming;
    public boolean isVisible;
    public boolean isVisibleOrAnimating;
    public LinearLayout itemsLayout;
    public boolean keepScreenOnFlagSet;
    public int keyboardSize;
    public long lastBufferedPositionCheck;
    public boolean lastCaptionTranslating;
    public String lastControlFrameDuration;
    public Bitmap lastFrameBitmap;
    public ImageView lastFrameImageView;
    public int lastImageId;
    public long lastPhotoSetTime;
    public long lastSaveTime;
    public CharSequence lastTitle;
    public BlurringShader.ThumbBlurer leftBlur;
    public MediaController.CropState leftCropState;
    public CropTransform leftCropTransform;
    public ImageReceiver leftImage;
    public boolean leftImageIsVideo;
    public PaintingOverlay leftPaintingOverlay;
    public Bulletin limitBulletin;
    public boolean loadInitialVideo;
    public boolean loadingMoreImages;
    public Runnable longPressRunnable;
    public float longPressX;
    public boolean manuallyPaused;
    public MaskPaintView maskPaintView;
    public boolean maskPaintViewEraser;
    public boolean maskPaintViewShuttingDown;
    public int maskPaintViewTouched;
    public StickersAlert masksAlert;
    public ActionBarMenuItem masksItem;
    public int maxSelectedPhotos;
    public float maxX;
    public float maxY;
    public ActionBarMenu menu;
    public ActionBarMenuItem menuItem;
    public OptionsSpeedIconDrawable menuItemIcon;
    public long mergeDialogId;
    public float minX;
    public float minY;
    public AnimatorSet miniProgressAnimator;
    public Runnable miniProgressShowRunnable;
    public RadialProgressView miniProgressView;
    public float mirror;
    public ImageView mirrorItem;
    public float moveStartX;
    public float moveStartY;
    public boolean moving;
    public ImageView muteItem;
    public boolean muteItemAvailable;
    public boolean muteVideo;
    public View navigationBar;
    public int navigationBarHeight;
    public boolean needCaptionLayout;
    public long needCaptureFrameReadyAtTime;
    public boolean needSearchImageInArr;
    public boolean needShowOnReady;
    public Runnable onUserLeaveHintListener;
    public boolean openedFromProfile;
    public boolean openedFullScreenVideo;
    public boolean opennedFromMedia;
    public OrientationEventListener orientationEventListener;
    public volatile int originalBitrate;
    public volatile int originalHeight;
    public long originalSize;
    public volatile int originalWidth;
    public BlurButton outlineBtn;
    public boolean padImageForHorizontalInsets;
    public PageBlocksAdapter pageBlocksAdapter;
    public ImageView paintItem;
    public AnimatorSet paintKeyboardAnimator;
    public KeyboardNotifier paintKeyboardNotifier;
    public int paintViewTouched;
    public PaintingOverlay paintingOverlay;
    public Activity parentActivity;
    public ChatAttachAlert parentAlert;
    public ChatActivity parentChatActivity;
    public BaseFragment parentFragment;
    public PhotoCropView photoCropView;
    public PhotoFilterView photoFilterView;
    public LPhotoPaintView photoPaintView;
    public PhotoProgressView[] photoProgressViews;
    public FrameLayout photoQualityLayout;
    public int photoQualityLayoutSize;
    public PhotoViewerWebView photoViewerWebView;
    public CounterView photosCounterView;
    public FrameLayout pickerView;
    public ImageView pickerViewSendButton;
    public Drawable pickerViewSendDrawable;
    public float pinchCenterX;
    public float pinchCenterY;
    public float pinchStartAngle;
    public float pinchStartDistance;
    public float pinchStartRotate;
    public float pinchStartScale;
    public float pinchStartX;
    public float pinchStartY;
    public boolean pipAnimationInProgress;
    public boolean pipAvailable;
    public ActionBarMenuItem pipItem;
    public int[] pipPosition;
    public boolean pipVideoOverlayAnimateFlag;
    public PhotoViewerProvider placeProvider;
    public View playButtonAccessibilityOverlay;
    public boolean playGifAsVideo;
    public boolean playerAutoStarted;
    public boolean playerInjected;
    public boolean playerLooping;
    public boolean playerWasPlaying;
    public boolean playerWasReady;
    public GradientDrawable[] pressedDrawable;
    public float[] pressedDrawableAlpha;
    public int prevOrientation;
    public int previousCompression;
    public boolean previousCropMirrored;
    public int previousCropOrientation;
    public float previousCropPh;
    public float previousCropPw;
    public float previousCropPx;
    public float previousCropPy;
    public float previousCropRotation;
    public float previousCropScale;
    public boolean previousHasTransform;
    public RadialProgressView progressView;
    public SeekBar qualityBar;
    public QualityChooseView qualityChooseView;
    public AnimatorSet qualityChooseViewAnimation;
    public PickerBottomLayoutViewer qualityPicker;
    public RenderNode renderNode;
    public TLRPC.Document replacedSticker;
    public boolean requestingPreview;
    public TextView resetButton;
    public Theme.ResourcesProvider resourcesProvider;
    public BlurButton restoreBtn;
    public volatile int resultHeight;
    public volatile int resultWidth;
    public BlurringShader.ThumbBlurer rightBlur;
    public MediaController.CropState rightCropState;
    public CropTransform rightCropTransform;
    public ImageReceiver rightImage;
    public boolean rightImageIsVideo;
    public PaintingOverlay rightPaintingOverlay;
    public float rotate;
    public ImageView rotateItem;
    public int rotationValue;
    public float savedRotation;
    public float savedScale;
    public SavedState savedState;
    public float savedTx;
    public float savedTy;
    public ArrayMap<String, SavedVideoPosition> savedVideoPositions;
    public float scale;
    public Scroller scroller;
    public final ArrayList<SecureDocument> secureDocuments;
    public float seekToProgressPending;
    public float seekToProgressPending2;
    public volatile int selectedCompression;
    public ArrayList<String> selectedEmojis;
    public ListAdapter selectedPhotosAdapter;
    public SelectedPhotosListView selectedPhotosListView;
    public ActionBarMenuItem sendItem;
    public ActionBarMenuItem sendNoQuoteItem;
    public int sendPhotoType;
    public ActionBarPopupWindow.ActionBarPopupWindowLayout sendPopupLayout;
    public ActionBarPopupWindow sendPopupWindow;
    public ImageUpdater.AvatarFor setAvatarFor;
    public Runnable setLoadingRunnable;
    public BlurringShader.StoryBlurDrawer shadowBlurer;
    public int sharedMediaType;
    public float shiftDp;
    public String shouldSavePositionForCurrentVideo;
    public String shouldSavePositionForCurrentVideoShortTerm;
    public PlaceProviderObject showAfterAnimation;
    public boolean shownControlsByEnd;
    public ImageReceiver sideImage;
    public boolean skipFirstBufferingProgress;
    public boolean skipLastFrameDraw;
    public int slideshowMessageId;
    public ActionBarPopupWindow.GapView speedGap;
    public ActionBarMenuSubItem speedItem;
    public int startOffset;
    public long startTime;
    public long startedPlayTime;
    public boolean stickerEmpty;
    public boolean stickerEmptySent;
    public StickerMakerBackgroundView stickerMakerBackgroundView;
    public StickerMakerView stickerMakerView;
    public boolean streamingAlertShown;
    public Paint surfaceBlackoutPaint;
    public TextureView.SurfaceTextureListener surfaceTextureListener;
    public int switchImageAfterAnimation;
    public Runnable switchToInlineRunnable;
    public boolean switchingInlineMode;
    public int switchingToIndex;
    public int switchingToMode;
    public int[] tempInt;
    public TextSelectionHelper.SimpleTextSelectionHelper textSelectionHelper;
    public ImageView textureImageView;
    public boolean textureUploaded;
    public Tooltip tooltip;
    public LinearGradient topFancyShadow;
    public Matrix topFancyShadowMatrix;
    public Paint topFancyShadowPaint;
    public long topicId;
    public int totalImagesCount;
    public int totalImagesCountMerge;
    public int touchSlop;
    public long transitionAnimationStartTime;
    public AnimationNotificationsLocker transitionNotificationLocker;
    public float translateY;
    public ValueAnimator translateYAnimator;
    public String translationChatLang;
    public float translationX;
    public float translationY;
    public boolean tryStartRequestPreviewOnFinish;
    public ImageView tuneItem;
    public TextView tvQuality;
    public BlurButton undoBtn;
    public final Runnable updateContainerFlagsRunnable;
    public Runnable updateProgressRunnable;
    public boolean usedSurfaceView;
    public VelocityTracker velocityTracker;
    public TextView videoAvatarTooltip;
    public volatile boolean videoConvertSupported;
    public float videoCrossfadeAlpha;
    public long videoCrossfadeAlphaLastTime;
    public boolean videoCrossfadeStarted;
    public float videoCutEnd;
    public float videoCutStart;
    public float videoDuration;
    public VideoForwardDrawable videoForwardDrawable;
    public Bitmap videoFrameBitmap;
    public Paint videoFrameBitmapPaint;
    public int videoFramerate;
    public long videoFramesSize;
    public int videoHeight;
    public Runnable videoPlayRunnable;
    public VideoPlayer videoPlayer;
    public Animator videoPlayerControlAnimator;
    public VideoPlayerControlFrameLayout videoPlayerControlFrameLayout;
    public boolean videoPlayerControlVisible;
    public int[] videoPlayerCurrentTime;
    public VideoPlayerRewinder videoPlayerRewinder;
    public VideoPlayerSeekBar videoPlayerSeekbar;
    public View videoPlayerSeekbarView;
    public SimpleTextView videoPlayerTime;
    public int[] videoPlayerTotalTime;
    public VideoSeekPreviewImage videoPreviewFrame;
    public AnimatorSet videoPreviewFrameAnimation;
    public MessageObject videoPreviewMessageObject;
    public boolean videoSizeSet;
    public SurfaceView videoSurfaceView;
    public TextureView videoTextureView;
    public ObjectAnimator videoTimelineAnimator;
    public VideoTimelinePlayView videoTimelineView;
    public FrameLayout videoTimelineViewContainer;
    public int videoWidth;
    public AlertDialog visibleDialog;
    public int waitingForDraw;
    public int waitingForFirstTextureUpload;
    public boolean wasCountViewShown;
    public boolean wasLayout;
    public boolean wasRotated;
    public WindowManager.LayoutParams windowLayoutParams;
    public FrameLayout windowView;
    public boolean zoomAnimation;
    public boolean zooming;

    public static class EmptyPhotoViewerProvider implements PhotoViewerProvider {
        @Override
        public boolean allowCaption() {
            return true;
        }

        @Override
        public boolean allowSendingSubmenu() {
            return true;
        }

        @Override
        public boolean canCaptureMorePhotos() {
            return true;
        }

        @Override
        public boolean canLoadMoreAvatars() {
            return PhotoViewerProvider.CC.$default$canLoadMoreAvatars(this);
        }

        @Override
        public boolean canReplace(int index) {
            return false;
        }

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

        @Override
        public boolean cancelButtonPressed() {
            return true;
        }

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

        @Override
        public void deleteImageAtIndex(int index) {
        }

        @Override
        public String getDeleteMessageString() {
            return null;
        }

        @Override
        public MessageObject getEditingMessageObject() {
            return null;
        }

        @Override
        public int getPhotoIndex(int index) {
            return -1;
        }

        @Override
        public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
            return null;
        }

        @Override
        public int getSelectedCount() {
            return 0;
        }

        @Override
        public HashMap<Object, Object> getSelectedPhotos() {
            return null;
        }

        @Override
        public ArrayList<Object> getSelectedPhotosOrder() {
            return null;
        }

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

        @Override
        public int getTotalImageCount() {
            return -1;
        }

        @Override
        public boolean isPhotoChecked(int index) {
            return false;
        }

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

        @Override
        public void needAddMorePhotos() {
        }

        @Override
        public void onApplyCaption(CharSequence caption) {
        }

        @Override
        public void onClose() {
        }

        @Override
        public boolean onDeletePhoto(int i) {
            return PhotoViewerProvider.CC.$default$onDeletePhoto(this, i);
        }

        @Override
        public void onEditModeChanged(boolean z) {
            PhotoViewerProvider.CC.$default$onEditModeChanged(this, z);
        }

        @Override
        public void onOpen() {
        }

        @Override
        public void onPreClose() {
            PhotoViewerProvider.CC.$default$onPreClose(this);
        }

        @Override
        public void onPreOpen() {
            PhotoViewerProvider.CC.$default$onPreOpen(this);
        }

        @Override
        public void onReleasePlayerBeforeClose(int i) {
            PhotoViewerProvider.CC.$default$onReleasePlayerBeforeClose(this, i);
        }

        @Override
        public void openPhotoForEdit(String file, String thumb, boolean isVideo) {
        }

        @Override
        public void replaceButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
        }

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

        @Override
        public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
        }

        @Override
        public int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) {
            return -1;
        }

        @Override
        public int setPhotoUnchecked(Object photoEntry) {
            return -1;
        }

        @Override
        public void updatePhotoAtIndex(int index) {
        }

        @Override
        public void willHidePhotoViewer() {
        }

        @Override
        public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
        }
    }

    public interface PageBlocksAdapter {
        TLRPC.PageBlock get(int index);

        List<TLRPC.PageBlock> getAll();

        CharSequence getCaption(int index);

        File getFile(int index);

        TLRPC.PhotoSize getFileLocation(TLObject media, int[] size);

        String getFileName(int index);

        int getItemsCount();

        TLObject getMedia(int index);

        Object getParentObject();

        boolean isHardwarePlayer(int index);

        boolean isVideo(int index);

        void updateSlideshowCell(TLRPC.PageBlock currentPageBlock);
    }

    public interface PhotoViewerProvider {

        public final class CC {
            public static boolean $default$canLoadMoreAvatars(PhotoViewerProvider photoViewerProvider) {
                return true;
            }

            public static boolean $default$onDeletePhoto(PhotoViewerProvider photoViewerProvider, int i) {
                return true;
            }

            public static void $default$onEditModeChanged(PhotoViewerProvider photoViewerProvider, boolean z) {
            }

            public static void $default$onPreClose(PhotoViewerProvider photoViewerProvider) {
            }

            public static void $default$onPreOpen(PhotoViewerProvider photoViewerProvider) {
            }

            public static void $default$onReleasePlayerBeforeClose(PhotoViewerProvider photoViewerProvider, int i) {
            }
        }

        boolean allowCaption();

        boolean allowSendingSubmenu();

        boolean canCaptureMorePhotos();

        boolean canLoadMoreAvatars();

        boolean canReplace(int index);

        boolean canScrollAway();

        boolean cancelButtonPressed();

        boolean closeKeyboard();

        void deleteImageAtIndex(int index);

        String getDeleteMessageString();

        MessageObject getEditingMessageObject();

        int getPhotoIndex(int index);

        PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview);

        int getSelectedCount();

        HashMap<Object, Object> getSelectedPhotos();

        ArrayList<Object> getSelectedPhotosOrder();

        ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);

        int getTotalImageCount();

        boolean isPhotoChecked(int index);

        boolean loadMore();

        void needAddMorePhotos();

        void onApplyCaption(CharSequence caption);

        void onClose();

        boolean onDeletePhoto(int index);

        void onEditModeChanged(boolean isEditMode);

        void onOpen();

        void onPreClose();

        void onPreOpen();

        void onReleasePlayerBeforeClose(int currentIndex);

        void openPhotoForEdit(String file, String thumb, boolean isVideo);

        void replaceButtonPressed(int index, VideoEditedInfo videoEditedInfo);

        boolean scaleToFill();

        void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument);

        int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo);

        int setPhotoUnchecked(Object photoEntry);

        void updatePhotoAtIndex(int index);

        void willHidePhotoViewer();

        void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
    }

    public static class PlaceProviderObject {
        public ClippingImageView animatingImageView;
        public int animatingImageViewYOffset;
        public boolean canEdit;
        public int clipBottomAddition;
        public int clipTopAddition;
        public long dialogId;
        public ImageReceiver imageReceiver;
        public boolean isEvent;
        public View parentView;
        public int[] radius;
        public long size;
        public int starOffset;
        public ImageReceiver.BitmapHolder thumb;
        public int viewX;
        public int viewY;
        public float scale = 1.0f;
        public boolean allowTakeAnimation = true;
    }

    public static void m6697$$Nest$mupdateCaptionTranslated(PhotoViewer photoViewer) {
        photoViewer.updateCaptionTranslated();
    }

    public static void lambda$sendPressed$52(DialogInterface dialogInterface, int i) {
    }

    public static void lambda$setParentActivity$19() {
    }

    public final boolean enableSwipeToPiP() {
        return false;
    }

    public void onConfigurationChanged(Configuration newConfig) {
    }

    public boolean onDoubleTapEvent(MotionEvent e) {
        return false;
    }

    public void onLongPress(MotionEvent ev) {
    }

    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        return false;
    }

    public void onShowPress(MotionEvent e) {
    }

    public void lambda$new$0() {
        toggleMiniProgressInternal(true);
    }

    public TextureView getVideoTextureView() {
        return this.videoTextureView;
    }

    public boolean isVisibleOrAnimating() {
        return this.isVisibleOrAnimating;
    }

    public SurfaceView getVideoSurfaceView() {
        return this.videoSurfaceView;
    }

    public static class PhotoViewerActionBarContainer extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
        public FrameLayout container;
        public boolean hasSubtitle;
        public int lastHeight;
        public float rightPadding;
        public ValueAnimator rightPaddingAnimator;
        public AnimatorSet subtitleAnimator;
        public AnimatedTextView subtitleTextView;
        public AnimatorSet titleAnimator;
        public FrameLayout titleLayout;
        public SimpleTextView[] titleTextView;

        public PhotoViewerActionBarContainer(Context context) {
            super(context);
            FrameLayout frameLayout = new FrameLayout(context);
            this.container = frameLayout;
            frameLayout.setPadding(AndroidUtilities.dp((AndroidUtilities.isTablet() ? 80 : 72) - 16), 0, 0, 0);
            addView(this.container, LayoutHelper.createFrame(-1, -1, 119));
            FrameLayout frameLayout2 = new FrameLayout(this, context) {
                @Override
                public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                    setPivotY(getMeasuredHeight());
                }
            };
            this.titleLayout = frameLayout2;
            frameLayout2.setPivotX(AndroidUtilities.dp(16.0f));
            this.titleLayout.setPadding(AndroidUtilities.dp(16.0f), 0, 0, 0);
            this.titleLayout.setClipToPadding(false);
            this.container.addView(this.titleLayout, LayoutHelper.createFrame(-1, -1, 119));
            this.titleTextView = new SimpleTextView[2];
            for (int i = 0; i < 2; i++) {
                this.titleTextView[i] = new SimpleTextView(context);
                this.titleTextView[i].setGravity(19);
                this.titleTextView[i].setTextColor(-1);
                this.titleTextView[i].setTextSize(20);
                this.titleTextView[i].setTypeface(AndroidUtilities.bold());
                this.titleTextView[i].setDrawablePadding(AndroidUtilities.dp(4.0f));
                this.titleTextView[i].setScrollNonFitText(true);
                this.titleLayout.addView(this.titleTextView[i], LayoutHelper.createFrame(-1, -2, 19));
            }
            AnimatedTextView animatedTextView = new AnimatedTextView(context, true, false, false);
            this.subtitleTextView = animatedTextView;
            animatedTextView.setAnimationProperties(0.4f, 0L, 320L, CubicBezierInterpolator.EASE_OUT_QUINT);
            this.subtitleTextView.setTextSize(AndroidUtilities.dp(14.0f));
            this.subtitleTextView.setGravity(19);
            this.subtitleTextView.setTextColor(-1);
            this.subtitleTextView.setEllipsizeByGradient(true);
            this.container.addView((View) this.subtitleTextView, (ViewGroup.LayoutParams) LayoutHelper.createFrame(-1, 20.0f, 51, 16.0f, 0.0f, 0.0f, 0.0f));
        }

        public void setTextShadows(boolean applyShadows) {
            this.titleTextView[0].getPaint().setShadowLayer(AndroidUtilities.dpf2(0.66f), 0.0f, 1.0f, applyShadows ? 1912602624 : 0);
            this.titleTextView[1].getPaint().setShadowLayer(AndroidUtilities.dpf2(0.66f), 0.0f, 1.0f, applyShadows ? 1912602624 : 0);
            this.subtitleTextView.getDrawable().setShadowLayer(AndroidUtilities.dpf2(0.66f), 0.0f, 1.0f, applyShadows ? 1912602624 : 0);
        }

        public void setTitle(CharSequence title) {
            this.titleTextView[1].setAlpha(0.0f);
            this.titleTextView[1].setVisibility(8);
            if (!areStringsEqual(this.titleTextView[0].getText(), title)) {
                this.titleTextView[0].resetScrolling();
            }
            this.titleTextView[0].setText(title);
            this.titleTextView[0].setAlpha(1.0f);
            this.titleTextView[0].setTranslationX(0.0f);
            this.titleTextView[0].setTranslationY(0.0f);
        }

        public final boolean areStringsEqual(CharSequence a, CharSequence b) {
            if (a == null && b == null) {
                return true;
            }
            if ((a == null) != (b == null)) {
                return false;
            }
            return TextUtils.equals(a.toString(), b.toString());
        }

        public void setTitleAnimated(CharSequence title, boolean axis, boolean direction) {
            if (areStringsEqual(this.titleTextView[0].getText(), title)) {
                return;
            }
            AnimatorSet animatorSet = this.titleAnimator;
            if (animatorSet != null) {
                animatorSet.cancel();
                this.titleAnimator = null;
            }
            SimpleTextView[] simpleTextViewArr = this.titleTextView;
            simpleTextViewArr[1].copyScrolling(simpleTextViewArr[0]);
            SimpleTextView[] simpleTextViewArr2 = this.titleTextView;
            simpleTextViewArr2[1].setText(simpleTextViewArr2[0].getText());
            this.titleTextView[1].setRightPadding((int) this.rightPadding);
            this.titleTextView[0].resetScrolling();
            this.titleTextView[0].setText(title);
            float dp = AndroidUtilities.dp(8.0f) * (direction ? 1 : -1);
            this.titleTextView[1].setTranslationX(0.0f);
            this.titleTextView[1].setTranslationY(0.0f);
            if (axis) {
                this.titleTextView[0].setTranslationX(0.0f);
                this.titleTextView[0].setTranslationY(-dp);
            } else {
                this.titleTextView[0].setTranslationX(-dp);
                this.titleTextView[0].setTranslationY(0.0f);
            }
            this.titleTextView[0].setAlpha(0.0f);
            this.titleTextView[1].setAlpha(1.0f);
            this.titleTextView[0].setVisibility(0);
            this.titleTextView[1].setVisibility(0);
            ArrayList arrayList = new ArrayList();
            arrayList.add(ObjectAnimator.ofFloat(this.titleTextView[1], (Property<SimpleTextView, Float>) View.ALPHA, 0.0f));
            arrayList.add(ObjectAnimator.ofFloat(this.titleTextView[0], (Property<SimpleTextView, Float>) View.ALPHA, 1.0f));
            arrayList.add(ObjectAnimator.ofFloat(this.titleTextView[1], (Property<SimpleTextView, Float>) (axis ? View.TRANSLATION_Y : View.TRANSLATION_X), dp));
            arrayList.add(ObjectAnimator.ofFloat(this.titleTextView[0], (Property<SimpleTextView, Float>) (axis ? View.TRANSLATION_Y : View.TRANSLATION_X), 0.0f));
            AnimatorSet animatorSet2 = new AnimatorSet();
            this.titleAnimator = animatorSet2;
            animatorSet2.playTogether(arrayList);
            this.titleAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (PhotoViewerActionBarContainer.this.titleAnimator == animation) {
                        PhotoViewerActionBarContainer.this.titleTextView[1].setVisibility(8);
                        PhotoViewerActionBarContainer.this.titleAnimator = null;
                    }
                }
            });
            this.titleAnimator.setDuration(320L);
            this.titleAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
            this.titleAnimator.start();
        }

        public void setSubtitle(CharSequence subtitle) {
            setSubtitle(subtitle, true);
        }

        public void setSubtitle(CharSequence subtitle, boolean animated) {
            boolean z = !TextUtils.isEmpty(subtitle);
            if (z != this.hasSubtitle) {
                this.hasSubtitle = z;
                AnimatorSet animatorSet = this.subtitleAnimator;
                if (animatorSet != null) {
                    animatorSet.cancel();
                }
                Point point = AndroidUtilities.displaySize;
                int dp = AndroidUtilities.dp((z ? 30 : 33) - (point.x > point.y ? 6 : 0));
                if (animated) {
                    ArrayList arrayList = new ArrayList();
                    AnimatedTextView animatedTextView = this.subtitleTextView;
                    Property property = View.ALPHA;
                    float[] fArr = new float[1];
                    fArr[0] = z ? 1.0f : 0.0f;
                    arrayList.add(ObjectAnimator.ofFloat(animatedTextView, (Property<AnimatedTextView, Float>) property, fArr));
                    arrayList.add(ObjectAnimator.ofFloat(this.subtitleTextView, (Property<AnimatedTextView, Float>) View.TRANSLATION_Y, dp));
                    FrameLayout frameLayout = this.titleLayout;
                    Property property2 = View.TRANSLATION_Y;
                    float[] fArr2 = new float[1];
                    fArr2[0] = z ? AndroidUtilities.dp(-12.0f) : 0.0f;
                    arrayList.add(ObjectAnimator.ofFloat(frameLayout, (Property<FrameLayout, Float>) property2, fArr2));
                    FrameLayout frameLayout2 = this.titleLayout;
                    Property property3 = View.SCALE_X;
                    float[] fArr3 = new float[1];
                    fArr3[0] = z ? 0.87f : 1.0f;
                    arrayList.add(ObjectAnimator.ofFloat(frameLayout2, (Property<FrameLayout, Float>) property3, fArr3));
                    FrameLayout frameLayout3 = this.titleLayout;
                    Property property4 = View.SCALE_Y;
                    float[] fArr4 = new float[1];
                    fArr4[0] = z ? 0.87f : 1.0f;
                    arrayList.add(ObjectAnimator.ofFloat(frameLayout3, (Property<FrameLayout, Float>) property4, fArr4));
                    AnimatorSet animatorSet2 = new AnimatorSet();
                    this.subtitleAnimator = animatorSet2;
                    animatorSet2.playTogether(arrayList);
                    this.subtitleAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
                    this.subtitleAnimator.start();
                } else {
                    this.subtitleTextView.setAlpha(z ? 1.0f : 0.0f);
                    this.subtitleTextView.setTranslationY(dp);
                    this.titleLayout.setTranslationY(z ? AndroidUtilities.dp(-12.0f) : 0.0f);
                    this.titleLayout.setScaleX(z ? 0.87f : 1.0f);
                    this.titleLayout.setScaleY(z ? 0.87f : 1.0f);
                }
            }
            this.subtitleTextView.setText(subtitle, animated);
        }

        public void updateOrientation() {
            this.hasSubtitle = !this.hasSubtitle;
            setSubtitle(this.subtitleTextView.getText(), false);
        }

        public void updateRightPadding(final float rightPadding, boolean animated) {
            ValueAnimator valueAnimator = this.rightPaddingAnimator;
            if (valueAnimator != null) {
                valueAnimator.cancel();
                this.rightPaddingAnimator = null;
            }
            if (animated) {
                ValueAnimator ofFloat = ValueAnimator.ofFloat(this.rightPadding, rightPadding);
                this.rightPaddingAnimator = ofFloat;
                ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator2) {
                        PhotoViewer.PhotoViewerActionBarContainer.this.lambda$updateRightPadding$0(rightPadding, valueAnimator2);
                    }
                });
                this.rightPaddingAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewerActionBarContainer.this.updateRightPadding(rightPadding, false);
                    }
                });
                this.rightPaddingAnimator.setDuration(320L);
                this.rightPaddingAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
                this.rightPaddingAnimator.start();
                return;
            }
            this.rightPadding = rightPadding;
            this.titleTextView[0].setRightPadding((int) rightPadding);
            this.subtitleTextView.setRightPadding(rightPadding);
        }

        public void lambda$updateRightPadding$0(float f, ValueAnimator valueAnimator) {
            this.rightPadding = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            int i = (int) f;
            this.titleTextView[0].setRightPadding(i);
            this.titleTextView[1].setRightPadding(i);
            this.subtitleTextView.setRightPadding(f);
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int size = View.MeasureSpec.getSize(widthMeasureSpec);
            int size2 = View.MeasureSpec.getSize(heightMeasureSpec);
            int i = Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0;
            int i2 = this.lastHeight;
            int i3 = AndroidUtilities.displaySize.y;
            if (i2 != i3) {
                this.lastHeight = i3;
                updateOrientation();
            }
            this.container.measure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(size2 - i, 1073741824));
            setMeasuredDimension(size, size2);
        }

        @Override
        public void onLayout(boolean changed, int left, int top, int right, int bottom) {
            this.container.layout(0, Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0, right - left, bottom - top);
        }

        public void didReceivedNotification(int id, int account, Object... args) {
            if (id == NotificationCenter.emojiLoaded) {
                this.titleTextView[0].invalidate();
                this.titleTextView[1].invalidate();
                this.subtitleTextView.invalidate();
            }
        }

        @Override
        public void onAttachedToWindow() {
            super.onAttachedToWindow();
            NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiLoaded);
        }

        @Override
        public void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiLoaded);
        }
    }

    public static class PhotoCountView extends View {
        public Paint backgroundPaint;
        public StaticLayout center;
        public float centerTop;
        public float centerWidth;
        public AnimatedTextView.AnimatedTextDrawable left;
        public String lng;
        public int marginTop;
        public boolean nextNotAnimate;
        public TextPaint paint;
        public AnimatedTextView.AnimatedTextDrawable right;
        public AnimatedFloat showT;
        public boolean shown;

        public PhotoCountView(Context context) {
            super(context);
            this.backgroundPaint = new Paint(1);
            this.paint = new TextPaint(1);
            this.shown = false;
            CubicBezierInterpolator cubicBezierInterpolator = CubicBezierInterpolator.EASE_OUT_QUINT;
            this.showT = new AnimatedFloat(this, 0L, 350L, cubicBezierInterpolator);
            this.backgroundPaint.setColor(2130706432);
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable = new AnimatedTextView.AnimatedTextDrawable(false, true, true);
            this.left = animatedTextDrawable;
            animatedTextDrawable.setAnimationProperties(0.3f, 0L, 320L, cubicBezierInterpolator);
            this.left.setTextColor(-1);
            this.left.setTextSize(AndroidUtilities.dp(14.0f));
            this.left.setTypeface(AndroidUtilities.bold());
            this.left.setCallback(this);
            this.left.setText("0");
            this.left.setOverrideFullWidth(AndroidUtilities.displaySize.x);
            this.paint.setColor(-1);
            this.paint.setTextSize(AndroidUtilities.dp(14.0f));
            this.paint.setTypeface(AndroidUtilities.bold());
            setCenterText();
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable2 = new AnimatedTextView.AnimatedTextDrawable(false, true, true);
            this.right = animatedTextDrawable2;
            animatedTextDrawable2.setAnimationProperties(0.3f, 0L, 320L, cubicBezierInterpolator);
            this.right.setTextColor(-1);
            this.right.setTextSize(AndroidUtilities.dp(14.0f));
            this.right.setTypeface(AndroidUtilities.bold());
            this.right.setCallback(this);
            this.right.setText("0");
            this.right.setOverrideFullWidth(AndroidUtilities.displaySize.x);
        }

        public final void setCenterText() {
            StaticLayout staticLayout = new StaticLayout(getOf(), this.paint, AndroidUtilities.dp(200.0f), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
            this.center = staticLayout;
            if (staticLayout.getLineCount() >= 1) {
                this.centerWidth = this.center.getLineWidth(0);
                this.centerTop = this.center.getLineDescent(0);
            } else {
                this.centerWidth = 0.0f;
                this.centerTop = 0.0f;
            }
        }

        public final String getOf() {
            this.lng = LocaleController.getInstance().getCurrentLocaleInfo().shortName;
            return LocaleController.getString("Of").replace("%1$d", "").replace("%2$d", "");
        }

        public void set(int left, int right) {
            set(left, right, true);
        }

        public void set(int left, int right, boolean animated) {
            boolean z = false;
            int max = Math.max(0, left);
            int max2 = Math.max(max, right);
            if (LocaleController.getInstance().getCurrentLocaleInfo() != null && !TextUtils.equals(this.lng, LocaleController.getInstance().getCurrentLocaleInfo().shortName)) {
                setCenterText();
            }
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable = this.left;
            Object[] objArr = new Object[1];
            objArr[0] = Integer.valueOf(LocaleController.isRTL ? max2 : max);
            animatedTextDrawable.setText(String.format("%d", objArr), (!animated || this.nextNotAnimate || LocaleController.isRTL) ? false : true);
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable2 = this.right;
            Object[] objArr2 = new Object[1];
            if (!LocaleController.isRTL) {
                max = max2;
            }
            objArr2[0] = Integer.valueOf(max);
            String format = String.format("%d", objArr2);
            if (animated && !this.nextNotAnimate && !LocaleController.isRTL) {
                z = true;
            }
            animatedTextDrawable2.setText(format, z);
            this.nextNotAnimate = !animated;
        }

        @Override
        public boolean verifyDrawable(Drawable who) {
            return this.left == who || this.right == who || super.verifyDrawable(who);
        }

        public void updateShow(boolean show, boolean animated) {
            if (this.shown != show) {
                this.shown = show;
                if (!show) {
                    this.nextNotAnimate = true;
                }
                if (!animated) {
                    this.showT.set(show ? 1.0f : 0.0f, true);
                }
                invalidate();
            }
        }

        @Override
        public boolean isShown() {
            return this.shown;
        }

        @Override
        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            float f = this.showT.set(this.shown ? 1.0f : 0.0f);
            if (f <= 0.0f) {
                return;
            }
            float currentWidth = this.left.getCurrentWidth() + this.centerWidth + this.right.getCurrentWidth() + AndroidUtilities.dp(18.0f);
            float f2 = this.marginTop + ((1.0f - f) * (-AndroidUtilities.dp(8.0f)));
            RectF rectF = AndroidUtilities.rectTmp;
            rectF.set((getWidth() - currentWidth) / 2.0f, AndroidUtilities.dpf2(10.0f) + f2, (getWidth() + currentWidth) / 2.0f, AndroidUtilities.dpf2(33.0f) + f2);
            int alpha = this.backgroundPaint.getAlpha();
            this.backgroundPaint.setAlpha((int) (alpha * f));
            canvas.drawRoundRect(rectF, AndroidUtilities.dpf2(12.0f), AndroidUtilities.dpf2(12.0f), this.backgroundPaint);
            this.backgroundPaint.setAlpha(alpha);
            canvas.save();
            canvas.translate(((getWidth() - currentWidth) / 2.0f) + AndroidUtilities.dp(9.0f), f2 + AndroidUtilities.dp(10.0f));
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable = this.left;
            animatedTextDrawable.setBounds(0, 0, (int) animatedTextDrawable.getCurrentWidth(), AndroidUtilities.dp(23.0f));
            int i = (int) (f * 255.0f);
            this.left.setAlpha(i);
            this.left.draw(canvas);
            canvas.translate(this.left.getCurrentWidth(), 0.0f);
            canvas.save();
            canvas.translate((-(this.center.getWidth() - this.centerWidth)) / 2.0f, ((AndroidUtilities.dp(23.0f) - this.center.getHeight()) + (this.centerTop / 2.0f)) / 2.0f);
            this.paint.setAlpha(i);
            this.center.draw(canvas);
            canvas.restore();
            canvas.translate(this.centerWidth, 0.0f);
            AnimatedTextView.AnimatedTextDrawable animatedTextDrawable2 = this.right;
            animatedTextDrawable2.setBounds(0, 0, (int) animatedTextDrawable2.getCurrentWidth(), AndroidUtilities.dp(23.0f));
            this.right.setAlpha(i);
            this.right.draw(canvas);
            canvas.restore();
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int size = View.MeasureSpec.getSize(widthMeasureSpec);
            this.marginTop = ActionBar.getCurrentActionBarHeight() + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
            this.left.setOverrideFullWidth(size);
            this.right.setOverrideFullWidth(size);
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(size, 1073741824), View.MeasureSpec.makeMeasureSpec(this.marginTop + AndroidUtilities.dp(43.0f), 1073741824));
        }
    }

    public void addPhoto(MessageObject message, int classGuid) {
        if (classGuid != this.classGuid) {
            return;
        }
        if (this.imagesByIds[0].indexOfKey(message.getId()) < 0) {
            if (this.opennedFromMedia) {
                this.imagesArr.add(message);
            } else {
                this.imagesArr.add(0, message);
            }
            this.imagesByIds[0].put(message.getId(), message);
        }
        this.endReached[0] = this.imagesArr.size() == this.totalImagesCount;
        setImages();
    }

    public int getClassGuid() {
        return this.classGuid;
    }

    public void setCaption(CharSequence caption) {
        this.hasCaptionForAllMedia = true;
        this.captionForAllMedia = caption;
        setCurrentCaption(null, caption, false, false);
        updateCaptionTextForCurrentPhoto(null);
    }

    public void setAvatarFor(ImageUpdater.AvatarFor avatarFor) {
        int i;
        String str;
        TLRPC.User user;
        this.setAvatarFor = avatarFor;
        if (this.sendPhotoType == 1) {
            if (useFullWidthSendButton()) {
                this.doneButtonFullWidth.setVisibility(0);
                this.pickerViewSendButton.setVisibility(8);
            } else {
                this.pickerViewSendButton.setVisibility(0);
                this.doneButtonFullWidth.setVisibility(8);
            }
            if (avatarFor != null && (user = avatarFor.fromObject) != null && avatarFor.type == 1 && this.setAvatarFor.self) {
                if (avatarFor.isVideo) {
                    this.photoCropView.setSubtitle(LocaleController.formatString("SetSuggestedVideoTooltip", R.string.SetSuggestedVideoTooltip, new Object[]{user.first_name}));
                } else {
                    this.photoCropView.setSubtitle(LocaleController.formatString("SetSuggestedPhotoTooltip", R.string.SetSuggestedPhotoTooltip, new Object[]{user.first_name}));
                }
            } else {
                this.photoCropView.setSubtitle((String) null);
            }
        }
        if (avatarFor != null) {
            if (avatarFor.type == 2) {
                if (avatarFor.isVideo) {
                    i = R.string.SuggestVideo;
                    str = "SuggestVideo";
                } else {
                    i = R.string.SuggestPhoto;
                    str = "SuggestPhoto";
                }
                setTitle(LocaleController.getString(str, i));
            }
            if (avatarFor.isVideo) {
                this.videoAvatarTooltip.setText(LocaleController.getString("SetCover", R.string.SetCover));
            }
            this.actionBar.setBackground(null);
            if (Build.VERSION.SDK_INT >= 21) {
                this.actionBar.setElevation(2.0f);
            }
        }
    }

    public final boolean useFullWidthSendButton() {
        ImageUpdater.AvatarFor avatarFor = this.setAvatarFor;
        return (avatarFor == null || !avatarFor.self || avatarFor.isVideo) ? false : true;
    }

    public static class SavedVideoPosition {
        public final float position;
        public final long timestamp;

        public SavedVideoPosition(float position, long timestamp) {
            this.position = position;
            this.timestamp = timestamp;
        }
    }

    public final void onLinkClick(ClickableSpan link, TextView widget) {
        if (widget != null && (link instanceof URLSpan)) {
            String url = ((URLSpan) link).getURL();
            if (url.startsWith("video")) {
                if (this.videoPlayer == null || this.currentMessageObject == null) {
                    return;
                }
                int intValue = Utilities.parseInt(url).intValue();
                if (this.videoPlayer.getDuration() == -9223372036854775807L) {
                    this.seekToProgressPending = intValue / ((float) this.currentMessageObject.getDuration());
                    return;
                }
                long j = intValue * 1000;
                this.videoPlayer.seekTo(j);
                this.videoPlayerSeekbar.setProgress(j / this.videoPlayer.getDuration(), true);
                this.videoPlayerSeekbarView.invalidate();
                return;
            }
            if (url.startsWith("#")) {
                if (this.parentActivity instanceof LaunchActivity) {
                    DialogsActivity dialogsActivity = new DialogsActivity(null);
                    dialogsActivity.setSearchString(url);
                    ((LaunchActivity) this.parentActivity).presentFragment(dialogsActivity, false, true);
                    closePhoto(false, false);
                    return;
                }
                return;
            }
            if (this.parentChatActivity != null && ((link instanceof URLSpanReplacement) || AndroidUtilities.shouldShowUrlInAlert(url))) {
                AlertsCreator.showOpenUrlAlert(this.parentChatActivity, url, true, true);
                return;
            } else {
                link.onClick(widget);
                return;
            }
        }
        link.onClick(widget);
    }

    public final void onLinkLongPress(final android.text.style.URLSpan r11, final android.widget.TextView r12, final java.lang.Runnable r13) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onLinkLongPress(android.text.style.URLSpan, android.widget.TextView, java.lang.Runnable):void");
    }

    public void lambda$onLinkLongPress$1(android.text.style.URLSpan r6, android.widget.TextView r7, int r8, android.content.DialogInterface r9, int r10) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.lambda$onLinkLongPress$1(android.text.style.URLSpan, android.widget.TextView, int, android.content.DialogInterface, int):void");
    }

    public final void cancelFlashAnimations() {
        View view = this.flashView;
        if (view != null) {
            view.animate().setListener(null).cancel();
            this.flashView.setAlpha(0.0f);
        }
        AnimatorSet animatorSet = this.flashAnimator;
        if (animatorSet != null) {
            animatorSet.cancel();
            this.flashAnimator = null;
        }
        PhotoCropView photoCropView = this.photoCropView;
        if (photoCropView != null) {
            photoCropView.cancelThumbAnimation();
        }
    }

    public final void cancelVideoPlayRunnable() {
        Runnable runnable = this.videoPlayRunnable;
        if (runnable != null) {
            AndroidUtilities.cancelRunOnUIThread(runnable);
            this.videoPlayRunnable = null;
        }
    }

    public final long getCurrentVideoPosition() {
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null && photoViewerWebView.isControllable()) {
            return this.photoViewerWebView.getCurrentPosition();
        }
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer == null) {
            return 0L;
        }
        return videoPlayer.getCurrentPosition();
    }

    public final long getVideoDuration() {
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null && photoViewerWebView.isControllable()) {
            return this.photoViewerWebView.getVideoDuration();
        }
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer == null) {
            return 0L;
        }
        return videoPlayer.getDuration();
    }

    public final void seekVideoOrWebTo(long position) {
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null && photoViewerWebView.isControllable()) {
            this.photoViewerWebView.seekTo(position);
        } else {
            VideoPlayer videoPlayer = this.videoPlayer;
            if (videoPlayer != null) {
                videoPlayer.seekTo(position);
            }
        }
        updateVideoPlayerTime();
    }

    public final boolean isVideoPlaying() {
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null && photoViewerWebView.isControllable()) {
            return this.photoViewerWebView.isPlaying();
        }
        VideoPlayer videoPlayer = this.videoPlayer;
        return videoPlayer != null && videoPlayer.isPlaying();
    }

    public class AnonymousClass5 implements Runnable {
        public AnonymousClass5() {
        }

        @Override
        public void run() {
            float f;
            if (PhotoViewer.this.videoPlayer != null || (PhotoViewer.this.photoViewerWebView != null && PhotoViewer.this.photoViewerWebView.isControllable())) {
                if (PhotoViewer.this.isCurrentVideo) {
                    if (!PhotoViewer.this.videoTimelineView.isDragging()) {
                        float currentVideoPosition = (!PhotoViewer.this.shownControlsByEnd || PhotoViewer.this.actionBarWasShownBeforeByEnd) ? PhotoViewer.this.getCurrentVideoPosition() / PhotoViewer.this.getVideoDuration() : 0.0f;
                        if (PhotoViewer.this.inPreview || (PhotoViewer.this.currentEditMode == 0 && PhotoViewer.this.videoTimelineViewContainer.getVisibility() != 0)) {
                            if (PhotoViewer.this.sendPhotoType != 1) {
                                PhotoViewer.this.videoTimelineView.setProgress(currentVideoPosition);
                            }
                        } else if (currentVideoPosition >= PhotoViewer.this.videoTimelineView.getRightProgress()) {
                            PhotoViewer.this.videoTimelineView.setProgress(PhotoViewer.this.videoTimelineView.getLeftProgress());
                            PhotoViewer.this.videoPlayer.seekTo((int) (PhotoViewer.this.videoTimelineView.getLeftProgress() * PhotoViewer.this.getVideoDuration()));
                            PhotoViewer.this.manuallyPaused = false;
                            PhotoViewer.this.cancelVideoPlayRunnable();
                            if (PhotoViewer.this.muteVideo || PhotoViewer.this.sendPhotoType == 1 || PhotoViewer.this.currentEditMode != 0 || PhotoViewer.this.switchingToMode > 0) {
                                PhotoViewer.this.playVideoOrWeb();
                            } else {
                                PhotoViewer.this.pauseVideoOrWeb();
                            }
                            PhotoViewer.this.containerView.invalidate();
                        } else {
                            PhotoViewer.this.videoTimelineView.setProgress(currentVideoPosition);
                        }
                        PhotoViewer.this.updateVideoPlayerTime();
                    }
                } else {
                    final float currentVideoPosition2 = PhotoViewer.this.getCurrentVideoPosition() / PhotoViewer.this.getVideoDuration();
                    if (PhotoViewer.this.shownControlsByEnd && !PhotoViewer.this.actionBarWasShownBeforeByEnd) {
                        currentVideoPosition2 = 0.0f;
                    }
                    if (PhotoViewer.this.currentVideoFinishedLoading) {
                        f = 1.0f;
                    } else {
                        long elapsedRealtime = SystemClock.elapsedRealtime();
                        if (Math.abs(elapsedRealtime - PhotoViewer.this.lastBufferedPositionCheck) >= 500) {
                            if (PhotoViewer.this.photoViewerWebView != null && PhotoViewer.this.photoViewerWebView.isControllable()) {
                                f = PhotoViewer.this.photoViewerWebView.getBufferedPosition();
                            } else if (PhotoViewer.this.isStreaming) {
                                f = FileLoader.getInstance(PhotoViewer.this.currentAccount).getBufferedProgressFromPosition(PhotoViewer.this.seekToProgressPending != 0.0f ? PhotoViewer.this.seekToProgressPending : currentVideoPosition2, PhotoViewer.this.currentFileNames[0]);
                            } else {
                                f = 1.0f;
                            }
                            PhotoViewer.this.lastBufferedPositionCheck = elapsedRealtime;
                        } else {
                            f = -1.0f;
                        }
                    }
                    if (PhotoViewer.this.inPreview || PhotoViewer.this.videoTimelineViewContainer.getVisibility() != 0) {
                        if (PhotoViewer.this.seekToProgressPending == 0.0f) {
                            PhotoViewer photoViewer = PhotoViewer.this;
                            VideoPlayerRewinder videoPlayerRewinder = photoViewer.videoPlayerRewinder;
                            if (videoPlayerRewinder.rewindCount == 0 || !videoPlayerRewinder.rewindByBackSeek) {
                                photoViewer.videoPlayerSeekbar.setProgress(currentVideoPosition2, false);
                            }
                        }
                        if (f != -1.0f) {
                            PhotoViewer.this.videoPlayerSeekbar.setBufferedProgress(f);
                            PipVideoOverlay.setBufferedProgress(f);
                        }
                    } else if (currentVideoPosition2 >= PhotoViewer.this.videoTimelineView.getRightProgress()) {
                        PhotoViewer.this.manuallyPaused = false;
                        PhotoViewer.this.pauseVideoOrWeb();
                        PhotoViewer.this.videoPlayerSeekbar.setProgress(0.0f);
                        PhotoViewer.this.seekVideoOrWebTo((int) (r1.videoTimelineView.getLeftProgress() * PhotoViewer.this.getVideoDuration()));
                        PhotoViewer.this.containerView.invalidate();
                    } else {
                        float leftProgress = currentVideoPosition2 - PhotoViewer.this.videoTimelineView.getLeftProgress();
                        if (leftProgress < 0.0f) {
                            leftProgress = 0.0f;
                        }
                        currentVideoPosition2 = leftProgress / (PhotoViewer.this.videoTimelineView.getRightProgress() - PhotoViewer.this.videoTimelineView.getLeftProgress());
                        if (currentVideoPosition2 > 1.0f) {
                            currentVideoPosition2 = 1.0f;
                        }
                        PhotoViewer.this.videoPlayerSeekbar.setProgress(currentVideoPosition2);
                    }
                    PhotoViewer.this.videoPlayerSeekbarView.invalidate();
                    if (PhotoViewer.this.shouldSavePositionForCurrentVideo != null && currentVideoPosition2 >= 0.0f && SystemClock.elapsedRealtime() - PhotoViewer.this.lastSaveTime >= 1000) {
                        final String str = PhotoViewer.this.shouldSavePositionForCurrentVideo;
                        PhotoViewer.this.lastSaveTime = SystemClock.elapsedRealtime();
                        Utilities.globalQueue.postRunnable(new Runnable() {
                            @Override
                            public final void run() {
                                PhotoViewer.AnonymousClass5.lambda$run$0(str, currentVideoPosition2);
                            }
                        });
                    }
                    PhotoViewer.this.updateVideoPlayerTime();
                }
            }
            if (PhotoViewer.this.firstFrameView != null) {
                PhotoViewer.this.firstFrameView.updateAlpha();
            }
            if (PhotoViewer.this.isPlaying) {
                AndroidUtilities.runOnUIThread(PhotoViewer.this.updateProgressRunnable, 17L);
            }
        }

        public static void lambda$run$0(String str, float f) {
            ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", 0).edit().putFloat(str, f).commit();
        }
    }

    public final void checkChangedTextureView(boolean enter) {
        if (enter) {
            TextureView textureView = this.changedTextureView;
            if (textureView == null) {
                return;
            }
            textureView.getViewTreeObserver().addOnPreDrawListener(new AnonymousClass8());
            this.changedTextureView.invalidate();
            return;
        }
        if (this.waitingForFirstTextureUpload == 2) {
            ImageView imageView = this.textureImageView;
            if (imageView != null) {
                imageView.setVisibility(4);
                this.textureImageView.setImageDrawable(null);
                Bitmap bitmap = this.currentBitmap;
                if (bitmap != null) {
                    bitmap.recycle();
                    this.currentBitmap = null;
                }
            }
            this.switchingInlineMode = false;
            if (Build.VERSION.SDK_INT >= 21) {
                final View view = this.usedSurfaceView ? this.videoSurfaceView : this.videoTextureView;
                AspectRatioFrameLayout aspectRatioFrameLayout = this.aspectRatioFrameLayout;
                if (aspectRatioFrameLayout == null) {
                    return;
                }
                aspectRatioFrameLayout.getLocationInWindow(this.pipPosition);
                this.pipPosition[1] = (int) (r2[1] - this.containerView.getTranslationY());
                ImageView imageView2 = this.textureImageView;
                if (imageView2 != null) {
                    imageView2.setTranslationX(imageView2.getTranslationX() + getLeftInset());
                }
                if (view != null) {
                    view.setTranslationX((view.getTranslationX() + getLeftInset()) - this.aspectRatioFrameLayout.getX());
                }
                FirstFrameView firstFrameView = this.firstFrameView;
                if (firstFrameView != null) {
                    firstFrameView.setTranslationX(view.getTranslationX());
                }
                ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
                ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.this.lambda$checkChangedTextureView$3(valueAnimator);
                    }
                });
                float x = this.usedSurfaceView ? 0.0f : this.pipPosition[0] - this.aspectRatioFrameLayout.getX();
                float y = this.usedSurfaceView ? 0.0f : this.pipPosition[1] - this.aspectRatioFrameLayout.getY();
                AnimatorSet animatorSet = new AnimatorSet();
                ArrayList arrayList = new ArrayList();
                arrayList.add(ofFloat);
                arrayList.add(ObjectAnimator.ofFloat(this.textureImageView, (Property<ImageView, Float>) View.SCALE_X, 1.0f));
                arrayList.add(ObjectAnimator.ofFloat(this.textureImageView, (Property<ImageView, Float>) View.SCALE_Y, 1.0f));
                ImageView imageView3 = this.textureImageView;
                Property property = View.TRANSLATION_X;
                float[] fArr = new float[1];
                fArr[0] = this.usedSurfaceView ? 0.0f : this.pipPosition[0];
                arrayList.add(ObjectAnimator.ofFloat(imageView3, (Property<ImageView, Float>) property, fArr));
                ImageView imageView4 = this.textureImageView;
                Property property2 = View.TRANSLATION_Y;
                float[] fArr2 = new float[1];
                fArr2[0] = this.usedSurfaceView ? 0.0f : this.pipPosition[1];
                arrayList.add(ObjectAnimator.ofFloat(imageView4, (Property<ImageView, Float>) property2, fArr2));
                arrayList.add(ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_X, 1.0f));
                arrayList.add(ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_Y, 1.0f));
                arrayList.add(ObjectAnimator.ofFloat(view, (Property<View, Float>) View.TRANSLATION_X, x));
                arrayList.add(ObjectAnimator.ofFloat(view, (Property<View, Float>) View.TRANSLATION_Y, y));
                arrayList.add(ObjectAnimator.ofInt(this.backgroundDrawable, (Property<BackgroundDrawable, Integer>) AnimationProperties.COLOR_DRAWABLE_ALPHA, 255));
                FirstFrameView firstFrameView2 = this.firstFrameView;
                if (firstFrameView2 != null) {
                    arrayList.add(ObjectAnimator.ofFloat(firstFrameView2, (Property<FirstFrameView, Float>) View.SCALE_X, 1.0f));
                    arrayList.add(ObjectAnimator.ofFloat(this.firstFrameView, (Property<FirstFrameView, Float>) View.SCALE_Y, 1.0f));
                    arrayList.add(ObjectAnimator.ofFloat(this.firstFrameView, (Property<FirstFrameView, Float>) View.TRANSLATION_X, x));
                    arrayList.add(ObjectAnimator.ofFloat(this.firstFrameView, (Property<FirstFrameView, Float>) View.TRANSLATION_Y, y));
                }
                float f = PipVideoOverlay.getPipRect(false, this.aspectRatioFrameLayout.getAspectRatio()).width;
                view.getWidth();
                ValueAnimator ofFloat2 = ValueAnimator.ofFloat(0.0f, 1.0f);
                ofFloat2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.this.lambda$checkChangedTextureView$4(view, valueAnimator);
                    }
                });
                arrayList.add(ofFloat2);
                animatorSet.playTogether(arrayList);
                DecelerateInterpolator decelerateInterpolator2 = new DecelerateInterpolator();
                animatorSet.setInterpolator(decelerateInterpolator2);
                animatorSet.setDuration(250L);
                SurfaceView surfaceView = this.videoSurfaceView;
                if (surfaceView != null) {
                    surfaceView.setVisibility(0);
                }
                animatorSet.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewer.this.pipAnimationInProgress = false;
                        view.setOutlineProvider(null);
                        if (PhotoViewer.this.textureImageView != null) {
                            PhotoViewer.this.textureImageView.setOutlineProvider(null);
                        }
                        if (PhotoViewer.this.firstFrameView != null) {
                            PhotoViewer.this.firstFrameView.setOutlineProvider(null);
                        }
                        if (PhotoViewer.this.videoSurfaceView != null) {
                            PhotoViewer.this.videoSurfaceView.setVisibility(0);
                        }
                    }
                });
                animatorSet.start();
                toggleActionBar(true, true, new ActionBarToggleParams().enableStatusBarAnimation(false).enableTranslationAnimation(false).animationDuration(250).animationInterpolator(decelerateInterpolator2));
            } else {
                toggleActionBar(true, false);
            }
            this.waitingForFirstTextureUpload = 0;
        }
    }

    public class AnonymousClass8 implements ViewTreeObserver.OnPreDrawListener {
        public AnonymousClass8() {
        }

        @Override
        public boolean onPreDraw() {
            PhotoViewer.this.changedTextureView.getViewTreeObserver().removeOnPreDrawListener(this);
            if (PhotoViewer.this.textureImageView != null) {
                if (PhotoViewer.this.isInline) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.AnonymousClass8.this.lambda$onPreDraw$0();
                        }
                    }, 300L);
                } else {
                    PhotoViewer.this.textureImageView.setVisibility(4);
                    PhotoViewer.this.textureImageView.setImageDrawable(null);
                    if (PhotoViewer.this.currentBitmap != null) {
                        PhotoViewer.this.currentBitmap.recycle();
                        PhotoViewer.this.currentBitmap = null;
                    }
                }
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass8.this.lambda$onPreDraw$1();
                }
            });
            PhotoViewer.this.waitingForFirstTextureUpload = 0;
            return true;
        }

        public void lambda$onPreDraw$0() {
            PhotoViewer.this.textureImageView.setVisibility(4);
            PhotoViewer.this.textureImageView.setImageDrawable(null);
            if (PhotoViewer.this.currentBitmap != null) {
                PhotoViewer.this.currentBitmap.recycle();
                PhotoViewer.this.currentBitmap = null;
            }
        }

        public void lambda$onPreDraw$1() {
            if (PhotoViewer.this.isInline) {
                PhotoViewer.this.dismissInternal();
            }
        }
    }

    public void lambda$checkChangedTextureView$3(ValueAnimator valueAnimator) {
        this.clippingImageProgress = 1.0f - ((Float) valueAnimator.getAnimatedValue()).floatValue();
    }

    public void lambda$checkChangedTextureView$4(View view, ValueAnimator valueAnimator) {
        this.inlineOutAnimationProgress = ((Float) valueAnimator.getAnimatedValue()).floatValue();
        view.invalidateOutline();
        ImageView imageView = this.textureImageView;
        if (imageView != null) {
            imageView.invalidateOutline();
        }
        FirstFrameView firstFrameView = this.firstFrameView;
        if (firstFrameView != null) {
            firstFrameView.invalidateOutline();
        }
    }

    public void lambda$new$5() {
        if (this.isVisible && this.animationInProgress == 0) {
            updateContainerFlags(this.isActionBarVisible);
        }
    }

    public static class EditState {
        public long averageDuration;
        public MediaController.CropState cropState;
        public ArrayList<VideoEditedInfo.MediaEntity> croppedMediaEntities;
        public String croppedPaintPath;
        public ArrayList<VideoEditedInfo.MediaEntity> mediaEntities;
        public String paintPath;
        public MediaController.SavedFilterState savedFilterState;

        public void reset() {
            this.paintPath = null;
            this.cropState = null;
            this.savedFilterState = null;
            this.mediaEntities = null;
            this.croppedPaintPath = null;
            this.croppedMediaEntities = null;
            this.averageDuration = 0L;
        }
    }

    public class SavedState {
        public int index;
        public ArrayList<MessageObject> messages;
        public PhotoViewerProvider provider;

        public SavedState(int index, ArrayList<MessageObject> messages, PhotoViewerProvider provider) {
            this.messages = messages;
            this.index = index;
            this.provider = provider;
        }

        public void restore() {
            PhotoViewer.this.placeProvider = this.provider;
            if (Build.VERSION.SDK_INT >= 21) {
                PhotoViewer.this.windowLayoutParams.flags = -2147286784;
            } else {
                PhotoViewer.this.windowLayoutParams.flags = 131072;
            }
            PhotoViewer.this.windowLayoutParams.softInputMode = 272;
            PhotoViewer.this.windowView.setFocusable(false);
            PhotoViewer.this.containerView.setFocusable(false);
            PhotoViewer.this.backgroundDrawable.setAlpha(255);
            PhotoViewer.this.containerView.setAlpha(1.0f);
            PhotoViewer photoViewer = PhotoViewer.this;
            ArrayList<MessageObject> arrayList = this.messages;
            int i = this.index;
            photoViewer.onPhotoShow(null, null, null, null, arrayList, null, null, i, this.provider.getPlaceForPhoto(arrayList.get(i), null, this.index, true));
        }
    }

    public class BackgroundDrawable extends ColorDrawable {
        public boolean allowDrawContent;
        public Runnable drawRunnable;
        public final Paint paint;
        public final RectF rect;
        public final RectF visibleRect;

        public BackgroundDrawable(int color) {
            super(color);
            this.rect = new RectF();
            this.visibleRect = new RectF();
            Paint paint = new Paint(1);
            this.paint = paint;
            paint.setColor(color);
        }

        @Override
        @Keep
        public void setAlpha(int alpha) {
            if (PhotoViewer.this.parentActivity instanceof LaunchActivity) {
                this.allowDrawContent = (PhotoViewer.this.isVisible && alpha == 255) ? false : true;
                ((LaunchActivity) PhotoViewer.this.parentActivity).drawerLayoutContainer.setAllowDrawContent(this.allowDrawContent);
                if (PhotoViewer.this.parentAlert != null) {
                    if (!this.allowDrawContent) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                PhotoViewer.BackgroundDrawable.this.lambda$setAlpha$0();
                            }
                        }, 50L);
                    } else {
                        PhotoViewer.this.parentAlert.setAllowDrawContent(true);
                    }
                }
            }
            super.setAlpha(alpha);
            this.paint.setAlpha(alpha);
        }

        public void lambda$setAlpha$0() {
            if (PhotoViewer.this.parentAlert != null) {
                PhotoViewer.this.parentAlert.setAllowDrawContent(this.allowDrawContent);
            }
        }

        @Override
        public void draw(Canvas canvas) {
            Runnable runnable;
            if (PhotoViewer.this.animationInProgress != 0 && !AndroidUtilities.isTablet() && PhotoViewer.this.currentPlaceObject != null && PhotoViewer.this.currentPlaceObject.animatingImageView != null) {
                PhotoViewer.this.animatingImageView.getClippedVisibleRect(this.visibleRect);
                if (!this.visibleRect.isEmpty()) {
                    this.visibleRect.inset(AndroidUtilities.dp(1.0f), AndroidUtilities.dp(1.0f));
                    Rect bounds = getBounds();
                    float f = bounds.right;
                    float f2 = bounds.bottom;
                    for (int i = 0; i < 4; i++) {
                        if (i == 0) {
                            RectF rectF = this.rect;
                            RectF rectF2 = this.visibleRect;
                            rectF.set(0.0f, rectF2.top, rectF2.left, rectF2.bottom);
                        } else if (i == 1) {
                            this.rect.set(0.0f, 0.0f, f, this.visibleRect.top);
                        } else if (i == 2) {
                            RectF rectF3 = this.rect;
                            RectF rectF4 = this.visibleRect;
                            rectF3.set(rectF4.right, rectF4.top, f, rectF4.bottom);
                        } else if (i == 3) {
                            this.rect.set(0.0f, this.visibleRect.bottom, f, f2);
                        }
                        canvas.drawRect(this.rect, this.paint);
                    }
                }
            } else {
                super.draw(canvas);
            }
            if (getAlpha() == 0 || (runnable = this.drawRunnable) == null) {
                return;
            }
            AndroidUtilities.runOnUIThread(runnable);
            this.drawRunnable = null;
        }
    }

    public static class SelectedPhotosListView extends RecyclerListView {
        public Drawable arrowDrawable;
        public Paint paint;
        public RectF rect;

        public SelectedPhotosListView(Context context) {
            super(context);
            this.paint = new Paint(1);
            this.rect = new RectF();
            setWillNotDraw(false);
            setClipToPadding(false);
            setTranslationY(-AndroidUtilities.dp(10.0f));
            DefaultItemAnimator defaultItemAnimator = new DefaultItemAnimator() {
                public void onMoveAnimationUpdate(RecyclerView.ViewHolder holder) {
                    SelectedPhotosListView.this.invalidate();
                }
            };
            setItemAnimator(defaultItemAnimator);
            defaultItemAnimator.setDelayAnimations(false);
            defaultItemAnimator.setSupportsChangeAnimations(false);
            setPadding(AndroidUtilities.dp(12.0f), AndroidUtilities.dp(12.0f), AndroidUtilities.dp(12.0f), AndroidUtilities.dp(6.0f));
            this.paint.setColor(2130706432);
            this.arrowDrawable = context.getResources().getDrawable(R.drawable.photo_tooltip2).mutate();
        }

        public void onDraw(Canvas c) {
            super/*androidx.recyclerview.widget.RecyclerView*/.onDraw(c);
            int childCount = getChildCount();
            if (childCount > 0) {
                int measuredWidth = getMeasuredWidth() - AndroidUtilities.dp(87.0f);
                Drawable drawable = this.arrowDrawable;
                drawable.setBounds(measuredWidth, 0, drawable.getIntrinsicWidth() + measuredWidth, AndroidUtilities.dp(6.0f));
                this.arrowDrawable.draw(c);
                int i = Integer.MAX_VALUE;
                int i2 = Integer.MIN_VALUE;
                for (int i3 = 0; i3 < childCount; i3++) {
                    View childAt = getChildAt(i3);
                    i = (int) Math.min(i, Math.floor(childAt.getX()));
                    i2 = (int) Math.max(i2, Math.ceil(childAt.getX() + childAt.getMeasuredWidth()));
                }
                if (i == Integer.MAX_VALUE || i2 == Integer.MIN_VALUE) {
                    return;
                }
                this.rect.set(i - AndroidUtilities.dp(6.0f), AndroidUtilities.dp(6.0f), i2 + AndroidUtilities.dp(6.0f), AndroidUtilities.dp(103.0f));
                c.drawRoundRect(this.rect, AndroidUtilities.dp(8.0f), AndroidUtilities.dp(8.0f), this.paint);
            }
        }
    }

    public static class CounterView extends View {
        public int currentCount;
        public int height;
        public Paint paint;
        public RectF rect;
        public float rotation;
        public StaticLayout staticLayout;
        public TextPaint textPaint;
        public int width;

        public CounterView(Context context) {
            super(context);
            this.currentCount = 0;
            TextPaint textPaint = new TextPaint(1);
            this.textPaint = textPaint;
            textPaint.setTextSize(AndroidUtilities.dp(15.0f));
            this.textPaint.setTypeface(AndroidUtilities.bold());
            this.textPaint.setColor(-1);
            Paint paint = new Paint(1);
            this.paint = paint;
            paint.setColor(-1);
            this.paint.setStrokeWidth(AndroidUtilities.dp(2.0f));
            this.paint.setStyle(Paint.Style.STROKE);
            this.paint.setStrokeJoin(Paint.Join.ROUND);
            this.rect = new RectF();
            setCount(0);
        }

        @Override
        @Keep
        public void setScaleX(float scaleX) {
            super.setScaleX(scaleX);
            invalidate();
        }

        @Override
        @Keep
        public void setRotationX(float rotationX) {
            this.rotation = rotationX;
            invalidate();
        }

        @Override
        public float getRotationX() {
            return this.rotation;
        }

        public void setCount(int value) {
            StaticLayout staticLayout = new StaticLayout("" + Math.max(1, value), this.textPaint, AndroidUtilities.dp(100.0f), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            this.staticLayout = staticLayout;
            this.width = (int) Math.ceil((double) staticLayout.getLineWidth(0));
            this.height = this.staticLayout.getLineBottom(0);
            AnimatorSet animatorSet = new AnimatorSet();
            if (value == 0) {
                Paint paint = this.paint;
                Property property = AnimationProperties.PAINT_ALPHA;
                animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_X, 0.0f), ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_Y, 0.0f), ObjectAnimator.ofInt(paint, (Property<Paint, Integer>) property, 0), ObjectAnimator.ofInt(this.textPaint, (Property<TextPaint, Integer>) property, 0));
                animatorSet.setInterpolator(new DecelerateInterpolator());
            } else {
                int i = this.currentCount;
                if (i == 0) {
                    Paint paint2 = this.paint;
                    Property property2 = AnimationProperties.PAINT_ALPHA;
                    animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_X, 0.0f, 1.0f), ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_Y, 0.0f, 1.0f), ObjectAnimator.ofInt(paint2, (Property<Paint, Integer>) property2, 0, 255), ObjectAnimator.ofInt(this.textPaint, (Property<TextPaint, Integer>) property2, 0, 255));
                    animatorSet.setInterpolator(new DecelerateInterpolator());
                } else if (value < i) {
                    animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_X, 1.1f, 1.0f), ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_Y, 1.1f, 1.0f));
                    animatorSet.setInterpolator(new OvershootInterpolator());
                } else {
                    animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_X, 0.9f, 1.0f), ObjectAnimator.ofFloat(this, (Property<CounterView, Float>) View.SCALE_Y, 0.9f, 1.0f));
                    animatorSet.setInterpolator(new OvershootInterpolator());
                }
            }
            animatorSet.setDuration(180L);
            animatorSet.start();
            requestLayout();
            this.currentCount = value;
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(Math.max(this.width + AndroidUtilities.dp(20.0f), AndroidUtilities.dp(30.0f)), 1073741824), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40.0f), 1073741824));
        }

        @Override
        public void onDraw(Canvas canvas) {
            int measuredHeight = getMeasuredHeight() / 2;
            this.paint.setAlpha(255);
            this.rect.set(AndroidUtilities.dp(1.0f), measuredHeight - AndroidUtilities.dp(14.0f), getMeasuredWidth() - AndroidUtilities.dp(1.0f), measuredHeight + AndroidUtilities.dp(14.0f));
            canvas.drawRoundRect(this.rect, AndroidUtilities.dp(15.0f), AndroidUtilities.dp(15.0f), this.paint);
            if (this.staticLayout != null) {
                this.textPaint.setAlpha((int) ((1.0f - this.rotation) * 255.0f));
                canvas.save();
                canvas.translate((getMeasuredWidth() - this.width) / 2, ((getMeasuredHeight() - this.height) / 2) + AndroidUtilities.dpf2(0.2f) + (this.rotation * AndroidUtilities.dp(5.0f)));
                this.staticLayout.draw(canvas);
                canvas.restore();
                this.paint.setAlpha((int) (this.rotation * 255.0f));
                int centerX = (int) this.rect.centerX();
                int centerY = (int) (((int) this.rect.centerY()) - (AndroidUtilities.dp(5.0f) * (1.0f - this.rotation)));
                canvas.drawLine(AndroidUtilities.dp(5.0f) + centerX, centerY - AndroidUtilities.dp(5.0f), centerX - AndroidUtilities.dp(5.0f), AndroidUtilities.dp(5.0f) + centerY, this.paint);
                canvas.drawLine(centerX - AndroidUtilities.dp(5.0f), centerY - AndroidUtilities.dp(5.0f), centerX + AndroidUtilities.dp(5.0f), centerY + AndroidUtilities.dp(5.0f), this.paint);
            }
        }
    }

    public class PhotoProgressView {
        public View parent;
        public final CombinedDrawable playDrawable;
        public final PlayPauseDrawable playPauseDrawable;
        public boolean visible;
        public long lastUpdateTime = 0;
        public float radOffset = 0.0f;
        public float currentProgress = 0.0f;
        public float animationProgressStart = 0.0f;
        public long currentProgressTime = 0;
        public float animatedProgressValue = 0.0f;
        public RectF progressRect = new RectF();
        public int backgroundState = -1;
        public int size = AndroidUtilities.dp(64.0f);
        public int previousBackgroundState = -2;
        public float animatedAlphaValue = 1.0f;
        public float[] animAlphas = new float[3];
        public float[] alphas = new float[3];
        public float scale = 1.0f;

        public void onBackgroundStateUpdated(int state) {
            throw null;
        }

        public void onVisibilityChanged(boolean visible) {
            throw null;
        }

        public PhotoProgressView(View parentView) {
            if (PhotoViewer.decelerateInterpolator == null) {
                PhotoViewer.decelerateInterpolator = new DecelerateInterpolator(1.5f);
                PhotoViewer.progressPaint = new Paint(1);
                PhotoViewer.progressPaint.setStyle(Paint.Style.STROKE);
                PhotoViewer.progressPaint.setStrokeCap(Paint.Cap.ROUND);
                PhotoViewer.progressPaint.setStrokeWidth(AndroidUtilities.dp(3.0f));
                PhotoViewer.progressPaint.setColor(-1);
            }
            this.parent = parentView;
            resetAlphas();
            PlayPauseDrawable playPauseDrawable = new PlayPauseDrawable(28);
            this.playPauseDrawable = playPauseDrawable;
            playPauseDrawable.setDuration(200);
            this.playDrawable = new CombinedDrawable(ContextCompat.getDrawable(PhotoViewer.this.parentActivity, R.drawable.circle_big).mutate(), playPauseDrawable);
        }

        public final void updateAnimation(boolean withProgressAnimation) {
            boolean z;
            long currentTimeMillis = System.currentTimeMillis();
            long j = currentTimeMillis - this.lastUpdateTime;
            if (j > 18) {
                j = 18;
            }
            this.lastUpdateTime = currentTimeMillis;
            int i = 0;
            if (withProgressAnimation) {
                if (this.animatedProgressValue == 1.0f && this.currentProgress == 1.0f) {
                    z = false;
                } else {
                    this.radOffset += (360 * j) / 3000.0f;
                    float f = this.currentProgress - this.animationProgressStart;
                    if (Math.abs(f) > 0.0f) {
                        long j2 = this.currentProgressTime + j;
                        this.currentProgressTime = j2;
                        if (j2 >= 300) {
                            float f2 = this.currentProgress;
                            this.animatedProgressValue = f2;
                            this.animationProgressStart = f2;
                            this.currentProgressTime = 0L;
                        } else {
                            this.animatedProgressValue = this.animationProgressStart + (f * PhotoViewer.decelerateInterpolator.getInterpolation(this.currentProgressTime / 300.0f));
                        }
                    }
                    z = true;
                }
                float f3 = this.animatedAlphaValue;
                if (f3 > 0.0f && this.previousBackgroundState != -2) {
                    float f4 = f3 - (j / 200.0f);
                    this.animatedAlphaValue = f4;
                    if (f4 <= 0.0f) {
                        this.animatedAlphaValue = 0.0f;
                        this.previousBackgroundState = -2;
                    }
                    z = true;
                }
            } else {
                z = false;
            }
            while (true) {
                float[] fArr = this.alphas;
                if (i >= fArr.length) {
                    break;
                }
                float f5 = fArr[i];
                float[] fArr2 = this.animAlphas;
                if (f5 > fArr2[i]) {
                    fArr2[i] = Math.min(1.0f, fArr2[i] + (j / 200.0f));
                } else if (fArr[i] < fArr2[i]) {
                    fArr2[i] = Math.max(0.0f, fArr2[i] - (j / 200.0f));
                } else {
                    i++;
                }
                z = true;
                i++;
            }
            if (z) {
                this.parent.postInvalidateOnAnimation();
            }
        }

        public void setProgress(float value, boolean animated) {
            if (!animated) {
                this.animatedProgressValue = value;
                this.animationProgressStart = value;
            } else {
                this.animationProgressStart = this.animatedProgressValue;
            }
            this.currentProgress = value;
            this.currentProgressTime = 0L;
            this.parent.invalidate();
        }

        public void setBackgroundState(int state, boolean animated, boolean animateIcon) {
            int i;
            int i2 = this.backgroundState;
            if (i2 == state) {
                return;
            }
            PlayPauseDrawable playPauseDrawable = this.playPauseDrawable;
            if (playPauseDrawable != null) {
                boolean z = animateIcon && (i2 == 3 || i2 == 4);
                if (state == 3) {
                    playPauseDrawable.setPause(false, z);
                } else if (state == 4) {
                    playPauseDrawable.setPause(true, z);
                }
                this.playPauseDrawable.setParent(this.parent);
                this.playPauseDrawable.invalidateSelf();
            }
            this.lastUpdateTime = System.currentTimeMillis();
            if (animated && (i = this.backgroundState) != state) {
                this.previousBackgroundState = i;
                this.animatedAlphaValue = 1.0f;
            } else {
                this.previousBackgroundState = -2;
            }
            this.backgroundState = state;
            onBackgroundStateUpdated(state);
            this.parent.invalidate();
        }

        public void setAlpha(float value) {
            setIndexedAlpha(0, value, false);
        }

        public void setScale(float value) {
            this.scale = value;
        }

        public void setIndexedAlpha(int index, float alpha, boolean animated) {
            float[] fArr = this.alphas;
            if (fArr[index] != alpha) {
                fArr[index] = alpha;
                if (!animated) {
                    this.animAlphas[index] = alpha;
                }
                checkVisibility();
                this.parent.invalidate();
            }
        }

        public void resetAlphas() {
            int i = 0;
            while (true) {
                float[] fArr = this.alphas;
                if (i < fArr.length) {
                    this.animAlphas[i] = 1.0f;
                    fArr[i] = 1.0f;
                    i++;
                } else {
                    checkVisibility();
                    return;
                }
            }
        }

        public final float calculateAlpha() {
            float f;
            float f2 = 1.0f;
            int i = 0;
            while (true) {
                float[] fArr = this.animAlphas;
                if (i >= fArr.length) {
                    return f2;
                }
                if (i == 2) {
                    f = AndroidUtilities.accelerateInterpolator.getInterpolation(fArr[i]);
                } else {
                    f = fArr[i];
                }
                f2 *= f;
                i++;
            }
        }

        public final void checkVisibility() {
            boolean z = false;
            int i = 0;
            while (true) {
                float[] fArr = this.alphas;
                if (i >= fArr.length) {
                    z = true;
                    break;
                } else if (fArr[i] != 1.0f) {
                    break;
                } else {
                    i++;
                }
            }
            if (z != this.visible) {
                this.visible = z;
                onVisibilityChanged(z);
            }
        }

        public boolean isVisible() {
            return this.visible;
        }

        public int getX() {
            return (PhotoViewer.this.containerView.getWidth() - ((int) (this.size * this.scale))) / 2;
        }

        public int getY() {
            int i = (int) ((((AndroidUtilities.displaySize.y + (PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0)) - ((int) (this.size * this.scale))) / 2) + PhotoViewer.this.currentPanTranslationY);
            return PhotoViewer.this.sendPhotoType == 1 ? i - AndroidUtilities.dp(38.0f) : i;
        }

        public void onDraw(Canvas canvas) {
            int i;
            Drawable drawable;
            Drawable drawable2;
            int i2 = (int) (this.size * this.scale);
            int x = getX();
            int y = getY();
            float calculateAlpha = calculateAlpha();
            int i3 = this.previousBackgroundState;
            if (i3 >= 0 && i3 < PhotoViewer.progressDrawables.length + 2) {
                if (this.previousBackgroundState < PhotoViewer.progressDrawables.length) {
                    drawable2 = PhotoViewer.progressDrawables[this.previousBackgroundState];
                } else {
                    drawable2 = this.playDrawable;
                }
                if (drawable2 != null) {
                    drawable2.setAlpha((int) (this.animatedAlphaValue * 255.0f * calculateAlpha));
                    drawable2.setBounds(x, y, x + i2, y + i2);
                    drawable2.draw(canvas);
                }
            }
            int i4 = this.backgroundState;
            if (i4 >= 0 && i4 < PhotoViewer.progressDrawables.length + 2) {
                if (this.backgroundState < PhotoViewer.progressDrawables.length) {
                    drawable = PhotoViewer.progressDrawables[this.backgroundState];
                } else {
                    drawable = this.playDrawable;
                }
                if (drawable != null) {
                    if (this.previousBackgroundState != -2) {
                        drawable.setAlpha((int) ((1.0f - this.animatedAlphaValue) * 255.0f * calculateAlpha));
                    } else {
                        drawable.setAlpha((int) (calculateAlpha * 255.0f));
                    }
                    drawable.setBounds(x, y, x + i2, y + i2);
                    drawable.draw(canvas);
                }
            }
            int i5 = this.backgroundState;
            if (i5 == 0 || i5 == 1 || (i = this.previousBackgroundState) == 0 || i == 1) {
                int dp = AndroidUtilities.dp(4.0f);
                if (this.previousBackgroundState != -2) {
                    PhotoViewer.progressPaint.setAlpha((int) (this.animatedAlphaValue * 255.0f * calculateAlpha));
                } else {
                    PhotoViewer.progressPaint.setAlpha((int) (calculateAlpha * 255.0f));
                }
                this.progressRect.set(x + dp, y + dp, (x + i2) - dp, (y + i2) - dp);
                canvas.drawArc(this.progressRect, this.radOffset - 90.0f, Math.max(4.0f, this.animatedProgressValue * 360.0f), false, PhotoViewer.progressPaint);
                updateAnimation(true);
                return;
            }
            updateAnimation(false);
        }
    }

    public class FrameLayoutDrawer extends SizeNotifierFrameLayoutPhoto {
        public boolean captionAbove;
        public ArrayList<Rect> exclusionRects;
        public boolean ignoreLayout;
        public Paint paint;

        public FrameLayoutDrawer(Context context, Activity activity) {
            super(context, activity, false);
            this.paint = new Paint();
            setWillNotDraw(false);
            this.paint.setColor(855638016);
            setLayerType(2, null);
        }

        public void onMeasure(int r18, int r19) {
            throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.FrameLayoutDrawer.onMeasure(int, int):void");
        }

        public void onLayout(boolean r16, int r17, int r18, int r19, int r20) {
            throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.FrameLayoutDrawer.onLayout(boolean, int, int, int, int):void");
        }

        public void updateExclusionRects() {
            if (Build.VERSION.SDK_INT >= 29) {
                if (this.exclusionRects == null) {
                    this.exclusionRects = new ArrayList<>();
                }
                this.exclusionRects.clear();
                if (PhotoViewer.this.currentEditMode == 1 || PhotoViewer.this.switchingToMode == 1) {
                    int measuredHeight = getMeasuredHeight();
                    int measuredWidth = getMeasuredWidth();
                    this.exclusionRects.add(new Rect(0, (measuredHeight - AndroidUtilities.dp(200.0f)) / 2, AndroidUtilities.dp(100.0f), (AndroidUtilities.dp(200.0f) + measuredHeight) / 2));
                    this.exclusionRects.add(new Rect(measuredWidth - AndroidUtilities.dp(100.0f), (measuredHeight - AndroidUtilities.dp(200.0f)) / 2, measuredWidth, (measuredHeight + AndroidUtilities.dp(200.0f)) / 2));
                }
                setSystemGestureExclusionRects(this.exclusionRects);
                invalidate();
            }
        }

        public void onDraw(Canvas canvas) {
            PhotoViewer.this.onDraw(canvas);
            if (!PhotoViewer.this.isStatusBarVisible() || AndroidUtilities.statusBarHeight == 0 || PhotoViewer.this.actionBar == null) {
                return;
            }
            if (Build.VERSION.SDK_INT < 21) {
                this.paint.setAlpha((int) (PhotoViewer.this.actionBar.getAlpha() * 255.0f * 0.2f));
                canvas.drawRect(0.0f, PhotoViewer.this.currentPanTranslationY, getMeasuredWidth(), PhotoViewer.this.currentPanTranslationY + AndroidUtilities.statusBarHeight, this.paint);
            }
            this.paint.setAlpha((int) (PhotoViewer.this.actionBar.getAlpha() * 255.0f * 0.498f));
            if (getPaddingRight() > 0) {
                canvas.drawRect(getMeasuredWidth() - getPaddingRight(), 0.0f, getMeasuredWidth(), getMeasuredHeight(), this.paint);
            }
            if (getPaddingLeft() > 0) {
                canvas.drawRect(0.0f, 0.0f, getPaddingLeft(), getMeasuredHeight(), this.paint);
            }
            if (getPaddingBottom() > 0) {
                float dpf2 = AndroidUtilities.dpf2(24.0f) * (1.0f - PhotoViewer.this.actionBar.getAlpha());
                canvas.drawRect(0.0f, (getMeasuredHeight() - getPaddingBottom()) + dpf2, getMeasuredWidth(), getMeasuredHeight() + dpf2, this.paint);
            }
        }

        public void draw(Canvas canvas) {
            super/*android.widget.FrameLayout*/.draw(canvas);
            if (PhotoViewer.this.photoViewerWebView == null || !PhotoViewer.this.photoViewerWebView.isControllable() || PhotoViewer.this.videoForwardDrawable == null || !PhotoViewer.this.videoForwardDrawable.isAnimating()) {
                return;
            }
            int measuredHeight = ((int) (PhotoViewer.this.photoViewerWebView.getWebView().getMeasuredHeight() * (PhotoViewer.this.scale - 1.0f))) / 2;
            PhotoViewer.this.videoForwardDrawable.setBounds(PhotoViewer.this.photoViewerWebView.getLeft(), (PhotoViewer.this.photoViewerWebView.getWebView().getTop() - measuredHeight) + ((int) (PhotoViewer.this.translationY / PhotoViewer.this.scale)), PhotoViewer.this.photoViewerWebView.getRight(), PhotoViewer.this.photoViewerWebView.getWebView().getBottom() + measuredHeight + ((int) (PhotoViewer.this.translationY / PhotoViewer.this.scale)));
            PhotoViewer.this.videoForwardDrawable.draw(canvas);
        }

        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            if (child == PhotoViewer.this.leftPaintingOverlay || child == PhotoViewer.this.rightPaintingOverlay) {
                return false;
            }
            if (child != PhotoViewer.this.navigationBar && (PhotoViewer.this.captionEdit == null || !((CaptionContainerView) PhotoViewer.this.captionEdit).editText.isPopupView(child))) {
                canvas.save();
            }
            boolean drawChildInternal = drawChildInternal(canvas, child, drawingTime);
            if (child != PhotoViewer.this.navigationBar && (PhotoViewer.this.captionEdit == null || !((CaptionContainerView) PhotoViewer.this.captionEdit).editText.isPopupView(child))) {
                canvas.restore();
            }
            return drawChildInternal;
        }

        public boolean drawChildInternal(Canvas canvas, View child, long drawingTime) {
            if (child == PhotoViewer.this.miniProgressView) {
                return false;
            }
            if (child == PhotoViewer.this.videoTimelineViewContainer && PhotoViewer.this.videoTimelineViewContainer.getTranslationY() > 0.0f && PhotoViewer.this.pickerView.getTranslationY() == 0.0f) {
                canvas.save();
                canvas.clipRect(PhotoViewer.this.videoTimelineViewContainer.getX(), PhotoViewer.this.videoTimelineViewContainer.getY(), PhotoViewer.this.videoTimelineViewContainer.getX() + PhotoViewer.this.videoTimelineViewContainer.getMeasuredWidth(), PhotoViewer.this.videoTimelineViewContainer.getBottom());
                boolean drawChild = super/*android.widget.FrameLayout*/.drawChild(canvas, child, drawingTime);
                canvas.restore();
                return drawChild;
            }
            try {
                if (child == PhotoViewer.this.aspectRatioFrameLayout || child == PhotoViewer.this.paintingOverlay) {
                    return false;
                }
                return super/*android.widget.FrameLayout*/.drawChild(canvas, child, drawingTime);
            } catch (Throwable unused) {
                return true;
            }
        }

        public void requestLayout() {
            if (this.ignoreLayout) {
                return;
            }
            super/*android.widget.FrameLayout*/.requestLayout();
        }

        public void onAttachedToWindow() {
            super/*org.telegram.ui.Components.SizeNotifierFrameLayout*/.onAttachedToWindow();
            Bulletin.addDelegate(this, new Bulletin.Delegate() {
                public boolean allowLayoutChanges() {
                    return Bulletin.Delegate.-CC.$default$allowLayoutChanges(this);
                }

                public boolean bottomOffsetAnimated() {
                    return Bulletin.Delegate.-CC.$default$bottomOffsetAnimated(this);
                }

                public boolean clipWithGradient(int i) {
                    return Bulletin.Delegate.-CC.$default$clipWithGradient(this, i);
                }

                public int getTopOffset(int i) {
                    return Bulletin.Delegate.-CC.$default$getTopOffset(this, i);
                }

                public void onBottomOffsetChange(float f) {
                    Bulletin.Delegate.-CC.$default$onBottomOffsetChange(this, f);
                }

                public void onHide(Bulletin bulletin) {
                    Bulletin.Delegate.-CC.$default$onHide(this, bulletin);
                }

                public void onShow(Bulletin bulletin) {
                    Bulletin.Delegate.-CC.$default$onShow(this, bulletin);
                }

                public int getBottomOffset(int tag) {
                    int height;
                    int i = 0;
                    if (PhotoViewer.this.editing) {
                        if (PhotoViewer.this.captionEdit != null && PhotoViewer.this.captionEdit.getVisibility() == 0) {
                            i = 0 + PhotoViewer.this.captionEdit.getEditTextHeight() + AndroidUtilities.dp(12.0f);
                        }
                        if (PhotoViewer.this.pickerView == null || PhotoViewer.this.pickerView.getVisibility() != 0) {
                            return i;
                        }
                        height = PhotoViewer.this.pickerView.getHeight();
                    } else {
                        if (PhotoViewer.this.bottomLayout != null && PhotoViewer.this.bottomLayout.getVisibility() == 0) {
                            i = 0 + PhotoViewer.this.bottomLayout.getHeight();
                        }
                        if (PhotoViewer.this.groupedPhotosListView == null || !PhotoViewer.this.groupedPhotosListView.hasPhotos()) {
                            return i;
                        }
                        if (!AndroidUtilities.isTablet() && PhotoViewer.this.containerView.getMeasuredHeight() <= PhotoViewer.this.containerView.getMeasuredWidth()) {
                            return i;
                        }
                        height = PhotoViewer.this.groupedPhotosListView.getHeight();
                    }
                    return i + height;
                }
            });
        }

        public void onDetachedFromWindow() {
            super/*org.telegram.ui.Components.SizeNotifierFrameLayout*/.onDetachedFromWindow();
            Bulletin.removeDelegate(this);
        }

        public void notifyHeightChanged() {
            super.notifyHeightChanged();
            if (PhotoViewer.this.isCurrentVideo) {
                PhotoViewer.this.photoProgressViews[0].setIndexedAlpha(2, getKeyboardHeight() <= AndroidUtilities.dp(20.0f) ? 1.0f : 0.0f, true);
            }
        }
    }

    static {
        String str = "progress";
        if (Build.VERSION.SDK_INT >= 24) {
            VPC_PROGRESS = new FloatProperty<VideoPlayerControlFrameLayout>(str) {
                @Override
                public void setValue(VideoPlayerControlFrameLayout object, float value) {
                    object.setProgress(value);
                }

                @Override
                public Float get(VideoPlayerControlFrameLayout object) {
                    return Float.valueOf(object.getProgress());
                }
            };
        } else {
            VPC_PROGRESS = new Property<VideoPlayerControlFrameLayout, Float>(Float.class, str) {
                @Override
                public void set(VideoPlayerControlFrameLayout object, Float value) {
                    object.setProgress(value.floatValue());
                }

                @Override
                public Float get(VideoPlayerControlFrameLayout object) {
                    return Float.valueOf(object.getProgress());
                }
            };
        }
        Instance = null;
        PipInstance = null;
    }

    public class VideoPlayerControlFrameLayout extends FrameLayout {
        public boolean ignoreLayout;
        public int lastTimeWidth;
        public int parentHeight;
        public int parentWidth;
        public float progress;
        public boolean seekBarTransitionEnabled;
        public SpringAnimation timeSpring;
        public FloatValueHolder timeValue;
        public boolean translationYAnimationEnabled;

        public void lambda$new$0(DynamicAnimation dynamicAnimation, float f, float f2) {
            PhotoViewer.this.videoPlayerSeekbar.setSize((int) (((getMeasuredWidth() - AndroidUtilities.dp(16.0f)) - f) - (this.parentWidth > this.parentHeight ? AndroidUtilities.dp(48.0f) : 0)), getMeasuredHeight());
        }

        public VideoPlayerControlFrameLayout(Context context) {
            super(context);
            this.progress = 1.0f;
            this.translationYAnimationEnabled = true;
            this.timeValue = new FloatValueHolder(0.0f);
            this.timeSpring = new SpringAnimation(this.timeValue).setSpring(new SpringForce(0.0f).setStiffness(750.0f).setDampingRatio(1.0f)).addUpdateListener(new DynamicAnimation.OnAnimationUpdateListener() {
                public final void onAnimationUpdate(DynamicAnimation dynamicAnimation, float f, float f2) {
                    PhotoViewer.VideoPlayerControlFrameLayout.this.lambda$new$0(dynamicAnimation, f, f2);
                }
            });
            setWillNotDraw(false);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (this.progress < 1.0f) {
                return false;
            }
            if (PhotoViewer.this.videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(2.0f), event.getY())) {
                getParent().requestDisallowInterceptTouchEvent(true);
                PhotoViewer.this.videoPlayerSeekbarView.invalidate();
            }
            return true;
        }

        @Override
        public void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            this.timeValue.setValue(0.0f);
            this.lastTimeWidth = 0;
        }

        @Override
        public void requestLayout() {
            if (this.ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int i;
            String format;
            this.ignoreLayout = true;
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) PhotoViewer.this.videoPlayerTime.getLayoutParams();
            if (this.parentWidth > this.parentHeight) {
                if (PhotoViewer.this.exitFullscreenButton.getVisibility() != 0) {
                    PhotoViewer.this.exitFullscreenButton.setVisibility(0);
                }
                i = AndroidUtilities.dp(48.0f);
                layoutParams.rightMargin = AndroidUtilities.dp(47.0f);
            } else {
                if (PhotoViewer.this.exitFullscreenButton.getVisibility() != 4) {
                    PhotoViewer.this.exitFullscreenButton.setVisibility(4);
                }
                layoutParams.rightMargin = AndroidUtilities.dp(12.0f);
                i = 0;
            }
            this.ignoreLayout = false;
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            long j = 0;
            if (PhotoViewer.this.videoPlayer != null) {
                long duration = PhotoViewer.this.videoPlayer.getDuration();
                if (duration != -9223372036854775807L) {
                    j = duration;
                }
            } else if (PhotoViewer.this.photoViewerWebView != null && PhotoViewer.this.photoViewerWebView.isControllable()) {
                j = PhotoViewer.this.photoViewerWebView.getVideoDuration();
            }
            long j2 = j / 1000;
            long j3 = j2 / 60;
            if (j3 > 60) {
                format = String.format(Locale.ROOT, "%02d:%02d:%02d", Long.valueOf(j3 / 60), Long.valueOf(j3 % 60), Long.valueOf(j2 % 60));
            } else {
                format = String.format(Locale.ROOT, "%02d:%02d", Long.valueOf(j3), Long.valueOf(j2 % 60));
            }
            int ceil = (int) Math.ceil(PhotoViewer.this.videoPlayerTime.getPaint().measureText(String.format(Locale.ROOT, "%1$s / %1$s", format)));
            this.timeSpring.cancel();
            if (this.lastTimeWidth != 0) {
                float f = ceil;
                if (this.timeValue.getValue() != f) {
                    this.timeSpring.getSpring().setFinalPosition(f);
                    this.timeSpring.start();
                    this.lastTimeWidth = ceil;
                }
            }
            PhotoViewer.this.videoPlayerSeekbar.setSize(((getMeasuredWidth() - AndroidUtilities.dp(16.0f)) - ceil) - i, getMeasuredHeight());
            this.timeValue.setValue(ceil);
            this.lastTimeWidth = ceil;
        }

        @Override
        public void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            float currentPosition = PhotoViewer.this.videoPlayer != null ? PhotoViewer.this.videoPlayer.getCurrentPosition() / PhotoViewer.this.videoPlayer.getDuration() : 0.0f;
            if (PhotoViewer.this.playerWasReady) {
                PhotoViewer.this.videoPlayerSeekbar.setProgress(currentPosition);
            }
            PhotoViewer.this.videoTimelineView.setProgress(currentPosition);
        }

        public float getProgress() {
            return this.progress;
        }

        public void setProgress(float progress) {
            if (this.progress != progress) {
                this.progress = progress;
                onProgressChanged(progress);
            }
        }

        public final void onProgressChanged(float progress) {
            PhotoViewer.this.videoPlayerTime.setAlpha(progress);
            PhotoViewer.this.exitFullscreenButton.setAlpha(progress);
            if (this.seekBarTransitionEnabled) {
                PhotoViewer.this.videoPlayerTime.setPivotX(PhotoViewer.this.videoPlayerTime.getWidth());
                PhotoViewer.this.videoPlayerTime.setPivotY(PhotoViewer.this.videoPlayerTime.getHeight());
                float f = 1.0f - progress;
                float f2 = 1.0f - (0.1f * f);
                PhotoViewer.this.videoPlayerTime.setScaleX(f2);
                PhotoViewer.this.videoPlayerTime.setScaleY(f2);
                PhotoViewer.this.videoPlayerSeekbar.setTransitionProgress(f);
                return;
            }
            if (this.translationYAnimationEnabled) {
                setTranslationY(AndroidUtilities.dpf2(24.0f) * (1.0f - progress));
            }
            PhotoViewer.this.videoPlayerSeekbarView.setAlpha(progress);
        }

        public void setSeekBarTransitionEnabled(boolean seekBarTransitionEnabled) {
            if (this.seekBarTransitionEnabled != seekBarTransitionEnabled) {
                this.seekBarTransitionEnabled = seekBarTransitionEnabled;
                if (seekBarTransitionEnabled) {
                    setTranslationY(0.0f);
                    PhotoViewer.this.videoPlayerSeekbarView.setAlpha(1.0f);
                } else {
                    PhotoViewer.this.videoPlayerTime.setScaleX(1.0f);
                    PhotoViewer.this.videoPlayerTime.setScaleY(1.0f);
                    PhotoViewer.this.videoPlayerSeekbar.setTransitionProgress(0.0f);
                }
                onProgressChanged(this.progress);
            }
        }

        public void setTranslationYAnimationEnabled(boolean translationYAnimationEnabled) {
            if (this.translationYAnimationEnabled != translationYAnimationEnabled) {
                this.translationYAnimationEnabled = translationYAnimationEnabled;
                if (!translationYAnimationEnabled) {
                    setTranslationY(0.0f);
                }
                onProgressChanged(this.progress);
            }
        }
    }

    public static class CaptionTextViewSwitcher extends TextViewSwitcher {
        public float alpha;
        public FrameLayout container;
        public boolean inScrollView;
        public NestedScrollView scrollView;

        public CaptionTextViewSwitcher(Context context) {
            super(context);
            this.inScrollView = false;
            this.alpha = 1.0f;
        }

        public void setScrollView(NestedScrollView scrollView) {
            this.scrollView = scrollView;
        }

        public void setContainer(FrameLayout container) {
            this.container = container;
        }

        public void setVisibility(int visibility) {
            setVisibility(visibility, true);
        }

        public void setVisibility(int visibility, boolean withScrollView) {
            super/*android.widget.ViewSwitcher*/.setVisibility(visibility);
            if (this.inScrollView && withScrollView) {
                this.scrollView.setVisibility(visibility);
            }
        }

        public void setAlpha(float alpha) {
            this.alpha = alpha;
            if (this.inScrollView) {
                this.scrollView.setAlpha(alpha);
            } else {
                super/*android.widget.ViewSwitcher*/.setAlpha(alpha);
            }
        }

        public float getAlpha() {
            if (this.inScrollView) {
                return this.alpha;
            }
            return super/*android.widget.ViewSwitcher*/.getAlpha();
        }

        public void setTranslationY(float translationY) {
            super/*android.widget.ViewSwitcher*/.setTranslationY(translationY);
            if (this.inScrollView) {
                this.scrollView.invalidate();
            }
        }

        public void onAttachedToWindow() {
            super/*android.widget.ViewSwitcher*/.onAttachedToWindow();
            if (this.container == null || getParent() != this.container) {
                return;
            }
            this.inScrollView = true;
            this.scrollView.setVisibility(getVisibility());
            this.scrollView.setAlpha(this.alpha);
            super/*android.widget.ViewSwitcher*/.setAlpha(1.0f);
        }

        public void onDetachedFromWindow() {
            super/*android.widget.ViewSwitcher*/.onDetachedFromWindow();
            if (this.inScrollView) {
                this.inScrollView = false;
                this.scrollView.setVisibility(8);
                super/*android.widget.ViewSwitcher*/.setAlpha(this.alpha);
            }
        }
    }

    public static class CaptionScrollView extends NestedScrollView {
        public Method abortAnimatedScrollMethod;
        public float backgroundAlpha;
        public final FrameLayout captionContainer;
        public final CaptionTextViewSwitcher captionTextViewSwitcher;
        public boolean dontChangeTopMargin;
        public boolean isLandscape;
        public boolean nestedScrollStarted;
        public float overScrollY;
        public final Paint paint;
        public int pendingTopMargin;
        public int prevHeight;
        public OverScroller scroller;
        public final SpringAnimation springAnimation;
        public int textHash;
        public float velocitySign;
        public float velocityY;

        public float getBottomFadingEdgeStrength() {
            return 1.0f;
        }

        public float getTopFadingEdgeStrength() {
            return 1.0f;
        }

        public boolean isStatusBarVisible() {
            return true;
        }

        public void onScrollEnd() {
        }

        public void onScrollStart() {
        }

        public void onScrollUpdate() {
        }

        public CaptionScrollView(Context context, CaptionTextViewSwitcher switcher, FrameLayout container) {
            super(context);
            Paint paint = new Paint(1);
            this.paint = paint;
            this.backgroundAlpha = 1.0f;
            this.pendingTopMargin = -1;
            this.captionTextViewSwitcher = switcher;
            this.captionContainer = container;
            setClipChildren(false);
            setOverScrollMode(2);
            paint.setColor(-16777216);
            setFadingEdgeLength(AndroidUtilities.dp(12.0f));
            setVerticalFadingEdgeEnabled(true);
            setWillNotDraw(false);
            SpringAnimation springAnimation = new SpringAnimation(switcher, DynamicAnimation.TRANSLATION_Y, 0.0f);
            this.springAnimation = springAnimation;
            springAnimation.getSpring().setStiffness(100.0f);
            springAnimation.setMinimumVisibleChange(1.0f);
            springAnimation.addUpdateListener(new DynamicAnimation.OnAnimationUpdateListener() {
                public final void onAnimationUpdate(DynamicAnimation dynamicAnimation, float f, float f2) {
                    PhotoViewer.CaptionScrollView.this.lambda$new$0(dynamicAnimation, f, f2);
                }
            });
            springAnimation.addEndListener(new DynamicAnimation.OnAnimationEndListener() {
                public final void onAnimationEnd(DynamicAnimation dynamicAnimation, boolean z, float f, float f2) {
                    PhotoViewer.CaptionScrollView.this.lambda$new$1(dynamicAnimation, z, f, f2);
                }
            });
            springAnimation.getSpring().setDampingRatio(1.0f);
            try {
                Method declaredMethod = NestedScrollView.class.getDeclaredMethod("abortAnimatedScroll", new Class[0]);
                this.abortAnimatedScrollMethod = declaredMethod;
                declaredMethod.setAccessible(true);
            } catch (Exception e) {
                this.abortAnimatedScrollMethod = null;
                FileLog.e(e);
            }
            try {
                Field declaredField = NestedScrollView.class.getDeclaredField("mScroller");
                declaredField.setAccessible(true);
                this.scroller = (OverScroller) declaredField.get(this);
            } catch (Exception e2) {
                this.scroller = null;
                FileLog.e(e2);
            }
        }

        public void lambda$new$0(DynamicAnimation dynamicAnimation, float f, float f2) {
            this.overScrollY = f;
            this.velocityY = f2;
            onScrollUpdate();
        }

        public void lambda$new$1(DynamicAnimation dynamicAnimation, boolean z, float f, float f2) {
            onScrollEnd();
        }

        public boolean onTouchEvent(MotionEvent ev) {
            if (ev.getAction() != 0 || ev.getY() >= (this.captionContainer.getTop() - getScrollY()) + this.captionTextViewSwitcher.getTranslationY()) {
                return super.onTouchEvent(ev);
            }
            return false;
        }

        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            updateTopMargin(View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(heightMeasureSpec));
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }

        public void applyPendingTopMargin() {
            this.dontChangeTopMargin = false;
            if (this.pendingTopMargin >= 0) {
                ((ViewGroup.MarginLayoutParams) this.captionContainer.getLayoutParams()).topMargin = this.pendingTopMargin;
                this.pendingTopMargin = -1;
                requestLayout();
            }
        }

        public int getPendingMarginTopDiff() {
            int i = this.pendingTopMargin;
            if (i >= 0) {
                return i - ((ViewGroup.MarginLayoutParams) this.captionContainer.getLayoutParams()).topMargin;
            }
            return 0;
        }

        public void updateTopMargin() {
            updateTopMargin(getWidth(), getHeight());
        }

        public final void updateTopMargin(int width, int height) {
            int calculateNewContainerMarginTop = calculateNewContainerMarginTop(width, height);
            if (calculateNewContainerMarginTop >= 0) {
                if (this.dontChangeTopMargin) {
                    this.pendingTopMargin = calculateNewContainerMarginTop;
                } else {
                    ((ViewGroup.MarginLayoutParams) this.captionContainer.getLayoutParams()).topMargin = calculateNewContainerMarginTop;
                    this.pendingTopMargin = -1;
                }
            }
        }

        public int calculateNewContainerMarginTop(int width, int height) {
            int dp;
            if (width == 0 || height == 0) {
                return -1;
            }
            TextView currentView = this.captionTextViewSwitcher.getCurrentView();
            CharSequence text = currentView.getText();
            int hashCode = text.hashCode();
            Point point = AndroidUtilities.displaySize;
            boolean z = point.x > point.y;
            if (this.textHash == hashCode && this.isLandscape == z && this.prevHeight == height) {
                return -1;
            }
            this.textHash = hashCode;
            this.isLandscape = z;
            this.prevHeight = height;
            currentView.measure(View.MeasureSpec.makeMeasureSpec(width, 1073741824), View.MeasureSpec.makeMeasureSpec(height, Integer.MIN_VALUE));
            Layout layout = currentView.getLayout();
            int lineCount = layout.getLineCount();
            if ((z && lineCount <= 2) || (!z && lineCount <= 5)) {
                dp = currentView.getMeasuredHeight();
            } else {
                int min = Math.min(z ? 2 : 5, lineCount);
                loop0: while (min > 1) {
                    int i = min - 1;
                    for (int lineStart = layout.getLineStart(i); lineStart < layout.getLineEnd(i); lineStart++) {
                        if (!Character.isWhitespace(text.charAt(lineStart))) {
                            break loop0;
                        }
                    }
                    min--;
                }
                height -= currentView.getPaint().getFontMetricsInt(null) * min;
                dp = AndroidUtilities.dp(8.0f);
            }
            return height - dp;
        }

        public void reset() {
            scrollTo(0, 0);
        }

        public void stopScrolling() {
            Method method = this.abortAnimatedScrollMethod;
            if (method != null) {
                try {
                    method.invoke(this, new Object[0]);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        }

        public void fling(int velocityY) {
            super.fling(velocityY);
            this.velocitySign = Math.signum(velocityY);
            this.velocityY = 0.0f;
        }

        public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow, int type) {
            consumed[1] = 0;
            if (this.nestedScrollStarted) {
                float f = this.overScrollY;
                if ((f > 0.0f && dy > 0) || (f < 0.0f && dy < 0)) {
                    float f2 = dy;
                    float f3 = f - f2;
                    if (f > 0.0f) {
                        if (f3 < 0.0f) {
                            this.overScrollY = 0.0f;
                            consumed[1] = (int) (consumed[1] + f2 + f3);
                        } else {
                            this.overScrollY = f3;
                            consumed[1] = consumed[1] + dy;
                        }
                    } else if (f3 > 0.0f) {
                        this.overScrollY = 0.0f;
                        consumed[1] = (int) (consumed[1] + f2 + f3);
                    } else {
                        this.overScrollY = f3;
                        consumed[1] = consumed[1] + dy;
                    }
                    onScrollUpdate();
                    this.captionTextViewSwitcher.setTranslationY(this.overScrollY);
                    return true;
                }
            }
            return false;
        }

        public void dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type, int[] consumed) {
            float f;
            if (dyUnconsumed != 0) {
                int round = Math.round(dyUnconsumed * (1.0f - Math.abs((-this.overScrollY) / (this.captionContainer.getTop() - ((isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight())))));
                if (round != 0) {
                    if (!this.nestedScrollStarted) {
                        if (!this.springAnimation.isRunning()) {
                            OverScroller overScroller = this.scroller;
                            float currVelocity = overScroller != null ? overScroller.getCurrVelocity() : Float.NaN;
                            if (Float.isNaN(currVelocity)) {
                                f = 0.0f;
                            } else {
                                Point point = AndroidUtilities.displaySize;
                                float min = Math.min(point.x > point.y ? 3000.0f : 5000.0f, currVelocity);
                                round = (int) ((round * min) / currVelocity);
                                f = min * (-this.velocitySign);
                            }
                            if (round != 0) {
                                float f2 = this.overScrollY - round;
                                this.overScrollY = f2;
                                this.captionTextViewSwitcher.setTranslationY(f2);
                            }
                            startSpringAnimationIfNotRunning(f);
                        }
                    } else {
                        float f3 = this.overScrollY - round;
                        this.overScrollY = f3;
                        this.captionTextViewSwitcher.setTranslationY(f3);
                    }
                }
                onScrollUpdate();
            }
        }

        public final void startSpringAnimationIfNotRunning(float velocityY) {
            if (this.springAnimation.isRunning()) {
                return;
            }
            this.springAnimation.setStartVelocity(velocityY);
            this.springAnimation.start();
        }

        public boolean startNestedScroll(int axes, int type) {
            if (type == 0) {
                this.springAnimation.cancel();
                this.nestedScrollStarted = true;
                this.overScrollY = this.captionTextViewSwitcher.getTranslationY();
                onScrollStart();
            }
            return true;
        }

        public void computeScroll() {
            OverScroller overScroller;
            super.computeScroll();
            if (!this.nestedScrollStarted && this.overScrollY != 0.0f && (overScroller = this.scroller) != null && overScroller.isFinished()) {
                startSpringAnimationIfNotRunning(0.0f);
            }
            onScrollUpdate();
        }

        public void stopNestedScroll(int type) {
            OverScroller overScroller;
            if (this.nestedScrollStarted && type == 0) {
                this.nestedScrollStarted = false;
                if (this.overScrollY != 0.0f && (overScroller = this.scroller) != null && overScroller.isFinished()) {
                    startSpringAnimationIfNotRunning(this.velocityY);
                }
                onScrollEnd();
            }
        }

        public void draw(Canvas canvas) {
            int width = getWidth();
            int height = getHeight();
            int scrollY = getScrollY();
            int save = canvas.save();
            int i = height + scrollY;
            canvas.clipRect(0, scrollY, width, i);
            this.paint.setAlpha((int) (this.backgroundAlpha * 127.0f));
            canvas.drawRect(0.0f, this.captionContainer.getTop() + this.captionTextViewSwitcher.getTranslationY(), width, i, this.paint);
            super.draw(canvas);
            canvas.restoreToCount(save);
        }
    }

    public static PhotoViewer getPipInstance() {
        return PipInstance;
    }

    public static PhotoViewer getInstance() {
        PhotoViewer photoViewer = Instance;
        if (photoViewer == null) {
            synchronized (PhotoViewer.class) {
                photoViewer = Instance;
                if (photoViewer == null) {
                    photoViewer = new PhotoViewer();
                    Instance = photoViewer;
                }
            }
        }
        return photoViewer;
    }

    public boolean isOpenedFullScreenVideo() {
        return this.openedFullScreenVideo;
    }

    public static boolean hasInstance() {
        return Instance != null;
    }

    public PhotoViewer() {
        this.ALLOW_USE_SURFACE = Build.VERSION.SDK_INT >= 30;
        this.maxSelectedPhotos = -1;
        this.allowOrder = true;
        this.miniProgressShowRunnable = new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$new$0();
            }
        };
        this.isActionBarVisible = true;
        this.closePhotoAfterSelect = true;
        this.actionBarItemsVisibility = new HashMap(3);
        this.backgroundDrawable = new BackgroundDrawable(-16777216);
        this.blackPaint = new Paint();
        this.photoProgressViews = new PhotoProgressView[3];
        this.onUserLeaveHintListener = new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.onUserLeaveHint();
            }
        };
        this.pressedDrawable = new GradientDrawable[2];
        this.drawPressedDrawable = new boolean[2];
        this.pressedDrawableAlpha = new float[2];
        this.cropTransform = new CropTransform();
        this.leftCropTransform = new CropTransform();
        this.rightCropTransform = new CropTransform();
        this.shiftDp = -8.0f;
        this.bitmapPaint = new Paint(2);
        this.insets = new Rect();
        this.setLoadingRunnable = new Runnable() {
            @Override
            public void run() {
                if (PhotoViewer.this.currentMessageObject == null) {
                    return;
                }
                FileLoader.getInstance(PhotoViewer.this.currentMessageObject.currentAccount).setLoadingVideo(PhotoViewer.this.currentMessageObject.getDocument(), true, false);
            }
        };
        this.hideActionBarRunnable = new Runnable() {
            @Override
            public void run() {
                if (PhotoViewer.this.videoPlayerControlVisible && PhotoViewer.this.isPlaying && !ApplicationLoader.mainInterfacePaused) {
                    if (PhotoViewer.this.menuItem == null || !PhotoViewer.this.menuItem.isSubMenuShowing()) {
                        if (PhotoViewer.this.captionScrollView == null || PhotoViewer.this.captionScrollView.getScrollY() == 0) {
                            if (PhotoViewer.this.miniProgressView == null || PhotoViewer.this.miniProgressView.getVisibility() != 0) {
                                PhotoViewer photoViewer = PhotoViewer.PipInstance;
                                PhotoViewer photoViewer2 = PhotoViewer.this;
                                if (photoViewer == photoViewer2) {
                                    return;
                                }
                                photoViewer2.toggleActionBar(false, true);
                            }
                        }
                    }
                }
            }
        };
        this.savedVideoPositions = new ArrayMap<>();
        this.videoPlayerControlVisible = true;
        this.videoPlayerCurrentTime = new int[2];
        this.videoPlayerTotalTime = new int[2];
        this.fullscreenButton = new ImageView[3];
        this.pipPosition = new int[2];
        this.pipVideoOverlayAnimateFlag = true;
        this.lastImageId = -1;
        this.prevOrientation = -10;
        this.videoPlayerRewinder = new VideoPlayerRewinder() {
            public void onRewindCanceled() {
                PhotoViewer.this.onTouchEvent(MotionEvent.obtain(0L, 0L, 3, 0.0f, 0.0f, 0));
                PhotoViewer.this.videoForwardDrawable.setShowing(false);
                PipVideoOverlay.onRewindCanceled();
            }

            public void updateRewindProgressUi(long timeDiff, float progress, boolean rewindByBackSeek) {
                PhotoViewer.this.videoForwardDrawable.setTime(Math.abs(timeDiff));
                if (rewindByBackSeek) {
                    PhotoViewer.this.videoPlayerSeekbar.setProgress(progress);
                    PhotoViewer.this.videoPlayerSeekbarView.invalidate();
                }
                PipVideoOverlay.onUpdateRewindProgressUi(timeDiff, progress, rewindByBackSeek);
            }

            public void onRewindStart(boolean rewindForward) {
                PhotoViewer.this.videoForwardDrawable.setOneShootAnimation(false);
                PhotoViewer.this.videoForwardDrawable.setLeftSide(!rewindForward);
                PhotoViewer.this.videoForwardDrawable.setShowing(true);
                PhotoViewer.this.containerView.invalidate();
                PipVideoOverlay.onRewindStart(rewindForward);
            }
        };
        this.FLASH_VIEW_VALUE = new AnimationProperties.FloatProperty<View>("flashViewAlpha") {
            public void setValue(View object, float value) {
                object.setAlpha(value);
                if (PhotoViewer.this.photoCropView != null) {
                    PhotoViewer.this.photoCropView.setVideoThumbFlashAlpha(value);
                }
            }

            public Float get(View object) {
                return Float.valueOf(object.getAlpha());
            }
        };
        this.updateProgressRunnable = new AnonymousClass5();
        this.switchToInlineRunnable = new Runnable() {
            @Override
            public void run() {
                if (PipVideoOverlay.isVisible()) {
                    PipVideoOverlay.dismiss();
                    AndroidUtilities.runOnUIThread(this, 250L);
                    return;
                }
                PhotoViewer.this.switchingInlineMode = false;
                if (PhotoViewer.this.currentBitmap != null) {
                    PhotoViewer.this.currentBitmap.recycle();
                    PhotoViewer.this.currentBitmap = null;
                }
                PhotoViewer.this.changingTextureView = true;
                TextureViewContainer textureViewContainer = new TextureViewContainer(PhotoViewer.this.parentActivity);
                try {
                    if (PhotoViewer.this.usedSurfaceView) {
                        Drawable drawable = PhotoViewer.this.textureImageView.getDrawable();
                        if (drawable instanceof BitmapDrawable) {
                            PhotoViewer.this.currentBitmap = ((BitmapDrawable) drawable).getBitmap();
                        } else {
                            PhotoViewer photoViewer = PhotoViewer.this;
                            photoViewer.currentBitmap = Bitmaps.createBitmap(photoViewer.videoSurfaceView.getWidth(), PhotoViewer.this.videoSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
                            AndroidUtilities.getBitmapFromSurface(PhotoViewer.this.videoSurfaceView, PhotoViewer.this.currentBitmap);
                        }
                    } else {
                        PhotoViewer photoViewer2 = PhotoViewer.this;
                        photoViewer2.currentBitmap = Bitmaps.createBitmap(photoViewer2.videoTextureView.getWidth(), PhotoViewer.this.videoTextureView.getHeight(), Bitmap.Config.ARGB_8888);
                        PhotoViewer.this.videoTextureView.getBitmap(PhotoViewer.this.currentBitmap);
                    }
                } catch (Throwable th) {
                    if (PhotoViewer.this.currentBitmap != null) {
                        PhotoViewer.this.currentBitmap.recycle();
                        PhotoViewer.this.currentBitmap = null;
                    }
                    FileLog.e(th);
                }
                if (PhotoViewer.this.currentBitmap != null) {
                    if (PhotoViewer.this.textureImageView != null) {
                        PhotoViewer.this.textureImageView.setVisibility(0);
                        PhotoViewer.this.textureImageView.setImageBitmap(PhotoViewer.this.currentBitmap);
                    }
                    textureViewContainer.imageReceiver.setImageBitmap(PhotoViewer.this.currentBitmap);
                }
                PhotoViewer.this.isInline = true;
                PhotoViewer.this.changedTextureView = textureViewContainer.textureView;
                if (PipVideoOverlay.show(false, PhotoViewer.this.parentActivity, textureViewContainer, PhotoViewer.this.videoWidth, PhotoViewer.this.videoHeight, PhotoViewer.this.pipVideoOverlayAnimateFlag)) {
                    PipVideoOverlay.setPhotoViewer(PhotoViewer.this);
                }
                PhotoViewer.this.pipVideoOverlayAnimateFlag = true;
                if (PhotoViewer.this.usedSurfaceView) {
                    if (PhotoViewer.this.aspectRatioFrameLayout != null) {
                        PhotoViewer.this.aspectRatioFrameLayout.removeView(PhotoViewer.this.videoTextureView);
                        PhotoViewer.this.aspectRatioFrameLayout.removeView(PhotoViewer.this.videoSurfaceView);
                    }
                    PhotoViewer.this.videoPlayer.setSurfaceView((SurfaceView) null);
                    PhotoViewer.this.videoPlayer.setTextureView((TextureView) null);
                    PhotoViewer.this.videoPlayer.play();
                    PhotoViewer.this.videoPlayer.setTextureView(PhotoViewer.this.changedTextureView);
                    PhotoViewer.this.checkChangedTextureView(true);
                    PhotoViewer.this.changedTextureView.setVisibility(0);
                    return;
                }
                PhotoViewer.this.changedTextureView.setVisibility(4);
                if (PhotoViewer.this.aspectRatioFrameLayout != null) {
                    PhotoViewer.this.aspectRatioFrameLayout.removeView(PhotoViewer.this.videoTextureView);
                    PhotoViewer.this.aspectRatioFrameLayout.removeView(PhotoViewer.this.videoSurfaceView);
                }
            }
        };
        this.surfaceTextureListener = new TextureView.SurfaceTextureListener() {
            @Override
            public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
            }

            @Override
            public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
            }

            @Override
            public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
                if (PhotoViewer.this.videoTextureView == null || !PhotoViewer.this.changingTextureView) {
                    return true;
                }
                if (PhotoViewer.this.switchingInlineMode) {
                    PhotoViewer.this.waitingForFirstTextureUpload = 2;
                }
                PhotoViewer.this.videoTextureView.setSurfaceTexture(surface);
                PhotoViewer.this.videoTextureView.setVisibility(0);
                PhotoViewer.this.changingTextureView = false;
                PhotoViewer.this.containerView.invalidate();
                return false;
            }

            @Override
            public void onSurfaceTextureUpdated(SurfaceTexture surface) {
                if (PhotoViewer.this.waitingForFirstTextureUpload == 1) {
                    PhotoViewer.this.checkChangedTextureView(true);
                }
            }
        };
        this.animationValues = (float[][]) Array.newInstance((Class<?>) float.class, 2, 13);
        this.updateContainerFlagsRunnable = new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$new$5();
            }
        };
        this.leftImage = new ImageReceiver();
        this.centerImage = new ImageReceiver() {
            public boolean setImageBitmapByKey(Drawable drawable, String key, int type, boolean memCache, int guid) {
                boolean imageBitmapByKey = super.setImageBitmapByKey(drawable, key, type, memCache, guid);
                PhotoViewer.this.prepareSegmentImage();
                return imageBitmapByKey;
            }
        };
        this.rightImage = new ImageReceiver();
        this.leftBlur = new BlurringShader.ThumbBlurer(1, new PhotoViewer$$ExternalSyntheticLambda72(this));
        this.centerBlur = new BlurringShader.ThumbBlurer(1, new PhotoViewer$$ExternalSyntheticLambda72(this));
        this.rightBlur = new BlurringShader.ThumbBlurer(1, new PhotoViewer$$ExternalSyntheticLambda72(this));
        this.centerImageTransformLocked = false;
        this.centerImageTransform = new Matrix();
        this.videoFrameBitmapPaint = new Paint();
        this.videoFrameBitmap = null;
        this.editState = new EditState();
        this.currentFileNames = new String[3];
        this.endReached = new boolean[]{false, true};
        this.scale = 1.0f;
        this.rotate = 0.0f;
        this.mirror = 0.0f;
        this.switchingToMode = -1;
        this.interpolator = new DecelerateInterpolator(1.5f);
        this.pinchStartScale = 1.0f;
        this.pinchStartRotate = 0.0f;
        this.canZoom = true;
        this.canDragDown = true;
        this.shownControlsByEnd = false;
        this.actionBarWasShownBeforeByEnd = false;
        this.imagesArrTemp = new ArrayList<>();
        this.imagesByIdsTemp = new SparseArray[]{new SparseArray<>(), new SparseArray<>()};
        this.imagesArr = new ArrayList<>();
        this.imagesByIds = new SparseArray[]{new SparseArray<>(), new SparseArray<>()};
        this.imagesArrLocations = new ArrayList<>();
        this.imagesArrLocationsVideo = new ArrayList<>();
        this.imagesArrLocationsSizes = new ArrayList<>();
        this.imagesArrMessages = new ArrayList<>();
        this.secureDocuments = new ArrayList<>();
        this.avatarsArr = new ArrayList<>();
        this.imagesArrLocals = new ArrayList<>();
        this.currentAvatarLocation = null;
        this.savedState = null;
        this.hitRect = new Rect();
        this.photoQualityLayoutSize = 30;
        this.transitionNotificationLocker = new AnimationNotificationsLocker(new int[]{NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoad, NotificationCenter.mediaDidLoad, NotificationCenter.dialogPhotosUpdate});
        this.longPressRunnable = new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.onLongPress();
            }
        };
        this.tempInt = new int[2];
        this.captureFrameAtTime = -1L;
        this.captureFrameReadyAtTime = -1L;
        this.needCaptureFrameReadyAtTime = -1L;
        this.compressionsCount = -1;
        this.blurAlpha = new AnimatedFloat(new PhotoViewer$$ExternalSyntheticLambda72(this), 180L, CubicBezierInterpolator.EASE_OUT);
        this.blackPaint.setColor(-16777216);
        this.videoFrameBitmapPaint.setColor(-1);
        this.centerImage.setFileLoadingPriority(3);
    }

    public void didReceivedNotification(int r32, int r33, java.lang.Object... r34) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.didReceivedNotification(int, int, java.lang.Object[]):void");
    }

    public final void showDownloadAlert() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this.parentActivity, this.resourcesProvider);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        MessageObject messageObject = this.currentMessageObject;
        boolean z = false;
        if (messageObject != null && messageObject.isVideo() && FileLoader.getInstance(this.currentMessageObject.currentAccount).isLoadingFile(this.currentFileNames[0])) {
            z = true;
        }
        if (z) {
            builder.setMessage(LocaleController.getString("PleaseStreamDownload", R.string.PleaseStreamDownload));
        } else {
            builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
        }
        showAlertDialog(builder);
    }

    public final void onSharePressed() {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onSharePressed():void");
    }

    public final void setScaleToFill() {
        float bitmapWidth = this.centerImage.getBitmapWidth();
        float bitmapHeight = this.centerImage.getBitmapHeight();
        if (bitmapWidth == 0.0f || bitmapHeight == 0.0f) {
            return;
        }
        float containerViewWidth = getContainerViewWidth();
        float containerViewHeight = getContainerViewHeight();
        float min = Math.min(containerViewHeight / bitmapHeight, containerViewWidth / bitmapWidth);
        float max = Math.max(containerViewWidth / ((int) (bitmapWidth * min)), containerViewHeight / ((int) (bitmapHeight * min)));
        this.scale = max;
        updateMinMax(max);
    }

    public void setParentAlert(ChatAttachAlert alert) {
        this.parentAlert = alert;
    }

    public void setParentActivity(Activity activity) {
        setParentActivity(activity, null, null);
    }

    public void setParentActivity(Activity activity, Theme.ResourcesProvider resourcesProvider) {
        setParentActivity(activity, null, resourcesProvider);
    }

    public void setParentActivity(BaseFragment fragment) {
        setParentActivity(fragment, (Theme.ResourcesProvider) null);
    }

    public void setParentActivity(BaseFragment fragment, Theme.ResourcesProvider resourcesProvider) {
        setParentActivity(null, fragment, resourcesProvider);
    }

    public void setParentActivity(Activity inActivity, BaseFragment fragment, final Theme.ResourcesProvider resourcesProvider) {
        GradientDrawable.Orientation orientation;
        final Activity parentActivity = inActivity != null ? inActivity : fragment.getParentActivity();
        int i = 0;
        Theme.createChatResources(parentActivity, false);
        this.resourcesProvider = resourcesProvider;
        this.parentFragment = fragment;
        int i2 = UserConfig.selectedAccount;
        this.currentAccount = i2;
        this.centerImage.setCurrentAccount(i2);
        this.leftImage.setCurrentAccount(this.currentAccount);
        this.rightImage.setCurrentAccount(this.currentAccount);
        CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
        if (captionPhotoViewer != null) {
            captionPhotoViewer.setAccount(this.currentAccount);
        }
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView != null) {
            stickerMakerView.setCurrentAccount(this.currentAccount);
        }
        if (this.parentActivity == parentActivity || parentActivity == null) {
            updateColors();
            return;
        }
        this.inBubbleMode = parentActivity instanceof BubbleActivity;
        this.parentActivity = parentActivity;
        this.activityContext = new ContextThemeWrapper(this.parentActivity, R.style.Theme_TMessages);
        this.touchSlop = ViewConfiguration.get(this.parentActivity).getScaledTouchSlop();
        boolean z = true;
        if (progressDrawables == null) {
            progressDrawables = new Drawable[]{ContextCompat.getDrawable(this.parentActivity, R.drawable.circle_big), ContextCompat.getDrawable(this.parentActivity, R.drawable.cancel_big), ContextCompat.getDrawable(this.parentActivity, R.drawable.load_big)};
        }
        this.scroller = new Scroller(parentActivity);
        AnonymousClass13 anonymousClass13 = new AnonymousClass13(parentActivity);
        this.windowView = anonymousClass13;
        anonymousClass13.setBackgroundDrawable(this.backgroundDrawable);
        this.windowView.setFocusable(false);
        ClippingImageView clippingImageView = new ClippingImageView(parentActivity);
        this.animatingImageView = clippingImageView;
        clippingImageView.setAnimationValues(this.animationValues);
        this.windowView.addView((View) this.animatingImageView, (ViewGroup.LayoutParams) LayoutHelper.createFrame(40, 40.0f));
        ?? r0 = new FrameLayoutDrawer(parentActivity, parentActivity) {
            public int getBottomPadding() {
                return PhotoViewer.this.pickerView.getHeight();
            }

            public boolean dispatchTouchEvent(MotionEvent ev) {
                PhotoViewer.this.textSelectionHelper.getOverlayView(getContext()).checkCancelAction(ev);
                if (PhotoViewer.this.textSelectionHelper.isInSelectionMode()) {
                    PhotoViewer.this.textSelectionHelper.getOverlayView(getContext()).onTouchEvent(ev);
                    return true;
                }
                return super/*android.widget.FrameLayout*/.dispatchTouchEvent(ev);
            }

            @Override
            public boolean drawChild(Canvas canvas, View child, long drawingTime) {
                if (child == PhotoViewer.this.textSelectionHelper.getOverlayView(PhotoViewer.this.windowView.getContext()) || child == PhotoViewer.this.stickerMakerBackgroundView) {
                    return false;
                }
                return super.drawChild(canvas, child, drawingTime);
            }

            public void dispatchDraw(Canvas canvas) {
                super/*org.telegram.ui.Components.SizeNotifierFrameLayout*/.dispatchDraw(canvas);
                PhotoViewer.this.textSelectionHelper.getOverlayView(PhotoViewer.this.windowView.getContext()).draw(canvas);
            }

            @Override
            public void onLayout(boolean changed, int _l, int t, int _r, int _b) {
                if (PhotoViewer.this.btnLayout != null && PhotoViewer.this.undoBtn != null) {
                    int dp = (_r - _l) - AndroidUtilities.dp(20.0f);
                    PhotoViewer.this.undoBtn.setTranslationY(((-dp) / 2.0f) - AndroidUtilities.dp(47.0f));
                    float f = dp / 2.0f;
                    PhotoViewer.this.btnLayout.setTranslationY(AndroidUtilities.dp(47.0f) + f);
                    PhotoViewer.this.cutOutBtn.setTranslationY(AndroidUtilities.dp(47.0f) + f);
                    PhotoViewer.this.outlineBtn.setTranslationY(f + AndroidUtilities.dp(95.0f));
                }
                super.onLayout(changed, _l, t, _r, _b);
            }
        };
        this.containerView = r0;
        r0.setFocusable(false);
        this.containerView.setClipChildren(true);
        this.containerView.setClipToPadding(true);
        this.windowView.setClipChildren(false);
        this.windowView.setClipToPadding(false);
        BlurringShader.BlurManager blurManager = new BlurringShader.BlurManager(this.containerView);
        this.blurManager = blurManager;
        blurManager.padding = 1;
        this.shadowBlurer = new BlurringShader.StoryBlurDrawer(blurManager, this.containerView, 6);
        this.windowView.addView((View) this.containerView, LayoutHelper.createFrame(-1, -1, 51));
        int i3 = Build.VERSION.SDK_INT;
        if (i3 >= 21) {
            this.containerView.setFitsSystemWindows(true);
            this.containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                @Override
                public final WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                    WindowInsets lambda$setParentActivity$6;
                    lambda$setParentActivity$6 = PhotoViewer.this.lambda$setParentActivity$6(view, windowInsets);
                    return lambda$setParentActivity$6;
                }
            });
            this.containerView.setSystemUiVisibility(1792);
        }
        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        this.windowLayoutParams = layoutParams;
        layoutParams.height = -1;
        layoutParams.format = -3;
        layoutParams.width = -1;
        layoutParams.gravity = 51;
        layoutParams.type = 99;
        if (i3 >= 28) {
            layoutParams.layoutInDisplayCutoutMode = 1;
        }
        if (i3 >= 21) {
            layoutParams.flags = -2147286784;
        } else {
            layoutParams.flags = 131072;
        }
        View paintingOverlay = new PaintingOverlay(this.parentActivity);
        this.paintingOverlay = paintingOverlay;
        this.containerView.addView(paintingOverlay, LayoutHelper.createFrame(-2, -2.0f));
        View paintingOverlay2 = new PaintingOverlay(this.parentActivity);
        this.leftPaintingOverlay = paintingOverlay2;
        this.containerView.addView(paintingOverlay2, LayoutHelper.createFrame(-2, -2.0f));
        View paintingOverlay3 = new PaintingOverlay(this.parentActivity);
        this.rightPaintingOverlay = paintingOverlay3;
        this.containerView.addView(paintingOverlay3, LayoutHelper.createFrame(-2, -2.0f));
        ActionBar actionBar = new ActionBar(parentActivity) {
            @Override
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                PhotoViewer.this.containerView.invalidate();
            }
        };
        this.actionBar = actionBar;
        actionBar.setOverlayTitleAnimation(true);
        this.actionBar.setTitleColor(-1);
        this.actionBar.setSubtitleColor(-1);
        this.actionBar.setBackgroundColor(2130706432);
        this.actionBar.setOccupyStatusBar(isStatusBarVisible());
        this.actionBar.setItemsBackgroundColor(1090519039, false);
        this.actionBar.setItemsColor(-1, false);
        ActionBar actionBar2 = this.actionBar;
        int i4 = R.drawable.ic_ab_back;
        actionBar2.setBackButtonImage(i4);
        if (Theme.usePlusTheme) {
            Drawable drawable = this.parentActivity.getResources().getDrawable(i4);
            SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("theme", 0);
            drawable.setColorFilter(Theme.chatHeaderIconsColor, PorterDuff.Mode.MULTIPLY);
            this.actionBar.setBackButtonDrawable(drawable);
            int i5 = sharedPreferences.getInt("chatHeaderGradient", 0);
            if (i5 > 0) {
                if (i5 == 2) {
                    orientation = GradientDrawable.Orientation.LEFT_RIGHT;
                } else if (i5 == 3) {
                    orientation = GradientDrawable.Orientation.TL_BR;
                } else if (i5 == 4) {
                    orientation = GradientDrawable.Orientation.BL_TR;
                } else {
                    orientation = GradientDrawable.Orientation.TOP_BOTTOM;
                }
                this.actionBar.setBackgroundDrawable(new GradientDrawable(orientation, new int[]{Theme.chatHeaderColor, sharedPreferences.getInt("chatHeaderGradientColor", Theme.defColor)}));
            }
        }
        PhotoViewerActionBarContainer photoViewerActionBarContainer = new PhotoViewerActionBarContainer(parentActivity);
        this.actionBarContainer = photoViewerActionBarContainer;
        this.actionBar.addView(photoViewerActionBarContainer, LayoutHelper.createFrame(-1, -1, 119));
        this.containerView.addView(this.actionBar, LayoutHelper.createFrame(-1, -2.0f));
        PhotoCountView photoCountView = new PhotoCountView(parentActivity);
        this.countView = photoCountView;
        this.containerView.addView(photoCountView, LayoutHelper.createFrame(-1, -2, 55));
        this.actionBar.setActionBarMenuOnItemClick(new AnonymousClass16(resourcesProvider));
        ActionBarMenu createMenu = this.actionBar.createMenu();
        this.menu = createMenu;
        createMenu.setOnLayoutListener(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.updateActionBarTitlePadding();
            }
        });
        ActionBarMenuItem addItem = this.menu.addItem(13, R.drawable.msg_mask);
        this.masksItem = addItem;
        addItem.setContentDescription(LocaleController.getString("Masks", R.string.Masks));
        ActionBarMenuItem addItem2 = this.menu.addItem(5, R.drawable.ic_goinline);
        this.pipItem = addItem2;
        addItem2.setContentDescription(LocaleController.getString("AccDescrPipMode", R.string.AccDescrPipMode));
        ActionBarMenuItem addItem3 = this.menu.addItem(30, R.drawable.msg_forward);
        this.sendNoQuoteItem = addItem3;
        addItem3.setContentDescription(LocaleController.getString("ForwardNoQuote", R.string.ForwardNoQuote));
        ActionBarMenuItem addItem4 = this.menu.addItem(20, R.drawable.msg_header_draw);
        this.editItem = addItem4;
        addItem4.setContentDescription(LocaleController.getString("AccDescrPhotoEditor", R.string.AccDescrPhotoEditor));
        ActionBarMenuItem addItem5 = this.menu.addItem(3, R.drawable.msg_forward_quote);
        this.sendItem = addItem5;
        addItem5.setContentDescription(LocaleController.getString("Forward", R.string.Forward));
        ActionBarMenu actionBarMenu = this.menu;
        OptionsSpeedIconDrawable optionsSpeedIconDrawable = new OptionsSpeedIconDrawable();
        this.menuItemIcon = optionsSpeedIconDrawable;
        ActionBarMenuItem addItem6 = actionBarMenu.addItem(0, (Drawable) optionsSpeedIconDrawable);
        this.menuItem = addItem6;
        addItem6.setOnMenuDismiss(new Utilities.Callback() {
            public final void run(Object obj) {
                PhotoViewer.this.lambda$setParentActivity$7((Boolean) obj);
            }
        });
        this.menuItem.getPopupLayout().swipeBackGravityRight = true;
        this.chooseSpeedLayout = new ChooseSpeedLayout(this.activityContext, this.menuItem.getPopupLayout().getSwipeBack(), new ChooseSpeedLayout.Callback() {
            @Override
            public void onSpeedSelected(float speed, boolean isFinal, boolean closeMenu) {
                if (speed != PhotoViewer.this.currentVideoSpeed) {
                    PhotoViewer.this.currentVideoSpeed = speed;
                    if (PhotoViewer.this.currentMessageObject != null) {
                        SharedPreferences sharedPreferences2 = ApplicationLoader.applicationContext.getSharedPreferences("playback_speed", 0);
                        if (Math.abs(PhotoViewer.this.currentVideoSpeed - 1.0f) < 0.001f) {
                            sharedPreferences2.edit().remove("speed" + PhotoViewer.this.currentMessageObject.getDialogId() + "_" + PhotoViewer.this.currentMessageObject.getId()).commit();
                        } else {
                            sharedPreferences2.edit().putFloat("speed" + PhotoViewer.this.currentMessageObject.getDialogId() + "_" + PhotoViewer.this.currentMessageObject.getId(), PhotoViewer.this.currentVideoSpeed).commit();
                        }
                    }
                    if (PhotoViewer.this.videoPlayer != null) {
                        PhotoViewer.this.videoPlayer.setPlaybackSpeed(PhotoViewer.this.currentVideoSpeed);
                    }
                    if (PhotoViewer.this.photoViewerWebView != null) {
                        PhotoViewer.this.photoViewerWebView.setPlaybackSpeed(PhotoViewer.this.currentVideoSpeed);
                    }
                }
                PhotoViewer.this.setMenuItemIcon(true, isFinal);
                if (closeMenu) {
                    PhotoViewer.this.menuItem.toggleSubMenu();
                }
            }
        });
        this.speedItem = this.menuItem.addSwipeBackItem(R.drawable.msg_speed, null, LocaleController.getString("Speed", R.string.Speed), this.chooseSpeedLayout.speedSwipeBackLayout);
        this.menuItem.getPopupLayout().setSwipeBackForegroundColor(-14540254);
        this.speedItem.setSubtext(LocaleController.getString("SpeedNormal", R.string.SpeedNormal));
        this.speedItem.setColors(-328966, -328966);
        ActionBarPopupWindow.GapView addColoredGap = this.menuItem.addColoredGap();
        this.speedGap = addColoredGap;
        addColoredGap.setColor(-15198184);
        this.menuItem.getPopupLayout().setFitItems(true);
        this.menuItem.addSubItem(11, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp)).setColors(-328966, -328966);
        this.menuItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
        ActionBarMenuSubItem addSubItem = this.menuItem.addSubItem(2, R.drawable.msg_media, LocaleController.getString(R.string.ShowAllMedia));
        this.allMediaItem = addSubItem;
        addSubItem.setColors(-328966, -328966);
        this.menuItem.addSubItem(14, R.drawable.msg_gif, LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs)).setColors(-328966, -328966);
        this.menuItem.addSubItem(4, R.drawable.msg_message, LocaleController.getString("ShowInChat", R.string.ShowInChat)).setColors(-328966, -328966);
        this.menuItem.addSubItem(15, R.drawable.msg_sticker, LocaleController.getString("ShowStickers", R.string.ShowStickers)).setColors(-328966, -328966);
        this.menuItem.addSubItem(10, R.drawable.msg_shareout, LocaleController.getString("ShareFile", R.string.ShareFile)).setColors(-328966, -328966);
        this.menuItem.addSubItem(1, R.drawable.msg_gallery, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setColors(-328966, -328966);
        this.menuItem.addSubItem(16, R.drawable.msg_openprofile, LocaleController.getString("SetAsMain", R.string.SetAsMain)).setColors(-328966, -328966);
        ActionBarMenuItem actionBarMenuItem = this.menuItem;
        int i6 = R.drawable.msg_translate;
        actionBarMenuItem.addSubItem(21, i6, LocaleController.getString(R.string.TranslateMessage)).setColors(-328966, -328966);
        this.menuItem.addSubItem(22, i6, LocaleController.getString(R.string.HideTranslation)).setColors(-328966, -328966);
        this.menuItem.addSubItem(6, R.drawable.msg_delete, LocaleController.getString("Delete", R.string.Delete)).setColors(-328966, -328966);
        this.menuItem.addSubItem(7, R.drawable.msg_cancel, LocaleController.getString("StopDownload", R.string.StopDownload)).setColors(-328966, -328966);
        this.menuItem.redrawPopup(-115203550);
        this.menuItem.hideSubItem(21);
        this.menuItem.hideSubItem(22);
        setMenuItemIcon(false, true);
        this.menuItem.setPopupItemsSelectorColor(268435455);
        this.menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {
            @Override
            public void onShowSubMenu() {
                if (PhotoViewer.this.videoPlayerControlVisible && PhotoViewer.this.isPlaying) {
                    AndroidUtilities.cancelRunOnUIThread(PhotoViewer.this.hideActionBarRunnable);
                }
            }

            @Override
            public void onHideSubMenu() {
                if (PhotoViewer.this.videoPlayerControlVisible && PhotoViewer.this.isPlaying) {
                    PhotoViewer.this.scheduleActionBarHide();
                }
            }
        });
        FrameLayout frameLayout = new FrameLayout(this, this.activityContext) {
            @Override
            public void dispatchDraw(Canvas canvas) {
                super.dispatchDraw(canvas);
            }
        };
        this.bottomLayout = frameLayout;
        frameLayout.setBackgroundColor(2130706432);
        this.containerView.addView(this.bottomLayout, LayoutHelper.createFrame(-1, 48, 83));
        View view = new View(this.activityContext);
        this.navigationBar = view;
        view.setBackgroundColor(this.sendPhotoType == 11 ? -16777216 : 2130706432);
        this.windowView.addView(this.navigationBar, LayoutHelper.createFrame(-1.0f, this.navigationBarHeight / AndroidUtilities.density, 87));
        this.pressedDrawable[0] = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[]{838860800, 0});
        this.pressedDrawable[0].setShape(0);
        this.pressedDrawable[1] = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, new int[]{838860800, 0});
        this.pressedDrawable[1].setShape(0);
        View groupedPhotosListView = new GroupedPhotosListView(this.activityContext, AndroidUtilities.dp(10.0f));
        this.groupedPhotosListView = groupedPhotosListView;
        this.containerView.addView(groupedPhotosListView, LayoutHelper.createFrame(-1, 68, 83));
        this.groupedPhotosListView.setDelegate(new GroupedPhotosListView.GroupedPhotosListViewDelegate() {
            public int getCurrentIndex() {
                return PhotoViewer.this.currentIndex;
            }

            public int getCurrentAccount() {
                return PhotoViewer.this.currentAccount;
            }

            public long getAvatarsDialogId() {
                return PhotoViewer.this.avatarsDialogId;
            }

            public int getSlideshowMessageId() {
                return PhotoViewer.this.slideshowMessageId;
            }

            public ArrayList<ImageLocation> getImagesArrLocations() {
                return PhotoViewer.this.imagesArrLocations;
            }

            public ArrayList<MessageObject> getImagesArr() {
                return PhotoViewer.this.imagesArr;
            }

            public List<TLRPC.PageBlock> getPageBlockArr() {
                if (PhotoViewer.this.pageBlocksAdapter != null) {
                    return PhotoViewer.this.pageBlocksAdapter.getAll();
                }
                return null;
            }

            public Object getParentObject() {
                if (PhotoViewer.this.pageBlocksAdapter != null) {
                    return PhotoViewer.this.pageBlocksAdapter.getParentObject();
                }
                return null;
            }

            public void setCurrentIndex(int index) {
                PhotoViewer.this.currentIndex = -1;
                if (PhotoViewer.this.currentThumb != null) {
                    PhotoViewer.this.currentThumb.release();
                    PhotoViewer.this.currentThumb = null;
                }
                PhotoViewer.this.dontAutoPlay = true;
                PhotoViewer.this.setImageIndex(index);
                PhotoViewer.this.dontAutoPlay = false;
            }

            public void onShowAnimationStart() {
                PhotoViewer.this.containerView.requestLayout();
            }

            public void onStopScrolling() {
                PhotoViewer photoViewer = PhotoViewer.this;
                if (photoViewer.shouldMessageObjectAutoPlayed(photoViewer.currentMessageObject)) {
                    PhotoViewer.this.playerAutoStarted = true;
                    PhotoViewer.this.onActionClick(true);
                    PhotoViewer.this.checkProgress(0, false, true);
                }
            }
        });
        for (int i7 = 0; i7 < 3; i7++) {
            this.fullscreenButton[i7] = new ImageView(this.parentActivity);
            this.fullscreenButton[i7].setImageResource(R.drawable.msg_maxvideo);
            this.fullscreenButton[i7].setContentDescription(LocaleController.getString("AccSwitchToFullscreen", R.string.AccSwitchToFullscreen));
            this.fullscreenButton[i7].setScaleType(ImageView.ScaleType.CENTER);
            this.fullscreenButton[i7].setBackground(Theme.createSelectorDrawable(1090519039));
            this.fullscreenButton[i7].setVisibility(4);
            this.fullscreenButton[i7].setAlpha(1.0f);
            this.containerView.addView(this.fullscreenButton[i7], LayoutHelper.createFrame(48, 48.0f));
            this.fullscreenButton[i7].setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view2) {
                    PhotoViewer.this.lambda$setParentActivity$8(view2);
                }
            });
        }
        this.textSelectionHelper = new TextSelectionHelper.SimpleTextSelectionHelper(this, null, new DarkThemeResourceProvider()) {
            @Override
            public int getParentBottomPadding() {
                return 0;
            }
        };
        ?? captionTextViewSwitcher = new CaptionTextViewSwitcher(this.containerView.getContext());
        this.captionTextViewSwitcher = captionTextViewSwitcher;
        captionTextViewSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
            @Override
            public final View makeView() {
                View lambda$setParentActivity$9;
                lambda$setParentActivity$9 = PhotoViewer.this.lambda$setParentActivity$9();
                return lambda$setParentActivity$9;
            }
        });
        this.captionTextViewSwitcher.setVisibility(4);
        setCaptionHwLayerEnabled(true);
        for (int i8 = 0; i8 < 3; i8++) {
            this.photoProgressViews[i8] = new PhotoProgressView(this.containerView) {
                @Override
                public void onBackgroundStateUpdated(int state) {
                    if (this == PhotoViewer.this.photoProgressViews[0]) {
                        PhotoViewer.this.updateAccessibilityOverlayVisibility();
                    }
                }

                @Override
                public void onVisibilityChanged(boolean visible) {
                    if (this == PhotoViewer.this.photoProgressViews[0]) {
                        PhotoViewer.this.updateAccessibilityOverlayVisibility();
                    }
                }
            };
            this.photoProgressViews[i8].setBackgroundState(0, false, true);
        }
        RadialProgressView radialProgressView = new RadialProgressView(this.activityContext, resourcesProvider) {
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                if (PhotoViewer.this.containerView != null) {
                    PhotoViewer.this.containerView.invalidate();
                }
            }

            public void invalidate() {
                super/*android.view.View*/.invalidate();
                if (PhotoViewer.this.containerView != null) {
                    PhotoViewer.this.containerView.invalidate();
                }
            }
        };
        this.miniProgressView = radialProgressView;
        radialProgressView.setUseSelfAlpha(true);
        this.miniProgressView.setProgressColor(-1);
        this.miniProgressView.setSize(AndroidUtilities.dp(54.0f));
        RadialProgressView radialProgressView2 = this.miniProgressView;
        int i9 = R.drawable.circle_big;
        radialProgressView2.setBackgroundResource(i9);
        this.miniProgressView.setVisibility(4);
        this.miniProgressView.setAlpha(0.0f);
        this.containerView.addView(this.miniProgressView, LayoutHelper.createFrame(64, 64, 17));
        createVideoControlsInterface();
        RadialProgressView radialProgressView3 = new RadialProgressView(this.parentActivity, resourcesProvider);
        this.progressView = radialProgressView3;
        radialProgressView3.setProgressColor(-1);
        this.progressView.setBackgroundResource(i9);
        this.progressView.setVisibility(4);
        this.containerView.addView(this.progressView, LayoutHelper.createFrame(54, 54, 17));
        PickerBottomLayoutViewer pickerBottomLayoutViewer = new PickerBottomLayoutViewer(this.parentActivity);
        this.qualityPicker = pickerBottomLayoutViewer;
        pickerBottomLayoutViewer.setBackgroundColor(2130706432);
        this.qualityPicker.updateSelectedCount(0, false);
        this.qualityPicker.setTranslationY(AndroidUtilities.dp(120.0f));
        this.qualityPicker.doneButton.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
        TextView textView = this.qualityPicker.doneButton;
        int i10 = Theme.key_chat_editMediaButton;
        textView.setTextColor(getThemedColor(i10));
        this.containerView.addView(this.qualityPicker, LayoutHelper.createFrame(-1, 48, 83));
        this.qualityPicker.cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$10(view2);
            }
        });
        this.qualityPicker.doneButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$11(view2);
            }
        });
        VideoForwardDrawable videoForwardDrawable = new VideoForwardDrawable(false);
        this.videoForwardDrawable = videoForwardDrawable;
        videoForwardDrawable.setDelegate(new VideoForwardDrawable.VideoForwardDrawableDelegate() {
            public void onAnimationEnd() {
            }

            public void invalidate() {
                PhotoViewer.this.containerView.invalidate();
            }
        });
        QualityChooseView qualityChooseView = new QualityChooseView(this.parentActivity);
        this.qualityChooseView = qualityChooseView;
        qualityChooseView.setTranslationY(AndroidUtilities.dp(120.0f));
        this.qualityChooseView.setVisibility(4);
        this.qualityChooseView.setBackgroundColor(2130706432);
        this.containerView.addView(this.qualityChooseView, LayoutHelper.createFrame(-1, 70.0f, 83, 0.0f, 0.0f, 0.0f, 48.0f));
        new Paint().setColor(2130706432);
        FrameLayout frameLayout2 = new FrameLayout(this.activityContext) {
            public final Paint bgPaint = new Paint(3);
            public final LinearGradient bgGradient = new LinearGradient(0.0f, 0.0f, 0.0f, 16.0f, new int[]{0, 2130706432}, new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP);
            public final Matrix bgMatrix = new Matrix();

            @Override
            public void dispatchDraw(Canvas canvas) {
                if (!PhotoViewer.this.fancyShadows) {
                    int measuredHeight = PhotoViewer.this.doneButtonFullWidth.getVisibility() == 0 ? getMeasuredHeight() - AndroidUtilities.dp(48.0f) : 0;
                    if (PhotoViewer.this.sendPhotoType == 0 || PhotoViewer.this.sendPhotoType == 2 || PhotoViewer.this.sendPhotoType == -1) {
                        this.bgMatrix.reset();
                        float min = Math.min(AndroidUtilities.dp(40.0f), getMeasuredHeight() - measuredHeight);
                        this.bgMatrix.postTranslate(0.0f, measuredHeight);
                        this.bgMatrix.postScale(1.0f, min / 16.0f);
                        this.bgGradient.setLocalMatrix(this.bgMatrix);
                        this.bgPaint.setShader(this.bgGradient);
                    } else {
                        this.bgPaint.setShader(null);
                        this.bgPaint.setColor(2130706432);
                    }
                    canvas.drawRect(0.0f, measuredHeight, getMeasuredWidth(), getMeasuredHeight(), this.bgPaint);
                }
                super.dispatchDraw(canvas);
            }

            @Override
            public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                ((FrameLayout.LayoutParams) PhotoViewer.this.itemsLayout.getLayoutParams()).rightMargin = PhotoViewer.this.pickerViewSendButton.getVisibility() == 0 ? AndroidUtilities.dp(70.0f) : 0;
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }

            @Override
            public void setTranslationY(float translationY) {
                super.setTranslationY(translationY);
                if (PhotoViewer.this.videoTimelineViewContainer != null && PhotoViewer.this.videoTimelineViewContainer.getVisibility() != 8) {
                    PhotoViewer.this.videoTimelineViewContainer.setTranslationY(translationY - Math.max(0, PhotoViewer.this.captionEdit.getEditTextHeight() - AndroidUtilities.dp(46.0f)));
                }
                if (PhotoViewer.this.captionEditContainer != null) {
                    PhotoViewer.this.captionEditContainer.setTranslationY(translationY);
                }
                if (PhotoViewer.this.videoAvatarTooltip == null || PhotoViewer.this.videoAvatarTooltip.getVisibility() == 8) {
                    return;
                }
                PhotoViewer.this.videoAvatarTooltip.setTranslationY(translationY);
            }

            @Override
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                if (PhotoViewer.this.videoTimelineViewContainer != null && PhotoViewer.this.videoTimelineViewContainer.getVisibility() != 8) {
                    PhotoViewer.this.videoTimelineViewContainer.setAlpha(alpha);
                }
                if (PhotoViewer.this.captionEdit == null || PhotoViewer.this.captionEdit.getVisibility() == 8) {
                    return;
                }
                PhotoViewer.this.captionEdit.setAlpha(alpha);
            }

            @Override
            public void setVisibility(int visibility) {
                super.setVisibility(visibility);
                if (PhotoViewer.this.videoTimelineViewContainer == null || PhotoViewer.this.videoTimelineViewContainer.getVisibility() == 8) {
                    return;
                }
                PhotoViewer.this.videoTimelineViewContainer.setVisibility(visibility == 0 ? 0 : 4);
            }

            @Override
            public void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);
                if (PhotoViewer.this.itemsLayout.getVisibility() != 8) {
                    int dp = (((right - left) - (PhotoViewer.this.pickerViewSendButton.getVisibility() == 0 ? AndroidUtilities.dp(70.0f) : 0)) - PhotoViewer.this.itemsLayout.getMeasuredWidth()) / 2;
                    PhotoViewer.this.itemsLayout.layout(dp, PhotoViewer.this.itemsLayout.getTop(), PhotoViewer.this.itemsLayout.getMeasuredWidth() + dp, PhotoViewer.this.itemsLayout.getTop() + PhotoViewer.this.itemsLayout.getMeasuredHeight());
                }
            }
        };
        this.pickerView = frameLayout2;
        this.containerView.addView(frameLayout2, LayoutHelper.createFrame(-1, -2, 83));
        TextView textView2 = new TextView(this.containerView.getContext());
        this.docNameTextView = textView2;
        textView2.setTextSize(1, 15.0f);
        this.docNameTextView.setTypeface(AndroidUtilities.bold());
        this.docNameTextView.setSingleLine(true);
        this.docNameTextView.setMaxLines(1);
        this.docNameTextView.setEllipsize(TextUtils.TruncateAt.END);
        this.docNameTextView.setTextColor(-1);
        this.docNameTextView.setGravity(3);
        this.pickerView.addView(this.docNameTextView, LayoutHelper.createFrame(-1, -2.0f, 51, 20.0f, 23.0f, 84.0f, 0.0f));
        TextView textView3 = new TextView(this.containerView.getContext());
        this.docInfoTextView = textView3;
        textView3.setTextSize(1, 14.0f);
        this.docInfoTextView.setSingleLine(true);
        this.docInfoTextView.setMaxLines(1);
        this.docInfoTextView.setEllipsize(TextUtils.TruncateAt.END);
        this.docInfoTextView.setTextColor(-1);
        this.docInfoTextView.setGravity(3);
        this.pickerView.addView(this.docInfoTextView, LayoutHelper.createFrame(-1, -2.0f, 51, 20.0f, 46.0f, 84.0f, 0.0f));
        TextView textView4 = new TextView(this.containerView.getContext());
        this.doneButtonFullWidth = textView4;
        int i11 = Theme.key_featuredStickers_addButton;
        textView4.setBackground(Theme.AdaptiveRipple.filledRect(getThemedColor(i11), 6.0f));
        TextView textView5 = this.doneButtonFullWidth;
        int i12 = Theme.key_featuredStickers_buttonText;
        textView5.setTextColor(getThemedColor(i12));
        this.doneButtonFullWidth.setEllipsize(TextUtils.TruncateAt.END);
        this.doneButtonFullWidth.setGravity(17);
        this.doneButtonFullWidth.setLines(1);
        this.doneButtonFullWidth.setSingleLine(true);
        this.doneButtonFullWidth.setText(LocaleController.getString("SetAsMyPhoto", R.string.SetAsMyPhoto));
        this.doneButtonFullWidth.setTextSize(1, 15.0f);
        this.doneButtonFullWidth.setTypeface(AndroidUtilities.bold());
        this.doneButtonFullWidth.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$12(view2);
            }
        });
        this.doneButtonFullWidth.setVisibility(8);
        this.pickerView.addView(this.doneButtonFullWidth, LayoutHelper.createFrame(-1, 48.0f, 51, 20.0f, 0.0f, 20.0f, 64.0f));
        VideoTimelinePlayView videoTimelinePlayView = new VideoTimelinePlayView(this.parentActivity) {
            public final BlurringShader.StoryBlurDrawer blur;

            public boolean customBlur() {
                return true;
            }

            {
                new Path();
                this.blur = new BlurringShader.StoryBlurDrawer(PhotoViewer.this.blurManager, this, 0);
            }

            public void setTranslationY(float translationY) {
                if (getTranslationY() != translationY) {
                    super/*android.view.View*/.setTranslationY(translationY);
                    PhotoViewer.this.containerView.invalidate();
                }
            }

            public void drawBlur(Canvas canvas, RectF rect) {
                canvas.save();
                canvas.clipRect(rect);
                canvas.translate((-getX()) - PhotoViewer.this.videoTimelineViewContainer.getX(), (-getY()) - PhotoViewer.this.videoTimelineViewContainer.getY());
                PhotoViewer.this.drawCaptionBlur(canvas, this.blur, -14803426, 855638016, false, true, false);
                canvas.restore();
            }

            public void invalidate() {
                if (SharedConfig.photoViewerBlur && (PhotoViewer.this.animationInProgress == 1 || PhotoViewer.this.animationInProgress == 2 || PhotoViewer.this.animationInProgress == 3)) {
                    return;
                }
                super/*android.view.View*/.invalidate();
            }
        };
        this.videoTimelineView = videoTimelinePlayView;
        videoTimelinePlayView.setDelegate(new AnonymousClass27());
        FrameLayout frameLayout3 = new FrameLayout(this.parentActivity);
        this.videoTimelineViewContainer = frameLayout3;
        frameLayout3.setClipChildren(false);
        this.videoTimelineViewContainer.addView((View) this.videoTimelineView, (ViewGroup.LayoutParams) LayoutHelper.createFrame(-1, 54, 83));
        showVideoTimeline(false, false);
        this.containerView.addView(this.videoTimelineViewContainer, LayoutHelper.createFrame(-1, 54.0f, 83, 0.0f, 8.0f, 0.0f, 0.0f));
        Context context = this.containerView.getContext();
        FrameLayout frameLayout4 = this.windowView;
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
        CaptionPhotoViewer captionPhotoViewer2 = new CaptionPhotoViewer(context, frameLayout4, sizeNotifierFrameLayoutPhoto, sizeNotifierFrameLayoutPhoto, resourcesProvider, this.blurManager, new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.applyCaption();
            }
        }) {
            public final Path path = new Path();

            public boolean customBlur() {
                return true;
            }

            public boolean ignoreTouches(float x, float y) {
                return (((CaptionContainerView) this).keyboardShown || PhotoViewer.this.currentEditMode == 0) ? false : true;
            }

            public void drawBlur(BlurringShader.StoryBlurDrawer blur, Canvas canvas, RectF rect, float r, boolean text, float ox, float oy, boolean thisView) {
                canvas.save();
                this.path.rewind();
                this.path.addRoundRect(rect, r, r, Path.Direction.CW);
                canvas.clipPath(this.path);
                if (thisView) {
                    canvas.translate(((-getX()) - PhotoViewer.this.captionEditContainer.getX()) + ox, ((-getY()) - PhotoViewer.this.captionEditContainer.getY()) + oy);
                } else {
                    canvas.translate(ox, oy);
                }
                PhotoViewer.this.drawCaptionBlur(canvas, blur, text ? -8882056 : -14277082, thisView ? text ? 0 : 855638016 : 1140850688, false, !text, !text && thisView);
                canvas.restore();
            }

            public boolean captionLimitToast() {
                if (PhotoViewer.this.limitBulletin != null && Bulletin.getVisibleBulletin() == PhotoViewer.this.limitBulletin) {
                    return false;
                }
                PhotoViewer photoViewer = PhotoViewer.this;
                return photoViewer.showCaptionLimitBulletin(photoViewer.containerView);
            }

            public void setupMentionContainer() {
                ((CaptionContainerView) this).mentionContainer.getAdapter().setAllowStickers(false);
                ((CaptionContainerView) this).mentionContainer.getAdapter().setAllowBots(false);
                ((CaptionContainerView) this).mentionContainer.getAdapter().setAllowChats(false);
                ((CaptionContainerView) this).mentionContainer.getAdapter().setSearchInDailogs(true);
                if (PhotoViewer.this.parentChatActivity != null) {
                    ((CaptionContainerView) this).mentionContainer.getAdapter().setChatInfo(PhotoViewer.this.parentChatActivity.chatInfo);
                    ((CaptionContainerView) this).mentionContainer.getAdapter().setNeedUsernames(PhotoViewer.this.parentChatActivity.currentChat != null);
                } else {
                    ((CaptionContainerView) this).mentionContainer.getAdapter().setChatInfo(null);
                    ((CaptionContainerView) this).mentionContainer.getAdapter().setNeedUsernames(false);
                }
                ((CaptionContainerView) this).mentionContainer.getAdapter().setNeedBotContext(false);
            }

            public void onUpdateShowKeyboard(float keyboardT) {
                super.onUpdateShowKeyboard(keyboardT);
                float f = 1.0f - keyboardT;
                PhotoViewer.this.muteItem.setAlpha((PhotoViewer.this.muteItem.getTag() != null ? 1 : 0) * f);
                PhotoViewer.this.videoTimelineViewContainer.setAlpha(f * (PhotoViewer.this.videoTimelineViewContainer.getTag() == null ? 0 : 1));
            }

            public void invalidate() {
                if (SharedConfig.photoViewerBlur && (PhotoViewer.this.animationInProgress == 1 || PhotoViewer.this.animationInProgress == 2 || PhotoViewer.this.animationInProgress == 3)) {
                    return;
                }
                super/*android.widget.FrameLayout*/.invalidate();
            }
        };
        this.captionEdit = captionPhotoViewer2;
        captionPhotoViewer2.setOnTimerChange(new Utilities.Callback() {
            public final void run(Object obj) {
                PhotoViewer.this.lambda$setParentActivity$13((Integer) obj);
            }
        });
        this.captionEdit.setAccount(this.currentAccount);
        this.captionEdit.setOnHeightUpdate(new Utilities.Callback() {
            public final void run(Object obj) {
                PhotoViewer.this.lambda$setParentActivity$14((Integer) obj);
            }
        });
        this.captionEdit.setOnAddPhotoClick(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$15(view2);
            }
        });
        StickerMakerBackgroundView stickerMakerBackgroundView = new StickerMakerBackgroundView(this.activityContext) {
            @Override
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                if (PhotoViewer.this.windowView != null) {
                    PhotoViewer.this.windowView.invalidate();
                }
            }
        };
        this.stickerMakerBackgroundView = stickerMakerBackgroundView;
        stickerMakerBackgroundView.setVisibility(8);
        this.containerView.addView(this.stickerMakerBackgroundView, LayoutHelper.createFrame(-1, -1.0f, 51, 0.0f, 0.0f, 0.0f, 0.0f));
        StickerMakerView stickerMakerView2 = new StickerMakerView(this.activityContext, resourcesProvider);
        this.stickerMakerView = stickerMakerView2;
        stickerMakerView2.setCurrentAccount(this.currentAccount);
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto2 = this.containerView;
        sizeNotifierFrameLayoutPhoto2.addView(this.stickerMakerView, sizeNotifierFrameLayoutPhoto2.indexOfChild(this.actionBar) - 1, LayoutHelper.createFrame(-1, -1.0f, 51, 0.0f, 0.0f, 0.0f, 0.0f));
        BlurButton blurButton = new BlurButton();
        this.cutOutBtn = blurButton;
        blurButton.setRad(18);
        this.cutOutBtn.wrapContentDynamic();
        this.stickerMakerView.setStickerCutOutBtn(this.cutOutBtn);
        this.cutOutBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$21(view2);
            }
        });
        this.cutOutBtn.setCutOutState(false);
        this.containerView.addView(this.cutOutBtn, LayoutHelper.createFrame(-1, 36, 17));
        LinearLayout linearLayout = new LinearLayout(this.parentActivity);
        this.btnLayout = linearLayout;
        linearLayout.setOrientation(0);
        BlurButton blurButton2 = new BlurButton();
        this.eraseBtn = blurButton2;
        blurButton2.wrapContent();
        this.eraseBtn.setRad(18);
        this.eraseBtn.setEraseState(false);
        this.eraseBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$22(view2);
            }
        });
        this.btnLayout.addView((View) this.eraseBtn, LayoutHelper.createLinear(-2, 36));
        this.btnLayout.addView(new Space(this.parentActivity), LayoutHelper.createLinear(12, -1));
        BlurButton blurButton3 = new BlurButton();
        this.restoreBtn = blurButton3;
        blurButton3.wrapContent();
        this.restoreBtn.setRad(18);
        this.restoreBtn.setRestoreState(false);
        this.restoreBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$23(view2);
            }
        });
        this.btnLayout.addView((View) this.restoreBtn, LayoutHelper.createLinear(-2, 36));
        this.containerView.addView(this.btnLayout, LayoutHelper.createFrame(-2, 36, 17));
        BlurButton blurButton4 = new BlurButton();
        this.undoBtn = blurButton4;
        blurButton4.setUndoState(false);
        this.undoBtn.setRad(18);
        this.undoBtn.wrapContent();
        this.undoBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$24(view2);
            }
        });
        this.containerView.addView(this.undoBtn, LayoutHelper.createFrame(-2, 36, 17));
        BlurButton blurButton5 = new BlurButton();
        this.outlineBtn = blurButton5;
        blurButton5.setOutlineState(false);
        this.outlineBtn.setRad(18);
        this.outlineBtn.wrapContent();
        this.outlineBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$25(view2);
            }
        });
        this.containerView.addView(this.outlineBtn, LayoutHelper.createFrame(-2, 36, 17));
        showEditCaption(false, false);
        showStickerMode(false, false);
        FrameLayout frameLayout5 = new FrameLayout(this.parentActivity) {
            @Override
            public void setTranslationY(float translationY) {
                super.setTranslationY(translationY);
                PhotoViewer.this.invalidateBlur();
            }
        };
        this.captionEditContainer = frameLayout5;
        frameLayout5.addView((View) this.captionEdit, (ViewGroup.LayoutParams) LayoutHelper.createFrame(-1, -1, 83));
        this.containerView.addView(this.captionEditContainer, LayoutHelper.createFrame(-1, -1.0f, 83, 0.0f, 8.0f, 0.0f, 0.0f));
        TextView textView6 = new TextView(this.parentActivity);
        this.videoAvatarTooltip = textView6;
        textView6.setSingleLine(true);
        this.videoAvatarTooltip.setVisibility(8);
        this.videoAvatarTooltip.setText(LocaleController.getString("ChooseCover", R.string.ChooseCover));
        this.videoAvatarTooltip.setGravity(1);
        this.videoAvatarTooltip.setTextSize(1, 14.0f);
        this.videoAvatarTooltip.setTextColor(-7566196);
        this.containerView.addView(this.videoAvatarTooltip, LayoutHelper.createFrame(-1, -2.0f, 83, 0.0f, 8.0f, 0.0f, 0.0f));
        ImageView imageView = new ImageView(this.parentActivity);
        this.pickerViewSendButton = imageView;
        imageView.setScaleType(ImageView.ScaleType.CENTER);
        int dp = AndroidUtilities.dp(48.0f);
        int themedColor = getThemedColor(i10);
        int i13 = Build.VERSION.SDK_INT;
        Drawable createSimpleSelectorCircleDrawable = Theme.createSimpleSelectorCircleDrawable(dp, themedColor, getThemedColor(i13 >= 21 ? Theme.key_dialogFloatingButtonPressed : i10));
        this.pickerViewSendDrawable = createSimpleSelectorCircleDrawable;
        this.pickerViewSendButton.setBackgroundDrawable(createSimpleSelectorCircleDrawable);
        this.pickerViewSendButton.setImageResource(R.drawable.msg_input_send_mini);
        this.pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
        this.containerView.addView(this.pickerViewSendButton, LayoutHelper.createFrame(48, 48.0f, 85, 0.0f, 0.0f, 14.0f, 2.33f));
        this.pickerViewSendButton.setContentDescription(LocaleController.getString("Send", R.string.Send));
        ScaleStateListAnimator.apply(this.pickerViewSendButton);
        this.pickerViewSendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$26(view2);
            }
        });
        this.pickerViewSendButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public final boolean onLongClick(View view2) {
                boolean lambda$setParentActivity$32;
                lambda$setParentActivity$32 = PhotoViewer.this.lambda$setParentActivity$32(resourcesProvider, view2);
                return lambda$setParentActivity$32;
            }
        });
        FrameLayout frameLayout6 = new FrameLayout(this.parentActivity);
        this.photoQualityLayout = frameLayout6;
        frameLayout6.setVisibility(8);
        this.containerView.addView(this.photoQualityLayout, LayoutHelper.createFrame(-1, this.photoQualityLayoutSize, 80, 0.0f, 0.0f, 0.0f, 50.0f));
        SeekBar seekBar = new SeekBar(this.parentActivity);
        this.qualityBar = seekBar;
        seekBar.setPadding(AndroidUtilities.dp(20.0f), 0, AndroidUtilities.dp(75.0f), 0);
        this.qualityBar.setBackgroundColor(0);
        this.qualityBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(-1, PorterDuff.Mode.MULTIPLY));
        if (i13 >= 16) {
            this.qualityBar.getThumb().setColorFilter(-1, PorterDuff.Mode.SRC_IN);
        }
        this.qualityBar.setMax(100);
        this.qualityBar.setProgress(Theme.plusPhotoQuality);
        this.barQualityValue = Theme.plusPhotoQuality;
        this.photoQualityLayout.addView(this.qualityBar, LayoutHelper.createFrame(-1, -1, 3));
        TextView textView7 = new TextView(this.parentActivity);
        this.tvQuality = textView7;
        textView7.setPadding(0, 0, AndroidUtilities.dp(20.0f), 0);
        this.tvQuality.setBackgroundColor(0);
        TextView textView8 = this.tvQuality;
        StringBuilder sb = new StringBuilder();
        int i14 = this.barQualityValue;
        if (i14 > 100) {
            i14 = 100;
        }
        sb.append(String.valueOf(i14));
        sb.append("%");
        textView8.setText(sb.toString());
        this.tvQuality.setTextSize(1, 16.0f);
        this.tvQuality.setTextColor(-1);
        this.photoQualityLayout.addView(this.tvQuality, LayoutHelper.createFrame(-2, -1, 5));
        this.qualityBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onStartTrackingTouch(SeekBar seekBar2) {
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar2) {
                SharedPreferences.Editor edit = ApplicationLoader.applicationContext.getSharedPreferences("plusconfig", 0).edit();
                if (PhotoViewer.this.barQualityValue == 0) {
                    PhotoViewer.this.barQualityValue = 1;
                    PhotoViewer.this.qualityBar.setProgress(PhotoViewer.this.barQualityValue);
                    PhotoViewer.this.tvQuality.setText(String.valueOf(PhotoViewer.this.barQualityValue) + "%");
                }
                int i15 = PhotoViewer.this.barQualityValue;
                Theme.plusPhotoQuality = i15;
                edit.putInt("photoQuality", i15);
                edit.apply();
            }

            @Override
            public void onProgressChanged(SeekBar seekBar2, int progress, boolean fromUser) {
                PhotoViewer.this.barQualityValue = progress;
                PhotoViewer.this.tvQuality.setText(String.valueOf(PhotoViewer.this.barQualityValue) + "%");
            }
        });
        LinearLayout linearLayout2 = new LinearLayout(this.parentActivity) {
            @Override
            public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                int childCount = getChildCount();
                int i15 = 0;
                for (int i16 = 0; i16 < childCount; i16++) {
                    if (getChildAt(i16).getVisibility() == 0) {
                        i15++;
                    }
                }
                int size = View.MeasureSpec.getSize(widthMeasureSpec);
                int size2 = View.MeasureSpec.getSize(heightMeasureSpec);
                if (i15 != 0) {
                    int min = Math.min(AndroidUtilities.dp(70.0f), size / i15);
                    if (PhotoViewer.this.compressItem.getVisibility() == 0) {
                        int max = Math.max(0, (min - AndroidUtilities.dp(PhotoViewer.this.selectedCompression < 2 ? 48 : 64)) / 2);
                        PhotoViewer.this.compressItem.setPadding(max, 0, max, 0);
                    }
                    for (int i17 = 0; i17 < childCount; i17++) {
                        View childAt = getChildAt(i17);
                        if (childAt.getVisibility() != 8) {
                            childAt.measure(View.MeasureSpec.makeMeasureSpec(min, 1073741824), View.MeasureSpec.makeMeasureSpec(size2, 1073741824));
                        }
                    }
                    setMeasuredDimension(min * i15, size2);
                    return;
                }
                setMeasuredDimension(size, size2);
            }
        };
        this.itemsLayout = linearLayout2;
        linearLayout2.setOrientation(0);
        this.pickerView.addView(this.itemsLayout, LayoutHelper.createFrame(-2, 48.0f, 81, 0.0f, 0.0f, 70.0f, 0.0f));
        ImageView imageView2 = new ImageView(this.parentActivity);
        this.cropItem = imageView2;
        imageView2.setScaleType(ImageView.ScaleType.CENTER);
        this.cropItem.setImageResource(R.drawable.media_crop);
        this.cropItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.itemsLayout.addView(this.cropItem, LayoutHelper.createLinear(48, 48));
        this.cropItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$33(view2);
            }
        });
        this.cropItem.setContentDescription(LocaleController.getString("CropImage", R.string.CropImage));
        ImageView imageView3 = new ImageView(this.parentActivity);
        this.rotateItem = imageView3;
        imageView3.setScaleType(ImageView.ScaleType.CENTER);
        this.rotateItem.setImageResource(R.drawable.msg_photo_rotate);
        this.rotateItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.itemsLayout.addView(this.rotateItem, LayoutHelper.createLinear(48, 48));
        this.rotateItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$34(view2);
            }
        });
        this.rotateItem.setContentDescription(LocaleController.getString("AccDescrRotate", R.string.AccDescrRotate));
        ImageView imageView4 = new ImageView(this.parentActivity);
        this.mirrorItem = imageView4;
        imageView4.setScaleType(ImageView.ScaleType.CENTER);
        this.mirrorItem.setImageResource(R.drawable.media_flip);
        this.mirrorItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.itemsLayout.addView(this.mirrorItem, LayoutHelper.createLinear(48, 48));
        this.mirrorItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$35(view2);
            }
        });
        this.mirrorItem.setContentDescription(LocaleController.getString("AccDescrMirror", R.string.AccDescrMirror));
        ImageView imageView5 = new ImageView(this.parentActivity);
        this.paintItem = imageView5;
        imageView5.setScaleType(ImageView.ScaleType.CENTER);
        this.paintItem.setImageResource(R.drawable.media_draw);
        this.paintItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.itemsLayout.addView(this.paintItem, LayoutHelper.createLinear(48, 48));
        this.paintItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$36(view2);
            }
        });
        this.paintItem.setContentDescription(LocaleController.getString("AccDescrPhotoEditor", R.string.AccDescrPhotoEditor));
        ImageView imageView6 = new ImageView(this.parentActivity);
        this.muteItem = imageView6;
        imageView6.setScaleType(ImageView.ScaleType.CENTER);
        this.muteItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.containerView.addView(this.muteItem, LayoutHelper.createFrame(48, 48.0f, 83, 16.0f, 0.0f, 0.0f, 0.0f));
        this.muteItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$37(view2);
            }
        });
        VideoCompressButton videoCompressButton = new VideoCompressButton(this.parentActivity);
        this.compressItem = videoCompressButton;
        videoCompressButton.setTag(1);
        this.compressItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.selectedCompression = selectCompression();
        this.compressItem.setState(this.videoConvertSupported && this.compressionsCount > 1, this.muteVideo, Math.min(this.resultWidth, this.resultHeight));
        this.compressItem.setContentDescription(LocaleController.getString("AccDescrVideoQuality", R.string.AccDescrVideoQuality));
        this.itemsLayout.addView((View) this.compressItem, (ViewGroup.LayoutParams) LayoutHelper.createLinear(48, 48));
        this.compressItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$38(parentActivity, view2);
            }
        });
        ImageView imageView7 = new ImageView(this.parentActivity);
        this.tuneItem = imageView7;
        imageView7.setScaleType(ImageView.ScaleType.CENTER);
        this.tuneItem.setImageResource(R.drawable.media_settings);
        this.tuneItem.setBackgroundDrawable(Theme.createSelectorDrawable(1090519039));
        this.itemsLayout.addView(this.tuneItem, LayoutHelper.createLinear(48, 48));
        this.tuneItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$39(view2);
            }
        });
        this.tuneItem.setContentDescription(LocaleController.getString("AccDescrPhotoAdjust", R.string.AccDescrPhotoAdjust));
        PickerBottomLayoutViewer pickerBottomLayoutViewer2 = new PickerBottomLayoutViewer(this.activityContext);
        this.editorDoneLayout = pickerBottomLayoutViewer2;
        pickerBottomLayoutViewer2.setBackgroundColor(-872415232);
        this.editorDoneLayout.updateSelectedCount(0, false);
        this.editorDoneLayout.setVisibility(8);
        this.containerView.addView(this.editorDoneLayout, LayoutHelper.createFrame(-1, 48, 83));
        this.editorDoneLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$41(view2);
            }
        });
        this.editorDoneLayout.doneButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$42(view2);
            }
        });
        TextView textView9 = new TextView(this.activityContext);
        this.resetButton = textView9;
        textView9.setClickable(false);
        this.resetButton.setVisibility(8);
        this.resetButton.setTextSize(1, 14.0f);
        this.resetButton.setTextColor(-1);
        this.resetButton.setGravity(17);
        this.resetButton.setBackgroundDrawable(Theme.createSelectorDrawable(-12763843, 0));
        this.resetButton.setPadding(AndroidUtilities.dp(20.0f), 0, AndroidUtilities.dp(20.0f), 0);
        this.resetButton.setText(LocaleController.getString("Reset", R.string.CropReset).toUpperCase());
        this.resetButton.setTypeface(AndroidUtilities.bold());
        this.editorDoneLayout.addView(this.resetButton, LayoutHelper.createFrame(-2, -1, 49));
        this.resetButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$44(view2);
            }
        });
        GestureDetector2 gestureDetector2 = new GestureDetector2(this.containerView.getContext(), this);
        this.gestureDetector = gestureDetector2;
        gestureDetector2.setIsLongpressEnabled(false);
        setDoubleTapEnabled(true);
        ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() {
            public final void didSetImage(ImageReceiver imageReceiver, boolean z2, boolean z3, boolean z4) {
                PhotoViewer.this.lambda$setParentActivity$45(imageReceiver, z2, z3, z4);
            }

            public void didSetImageBitmap(int i15, String str, Drawable drawable2) {
                ImageReceiver.ImageReceiverDelegate.-CC.$default$didSetImageBitmap(this, i15, str, drawable2);
            }

            public void onAnimationReady(ImageReceiver imageReceiver) {
                ImageReceiver.ImageReceiverDelegate.-CC.$default$onAnimationReady(this, imageReceiver);
            }
        };
        this.centerImage.setParentView(this.containerView);
        this.centerImage.setCrossfadeAlpha((byte) 2);
        this.centerImage.setInvalidateAll(true);
        this.centerImage.setDelegate(imageReceiverDelegate);
        this.leftImage.setParentView(this.containerView);
        this.leftImage.setCrossfadeAlpha((byte) 2);
        this.leftImage.setInvalidateAll(true);
        this.leftImage.setDelegate(imageReceiverDelegate);
        this.rightImage.setParentView(this.containerView);
        this.rightImage.setCrossfadeAlpha((byte) 2);
        this.rightImage.setInvalidateAll(true);
        this.rightImage.setDelegate(imageReceiverDelegate);
        int rotation = ((WindowManager) ApplicationLoader.applicationContext.getSystemService("window")).getDefaultDisplay().getRotation();
        CheckBox checkBox = new CheckBox(this.containerView.getContext(), R.drawable.selectphoto_large);
        this.checkImageView = checkBox;
        checkBox.setDrawBackground(true);
        this.checkImageView.setHasBorder(true);
        this.checkImageView.setSize(34);
        this.checkImageView.setCheckOffset(AndroidUtilities.dp(1.0f));
        this.checkImageView.setColor(Theme.usePlusTheme ? Theme.defColor : getThemedColor(i10), -1);
        this.checkImageView.setVisibility(8);
        this.containerView.addView(this.checkImageView, LayoutHelper.createFrame(34, 34.0f, 53, 0.0f, (rotation == 3 || rotation == 1) ? 61.0f : 71.0f, 11.0f, 0.0f));
        if (isStatusBarVisible()) {
            ((FrameLayout.LayoutParams) this.checkImageView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
        }
        this.checkImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$46(view2);
            }
        });
        if (Theme.usePlusTheme) {
            this.menuItem.setIconColor(Theme.chatHeaderIconsColor);
            this.masksItem.setIconColor(Theme.chatHeaderIconsColor);
        }
        CounterView counterView = new CounterView(this.parentActivity);
        this.photosCounterView = counterView;
        this.containerView.addView(counterView, LayoutHelper.createFrame(40, 40.0f, 53, 0.0f, (rotation == 3 || rotation == 1) ? 58.0f : 68.0f, 64.0f, 0.0f));
        if (isStatusBarVisible()) {
            ((FrameLayout.LayoutParams) this.photosCounterView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
        }
        this.photosCounterView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$setParentActivity$47(view2);
            }
        });
        SelectedPhotosListView selectedPhotosListView = new SelectedPhotosListView(this.parentActivity);
        this.selectedPhotosListView = selectedPhotosListView;
        selectedPhotosListView.setVisibility(8);
        this.selectedPhotosListView.setAlpha(0.0f);
        this.selectedPhotosListView.setLayoutManager(new LinearLayoutManager(this, this.parentActivity, i, z) {
            public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
                LinearSmoothScrollerEnd linearSmoothScrollerEnd = new LinearSmoothScrollerEnd(this, recyclerView.getContext()) {
                    public int calculateTimeForDeceleration(int dx) {
                        return Math.max(180, super.calculateTimeForDeceleration(dx));
                    }
                };
                linearSmoothScrollerEnd.setTargetPosition(position);
                startSmoothScroll(linearSmoothScrollerEnd);
            }
        });
        SelectedPhotosListView selectedPhotosListView2 = this.selectedPhotosListView;
        ListAdapter listAdapter = new ListAdapter(this.parentActivity);
        this.selectedPhotosAdapter = listAdapter;
        selectedPhotosListView2.setAdapter(listAdapter);
        this.containerView.addView(this.selectedPhotosListView, LayoutHelper.createFrame(-1, 103, 51));
        this.selectedPhotosListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
            public final void onItemClick(View view2, int i15) {
                PhotoViewer.this.lambda$setParentActivity$48(view2, i15);
            }
        });
        UndoView undoView = new UndoView(this.activityContext, (BaseFragment) null, false, resourcesProvider);
        this.hintView = undoView;
        undoView.setAdditionalTranslationY(AndroidUtilities.dp(112.0f));
        this.hintView.setColors(-115203550, -1);
        this.containerView.addView(this.hintView, LayoutHelper.createFrame(-1, -2.0f, 83, 8.0f, 0.0f, 8.0f, 8.0f));
        if (AndroidUtilities.isAccessibilityScreenReaderEnabled()) {
            View view2 = new View(this.activityContext);
            this.playButtonAccessibilityOverlay = view2;
            view2.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
            this.playButtonAccessibilityOverlay.setFocusable(true);
            this.containerView.addView(this.playButtonAccessibilityOverlay, LayoutHelper.createFrame(64, 64, 17));
        }
        this.doneButtonFullWidth.setBackground(Theme.AdaptiveRipple.filledRect(getThemedColor(i11), 6.0f));
        this.doneButtonFullWidth.setTextColor(getThemedColor(i12));
        TextSelectionHelper.SimpleTextSelectionHelper simpleTextSelectionHelper = this.textSelectionHelper;
        simpleTextSelectionHelper.allowScrollPrentRelative = true;
        simpleTextSelectionHelper.useMovingOffset = false;
        View overlayView = simpleTextSelectionHelper.getOverlayView(this.windowView.getContext());
        if (overlayView != null) {
            AndroidUtilities.removeFromParent(overlayView);
            this.containerView.addView(overlayView);
        }
        this.textSelectionHelper.setParentView(this.containerView);
        this.textSelectionHelper.setInvalidateParent();
    }

    public class AnonymousClass13 extends FrameLayout {
        public AnonymousClass13(Context context) {
            super(context);
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return PhotoViewer.this.isVisible && super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            return PhotoViewer.this.isVisible && PhotoViewer.this.onTouchEvent(event);
        }

        @Override
        public boolean dispatchKeyEvent(KeyEvent event) {
            event.getKeyCode();
            if (!PhotoViewer.this.muteVideo && PhotoViewer.this.sendPhotoType != 1 && PhotoViewer.this.isCurrentVideo && PhotoViewer.this.videoPlayer != null && event.getRepeatCount() == 0 && event.getAction() == 0 && (event.getKeyCode() == 24 || event.getKeyCode() == 25)) {
                PhotoViewer.this.videoPlayer.setVolume(1.0f);
            }
            return super.dispatchKeyEvent(event);
        }

        @Override
        public boolean dispatchTouchEvent(android.view.MotionEvent r3) {
            throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.AnonymousClass13.dispatchTouchEvent(android.view.MotionEvent):boolean");
        }

        @Override
        public boolean drawChild(Canvas canvas, View child, long drawingTime) {
            try {
                return super.drawChild(canvas, child, drawingTime);
            } catch (Throwable unused) {
                return false;
            }
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int i;
            int i2;
            int size = View.MeasureSpec.getSize(widthMeasureSpec);
            int size2 = View.MeasureSpec.getSize(heightMeasureSpec);
            int i3 = Build.VERSION.SDK_INT;
            if (i3 >= 21) {
                if (!PhotoViewer.this.inBubbleMode) {
                    if (AndroidUtilities.incorrectDisplaySizeFix) {
                        int i4 = AndroidUtilities.displaySize.y;
                        if (size2 > i4) {
                            size2 = i4;
                        }
                        size2 += AndroidUtilities.statusBarHeight;
                    } else if (PhotoViewer.this.insets.bottom >= 0 && (i = AndroidUtilities.statusBarHeight) >= 0 && (i2 = (size2 - i) - PhotoViewer.this.insets.bottom) > 0 && i2 < 4096) {
                        AndroidUtilities.displaySize.y = i2;
                    }
                }
                size2 -= PhotoViewer.this.insets.bottom;
            } else {
                if (i3 < 21) {
                    PhotoViewer.this.insets.top = AndroidUtilities.statusBarHeight;
                    PhotoViewer.this.insets.bottom = AndroidUtilities.navigationBarHeight;
                }
                int i5 = AndroidUtilities.displaySize.y;
                if (size2 > i5) {
                    size2 = i5;
                }
            }
            int paddingLeft = size - (getPaddingLeft() + getPaddingRight());
            int paddingBottom = size2 - getPaddingBottom();
            setMeasuredDimension(paddingLeft, paddingBottom);
            ViewGroup.LayoutParams layoutParams = PhotoViewer.this.animatingImageView.getLayoutParams();
            PhotoViewer.this.animatingImageView.measure(View.MeasureSpec.makeMeasureSpec(layoutParams.width, Integer.MIN_VALUE), View.MeasureSpec.makeMeasureSpec(layoutParams.height, Integer.MIN_VALUE));
            PhotoViewer.this.containerView.measure(View.MeasureSpec.makeMeasureSpec(paddingLeft, 1073741824), View.MeasureSpec.makeMeasureSpec(paddingBottom, 1073741824));
            PhotoViewer.this.navigationBar.measure(View.MeasureSpec.makeMeasureSpec(paddingLeft, 1073741824), View.MeasureSpec.makeMeasureSpec(PhotoViewer.this.navigationBarHeight, 1073741824));
        }

        @Override
        public void onLayout(boolean changed, int left, int top, int right, int bottom) {
            PhotoViewer.this.animatingImageView.layout(getPaddingLeft(), 0, getPaddingLeft() + PhotoViewer.this.animatingImageView.getMeasuredWidth(), PhotoViewer.this.animatingImageView.getMeasuredHeight());
            PhotoViewer.this.containerView.layout(getPaddingLeft(), 0, getPaddingLeft() + PhotoViewer.this.containerView.getMeasuredWidth(), PhotoViewer.this.containerView.getMeasuredHeight());
            PhotoViewer.this.navigationBar.layout(getPaddingLeft(), PhotoViewer.this.containerView.getMeasuredHeight(), PhotoViewer.this.navigationBar.getMeasuredWidth(), PhotoViewer.this.containerView.getMeasuredHeight() + PhotoViewer.this.navigationBar.getMeasuredHeight());
            PhotoViewer.this.wasLayout = true;
            if (changed) {
                if (!PhotoViewer.this.dontResetZoomOnFirstLayout) {
                    PhotoViewer photoViewer = PhotoViewer.this;
                    photoViewer.scale = photoViewer.scale1();
                    PhotoViewer.this.translationX = 0.0f;
                    PhotoViewer.this.translationY = 0.0f;
                    PhotoViewer photoViewer2 = PhotoViewer.this;
                    photoViewer2.updateMinMax(photoViewer2.scale);
                }
                if (PhotoViewer.this.checkImageView != null) {
                    PhotoViewer.this.checkImageView.post(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.AnonymousClass13.this.lambda$onLayout$0();
                        }
                    });
                }
            }
            if (PhotoViewer.this.dontResetZoomOnFirstLayout) {
                PhotoViewer.this.setScaleToFill();
                PhotoViewer.this.dontResetZoomOnFirstLayout = false;
            }
        }

        public void lambda$onLayout$0() {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) PhotoViewer.this.checkImageView.getLayoutParams();
            ((WindowManager) ApplicationLoader.applicationContext.getSystemService("window")).getDefaultDisplay().getRotation();
            int currentActionBarHeight = ((ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(34.0f)) / 2) + (PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
            if (currentActionBarHeight != layoutParams.topMargin) {
                layoutParams.topMargin = currentActionBarHeight;
                PhotoViewer.this.checkImageView.setLayoutParams(layoutParams);
            }
            FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) PhotoViewer.this.photosCounterView.getLayoutParams();
            int currentActionBarHeight2 = ((ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(40.0f)) / 2) + (PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
            if (layoutParams2.topMargin != currentActionBarHeight2) {
                layoutParams2.topMargin = currentActionBarHeight2;
                PhotoViewer.this.photosCounterView.setLayoutParams(layoutParams2);
            }
        }

        @Override
        public void onAttachedToWindow() {
            super.onAttachedToWindow();
            PhotoViewer.this.centerImage.onAttachedToWindow();
            PhotoViewer.this.leftImage.onAttachedToWindow();
            PhotoViewer.this.rightImage.onAttachedToWindow();
            PhotoViewer.this.attachedToWindow = true;
        }

        @Override
        public void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            PhotoViewer.this.centerImage.onDetachedFromWindow();
            PhotoViewer.this.leftImage.onDetachedFromWindow();
            PhotoViewer.this.rightImage.onDetachedFromWindow();
            PhotoViewer.this.attachedToWindow = false;
            PhotoViewer.this.wasLayout = false;
        }

        @Override
        public boolean dispatchKeyEventPreIme(KeyEvent event) {
            if (event != null && event.getKeyCode() == 4 && event.getAction() == 1) {
                if (PhotoViewer.this.textSelectionHelper.isInSelectionMode()) {
                    PhotoViewer.this.textSelectionHelper.clear();
                }
                if (PhotoViewer.this.isCaptionOpen()) {
                    PhotoViewer.this.closeCaptionEnter(true);
                    return false;
                }
                if (ContentPreviewViewer.getInstance().isVisible()) {
                    ContentPreviewViewer.getInstance().closeWithMenu();
                    return false;
                }
                PhotoViewer.getInstance().closePhoto(true, false);
                return true;
            }
            return super.dispatchKeyEventPreIme(event);
        }

        @Override
        public void onDraw(Canvas canvas) {
            if (PhotoViewer.this.stickerMakerBackgroundView != null && PhotoViewer.this.stickerMakerBackgroundView.getVisibility() == 0) {
                View view = (View) PhotoViewer.this.stickerMakerBackgroundView.getParent();
                float min = Math.min(PhotoViewer.this.stickerMakerBackgroundView.getAlpha(), view != null ? view.getAlpha() : 1.0f);
                if (min > 0.0f) {
                    canvas.saveLayerAlpha(0.0f, 0.0f, getWidth(), getHeight(), (int) (min * 255.0f), 31);
                    PhotoViewer.this.stickerMakerBackgroundView.draw(canvas);
                    canvas.restore();
                }
            }
            if (Build.VERSION.SDK_INT < 21 || !PhotoViewer.this.isVisible) {
                return;
            }
            PhotoViewer.this.blackPaint.setAlpha(PhotoViewer.this.backgroundDrawable.getAlpha());
            canvas.drawRect(0.0f, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight() + PhotoViewer.this.insets.bottom, PhotoViewer.this.blackPaint);
        }

        @Override
        public void dispatchDraw(Canvas canvas) {
            UndoView undoView;
            super.dispatchDraw(canvas);
            if (PhotoViewer.this.parentChatActivity == null || (undoView = PhotoViewer.this.parentChatActivity.getUndoView()) == null || undoView.getVisibility() != 0) {
                return;
            }
            canvas.save();
            View view = (View) undoView.getParent();
            canvas.clipRect(view.getX(), view.getY(), view.getX() + view.getWidth(), view.getY() + view.getHeight());
            canvas.translate(undoView.getX(), undoView.getY());
            undoView.draw(canvas);
            canvas.restore();
            invalidate();
        }
    }

    public WindowInsets lambda$setParentActivity$6(View view, WindowInsets windowInsets) {
        Rect rect = new Rect(this.insets);
        int i = Build.VERSION.SDK_INT;
        if (i >= 30) {
            Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.systemBars());
            this.insets.set(insets.left, insets.top, insets.right, insets.bottom);
        } else {
            this.insets.set(windowInsets.getStableInsetLeft(), windowInsets.getStableInsetTop(), windowInsets.getStableInsetRight(), windowInsets.getStableInsetBottom());
        }
        int i2 = this.insets.top;
        Object obj = this.parentActivity;
        if ((obj instanceof LaunchActivity) && ((i2 != 0 || AndroidUtilities.isInMultiwindow) && !this.inBubbleMode && AndroidUtilities.statusBarHeight != i2)) {
            AndroidUtilities.statusBarHeight = i2;
            ((LaunchActivity) obj).drawerLayoutContainer.requestLayout();
        }
        if (!rect.equals(windowInsets)) {
            int i3 = this.animationInProgress;
            if (i3 == 1 || i3 == 3) {
                ClippingImageView clippingImageView = this.animatingImageView;
                clippingImageView.setTranslationX(clippingImageView.getTranslationX() - getLeftInset());
                this.animationValues[0][2] = this.animatingImageView.getTranslationX();
            }
            FrameLayout frameLayout = this.windowView;
            if (frameLayout != null) {
                frameLayout.requestLayout();
            }
        }
        View view2 = this.navigationBar;
        if (view2 != null) {
            this.navigationBarHeight = this.insets.bottom;
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view2.getLayoutParams();
            int i4 = this.navigationBarHeight;
            marginLayoutParams.height = i4;
            marginLayoutParams.bottomMargin = (-i4) / 2;
            this.navigationBar.setLayoutParams(marginLayoutParams);
        }
        this.containerView.setPadding(windowInsets.getSystemWindowInsetLeft(), 0, windowInsets.getSystemWindowInsetRight(), 0);
        if (this.actionBar != null) {
            AndroidUtilities.cancelRunOnUIThread(this.updateContainerFlagsRunnable);
            if (this.isVisible && this.animationInProgress == 0) {
                AndroidUtilities.runOnUIThread(this.updateContainerFlagsRunnable, 200L);
            }
        }
        if (i >= 30) {
            return WindowInsets.CONSUMED;
        }
        return windowInsets.consumeSystemWindowInsets();
    }

    public class AnonymousClass16 extends ActionBar.ActionBarMenuOnItemClick {
        public final Theme.ResourcesProvider val$resourcesProvider;

        public AnonymousClass16(final Theme.ResourcesProvider val$resourcesProvider) {
            this.val$resourcesProvider = val$resourcesProvider;
        }

        public void lambda$onItemClick$0(boolean z, Uri uri) {
            BulletinFactory.createSaveToGalleryBulletin(PhotoViewer.this.containerView, z, -115203550, -1).show();
        }

        public void lambda$onItemClick$2(DialogInterface dialogInterface, int i) {
            File pathToMessage;
            if (PhotoViewer.this.currentMessageObject == null) {
                return;
            }
            if ((MessageObject.getMedia(PhotoViewer.this.currentMessageObject.messageOwner) instanceof TLRPC.TL_messageMediaWebPage) && MessageObject.getMedia(PhotoViewer.this.currentMessageObject.messageOwner).webpage != null && MessageObject.getMedia(PhotoViewer.this.currentMessageObject.messageOwner).webpage.document == null) {
                PhotoViewer photoViewer = PhotoViewer.this;
                pathToMessage = FileLoader.getInstance(PhotoViewer.this.currentAccount).getPathToAttach(photoViewer.getFileLocation(photoViewer.currentIndex, null), true);
            } else {
                pathToMessage = FileLoader.getInstance(PhotoViewer.this.currentAccount).getPathToMessage(PhotoViewer.this.currentMessageObject.messageOwner);
            }
            final boolean isVideo = PhotoViewer.this.currentMessageObject.isVideo();
            if (pathToMessage != null && pathToMessage.exists()) {
                MediaController.saveFile(pathToMessage.toString(), PhotoViewer.this.parentActivity, isVideo ? 1 : 0, (String) null, (String) null, new Utilities.Callback() {
                    public final void run(Object obj) {
                        PhotoViewer.AnonymousClass16.this.lambda$onItemClick$1(isVideo, (Uri) obj);
                    }
                });
                return;
            }
            PhotoViewer.this.showDownloadAlert();
        }

        public void lambda$onItemClick$1(boolean z, Uri uri) {
            BulletinFactory.createSaveToGalleryBulletin(PhotoViewer.this.containerView, z, -115203550, -1).show();
        }

        public void lambda$onItemClick$5(final boolean z, ArrayList arrayList, DialogInterface dialogInterface, int i) {
            File pathToMessage;
            final int[] iArr = new int[1];
            final int[] iArr2 = new int[1];
            final Runnable runnable = new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass16.this.lambda$onItemClick$3(iArr2, iArr, z);
                }
            };
            for (int i2 = 0; i2 < arrayList.size(); i2++) {
                MessageObject messageObject = (MessageObject) arrayList.get(i2);
                if (messageObject != null) {
                    if ((MessageObject.getMedia(messageObject.messageOwner) instanceof TLRPC.TL_messageMediaWebPage) && MessageObject.getMedia(messageObject.messageOwner).webpage != null && MessageObject.getMedia(messageObject.messageOwner).webpage.document == null) {
                        FileLoader fileLoader = FileLoader.getInstance(PhotoViewer.this.currentAccount);
                        PhotoViewer photoViewer = PhotoViewer.this;
                        pathToMessage = fileLoader.getPathToAttach(photoViewer.getFileLocation(photoViewer.currentIndex, null), true);
                    } else {
                        pathToMessage = FileLoader.getInstance(PhotoViewer.this.currentAccount).getPathToMessage(messageObject.messageOwner);
                    }
                    boolean isVideo = messageObject.isVideo();
                    if (pathToMessage != null && pathToMessage.exists()) {
                        iArr[0] = iArr[0] + 1;
                        MediaController.saveFile(pathToMessage.toString(), PhotoViewer.this.parentActivity, isVideo ? 1 : 0, (String) null, (String) null, new Utilities.Callback() {
                            public final void run(Object obj) {
                                AndroidUtilities.runOnUIThread(runnable);
                            }
                        });
                    }
                }
            }
        }

        public void lambda$onItemClick$3(int[] iArr, int[] iArr2, boolean z) {
            iArr[0] = iArr[0] + 1;
            if (iArr[0] == iArr2[0]) {
                BulletinFactory.createSaveToGalleryBulletin(PhotoViewer.this.containerView, iArr2[0], z, -115203550, -1).show();
            }
        }

        public void lambda$onItemClick$7(DialogInterface dialogInterface, int i) {
            ArrayList arrayList = new ArrayList(1);
            arrayList.add(PhotoViewer.this.currentMessageObject);
            PhotoViewer.this.showShareAlert(arrayList);
        }

        public void lambda$onItemClick$8(ArrayList arrayList, DialogInterface dialogInterface, int i) {
            PhotoViewer.this.showShareAlert(arrayList);
        }

        public boolean lambda$onItemClick$10(ArrayList arrayList, boolean z, ChatActivity chatActivity, DialogsActivity dialogsActivity, ArrayList arrayList2, CharSequence charSequence, boolean z2, TopicsFragment topicsFragment) {
            UndoView undoView;
            if (arrayList2.size() > 1 || ((MessagesStorage.TopicKey) arrayList2.get(0)).dialogId == UserConfig.getInstance(PhotoViewer.this.currentAccount).getClientUserId() || charSequence != null) {
                for (int i = 0; i < arrayList2.size(); i++) {
                    long j = ((MessagesStorage.TopicKey) arrayList2.get(i)).dialogId;
                    if (charSequence != null) {
                        SendMessagesHelper.getInstance(PhotoViewer.this.currentAccount).sendMessage(SendMessagesHelper.SendMessageParams.of(charSequence.toString(), j, (MessageObject) null, (MessageObject) null, (TLRPC.WebPage) null, true, (ArrayList) null, (TLRPC.ReplyMarkup) null, (HashMap) null, true, 0, (MessageObject.SendAnimationData) null, false));
                    }
                    SendMessagesHelper.getInstance(PhotoViewer.this.currentAccount).sendMessage(arrayList, j, !z, false, true, 0);
                }
                dialogsActivity.finishFragment();
                if (chatActivity != null && (undoView = chatActivity.getUndoView()) != null) {
                    if (arrayList2.size() == 1) {
                        undoView.showWithAction(((MessagesStorage.TopicKey) arrayList2.get(0)).dialogId, 53, Integer.valueOf(arrayList.size()));
                    } else {
                        undoView.showWithAction(0L, 53, Integer.valueOf(arrayList.size()), Integer.valueOf(arrayList2.size()), (Runnable) null, (Runnable) null);
                    }
                }
            } else {
                MessagesStorage.TopicKey topicKey = (MessagesStorage.TopicKey) arrayList2.get(0);
                long j2 = topicKey.dialogId;
                Bundle bundle = new Bundle();
                bundle.putBoolean("scrollToTopOnResume", true);
                bundle.putBoolean("quote", z);
                if (DialogObject.isEncryptedDialog(j2)) {
                    bundle.putInt("enc_id", DialogObject.getEncryptedChatId(j2));
                } else if (DialogObject.isUserDialog(j2)) {
                    bundle.putLong("user_id", j2);
                } else {
                    bundle.putLong("chat_id", -j2);
                }
                ChatActivity chatActivity2 = new ChatActivity(bundle);
                if (topicKey.topicId != 0) {
                    ForumUtilities.applyTopic(chatActivity2, topicKey);
                }
                if (((LaunchActivity) PhotoViewer.this.parentActivity).presentFragment(chatActivity2, true, false)) {
                    chatActivity2.showFieldPanelForForward(true, arrayList);
                } else {
                    dialogsActivity.finishFragment();
                }
            }
            return true;
        }

        public static void lambda$onItemClick$11(boolean[] zArr, View view) {
            zArr[0] = !zArr[0];
            ((CheckBoxCell) view).setChecked(zArr[0], true);
        }

        public void lambda$onItemClick$12(boolean[] zArr, DialogInterface dialogInterface, int i) {
            ArrayList arrayList;
            TLRPC.EncryptedChat encryptedChat;
            if (!PhotoViewer.this.placeProvider.onDeletePhoto(PhotoViewer.this.currentIndex)) {
                PhotoViewer.this.closePhoto(false, false);
                return;
            }
            if (!PhotoViewer.this.imagesArr.isEmpty()) {
                if (PhotoViewer.this.currentIndex < 0 || PhotoViewer.this.currentIndex >= PhotoViewer.this.imagesArr.size()) {
                    return;
                }
                MessageObject messageObject = (MessageObject) PhotoViewer.this.imagesArr.get(PhotoViewer.this.currentIndex);
                if (messageObject.isSent()) {
                    PhotoViewer.this.closePhoto(false, false);
                    ArrayList arrayList2 = new ArrayList();
                    if (PhotoViewer.this.slideshowMessageId != 0) {
                        arrayList2.add(Integer.valueOf(PhotoViewer.this.slideshowMessageId));
                    } else {
                        arrayList2.add(Integer.valueOf(messageObject.getId()));
                    }
                    if (!DialogObject.isEncryptedDialog(messageObject.getDialogId()) || messageObject.messageOwner.random_id == 0) {
                        arrayList = null;
                        encryptedChat = null;
                    } else {
                        ArrayList arrayList3 = new ArrayList();
                        arrayList3.add(Long.valueOf(messageObject.messageOwner.random_id));
                        arrayList = arrayList3;
                        encryptedChat = MessagesController.getInstance(PhotoViewer.this.currentAccount).getEncryptedChat(Integer.valueOf(DialogObject.getEncryptedChatId(messageObject.getDialogId())));
                    }
                    MessagesController.getInstance(PhotoViewer.this.currentAccount).deleteMessages(arrayList2, arrayList, encryptedChat, messageObject.getDialogId(), messageObject.getQuickReplyId(), zArr[0], messageObject.getChatMode());
                    return;
                }
                return;
            }
            if (!PhotoViewer.this.avatarsArr.isEmpty()) {
                if (PhotoViewer.this.currentIndex < 0 || PhotoViewer.this.currentIndex >= PhotoViewer.this.avatarsArr.size()) {
                    return;
                }
                TLRPC.Message message = (TLRPC.Message) PhotoViewer.this.imagesArrMessages.get(PhotoViewer.this.currentIndex);
                if (message != null) {
                    ArrayList arrayList4 = new ArrayList();
                    arrayList4.add(Integer.valueOf(message.id));
                    MessagesController.getInstance(PhotoViewer.this.currentAccount).deleteMessages(arrayList4, (ArrayList) null, (TLRPC.EncryptedChat) null, MessageObject.getDialogId(message), message.quick_reply_shortcut_id, true, 0);
                    NotificationCenter.getInstance(PhotoViewer.this.currentAccount).postNotificationName(NotificationCenter.reloadDialogPhotos, new Object[0]);
                }
                if (PhotoViewer.this.isCurrentAvatarSet()) {
                    if (PhotoViewer.this.avatarsDialogId > 0) {
                        MessagesController.getInstance(PhotoViewer.this.currentAccount).deleteUserPhoto((TLRPC.InputPhoto) null);
                    } else {
                        MessagesController.getInstance(PhotoViewer.this.currentAccount).changeChatAvatar(-PhotoViewer.this.avatarsDialogId, (TLRPC.TL_inputChatPhoto) null, (TLRPC.InputFile) null, (TLRPC.InputFile) null, (TLRPC.VideoSize) null, 0.0d, (String) null, (TLRPC.FileLocation) null, (TLRPC.FileLocation) null, (Runnable) null);
                    }
                    PhotoViewer.this.closePhoto(false, false);
                    return;
                }
                TLRPC.Photo photo = (TLRPC.Photo) PhotoViewer.this.avatarsArr.get(PhotoViewer.this.currentIndex);
                if (photo == null) {
                    return;
                }
                TLRPC.TL_inputPhoto tL_inputPhoto = new TLRPC.TL_inputPhoto();
                ((TLRPC.InputPhoto) tL_inputPhoto).id = photo.id;
                ((TLRPC.InputPhoto) tL_inputPhoto).access_hash = photo.access_hash;
                byte[] bArr = photo.file_reference;
                ((TLRPC.InputPhoto) tL_inputPhoto).file_reference = bArr;
                if (bArr == null) {
                    ((TLRPC.InputPhoto) tL_inputPhoto).file_reference = new byte[0];
                }
                if (PhotoViewer.this.avatarsDialogId > 0) {
                    MessagesController.getInstance(PhotoViewer.this.currentAccount).deleteUserPhoto(tL_inputPhoto);
                }
                MessagesStorage.getInstance(PhotoViewer.this.currentAccount).clearUserPhoto(PhotoViewer.this.avatarsDialogId, photo.id);
                PhotoViewer.this.imagesArrLocations.remove(PhotoViewer.this.currentIndex);
                PhotoViewer.this.imagesArrLocationsSizes.remove(PhotoViewer.this.currentIndex);
                PhotoViewer.this.imagesArrLocationsVideo.remove(PhotoViewer.this.currentIndex);
                PhotoViewer.this.imagesArrMessages.remove(PhotoViewer.this.currentIndex);
                PhotoViewer.this.avatarsArr.remove(PhotoViewer.this.currentIndex);
                if (PhotoViewer.this.imagesArrLocations.isEmpty()) {
                    PhotoViewer.this.closePhoto(false, false);
                } else {
                    int i2 = PhotoViewer.this.currentIndex;
                    if (i2 >= PhotoViewer.this.avatarsArr.size()) {
                        i2 = PhotoViewer.this.avatarsArr.size() - 1;
                    }
                    PhotoViewer.this.currentIndex = -1;
                    PhotoViewer.this.setImageIndex(i2);
                }
                if (message == null) {
                    NotificationCenter.getInstance(PhotoViewer.this.currentAccount).postNotificationName(NotificationCenter.reloadDialogPhotos, new Object[0]);
                    return;
                }
                return;
            }
            if (PhotoViewer.this.secureDocuments.isEmpty() || PhotoViewer.this.placeProvider == null) {
                return;
            }
            PhotoViewer.this.secureDocuments.remove(PhotoViewer.this.currentIndex);
            PhotoViewer.this.placeProvider.deleteImageAtIndex(PhotoViewer.this.currentIndex);
            if (PhotoViewer.this.secureDocuments.isEmpty()) {
                PhotoViewer.this.closePhoto(false, false);
                return;
            }
            int i3 = PhotoViewer.this.currentIndex;
            if (i3 >= PhotoViewer.this.secureDocuments.size()) {
                i3 = PhotoViewer.this.secureDocuments.size() - 1;
            }
            PhotoViewer.this.currentIndex = -1;
            PhotoViewer.this.setImageIndex(i3);
        }

        @Override
        public void onItemClick(int r30) {
            throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.AnonymousClass16.onItemClick(int):void");
        }

        public void lambda$onItemClick$14(final UserConfig userConfig, final TLRPC.Photo photo, final TLObject tLObject, TLRPC.TL_error tL_error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass16.this.lambda$onItemClick$13(tLObject, userConfig, photo);
                }
            });
        }

        public void lambda$onItemClick$13(TLObject tLObject, UserConfig userConfig, TLRPC.Photo photo) {
            if (tLObject instanceof TLRPC.TL_photos_photo) {
                TLRPC.TL_photos_photo tL_photos_photo = (TLRPC.TL_photos_photo) tLObject;
                MessagesController.getInstance(PhotoViewer.this.currentAccount).putUsers(tL_photos_photo.users, false);
                TLRPC.User user = MessagesController.getInstance(PhotoViewer.this.currentAccount).getUser(Long.valueOf(userConfig.clientUserId));
                if (tL_photos_photo.photo instanceof TLRPC.TL_photo) {
                    int indexOf = PhotoViewer.this.avatarsArr.indexOf(photo);
                    if (indexOf >= 0) {
                        PhotoViewer.this.avatarsArr.set(indexOf, tL_photos_photo.photo);
                    }
                    if (user != null) {
                        user.photo.photo_id = tL_photos_photo.photo.id;
                        userConfig.setCurrentUser(user);
                        userConfig.saveConfig(true);
                    }
                }
            }
        }

        public void lambda$onItemClick$15() {
            if (PhotoViewer.this.menuItem == null) {
                return;
            }
            PhotoViewer.this.menuItem.hideSubItem(16);
        }

        public void lambda$onItemClick$16() {
            PhotoViewer.this.menuItem.hideSubItem(21);
            PhotoViewer.this.menuItem.showSubItem(22);
        }

        public void lambda$onItemClick$18() {
            PhotoViewer.this.menuItem.showSubItem(21);
            PhotoViewer.this.menuItem.hideSubItem(22);
        }

        @Override
        public boolean canOpenMenu() {
            if (PhotoViewer.this.currentMessageObject != null || PhotoViewer.this.currentSecureDocument != null) {
                return true;
            }
            if (PhotoViewer.this.currentFileLocationVideo == null) {
                return PhotoViewer.this.pageBlocksAdapter != null;
            }
            File pathToAttach = FileLoader.getInstance(PhotoViewer.this.currentAccount).getPathToAttach(PhotoViewer.getFileLocation(PhotoViewer.this.currentFileLocationVideo), PhotoViewer.getFileLocationExt(PhotoViewer.this.currentFileLocationVideo), PhotoViewer.this.avatarsDialogId != 0 || PhotoViewer.this.isEvent);
            return pathToAttach.exists() || new File(FileLoader.getDirectory(4), pathToAttach.getName()).exists();
        }
    }

    public void lambda$setParentActivity$7(Boolean bool) {
        checkProgress(0, false, false);
    }

    public void lambda$setParentActivity$8(View view) {
        Activity activity = this.parentActivity;
        if (activity == null) {
            return;
        }
        this.wasRotated = false;
        this.fullscreenedByButton = 1;
        if (this.prevOrientation == -10) {
            this.prevOrientation = activity.getRequestedOrientation();
        }
        if (((WindowManager) this.parentActivity.getSystemService("window")).getDefaultDisplay().getRotation() == 3) {
            this.parentActivity.setRequestedOrientation(8);
        } else {
            this.parentActivity.setRequestedOrientation(0);
        }
        toggleActionBar(false, false);
    }

    public View lambda$setParentActivity$9() {
        return new CaptionTextView(this.activityContext, this.captionScrollView, this.textSelectionHelper, new Utilities.Callback2() {
            public final void run(Object obj, Object obj2) {
                PhotoViewer.this.onLinkClick((ClickableSpan) obj, (TextView) obj2);
            }
        }, new Utilities.Callback3() {
            public final void run(Object obj, Object obj2, Object obj3) {
                PhotoViewer.this.onLinkLongPress((URLSpan) obj, (TextView) obj2, (Runnable) obj3);
            }
        });
    }

    public void lambda$setParentActivity$10(View view) {
        this.selectedCompression = this.previousCompression;
        didChangedCompressionLevel(false);
        showQualityView(false);
        requestVideoPreview(2);
    }

    public void lambda$setParentActivity$11(View view) {
        Object obj = this.imagesArrLocals.get(this.currentIndex);
        if (obj instanceof MediaController.MediaEditState) {
            ((MediaController.MediaEditState) obj).editedInfo = getCurrentVideoEditedInfo();
        }
        showQualityView(false);
        requestVideoPreview(2);
    }

    public void lambda$setParentActivity$12(View view) {
        sendPressed(false, 0);
    }

    public class AnonymousClass27 implements VideoTimelinePlayView.VideoTimelineViewDelegate {
        public int seekTo;
        public Runnable seekToRunnable;
        public boolean wasPlaying;

        public AnonymousClass27() {
        }

        public void onLeftProgressChanged(float progress) {
            if (PhotoViewer.this.videoPlayer == null) {
                return;
            }
            if (PhotoViewer.this.videoPlayer.isPlaying()) {
                PhotoViewer.this.manuallyPaused = false;
                PhotoViewer.this.videoPlayer.pause();
                PhotoViewer.this.containerView.invalidate();
            }
            updateAvatarStartTime(1);
            seekTo(progress);
            PhotoViewer.this.videoPlayerSeekbar.setProgress(0.0f);
            PhotoViewer.this.videoTimelineView.setProgress(progress);
            PhotoViewer.this.updateVideoInfo();
        }

        public void onRightProgressChanged(float progress) {
            if (PhotoViewer.this.videoPlayer == null) {
                return;
            }
            if (PhotoViewer.this.videoPlayer.isPlaying()) {
                PhotoViewer.this.manuallyPaused = false;
                PhotoViewer.this.videoPlayer.pause();
                PhotoViewer.this.containerView.invalidate();
            }
            updateAvatarStartTime(2);
            seekTo(progress);
            PhotoViewer.this.videoPlayerSeekbar.setProgress(1.0f);
            PhotoViewer.this.videoTimelineView.setProgress(progress);
            PhotoViewer.this.updateVideoInfo();
        }

        public void onPlayProgressChanged(float progress) {
            if (PhotoViewer.this.videoPlayer == null) {
                return;
            }
            if (PhotoViewer.this.sendPhotoType == 1) {
                updateAvatarStartTime(0);
            }
            seekTo(progress);
        }

        public final void seekTo(float progress) {
            this.seekTo = (int) (PhotoViewer.this.videoDuration * progress);
            if (SharedConfig.getDevicePerformanceClass() == 2) {
                PhotoViewer.this.seekVideoOrWebTo(this.seekTo);
                if (PhotoViewer.this.sendPhotoType == 1) {
                    PhotoViewer.this.needCaptureFrameReadyAtTime = this.seekTo;
                    if (PhotoViewer.this.captureFrameReadyAtTime != PhotoViewer.this.needCaptureFrameReadyAtTime) {
                        PhotoViewer.this.captureFrameReadyAtTime = -1L;
                    }
                }
                this.seekToRunnable = null;
                return;
            }
            if (this.seekToRunnable == null) {
                Runnable runnable = new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass27.this.lambda$seekTo$0();
                    }
                };
                this.seekToRunnable = runnable;
                AndroidUtilities.runOnUIThread(runnable, 100L);
            }
        }

        public void lambda$seekTo$0() {
            PhotoViewer.this.seekVideoOrWebTo(this.seekTo);
            if (PhotoViewer.this.sendPhotoType == 1) {
                PhotoViewer.this.needCaptureFrameReadyAtTime = this.seekTo;
                if (PhotoViewer.this.captureFrameReadyAtTime != PhotoViewer.this.needCaptureFrameReadyAtTime) {
                    PhotoViewer.this.captureFrameReadyAtTime = -1L;
                }
            }
            this.seekToRunnable = null;
        }

        public final void updateAvatarStartTime(int fix) {
            if (PhotoViewer.this.sendPhotoType != 1) {
                return;
            }
            if (fix != 0) {
                if (PhotoViewer.this.photoCropView != null) {
                    if (PhotoViewer.this.videoTimelineView.getLeftProgress() > PhotoViewer.this.avatarStartProgress || PhotoViewer.this.videoTimelineView.getRightProgress() < PhotoViewer.this.avatarStartProgress) {
                        PhotoViewer.this.photoCropView.setVideoThumbVisible(false);
                        if (fix == 1) {
                            PhotoViewer photoViewer = PhotoViewer.this;
                            photoViewer.avatarStartTime = (long) (photoViewer.videoDuration * 1000.0f * PhotoViewer.this.videoTimelineView.getLeftProgress());
                        } else {
                            PhotoViewer photoViewer2 = PhotoViewer.this;
                            photoViewer2.avatarStartTime = (long) (photoViewer2.videoDuration * 1000.0f * PhotoViewer.this.videoTimelineView.getRightProgress());
                        }
                        PhotoViewer.this.captureFrameAtTime = -1L;
                        return;
                    }
                    return;
                }
                return;
            }
            PhotoViewer photoViewer3 = PhotoViewer.this;
            photoViewer3.avatarStartProgress = photoViewer3.videoTimelineView.getProgress();
            PhotoViewer photoViewer4 = PhotoViewer.this;
            photoViewer4.avatarStartTime = (long) (photoViewer4.videoDuration * 1000.0f * PhotoViewer.this.avatarStartProgress);
        }

        public void didStartDragging(int type) {
            if (type == VideoTimelinePlayView.TYPE_PROGRESS) {
                PhotoViewer.this.cancelVideoPlayRunnable();
                if (PhotoViewer.this.sendPhotoType == 1) {
                    PhotoViewer.this.cancelFlashAnimations();
                    PhotoViewer.this.captureFrameAtTime = -1L;
                }
                boolean isVideoPlaying = PhotoViewer.this.isVideoPlaying();
                this.wasPlaying = isVideoPlaying;
                if (isVideoPlaying) {
                    PhotoViewer.this.manuallyPaused = false;
                    PhotoViewer.this.pauseVideoOrWeb();
                    PhotoViewer.this.containerView.invalidate();
                }
            }
        }

        public void didStopDragging(int type) {
            Runnable runnable = this.seekToRunnable;
            if (runnable != null) {
                AndroidUtilities.cancelRunOnUIThread(runnable);
                this.seekToRunnable.run();
            }
            PhotoViewer.this.cancelVideoPlayRunnable();
            if (PhotoViewer.this.sendPhotoType == 1 && PhotoViewer.this.flashView != null && type == VideoTimelinePlayView.TYPE_PROGRESS) {
                PhotoViewer.this.cancelFlashAnimations();
                PhotoViewer photoViewer = PhotoViewer.this;
                photoViewer.captureFrameAtTime = photoViewer.avatarStartTime;
                if (PhotoViewer.this.captureFrameReadyAtTime == this.seekTo) {
                    PhotoViewer.this.captureCurrentFrame();
                    return;
                }
                return;
            }
            if (PhotoViewer.this.sendPhotoType == 1 || this.wasPlaying) {
                PhotoViewer.this.manuallyPaused = false;
                PhotoViewer.this.playVideoOrWeb();
            }
        }
    }

    public void lambda$setParentActivity$13(Integer num) {
        Object obj = this.imagesArrLocals.get(this.currentIndex);
        if (obj instanceof MediaController.PhotoEntry) {
            ((MediaController.MediaEditState) ((MediaController.PhotoEntry) obj)).ttl = num.intValue();
        } else if (obj instanceof MediaController.SearchImage) {
            ((MediaController.MediaEditState) ((MediaController.SearchImage) obj)).ttl = num.intValue();
        }
        if (num.intValue() == 0 || this.placeProvider.isPhotoChecked(this.currentIndex)) {
            return;
        }
        setPhotoChecked();
    }

    public void lambda$setParentActivity$14(Integer num) {
        FrameLayout frameLayout = this.videoTimelineViewContainer;
        if (frameLayout != null && frameLayout.getVisibility() != 8) {
            this.videoTimelineViewContainer.setTranslationY(this.pickerView.getTranslationY() - Math.max(0, this.captionEdit.getEditTextHeight() - AndroidUtilities.dp(46.0f)));
        }
        this.muteItem.setTranslationY(-Math.max(0, num.intValue() - AndroidUtilities.dp(46.0f)));
    }

    public void lambda$setParentActivity$15(View view) {
        if (this.placeProvider == null || isCaptionOpen()) {
            return;
        }
        this.placeProvider.needAddMorePhotos();
        closePhoto(true, false);
    }

    public void lambda$setParentActivity$21(View view) {
        int i;
        if (this.stickerEmpty || this.cutOutBtn.isLoading() || this.cutOutBtn.isUndoCutState() || (i = this.currentIndex) < 0 || i >= this.imagesArrLocals.size() || this.stickerMakerView.isThanosInProgress) {
            return;
        }
        final MediaController.MediaEditState mediaEditState = (MediaController.MediaEditState) this.imagesArrLocals.get(this.currentIndex);
        final boolean z = !TextUtils.isEmpty(mediaEditState.filterPath);
        if (this.cutOutBtn.isCutOutState()) {
            this.cutOutBtn.setCancelState(true);
            this.stickerMakerView.enableClippingMode(new Utilities.Callback() {
                public final void run(Object obj) {
                    PhotoViewer.this.lambda$setParentActivity$20(z, mediaEditState, (StickerMakerView.SegmentedObject) obj);
                }
            });
            this.containerView.invalidate();
        } else {
            if (this.cutOutBtn.isCancelState()) {
                this.cutOutBtn.setCutOutState(true);
                showEditStickerMode(false, true);
                this.stickerMakerView.disableClippingMode();
                this.containerView.invalidate();
                return;
            }
            this.stickerMakerView.resetPaths();
            this.stickerMakerView.getThanosEffect();
            this.stickerMakerView.setSegmentedState(false, null);
            this.centerImage.setImageBitmap(this.stickerMakerView.getSourceBitmap(z));
            this.cutOutBtn.setCutOutState(true);
            showEditStickerMode(false, true);
            applyCurrentEditMode();
        }
    }

    public void lambda$setParentActivity$20(boolean z, MediaController.MediaEditState mediaEditState, StickerMakerView.SegmentedObject segmentedObject) {
        float f;
        float f2;
        float f3;
        if (this.stickerMakerView.hasSegmentedBitmap()) {
            ThanosEffect thanosEffect = this.stickerMakerView.getThanosEffect();
            this.stickerMakerView.setSegmentedState(true, segmentedObject);
            final Bitmap segmentedImage = this.stickerMakerView.getSegmentedImage(this.centerImage.getBitmap(), z, this.centerImage.getOrientation());
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) this.imagesArrLocals.get(this.currentIndex);
            if (thanosEffect == null) {
                this.centerImage.setImageBitmap(segmentedImage);
                this.cutOutBtn.setUndoCutState(true);
                showStickerMode(true, true);
                this.cutOutBtn.post(new PhotoViewer$$ExternalSyntheticLambda77(this));
                return;
            }
            Bitmap thanosImage = this.stickerMakerView.getThanosImage(photoEntry, this.centerImage.getOrientation());
            if (thanosImage == null) {
                this.centerImage.setImageBitmap(segmentedImage);
                this.cutOutBtn.setUndoCutState(true);
                showStickerMode(true, true);
                this.cutOutBtn.post(new PhotoViewer$$ExternalSyntheticLambda77(this));
                return;
            }
            MediaController.CropState cropState = mediaEditState.cropState;
            if (cropState != null) {
                thanosImage = createCroppedBitmap(thanosImage, cropState, new int[]{this.centerImage.getOrientation(), this.centerImage.getInvert()}, true);
            }
            if (thanosImage == null) {
                this.centerImage.setImageBitmap(segmentedImage);
                this.cutOutBtn.setUndoCutState(true);
                showEditStickerMode(true, true);
                this.cutOutBtn.post(new PhotoViewer$$ExternalSyntheticLambda77(this));
                return;
            }
            Matrix matrix = new Matrix();
            int width = thanosImage.getWidth();
            int height = thanosImage.getHeight();
            if (!((MediaController.MediaEditState) photoEntry).isCropped && (this.centerImage.getOrientation() / 90) % 2 != 0) {
                width = thanosImage.getHeight();
                height = thanosImage.getWidth();
            }
            float f4 = width;
            float f5 = height;
            float min = Math.min(getContainerViewWidth() / f4, getContainerViewHeight() / f5);
            float f6 = f4 * min;
            float f7 = f5 * min;
            float f8 = 0.0f;
            if ((this.centerImage.getOrientation() == 0 || ((MediaController.MediaEditState) photoEntry).isCropped) && this.rotate == 0.0f) {
                f = f6;
                f2 = f7;
                f3 = 0.0f;
            } else {
                float width2 = thanosImage.getWidth();
                float height2 = thanosImage.getHeight();
                float f9 = width2 / 2.0f;
                float f10 = height2 / 2.0f;
                float sqrt = (float) Math.sqrt((f9 * f9) + (f10 * f10));
                float f11 = sqrt * 2.0f;
                int i = (int) f11;
                Bitmap createBitmap = Bitmap.createBitmap(i, i, Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(createBitmap);
                canvas.save();
                canvas.rotate((((MediaController.MediaEditState) photoEntry).isCropped ? 0 : this.centerImage.getOrientation()) + this.rotate, sqrt, sqrt);
                canvas.drawBitmap(thanosImage, (f11 - width2) / 2.0f, (f11 - height2) / 2.0f, (Paint) null);
                thanosImage.recycle();
                float f12 = f6 / 2.0f;
                float f13 = f7 / 2.0f;
                f = ((float) Math.sqrt((f12 * f12) + (f13 * f13))) * 2.0f;
                f8 = (-(f - f6)) / 2.0f;
                f3 = (-(f - f7)) / 2.0f;
                thanosImage = createBitmap;
                f2 = f;
            }
            matrix.postScale(f, f2);
            float f14 = this.scale;
            matrix.postScale(f14, f14, f / 2.0f, f2 / 2.0f);
            matrix.postTranslate(this.translationX + f8 + Math.max(0, (int) ((getContainerViewWidth() - f6) / 2.0f)), this.translationY + f3 + Math.max(0, (int) ((getContainerViewHeight() - f7) / 2.0f)));
            this.stickerMakerView.isThanosInProgress = true;
            Utilities.themeQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$setParentActivity$16(segmentedImage);
                }
            });
            final Runnable runnable = new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$setParentActivity$17();
                }
            };
            thanosEffect.animate(matrix, thanosImage, new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$setParentActivity$18(segmentedImage, runnable);
                }
            }, new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.lambda$setParentActivity$19();
                }
            });
            AndroidUtilities.runOnUIThread(runnable, 1200L);
        } else {
            this.cutOutBtn.setCutOutState(true);
            showEditStickerMode(false, true);
        }
        this.stickerMakerView.disableClippingMode();
        this.containerView.invalidate();
    }

    public void lambda$setParentActivity$17() {
        this.stickerMakerView.isThanosInProgress = false;
    }

    public void lambda$setParentActivity$18(Bitmap bitmap, Runnable runnable) {
        this.centerImage.setImageBitmap(bitmap);
        this.cutOutBtn.setUndoCutState(true);
        showStickerMode(true, true);
        AndroidUtilities.cancelRunOnUIThread(runnable);
        AndroidUtilities.runOnUIThread(runnable, 800L);
    }

    public void lambda$setParentActivity$22(View view) {
        this.eraseBtn.setActive(true, true);
        this.restoreBtn.setActive(false, true);
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView != null) {
            stickerMakerView.setOutlineVisible(false);
        }
        this.maskPaintViewEraser = true;
        MaskPaintView maskPaintView = this.maskPaintView;
        if (maskPaintView != null) {
            maskPaintView.setEraser(true);
        }
        switchToEditMode(4);
    }

    public void lambda$setParentActivity$23(View view) {
        this.eraseBtn.setActive(false, true);
        this.restoreBtn.setActive(true, true);
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView != null) {
            stickerMakerView.setOutlineVisible(false);
        }
        this.maskPaintViewEraser = false;
        MaskPaintView maskPaintView = this.maskPaintView;
        if (maskPaintView != null) {
            maskPaintView.setEraser(false);
        }
        switchToEditMode(4);
    }

    public void lambda$setParentActivity$24(View view) {
        MaskPaintView maskPaintView = this.maskPaintView;
        if (maskPaintView == null || !maskPaintView.undo()) {
            switchToEditMode(0);
            this.stickerMakerView.resetPaths();
            boolean z = !TextUtils.isEmpty(((MediaController.MediaEditState) this.imagesArrLocals.get(this.currentIndex)).filterPath);
            StickerMakerView stickerMakerView = this.stickerMakerView;
            if (stickerMakerView != null && !stickerMakerView.empty) {
                stickerMakerView.setSegmentedState(false, null);
            }
            this.centerImage.setImageBitmap(this.stickerMakerView.getSourceBitmap(z));
            StickerMakerView stickerMakerView2 = this.stickerMakerView;
            if (stickerMakerView2 == null || !stickerMakerView2.empty) {
                this.cutOutBtn.setCutOutState(true);
            }
            showStickerMode(true, true);
        }
    }

    public void lambda$setParentActivity$25(View view) {
        if (this.stickerMakerView != null) {
            this.outlineBtn.setActive(!r3.isActive(), true);
            this.stickerMakerView.setOutlineVisible((!this.outlineBtn.isActive() || this.eraseBtn.isActive() || this.restoreBtn.isActive()) ? false : true);
        }
    }

    public void lambda$setParentActivity$26(View view) {
        if (this.captionEdit.isCaptionOverLimit()) {
            AnimatedTextView animatedTextView = ((CaptionContainerView) this.captionEdit).limitTextView;
            float f = -this.shiftDp;
            this.shiftDp = f;
            AndroidUtilities.shakeViewSpring(animatedTextView, f);
            BotWebViewVibrationEffect.APP_ERROR.vibrate();
            if (MessagesController.getInstance(this.currentAccount).premiumFeaturesBlocked() || MessagesController.getInstance(this.currentAccount).captionLengthLimitPremium <= this.captionEdit.getCodePointCount()) {
                return;
            }
            showCaptionLimitBulletin(this.containerView);
            return;
        }
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity != null && chatActivity.isInScheduleMode() && !this.parentChatActivity.isEditingMessageMedia()) {
            showScheduleDatePickerDialog();
        } else {
            sendPressed(true, 0);
        }
    }

    public boolean lambda$setParentActivity$32(org.telegram.ui.ActionBar.Theme.ResourcesProvider r18, android.view.View r19) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.lambda$setParentActivity$32(org.telegram.ui.ActionBar.Theme$ResourcesProvider, android.view.View):boolean");
    }

    public boolean lambda$setParentActivity$27(View view, MotionEvent motionEvent) {
        ActionBarPopupWindow actionBarPopupWindow;
        if (motionEvent.getActionMasked() != 0 || (actionBarPopupWindow = this.sendPopupWindow) == null || !actionBarPopupWindow.isShowing()) {
            return false;
        }
        view.getHitRect(this.hitRect);
        if (this.hitRect.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
            return false;
        }
        this.sendPopupWindow.dismiss();
        return false;
    }

    public void lambda$setParentActivity$28(KeyEvent keyEvent) {
        ActionBarPopupWindow actionBarPopupWindow;
        if (keyEvent.getKeyCode() == 4 && keyEvent.getRepeatCount() == 0 && (actionBarPopupWindow = this.sendPopupWindow) != null && actionBarPopupWindow.isShowing()) {
            this.sendPopupWindow.dismiss();
        }
    }

    public void lambda$setParentActivity$29(int i, View view) {
        ActionBarPopupWindow actionBarPopupWindow = this.sendPopupWindow;
        if (actionBarPopupWindow != null && actionBarPopupWindow.isShowing()) {
            this.sendPopupWindow.dismiss();
        }
        if (i == 0) {
            showScheduleDatePickerDialog();
            return;
        }
        if (i == 1) {
            sendPressed(false, 0);
            return;
        }
        if (i == 2) {
            replacePressed();
        } else if (i == 3) {
            sendPressed(true, 0);
        } else if (i == 4) {
            sendPressed(true, 0, false, true, false);
        }
    }

    public void lambda$setParentActivity$30(View view) {
        ActionBarPopupWindow actionBarPopupWindow = this.sendPopupWindow;
        if (actionBarPopupWindow != null && actionBarPopupWindow.isShowing()) {
            this.sendPopupWindow.dismiss();
        }
        sendPressed(true, 2147483646);
    }

    public void lambda$setParentActivity$31(View view) {
        ActionBarPopupWindow actionBarPopupWindow = this.sendPopupWindow;
        if (actionBarPopupWindow != null && actionBarPopupWindow.isShowing()) {
            this.sendPopupWindow.dismiss();
        }
        translateMessage();
    }

    public void lambda$setParentActivity$33(View view) {
        cancelStickerClippingMode();
        if (isCaptionOpen()) {
            return;
        }
        if (this.isCurrentVideo) {
            if (!this.videoConvertSupported) {
                return;
            }
            VideoEditTextureView videoEditTextureView = this.videoTextureView;
            if (!(videoEditTextureView instanceof VideoEditTextureView)) {
                return;
            }
            VideoEditTextureView videoEditTextureView2 = videoEditTextureView;
            if (videoEditTextureView2.getVideoWidth() <= 0 || videoEditTextureView2.getVideoHeight() <= 0) {
                return;
            }
        }
        switchToEditMode(1);
    }

    public void lambda$setParentActivity$34(View view) {
        cropRotate(-90.0f);
    }

    public void lambda$setParentActivity$35(View view) {
        cropMirror();
    }

    public void lambda$setParentActivity$36(View view) {
        cancelStickerClippingMode();
        if (isCaptionOpen()) {
            return;
        }
        if (this.isCurrentVideo) {
            if (!this.videoConvertSupported) {
                return;
            }
            VideoEditTextureView videoEditTextureView = this.videoTextureView;
            if (!(videoEditTextureView instanceof VideoEditTextureView)) {
                return;
            }
            VideoEditTextureView videoEditTextureView2 = videoEditTextureView;
            if (videoEditTextureView2.getVideoWidth() <= 0 || videoEditTextureView2.getVideoHeight() <= 0) {
                return;
            }
        }
        switchToEditMode(3);
    }

    public void lambda$setParentActivity$37(View view) {
        if (isCaptionOpen()) {
            return;
        }
        this.muteVideo = !this.muteVideo;
        updateMuteButton();
        updateVideoInfo();
        if (this.muteVideo && !this.checkImageView.isChecked()) {
            this.checkImageView.callOnClick();
            return;
        }
        Object obj = this.imagesArrLocals.get(this.currentIndex);
        if (obj instanceof MediaController.MediaEditState) {
            ((MediaController.MediaEditState) obj).editedInfo = getCurrentVideoEditedInfo();
        }
    }

    public void lambda$setParentActivity$38(Activity activity, View view) {
        if (isCaptionOpen() || this.muteVideo) {
            return;
        }
        if (this.compressItem.getTag() == null) {
            if (this.videoConvertSupported) {
                if (this.tooltip == null) {
                    this.tooltip = new Tooltip(activity, this.containerView, -871296751, -1);
                }
                this.tooltip.setText(LocaleController.getString("VideoQualityIsTooLow", R.string.VideoQualityIsTooLow));
                this.tooltip.show(this.compressItem);
                return;
            }
            return;
        }
        showQualityView(true);
        requestVideoPreview(1);
    }

    public void lambda$setParentActivity$39(View view) {
        if (view.getAlpha() < 0.9f) {
            return;
        }
        cancelStickerClippingMode();
        if (isCaptionOpen()) {
            return;
        }
        if (this.isCurrentVideo) {
            if (!this.videoConvertSupported) {
                return;
            }
            VideoEditTextureView videoEditTextureView = this.videoTextureView;
            if (!(videoEditTextureView instanceof VideoEditTextureView)) {
                return;
            }
            VideoEditTextureView videoEditTextureView2 = videoEditTextureView;
            if (videoEditTextureView2.getVideoWidth() <= 0 || videoEditTextureView2.getVideoHeight() <= 0) {
                return;
            }
        }
        switchToEditMode(2);
    }

    public void lambda$setParentActivity$41(View view) {
        if (this.imageMoveAnimation != null) {
            return;
        }
        Runnable runnable = new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$setParentActivity$40();
            }
        };
        if (!this.previousHasTransform) {
            float stateOrientation = this.previousCropOrientation - this.photoCropView.cropView.getStateOrientation();
            if (Math.abs(stateOrientation) > 180.0f) {
                stateOrientation = stateOrientation < 0.0f ? stateOrientation + 360.0f : -(360.0f - stateOrientation);
            }
            cropRotate(stateOrientation, this.photoCropView.cropView.getStateMirror(), runnable);
            return;
        }
        runnable.run();
    }

    public void lambda$setParentActivity$40() {
        this.cropTransform.setViewTransform(this.previousHasTransform, this.previousCropPx, this.previousCropPy, this.previousCropRotation, this.previousCropOrientation, this.previousCropScale, scale1(), scale1(), this.previousCropPw, this.previousCropPh, 0.0f, 0.0f, this.previousCropMirrored);
        switchToEditMode(0);
    }

    public void lambda$setParentActivity$42(View view) {
        if (this.currentEditMode != 1 || this.photoCropView.isReady()) {
            applyCurrentEditMode();
            switchToEditMode(0);
        }
    }

    public void lambda$setParentActivity$44(View view) {
        float f = -this.photoCropView.cropView.getStateOrientation();
        if (Math.abs(f) > 180.0f) {
            f = f < 0.0f ? f + 360.0f : -(360.0f - f);
        }
        cropRotate(f, this.photoCropView.cropView.getStateMirror(), new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$setParentActivity$43();
            }
        });
    }

    public void lambda$setParentActivity$43() {
        this.photoCropView.reset(true);
    }

    public void lambda$setParentActivity$45(ImageReceiver imageReceiver, boolean z, boolean z2, boolean z3) {
        PhotoViewerProvider photoViewerProvider;
        int i;
        Bitmap bitmap;
        int i2;
        if (imageReceiver == this.centerImage && z && !z2) {
            if (!this.isCurrentVideo && ((this.currentEditMode == 1 || (i2 = this.sendPhotoType) == 1 || i2 == 11) && this.photoCropView != null && (bitmap = imageReceiver.getBitmap()) != null)) {
                PhotoCropView photoCropView = this.photoCropView;
                int orientation = imageReceiver.getOrientation();
                int i3 = this.sendPhotoType;
                photoCropView.setBitmap(bitmap, orientation, (i3 == 1 || i3 == 11) ? false : true, true, this.paintingOverlay, this.cropTransform, (VideoEditTextureView) null, (MediaController.CropState) null);
            }
            if (this.paintingOverlay.getVisibility() == 0) {
                this.containerView.requestLayout();
            }
            detectFaces();
        }
        if (imageReceiver != this.centerImage || !z || (photoViewerProvider = this.placeProvider) == null || !photoViewerProvider.scaleToFill() || this.ignoreDidSetImage || (i = this.sendPhotoType) == 1 || i == 11) {
            return;
        }
        if (!this.wasLayout) {
            this.dontResetZoomOnFirstLayout = true;
        } else {
            setScaleToFill();
        }
    }

    public void lambda$setParentActivity$46(View view) {
        if (isCaptionOpen()) {
            return;
        }
        setPhotoChecked();
    }

    public void lambda$setParentActivity$47(View view) {
        PhotoViewerProvider photoViewerProvider;
        if (isCaptionOpen() || (photoViewerProvider = this.placeProvider) == null || photoViewerProvider.getSelectedPhotosOrder() == null || this.placeProvider.getSelectedPhotosOrder().isEmpty()) {
            return;
        }
        togglePhotosListView(!this.isPhotosListViewVisible, true);
    }

    public void lambda$setParentActivity$48(View view, int i) {
        int i2;
        if (!this.imagesArrLocals.isEmpty() && (i2 = this.currentIndex) >= 0 && i2 < this.imagesArrLocals.size()) {
            Object obj = this.imagesArrLocals.get(this.currentIndex);
            if (obj instanceof MediaController.MediaEditState) {
                ((MediaController.MediaEditState) obj).editedInfo = getCurrentVideoEditedInfo();
            }
        }
        this.ignoreDidSetImage = true;
        int indexOf = this.imagesArrLocals.indexOf(view.getTag());
        if (indexOf >= 0) {
            this.currentIndex = -1;
            setImageIndex(indexOf);
        }
        this.ignoreDidSetImage = false;
    }

    public boolean showCaptionLimitBulletin(FrameLayout view) {
        BaseFragment baseFragment = this.parentFragment;
        if (!(baseFragment instanceof ChatActivity) || !ChatObject.isChannelAndNotMegaGroup(((ChatActivity) baseFragment).getCurrentChat())) {
            return false;
        }
        this.limitBulletin = BulletinFactory.of(view, this.resourcesProvider).createCaptionLimitBulletin(MessagesController.getInstance(this.currentAccount).captionLengthLimitPremium, new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$showCaptionLimitBulletin$49();
            }
        }).setOnHideListener(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$showCaptionLimitBulletin$50();
            }
        }).show();
        return true;
    }

    public void lambda$showCaptionLimitBulletin$49() {
        closePhoto(false, false);
        ChatAttachAlert chatAttachAlert = this.parentAlert;
        if (chatAttachAlert != null) {
            chatAttachAlert.dismiss(true);
        }
        BaseFragment baseFragment = this.parentFragment;
        if (baseFragment != null) {
            baseFragment.presentFragment(new PremiumPreviewFragment("caption_limit"));
        }
    }

    public void lambda$showCaptionLimitBulletin$50() {
        this.limitBulletin = null;
    }

    public final void showScheduleDatePickerDialog() {
        if (this.parentChatActivity == null) {
            return;
        }
        AlertsCreator.createScheduleDatePickerDialog(this.parentActivity, this.parentChatActivity.getDialogId(), new AlertsCreator.ScheduleDatePickerDelegate() {
            public final void didSelectDate(boolean z, int i) {
                PhotoViewer.this.sendPressed(z, i);
            }
        }, new AlertsCreator.ScheduleDatePickerColors(-1, -14342875, -1, 520093695, -1, -115203550, 620756991));
    }

    public final void sendPressed(boolean notify, int scheduleDate) {
        sendPressed(notify, scheduleDate, false, false, false);
    }

    public final void replacePressed() {
        sendPressed(false, 0, true, false, false);
    }

    public final void sendPressed(final boolean notify, final int scheduleDate, final boolean replace, final boolean forceDocument, boolean confirmed) {
        Bitmap bitmap;
        VideoEditedInfo videoEditedInfo;
        String str;
        Object obj;
        MediaController.CropState cropState;
        int i;
        ChatActivity chatActivity;
        ImageUpdater.AvatarFor avatarFor;
        String str2;
        CharSequence string;
        TextureView textureView;
        if (isCaptionOpen() || this.placeProvider == null || this.doneButtonPressed) {
            return;
        }
        char c = 1;
        if (this.sendPhotoType == 1) {
            if (!confirmed && (avatarFor = this.setAvatarFor) != null) {
                long j = 0;
                TLRPC.User user = avatarFor.object;
                if (user instanceof TLRPC.User) {
                    String str3 = user.first_name;
                    long j2 = user.id;
                    str2 = str3;
                    j = j2;
                } else {
                    str2 = "";
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(this.containerView.getContext());
                builder.setAdditionalHorizontalPadding(AndroidUtilities.dp(8.0f));
                SuggestUserPhotoView suggestUserPhotoView = new SuggestUserPhotoView(this.containerView.getContext());
                suggestUserPhotoView.setImages(this.setAvatarFor.object, this.containerView, this.photoCropView);
                builder.setTopView(suggestUserPhotoView);
                if (this.setAvatarFor.type == 1) {
                    if (UserConfig.getInstance(this.currentAccount).clientUserId == j) {
                        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("SetUserPhotoSelfAlertMessage", R.string.SetUserPhotoSelfAlertMessage)));
                    } else {
                        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("SetUserPhotoAlertMessage", R.string.SetUserPhotoAlertMessage, new Object[]{str2, str2})));
                    }
                    if (this.centerImageIsVideo) {
                        string = LocaleController.getString("SetVideo", R.string.SetVideo);
                    } else {
                        string = LocaleController.getString("SetPhoto", R.string.SetPhoto);
                    }
                } else {
                    if (this.centerImageIsVideo) {
                        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("SuggestVideoAlertMessage", R.string.SuggestVideoAlertMessage, new Object[]{str2})));
                    } else {
                        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("SuggestPhotoAlertMessage", R.string.SuggestPhotoAlertMessage, new Object[]{str2})));
                    }
                    string = LocaleController.getString("SuggestPhotoShort", R.string.SuggestPhotoShort);
                }
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(DialogInterface dialogInterface, int i2) {
                        PhotoViewer.lambda$sendPressed$52(dialogInterface, i2);
                    }
                });
                builder.setPositiveButton(string, new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(DialogInterface dialogInterface, int i2) {
                        PhotoViewer.this.lambda$sendPressed$53(notify, scheduleDate, replace, forceDocument, dialogInterface, i2);
                    }
                });
                builder.setDialogButtonColorKey(Theme.key_voipgroup_listeningText);
                AlertDialog create = builder.create();
                create.setBlurParams(0.8f, false, true);
                create.setBackgroundColor(ColorUtils.setAlphaComponent(-15461356, 204));
                create.show();
                create.setTextColor(Theme.getColor(Theme.key_voipgroup_nameText));
                create.setOnDismissListener(new AnonymousClass36());
                if (!this.isCurrentVideo || (textureView = this.videoTextureView) == null) {
                    return;
                }
                try {
                    this.lastFrameBitmap = textureView.getBitmap();
                    ImageView imageView = this.lastFrameImageView;
                    if (imageView != null) {
                        this.aspectRatioFrameLayout.removeView(imageView);
                        this.lastFrameImageView = null;
                    }
                    ImageView imageView2 = new ImageView(this.videoTextureView.getContext());
                    this.lastFrameImageView = imageView2;
                    imageView2.setBackground(new BitmapDrawable(this.lastFrameBitmap));
                    this.aspectRatioFrameLayout.addView(this.lastFrameImageView);
                    return;
                } catch (Throwable th) {
                    Bitmap bitmap2 = this.currentBitmap;
                    if (bitmap2 != null) {
                        bitmap2.recycle();
                        this.currentBitmap = null;
                    }
                    FileLog.e(th);
                    return;
                }
            }
            applyCurrentEditMode();
        }
        if (!replace && (chatActivity = this.parentChatActivity) != null) {
            TLRPC.Chat currentChat = chatActivity.getCurrentChat();
            if ((this.parentChatActivity.getCurrentUser() != null || ((ChatObject.isChannel(currentChat) && currentChat.megagroup) || !ChatObject.isChannel(currentChat))) && !PlusSettings.showSendWithoutSound) {
                MessagesController.getNotificationsSettings(this.currentAccount).edit().putBoolean("silent_" + this.parentChatActivity.getDialogId(), !notify).commit();
            }
        }
        VideoEditedInfo currentVideoEditedInfo = getCurrentVideoEditedInfo();
        if (!this.imagesArrLocals.isEmpty() && (i = this.currentIndex) >= 0 && i < this.imagesArrLocals.size()) {
            Object obj2 = this.imagesArrLocals.get(this.currentIndex);
            if (obj2 instanceof MediaController.MediaEditState) {
                ((MediaController.MediaEditState) obj2).editedInfo = currentVideoEditedInfo;
            }
        }
        ChatActivity chatActivity2 = this.parentChatActivity;
        if (chatActivity2 != null && chatActivity2.getCurrentChat() != null) {
            boolean z = this.isCurrentVideo || currentVideoEditedInfo != null;
            if (z && !ChatObject.canSendVideo(this.parentChatActivity.getCurrentChat())) {
                BulletinFactory.of(this.containerView, this.resourcesProvider).createErrorBulletin(LocaleController.getString(R.string.GlobalAttachVideoRestricted)).show();
                return;
            } else if (!z && !ChatObject.canSendPhoto(this.parentChatActivity.getCurrentChat())) {
                BulletinFactory.of(this.containerView, this.resourcesProvider).createErrorBulletin(LocaleController.getString(R.string.GlobalAttachPhotoRestricted)).show();
                return;
            }
        }
        this.doneButtonPressed = true;
        if (currentVideoEditedInfo != null) {
            long j3 = (long) (currentVideoEditedInfo.estimatedSize * 0.9f);
            if ((j3 > 2097152000 && !UserConfig.getInstance(this.currentAccount).isPremium()) || j3 > 4194304000L) {
                if (this.parentAlert != null) {
                    new LimitReachedBottomSheet(this.parentAlert.getBaseFragment(), this.parentAlert.getContainer().getContext(), 6, UserConfig.selectedAccount, null).show();
                    return;
                }
                return;
            }
        }
        if (!replace) {
            if (this.sendPhotoType == 11) {
                Object obj3 = this.imagesArrLocals.get(this.currentIndex);
                if (obj3 instanceof MediaController.PhotoEntry) {
                    final MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj3;
                    Bitmap createBitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(createBitmap);
                    Path path = new Path();
                    RectF rectF = new RectF();
                    rectF.set(0.0f, 0.0f, createBitmap.getWidth(), createBitmap.getHeight());
                    int i2 = 8;
                    float width = createBitmap.getWidth() / 8;
                    path.addRoundRect(rectF, width, width, Path.Direction.CW);
                    canvas.clipPath(path);
                    int containerViewWidth = getContainerViewWidth();
                    getContainerViewHeight();
                    float dp = containerViewWidth - AndroidUtilities.dp(20.0f);
                    StickerMakerView stickerMakerView = this.stickerMakerView;
                    if (stickerMakerView != null && stickerMakerView.outlineVisible && stickerMakerView.getSourceBitmap() != null) {
                        canvas.save();
                        canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
                        canvas.scale(createBitmap.getWidth() / dp, createBitmap.getHeight() / dp);
                        applyTransformToOutline(canvas);
                        this.stickerMakerView.drawOutline(canvas, false, null, false);
                        canvas.restore();
                        canvas.save();
                        canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
                        canvas.scale(createBitmap.getWidth() / dp, createBitmap.getHeight() / dp);
                        applyTransformToOutline(canvas);
                        this.centerImage.draw(canvas);
                        canvas.restore();
                        canvas.save();
                        canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
                        canvas.scale(createBitmap.getWidth() / dp, createBitmap.getHeight() / dp);
                        applyTransformToOutline(canvas);
                        this.stickerMakerView.drawOutline(canvas, true, null, false);
                        canvas.restore();
                    } else {
                        canvas.save();
                        canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
                        canvas.scale(createBitmap.getWidth() / dp, createBitmap.getHeight() / dp);
                        applyTransformToOutline(canvas);
                        this.centerImage.draw(canvas);
                        canvas.restore();
                    }
                    if (this.paintingOverlay != null) {
                        canvas.save();
                        canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
                        canvas.scale(createBitmap.getWidth() / dp, createBitmap.getHeight() / dp);
                        applyTransformToOutline(canvas);
                        canvas.translate((-this.centerImage.getImageWidth()) / 2.0f, (-this.centerImage.getImageHeight()) / 2.0f);
                        canvas.scale(this.centerImage.getImageWidth() / this.paintingOverlay.getMeasuredWidth(), this.centerImage.getImageHeight() / this.paintingOverlay.getMeasuredHeight());
                        this.paintingOverlay.drawChildren = !hasAnimatedMediaEntities();
                        this.paintingOverlay.draw(canvas);
                        this.paintingOverlay.drawChildren = true;
                        canvas.restore();
                    }
                    if (hasAnimatedMediaEntities()) {
                        Matrix matrix = new Matrix();
                        matrix.reset();
                        float f = dp / 2.0f;
                        matrix.preTranslate(f, f);
                        applyTransformToMatrix(matrix);
                        matrix.preTranslate((-this.centerImage.getImageWidth()) / 2.0f, (-this.centerImage.getImageHeight()) / 2.0f);
                        matrix.preScale(this.centerImage.getImageWidth(), this.centerImage.getImageHeight());
                        ArrayList arrayList = new ArrayList();
                        Iterator it = ((MediaController.MediaEditState) photoEntry).mediaEntities.iterator();
                        String str4 = null;
                        while (it.hasNext()) {
                            VideoEditedInfo.MediaEntity copy = ((VideoEditedInfo.MediaEntity) it.next()).copy();
                            float f2 = copy.x;
                            float f3 = copy.y;
                            float f4 = copy.width;
                            float f5 = copy.height;
                            Iterator it2 = it;
                            float[] fArr = new float[i2];
                            fArr[0] = f2;
                            fArr[c] = f3;
                            float f6 = f4 + f2;
                            fArr[2] = f6;
                            fArr[3] = f3;
                            fArr[4] = f6;
                            float f7 = f3 + f5;
                            fArr[5] = f7;
                            fArr[6] = f2;
                            fArr[7] = f7;
                            matrix.mapPoints(fArr);
                            Bitmap bitmap3 = createBitmap;
                            copy.width = ((float) Math.sqrt(Math.pow(fArr[0] - fArr[2], 2.0d) + Math.pow(fArr[c] - fArr[3], 2.0d))) / dp;
                            float sqrt = ((float) Math.sqrt(Math.pow(fArr[0] - fArr[6], 2.0d) + Math.pow(fArr[1] - fArr[7], 2.0d))) / dp;
                            copy.height = sqrt;
                            copy.x = (((fArr[0] + fArr[4]) / 2.0f) / dp) - (copy.width / 2.0f);
                            copy.y = (((fArr[1] + fArr[5]) / 2.0f) / dp) - (sqrt / 2.0f);
                            copy.scale = 1.0f;
                            copy.customTextView = true;
                            if (((MediaController.MediaEditState) photoEntry).isCropped && (cropState = ((MediaController.MediaEditState) photoEntry).cropState) != null) {
                                double d = copy.rotation;
                                double d2 = cropState.transformRotation / 180.0f;
                                Double.isNaN(d2);
                                Double.isNaN(d);
                                copy.rotation = (float) (d - (d2 * 3.141592653589793d));
                            }
                            double d3 = copy.rotation;
                            double d4 = this.rotate / 180.0f;
                            Double.isNaN(d4);
                            Double.isNaN(d3);
                            copy.rotation = (float) (d3 - (d4 * 3.141592653589793d));
                            arrayList.add(copy);
                            TLRPC.Document document = copy.document;
                            if (document == null || str4 != null) {
                                obj = null;
                            } else {
                                obj = null;
                                str4 = MessageObject.findAnimatedEmojiEmoticon(document, (String) null);
                            }
                            it = it2;
                            createBitmap = bitmap3;
                            c = 1;
                            i2 = 8;
                        }
                        bitmap = createBitmap;
                        VideoEditedInfo videoEditedInfo2 = new VideoEditedInfo();
                        videoEditedInfo2.isPhoto = true;
                        videoEditedInfo2.resultWidth = 512;
                        videoEditedInfo2.originalWidth = 512;
                        videoEditedInfo2.resultHeight = 512;
                        videoEditedInfo2.originalHeight = 512;
                        videoEditedInfo2.mediaEntities = arrayList;
                        long clamp = Utilities.clamp(((MediaController.MediaEditState) photoEntry).averageDuration, 2999L, 800L);
                        videoEditedInfo2.estimatedDuration = clamp;
                        videoEditedInfo2.originalDuration = clamp;
                        videoEditedInfo2.bitrate = 200000;
                        videoEditedInfo2.framerate = 30;
                        videoEditedInfo2.isSticker = true;
                        videoEditedInfo2.estimatedSize = 262144L;
                        videoEditedInfo = videoEditedInfo2;
                        str = str4;
                    } else {
                        bitmap = createBitmap;
                        videoEditedInfo = null;
                        str = null;
                    }
                    float f8 = 512;
                    final String file = FileLoader.getInstance(UserConfig.selectedAccount).getPathToAttach(ImageLoader.scaleAndSaveImage(bitmap, Bitmap.CompressFormat.WEBP, f8, f8, 100, false, 101, 101), "webp", true).toString();
                    if (videoEditedInfo != null) {
                        videoEditedInfo.originalPath = file;
                    }
                    if (this.selectedEmojis == null) {
                        this.selectedEmojis = new ArrayList<>();
                    }
                    if (this.selectedEmojis.isEmpty()) {
                        String str5 = this.stickerMakerView.detectedEmoji;
                        if (str5 != null && Emoji.getEmojiDrawable(str5) != null) {
                            this.selectedEmojis.add(this.stickerMakerView.detectedEmoji);
                        } else if (str != null) {
                            this.selectedEmojis.add(str);
                        } else {
                            this.selectedEmojis.add("👍");
                        }
                    }
                    this.doneButtonPressed = false;
                    final VideoEditedInfo videoEditedInfo3 = videoEditedInfo;
                    ContentPreviewViewer.getInstance().showCustomStickerActions(file, videoEditedInfo, this.stickerMakerView, this.selectedEmojis, new ContentPreviewViewer.ContentPreviewViewerDelegate() {
                        @Override
                        public boolean can() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$can(this);
                        }

                        @Override
                        public boolean canDeleteSticker(TLRPC.Document document2) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$canDeleteSticker(this, document2);
                        }

                        @Override
                        public boolean canEditSticker() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$canEditSticker(this);
                        }

                        @Override
                        public boolean canSchedule() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$canSchedule(this);
                        }

                        @Override
                        public Boolean canSetAsStatus(TLRPC.Document document2) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$canSetAsStatus(this, document2);
                        }

                        @Override
                        public void copyEmoji(TLRPC.Document document2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$copyEmoji(this, document2);
                        }

                        @Override
                        public void deleteSticker(TLRPC.Document document2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$deleteSticker(this, document2);
                        }

                        @Override
                        public void editSticker(TLRPC.Document document2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$editSticker(this, document2);
                        }

                        @Override
                        public String getQuery(boolean z2) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$getQuery(this, z2);
                        }

                        @Override
                        public void gifAddedOrDeleted() {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$gifAddedOrDeleted(this);
                        }

                        @Override
                        public boolean isInScheduleMode() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$isInScheduleMode(this);
                        }

                        @Override
                        public boolean isPhotoEditor() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$isPhotoEditor(this);
                        }

                        @Override
                        public boolean isStickerEditor() {
                            return true;
                        }

                        @Override
                        public boolean needCopy(TLRPC.Document document2) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needCopy(this, document2);
                        }

                        @Override
                        public boolean needMenu() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needMenu(this);
                        }

                        @Override
                        public boolean needOpen() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needOpen(this);
                        }

                        @Override
                        public boolean needRemove() {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needRemove(this);
                        }

                        @Override
                        public boolean needRemoveFromRecent(TLRPC.Document document2) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needRemoveFromRecent(this, document2);
                        }

                        @Override
                        public boolean needSend(int i3) {
                            return ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$needSend(this, i3);
                        }

                        @Override
                        public void openSet(TLRPC.InputStickerSet inputStickerSet, boolean z2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$openSet(this, inputStickerSet, z2);
                        }

                        @Override
                        public void remove(SendMessagesHelper.ImportingSticker importingSticker) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$remove(this, importingSticker);
                        }

                        @Override
                        public void removeFromRecent(TLRPC.Document document2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$removeFromRecent(this, document2);
                        }

                        @Override
                        public void resetTouch() {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$resetTouch(this);
                        }

                        @Override
                        public void sendEmoji(TLRPC.Document document2) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$sendEmoji(this, document2);
                        }

                        @Override
                        public void sendGif(Object obj4, Object obj5, boolean z2, int i3) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$sendGif(this, obj4, obj5, z2, i3);
                        }

                        @Override
                        public void sendSticker(TLRPC.Document document2, String str6, Object obj4, boolean z2, int i3) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$sendSticker(this, document2, str6, obj4, z2, i3);
                        }

                        @Override
                        public void setAsEmojiStatus(TLRPC.Document document2, Integer num) {
                            ContentPreviewViewer.ContentPreviewViewerDelegate.CC.$default$setAsEmojiStatus(this, document2, num);
                        }

                        @Override
                        public void sendSticker() {
                            if (PhotoViewer.this.placeProvider == null) {
                                return;
                            }
                            PhotoViewer.this.stickerEmptySent = true;
                            generateThumb();
                            ((MediaController.MediaEditState) photoEntry).imagePath = file;
                            PhotoViewer.this.placeProvider.sendButtonPressed(PhotoViewer.this.currentIndex, videoEditedInfo3, notify, scheduleDate, forceDocument);
                            NotificationCenter.getInstance(UserConfig.selectedAccount).postNotificationNameOnUIThread(NotificationCenter.customStickerCreated, new Object[]{Boolean.TRUE});
                        }

                        public final void generateThumb() {
                            ContentPreviewViewer contentPreviewViewer = ContentPreviewViewer.getInstance();
                            if (((MediaController.MediaEditState) photoEntry).thumbPath != null) {
                                try {
                                    new File(((MediaController.MediaEditState) photoEntry).thumbPath).delete();
                                } catch (Exception e) {
                                    FileLog.e(e);
                                }
                                ((MediaController.MediaEditState) photoEntry).thumbPath = null;
                            }
                            Bitmap createBitmap2 = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
                            Canvas canvas2 = new Canvas(createBitmap2);
                            ImageReceiver imageReceiver = contentPreviewViewer.centerImage;
                            if (imageReceiver != null) {
                                imageReceiver.setAlpha(1.0f);
                                contentPreviewViewer.centerImage.setImageCoords(0.0f, 0.0f, createBitmap2.getWidth(), createBitmap2.getHeight());
                                contentPreviewViewer.centerImage.draw(canvas2);
                            }
                            if (contentPreviewViewer.paintingOverlay != null) {
                                canvas2.save();
                                canvas2.scale(createBitmap2.getWidth() / contentPreviewViewer.paintingOverlay.getWidth(), createBitmap2.getHeight() / contentPreviewViewer.paintingOverlay.getHeight());
                                contentPreviewViewer.paintingOverlay.setAlpha(1.0f);
                                Path path2 = new Path();
                                path2.rewind();
                                RectF rectF2 = AndroidUtilities.rectTmp;
                                rectF2.set(0.0f, 0.0f, contentPreviewViewer.paintingOverlay.getWidth(), contentPreviewViewer.paintingOverlay.getHeight());
                                path2.addRoundRect(rectF2, contentPreviewViewer.paintingOverlay.getWidth() / 8.0f, contentPreviewViewer.paintingOverlay.getHeight() / 8.0f, Path.Direction.CW);
                                canvas2.clipPath(path2);
                                contentPreviewViewer.paintingOverlay.draw(canvas2);
                                canvas2.restore();
                            }
                            ((MediaController.MediaEditState) photoEntry).thumbPath = FileLoader.getInstance(PhotoViewer.this.currentAccount).getPathToAttach(ImageLoader.scaleAndSaveImage(createBitmap2, PhotoViewer.this.getCompressFormat(), 512.0f, 512.0f, 83, false, 101, 101), true).toString();
                        }

                        @Override
                        public void addToFavoriteSelected(String emoji) {
                            PhotoViewer.this.stickerEmptySent = true;
                            generateThumb();
                            PhotoViewer.this.stickerMakerView.uploadStickerFile(file, videoEditedInfo3, emoji, null, true, null, null, ((MediaController.MediaEditState) photoEntry).thumbPath, null, null);
                        }

                        @Override
                        public void stickerSetSelected(TLRPC.StickerSet stickerSet, String emoji) {
                            PhotoViewer.this.stickerEmptySent = true;
                            generateThumb();
                            PhotoViewer photoViewer = PhotoViewer.this;
                            photoViewer.stickerMakerView.uploadStickerFile(file, videoEditedInfo3, emoji, null, false, stickerSet, photoViewer.replacedSticker, ((MediaController.MediaEditState) photoEntry).thumbPath, null, null);
                        }

                        @Override
                        public void newStickerPackSelected(CharSequence name, String emoji, Utilities.Callback<Boolean> whenDone) {
                            PhotoViewer.this.stickerEmptySent = true;
                            generateThumb();
                            PhotoViewer.this.stickerMakerView.uploadStickerFile(file, videoEditedInfo3, emoji, name, false, null, null, ((MediaController.MediaEditState) photoEntry).thumbPath, whenDone, null);
                        }

                        @Override
                        public void setIntroSticker(String emoji) {
                            PhotoViewer.this.stickerEmptySent = true;
                            generateThumb();
                            PhotoViewer photoViewer = PhotoViewer.this;
                            photoViewer.stickerMakerView.uploadStickerFile(file, videoEditedInfo3, emoji, null, false, null, null, ((MediaController.MediaEditState) photoEntry).thumbPath, null, photoViewer.customStickerHandler);
                        }

                        @Override
                        public boolean isReplacedSticker() {
                            return PhotoViewer.this.replacedSticker != null;
                        }

                        @Override
                        public boolean isSettingIntroSticker() {
                            return PhotoViewer.this.customStickerHandler != null;
                        }

                        @Override
                        public long getDialogId() {
                            return PhotoViewer.this.currentDialogId;
                        }
                    });
                    return;
                }
            }
            this.placeProvider.sendButtonPressed(this.currentIndex, currentVideoEditedInfo, notify, scheduleDate, forceDocument);
        } else {
            this.placeProvider.replaceButtonPressed(this.currentIndex, currentVideoEditedInfo);
        }
        if (this.closePhotoAfterSelect) {
            closePhoto(false, false);
        }
    }

    public void lambda$sendPressed$53(boolean z, int i, boolean z2, boolean z3, DialogInterface dialogInterface, int i2) {
        sendPressed(z, i, z2, z3, true);
    }

    public class AnonymousClass36 implements DialogInterface.OnDismissListener {
        public AnonymousClass36() {
        }

        @Override
        public void onDismiss(DialogInterface dialog) {
            if (PhotoViewer.this.lastFrameImageView != null) {
                PhotoViewer.this.lastFrameImageView.animate().alpha(0.0f).withEndAction(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass36.this.lambda$onDismiss$0();
                    }
                }).setDuration(150L).start();
            }
        }

        public void lambda$onDismiss$0() {
            if (PhotoViewer.this.lastFrameImageView == null || PhotoViewer.this.lastFrameImageView.getParent() == null) {
                return;
            }
            ((ViewGroup) PhotoViewer.this.lastFrameImageView.getParent()).removeView(PhotoViewer.this.lastFrameImageView);
            if (PhotoViewer.this.lastFrameBitmap != null) {
                if (PhotoViewer.this.lastFrameImageView != null) {
                    PhotoViewer.this.lastFrameImageView.setBackground(null);
                }
                AndroidUtilities.recycleBitmap(PhotoViewer.this.lastFrameBitmap);
                PhotoViewer.this.lastFrameBitmap = null;
            }
            PhotoViewer.this.lastFrameImageView = null;
        }
    }

    public final String getTempFileAbsolutePath() {
        return new File(FileLoader.getDirectory(4), SharedConfig.getLastLocalId() + "_temp.jpg").getAbsolutePath();
    }

    public final Bitmap.CompressFormat getCompressFormat() {
        return this.sendPhotoType == 11 ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG;
    }

    public final boolean isCaptionOpen() {
        CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
        return captionPhotoViewer != null && (((CaptionContainerView) captionPhotoViewer).keyboardNotifier.keyboardVisible() || ((CaptionContainerView) this.captionEdit).editText.isPopupShowing());
    }

    public final void showShareAlert(ArrayList<MessageObject> messages) {
        boolean z;
        boolean z2;
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
        requestAdjustToNothing();
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity == null || chatActivity.getChatActivityEnterView() == null || this.parentChatActivity.getFragmentView() == null) {
            z = false;
        } else {
            if (this.parentChatActivity.getChatActivityEnterView().isKeyboardVisible()) {
                this.parentChatActivity.getChatActivityEnterView().showEmojiView();
                z2 = true;
            } else {
                z2 = false;
            }
            AndroidUtilities.setAdjustResizeToNothing(this.parentChatActivity.getParentActivity(), this.classGuid);
            this.parentChatActivity.getFragmentView().requestLayout();
            z = z2;
        }
        final ShareAlert anonymousClass38 = new AnonymousClass38(this.parentActivity, this.parentChatActivity, messages, null, null, false, null, null, false, true, false, null, sizeNotifierFrameLayoutPhoto, z);
        anonymousClass38.setFocusable(false);
        anonymousClass38.getWindow().setSoftInputMode(48);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$showShareAlert$54(anonymousClass38);
            }
        }, 250L);
        anonymousClass38.show();
    }

    public class AnonymousClass38 extends ShareAlert {
        public final boolean val$finalOpenKeyboardOnShareAlertClose;
        public final FrameLayout val$photoContainerView;

        public AnonymousClass38(final Context context, ChatActivity fragment, ArrayList messages, final String text, final String text2, boolean channel, final String copyLink, final String copyLink2, boolean fullScreen, boolean forCall, boolean includeStory, Theme.ResourcesProvider resourcesProvider, final FrameLayout val$photoContainerView, final boolean val$finalOpenKeyboardOnShareAlertClose) {
            super(context, fragment, messages, text, text2, channel, copyLink, copyLink2, fullScreen, forCall, includeStory, resourcesProvider);
            this.val$photoContainerView = val$photoContainerView;
            this.val$finalOpenKeyboardOnShareAlertClose = val$finalOpenKeyboardOnShareAlertClose;
        }

        public void onSend(final LongSparseArray<TLRPC.Dialog> dids, final int count, TLRPC.TL_forumTopic topic) {
            final FrameLayout frameLayout = this.val$photoContainerView;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass38.this.lambda$onSend$0(frameLayout, dids, count);
                }
            }, 250L);
        }

        public void lambda$onSend$0(FrameLayout frameLayout, LongSparseArray longSparseArray, int i) {
            BulletinFactory.createForwardedBulletin(PhotoViewer.this.parentActivity, frameLayout, longSparseArray.size(), longSparseArray.size() == 1 ? ((TLRPC.Dialog) longSparseArray.valueAt(0)).id : 0L, i, -115203550, -1).show();
        }

        public void dismissInternal() {
            super.dismissInternal();
            if (this.val$finalOpenKeyboardOnShareAlertClose) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass38.this.lambda$dismissInternal$1();
                    }
                }, 50L);
            }
            PhotoViewer.this.requestAdjust();
        }

        public void lambda$dismissInternal$1() {
            if (PhotoViewer.this.parentChatActivity == null || PhotoViewer.this.parentChatActivity.getChatActivityEnterView() == null) {
                return;
            }
            PhotoViewer.this.parentChatActivity.getChatActivityEnterView().openKeyboard();
        }
    }

    public void lambda$showShareAlert$54(ShareAlert shareAlert) {
        if (shareAlert == null || shareAlert.getWindow() == null) {
            return;
        }
        shareAlert.setFocusable(true);
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity == null || chatActivity.getChatActivityEnterView() == null) {
            return;
        }
        this.parentChatActivity.getChatActivityEnterView().hidePopup(false);
    }

    public final void updateActionBarTitlePadding() {
        if (this.menu == null || this.actionBarContainer == null) {
            return;
        }
        float f = 0.0f;
        for (int i = 0; i < this.menu.getChildCount(); i++) {
            View childAt = this.menu.getChildAt(i);
            if (childAt.getVisibility() == 0) {
                f += Math.min(0.5f, childAt.getAlpha()) * 2.0f * childAt.getWidth();
            }
        }
        CheckBox checkBox = this.checkImageView;
        if (checkBox != null && checkBox.getVisibility() == 0) {
            f = Math.max(f, AndroidUtilities.dp(48.0f));
        }
        CounterView counterView = this.photosCounterView;
        if (counterView != null && counterView.getVisibility() == 0) {
            f = Math.max(f, AndroidUtilities.dp(100.0f));
        }
        this.actionBarContainer.updateRightPadding(f, false);
    }

    public final void setMenuItemIcon(boolean animated, boolean isFinal) {
        if (this.speedItem.getVisibility() != 0) {
            this.menuItemIcon.setSpeed((Float) null, animated);
            return;
        }
        this.menuItemIcon.setSpeed(Math.abs(this.currentVideoSpeed - 1.0f) >= 0.001f ? Float.valueOf(this.currentVideoSpeed) : null, animated);
        if (isFinal) {
            if (Math.abs(this.currentVideoSpeed - 0.2f) < 0.05f) {
                this.speedItem.setSubtext(LocaleController.getString("VideoSpeedVerySlow", R.string.VideoSpeedVerySlow));
            } else if (Math.abs(this.currentVideoSpeed - 0.5f) < 0.05f) {
                this.speedItem.setSubtext(LocaleController.getString("VideoSpeedSlow", R.string.VideoSpeedSlow));
            } else if (Math.abs(this.currentVideoSpeed - 1.0f) < 0.05f) {
                this.speedItem.setSubtext(LocaleController.getString("VideoSpeedNormal", R.string.VideoSpeedNormal));
            } else if (Math.abs(this.currentVideoSpeed - 1.5f) < 0.05f) {
                this.speedItem.setSubtext(LocaleController.getString("VideoSpeedFast", R.string.VideoSpeedFast));
            } else if (Math.abs(this.currentVideoSpeed - 2.0f) < 0.05f) {
                this.speedItem.setSubtext(LocaleController.getString("VideoSpeedVeryFast", R.string.VideoSpeedVeryFast));
            } else {
                this.speedItem.setSubtext(LocaleController.formatString("VideoSpeedCustom", R.string.VideoSpeedCustom, new Object[]{SpeedIconDrawable.formatNumber(this.currentVideoSpeed) + "x"}));
            }
        }
        this.chooseSpeedLayout.update(this.currentVideoSpeed, isFinal);
    }

    public float getCurrentVideoSpeed() {
        return this.currentVideoSpeed;
    }

    public final boolean checkInlinePermissions() {
        Activity activity = this.parentActivity;
        if (activity == null) {
            return false;
        }
        if (Build.VERSION.SDK_INT < 23 || Settings.canDrawOverlays(activity)) {
            return true;
        }
        AlertsCreator.createDrawOverlayPermissionDialog(this.parentActivity, (DialogInterface.OnClickListener) null).show();
        return false;
    }

    public final void captureCurrentFrame() {
        TextureView textureView;
        if (this.captureFrameAtTime == -1 || (textureView = this.videoTextureView) == null) {
            return;
        }
        this.captureFrameAtTime = -1L;
        final Bitmap bitmap = textureView.getBitmap();
        this.flashView.animate().alpha(1.0f).setInterpolator(CubicBezierInterpolator.EASE_BOTH).setDuration(85L).setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                PhotoViewer.this.photoCropView.setVideoThumb(bitmap, 0);
                PhotoViewer.this.flashAnimator = new AnimatorSet();
                PhotoViewer.this.flashAnimator.playTogether(ObjectAnimator.ofFloat(PhotoViewer.this.flashView, PhotoViewer.this.FLASH_VIEW_VALUE, 0.0f));
                PhotoViewer.this.flashAnimator.setDuration(85L);
                PhotoViewer.this.flashAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT);
                PhotoViewer.this.flashAnimator.addListener(new AnonymousClass1());
                PhotoViewer.this.flashAnimator.start();
            }

            public class AnonymousClass1 extends AnimatorListenerAdapter {
                public AnonymousClass1() {
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (PhotoViewer.this.flashAnimator == null) {
                        return;
                    }
                    PhotoViewer photoViewer = PhotoViewer.this;
                    Runnable runnable = new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.AnonymousClass39.AnonymousClass1.this.lambda$onAnimationEnd$0();
                        }
                    };
                    photoViewer.videoPlayRunnable = runnable;
                    AndroidUtilities.runOnUIThread(runnable, 860L);
                }

                public void lambda$onAnimationEnd$0() {
                    PhotoViewer.this.manuallyPaused = false;
                    if (PhotoViewer.this.videoPlayer != null) {
                        PhotoViewer.this.videoPlayer.play();
                    }
                    PhotoViewer.this.videoPlayRunnable = null;
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    PhotoViewer.this.flashAnimator = null;
                }
            }
        }).start();
    }

    public static class CaptionTextView extends SpoilersTextView {
        public AnimatedEmojiSpan.EmojiGroupedSpans animatedEmojiDrawables;
        public boolean hasQuote;
        public Layout lastLayout;
        public Layout lastLoadingLayout;
        public final LinkSpanDrawable.LinkCollector links;
        public boolean loading;
        public LoadingDrawable loadingDrawable;
        public Path loadingPath;
        public final Utilities.Callback2<ClickableSpan, TextView> onLinkClick;
        public final Utilities.Callback3<URLSpan, TextView, Runnable> onLinkLongPress;
        public LinkSpanDrawable<ClickableSpan> pressedLink;
        public ArrayList<QuoteSpan.Block> quoteBlocks;
        public final CaptionScrollView scrollView;
        public final TextSelectionHelper.SimpleTextSelectionHelper textSelectionHelper;

        public CaptionTextView(Context context, final CaptionScrollView scrollView, TextSelectionHelper.SimpleTextSelectionHelper textSelectionHelper, Utilities.Callback2<ClickableSpan, TextView> onLinkClick, Utilities.Callback3<URLSpan, TextView, Runnable> onLinkLongPress) {
            super(context);
            this.links = new LinkSpanDrawable.LinkCollector(this);
            this.scrollView = scrollView;
            this.onLinkClick = onLinkClick;
            this.onLinkLongPress = onLinkLongPress;
            this.textSelectionHelper = textSelectionHelper;
            ViewHelper.setPadding(this, 16.0f, 8.0f, 16.0f, 8.0f);
            setLinkTextColor(-8796932);
            setTextColor(-1);
            setHighlightColor(872415231);
            setGravity(LayoutHelper.getAbsoluteGravityStart() | 16);
            setTextSize(1, 16.0f);
            setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PhotoViewer.CaptionTextView.lambda$new$0(PhotoViewer.CaptionScrollView.this, view);
                }
            });
        }

        public static void lambda$new$0(CaptionScrollView captionScrollView, View view) {
            if (captionScrollView != null) {
                captionScrollView.smoothScrollBy(0, AndroidUtilities.dp(64.0f));
            }
        }

        public boolean onTouchEvent(android.view.MotionEvent r10) {
            throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.CaptionTextView.onTouchEvent(android.view.MotionEvent):boolean");
        }

        public void lambda$onTouchEvent$1(LinkSpanDrawable linkSpanDrawable) {
            LinkSpanDrawable<ClickableSpan> linkSpanDrawable2 = this.pressedLink;
            if (linkSpanDrawable == linkSpanDrawable2 && linkSpanDrawable2 != null && (linkSpanDrawable2.getSpan() instanceof URLSpan)) {
                Utilities.Callback3<URLSpan, TextView, Runnable> callback3 = this.onLinkLongPress;
                URLSpan uRLSpan = (URLSpan) this.pressedLink.getSpan();
                final LinkSpanDrawable.LinkCollector linkCollector = this.links;
                Objects.requireNonNull(linkCollector);
                callback3.run(uRLSpan, this, new Runnable() {
                    @Override
                    public final void run() {
                        linkCollector.clear();
                    }
                });
                this.pressedLink = null;
            }
        }

        public void setPressed(boolean pressed) {
            boolean z = pressed != isPressed();
            super/*android.widget.TextView*/.setPressed(pressed);
            if (z) {
                invalidate();
            }
        }

        public void onDraw(Canvas canvas) {
            TextSelectionHelper.SimpleTextSelectionHelper simpleTextSelectionHelper = this.textSelectionHelper;
            if (simpleTextSelectionHelper != null && simpleTextSelectionHelper.isInSelectionMode()) {
                canvas.save();
                canvas.translate(getPaddingLeft(), getPaddingTop());
                if (this.textSelectionHelper != null && getStaticTextLayout() != null && this.textSelectionHelper.isCurrent(this)) {
                    this.textSelectionHelper.draw(canvas);
                }
                canvas.restore();
            }
            canvas.save();
            canvas.translate(getPaddingLeft(), 0.0f);
            if (this.links.draw(canvas)) {
                invalidate();
            }
            canvas.restore();
            super.onDraw(canvas);
            if (this.lastLayout != getLayout()) {
                this.animatedEmojiDrawables = AnimatedEmojiSpan.update(0, this, this.animatedEmojiDrawables, new Layout[]{getLayout()});
                this.quoteBlocks = QuoteSpan.updateQuoteBlocksSpanned(getLayout(), this.quoteBlocks);
                boolean z = getLayout() != null && (getLayout().getText() instanceof Spanned) && ((QuoteSpan.QuoteStyleSpan[]) ((Spanned) getLayout().getText()).getSpans(0, getLayout().getText().length(), QuoteSpan.QuoteStyleSpan.class)).length > 0;
                this.hasQuote = z;
                ViewHelper.setPadding(this, 16.0f, 8.0f, (z ? 32 : 0) + 16, 8.0f);
                this.lastLayout = getLayout();
            }
        }

        public void onDetachedFromWindow() {
            super/*android.widget.TextView*/.onDetachedFromWindow();
            AnimatedEmojiSpan.release(this, this.animatedEmojiDrawables);
            this.quoteBlocks = QuoteSpan.updateQuoteBlocksSpanned((Layout) null, this.quoteBlocks);
        }

        public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
            super.onTextChanged(text, start, lengthBefore, lengthAfter);
            this.animatedEmojiDrawables = AnimatedEmojiSpan.update(0, this, this.animatedEmojiDrawables, new Layout[]{getLayout()});
            this.quoteBlocks = QuoteSpan.updateQuoteBlocksSpanned(getLayout(), this.quoteBlocks);
        }

        public void dispatchDraw(Canvas canvas) {
            if (this.loading) {
                checkLoadingPath();
                if (this.loadingDrawable == null) {
                    LoadingDrawable loadingDrawable = new LoadingDrawable();
                    this.loadingDrawable = loadingDrawable;
                    loadingDrawable.usePath(this.loadingPath);
                    this.loadingDrawable.setRadiiDp(4.0f);
                    this.loadingDrawable.setColors(Theme.multAlpha(-1, 0.3f), Theme.multAlpha(-1, 0.1f), Theme.multAlpha(-1, 0.2f), Theme.multAlpha(-1, 0.7f));
                    this.loadingDrawable.setCallback(this);
                }
                this.loadingDrawable.setBounds(0, 0, getWidth(), getHeight());
                this.loadingDrawable.draw(canvas);
            }
            if (this.loading) {
                canvas.saveLayerAlpha(0.0f, 0.0f, getWidth(), getHeight(), 178, 31);
            }
            if (this.quoteBlocks != null && this.hasQuote) {
                canvas.save();
                canvas.translate(getPaddingLeft(), getPaddingTop());
                for (int i = 0; i < this.quoteBlocks.size(); i++) {
                    this.quoteBlocks.get(i).draw(canvas, 0.0f, ((getWidth() - getPaddingLeft()) - getPaddingRight()) + (this.hasQuote ? AndroidUtilities.dp(32.0f) : 0), -1, 1.0f, getPaint());
                }
                canvas.restore();
            }
            super/*android.widget.TextView*/.dispatchDraw(canvas);
            if (this.loading) {
                canvas.restore();
            }
            canvas.save();
            canvas.translate(getPaddingLeft(), getPaddingTop());
            canvas.clipRect(0.0f, getScrollY(), getWidth() - getPaddingRight(), (getHeight() + getScrollY()) - (getPaddingBottom() * 0.75f));
            AnimatedEmojiSpan.drawAnimatedEmojis(canvas, getLayout(), this.animatedEmojiDrawables, 0.0f, (List) null, 0.0f, 0.0f, 0.0f, 1.0f);
            canvas.restore();
        }

        public void setLoading(boolean loading) {
            if (this.loading == loading) {
                return;
            }
            this.loading = loading;
            invalidate();
        }

        public final void checkLoadingPath() {
            Layout layout = getLayout();
            Path path = this.loadingPath;
            if (path == null || this.lastLoadingLayout != layout) {
                if (path == null) {
                    this.loadingPath = new Path();
                } else {
                    path.rewind();
                }
                if (layout != null) {
                    float dp = AndroidUtilities.dp(16.0f);
                    float dp2 = AndroidUtilities.dp(8.0f);
                    float f = 0.0f;
                    int i = 0;
                    while (i < layout.getLineCount()) {
                        float f2 = dp / 3.0f;
                        float lineLeft = layout.getLineLeft(i) - f2;
                        float lineRight = layout.getLineRight(i) + f2;
                        if (i == 0) {
                            f = layout.getLineTop(i) - (dp2 / 3.0f);
                        }
                        float lineBottom = layout.getLineBottom(i);
                        if (i >= layout.getLineCount() - 1) {
                            lineBottom += dp2 / 3.0f;
                        }
                        this.loadingPath.addRect(getPaddingLeft() + lineLeft, getPaddingTop() + f, getPaddingLeft() + lineRight, getPaddingTop() + lineBottom, Path.Direction.CW);
                        i++;
                        f = lineBottom;
                    }
                }
                this.lastLoadingLayout = layout;
            }
        }

        public boolean verifyDrawable(Drawable who) {
            return who == this.loadingDrawable || super/*android.widget.TextView*/.verifyDrawable(who);
        }
    }

    public final int getLeftInset() {
        return this.insets.left;
    }

    public final int getRightInset() {
        return this.insets.right;
    }

    public final void dismissInternal() {
        try {
            if (this.windowView.getParent() != null) {
                Object obj = this.parentActivity;
                if (obj instanceof LaunchActivity) {
                    ((LaunchActivity) obj).drawerLayoutContainer.setAllowDrawContent(true);
                }
                ((WindowManager) this.parentActivity.getSystemService("window")).removeView(this.windowView);
                onHideView();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public final void switchToPip(boolean fromGesture) {
        float translationX;
        float translationY;
        float translationY2;
        float f;
        CubicBezierInterpolator cubicBezierInterpolator;
        CubicBezierInterpolator cubicBezierInterpolator2;
        if (this.videoPlayer == null || !this.textureUploaded || !checkInlinePermissions() || this.changingTextureView || this.switchingInlineMode || this.isInline) {
            return;
        }
        if (PipInstance != null) {
            PipInstance.destroyPhotoViewer();
        }
        this.openedFullScreenVideo = false;
        PipInstance = Instance;
        Instance = null;
        this.switchingInlineMode = true;
        this.isVisible = false;
        this.isVisibleOrAnimating = false;
        AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
        PlaceProviderObject placeProviderObject = this.currentPlaceObject;
        if (placeProviderObject != null && !placeProviderObject.imageReceiver.getVisible()) {
            this.currentPlaceObject.imageReceiver.setVisible(true, true);
            AnimatedFileDrawable animation = this.currentPlaceObject.imageReceiver.getAnimation();
            if (animation != null) {
                Bitmap animatedBitmap = animation.getAnimatedBitmap();
                if (animatedBitmap != null) {
                    try {
                        if (this.usedSurfaceView) {
                            AndroidUtilities.getBitmapFromSurface(this.videoSurfaceView, animatedBitmap);
                        } else {
                            Bitmap bitmap = this.videoTextureView.getBitmap(animatedBitmap.getWidth(), animatedBitmap.getHeight());
                            new Canvas(animatedBitmap).drawBitmap(bitmap, 0.0f, 0.0f, (Paint) null);
                            bitmap.recycle();
                        }
                    } catch (Throwable th) {
                        FileLog.e(th);
                    }
                }
                animation.seekTo(this.videoPlayer.getCurrentPosition(), true);
                if (fromGesture) {
                    this.currentPlaceObject.imageReceiver.setAlpha(0.0f);
                    final ImageReceiver imageReceiver = this.currentPlaceObject.imageReceiver;
                    ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
                    ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                            PhotoViewer.lambda$switchToPip$55(imageReceiver, valueAnimator);
                        }
                    });
                    ofFloat.addListener(new AnimatorListenerAdapter(this) {
                        @Override
                        public void onAnimationEnd(Animator animation2) {
                            imageReceiver.setAlpha(1.0f);
                        }
                    });
                    ofFloat.setDuration(250L);
                    ofFloat.start();
                }
                this.currentPlaceObject.imageReceiver.setAllowStartAnimation(true);
                this.currentPlaceObject.imageReceiver.startAnimation();
            }
        }
        if (Build.VERSION.SDK_INT >= 21) {
            this.pipAnimationInProgress = true;
            org.telegram.ui.Components.Rect pipRect = PipVideoOverlay.getPipRect(true, this.aspectRatioFrameLayout.getAspectRatio());
            final View view = this.usedSurfaceView ? this.videoSurfaceView : this.videoTextureView;
            final float width = pipRect.width / view.getWidth();
            final ValueAnimator ofFloat2 = ValueAnimator.ofFloat(0.0f, 1.0f);
            if (this.usedSurfaceView) {
                translationX = this.aspectRatioFrameLayout.getLeft() + view.getTranslationX();
                translationY = this.aspectRatioFrameLayout.getTop() + view.getTranslationY() + this.translationY;
                translationY2 = this.aspectRatioFrameLayout.getTop() + this.textureImageView.getTranslationY();
                f = this.translationY;
            } else {
                translationX = view.getTranslationX();
                translationY = view.getTranslationY() + this.translationY;
                translationY2 = this.textureImageView.getTranslationY();
                f = this.translationY;
            }
            final float f2 = translationY2 + f;
            final float f3 = translationY;
            final float f4 = translationX;
            final float f5 = pipRect.x;
            final float leftInset = getLeftInset() + (f5 - this.aspectRatioFrameLayout.getX());
            final float f6 = pipRect.y;
            final float y = f6 - this.aspectRatioFrameLayout.getY();
            if (this.videoSurfaceView != null) {
                this.videoPlayer.player.pause();
                this.textureImageView.setVisibility(0);
                if (this.usedSurfaceView) {
                    Bitmap createBitmap = Bitmaps.createBitmap(this.videoSurfaceView.getWidth(), this.videoSurfaceView.getHeight(), Bitmap.Config.ARGB_8888);
                    AndroidUtilities.getBitmapFromSurface(this.videoSurfaceView, createBitmap);
                    this.textureImageView.setImageBitmap(createBitmap);
                }
                this.videoSurfaceView.setVisibility(4);
            }
            this.textureImageView.setTranslationY(f2);
            view.setTranslationY(f3);
            FirstFrameView firstFrameView = this.firstFrameView;
            if (firstFrameView != null) {
                firstFrameView.setTranslationY(f3);
            }
            this.translationY = 0.0f;
            this.containerView.invalidate();
            if (fromGesture) {
                if (f3 < y) {
                    cubicBezierInterpolator2 = new CubicBezierInterpolator(0.5d, 0.0d, 0.9d, 0.9d);
                } else {
                    cubicBezierInterpolator2 = new CubicBezierInterpolator(0.0d, 0.5d, 0.9d, 0.9d);
                }
                cubicBezierInterpolator = cubicBezierInterpolator2;
            } else {
                cubicBezierInterpolator = null;
            }
            ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider(this) {
                @Override
                public void getOutline(View view2, Outline outline) {
                    outline.setRoundRect(0, 0, view2.getMeasuredWidth(), view2.getMeasuredHeight(), ((Float) ofFloat2.getAnimatedValue()).floatValue() * AndroidUtilities.dp(10.0f) * (1.0f / width));
                }
            };
            view.setOutlineProvider(viewOutlineProvider);
            view.setClipToOutline(true);
            this.textureImageView.setOutlineProvider(viewOutlineProvider);
            this.textureImageView.setClipToOutline(true);
            FirstFrameView firstFrameView2 = this.firstFrameView;
            if (firstFrameView2 != null) {
                firstFrameView2.setOutlineProvider(viewOutlineProvider);
                this.firstFrameView.setClipToOutline(true);
            }
            final CubicBezierInterpolator cubicBezierInterpolator3 = cubicBezierInterpolator;
            ofFloat2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                    PhotoViewer.this.lambda$switchToPip$56(cubicBezierInterpolator3, f4, f5, f2, f6, view, leftInset, f3, y, valueAnimator);
                }
            });
            AnimatorSet animatorSet = new AnimatorSet();
            ValueAnimator ofFloat3 = ValueAnimator.ofFloat(0.0f, 1.0f);
            ofFloat3.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                    PhotoViewer.this.lambda$switchToPip$57(valueAnimator);
                }
            });
            animatorSet.playTogether(ofFloat3, ObjectAnimator.ofFloat(this.textureImageView, (Property<ImageView, Float>) View.SCALE_X, width), ObjectAnimator.ofFloat(this.textureImageView, (Property<ImageView, Float>) View.SCALE_Y, width), ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_X, width), ObjectAnimator.ofFloat(view, (Property<View, Float>) View.SCALE_Y, width), ObjectAnimator.ofInt(this.backgroundDrawable, (Property<BackgroundDrawable, Integer>) AnimationProperties.COLOR_DRAWABLE_ALPHA, 0), ofFloat2);
            if (fromGesture) {
                animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
                animatorSet.setDuration(300L);
            } else {
                animatorSet.setInterpolator(new DecelerateInterpolator());
                animatorSet.setDuration(250L);
            }
            animatorSet.addListener(new AnonymousClass42(view));
            animatorSet.start();
            if (!fromGesture) {
                toggleActionBar(false, true, new ActionBarToggleParams().enableStatusBarAnimation(false).enableTranslationAnimation(false).animationDuration(250).animationInterpolator(new DecelerateInterpolator()));
            }
        } else {
            this.switchToInlineRunnable.run();
            dismissInternal();
        }
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity == null || chatActivity.getFragmentView() == null) {
            return;
        }
        this.parentChatActivity.getFragmentView().invalidate();
    }

    public static void lambda$switchToPip$55(ImageReceiver imageReceiver, ValueAnimator valueAnimator) {
        imageReceiver.setAlpha(((Float) valueAnimator.getAnimatedValue()).floatValue());
    }

    public void lambda$switchToPip$56(CubicBezierInterpolator cubicBezierInterpolator, float f, float f2, float f3, float f4, View view, float f5, float f6, float f7, ValueAnimator valueAnimator) {
        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
        float interpolation = cubicBezierInterpolator == null ? floatValue : cubicBezierInterpolator.getInterpolation(floatValue);
        ImageView imageView = this.textureImageView;
        if (imageView != null) {
            imageView.setTranslationX(((1.0f - floatValue) * f) + (f2 * floatValue));
            this.textureImageView.setTranslationY((f3 * (1.0f - interpolation)) + (f4 * interpolation));
            this.textureImageView.invalidateOutline();
        }
        view.setTranslationX((f * (1.0f - floatValue)) + (f5 * floatValue));
        view.setTranslationY((f6 * (1.0f - interpolation)) + (f7 * interpolation));
        view.invalidateOutline();
        FirstFrameView firstFrameView = this.firstFrameView;
        if (firstFrameView != null) {
            firstFrameView.setTranslationX(view.getTranslationX());
            this.firstFrameView.setTranslationY(view.getTranslationY());
            this.firstFrameView.setScaleX(view.getScaleX());
            this.firstFrameView.setScaleY(view.getScaleY());
            this.firstFrameView.invalidateOutline();
        }
    }

    public void lambda$switchToPip$57(ValueAnimator valueAnimator) {
        this.clippingImageProgress = ((Float) valueAnimator.getAnimatedValue()).floatValue();
    }

    public class AnonymousClass42 extends AnimatorListenerAdapter {
        public final View val$textureView;

        public AnonymousClass42(final View val$textureView) {
            this.val$textureView = val$textureView;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            PhotoViewer.this.pipAnimationInProgress = false;
            PhotoViewer.this.switchToInlineRunnable.run();
            final View view = this.val$textureView;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass42.this.lambda$onAnimationEnd$0(view);
                }
            }, 100L);
        }

        public void lambda$onAnimationEnd$0(View view) {
            view.setOutlineProvider(null);
            if (PhotoViewer.this.textureImageView != null) {
                PhotoViewer.this.textureImageView.setOutlineProvider(null);
            }
            if (PhotoViewer.this.firstFrameView != null) {
                PhotoViewer.this.firstFrameView.setOutlineProvider(null);
            }
        }
    }

    public final boolean cropMirror() {
        if (this.imageMoveAnimation != null || this.photoCropView == null) {
            return false;
        }
        this.mirror = 0.0f;
        this.animateToMirror = 1.0f;
        this.animationStartTime = System.currentTimeMillis();
        AnimatorSet animatorSet = new AnimatorSet();
        this.imageMoveAnimation = animatorSet;
        animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<PhotoViewer, Float>) AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0.0f, 1.0f));
        this.imageMoveAnimation.setDuration(250L);
        this.imageMoveAnimation.setInterpolator(CubicBezierInterpolator.DEFAULT);
        this.imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                PhotoViewer.this.imageMoveAnimation = null;
                if (PhotoViewer.this.photoCropView == null) {
                    return;
                }
                if (PhotoViewer.this.photoCropView.mirror()) {
                    PhotoViewer.this.mirrorItem.setColorFilter(new PorterDuffColorFilter(PhotoViewer.this.getThemedColor(Theme.key_chat_editMediaButton), PorterDuff.Mode.MULTIPLY));
                } else {
                    PhotoViewer.this.mirrorItem.setColorFilter((ColorFilter) null);
                }
                PhotoViewer photoViewer = PhotoViewer.this;
                photoViewer.animateToMirror = 0.0f;
                photoViewer.mirror = 0.0f;
                PhotoViewer.this.containerView.invalidate();
            }
        });
        this.imageMoveAnimation.start();
        return !this.photoCropView.cropView.isMirrored();
    }

    public final boolean cropRotate(float diff) {
        return cropRotate(diff, false, null);
    }

    public final float scale1() {
        return scale1(true);
    }

    public final float scale1(boolean fit) {
        int i;
        if (this.sendPhotoType != 11) {
            return 1.0f;
        }
        int containerViewWidth = getContainerViewWidth();
        if (containerViewWidth == 0) {
            containerViewWidth = AndroidUtilities.displaySize.x;
        }
        float dp = ((containerViewWidth - AndroidUtilities.dp(20.0f)) + 1) / containerViewWidth;
        if (!fit) {
            return dp;
        }
        int bitmapWidth = this.centerImage.getBitmapWidth();
        int bitmapHeight = this.centerImage.getBitmapHeight();
        if ((bitmapWidth <= 1 || bitmapHeight <= 1) && (i = this.currentIndex) >= 0 && i < this.imagesArrLocals.size()) {
            Object obj = this.imagesArrLocals.get(this.currentIndex);
            if (obj instanceof MediaController.PhotoEntry) {
                MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj;
                if ((photoEntry.orientation / 90) % 2 != 0) {
                    bitmapWidth = photoEntry.height;
                    bitmapHeight = photoEntry.width;
                } else {
                    bitmapWidth = photoEntry.width;
                    bitmapHeight = photoEntry.height;
                }
            }
        }
        return (bitmapWidth <= 1 || bitmapHeight <= 1 || bitmapWidth <= bitmapHeight) ? dp : dp * (bitmapWidth / bitmapHeight);
    }

    public final boolean cropRotate(final float diff, boolean restoreMirror, final Runnable onEnd) {
        PhotoCropView photoCropView;
        if (this.imageMoveAnimation != null || (photoCropView = this.photoCropView) == null) {
            return false;
        }
        photoCropView.cropView.maximize(true);
        this.rotate = 0.0f;
        this.animateToRotate = 0.0f + diff;
        if (restoreMirror) {
            this.mirror = 0.0f;
            this.animateToMirror = 1.0f;
        }
        this.animationStartTime = System.currentTimeMillis();
        this.imageMoveAnimation = new AnimatorSet();
        if (this.sendPhotoType == 1) {
            this.animateToScale = 1.0f;
            this.scale = 1.0f;
        } else {
            ImageReceiver imageReceiver = this.centerImage;
            if (imageReceiver != null) {
                int bitmapWidth = imageReceiver.getBitmapWidth();
                int bitmapHeight = this.centerImage.getBitmapHeight();
                if (Math.abs((((int) this.photoCropView.cropView.getStateOrientation()) / 90) % 2) == 1) {
                    bitmapHeight = bitmapWidth;
                    bitmapWidth = bitmapHeight;
                }
                MediaController.CropState cropState = this.editState.cropState;
                if (cropState != null) {
                    bitmapWidth = (int) (bitmapWidth * cropState.cropPw);
                    bitmapHeight = (int) (bitmapHeight * cropState.cropPh);
                }
                float f = bitmapWidth;
                float f2 = bitmapHeight;
                float min = Math.min(getContainerViewWidth(1) / f, getContainerViewHeight(1) / f2);
                this.animateToScale = (Math.abs((diff / 90.0f) % 2.0f) == 1.0f ? Math.min(getContainerViewWidth(1) / f2, getContainerViewHeight(1) / f) : min) / min;
            }
        }
        if (this.sendPhotoType == 11) {
            this.scale *= scale1(false);
            this.animateToScale *= scale1(false);
        }
        ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        final float rotation = this.photoCropView.wheelView.getRotation();
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                PhotoViewer.this.lambda$cropRotate$58(diff, rotation, valueAnimator);
            }
        });
        this.imageMoveAnimation.playTogether(ObjectAnimator.ofFloat(this, (Property<PhotoViewer, Float>) AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0.0f, 1.0f), ofFloat);
        this.imageMoveAnimation.setDuration(250L);
        this.imageMoveAnimation.setInterpolator(CubicBezierInterpolator.DEFAULT);
        this.imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                PhotoViewer.this.imageMoveAnimation = null;
                PhotoViewer photoViewer = PhotoViewer.this;
                photoViewer.animateToRotate = 0.0f;
                photoViewer.rotate = 0.0f;
                PhotoViewer photoViewer2 = PhotoViewer.this;
                photoViewer2.animateToMirror = 0.0f;
                photoViewer2.mirror = 0.0f;
                PhotoViewer photoViewer3 = PhotoViewer.this;
                float scale1 = photoViewer3.scale1(false);
                photoViewer3.animateToScale = scale1;
                photoViewer3.scale = scale1;
                PhotoViewer.this.containerView.invalidate();
                PhotoViewer.this.photoCropView.cropView.areaView.setRotationScaleTranslation(0.0f, PhotoViewer.this.scale1(false), 0.0f, 0.0f);
                PhotoViewer.this.photoCropView.wheelView.setRotated(false);
                if (Math.abs(diff) > 0.0f) {
                    if (PhotoViewer.this.photoCropView.rotate(diff)) {
                        PhotoViewer.this.rotateItem.setColorFilter(new PorterDuffColorFilter(PhotoViewer.this.getThemedColor(Theme.key_chat_editMediaButton), PorterDuff.Mode.MULTIPLY));
                    } else {
                        PhotoViewer.this.rotateItem.setColorFilter((ColorFilter) null);
                    }
                }
                if (PhotoViewer.this.editState.cropState != null) {
                    MediaController.CropState cropState2 = PhotoViewer.this.editState.cropState;
                    PhotoViewer.this.editState.cropState.cropPy = 0.0f;
                    cropState2.cropPx = 0.0f;
                    MediaController.CropState cropState3 = PhotoViewer.this.editState.cropState;
                    PhotoViewer.this.editState.cropState.cropPh = 1.0f;
                    cropState3.cropPw = 1.0f;
                }
                Runnable runnable = onEnd;
                if (runnable != null) {
                    runnable.run();
                }
            }
        });
        this.imageMoveAnimation.start();
        return Math.abs(this.photoCropView.cropView.getStateOrientation() + diff) > 0.01f;
    }

    public void lambda$cropRotate$58(float f, float f2, ValueAnimator valueAnimator) {
        CropAreaView cropAreaView = this.photoCropView.cropView.areaView;
        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue() * f;
        float f3 = this.scale;
        cropAreaView.setRotationScaleTranslation(floatValue, f3 + ((this.animateToScale - f3) * this.animationValue), 0.0f, 0.0f);
        this.photoCropView.wheelView.setRotation(AndroidUtilities.lerp(f2, 0.0f, ((Float) valueAnimator.getAnimatedValue()).floatValue()), false);
    }

    public VideoPlayer getVideoPlayer() {
        return this.videoPlayer;
    }

    public void exitFromPip() {
        if (this.isInline) {
            if (Instance != null) {
                Instance.closePhoto(false, true);
            }
            PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
            if (photoViewerWebView != null) {
                photoViewerWebView.exitFromPip();
            }
            Instance = PipInstance;
            PipInstance = null;
            if (this.photoViewerWebView == null) {
                this.switchingInlineMode = true;
                Bitmap bitmap = this.currentBitmap;
                if (bitmap != null) {
                    bitmap.recycle();
                    this.currentBitmap = null;
                }
                this.changingTextureView = true;
            }
            this.isInline = false;
            View view = this.usedSurfaceView ? this.videoSurfaceView : this.videoTextureView;
            if (this.photoViewerWebView == null && view != null) {
                AndroidUtilities.removeFromParent(view);
                view.setVisibility(4);
                this.aspectRatioFrameLayout.addView(view);
            }
            if (ApplicationLoader.mainInterfacePaused) {
                try {
                    this.parentActivity.startService(new Intent(ApplicationLoader.applicationContext, (Class<?>) BringAppForegroundService.class));
                } catch (Throwable th) {
                    FileLog.e(th);
                }
            }
            if (this.photoViewerWebView == null) {
                if (Build.VERSION.SDK_INT >= 21 && view != null) {
                    this.pipAnimationInProgress = true;
                    org.telegram.ui.Components.Rect pipRect = PipVideoOverlay.getPipRect(false, this.aspectRatioFrameLayout.getAspectRatio());
                    final float f = pipRect.width / this.textureImageView.getLayoutParams().width;
                    this.textureImageView.setScaleX(f);
                    this.textureImageView.setScaleY(f);
                    this.textureImageView.setTranslationX(pipRect.x);
                    this.textureImageView.setTranslationY(pipRect.y);
                    view.setScaleX(f);
                    view.setScaleY(f);
                    view.setTranslationX(pipRect.x - this.aspectRatioFrameLayout.getX());
                    view.setTranslationY(pipRect.y - this.aspectRatioFrameLayout.getY());
                    FirstFrameView firstFrameView = this.firstFrameView;
                    if (firstFrameView != null) {
                        firstFrameView.setScaleX(f);
                        this.firstFrameView.setScaleY(f);
                        this.firstFrameView.setTranslationX(view.getTranslationX());
                        this.firstFrameView.setTranslationY(view.getTranslationY());
                    }
                    this.inlineOutAnimationProgress = 0.0f;
                    ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() {
                        @Override
                        public void getOutline(View view2, Outline outline) {
                            outline.setRoundRect(0, 0, view2.getMeasuredWidth(), view2.getMeasuredHeight(), (1.0f - PhotoViewer.this.inlineOutAnimationProgress) * AndroidUtilities.dp(10.0f) * (1.0f / f));
                        }
                    };
                    view.setOutlineProvider(viewOutlineProvider);
                    view.setClipToOutline(true);
                    this.textureImageView.setOutlineProvider(viewOutlineProvider);
                    this.textureImageView.setClipToOutline(true);
                    FirstFrameView firstFrameView2 = this.firstFrameView;
                    if (firstFrameView2 != null) {
                        firstFrameView2.setOutlineProvider(viewOutlineProvider);
                        this.firstFrameView.setClipToOutline(true);
                    }
                } else {
                    PipVideoOverlay.dismiss(true);
                }
            } else {
                this.clippingImageProgress = 0.0f;
            }
            try {
                this.isVisible = true;
                this.isVisibleOrAnimating = true;
                ((WindowManager) this.parentActivity.getSystemService("window")).addView(this.windowView, this.windowLayoutParams);
                onShowView();
                PlaceProviderObject placeProviderObject = this.currentPlaceObject;
                if (placeProviderObject != null) {
                    placeProviderObject.imageReceiver.setVisible(false, false);
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (this.usedSurfaceView) {
                ExoPlayer exoPlayer = this.videoPlayer.player;
                if (exoPlayer != null) {
                    exoPlayer.setVideoTextureView((TextureView) null);
                }
                this.videoPlayer.setSurfaceView(this.videoSurfaceView);
                this.videoSurfaceView.setVisibility(4);
                this.waitingForFirstTextureUpload = 2;
                this.changingTextureView = false;
                this.containerView.invalidate();
                if (Build.VERSION.SDK_INT >= 21) {
                    this.waitingForDraw = 4;
                    return;
                }
                return;
            }
            if (Build.VERSION.SDK_INT >= 21) {
                this.waitingForDraw = 4;
            }
        }
    }

    public final void onShowView() {
        Object obj = this.parentActivity;
        if (obj instanceof LaunchActivity) {
            ((LaunchActivity) obj).addOnUserLeaveHintListener(this.onUserLeaveHintListener);
        }
    }

    public final void onHideView() {
        Object obj = this.parentActivity;
        if (obj instanceof LaunchActivity) {
            ((LaunchActivity) obj).removeOnUserLeaveHintListener(this.onUserLeaveHintListener);
        }
        BaseFragment baseFragment = this.parentFragment;
        if (baseFragment == null || baseFragment.getFragmentView() == null) {
            return;
        }
        this.clippingImageProgress = 1.0f;
        View fragmentView = this.parentFragment.getFragmentView();
        fragmentView.setScaleX(1.0f);
        fragmentView.setScaleY(1.0f);
        ChatAttachAlert chatAttachAlert = this.parentAlert;
        if (chatAttachAlert != null) {
            BottomSheet.ContainerView container = chatAttachAlert.getContainer();
            container.setScaleX(1.0f);
            container.setScaleY(1.0f);
        }
    }

    public final void onUserLeaveHint() {
        if (this.pipItem.getAlpha() == 1.0f && AndroidUtilities.checkInlinePermissions(this.parentActivity) && !PipVideoOverlay.isVisible() && this.isPlaying) {
            if (this.isEmbedVideo) {
                PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
                if (photoViewerWebView == null || photoViewerWebView.isInAppOnly() || !this.photoViewerWebView.openInPip()) {
                    return;
                }
                this.pipVideoOverlayAnimateFlag = false;
                if (PipInstance != null) {
                    PipInstance.destroyPhotoViewer();
                }
                this.isInline = true;
                PipInstance = Instance;
                Instance = null;
                this.isVisible = false;
                PlaceProviderObject placeProviderObject = this.currentPlaceObject;
                if (placeProviderObject != null && !placeProviderObject.imageReceiver.getVisible()) {
                    this.currentPlaceObject.imageReceiver.setVisible(true, true);
                }
                this.clippingImageProgress = 1.0f;
                this.containerView.invalidate();
                dismissInternal();
                return;
            }
            this.pipVideoOverlayAnimateFlag = false;
            switchToPip(false);
        }
    }

    public final void updateVideoSeekPreviewPosition() {
        int thumbX = (this.videoPlayerSeekbar.getThumbX() + AndroidUtilities.dp(2.0f)) - (this.videoPreviewFrame.getMeasuredWidth() / 2);
        int dp = AndroidUtilities.dp(10.0f);
        int measuredWidth = (this.videoPlayerControlFrameLayout.getMeasuredWidth() - AndroidUtilities.dp(10.0f)) - (this.videoPreviewFrame.getMeasuredWidth() / 2);
        if (thumbX < dp) {
            this.videoPreviewFrame.setPivotX(Utilities.clamp((r4.getMeasuredWidth() / 2.0f) - (dp - thumbX), this.videoPreviewFrame.getMeasuredWidth(), 0.0f));
            thumbX = dp;
        } else if (thumbX >= measuredWidth) {
            this.videoPreviewFrame.setPivotX(Utilities.clamp((r3.getMeasuredWidth() / 2.0f) + (thumbX - measuredWidth), this.videoPreviewFrame.getMeasuredWidth(), 0.0f));
            thumbX = measuredWidth;
        } else {
            this.videoPreviewFrame.setPivotX(r2.getMeasuredWidth() / 2.0f);
        }
        this.videoPreviewFrame.setTranslationX(thumbX);
    }

    public final void showVideoSeekPreviewPosition(boolean show) {
        PhotoViewerWebView photoViewerWebView;
        if (!show || this.videoPreviewFrame.getTag() == null) {
            if (show || this.videoPreviewFrame.getTag() != null) {
                if (show && !this.videoPreviewFrame.isReady() && ((photoViewerWebView = this.photoViewerWebView) == null || !photoViewerWebView.isYouTube() || !this.photoViewerWebView.hasYoutubeStoryboards())) {
                    this.needShowOnReady = true;
                    return;
                }
                AnimatorSet animatorSet = this.videoPreviewFrameAnimation;
                if (animatorSet != null) {
                    animatorSet.cancel();
                }
                this.videoPreviewFrame.setTag(show ? 1 : null);
                AnimatorSet animatorSet2 = new AnimatorSet();
                this.videoPreviewFrameAnimation = animatorSet2;
                Animator[] animatorArr = new Animator[4];
                VideoSeekPreviewImage videoSeekPreviewImage = this.videoPreviewFrame;
                Property property = View.ALPHA;
                float[] fArr = new float[1];
                fArr[0] = show ? 1.0f : 0.0f;
                animatorArr[0] = ObjectAnimator.ofFloat(videoSeekPreviewImage, (Property<VideoSeekPreviewImage, Float>) property, fArr);
                VideoSeekPreviewImage videoSeekPreviewImage2 = this.videoPreviewFrame;
                Property property2 = View.SCALE_X;
                float[] fArr2 = new float[1];
                fArr2[0] = show ? 1.0f : 0.5f;
                animatorArr[1] = ObjectAnimator.ofFloat(videoSeekPreviewImage2, (Property<VideoSeekPreviewImage, Float>) property2, fArr2);
                VideoSeekPreviewImage videoSeekPreviewImage3 = this.videoPreviewFrame;
                Property property3 = View.SCALE_Y;
                float[] fArr3 = new float[1];
                fArr3[0] = show ? 1.0f : 0.5f;
                animatorArr[2] = ObjectAnimator.ofFloat(videoSeekPreviewImage3, (Property<VideoSeekPreviewImage, Float>) property3, fArr3);
                VideoSeekPreviewImage videoSeekPreviewImage4 = this.videoPreviewFrame;
                Property property4 = View.TRANSLATION_Y;
                float[] fArr4 = new float[1];
                fArr4[0] = show ? 0.0f : AndroidUtilities.dp(12.0f);
                animatorArr[3] = ObjectAnimator.ofFloat(videoSeekPreviewImage4, (Property<VideoSeekPreviewImage, Float>) property4, fArr4);
                animatorSet2.playTogether(animatorArr);
                this.videoPreviewFrameAnimation.setDuration(380L);
                this.videoPreviewFrameAnimation.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
                this.videoPreviewFrameAnimation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewer.this.videoPreviewFrameAnimation = null;
                    }
                });
                this.videoPreviewFrameAnimation.start();
            }
        }
    }

    public final void createVideoControlsInterface() {
        VideoPlayerControlFrameLayout videoPlayerControlFrameLayout = new VideoPlayerControlFrameLayout(this.containerView.getContext());
        this.videoPlayerControlFrameLayout = videoPlayerControlFrameLayout;
        this.containerView.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(-1, 48, 83));
        final VideoPlayerSeekBar.SeekBarDelegate seekBarDelegate = new VideoPlayerSeekBar.SeekBarDelegate() {
            public void onSeekBarDrag(float progress) {
                if (PhotoViewer.this.videoPlayer != null || (PhotoViewer.this.photoViewerWebView != null && PhotoViewer.this.photoViewerWebView.isControllable())) {
                    if (!PhotoViewer.this.inPreview && PhotoViewer.this.videoTimelineViewContainer.getVisibility() == 0) {
                        progress = PhotoViewer.this.videoTimelineView.getLeftProgress() + ((PhotoViewer.this.videoTimelineView.getRightProgress() - PhotoViewer.this.videoTimelineView.getLeftProgress()) * progress);
                    }
                    if (PhotoViewer.this.getVideoDuration() == -9223372036854775807L) {
                        PhotoViewer.this.seekToProgressPending = progress;
                    } else {
                        PhotoViewer.this.seekVideoOrWebTo((int) (progress * r0));
                    }
                    PhotoViewer.this.showVideoSeekPreviewPosition(false);
                    PhotoViewer.this.needShowOnReady = false;
                }
            }

            public void onSeekBarContinuousDrag(float progress) {
                if (PhotoViewer.this.photoViewerWebView != null && PhotoViewer.this.photoViewerWebView.isYouTube() && PhotoViewer.this.videoPreviewFrame != null) {
                    PhotoViewer.this.videoPreviewFrame.setProgressForYouTube(PhotoViewer.this.photoViewerWebView, progress, PhotoViewer.this.videoPlayerSeekbar.getWidth());
                } else if (PhotoViewer.this.videoPlayer != null && PhotoViewer.this.videoPreviewFrame != null) {
                    PhotoViewer.this.videoPreviewFrame.setProgress(progress, PhotoViewer.this.videoPlayerSeekbar.getWidth());
                }
                PhotoViewer.this.showVideoSeekPreviewPosition(true);
                PhotoViewer.this.updateVideoSeekPreviewPosition();
            }
        };
        View.AccessibilityDelegate accessibilityDelegate = new FloatSeekBarAccessibilityDelegate() {
            public float getProgress() {
                return PhotoViewer.this.videoPlayerSeekbar.getProgress();
            }

            public void setProgress(float progress) {
                seekBarDelegate.onSeekBarDrag(progress);
                PhotoViewer.this.videoPlayerSeekbar.setProgress(progress);
                PhotoViewer.this.videoPlayerSeekbarView.invalidate();
            }

            public String getContentDescription(View host) {
                return LocaleController.formatString("AccDescrPlayerDuration", R.string.AccDescrPlayerDuration, new Object[]{LocaleController.formatPluralString("Minutes", PhotoViewer.this.videoPlayerCurrentTime[0], new Object[0]) + ' ' + LocaleController.formatPluralString("Seconds", PhotoViewer.this.videoPlayerCurrentTime[1], new Object[0]), LocaleController.formatPluralString("Minutes", PhotoViewer.this.videoPlayerTotalTime[0], new Object[0]) + ' ' + LocaleController.formatPluralString("Seconds", PhotoViewer.this.videoPlayerTotalTime[1], new Object[0])});
            }
        };
        View view = new View(this.containerView.getContext()) {
            @Override
            public void onDraw(Canvas canvas) {
                PhotoViewer.this.videoPlayerSeekbar.draw(canvas, this);
            }
        };
        this.videoPlayerSeekbarView = view;
        view.setAccessibilityDelegate(accessibilityDelegate);
        this.videoPlayerSeekbarView.setImportantForAccessibility(1);
        this.videoPlayerControlFrameLayout.addView(this.videoPlayerSeekbarView, LayoutHelper.createFrame(-1, -1.0f));
        VideoPlayerSeekBar videoPlayerSeekBar = new VideoPlayerSeekBar(this.videoPlayerSeekbarView);
        this.videoPlayerSeekbar = videoPlayerSeekBar;
        videoPlayerSeekBar.setHorizontalPadding(AndroidUtilities.dp(2.0f));
        this.videoPlayerSeekbar.setColors(872415231, 872415231, -1, -1, -1, 1509949439);
        this.videoPlayerSeekbar.setDelegate(seekBarDelegate);
        VideoSeekPreviewImage videoSeekPreviewImage = new VideoSeekPreviewImage(this.containerView.getContext(), new VideoSeekPreviewImage.VideoSeekPreviewImageDelegate() {
            public final void onReady() {
                PhotoViewer.this.lambda$createVideoControlsInterface$59();
            }
        }) {
            public void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super/*android.view.View*/.onLayout(changed, left, top, right, bottom);
                PhotoViewer.this.updateVideoSeekPreviewPosition();
            }

            public void setVisibility(int visibility) {
                super/*android.view.View*/.setVisibility(visibility);
                if (visibility == 0) {
                    PhotoViewer.this.updateVideoSeekPreviewPosition();
                }
            }
        };
        this.videoPreviewFrame = videoSeekPreviewImage;
        videoSeekPreviewImage.setAlpha(0.0f);
        this.containerView.addView(this.videoPreviewFrame, LayoutHelper.createFrame(-2, -2.0f, 83, 0.0f, 0.0f, 0.0f, 58.0f));
        SimpleTextView simpleTextView = new SimpleTextView(this.containerView.getContext());
        this.videoPlayerTime = simpleTextView;
        simpleTextView.setTextColor(-1);
        this.videoPlayerTime.setGravity(53);
        this.videoPlayerTime.setTextSize(14);
        this.videoPlayerTime.setImportantForAccessibility(2);
        this.videoPlayerControlFrameLayout.addView(this.videoPlayerTime, LayoutHelper.createFrame(-2, -2.0f, 53, 0.0f, 15.0f, 12.0f, 0.0f));
        ImageView imageView = new ImageView(this.containerView.getContext());
        this.exitFullscreenButton = imageView;
        imageView.setImageResource(R.drawable.msg_minvideo);
        this.exitFullscreenButton.setContentDescription(LocaleController.getString("AccExitFullscreen", R.string.AccExitFullscreen));
        this.exitFullscreenButton.setScaleType(ImageView.ScaleType.CENTER);
        this.exitFullscreenButton.setBackground(Theme.createSelectorDrawable(1090519039));
        this.exitFullscreenButton.setVisibility(4);
        this.videoPlayerControlFrameLayout.addView(this.exitFullscreenButton, LayoutHelper.createFrame(48, 48, 53));
        this.exitFullscreenButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PhotoViewer.this.lambda$createVideoControlsInterface$60(view2);
            }
        });
    }

    public void lambda$createVideoControlsInterface$59() {
        if (this.needShowOnReady) {
            showVideoSeekPreviewPosition(true);
        }
    }

    public void lambda$createVideoControlsInterface$60(View view) {
        Activity activity = this.parentActivity;
        if (activity == null) {
            return;
        }
        this.wasRotated = false;
        this.fullscreenedByButton = 2;
        if (this.prevOrientation == -10) {
            this.prevOrientation = activity.getRequestedOrientation();
        }
        this.parentActivity.setRequestedOrientation(1);
    }

    public final int[] fixVideoWidthHeight(int r8, int r9) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.fixVideoWidthHeight(int, int):int[]");
    }

    public final VideoEditedInfo getCurrentVideoEditedInfo() {
        int i;
        long j;
        ArrayList<VideoEditedInfo.MediaEntity> arrayList = null;
        if (!this.isCurrentVideo && hasAnimatedMediaEntities() && this.centerImage.getBitmapWidth() > 0) {
            float f = 854.0f;
            int i2 = this.sendPhotoType;
            if (i2 == 1) {
                f = 800.0f;
            } else if (i2 == 11) {
                f = 500.0f;
            }
            VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
            videoEditedInfo.startTime = 0L;
            videoEditedInfo.start = 0L;
            videoEditedInfo.endTime = Math.min(3000L, this.editState.averageDuration);
            while (true) {
                j = videoEditedInfo.endTime;
                if (j <= 0 || j >= 1000) {
                    break;
                }
                videoEditedInfo.endTime = j * 2;
            }
            videoEditedInfo.end = j;
            videoEditedInfo.compressQuality = this.selectedCompression;
            videoEditedInfo.rotationValue = 0;
            videoEditedInfo.originalPath = this.currentImagePath;
            long j2 = videoEditedInfo.endTime;
            videoEditedInfo.estimatedSize = (int) ((j2 / 1000.0f) * 115200.0f);
            videoEditedInfo.estimatedDuration = j2;
            videoEditedInfo.framerate = 30;
            videoEditedInfo.originalDuration = j2;
            EditState editState = this.editState;
            videoEditedInfo.filterState = editState.savedFilterState;
            String str = editState.croppedPaintPath;
            if (str != null) {
                videoEditedInfo.paintPath = str;
                ArrayList<VideoEditedInfo.MediaEntity> arrayList2 = editState.croppedMediaEntities;
                if (arrayList2 != null && !arrayList2.isEmpty()) {
                    arrayList = this.editState.croppedMediaEntities;
                }
                videoEditedInfo.mediaEntities = arrayList;
            } else {
                videoEditedInfo.paintPath = editState.paintPath;
                videoEditedInfo.mediaEntities = editState.mediaEntities;
            }
            videoEditedInfo.isPhoto = true;
            int bitmapWidth = this.centerImage.getBitmapWidth();
            int bitmapHeight = this.centerImage.getBitmapHeight();
            MediaController.CropState cropState = this.editState.cropState;
            if (cropState != null) {
                int i3 = cropState.transformRotation;
                if (i3 == 90 || i3 == 270) {
                    bitmapHeight = bitmapWidth;
                    bitmapWidth = bitmapHeight;
                }
                bitmapWidth = (int) (bitmapWidth * cropState.cropPw);
                bitmapHeight = (int) (bitmapHeight * cropState.cropPh);
            }
            int i4 = this.sendPhotoType;
            if (i4 == 1 || i4 == 11) {
                bitmapWidth = bitmapHeight;
            }
            float f2 = bitmapWidth;
            float f3 = bitmapHeight;
            float max = Math.max(f2 / f, f3 / f);
            if (max < 1.0f) {
                max = 1.0f;
            }
            int i5 = (int) (f2 / max);
            int i6 = (int) (f3 / max);
            if (i5 % 16 != 0) {
                i5 = Math.max(1, Math.round(i5 / 16.0f)) * 16;
            }
            if (i6 % 16 != 0) {
                i6 = Math.max(1, Math.round(i6 / 16.0f)) * 16;
            }
            videoEditedInfo.resultWidth = i5;
            videoEditedInfo.originalWidth = i5;
            videoEditedInfo.resultHeight = i6;
            videoEditedInfo.originalHeight = i6;
            videoEditedInfo.bitrate = -1;
            videoEditedInfo.muted = true;
            videoEditedInfo.avatarStartTime = 0L;
            return videoEditedInfo;
        }
        if (!this.isCurrentVideo || this.currentPlayingVideoFile == null || this.compressionsCount == 0) {
            return null;
        }
        VideoEditedInfo videoEditedInfo2 = new VideoEditedInfo();
        videoEditedInfo2.startTime = this.startTime;
        videoEditedInfo2.endTime = this.endTime;
        videoEditedInfo2.start = this.videoCutStart;
        videoEditedInfo2.end = this.videoCutEnd;
        videoEditedInfo2.compressQuality = this.selectedCompression;
        videoEditedInfo2.rotationValue = this.rotationValue;
        videoEditedInfo2.originalWidth = this.originalWidth;
        videoEditedInfo2.originalHeight = this.originalHeight;
        videoEditedInfo2.bitrate = this.bitrate;
        videoEditedInfo2.originalPath = this.currentPathObject;
        long j3 = this.estimatedSize;
        if (j3 == 0) {
            j3 = 1;
        }
        videoEditedInfo2.estimatedSize = j3;
        videoEditedInfo2.estimatedDuration = this.estimatedDuration;
        videoEditedInfo2.framerate = this.videoFramerate;
        videoEditedInfo2.originalDuration = (long) (this.videoDuration * 1000.0f);
        EditState editState2 = this.editState;
        videoEditedInfo2.filterState = editState2.savedFilterState;
        String str2 = editState2.croppedPaintPath;
        if (str2 != null) {
            videoEditedInfo2.paintPath = str2;
            ArrayList<VideoEditedInfo.MediaEntity> arrayList3 = editState2.croppedMediaEntities;
            if (arrayList3 != null && !arrayList3.isEmpty()) {
                arrayList = this.editState.croppedMediaEntities;
            }
            videoEditedInfo2.mediaEntities = arrayList;
        } else {
            videoEditedInfo2.paintPath = editState2.paintPath;
            ArrayList<VideoEditedInfo.MediaEntity> arrayList4 = editState2.mediaEntities;
            if (arrayList4 != null && !arrayList4.isEmpty()) {
                arrayList = this.editState.mediaEntities;
            }
            videoEditedInfo2.mediaEntities = arrayList;
        }
        if (this.sendPhotoType != 1 && !this.muteVideo && (this.compressItem.getTag() == null || (videoEditedInfo2.resultWidth == this.originalWidth && videoEditedInfo2.resultHeight == this.originalHeight))) {
            videoEditedInfo2.resultWidth = this.originalWidth;
            videoEditedInfo2.resultHeight = this.originalHeight;
            videoEditedInfo2.bitrate = this.muteVideo ? -1 : this.originalBitrate;
        } else {
            if (this.muteVideo || this.sendPhotoType == 1) {
                this.selectedCompression = 1;
                updateWidthHeightBitrateForCompression();
            }
            videoEditedInfo2.resultWidth = this.resultWidth;
            videoEditedInfo2.resultHeight = this.resultHeight;
            if (!this.muteVideo && this.sendPhotoType != 1) {
                r5 = this.bitrate;
            }
            videoEditedInfo2.bitrate = r5;
        }
        MediaController.CropState cropState2 = this.editState.cropState;
        videoEditedInfo2.cropState = cropState2;
        if (cropState2 != null) {
            videoEditedInfo2.rotationValue += cropState2.transformRotation;
            while (true) {
                i = videoEditedInfo2.rotationValue;
                if (i < 360) {
                    break;
                }
                videoEditedInfo2.rotationValue = i - 360;
            }
            if (i == 90 || i == 270) {
                MediaController.CropState cropState3 = videoEditedInfo2.cropState;
                cropState3.transformWidth = (int) (videoEditedInfo2.resultWidth * cropState3.cropPh);
                cropState3.transformHeight = (int) (videoEditedInfo2.resultHeight * cropState3.cropPw);
            } else {
                MediaController.CropState cropState4 = videoEditedInfo2.cropState;
                cropState4.transformWidth = (int) (videoEditedInfo2.resultWidth * cropState4.cropPw);
                cropState4.transformHeight = (int) (videoEditedInfo2.resultHeight * cropState4.cropPh);
            }
            if (this.sendPhotoType == 1) {
                MediaController.CropState cropState5 = videoEditedInfo2.cropState;
                if (cropState5.transformWidth > 800) {
                    cropState5.transformWidth = 800;
                }
                if (cropState5.transformHeight > 800) {
                    cropState5.transformHeight = 800;
                }
                int min = Math.min(cropState5.transformWidth, cropState5.transformHeight);
                cropState5.transformHeight = min;
                cropState5.transformWidth = min;
            }
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("original transformed w = " + videoEditedInfo2.cropState.transformWidth + " h = " + videoEditedInfo2.cropState.transformHeight + " r = " + videoEditedInfo2.rotationValue);
            }
            MediaController.CropState cropState6 = videoEditedInfo2.cropState;
            int[] fixVideoWidthHeight = fixVideoWidthHeight(cropState6.transformWidth, cropState6.transformHeight);
            MediaController.CropState cropState7 = videoEditedInfo2.cropState;
            cropState7.transformWidth = fixVideoWidthHeight[0];
            cropState7.transformHeight = fixVideoWidthHeight[1];
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("fixed transformed w = " + videoEditedInfo2.cropState.transformWidth + " h = " + videoEditedInfo2.cropState.transformHeight);
            }
        }
        if (this.sendPhotoType == 1) {
            videoEditedInfo2.avatarStartTime = this.avatarStartTime;
            videoEditedInfo2.originalBitrate = this.originalBitrate;
        }
        videoEditedInfo2.muted = this.muteVideo || this.sendPhotoType == 1;
        return videoEditedInfo2;
    }

    public final boolean supportsSendingNewEntities() {
        TLRPC.EncryptedChat encryptedChat;
        ChatActivity chatActivity = this.parentChatActivity;
        return chatActivity != null && ((encryptedChat = chatActivity.currentEncryptedChat) == null || AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 101);
    }

    public final void closeCaptionEnter(boolean apply) {
        int i = this.currentIndex;
        if (i < 0 || i >= this.imagesArrLocals.size() || !isCaptionOpen()) {
            return;
        }
        this.imagesArrLocals.get(this.currentIndex);
        if (apply) {
            applyCaption();
        }
        this.captionEdit.onBackPressed();
    }

    public final CharSequence applyCaption() {
        int i;
        if (!isVisible() || this.placeProvider == null || (i = this.currentIndex) < 0 || i >= this.imagesArrLocals.size()) {
            return null;
        }
        Object obj = this.imagesArrLocals.get(this.currentIndex);
        CharSequence text = this.captionEdit.getText();
        CharSequence[] charSequenceArr = {text};
        if (this.hasCaptionForAllMedia && !TextUtils.equals(this.captionForAllMedia, text) && this.placeProvider.getPhotoIndex(this.currentIndex) != 0 && this.placeProvider.getSelectedCount() > 0) {
            this.hasCaptionForAllMedia = false;
        }
        ArrayList entities = MediaDataController.getInstance(this.currentAccount).getEntities(charSequenceArr, supportsSendingNewEntities());
        this.captionForAllMedia = charSequenceArr[0];
        if (obj instanceof MediaController.PhotoEntry) {
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj;
            ((MediaController.MediaEditState) photoEntry).caption = charSequenceArr[0];
            ((MediaController.MediaEditState) photoEntry).entities = entities;
        } else if (obj instanceof MediaController.SearchImage) {
            MediaController.SearchImage searchImage = (MediaController.SearchImage) obj;
            searchImage.caption = charSequenceArr[0];
            ((MediaController.MediaEditState) searchImage).entities = entities;
        }
        if (text.length() != 0 && !this.placeProvider.isPhotoChecked(this.currentIndex)) {
            setPhotoChecked();
        }
        PhotoViewerProvider photoViewerProvider = this.placeProvider;
        if (photoViewerProvider != null) {
            photoViewerProvider.onApplyCaption(text);
        }
        if (Theme.plusShowPhotoQualityBar && !this.isCurrentVideo) {
            this.photoQualityLayout.setVisibility(0);
        }
        return text;
    }

    public final void updateVideoPlayerTime() {
        String format;
        String format2;
        Arrays.fill(this.videoPlayerCurrentTime, 0);
        Arrays.fill(this.videoPlayerTotalTime, 0);
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            long max = Math.max(0L, videoPlayer.getCurrentPosition());
            if (this.shownControlsByEnd && !this.actionBarWasShownBeforeByEnd) {
                max = 0;
            }
            long max2 = Math.max(0L, this.videoPlayer.getDuration());
            if (!this.inPreview && this.videoTimelineViewContainer.getVisibility() == 0) {
                max2 = (long) (max2 * (this.videoTimelineView.getRightProgress() - this.videoTimelineView.getLeftProgress()));
                max = (long) (max - (this.videoTimelineView.getLeftProgress() * max2));
                if (max > max2) {
                    max = max2;
                }
            }
            long j = max / 1000;
            long j2 = max2 / 1000;
            int[] iArr = this.videoPlayerCurrentTime;
            iArr[0] = (int) (j / 60);
            iArr[1] = (int) (j % 60);
            int[] iArr2 = this.videoPlayerTotalTime;
            iArr2[0] = (int) (j2 / 60);
            iArr2[1] = (int) (j2 % 60);
        } else {
            PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
            if (photoViewerWebView != null && photoViewerWebView.isControllable()) {
                long max3 = (!this.shownControlsByEnd || this.actionBarWasShownBeforeByEnd) ? Math.max(0, this.photoViewerWebView.getCurrentPosition()) : 0L;
                long max4 = Math.max(0, this.photoViewerWebView.getVideoDuration());
                if (!this.inPreview && this.videoTimelineViewContainer.getVisibility() == 0) {
                    max4 = (long) (max4 * (this.videoTimelineView.getRightProgress() - this.videoTimelineView.getLeftProgress()));
                    max3 = (long) (max3 - (this.videoTimelineView.getLeftProgress() * max4));
                    if (max3 > max4) {
                        max3 = max4;
                    }
                }
                long j3 = max3 / 1000;
                long j4 = max4 / 1000;
                int[] iArr3 = this.videoPlayerCurrentTime;
                iArr3[0] = (int) (j3 / 60);
                iArr3[1] = (int) (j3 % 60);
                int[] iArr4 = this.videoPlayerTotalTime;
                iArr4[0] = (int) (j4 / 60);
                iArr4[1] = (int) (j4 % 60);
            }
        }
        int[] iArr5 = this.videoPlayerCurrentTime;
        if (iArr5[0] >= 60) {
            format = format(iArr5[0] / 60, iArr5[0] % 60, iArr5[1]);
        } else {
            format = format(iArr5[0], iArr5[1]);
        }
        int[] iArr6 = this.videoPlayerTotalTime;
        if (iArr6[0] >= 60) {
            format2 = format(iArr6[0] / 60, iArr6[0] % 60, iArr6[1]);
        } else {
            format2 = format(iArr6[0], iArr6[1]);
        }
        this.videoPlayerTime.setText(format + " / " + format2);
        if (Objects.equals(this.lastControlFrameDuration, format2)) {
            return;
        }
        this.lastControlFrameDuration = format2;
        this.videoPlayerControlFrameLayout.requestLayout();
    }

    public final String format(int h, int m, int s) {
        char[] cArr = new char[8];
        cArr[0] = (char) (((h >= 100 ? 99 : h) / 10) + 48);
        if (h >= 100) {
            h = 99;
        }
        cArr[1] = (char) ((h % 10) + 48);
        cArr[2] = ':';
        cArr[3] = (char) (((m >= 100 ? 99 : m) / 10) + 48);
        if (m >= 100) {
            m = 99;
        }
        cArr[4] = (char) ((m % 10) + 48);
        cArr[5] = ':';
        cArr[6] = (char) (((s >= 100 ? 99 : s) / 10) + 48);
        if (s >= 100) {
            s = 99;
        }
        cArr[7] = (char) ((s % 10) + 48);
        return new String(cArr);
    }

    public final String format(int m, int s) {
        char[] cArr = new char[5];
        cArr[0] = (char) (((m >= 100 ? 99 : m) / 10) + 48);
        if (m >= 100) {
            m = 99;
        }
        cArr[1] = (char) ((m % 10) + 48);
        cArr[2] = ':';
        cArr[3] = (char) (((s >= 100 ? 99 : s) / 10) + 48);
        if (s >= 100) {
            s = 99;
        }
        cArr[4] = (char) ((s % 10) + 48);
        return new String(cArr);
    }

    public final void checkBufferedProgress(float progress) {
        MessageObject messageObject;
        TLRPC.Document document;
        if (!this.isStreaming || this.parentActivity == null || this.streamingAlertShown || this.videoPlayer == null || (messageObject = this.currentMessageObject) == null || (document = messageObject.getDocument()) == null || this.currentMessageObject.getDuration() < 20.0d) {
            return;
        }
        boolean z = document.size >= 2147483648L;
        if (!((DownloadController.getInstance(this.currentAccount).getAutodownloadMask() & 4) != 0) || progress >= 0.9f) {
            return;
        }
        long j = document.size;
        if (j * progress >= 5242880.0f || (progress >= 0.5f && j >= 2097152)) {
            if (Math.abs(SystemClock.elapsedRealtime() - this.startedPlayTime) >= (z ? 10000 : 3000)) {
                if (this.videoPlayer.getDuration() == -9223372036854775807L) {
                    Toast.makeText(this.parentActivity, LocaleController.getString(R.string.VideoDoesNotSupportStreaming), 1).show();
                }
                this.streamingAlertShown = true;
            }
        }
    }

    public void updateColors() {
        int i = Theme.key_chat_editMediaButton;
        int themedColor = getThemedColor(i);
        ImageView imageView = this.pickerViewSendButton;
        if (imageView != null) {
            Drawable background = imageView.getBackground();
            Theme.setSelectorDrawableColor(background, themedColor, false);
            Theme.setSelectorDrawableColor(background, getThemedColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : i), true);
            this.pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
        }
        CheckBox checkBox = this.checkImageView;
        if (checkBox != null) {
            checkBox.setColor(getThemedColor(i), -1);
        }
        PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(themedColor, PorterDuff.Mode.MULTIPLY);
        ImageView imageView2 = this.paintItem;
        if (imageView2 != null && imageView2.getColorFilter() != null) {
            this.paintItem.setColorFilter(porterDuffColorFilter);
        }
        ImageView imageView3 = this.cropItem;
        if (imageView3 != null && imageView3.getColorFilter() != null) {
            this.cropItem.setColorFilter(porterDuffColorFilter);
        }
        ImageView imageView4 = this.tuneItem;
        if (imageView4 != null && imageView4.getColorFilter() != null) {
            this.tuneItem.setColorFilter(porterDuffColorFilter);
        }
        ImageView imageView5 = this.rotateItem;
        if (imageView5 != null && imageView5.getColorFilter() != null) {
            this.rotateItem.setColorFilter(porterDuffColorFilter);
        }
        ImageView imageView6 = this.mirrorItem;
        if (imageView6 != null && imageView6.getColorFilter() != null) {
            this.mirrorItem.setColorFilter(porterDuffColorFilter);
        }
        PickerBottomLayoutViewer pickerBottomLayoutViewer = this.editorDoneLayout;
        if (pickerBottomLayoutViewer != null) {
            pickerBottomLayoutViewer.doneButton.setTextColor(themedColor);
        }
        PickerBottomLayoutViewer pickerBottomLayoutViewer2 = this.qualityPicker;
        if (pickerBottomLayoutViewer2 != null) {
            pickerBottomLayoutViewer2.doneButton.setTextColor(themedColor);
        }
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.updateColors();
        }
        PhotoFilterView photoFilterView = this.photoFilterView;
        if (photoFilterView != null) {
            photoFilterView.updateColors();
        }
        CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
        if (captionPhotoViewer != null) {
            captionPhotoViewer.updateColors(this.resourcesProvider);
        }
        VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
        if (videoTimelinePlayView != null) {
            videoTimelinePlayView.invalidate();
        }
        RecyclerListView recyclerListView = this.selectedPhotosListView;
        if (recyclerListView != null) {
            int childCount = recyclerListView.getChildCount();
            for (int i2 = 0; i2 < childCount; i2++) {
                View childAt = this.selectedPhotosListView.getChildAt(i2);
                if (childAt instanceof PhotoPickerPhotoCell) {
                    ((PhotoPickerPhotoCell) childAt).updateColors();
                }
            }
        }
        StickersAlert stickersAlert = this.masksAlert;
        if (stickersAlert != null) {
            stickersAlert.updateColors(true);
        }
    }

    public void injectVideoPlayer(VideoPlayer player) {
        this.injectingVideoPlayer = player;
    }

    public void injectVideoPlayerSurface(SurfaceTexture surface) {
        this.injectingVideoPlayerSurface = surface;
    }

    public boolean isInjectingVideoPlayer() {
        return this.injectingVideoPlayer != null;
    }

    public final void scheduleActionBarHide() {
        scheduleActionBarHide(3000);
    }

    public final void scheduleActionBarHide(int delay) {
        if (isAccessibilityEnabled()) {
            return;
        }
        AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
        AndroidUtilities.runOnUIThread(this.hideActionBarRunnable, delay);
    }

    public final boolean isAccessibilityEnabled() {
        try {
            AccessibilityManager accessibilityManager = (AccessibilityManager) this.activityContext.getSystemService("accessibility");
            if (accessibilityManager.isEnabled()) {
                return accessibilityManager.isTouchExplorationEnabled();
            }
            return false;
        } catch (Exception e) {
            FileLog.e(e);
            return false;
        }
    }

    public void updateWebPlayerState(boolean playWhenReady, int playbackState) {
        updatePlayerState(playWhenReady, playbackState);
    }

    public final void updatePlayerState(boolean playWhenReady, int playbackState) {
        VideoPlayer videoPlayer;
        MessageObject messageObject;
        TLRPC.MessageMedia messageMedia;
        TLRPC.WebPage webPage;
        PhotoViewerWebView photoViewerWebView;
        if (this.videoPlayer != null || ((photoViewerWebView = this.photoViewerWebView) != null && photoViewerWebView.isControllable())) {
            PhotoViewerWebView photoViewerWebView2 = this.photoViewerWebView;
            if (photoViewerWebView2 != null && photoViewerWebView2.isControllable() && !playWhenReady) {
                toggleActionBar(true, true);
            }
            PhotoViewerWebView photoViewerWebView3 = this.photoViewerWebView;
            float f = 0.0f;
            if (photoViewerWebView3 != null && photoViewerWebView3.isControllable() && playbackState == 3 && getVideoDuration() >= 10000 && this.shouldSavePositionForCurrentVideo == null && this.shouldSavePositionForCurrentVideoShortTerm == null) {
                if (this.currentMessageObject != null) {
                    long videoDuration = getVideoDuration() / 1000;
                    TLRPC.Message message = this.currentMessageObject.messageOwner;
                    String str = (message == null || (messageMedia = message.media) == null || (webPage = messageMedia.webpage) == null) ? null : webPage.url;
                    if (!TextUtils.isEmpty(str)) {
                        if (videoDuration >= 600) {
                            if (this.currentMessageObject.forceSeekTo < 0.0f) {
                                float f2 = ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", 0).getFloat(str, -1.0f);
                                if (f2 > 0.0f && f2 < 0.999f) {
                                    this.currentMessageObject.forceSeekTo = f2;
                                    this.videoPlayerSeekbar.setProgress(f2);
                                }
                            }
                            this.shouldSavePositionForCurrentVideo = str;
                        } else if (videoDuration >= 10) {
                            SavedVideoPosition savedVideoPosition = null;
                            for (int size = this.savedVideoPositions.size() - 1; size >= 0; size--) {
                                SavedVideoPosition savedVideoPosition2 = (SavedVideoPosition) this.savedVideoPositions.valueAt(size);
                                if (savedVideoPosition2.timestamp < SystemClock.elapsedRealtime() - 5000) {
                                    this.savedVideoPositions.removeAt(size);
                                } else if (savedVideoPosition == null && ((String) this.savedVideoPositions.keyAt(size)).equals(str)) {
                                    savedVideoPosition = savedVideoPosition2;
                                }
                            }
                            MessageObject messageObject2 = this.currentMessageObject;
                            if (messageObject2.forceSeekTo < 0.0f && savedVideoPosition != null) {
                                float f3 = savedVideoPosition.position;
                                if (f3 > 0.0f && f3 < 0.999f) {
                                    messageObject2.forceSeekTo = f3;
                                    this.videoPlayerSeekbar.setProgress(f3);
                                }
                            }
                            this.shouldSavePositionForCurrentVideoShortTerm = str;
                        }
                    }
                }
                MessageObject messageObject3 = this.currentMessageObject;
                if (messageObject3 != null) {
                    float f4 = messageObject3.forceSeekTo;
                    if (f4 >= 0.0f) {
                        seekVideoOrWebToProgress(f4);
                        this.currentMessageObject.forceSeekTo = -1.0f;
                    }
                }
            }
            if (this.isStreaming) {
                if (playbackState != 2 || !this.skipFirstBufferingProgress) {
                    boolean z = this.seekToProgressPending != 0.0f || playbackState == 2;
                    if (z) {
                        AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
                    } else {
                        scheduleActionBarHide();
                    }
                    toggleMiniProgress(z, true);
                } else if (playWhenReady) {
                    this.skipFirstBufferingProgress = false;
                }
            }
            AspectRatioFrameLayout aspectRatioFrameLayout = this.aspectRatioFrameLayout;
            if (aspectRatioFrameLayout != null) {
                aspectRatioFrameLayout.setKeepScreenOn((!playWhenReady || playbackState == 4 || playbackState == 1) ? false : true);
            }
            if (playWhenReady && playbackState != 4 && playbackState != 1) {
                try {
                    this.parentActivity.getWindow().addFlags(128);
                    this.keepScreenOnFlagSet = true;
                } catch (Exception e) {
                    FileLog.e(e);
                }
            } else {
                try {
                    this.parentActivity.getWindow().clearFlags(128);
                    this.keepScreenOnFlagSet = false;
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
            }
            if (playbackState == 3 || playbackState == 1) {
                if (this.currentMessageObject != null && (videoPlayer = this.videoPlayer) != null) {
                    this.videoPreviewFrame.open(videoPlayer.getCurrentUri());
                }
                float f5 = this.seekToProgressPending;
                if (f5 != 0.0f) {
                    seekVideoOrWebToProgress(f5);
                    this.seekToProgressPending = 0.0f;
                    MessageObject messageObject4 = this.currentMessageObject;
                    if (messageObject4 != null && !FileLoader.getInstance(messageObject4.currentAccount).isLoadingVideoAny(this.currentMessageObject.getDocument())) {
                        this.skipFirstBufferingProgress = true;
                    }
                }
            }
            if (playbackState == 3) {
                AspectRatioFrameLayout aspectRatioFrameLayout2 = this.aspectRatioFrameLayout;
                if (aspectRatioFrameLayout2 != null && aspectRatioFrameLayout2.getVisibility() != 0) {
                    this.aspectRatioFrameLayout.setVisibility(0);
                }
                if (!this.pipItem.isEnabled() && this.pipItem.getVisibility() == 0) {
                    this.pipAvailable = true;
                    this.pipItem.setEnabled(true);
                    this.pipItem.animate().alpha(1.0f).setDuration(175L).withEndAction(null).start();
                }
                this.playerWasReady = true;
                MessageObject messageObject5 = this.currentMessageObject;
                if (messageObject5 != null && (messageObject5.isVideo() || this.playGifAsVideo)) {
                    AndroidUtilities.cancelRunOnUIThread(this.setLoadingRunnable);
                    FileLoader.getInstance(this.currentMessageObject.currentAccount).removeLoadingVideo(this.currentMessageObject.getDocument(), true, false);
                }
            } else if (playbackState == 2 && playWhenReady && (messageObject = this.currentMessageObject) != null && (messageObject.isVideo() || this.playGifAsVideo)) {
                if (this.playerWasReady) {
                    this.setLoadingRunnable.run();
                } else {
                    AndroidUtilities.runOnUIThread(this.setLoadingRunnable, 1000L);
                }
            }
            VideoPlayer videoPlayer2 = this.videoPlayer;
            if (videoPlayer2 == null ? this.photoViewerWebView.isPlaying() : videoPlayer2.isPlaying()) {
                if (playbackState != 4) {
                    if (!this.isPlaying) {
                        this.isPlaying = true;
                        this.photoProgressViews[0].setBackgroundState(this.isCurrentVideo ? -1 : 4, false, true);
                        PhotoProgressView photoProgressView = this.photoProgressViews[0];
                        if (this.isCurrentVideo || ((isAccessibilityEnabled() && !this.playerWasPlaying) || ((!this.playerAutoStarted || this.playerWasPlaying) && this.isActionBarVisible))) {
                            f = 1.0f;
                        }
                        photoProgressView.setIndexedAlpha(1, f, false);
                        this.playerWasPlaying = true;
                        AndroidUtilities.runOnUIThread(this.updateProgressRunnable);
                    }
                    PipVideoOverlay.updatePlayButton();
                    this.videoPlayerSeekbar.updateTimestamps(this.currentMessageObject, getVideoDuration());
                    updateVideoPlayerTime();
                }
            }
            if (this.isPlaying || playbackState == 4) {
                if (this.currentEditMode != 3) {
                    this.photoProgressViews[0].setIndexedAlpha(1, 1.0f, playbackState == 4);
                    PhotoProgressView[] photoProgressViewArr = this.photoProgressViews;
                    photoProgressViewArr[0].setBackgroundState(3, false, photoProgressViewArr[0].animAlphas[1] > 0.0f);
                }
                this.isPlaying = false;
                AndroidUtilities.cancelRunOnUIThread(this.updateProgressRunnable);
                if (playbackState == 4) {
                    if (this.isCurrentVideo) {
                        if (!this.videoTimelineView.isDragging()) {
                            VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
                            videoTimelinePlayView.setProgress(videoTimelinePlayView.getLeftProgress());
                            if (!this.inPreview && (this.currentEditMode != 0 || this.videoTimelineViewContainer.getVisibility() == 0)) {
                                seekVideoOrWebToProgress(this.videoTimelineView.getLeftProgress());
                            } else {
                                seekVideoOrWebToProgress(0.0f);
                            }
                            this.manuallyPaused = false;
                            cancelVideoPlayRunnable();
                            if (this.sendPhotoType != 1 && this.currentEditMode == 0 && this.switchingToMode <= 0) {
                                pauseVideoOrWeb();
                            } else {
                                playVideoOrWeb();
                            }
                            this.containerView.invalidate();
                        }
                    } else {
                        this.videoPlayerSeekbar.setProgress(0.0f);
                        this.videoPlayerSeekbarView.invalidate();
                        if (!this.inPreview && this.videoTimelineViewContainer.getVisibility() == 0) {
                            seekVideoOrWebToProgress(this.videoTimelineView.getLeftProgress());
                        } else {
                            seekVideoOrWebToProgress(0.0f);
                        }
                        this.manuallyPaused = false;
                        pauseVideoOrWeb();
                        if (!this.isActionBarVisible) {
                            toggleActionBar(true, true);
                        }
                    }
                    PipVideoOverlay.onVideoCompleted();
                }
            }
            PipVideoOverlay.updatePlayButton();
            this.videoPlayerSeekbar.updateTimestamps(this.currentMessageObject, getVideoDuration());
            updateVideoPlayerTime();
        }
    }

    public final void playVideoOrWeb() {
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            videoPlayer.play();
            return;
        }
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null) {
            photoViewerWebView.playVideo();
        }
    }

    public final void pauseVideoOrWeb() {
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            videoPlayer.pause();
            return;
        }
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null) {
            photoViewerWebView.pauseVideo();
        }
    }

    public final void seekVideoOrWebToProgress(float progress) {
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            videoPlayer.seekTo((long) (progress * videoPlayer.getDuration()));
            return;
        }
        PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
        if (photoViewerWebView != null) {
            photoViewerWebView.seekTo((long) (progress * photoViewerWebView.getVideoDuration()));
        }
    }

    public final void preparePlayer(Uri uri, boolean playWhenReady, boolean preview) {
        preparePlayer(uri, playWhenReady, preview, null);
    }

    public final void preparePlayer(Uri uri, boolean playWhenReady, boolean preview, MediaController.SavedFilterState savedFilterState) {
        boolean z;
        PageBlocksAdapter pageBlocksAdapter;
        if (!preview) {
            this.currentPlayingVideoFile = uri;
        }
        if (this.parentActivity == null) {
            return;
        }
        this.streamingAlertShown = false;
        this.startedPlayTime = SystemClock.elapsedRealtime();
        this.currentVideoFinishedLoading = false;
        this.lastBufferedPositionCheck = 0L;
        this.firstAnimationDelay = true;
        this.inPreview = preview;
        releasePlayer(false);
        SavedVideoPosition savedVideoPosition = null;
        if (this.imagesArrLocals.isEmpty()) {
            createVideoTextureView(null);
        }
        if (Build.VERSION.SDK_INT >= 21 && this.textureImageView == null) {
            ImageView imageView = new ImageView(this.parentActivity);
            this.textureImageView = imageView;
            imageView.setBackgroundColor(-65536);
            this.textureImageView.setPivotX(0.0f);
            this.textureImageView.setPivotY(0.0f);
            this.textureImageView.setVisibility(4);
            this.containerView.addView(this.textureImageView);
        }
        checkFullscreenButton();
        if (this.orientationEventListener == null) {
            OrientationEventListener orientationEventListener = new OrientationEventListener(ApplicationLoader.applicationContext) {
                @Override
                public void onOrientationChanged(int orientation) {
                    if (PhotoViewer.this.orientationEventListener == null || PhotoViewer.this.aspectRatioFrameLayout == null || PhotoViewer.this.aspectRatioFrameLayout.getVisibility() != 0 || PhotoViewer.this.parentActivity == null || PhotoViewer.this.fullscreenedByButton == 0) {
                        return;
                    }
                    if (PhotoViewer.this.fullscreenedByButton != 1) {
                        if (orientation > 0 && (orientation >= 330 || orientation <= 30)) {
                            PhotoViewer.this.wasRotated = true;
                            return;
                        }
                        if (!PhotoViewer.this.wasRotated || orientation < 240 || orientation > 300) {
                            return;
                        }
                        PhotoViewer.this.parentActivity.setRequestedOrientation(PhotoViewer.this.prevOrientation);
                        PhotoViewer.this.fullscreenedByButton = 0;
                        PhotoViewer.this.wasRotated = false;
                        return;
                    }
                    if (orientation >= 240 && orientation <= 300) {
                        PhotoViewer.this.wasRotated = true;
                        return;
                    }
                    if (!PhotoViewer.this.wasRotated || orientation <= 0) {
                        return;
                    }
                    if (orientation >= 330 || orientation <= 30) {
                        PhotoViewer.this.parentActivity.setRequestedOrientation(PhotoViewer.this.prevOrientation);
                        PhotoViewer.this.fullscreenedByButton = 0;
                        PhotoViewer.this.wasRotated = false;
                    }
                }
            };
            this.orientationEventListener = orientationEventListener;
            if (orientationEventListener.canDetectOrientation()) {
                this.orientationEventListener.enable();
            } else {
                this.orientationEventListener.disable();
                this.orientationEventListener = null;
            }
        }
        this.textureUploaded = false;
        this.videoSizeSet = false;
        this.videoCrossfadeStarted = false;
        this.playerWasReady = false;
        this.playerWasPlaying = false;
        this.captureFrameReadyAtTime = -1L;
        this.captureFrameAtTime = -1L;
        this.needCaptureFrameReadyAtTime = -1L;
        this.firstFrameRendered = false;
        if (this.videoPlayer == null) {
            VideoPlayer videoPlayer = this.injectingVideoPlayer;
            if (videoPlayer != null) {
                this.videoPlayer = videoPlayer;
                this.injectingVideoPlayer = null;
                this.playerInjected = true;
                updatePlayerState(videoPlayer.getPlayWhenReady(), this.videoPlayer.getPlaybackState());
                z = false;
            } else {
                this.videoPlayer = new VideoPlayer() {
                    public void play() {
                        super.play();
                        PhotoViewer.this.playOrStopAnimatedStickers(true);
                    }

                    public void pause() {
                        super.pause();
                        if (PhotoViewer.this.currentEditMode == 0) {
                            PhotoViewer.this.playOrStopAnimatedStickers(false);
                        }
                    }

                    public void seekTo(long positionMs) {
                        super.seekTo(positionMs);
                        if (PhotoViewer.this.isCurrentVideo) {
                            PhotoViewer.this.seekAnimatedStickersTo(positionMs);
                        }
                    }

                    public void onRenderedFirstFrame() {
                        super.onRenderedFirstFrame();
                        PhotoViewer.this.firstFrameRendered = true;
                        if (PhotoViewer.this.usedSurfaceView) {
                            PhotoViewer.this.containerView.invalidate();
                        }
                    }
                };
                z = true;
            }
            TextureView textureView = this.videoTextureView;
            if (textureView != null) {
                this.videoPlayer.setTextureView(textureView);
            } else {
                SurfaceView surfaceView = this.videoSurfaceView;
                if (surfaceView != null) {
                    this.videoPlayer.setSurfaceView(surfaceView);
                }
            }
            FirstFrameView firstFrameView = this.firstFrameView;
            if (firstFrameView != null) {
                firstFrameView.clear();
            }
            this.videoPlayer.setDelegate(new AnonymousClass53());
        } else {
            z = false;
        }
        if (!this.imagesArrLocals.isEmpty()) {
            createVideoTextureView(savedFilterState);
        }
        this.videoCrossfadeAlpha = 0.0f;
        TextureView textureView2 = this.videoTextureView;
        if (textureView2 != null) {
            textureView2.setAlpha(0.0f);
        }
        SurfaceView surfaceView2 = this.videoSurfaceView;
        if (surfaceView2 != null) {
            surfaceView2.setVisibility(4);
        }
        PaintingOverlay paintingOverlay = this.paintingOverlay;
        if (paintingOverlay != null) {
            paintingOverlay.setAlpha(this.videoCrossfadeAlpha);
        }
        this.shouldSavePositionForCurrentVideo = null;
        this.shouldSavePositionForCurrentVideoShortTerm = null;
        this.lastSaveTime = 0L;
        if (z) {
            this.seekToProgressPending = this.seekToProgressPending2;
            this.videoPlayerSeekbar.setProgress(0.0f);
            VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
            videoTimelinePlayView.setProgress(videoTimelinePlayView.getLeftProgress());
            this.videoPlayerSeekbar.setBufferedProgress(0.0f);
            MessageObject messageObject = this.currentMessageObject;
            if (messageObject != null) {
                int duration = (int) messageObject.getDuration();
                String fileName = this.currentMessageObject.getFileName();
                if (!TextUtils.isEmpty(fileName)) {
                    if (duration >= 600) {
                        if (this.currentMessageObject.forceSeekTo < 0.0f) {
                            float f = ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", 0).getFloat(fileName, -1.0f);
                            if (f > 0.0f && f < 0.999f) {
                                this.currentMessageObject.forceSeekTo = f;
                                this.videoPlayerSeekbar.setProgress(f);
                            }
                        }
                        this.shouldSavePositionForCurrentVideo = fileName;
                    } else if (duration >= 10) {
                        for (int size = this.savedVideoPositions.size() - 1; size >= 0; size--) {
                            SavedVideoPosition savedVideoPosition2 = (SavedVideoPosition) this.savedVideoPositions.valueAt(size);
                            if (savedVideoPosition2.timestamp < SystemClock.elapsedRealtime() - 5000) {
                                this.savedVideoPositions.removeAt(size);
                            } else if (savedVideoPosition == null && ((String) this.savedVideoPositions.keyAt(size)).equals(fileName)) {
                                savedVideoPosition = savedVideoPosition2;
                            }
                        }
                        MessageObject messageObject2 = this.currentMessageObject;
                        if (messageObject2 != null && messageObject2.forceSeekTo < 0.0f && savedVideoPosition != null) {
                            float f2 = savedVideoPosition.position;
                            if (f2 > 0.0f && f2 < 0.999f) {
                                messageObject2.forceSeekTo = f2;
                                this.videoPlayerSeekbar.setProgress(f2);
                            }
                        }
                        this.shouldSavePositionForCurrentVideoShortTerm = fileName;
                    }
                }
            }
            this.videoPlayer.preparePlayer(uri, "other");
            this.videoPlayer.setPlayWhenReady(playWhenReady);
        }
        MessageObject messageObject3 = this.currentMessageObject;
        boolean z2 = (messageObject3 != null && messageObject3.getDuration() <= 30.0d) || ((pageBlocksAdapter = this.pageBlocksAdapter) != null && pageBlocksAdapter.isHardwarePlayer(this.currentIndex));
        this.playerLooping = z2;
        this.videoPlayerControlFrameLayout.setSeekBarTransitionEnabled(z2);
        this.videoPlayer.setLooping(this.playerLooping);
        MessageObject messageObject4 = this.currentMessageObject;
        if (messageObject4 != null) {
            float f3 = messageObject4.forceSeekTo;
            if (f3 >= 0.0f) {
                this.seekToProgressPending = f3;
                messageObject4.forceSeekTo = -1.0f;
            }
        }
        TLRPC.BotInlineResult botInlineResult = this.currentBotInlineResult;
        if (botInlineResult != null && (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(this.currentBotInlineResult.document))) {
            this.bottomLayout.setVisibility(0);
            this.bottomLayout.setPadding(0, 0, AndroidUtilities.dp(84.0f), 0);
            this.pickerView.setVisibility(8);
        } else {
            this.bottomLayout.setPadding(0, 0, 0, 0);
        }
        if (this.pageBlocksAdapter != null) {
            this.bottomLayout.setVisibility(0);
        }
        PageBlocksAdapter pageBlocksAdapter2 = this.pageBlocksAdapter;
        if (pageBlocksAdapter2 != null && pageBlocksAdapter2.isHardwarePlayer(this.currentIndex) && !this.pageBlocksAdapter.isVideo(this.currentIndex)) {
            setVideoPlayerControlVisible(false, true);
        } else {
            setVideoPlayerControlVisible(!this.isCurrentVideo, true);
        }
        if (!this.isCurrentVideo) {
            scheduleActionBarHide(this.playerAutoStarted ? 3000 : 1000);
        }
        if (this.currentMessageObject != null) {
            this.videoPlayer.setPlaybackSpeed(this.currentVideoSpeed);
        }
        this.inPreview = preview;
    }

    public class AnonymousClass53 implements VideoPlayer.VideoPlayerDelegate {
        public boolean firstState = true;

        public void onSeekFinished(AnalyticsListener.EventTime eventTime) {
            VideoPlayer.VideoPlayerDelegate.-CC.$default$onSeekFinished(this, eventTime);
        }

        public void onSeekStarted(AnalyticsListener.EventTime eventTime) {
            VideoPlayer.VideoPlayerDelegate.-CC.$default$onSeekStarted(this, eventTime);
        }

        public AnonymousClass53() {
        }

        public void onStateChanged(boolean playWhenReady, int playbackState) {
            if (this.firstState && PhotoViewer.this.videoPlayer != null && PhotoViewer.this.videoPlayer.getDuration() != -9223372036854775807L) {
                this.firstState = false;
                if (PhotoViewer.this.imagesArr.isEmpty() && PhotoViewer.this.secureDocuments.isEmpty() && PhotoViewer.this.imagesArrLocations.isEmpty() && !PhotoViewer.this.imagesArrLocals.isEmpty() && PhotoViewer.this.switchingToIndex >= 0 && PhotoViewer.this.switchingToIndex < PhotoViewer.this.imagesArrLocals.size()) {
                    Object obj = PhotoViewer.this.imagesArrLocals.get(PhotoViewer.this.switchingToIndex);
                    if (obj instanceof MediaController.PhotoEntry) {
                        MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj;
                        if (photoEntry.isVideo && ((MediaController.MediaEditState) photoEntry).editedInfo != null) {
                            PhotoViewer.this.videoPlayer.seekTo((long) (((MediaController.MediaEditState) photoEntry).editedInfo.start * PhotoViewer.this.videoPlayer.getDuration()));
                            if (PhotoViewer.this.videoTimelineView != null) {
                                PhotoViewer.this.videoTimelineView.setProgress(((MediaController.MediaEditState) photoEntry).editedInfo.start);
                            }
                        }
                    }
                }
            }
            PhotoViewer.this.updatePlayerState(playWhenReady, playbackState);
        }

        public void onError(VideoPlayer player, Exception e) {
            if (PhotoViewer.this.videoPlayer != player) {
                return;
            }
            FileLog.e(e);
            if (PhotoViewer.this.menuItem.isSubItemVisible(11)) {
                AlertDialog.Builder builder = new AlertDialog.Builder(PhotoViewer.this.parentActivity, PhotoViewer.this.resourcesProvider);
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("CantPlayVideo", R.string.CantPlayVideo));
                builder.setPositiveButton(LocaleController.getString("Open", R.string.Open), new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(DialogInterface dialogInterface, int i) {
                        PhotoViewer.AnonymousClass53.this.lambda$onError$0(dialogInterface, i);
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                PhotoViewer.this.showAlertDialog(builder);
            }
        }

        public void lambda$onError$0(DialogInterface dialogInterface, int i) {
            try {
                AndroidUtilities.openForView(PhotoViewer.this.currentMessageObject, PhotoViewer.this.parentActivity, PhotoViewer.this.resourcesProvider);
                PhotoViewer.this.closePhoto(false, false);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }

        public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
            if (PhotoViewer.this.aspectRatioFrameLayout != null) {
                if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
                    height = width;
                    width = height;
                }
                float f = width * pixelWidthHeightRatio;
                int i = (int) f;
                PhotoViewer.this.videoWidth = i;
                float f2 = height;
                PhotoViewer.this.videoHeight = (int) (pixelWidthHeightRatio * f2);
                PhotoViewer.this.aspectRatioFrameLayout.setAspectRatio(height == 0 ? 1.0f : f / f2, unappliedRotationDegrees);
                if (PhotoViewer.this.videoTextureView instanceof VideoEditTextureView) {
                    PhotoViewer.this.videoTextureView.setHDRInfo(PhotoViewer.this.videoPlayer.getHDRStaticInfo((StoryEntry.HDRInfo) null));
                    PhotoViewer.this.videoTextureView.setVideoSize(i, height);
                    if (PhotoViewer.this.sendPhotoType == 1) {
                        PhotoViewer.this.setCropBitmap();
                    }
                }
                PhotoViewer.this.videoSizeSet = true;
            }
        }

        public void onRenderedFirstFrame() {
            if (!PhotoViewer.this.textureUploaded) {
                PhotoViewer.this.textureUploaded = true;
                PhotoViewer.this.containerView.invalidate();
            }
            if (PhotoViewer.this.firstFrameView != null) {
                if (PhotoViewer.this.videoPlayer == null || !PhotoViewer.this.videoPlayer.isLooping()) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.AnonymousClass53.this.lambda$onRenderedFirstFrame$1();
                        }
                    }, 64L);
                }
            }
        }

        public void lambda$onRenderedFirstFrame$1() {
            PhotoViewer.this.firstFrameView.updateAlpha();
        }

        public void onRenderedFirstFrame(AnalyticsListener.EventTime eventTime) {
            if (eventTime.eventPlaybackPositionMs == PhotoViewer.this.needCaptureFrameReadyAtTime) {
                PhotoViewer.this.captureFrameReadyAtTime = eventTime.eventPlaybackPositionMs;
                PhotoViewer.this.needCaptureFrameReadyAtTime = -1L;
                PhotoViewer.this.captureCurrentFrame();
            }
            if (PhotoViewer.this.firstFrameView != null) {
                if (PhotoViewer.this.videoPlayer == null || !PhotoViewer.this.videoPlayer.isLooping()) {
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.AnonymousClass53.this.lambda$onRenderedFirstFrame$2();
                        }
                    }, 64L);
                }
            }
        }

        public void lambda$onRenderedFirstFrame$2() {
            PhotoViewer.this.firstFrameView.updateAlpha();
        }

        public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
            if (PhotoViewer.this.changingTextureView) {
                PhotoViewer.this.changingTextureView = false;
                if (PhotoViewer.this.isInline) {
                    PhotoViewer.this.waitingForFirstTextureUpload = 1;
                    PhotoViewer.this.changedTextureView.setSurfaceTexture(surfaceTexture);
                    PhotoViewer.this.changedTextureView.setSurfaceTextureListener(PhotoViewer.this.surfaceTextureListener);
                    PhotoViewer.this.changedTextureView.setVisibility(0);
                    return true;
                }
            }
            return false;
        }

        public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
            PhotoViewer.this.checkChangedTextureView(false);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass53.this.lambda$onSurfaceTextureUpdated$3();
                }
            });
        }

        public void lambda$onSurfaceTextureUpdated$3() {
            if (PhotoViewer.this.firstFrameView != null) {
                PhotoViewer.this.firstFrameView.checkFromPlayer(PhotoViewer.this.videoPlayer);
            }
        }
    }

    public void checkFullscreenButton() {
        int measuredWidth;
        TextureView textureView;
        int measuredHeight;
        TextureView textureView2;
        float f;
        MessageObject messageObject;
        if (this.imagesArr.isEmpty()) {
            for (int i = 0; i < 3; i++) {
                this.fullscreenButton[i].setVisibility(4);
            }
            return;
        }
        int i2 = 0;
        while (i2 < 3) {
            int i3 = this.currentIndex;
            if (i2 == 1) {
                i3++;
            } else if (i2 == 2) {
                i3--;
            }
            if (i3 < 0 || i3 >= this.imagesArr.size()) {
                this.fullscreenButton[i2].setVisibility(4);
            } else {
                MessageObject messageObject2 = this.imagesArr.get(i3);
                if (!messageObject2.isVideo() && !messageObject2.isYouTubeVideo()) {
                    this.fullscreenButton[i2].setVisibility(4);
                } else {
                    boolean z = messageObject2.isYouTubeVideo() && (messageObject = this.currentMessageObject) != null && messageObject.getId() == messageObject2.getId();
                    if (z) {
                        measuredWidth = messageObject2.messageOwner.media.webpage.embed_width;
                    } else {
                        measuredWidth = (i2 != 0 || (textureView = this.videoTextureView) == null) ? 0 : textureView.getMeasuredWidth();
                    }
                    if (z) {
                        measuredHeight = messageObject2.messageOwner.media.webpage.embed_height;
                    } else {
                        measuredHeight = (i2 != 0 || (textureView2 = this.videoTextureView) == null) ? 0 : textureView2.getMeasuredHeight();
                    }
                    TLRPC.Document document = messageObject2.getDocument();
                    if (document != null) {
                        int size = document.attributes.size();
                        int i4 = 0;
                        while (true) {
                            if (i4 >= size) {
                                break;
                            }
                            TLRPC.DocumentAttribute documentAttribute = (TLRPC.DocumentAttribute) document.attributes.get(i4);
                            if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                                measuredWidth = documentAttribute.w;
                                measuredHeight = documentAttribute.h;
                                break;
                            }
                            i4++;
                        }
                    }
                    Point point = AndroidUtilities.displaySize;
                    if (point.y > point.x && measuredWidth > measuredHeight) {
                        if (this.fullscreenButton[i2].getVisibility() != 0) {
                            this.fullscreenButton[i2].setVisibility(0);
                        }
                        if (this.isActionBarVisible) {
                            this.fullscreenButton[i2].setAlpha(1.0f);
                        }
                        ((FrameLayout.LayoutParams) this.fullscreenButton[i2].getLayoutParams()).topMargin = ((this.containerView.getMeasuredHeight() + ((int) (measuredHeight / (measuredWidth / this.containerView.getMeasuredWidth())))) / 2) - AndroidUtilities.dp(48.0f);
                    } else if (this.fullscreenButton[i2].getVisibility() != 4) {
                        this.fullscreenButton[i2].setVisibility(4);
                    }
                    if (this.imageMoveAnimation != null) {
                        float f2 = this.translationX;
                        f = f2 + ((this.animateToX - f2) * this.animationValue);
                    } else {
                        f = this.translationX;
                    }
                    float f3 = 0.0f;
                    if (i2 != 1) {
                        if (i2 == 2) {
                            f3 = ((-AndroidUtilities.displaySize.x) - AndroidUtilities.dp(15.0f)) + (f - this.maxX);
                        } else {
                            float f4 = this.minX;
                            if (f < f4) {
                                f3 = f - f4;
                            }
                        }
                    }
                    this.fullscreenButton[i2].setTranslationX((f3 + AndroidUtilities.displaySize.x) - AndroidUtilities.dp(48.0f));
                }
            }
            i2++;
        }
    }

    public final void createVideoTextureView(final MediaController.SavedFilterState savedFilterState) {
        if (this.videoTextureView != null) {
            return;
        }
        AspectRatioFrameLayout aspectRatioFrameLayout = new AspectRatioFrameLayout(this.parentActivity) {
            public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                if (PhotoViewer.this.textureImageView != null) {
                    ViewGroup.LayoutParams layoutParams = PhotoViewer.this.textureImageView.getLayoutParams();
                    layoutParams.width = getMeasuredWidth();
                    layoutParams.height = getMeasuredHeight();
                }
                if (PhotoViewer.this.videoTextureView instanceof VideoEditTextureView) {
                    PhotoViewer.this.videoTextureView.setPivotX(PhotoViewer.this.videoTextureView.getMeasuredWidth() / 2);
                    PhotoViewer.this.firstFrameView.setPivotX(PhotoViewer.this.videoTextureView.getMeasuredWidth() / 2);
                } else {
                    if (PhotoViewer.this.videoTextureView != null) {
                        PhotoViewer.this.videoTextureView.setPivotX(0.0f);
                    }
                    if (PhotoViewer.this.videoSurfaceView != null) {
                        PhotoViewer.this.videoSurfaceView.setPivotX(0.0f);
                    }
                    PhotoViewer.this.firstFrameView.setPivotX(0.0f);
                }
                PhotoViewer.this.checkFullscreenButton();
            }

            public boolean drawChild(Canvas canvas, View child, long drawingTime) {
                if (child == PhotoViewer.this.lastFrameImageView && PhotoViewer.this.skipLastFrameDraw) {
                    return true;
                }
                return super/*android.widget.FrameLayout*/.drawChild(canvas, child, drawingTime);
            }
        };
        this.aspectRatioFrameLayout = aspectRatioFrameLayout;
        aspectRatioFrameLayout.setWillNotDraw(false);
        this.aspectRatioFrameLayout.setVisibility(4);
        this.containerView.addView(this.aspectRatioFrameLayout, 0, LayoutHelper.createFrame(-1, -1, 17));
        this.usedSurfaceView = false;
        if (this.imagesArrLocals.isEmpty()) {
            if (this.ALLOW_USE_SURFACE && this.injectingVideoPlayerSurface == null) {
                this.videoSurfaceView = new SurfaceView(this.parentActivity);
                this.usedSurfaceView = true;
            } else {
                this.videoTextureView = new TextureView(this.parentActivity);
            }
        } else {
            VideoEditTextureView videoEditTextureView = new VideoEditTextureView(this.parentActivity, this.videoPlayer);
            this.blurManager.resetBitmap();
            videoEditTextureView.updateUiBlurManager(this.blurManager);
            if (savedFilterState != null) {
                videoEditTextureView.setDelegate(new VideoEditTextureView.VideoEditTextureViewDelegate() {
                    public final void onEGLThreadAvailable(FilterGLThread filterGLThread) {
                        PhotoViewer.lambda$createVideoTextureView$61(savedFilterState, filterGLThread);
                    }
                });
            }
            this.videoTextureView = videoEditTextureView;
        }
        SurfaceTexture surfaceTexture = this.injectingVideoPlayerSurface;
        if (surfaceTexture != null) {
            this.videoTextureView.setSurfaceTexture(surfaceTexture);
            this.textureUploaded = true;
            this.videoSizeSet = true;
            this.injectingVideoPlayerSurface = null;
        }
        TextureView textureView = this.videoTextureView;
        if (textureView != null) {
            textureView.setPivotX(0.0f);
            this.videoTextureView.setPivotY(0.0f);
            this.videoTextureView.setOpaque(false);
            this.aspectRatioFrameLayout.addView(this.videoTextureView, LayoutHelper.createFrame(-1, -1, 17));
        } else {
            this.aspectRatioFrameLayout.addView(this.videoSurfaceView, LayoutHelper.createFrame(-1, -1, 17));
        }
        FirstFrameView firstFrameView = new FirstFrameView(this.parentActivity);
        this.firstFrameView = firstFrameView;
        firstFrameView.setPivotX(0.0f);
        this.firstFrameView.setPivotY(0.0f);
        this.firstFrameView.setScaleType(ImageView.ScaleType.FIT_XY);
        this.aspectRatioFrameLayout.addView(this.firstFrameView, LayoutHelper.createFrame(-1, -1, 17));
        if (this.sendPhotoType == 1) {
            View view = new View(this.parentActivity);
            this.flashView = view;
            view.setBackgroundColor(-1);
            this.flashView.setAlpha(0.0f);
            this.aspectRatioFrameLayout.addView(this.flashView, LayoutHelper.createFrame(-1, -1, 17));
        }
    }

    public static void lambda$createVideoTextureView$61(MediaController.SavedFilterState savedFilterState, FilterGLThread filterGLThread) {
        filterGLThread.setFilterGLThreadDelegate(FilterShaders.getFilterShadersDelegate(savedFilterState));
    }

    public final void releasePlayer(boolean onClose) {
        this.usedSurfaceView = false;
        if (this.videoPlayer != null) {
            cancelVideoPlayRunnable();
            AndroidUtilities.cancelRunOnUIThread(this.setLoadingRunnable);
            AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
            if (this.shouldSavePositionForCurrentVideoShortTerm != null) {
                this.savedVideoPositions.put(this.shouldSavePositionForCurrentVideoShortTerm, new SavedVideoPosition(this.videoPlayer.getCurrentPosition() / this.videoPlayer.getDuration(), SystemClock.elapsedRealtime()));
            }
            this.videoPlayer.releasePlayer(true);
            this.videoPlayer = null;
        } else {
            this.playerWasPlaying = false;
        }
        if (this.photoViewerWebView != null) {
            AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
            if (this.shouldSavePositionForCurrentVideoShortTerm != null) {
                this.savedVideoPositions.put(this.shouldSavePositionForCurrentVideoShortTerm, new SavedVideoPosition(getCurrentVideoPosition() / getVideoDuration(), SystemClock.elapsedRealtime()));
            }
        }
        OrientationEventListener orientationEventListener = this.orientationEventListener;
        if (orientationEventListener != null) {
            orientationEventListener.disable();
            this.orientationEventListener = null;
        }
        this.videoPreviewFrame.close();
        toggleMiniProgress(false, false);
        this.pipAvailable = false;
        this.playerInjected = false;
        if (this.pipItem.isEnabled()) {
            this.pipItem.setEnabled(false);
            this.pipItem.animate().alpha(0.5f).setDuration(175L).withEndAction(null).start();
        }
        if (this.keepScreenOnFlagSet) {
            try {
                this.parentActivity.getWindow().clearFlags(128);
                this.keepScreenOnFlagSet = false;
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        View view = this.aspectRatioFrameLayout;
        if (view != null) {
            try {
                this.containerView.removeView(view);
            } catch (Throwable unused) {
            }
            this.aspectRatioFrameLayout = null;
        }
        cancelFlashAnimations();
        this.flashView = null;
        VideoEditTextureView videoEditTextureView = this.videoTextureView;
        if (videoEditTextureView != null) {
            if (videoEditTextureView instanceof VideoEditTextureView) {
                videoEditTextureView.release();
            }
            this.videoTextureView = null;
        }
        this.blurManager.resetBitmap();
        if (this.videoSurfaceView != null) {
            this.videoSurfaceView = null;
        }
        if (this.isPlaying) {
            this.isPlaying = false;
            AndroidUtilities.cancelRunOnUIThread(this.updateProgressRunnable);
        }
        if (!onClose && !this.inPreview && !this.requestingPreview) {
            setVideoPlayerControlVisible(false, true);
        }
        this.photoProgressViews[0].resetAlphas();
    }

    public final void setVideoPlayerControlVisible(final boolean visible, boolean animated) {
        if (this.videoPlayerControlVisible != visible) {
            if (visible) {
                this.bottomLayout.setTag(1);
            } else {
                this.bottomLayout.setTag(null);
            }
            Animator animator = this.videoPlayerControlAnimator;
            if (animator != null) {
                animator.cancel();
            }
            this.videoPlayerControlVisible = visible;
            if (animated) {
                if (visible) {
                    this.videoPlayerControlFrameLayout.setVisibility(0);
                }
                float[] fArr = new float[2];
                fArr[0] = this.videoPlayerControlFrameLayout.getAlpha();
                fArr[1] = visible ? 1.0f : 0.0f;
                ValueAnimator ofFloat = ValueAnimator.ofFloat(fArr);
                ofFloat.setDuration(200L);
                ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.this.lambda$setVideoPlayerControlVisible$62(valueAnimator);
                    }
                });
                ofFloat.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (visible) {
                            return;
                        }
                        PhotoViewer.this.videoPlayerControlFrameLayout.setVisibility(8);
                    }
                });
                this.videoPlayerControlAnimator = ofFloat;
                ofFloat.start();
            } else {
                this.videoPlayerControlFrameLayout.setVisibility(visible ? 0 : 8);
                this.videoPlayerControlFrameLayout.setAlpha(visible ? 1.0f : 0.0f);
            }
            if (this.allowShare && this.pageBlocksAdapter == null) {
                if (visible) {
                    this.menuItem.showSubItem(10);
                } else {
                    this.menuItem.hideSubItem(10);
                }
            }
        }
    }

    public void lambda$setVideoPlayerControlVisible$62(ValueAnimator valueAnimator) {
        this.videoPlayerControlFrameLayout.setAlpha(((Float) valueAnimator.getAnimatedValue()).floatValue());
    }

    public final void updateCaptionTextForCurrentPhoto(Object object) {
        CharSequence charSequence;
        if (this.hasCaptionForAllMedia) {
            charSequence = this.captionForAllMedia;
        } else if (object instanceof MediaController.PhotoEntry) {
            charSequence = ((MediaController.MediaEditState) ((MediaController.PhotoEntry) object)).caption;
        } else {
            charSequence = (!(object instanceof TLRPC.BotInlineResult) && (object instanceof MediaController.SearchImage)) ? ((MediaController.SearchImage) object).caption : null;
        }
        if (TextUtils.isEmpty(charSequence)) {
            this.captionEdit.setText("");
        } else {
            this.captionEdit.setText(AnimatedEmojiSpan.cloneSpans(charSequence, 3));
        }
        ((CaptionContainerView) this.captionEdit).editText.getEditText().setAllowTextEntitiesIntersection(supportsSendingNewEntities());
    }

    public void showAlertDialog(AlertDialog.Builder builder) {
        if (this.parentActivity == null) {
            return;
        }
        try {
            AlertDialog alertDialog = this.visibleDialog;
            if (alertDialog != null) {
                alertDialog.dismiss();
                this.visibleDialog = null;
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        try {
            AlertDialog show = builder.show();
            this.visibleDialog = show;
            show.setCanceledOnTouchOutside(true);
            this.visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public final void onDismiss(DialogInterface dialogInterface) {
                    PhotoViewer.this.lambda$showAlertDialog$63(dialogInterface);
                }
            });
        } catch (Exception e2) {
            FileLog.e(e2);
        }
    }

    public void lambda$showAlertDialog$63(DialogInterface dialogInterface) {
        this.visibleDialog = null;
    }

    public final void mergeImages(String finalPath, String thumbPath, Bitmap thumb, Bitmap bitmap, float size, boolean reverse) {
        boolean z;
        if (thumb == null) {
            try {
                thumb = BitmapFactory.decodeFile(thumbPath);
                z = true;
            } catch (Throwable th) {
                FileLog.e(th);
                return;
            }
        } else {
            z = false;
        }
        int width = thumb.getWidth();
        int height = thumb.getHeight();
        float f = width;
        if (f > size || height > size) {
            float max = Math.max(width, height) / size;
            height = (int) (height / max);
            width = (int) (f / max);
        }
        Bitmap createBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        Rect rect = new Rect(0, 0, width, height);
        if (reverse) {
            canvas.drawBitmap(bitmap, (Rect) null, rect, this.bitmapPaint);
            canvas.drawBitmap(thumb, (Rect) null, rect, this.bitmapPaint);
        } else {
            canvas.drawBitmap(thumb, (Rect) null, rect, this.bitmapPaint);
            canvas.drawBitmap(bitmap, (Rect) null, rect, this.bitmapPaint);
        }
        FileOutputStream fileOutputStream = new FileOutputStream(new File(finalPath));
        createBitmap.compress(getCompressFormat(), size == 512.0f ? 83 : 87, fileOutputStream);
        try {
            fileOutputStream.close();
        } catch (Exception e) {
            FileLog.e(e);
        }
        if (z) {
            thumb.recycle();
        }
        createBitmap.recycle();
    }

    public final void seekAnimatedStickersTo(long ms) {
        RLottieDrawable lottieAnimation;
        ArrayList<VideoEditedInfo.MediaEntity> arrayList = this.editState.mediaEntities;
        if (arrayList != null) {
            int size = arrayList.size();
            for (int i = 0; i < size; i++) {
                VideoEditedInfo.MediaEntity mediaEntity = this.editState.mediaEntities.get(i);
                if (mediaEntity.type == 0 && (mediaEntity.subType & 1) != 0) {
                    BackupImageView backupImageView = mediaEntity.view;
                    if ((backupImageView instanceof BackupImageView) && (lottieAnimation = backupImageView.getImageReceiver().getLottieAnimation()) != null) {
                        long j = this.startTime;
                        lottieAnimation.setProgressMs(ms - (j > 0 ? j / 1000 : 0L));
                    }
                }
            }
        }
    }

    public final void playOrStopAnimatedStickers(boolean play) {
        RLottieDrawable lottieAnimation;
        ArrayList<VideoEditedInfo.MediaEntity> arrayList = this.editState.mediaEntities;
        if (arrayList != null) {
            int size = arrayList.size();
            for (int i = 0; i < size; i++) {
                VideoEditedInfo.MediaEntity mediaEntity = this.editState.mediaEntities.get(i);
                if (mediaEntity.type == 0 && (mediaEntity.subType & 1) != 0) {
                    BackupImageView backupImageView = mediaEntity.view;
                    if ((backupImageView instanceof BackupImageView) && (lottieAnimation = backupImageView.getImageReceiver().getLottieAnimation()) != null) {
                        if (play) {
                            lottieAnimation.start();
                        } else {
                            lottieAnimation.stop();
                        }
                    }
                }
            }
        }
    }

    public final int getAnimatedMediaEntitiesCount(boolean r7) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.getAnimatedMediaEntitiesCount(boolean):int");
    }

    public final boolean hasAnimatedMediaEntities() {
        return getAnimatedMediaEntitiesCount(true) != 0;
    }

    public final android.graphics.Bitmap createCroppedBitmap(android.graphics.Bitmap r17, org.telegram.messenger.MediaController.CropState r18, int[] r19, boolean r20) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.createCroppedBitmap(android.graphics.Bitmap, org.telegram.messenger.MediaController$CropState, int[], boolean):android.graphics.Bitmap");
    }

    public final void lambda$setParentActivity$16(android.graphics.Bitmap r15) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.lambda$setParentActivity$16(android.graphics.Bitmap):void");
    }

    public final void applyCurrentEditMode() {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.applyCurrentEditMode():void");
    }

    public final void setPhotoChecked() {
        ChatActivity chatActivity;
        TLRPC.Chat currentChat;
        PhotoViewerProvider photoViewerProvider = this.placeProvider;
        if (photoViewerProvider != null) {
            if (photoViewerProvider.getSelectedPhotos() != null && this.maxSelectedPhotos > 0 && this.placeProvider.getSelectedPhotos().size() >= this.maxSelectedPhotos && !this.placeProvider.isPhotoChecked(this.currentIndex)) {
                if (!this.allowOrder || (chatActivity = this.parentChatActivity) == null || (currentChat = chatActivity.getCurrentChat()) == null || ChatObject.hasAdminRights(currentChat) || !currentChat.slowmode_enabled) {
                    return;
                }
                AlertsCreator.createSimpleAlert(this.parentActivity, LocaleController.getString("Slowmode", R.string.Slowmode), LocaleController.getString("SlowmodeSelectSendError", R.string.SlowmodeSelectSendError)).show();
                return;
            }
            int photoChecked = this.placeProvider.setPhotoChecked(this.currentIndex, getCurrentVideoEditedInfo());
            boolean isPhotoChecked = this.placeProvider.isPhotoChecked(this.currentIndex);
            this.checkImageView.setChecked(isPhotoChecked, true);
            if (photoChecked >= 0) {
                if (isPhotoChecked) {
                    this.selectedPhotosAdapter.notifyItemInserted(photoChecked);
                    this.selectedPhotosListView.smoothScrollToPosition(photoChecked);
                } else {
                    this.selectedPhotosAdapter.notifyItemRemoved(photoChecked);
                    if (photoChecked == 0) {
                        this.selectedPhotosAdapter.notifyItemChanged(0);
                    }
                }
            }
            updateSelectedCount();
        }
    }

    public final void updateResetButtonVisibility(final boolean show) {
        if (this.resetButton.isClickable() != show) {
            this.resetButton.setClickable(show);
            this.resetButton.setVisibility(0);
            this.resetButton.clearAnimation();
            this.resetButton.animate().alpha(show ? 1.0f : 0.0f).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(150L).withEndAction(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$updateResetButtonVisibility$64(show);
                }
            });
        }
    }

    public void lambda$updateResetButtonVisibility$64(boolean z) {
        if (z) {
            return;
        }
        this.resetButton.setVisibility(8);
    }

    public final void createCropView() {
        if (this.photoCropView != null) {
            return;
        }
        PhotoCropView photoCropView = new PhotoCropView(this.activityContext, this.resourcesProvider);
        this.photoCropView = photoCropView;
        photoCropView.setVisibility(8);
        this.photoCropView.onDisappear();
        this.containerView.addView(this.photoCropView, this.containerView.indexOfChild(this.videoTimelineViewContainer) - 1, LayoutHelper.createFrame(-1, -1.0f, 51, 0.0f, 0.0f, 0.0f, 48.0f));
        this.photoCropView.setDelegate(new AnonymousClass56());
    }

    public class AnonymousClass56 implements PhotoCropView.PhotoCropViewDelegate {
        public AnonymousClass56() {
        }

        public void onChange(boolean reset) {
            PhotoViewer.this.updateResetButtonVisibility(!reset);
        }

        public void onUpdate() {
            PhotoViewer.this.containerView.invalidate();
        }

        public void onTapUp() {
            if (PhotoViewer.this.sendPhotoType == 1) {
                PhotoViewer.this.manuallyPaused = true;
                PhotoViewer.this.toggleVideoPlayer();
            }
        }

        public void onVideoThumbClick() {
            if (PhotoViewer.this.videoPlayer == null) {
                return;
            }
            PhotoViewer.this.videoPlayer.seekTo((long) (PhotoViewer.this.videoPlayer.getDuration() * PhotoViewer.this.avatarStartProgress));
            PhotoViewer.this.videoPlayer.pause();
            PhotoViewer.this.videoTimelineView.setProgress(PhotoViewer.this.avatarStartProgress);
            PhotoViewer.this.cancelVideoPlayRunnable();
            PhotoViewer photoViewer = PhotoViewer.this;
            Runnable runnable = new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass56.this.lambda$onVideoThumbClick$0();
                }
            };
            photoViewer.videoPlayRunnable = runnable;
            AndroidUtilities.runOnUIThread(runnable, 860L);
        }

        public void lambda$onVideoThumbClick$0() {
            PhotoViewer.this.manuallyPaused = false;
            if (PhotoViewer.this.videoPlayer != null) {
                PhotoViewer.this.videoPlayer.play();
            }
            PhotoViewer.this.videoPlayRunnable = null;
        }

        public boolean rotate() {
            return PhotoViewer.this.cropRotate(-90.0f);
        }

        public boolean mirror() {
            return PhotoViewer.this.cropMirror();
        }

        public int getVideoThumbX() {
            return (int) (AndroidUtilities.dp(16.0f) + ((PhotoViewer.this.videoTimelineView.getMeasuredWidth() - AndroidUtilities.dp(32.0f)) * PhotoViewer.this.avatarStartProgress));
        }
    }

    public final void startVideoPlayer() {
        VideoPlayer videoPlayer;
        if (!this.isCurrentVideo || (videoPlayer = this.videoPlayer) == null || videoPlayer.isPlaying()) {
            return;
        }
        if (!this.muteVideo || this.sendPhotoType == 1) {
            this.videoPlayer.setVolume(0.0f);
        }
        this.manuallyPaused = false;
        toggleVideoPlayer();
    }

    public final void detectFaces() {
        if (this.centerImage.getAnimation() != null || this.imagesArrLocals.isEmpty() || this.sendPhotoType == 1) {
            return;
        }
        String imageKey = this.centerImage.getImageKey();
        String str = this.currentImageFaceKey;
        if (str == null || !str.equals(imageKey)) {
            this.currentImageHasFace = 0;
            detectFaces(imageKey, this.centerImage.getBitmapSafe(), this.centerImage.getOrientation());
        }
    }

    public final void detectFaces(final String key, final ImageReceiver.BitmapHolder bitmap, final int orientation) {
        if (key == null || bitmap == null || bitmap.bitmap == null) {
            return;
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$detectFaces$67(bitmap, orientation, key);
            }
        });
    }

    public void lambda$detectFaces$67(final ImageReceiver.BitmapHolder bitmapHolder, int i, final String str) {
        FaceDetector faceDetector = null;
        try {
            try {
                final boolean z = false;
                faceDetector = new FaceDetector.Builder(ApplicationLoader.applicationContext).setMode(0).setLandmarkType(0).setTrackingEnabled(false).build();
                if (faceDetector.isOperational()) {
                    SparseArray detect = faceDetector.detect(new Frame.Builder().setBitmap(bitmapHolder.bitmap).setRotation(i).build());
                    if (detect != null && detect.size() != 0) {
                        z = true;
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.this.lambda$detectFaces$65(str, z);
                        }
                    });
                } else {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.e("face detection is not operational");
                    }
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.this.lambda$detectFaces$66(bitmapHolder, str);
                        }
                    });
                }
            } catch (Exception e) {
                FileLog.e(e);
                if (0 == 0) {
                    return;
                }
            }
            faceDetector.release();
        } catch (Throwable th) {
            if (0 != 0) {
                faceDetector.release();
            }
            throw th;
        }
    }

    public void lambda$detectFaces$65(String str, boolean z) {
        if (str.equals(this.centerImage.getImageKey())) {
            this.currentImageHasFace = z ? 1 : 0;
            this.currentImageFaceKey = str;
        }
    }

    public void lambda$detectFaces$66(ImageReceiver.BitmapHolder bitmapHolder, String str) {
        bitmapHolder.release();
        if (str.equals(this.centerImage.getImageKey())) {
            this.currentImageHasFace = 2;
            this.currentImageFaceKey = str;
        }
    }

    public void switchToEditMode(final int r33) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.switchToEditMode(int):void");
    }

    public void lambda$switchToEditMode$68(ValueAnimator valueAnimator) {
        this.photoCropView.cropView.areaView.setRotationScaleTranslation(0.0f, AndroidUtilities.lerp(this.scale, this.animateToScale, this.animationValue), AndroidUtilities.lerp(this.translationX, this.animateToX, this.animationValue), AndroidUtilities.lerp(this.translationY, this.animateToY, this.animationValue));
    }

    public void lambda$switchToEditMode$69(ValueAnimator valueAnimator) {
        this.photoPaintView.setOffsetTranslationY(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f, 0, false);
    }

    public void lambda$switchToEditMode$70(ValueAnimator valueAnimator) {
        this.photoPaintView.setOffsetTranslationX(((Float) valueAnimator.getAnimatedValue()).floatValue());
    }

    public class AnonymousClass57 extends AnimatorListenerAdapter {
        public final int val$mode;

        public AnonymousClass57(final int val$mode) {
            this.val$mode = val$mode;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (PhotoViewer.this.currentEditMode == 1) {
                PhotoViewer.this.photoCropView.onDisappear();
                PhotoViewer.this.photoCropView.onHide();
                PhotoViewer.this.editorDoneLayout.setVisibility(8);
                PhotoViewer.this.photoCropView.setVisibility(8);
                PhotoViewer.this.photoCropView.cropView.areaView.setRotationScaleTranslation(0.0f, 1.0f, 0.0f, 0.0f);
            } else if (PhotoViewer.this.currentEditMode == 2) {
                try {
                    PhotoViewer.this.containerView.removeView(PhotoViewer.this.photoFilterView);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                PhotoViewer.this.photoFilterView = null;
            } else if (PhotoViewer.this.currentEditMode == 3) {
                PhotoViewer.this.photoPaintView.onAnimationStateChanged(false);
                try {
                    PhotoViewer.this.containerView.removeView(PhotoViewer.this.photoPaintView.getView());
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
                PhotoViewer.this.photoPaintView = null;
            } else if (PhotoViewer.this.currentEditMode == 4) {
                PhotoViewer.this.maskPaintViewShuttingDown = true;
                PhotoViewer.this.containerView.invalidate();
                final MaskPaintView maskPaintView = PhotoViewer.this.maskPaintView;
                PhotoViewer.this.containerView.post(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass57.this.lambda$onAnimationEnd$0(maskPaintView);
                    }
                });
                PhotoViewer.this.maskPaintView = null;
                PhotoViewer.this.eraseBtn.setActive(false, true);
                PhotoViewer.this.restoreBtn.setActive(false, true);
            }
            PhotoViewer.this.imageMoveAnimation = null;
            int i = PhotoViewer.this.currentEditMode;
            PhotoViewer.this.currentEditMode = this.val$mode;
            ((CaptionContainerView) PhotoViewer.this.captionEdit).keyboardNotifier.ignore(PhotoViewer.this.currentEditMode != 0);
            if (PhotoViewer.this.paintKeyboardNotifier != null) {
                PhotoViewer.this.paintKeyboardNotifier.ignore(PhotoViewer.this.currentEditMode != 3);
            }
            if (PhotoViewer.this.currentEditMode != 3) {
                PhotoViewer.this.translateY = 0.0f;
            }
            PhotoViewer.this.applying = false;
            if (PhotoViewer.this.sendPhotoType == 1) {
                PhotoViewer.this.photoCropView.setVisibility(0);
            }
            if (PhotoViewer.this.sendPhotoType == 11 && (i == 3 || i == 2 || i == 1 || i == 4)) {
                PhotoViewer photoViewer = PhotoViewer.this;
                photoViewer.animateToX = photoViewer.savedTx;
                PhotoViewer photoViewer2 = PhotoViewer.this;
                photoViewer2.animateToY = photoViewer2.savedTy;
                PhotoViewer photoViewer3 = PhotoViewer.this;
                photoViewer3.animateToScale = photoViewer3.savedScale;
                PhotoViewer photoViewer4 = PhotoViewer.this;
                photoViewer4.animateToRotate = photoViewer4.savedRotation;
            } else {
                PhotoViewer photoViewer5 = PhotoViewer.this;
                float scale1 = photoViewer5.scale1(false);
                photoViewer5.animateToScale = scale1;
                photoViewer5.scale = scale1;
                PhotoViewer photoViewer6 = PhotoViewer.this;
                photoViewer6.updateMinMax(photoViewer6.scale);
                PhotoViewer.this.animateToX = 0.0f;
                PhotoViewer.this.animateToY = 0.0f;
            }
            PhotoViewer.this.switchingToMode = -1;
            PhotoViewer.this.containerView.invalidate();
            if (PhotoViewer.this.savedState != null) {
                PhotoViewer.this.savedState.restore();
                PhotoViewer.this.savedState = null;
                ActionBarToggleParams enableStatusBarAnimation = new ActionBarToggleParams().enableStatusBarAnimation(false);
                PhotoViewer.this.toggleActionBar(false, false, enableStatusBarAnimation);
                PhotoViewer.this.toggleActionBar(true, true, enableStatusBarAnimation);
                return;
            }
            AnimatorSet animatorSet = new AnimatorSet();
            ArrayList arrayList = new ArrayList();
            arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.TRANSLATION_Y, 0.0f));
            arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.ALPHA, 1.0f));
            StickerMakerView stickerMakerView = PhotoViewer.this.stickerMakerView;
            if (stickerMakerView != null) {
                arrayList.add(ObjectAnimator.ofFloat(stickerMakerView, (Property<StickerMakerView, Float>) View.ALPHA, 1.0f));
            }
            if (PhotoViewer.this.stickerMakerBackgroundView != null) {
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.stickerMakerBackgroundView, (Property<StickerMakerBackgroundView, Float>) View.ALPHA, 1.0f));
            }
            arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.pickerViewSendButton, (Property<ImageView, Float>) View.TRANSLATION_Y, 0.0f));
            if (PhotoViewer.this.sendPhotoType != 1) {
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.actionBar, (Property<ActionBar, Float>) View.TRANSLATION_Y, 0.0f));
            }
            if (PhotoViewer.this.needCaptionLayout) {
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.captionTextViewSwitcher, (Property<CaptionTextViewSwitcher, Float>) View.TRANSLATION_Y, 0.0f));
            }
            if (PhotoViewer.this.sendPhotoType == 0 || PhotoViewer.this.sendPhotoType == 4) {
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.checkImageView, (Property<CheckBox, Float>) View.ALPHA, 1.0f));
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.photosCounterView, (Property<CounterView, Float>) View.ALPHA, 1.0f));
            } else if (PhotoViewer.this.sendPhotoType == 1) {
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.photoCropView, (Property<PhotoCropView, Float>) View.ALPHA, 1.0f));
            }
            arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.photoQualityLayout, (Property<FrameLayout, Float>) View.ALPHA, 1.0f));
            if (PhotoViewer.this.muteItem.getTag() != null) {
                PhotoViewer.this.muteItem.setVisibility(0);
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.muteItem, (Property<ImageView, Float>) View.ALPHA, 1.0f));
            }
            if (PhotoViewer.this.navigationBar != null) {
                PhotoViewer.this.navigationBar.setVisibility(0);
                arrayList.add(ObjectAnimator.ofFloat(PhotoViewer.this.navigationBar, (Property<View, Float>) View.ALPHA, 1.0f));
            }
            animatorSet.playTogether(arrayList);
            animatorSet.setDuration(200L);
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation2) {
                    PhotoViewer.this.pickerView.setVisibility(0);
                    if (PhotoViewer.this.useFullWidthSendButton()) {
                        PhotoViewer.this.doneButtonFullWidth.setVisibility(0);
                    } else {
                        PhotoViewer.this.pickerViewSendButton.setVisibility(0);
                    }
                    PhotoViewer.this.actionBar.setVisibility(0);
                    if (PhotoViewer.this.needCaptionLayout) {
                        PhotoViewer.this.captionTextViewSwitcher.setVisibility(PhotoViewer.this.captionTextViewSwitcher.getTag() != null ? 0 : 4);
                    }
                    if (PhotoViewer.this.sendPhotoType == 0 || PhotoViewer.this.sendPhotoType == 4 || ((PhotoViewer.this.sendPhotoType == 2 || PhotoViewer.this.sendPhotoType == 5) && PhotoViewer.this.imagesArrLocals.size() > 1)) {
                        PhotoViewer.this.checkImageView.setVisibility(0);
                        PhotoViewer.this.photosCounterView.setVisibility(0);
                        PhotoViewer.this.updateActionBarTitlePadding();
                    }
                    if (PhotoViewer.this.isCurrentVideo || !Theme.plusShowPhotoQualityBar) {
                        return;
                    }
                    PhotoViewer.this.photoQualityLayout.setVisibility(0);
                }

                @Override
                public void onAnimationEnd(Animator animation2) {
                    if (PhotoViewer.this.videoConvertSupported && PhotoViewer.this.isCurrentVideo) {
                        PhotoViewer.this.updateVideoInfo();
                    }
                }
            });
            animatorSet.start();
        }

        public void lambda$onAnimationEnd$0(MaskPaintView maskPaintView) {
            maskPaintView.shutdown();
            try {
                PhotoViewer.this.containerView.removeView(maskPaintView);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
    }

    public void lambda$switchToEditMode$71(View view) {
        applyCurrentEditMode();
        switchToEditMode(0);
    }

    public void lambda$switchToEditMode$73(View view) {
        if (this.photoFilterView.hasChanges()) {
            Activity activity = this.parentActivity;
            if (activity == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(activity, this.resourcesProvider);
            builder.setMessage(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                @Override
                public final void onClick(DialogInterface dialogInterface, int i) {
                    PhotoViewer.this.lambda$switchToEditMode$72(dialogInterface, i);
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showAlertDialog(builder);
            return;
        }
        switchToEditMode(0);
    }

    public void lambda$switchToEditMode$72(DialogInterface dialogInterface, int i) {
        switchToEditMode(0);
    }

    public final void createMaskPaintView() {
        MediaController.CropState cropState;
        if (this.maskPaintView != null) {
            return;
        }
        if (this.sendPhotoType == 1) {
            cropState = new MediaController.CropState();
            cropState.transformRotation = this.cropTransform.getOrientation();
        } else {
            cropState = this.editState.cropState;
        }
        MediaController.CropState cropState2 = cropState;
        Bitmap createBitmap = Bitmap.createBitmap(this.centerImage.getBitmapWidth(), this.centerImage.getBitmapHeight(), Bitmap.Config.ARGB_8888);
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView != null && stickerMakerView.getSourceBitmap() != null) {
            Bitmap sourceBitmap = this.stickerMakerView.getSourceBitmap();
            Canvas canvas = new Canvas(createBitmap);
            canvas.translate(createBitmap.getWidth() / 2.0f, createBitmap.getHeight() / 2.0f);
            canvas.rotate(this.stickerMakerView.orientation);
            float width = createBitmap.getWidth() / ((this.stickerMakerView.orientation / 90) % 2 != 0 ? sourceBitmap.getHeight() : sourceBitmap.getWidth());
            RectF rectF = AndroidUtilities.rectTmp;
            rectF.set(((-sourceBitmap.getWidth()) / 2.0f) * width, ((-sourceBitmap.getHeight()) / 2.0f) * width, (sourceBitmap.getWidth() / 2.0f) * width, (sourceBitmap.getHeight() / 2.0f) * width);
            canvas.drawBitmap(sourceBitmap, (Rect) null, rectF, new Paint(3));
        }
        Bitmap createBitmap2 = Bitmap.createBitmap(this.centerImage.getBitmapWidth(), this.centerImage.getBitmapHeight(), Bitmap.Config.ARGB_8888);
        if (this.centerImage.getBitmap() != null) {
            Bitmap bitmap = this.centerImage.getBitmap();
            Canvas canvas2 = new Canvas(createBitmap2);
            canvas2.translate(createBitmap2.getWidth() / 2.0f, createBitmap2.getHeight() / 2.0f);
            canvas2.rotate(this.centerImage.getOrientation());
            float width2 = createBitmap2.getWidth() / ((this.centerImage.getOrientation() / 90) % 2 != 0 ? bitmap.getHeight() : bitmap.getWidth());
            RectF rectF2 = AndroidUtilities.rectTmp;
            rectF2.set(((-bitmap.getWidth()) / 2.0f) * width2, ((-bitmap.getHeight()) / 2.0f) * width2, (bitmap.getWidth() / 2.0f) * width2, (bitmap.getHeight() / 2.0f) * width2);
            canvas2.drawBitmap(bitmap, (Rect) null, rectF2, new Paint(3));
        }
        MaskPaintView maskPaintView = new MaskPaintView(this.parentActivity, this.currentAccount, createBitmap2, createBitmap, this.centerImage.getOrientation(), cropState2) {
            @Override
            public void onRenderViewAlphaUpdate(ValueAnimator animation) {
                super.onRenderViewAlphaUpdate(animation);
                PhotoViewer.this.containerView.invalidate();
            }

            @Override
            public void onDrawn() {
                PhotoViewer.this.showEditStickerMode(true, true);
            }
        };
        this.maskPaintView = maskPaintView;
        maskPaintView.cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PhotoViewer.this.lambda$createMaskPaintView$74(view);
            }
        });
        this.maskPaintView.doneButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PhotoViewer.this.lambda$createMaskPaintView$75(view);
            }
        });
        this.maskPaintView.setEraser(this.maskPaintViewEraser);
        int indexOfChild = this.containerView.indexOfChild(this.btnLayout) - 1;
        if (indexOfChild < 0) {
            indexOfChild = this.containerView.getChildCount();
        }
        this.containerView.addView(this.maskPaintView, indexOfChild, LayoutHelper.createFrame(-1, -1.0f));
        this.maskPaintViewShuttingDown = false;
    }

    public void lambda$createMaskPaintView$74(View view) {
        this.eraseBtn.setActive(false, true);
        this.restoreBtn.setActive(false, true);
        switchToEditMode(0);
    }

    public void lambda$createMaskPaintView$75(View view) {
        this.eraseBtn.setActive(false, true);
        this.restoreBtn.setActive(false, true);
        applyCurrentEditMode();
        switchToEditMode(0);
    }

    public final void createPaintView() {
        int bitmapWidth;
        int bitmapHeight;
        MediaController.CropState cropState;
        if (this.photoPaintView == null) {
            VideoEditTextureView videoEditTextureView = this.videoTextureView;
            if (videoEditTextureView != null) {
                VideoEditTextureView videoEditTextureView2 = videoEditTextureView;
                bitmapWidth = videoEditTextureView2.getVideoWidth();
                bitmapHeight = videoEditTextureView2.getVideoHeight();
                while (true) {
                    if (bitmapWidth <= 1280 && bitmapHeight <= 1280) {
                        break;
                    }
                    bitmapWidth /= 2;
                    bitmapHeight /= 2;
                }
            } else {
                bitmapWidth = this.centerImage.getBitmapWidth();
                bitmapHeight = this.centerImage.getBitmapHeight();
            }
            Bitmap bitmap = this.paintingOverlay.getBitmap();
            Bitmap createBitmap = bitmap == null ? Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888) : bitmap;
            if (this.sendPhotoType == 1) {
                cropState = new MediaController.CropState();
                cropState.transformRotation = this.cropTransform.getOrientation();
            } else {
                cropState = this.editState.cropState;
            }
            MediaController.CropState cropState2 = cropState;
            KeyboardNotifier keyboardNotifier = new KeyboardNotifier(this.windowView, new Utilities.Callback() {
                public final void run(Object obj) {
                    PhotoViewer.this.lambda$createPaintView$77((Integer) obj);
                }
            });
            this.paintKeyboardNotifier = keyboardNotifier;
            keyboardNotifier.ignore(this.currentEditMode != 3);
            Activity activity = this.parentActivity;
            LPhotoPaintView lPhotoPaintView = new LPhotoPaintView(activity, activity, this.currentAccount, createBitmap, this.isCurrentVideo ? null : this.centerImage.getBitmap(), this.centerImage.getOrientation(), this.editState.mediaEntities, cropState2, new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$createPaintView$78();
                }
            }, this.resourcesProvider) {
                @Override
                public void onOpenCloseStickersAlert(boolean open) {
                    if (PhotoViewer.this.videoPlayer == null) {
                        return;
                    }
                    PhotoViewer.this.manuallyPaused = false;
                    PhotoViewer.this.cancelVideoPlayRunnable();
                    if (open) {
                        PhotoViewer.this.videoPlayer.pause();
                    } else {
                        PhotoViewer.this.videoPlayer.play();
                    }
                }

                @Override
                public int getPKeyboardHeight() {
                    if (PhotoViewer.this.paintKeyboardNotifier != null) {
                        return PhotoViewer.this.paintKeyboardNotifier.getKeyboardHeight();
                    }
                    return 0;
                }

                @Override
                public void onEmojiViewCloseByClick() {
                    if (PhotoViewer.this.paintKeyboardNotifier != null) {
                        PhotoViewer.this.paintKeyboardNotifier.awaitKeyboard();
                    }
                }

                @Override
                public void updateKeyboard() {
                    if (PhotoViewer.this.paintKeyboardNotifier != null) {
                        PhotoViewer.this.paintKeyboardNotifier.fire();
                    }
                }

                @Override
                public void didSetAnimatedSticker(RLottieDrawable drawable) {
                    if (PhotoViewer.this.videoPlayer == null) {
                        return;
                    }
                    drawable.setProgressMs(PhotoViewer.this.videoPlayer.getCurrentPosition() - (PhotoViewer.this.startTime > 0 ? PhotoViewer.this.startTime / 1000 : 0L));
                }

                @Override
                public void onTextAdd() {
                    PhotoViewer.this.windowView.isFocusable();
                }
            };
            this.photoPaintView = lPhotoPaintView;
            this.containerView.addView(lPhotoPaintView.getView(), LayoutHelper.createFrame(-1, -1.0f));
            this.photoPaintView.setOnDoneButtonClickedListener(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$createPaintView$79();
                }
            });
            this.photoPaintView.getCancelView().setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PhotoViewer.this.lambda$createPaintView$80(view);
                }
            });
            this.photoPaintView.setOffsetTranslationY(AndroidUtilities.dp(126.0f), 0.0f, 0, false);
            this.photoPaintView.setOffsetTranslationX(-AndroidUtilities.dp(12.0f));
        }
    }

    public void lambda$createPaintView$77(Integer num) {
        this.photoPaintView.keyboardVisible = this.paintKeyboardNotifier.keyboardVisible();
        this.containerView.invalidate();
        Integer valueOf = Integer.valueOf(Math.max(num.intValue(), this.photoPaintView.getEmojiPadding(false)));
        translateY((!this.photoPaintView.isCurrentText() || valueOf.intValue() <= 0) ? 0.0f : ((AndroidUtilities.displaySize.y - valueOf.intValue()) - AndroidUtilities.dp(80.0f)) - this.photoPaintView.getSelectedEntityBottom());
        AnimatorSet animatorSet = this.paintKeyboardAnimator;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        ValueAnimator ofFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                PhotoViewer.this.lambda$createPaintView$76(valueAnimator);
            }
        });
        AnimatorSet animatorSet2 = new AnimatorSet();
        this.paintKeyboardAnimator = animatorSet2;
        Animator[] animatorArr = new Animator[6];
        animatorArr[0] = ObjectAnimator.ofFloat(this.photoPaintView.weightChooserView, (Property<PaintWeightChooserView, Float>) View.TRANSLATION_Y, (-valueOf.intValue()) / 2.5f);
        animatorArr[1] = ObjectAnimator.ofFloat(this.photoPaintView.bottomLayout, (Property<FrameLayout, Float>) View.TRANSLATION_Y, Math.min(0, (-valueOf.intValue()) + AndroidUtilities.dp(40.0f)));
        LinearLayout linearLayout = this.photoPaintView.tabsLayout;
        Property property = View.ALPHA;
        float[] fArr = new float[1];
        fArr[0] = valueOf.intValue() > AndroidUtilities.dp(20.0f) ? 0.0f : 1.0f;
        animatorArr[2] = ObjectAnimator.ofFloat(linearLayout, (Property<LinearLayout, Float>) property, fArr);
        PaintCancelView paintCancelView = this.photoPaintView.cancelButton;
        Property property2 = View.ALPHA;
        float[] fArr2 = new float[1];
        fArr2[0] = valueOf.intValue() > AndroidUtilities.dp(20.0f) ? 0.0f : 1.0f;
        animatorArr[3] = ObjectAnimator.ofFloat(paintCancelView, (Property<PaintCancelView, Float>) property2, fArr2);
        PaintDoneView paintDoneView = this.photoPaintView.doneButton;
        Property property3 = View.ALPHA;
        float[] fArr3 = new float[1];
        fArr3[0] = valueOf.intValue() <= AndroidUtilities.dp(20.0f) ? 1.0f : 0.0f;
        animatorArr[4] = ObjectAnimator.ofFloat(paintDoneView, (Property<PaintDoneView, Float>) property3, fArr3);
        animatorArr[5] = ofFloat;
        animatorSet2.playTogether(animatorArr);
        animatorSet2.setDuration(320L);
        animatorSet2.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
        animatorSet2.start();
        this.photoPaintView.updatePlusEmojiKeyboardButton();
    }

    public void lambda$createPaintView$76(ValueAnimator valueAnimator) {
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.overlayLayout.invalidate();
        }
    }

    public void lambda$createPaintView$78() {
        this.paintingOverlay.hideBitmap();
    }

    public void lambda$createPaintView$79() {
        this.savedState = null;
        applyCurrentEditMode();
        switchToEditMode(0);
    }

    public void lambda$createPaintView$80(View view) {
        closePaintMode();
    }

    public final void translateY(float ty) {
        ValueAnimator valueAnimator = this.translateYAnimator;
        if (valueAnimator != null) {
            valueAnimator.cancel();
            this.translateYAnimator = null;
        }
        if (this.currentEditMode != 3) {
            ty = 0.0f;
        }
        ValueAnimator ofFloat = ValueAnimator.ofFloat(this.translateY, ty);
        this.translateYAnimator = ofFloat;
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator2) {
                PhotoViewer.this.lambda$translateY$81(valueAnimator2);
            }
        });
        this.translateYAnimator.setDuration(320L);
        this.translateYAnimator.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
        this.translateYAnimator.start();
    }

    public void lambda$translateY$81(ValueAnimator valueAnimator) {
        float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
        this.translateY = floatValue;
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.translateY(floatValue);
        }
        this.containerView.invalidate();
    }

    public void lambda$closePaintMode$82() {
        switchToEditMode(0);
    }

    public final void closePaintMode() {
        this.photoPaintView.maybeShowDismissalAlert(this, this.parentActivity, new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$closePaintMode$82();
            }
        });
    }

    public final void switchToPaintMode() {
        EditState editState;
        this.changeModeAnimation = null;
        this.pickerView.setVisibility(8);
        this.pickerViewSendButton.setVisibility(8);
        this.doneButtonFullWidth.setVisibility(8);
        this.muteItem.setVisibility(8);
        PhotoCropView photoCropView = this.photoCropView;
        if (photoCropView != null) {
            photoCropView.setVisibility(4);
        }
        this.selectedPhotosListView.setVisibility(8);
        this.selectedPhotosListView.setAlpha(0.0f);
        this.selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10.0f));
        this.photosCounterView.setRotationX(0.0f);
        this.selectedPhotosListView.setEnabled(false);
        this.isPhotosListViewVisible = false;
        if (this.needCaptionLayout) {
            this.captionTextViewSwitcher.setVisibility(4);
        }
        int i = this.sendPhotoType;
        if (i == 0 || i == 4 || ((i == 2 || i == 5) && this.imagesArrLocals.size() > 1)) {
            this.checkImageView.setVisibility(8);
            this.photosCounterView.setVisibility(8);
            updateActionBarTitlePadding();
        }
        showEditCaption(false, true);
        showStickerMode(false, false, true);
        this.photoQualityLayout.setVisibility(8);
        Bitmap bitmap = this.centerImage.getBitmap();
        float f = this.scale;
        if (this.sendPhotoType == 11) {
            this.savedTy = this.translationY;
            this.savedTx = this.translationX;
            this.savedScale = f;
            this.savedRotation = this.rotate;
            this.animateToRotate = 0.0f;
        }
        if (bitmap != null) {
            int bitmapWidth = this.centerImage.getBitmapWidth();
            int bitmapHeight = this.centerImage.getBitmapHeight();
            if (this.sendPhotoType == 1) {
                float dp = AndroidUtilities.dp(12.0f);
                this.animateToY = dp;
                if (this.photoPaintView != null) {
                    this.animateToY = dp + (r15.getAdditionalTop() / 2.0f);
                }
                if (this.cropTransform.getOrientation() == 90 || this.cropTransform.getOrientation() == 270) {
                    bitmapHeight = bitmapWidth;
                    bitmapWidth = bitmapHeight;
                }
            } else {
                float f2 = (-AndroidUtilities.dp(44.0f)) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight / 2 : 0);
                this.animateToY = f2;
                if (this.photoPaintView != null) {
                    float additionalTop = f2 + (r15.getAdditionalTop() / 2.0f);
                    this.animateToY = additionalTop;
                    this.animateToY = additionalTop - (this.photoPaintView.getAdditionalBottom() / 2.0f);
                }
                MediaController.CropState cropState = this.editState.cropState;
                if (cropState != null) {
                    int i2 = cropState.transformRotation;
                    if (i2 == 90 || i2 == 270) {
                        bitmapHeight = bitmapWidth;
                        bitmapWidth = bitmapHeight;
                    }
                    bitmapWidth = (int) (bitmapWidth * cropState.cropPw);
                    bitmapHeight = (int) (bitmapHeight * cropState.cropPh);
                }
            }
            float f3 = bitmapWidth;
            float f4 = bitmapHeight;
            this.animateToScale = (Math.min(getContainerViewWidth(3) / f3, getContainerViewHeight(3) / f4) / Math.min(getContainerViewWidth() / f3, getContainerViewHeight() / f4)) * scale1(false);
            this.animateToX = (getLeftInset() / 2) - (getRightInset() / 2);
            this.animationStartTime = System.currentTimeMillis();
            this.zoomAnimation = true;
        }
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.setDrawShadow(this.sendPhotoType == 11 && ((editState = this.editState) == null || editState.cropState == null));
        }
        this.windowView.setClipChildren(true);
        this.navigationBar.setVisibility(4);
        this.imageMoveAnimation = new AnimatorSet();
        ValueAnimator ofFloat = ValueAnimator.ofFloat(AndroidUtilities.dp(126.0f), 0.0f);
        ValueAnimator ofFloat2 = ValueAnimator.ofFloat(-AndroidUtilities.dp(12.0f), 0.0f);
        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                PhotoViewer.this.lambda$switchToPaintMode$83(valueAnimator);
            }
        });
        ofFloat2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                PhotoViewer.this.lambda$switchToPaintMode$84(valueAnimator);
            }
        });
        this.imageMoveAnimation.playTogether(ObjectAnimator.ofFloat(this, (Property<PhotoViewer, Float>) AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0.0f, 1.0f), ofFloat, ofFloat2);
        this.photoPaintView.onAnimationStateChanged(true);
        this.imageMoveAnimation.setDuration(200L);
        this.imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                PhotoViewer.this.photoPaintView.onAnimationStateChanged(false);
                PhotoViewer.this.photoPaintView.init();
                PhotoViewer.this.paintingOverlay.hideEntities();
                PhotoViewer.this.imageMoveAnimation = null;
                PhotoViewer.this.currentEditMode = 3;
                ((CaptionContainerView) PhotoViewer.this.captionEdit).keyboardNotifier.ignore(PhotoViewer.this.currentEditMode != 0);
                if (PhotoViewer.this.paintKeyboardNotifier != null) {
                    PhotoViewer.this.paintKeyboardNotifier.ignore(PhotoViewer.this.currentEditMode != 3);
                }
                PhotoViewer.this.switchingToMode = -1;
                PhotoViewer photoViewer = PhotoViewer.this;
                float scale1 = photoViewer.scale1(false);
                photoViewer.scale = scale1;
                photoViewer.animateToScale = scale1;
                PhotoViewer.this.animateToX = 0.0f;
                PhotoViewer.this.animateToY = 0.0f;
                PhotoViewer photoViewer2 = PhotoViewer.this;
                photoViewer2.updateMinMax(photoViewer2.scale);
                PhotoViewer.this.padImageForHorizontalInsets = true;
                PhotoViewer.this.containerView.invalidate();
                if (PhotoViewer.this.placeProvider == null || !PhotoViewer.this.placeProvider.closeKeyboard()) {
                    PhotoViewer.this.makeFocusable();
                }
            }
        });
        this.imageMoveAnimation.start();
    }

    public void lambda$switchToPaintMode$83(ValueAnimator valueAnimator) {
        this.photoPaintView.setOffsetTranslationY(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f, 0, false);
    }

    public void lambda$switchToPaintMode$84(ValueAnimator valueAnimator) {
        this.photoPaintView.setOffsetTranslationX(((Float) valueAnimator.getAnimatedValue()).floatValue());
    }

    public final void toggleCheckImageView(boolean show) {
        AnimatorSet animatorSet = new AnimatorSet();
        ArrayList arrayList = new ArrayList();
        float dpf2 = AndroidUtilities.dpf2(24.0f);
        FrameLayout frameLayout = this.pickerView;
        Property property = View.ALPHA;
        float[] fArr = new float[1];
        fArr[0] = show ? 1.0f : 0.0f;
        arrayList.add(ObjectAnimator.ofFloat(frameLayout, (Property<FrameLayout, Float>) property, fArr));
        FrameLayout frameLayout2 = this.pickerView;
        Property property2 = View.TRANSLATION_Y;
        float[] fArr2 = new float[1];
        fArr2[0] = show ? 0.0f : dpf2;
        arrayList.add(ObjectAnimator.ofFloat(frameLayout2, (Property<FrameLayout, Float>) property2, fArr2));
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView != null) {
            Property property3 = View.ALPHA;
            float[] fArr3 = new float[1];
            fArr3[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(stickerMakerView, (Property<StickerMakerView, Float>) property3, fArr3));
        }
        if (this.stickerMakerView != null) {
            StickerMakerBackgroundView stickerMakerBackgroundView = this.stickerMakerBackgroundView;
            Property property4 = View.ALPHA;
            float[] fArr4 = new float[1];
            fArr4[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(stickerMakerBackgroundView, (Property<StickerMakerBackgroundView, Float>) property4, fArr4));
        }
        ImageView imageView = this.pickerViewSendButton;
        Property property5 = View.ALPHA;
        float[] fArr5 = new float[1];
        fArr5[0] = show ? 1.0f : 0.0f;
        arrayList.add(ObjectAnimator.ofFloat(imageView, (Property<ImageView, Float>) property5, fArr5));
        ImageView imageView2 = this.pickerViewSendButton;
        Property property6 = View.TRANSLATION_Y;
        float[] fArr6 = new float[1];
        fArr6[0] = show ? 0.0f : dpf2;
        arrayList.add(ObjectAnimator.ofFloat(imageView2, (Property<ImageView, Float>) property6, fArr6));
        int i = this.sendPhotoType;
        if (i == 0 || i == 4) {
            CheckBox checkBox = this.checkImageView;
            Property property7 = View.ALPHA;
            float[] fArr7 = new float[1];
            fArr7[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(checkBox, (Property<CheckBox, Float>) property7, fArr7));
            CheckBox checkBox2 = this.checkImageView;
            Property property8 = View.TRANSLATION_Y;
            float[] fArr8 = new float[1];
            fArr8[0] = show ? 0.0f : -dpf2;
            arrayList.add(ObjectAnimator.ofFloat(checkBox2, (Property<CheckBox, Float>) property8, fArr8));
            CounterView counterView = this.photosCounterView;
            Property property9 = View.ALPHA;
            float[] fArr9 = new float[1];
            fArr9[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(counterView, (Property<CounterView, Float>) property9, fArr9));
            CounterView counterView2 = this.photosCounterView;
            Property property10 = View.TRANSLATION_Y;
            float[] fArr10 = new float[1];
            fArr10[0] = show ? 0.0f : -dpf2;
            arrayList.add(ObjectAnimator.ofFloat(counterView2, (Property<CounterView, Float>) property10, fArr10));
        }
        FrameLayout frameLayout3 = this.photoQualityLayout;
        Property property11 = View.ALPHA;
        float[] fArr11 = new float[1];
        fArr11[0] = show ? 1.0f : 0.0f;
        arrayList.add(ObjectAnimator.ofFloat(frameLayout3, (Property<FrameLayout, Float>) property11, fArr11));
        animatorSet.playTogether(arrayList);
        animatorSet.setDuration(200L);
        animatorSet.start();
        if (show || !isCaptionOpen()) {
            return;
        }
        if (((CaptionContainerView) this.captionEdit).editText.isPopupShowing()) {
            ((CaptionContainerView) this.captionEdit).editText.hidePopup(true);
        }
        ((CaptionContainerView) this.captionEdit).editText.closeKeyboard();
    }

    public final void toggleMiniProgressInternal(final boolean show) {
        if (show) {
            this.miniProgressView.setVisibility(0);
        }
        AnimatorSet animatorSet = new AnimatorSet();
        this.miniProgressAnimator = animatorSet;
        Animator[] animatorArr = new Animator[1];
        RadialProgressView radialProgressView = this.miniProgressView;
        Property property = View.ALPHA;
        float[] fArr = new float[1];
        fArr[0] = show ? 1.0f : 0.0f;
        animatorArr[0] = ObjectAnimator.ofFloat(radialProgressView, (Property<RadialProgressView, Float>) property, fArr);
        animatorSet.playTogether(animatorArr);
        this.miniProgressAnimator.setDuration(200L);
        this.miniProgressAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (animation.equals(PhotoViewer.this.miniProgressAnimator)) {
                    if (!show) {
                        PhotoViewer.this.miniProgressView.setVisibility(4);
                    }
                    PhotoViewer.this.miniProgressAnimator = null;
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (animation.equals(PhotoViewer.this.miniProgressAnimator)) {
                    PhotoViewer.this.miniProgressAnimator = null;
                }
            }
        });
        this.miniProgressAnimator.start();
    }

    public final void toggleMiniProgress(final boolean show, final boolean animated) {
        AndroidUtilities.cancelRunOnUIThread(this.miniProgressShowRunnable);
        if (animated) {
            toggleMiniProgressInternal(show);
            if (show) {
                AnimatorSet animatorSet = this.miniProgressAnimator;
                if (animatorSet != null) {
                    animatorSet.cancel();
                    this.miniProgressAnimator = null;
                }
                if (this.firstAnimationDelay) {
                    this.firstAnimationDelay = false;
                    toggleMiniProgressInternal(true);
                    return;
                } else {
                    AndroidUtilities.runOnUIThread(this.miniProgressShowRunnable, 500L);
                    return;
                }
            }
            AnimatorSet animatorSet2 = this.miniProgressAnimator;
            if (animatorSet2 != null) {
                animatorSet2.cancel();
                toggleMiniProgressInternal(false);
                return;
            }
            return;
        }
        AnimatorSet animatorSet3 = this.miniProgressAnimator;
        if (animatorSet3 != null) {
            animatorSet3.cancel();
            this.miniProgressAnimator = null;
        }
        this.miniProgressView.setAlpha(show ? 1.0f : 0.0f);
        this.miniProgressView.setVisibility(show ? 0 : 4);
    }

    public final void updateContainerFlags(boolean actionBarVisible) {
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto;
        if (Build.VERSION.SDK_INT < 21 || this.sendPhotoType == 1 || (sizeNotifierFrameLayoutPhoto = this.containerView) == null) {
            return;
        }
        int i = 1792;
        if (!actionBarVisible) {
            i = 1796;
            if (sizeNotifierFrameLayoutPhoto.getPaddingLeft() > 0 || this.containerView.getPaddingRight() > 0) {
                i = 5894;
            }
        }
        this.containerView.setSystemUiVisibility(i);
    }

    public static class ActionBarToggleParams {
        public static final ActionBarToggleParams DEFAULT = new ActionBarToggleParams();
        public Interpolator animationInterpolator;
        public int animationDuration = 200;
        public boolean enableStatusBarAnimation = true;
        public boolean enableTranslationAnimation = true;

        public ActionBarToggleParams enableStatusBarAnimation(boolean val) {
            this.enableStatusBarAnimation = val;
            return this;
        }

        public ActionBarToggleParams enableTranslationAnimation(boolean val) {
            this.enableTranslationAnimation = val;
            return this;
        }

        public ActionBarToggleParams animationDuration(int val) {
            this.animationDuration = val;
            return this;
        }

        public ActionBarToggleParams animationInterpolator(Interpolator val) {
            this.animationInterpolator = val;
            return this;
        }
    }

    public final void toggleActionBar(final boolean show, final boolean animated) {
        toggleActionBar(show, animated, ActionBarToggleParams.DEFAULT);
    }

    public final void toggleActionBar(final boolean show, final boolean animated, final ActionBarToggleParams params) {
        NestedScrollView nestedScrollView;
        CaptionScrollView captionScrollView;
        if (this.currentEditMode == 0) {
            int i = this.switchingToMode;
            if (i == 0 || i == -1) {
                AnimatorSet animatorSet = this.actionBarAnimator;
                if (animatorSet != null) {
                    animatorSet.cancel();
                }
                if (show) {
                    this.actionBar.setVisibility(0);
                    if (this.bottomLayout.getTag() != null) {
                        this.bottomLayout.setVisibility(0);
                    }
                    if (this.captionTextViewSwitcher.getTag() != null) {
                        this.captionTextViewSwitcher.setVisibility(0);
                        VideoSeekPreviewImage videoSeekPreviewImage = this.videoPreviewFrame;
                        if (videoSeekPreviewImage != null) {
                            videoSeekPreviewImage.requestLayout();
                        }
                    }
                }
                this.isActionBarVisible = show;
                PhotoViewerWebView photoViewerWebView = this.photoViewerWebView;
                if (photoViewerWebView != null) {
                    photoViewerWebView.setTouchDisabled(show);
                }
                if (params.enableStatusBarAnimation) {
                    updateContainerFlags(show);
                }
                if (this.videoPlayerControlVisible && this.isPlaying && show) {
                    scheduleActionBarHide();
                } else {
                    AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
                }
                if (!show) {
                    Bulletin.hide(this.containerView);
                }
                float dpf2 = AndroidUtilities.dpf2(24.0f);
                this.videoPlayerControlFrameLayout.setSeekBarTransitionEnabled(params.enableTranslationAnimation && this.playerLooping);
                this.videoPlayerControlFrameLayout.setTranslationYAnimationEnabled(params.enableTranslationAnimation);
                if (animated) {
                    ArrayList arrayList = new ArrayList();
                    ActionBar actionBar = this.actionBar;
                    Property property = View.ALPHA;
                    float[] fArr = new float[1];
                    fArr[0] = show ? 1.0f : 0.0f;
                    arrayList.add(ObjectAnimator.ofFloat(actionBar, (Property<ActionBar, Float>) property, fArr));
                    if (params.enableTranslationAnimation) {
                        ActionBar actionBar2 = this.actionBar;
                        Property property2 = View.TRANSLATION_Y;
                        float[] fArr2 = new float[1];
                        fArr2[0] = show ? 0.0f : -dpf2;
                        arrayList.add(ObjectAnimator.ofFloat(actionBar2, (Property<ActionBar, Float>) property2, fArr2));
                    } else {
                        this.actionBar.setTranslationY(0.0f);
                    }
                    if (this.allowShowFullscreenButton) {
                        ImageView imageView = this.fullscreenButton[0];
                        Property property3 = View.ALPHA;
                        float[] fArr3 = new float[1];
                        fArr3[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(imageView, (Property<ImageView, Float>) property3, fArr3));
                    }
                    for (int i2 = 1; i2 < 3; i2++) {
                        this.fullscreenButton[i2].setTranslationY(show ? 0.0f : dpf2);
                    }
                    if (params.enableTranslationAnimation) {
                        ImageView imageView2 = this.fullscreenButton[0];
                        Property property4 = View.TRANSLATION_Y;
                        float[] fArr4 = new float[1];
                        fArr4[0] = show ? 0.0f : dpf2;
                        arrayList.add(ObjectAnimator.ofFloat(imageView2, (Property<ImageView, Float>) property4, fArr4));
                    } else {
                        this.fullscreenButton[0].setTranslationY(0.0f);
                    }
                    FrameLayout frameLayout = this.bottomLayout;
                    if (frameLayout != null) {
                        Property property5 = View.ALPHA;
                        float[] fArr5 = new float[1];
                        fArr5[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(frameLayout, (Property<FrameLayout, Float>) property5, fArr5));
                        if (params.enableTranslationAnimation) {
                            FrameLayout frameLayout2 = this.bottomLayout;
                            Property property6 = View.TRANSLATION_Y;
                            float[] fArr6 = new float[1];
                            fArr6[0] = show ? 0.0f : dpf2;
                            arrayList.add(ObjectAnimator.ofFloat(frameLayout2, (Property<FrameLayout, Float>) property6, fArr6));
                        } else {
                            this.bottomLayout.setTranslationY(0.0f);
                        }
                    }
                    PhotoCountView photoCountView = this.countView;
                    if (photoCountView != null) {
                        Property property7 = View.ALPHA;
                        float[] fArr7 = new float[1];
                        fArr7[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(photoCountView, (Property<PhotoCountView, Float>) property7, fArr7));
                        if (params.enableTranslationAnimation) {
                            PhotoCountView photoCountView2 = this.countView;
                            Property property8 = View.TRANSLATION_Y;
                            float[] fArr8 = new float[1];
                            fArr8[0] = show ? 0.0f : -dpf2;
                            arrayList.add(ObjectAnimator.ofFloat(photoCountView2, (Property<PhotoCountView, Float>) property8, fArr8));
                        } else {
                            this.countView.setTranslationY(0.0f);
                        }
                    }
                    View view = this.navigationBar;
                    if (view != null) {
                        Property property9 = View.ALPHA;
                        float[] fArr9 = new float[1];
                        fArr9[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(view, (Property<View, Float>) property9, fArr9));
                    }
                    if (this.videoPlayerControlVisible) {
                        VideoPlayerControlFrameLayout videoPlayerControlFrameLayout = this.videoPlayerControlFrameLayout;
                        Property<VideoPlayerControlFrameLayout, Float> property10 = VPC_PROGRESS;
                        float[] fArr10 = new float[1];
                        fArr10[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(videoPlayerControlFrameLayout, property10, fArr10));
                    } else {
                        this.videoPlayerControlFrameLayout.setProgress(show ? 1.0f : 0.0f);
                    }
                    GroupedPhotosListView groupedPhotosListView = this.groupedPhotosListView;
                    Property property11 = View.ALPHA;
                    float[] fArr11 = new float[1];
                    fArr11[0] = show ? 1.0f : 0.0f;
                    arrayList.add(ObjectAnimator.ofFloat(groupedPhotosListView, (Property<GroupedPhotosListView, Float>) property11, fArr11));
                    if (params.enableTranslationAnimation) {
                        GroupedPhotosListView groupedPhotosListView2 = this.groupedPhotosListView;
                        Property property12 = View.TRANSLATION_Y;
                        float[] fArr12 = new float[1];
                        fArr12[0] = show ? 0.0f : dpf2;
                        arrayList.add(ObjectAnimator.ofFloat(groupedPhotosListView2, (Property<GroupedPhotosListView, Float>) property12, fArr12));
                    } else {
                        this.groupedPhotosListView.setTranslationY(0.0f);
                    }
                    if (!this.needCaptionLayout && (captionScrollView = this.captionScrollView) != null) {
                        Property property13 = View.ALPHA;
                        float[] fArr13 = new float[1];
                        fArr13[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(captionScrollView, (Property<CaptionScrollView, Float>) property13, fArr13));
                        if (params.enableTranslationAnimation) {
                            CaptionScrollView captionScrollView2 = this.captionScrollView;
                            Property property14 = View.TRANSLATION_Y;
                            float[] fArr14 = new float[1];
                            if (show) {
                                dpf2 = 0.0f;
                            }
                            fArr14[0] = dpf2;
                            arrayList.add(ObjectAnimator.ofFloat(captionScrollView2, (Property<CaptionScrollView, Float>) property14, fArr14));
                        } else {
                            this.captionScrollView.setTranslationY(0.0f);
                        }
                    }
                    if (this.videoPlayerControlVisible && this.isPlaying) {
                        float[] fArr15 = new float[2];
                        fArr15[0] = this.photoProgressViews[0].animAlphas[1];
                        fArr15[1] = show ? 1.0f : 0.0f;
                        ValueAnimator ofFloat = ValueAnimator.ofFloat(fArr15);
                        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                                PhotoViewer.this.lambda$toggleActionBar$85(valueAnimator);
                            }
                        });
                        arrayList.add(ofFloat);
                    }
                    if (this.muteItem.getTag() != null) {
                        ImageView imageView3 = this.muteItem;
                        Property property15 = View.ALPHA;
                        float[] fArr16 = new float[1];
                        fArr16[0] = show ? 1.0f : 0.0f;
                        arrayList.add(ObjectAnimator.ofFloat(imageView3, (Property<ImageView, Float>) property15, fArr16));
                    }
                    AnimatorSet animatorSet2 = new AnimatorSet();
                    this.actionBarAnimator = animatorSet2;
                    animatorSet2.playTogether(arrayList);
                    this.actionBarAnimator.setDuration(params.animationDuration);
                    this.actionBarAnimator.setInterpolator(params.animationInterpolator);
                    this.actionBarAnimator.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (animation.equals(PhotoViewer.this.actionBarAnimator)) {
                                if (!show) {
                                    PhotoViewer.this.actionBar.setVisibility(4);
                                    if (PhotoViewer.this.bottomLayout.getTag() != null) {
                                        PhotoViewer.this.bottomLayout.setVisibility(4);
                                    }
                                    if (PhotoViewer.this.captionTextViewSwitcher.getTag() != null) {
                                        PhotoViewer.this.captionTextViewSwitcher.setVisibility(4);
                                    }
                                }
                                PhotoViewer.this.actionBarAnimator = null;
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            if (animation.equals(PhotoViewer.this.actionBarAnimator)) {
                                PhotoViewer.this.actionBarAnimator = null;
                            }
                        }
                    });
                    this.actionBarAnimator.start();
                    return;
                }
                this.actionBar.setAlpha(show ? 1.0f : 0.0f);
                if (this.fullscreenButton[0].getTranslationX() != 0.0f && this.allowShowFullscreenButton) {
                    this.fullscreenButton[0].setAlpha(show ? 1.0f : 0.0f);
                }
                for (int i3 = 0; i3 < 3; i3++) {
                    this.fullscreenButton[i3].setTranslationY(show ? 0.0f : dpf2);
                }
                this.actionBar.setTranslationY(show ? 0.0f : -dpf2);
                PhotoCountView photoCountView3 = this.countView;
                if (photoCountView3 != null) {
                    photoCountView3.setAlpha(show ? 1.0f : 0.0f);
                    this.countView.setTranslationY(show ? 0.0f : -dpf2);
                }
                this.bottomLayout.setAlpha(show ? 1.0f : 0.0f);
                this.bottomLayout.setTranslationY(show ? 0.0f : dpf2);
                this.navigationBar.setAlpha(show ? 1.0f : 0.0f);
                this.groupedPhotosListView.setAlpha((!show || this.aboutToSwitchTo == 3) ? 0.0f : 1.0f);
                this.groupedPhotosListView.setTranslationY((!show || this.aboutToSwitchTo == 3) ? dpf2 : 0.0f);
                if (!this.needCaptionLayout && (nestedScrollView = this.captionScrollView) != null) {
                    nestedScrollView.setAlpha(show ? 1.0f : 0.0f);
                    NestedScrollView nestedScrollView2 = this.captionScrollView;
                    if (show) {
                        dpf2 = 0.0f;
                    }
                    nestedScrollView2.setTranslationY(dpf2);
                }
                this.videoPlayerControlFrameLayout.setProgress(show ? 1.0f : 0.0f);
                if (this.muteItem.getTag() != null) {
                    this.muteItem.setAlpha(show ? 1.0f : 0.0f);
                }
                if (this.videoPlayerControlVisible && this.isPlaying) {
                    this.photoProgressViews[0].setIndexedAlpha(1, show ? 1.0f : 0.0f, false);
                }
            }
        }
    }

    public void lambda$toggleActionBar$85(ValueAnimator valueAnimator) {
        this.photoProgressViews[0].setIndexedAlpha(1, ((Float) valueAnimator.getAnimatedValue()).floatValue(), false);
    }

    public final void togglePhotosListView(boolean show, final boolean animated) {
        if (show == this.isPhotosListViewVisible) {
            return;
        }
        if (show) {
            this.selectedPhotosListView.setVisibility(0);
        }
        this.isPhotosListViewVisible = show;
        this.selectedPhotosListView.setEnabled(show);
        if (animated) {
            ArrayList arrayList = new ArrayList();
            SelectedPhotosListView selectedPhotosListView = this.selectedPhotosListView;
            Property property = View.ALPHA;
            float[] fArr = new float[1];
            fArr[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, (Property<SelectedPhotosListView, Float>) property, fArr));
            SelectedPhotosListView selectedPhotosListView2 = this.selectedPhotosListView;
            Property property2 = View.TRANSLATION_Y;
            float[] fArr2 = new float[1];
            fArr2[0] = show ? 0.0f : -AndroidUtilities.dp(10.0f);
            arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView2, (Property<SelectedPhotosListView, Float>) property2, fArr2));
            CounterView counterView = this.photosCounterView;
            Property property3 = View.ROTATION_X;
            float[] fArr3 = new float[1];
            fArr3[0] = show ? 1.0f : 0.0f;
            arrayList.add(ObjectAnimator.ofFloat(counterView, (Property<CounterView, Float>) property3, fArr3));
            AnimatorSet animatorSet = new AnimatorSet();
            this.currentListViewAnimation = animatorSet;
            animatorSet.playTogether(arrayList);
            if (!show) {
                this.currentListViewAnimation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (PhotoViewer.this.currentListViewAnimation == null || !PhotoViewer.this.currentListViewAnimation.equals(animation)) {
                            return;
                        }
                        PhotoViewer.this.selectedPhotosListView.setVisibility(8);
                        PhotoViewer.this.currentListViewAnimation = null;
                    }
                });
            }
            this.currentListViewAnimation.setDuration(200L);
            this.currentListViewAnimation.start();
            return;
        }
        this.selectedPhotosListView.setAlpha(show ? 1.0f : 0.0f);
        this.selectedPhotosListView.setTranslationY(show ? 0.0f : -AndroidUtilities.dp(10.0f));
        this.photosCounterView.setRotationX(show ? 1.0f : 0.0f);
        if (show) {
            return;
        }
        this.selectedPhotosListView.setVisibility(8);
    }

    public final void toggleVideoPlayer() {
        VideoPlayer videoPlayer;
        VideoPlayer videoPlayer2;
        PhotoViewerWebView photoViewerWebView;
        if (this.videoPlayer != null || ((photoViewerWebView = this.photoViewerWebView) != null && photoViewerWebView.isControllable())) {
            boolean isPlaying = this.videoPlayer != null ? this.isPlaying : this.photoViewerWebView.isPlaying();
            cancelVideoPlayRunnable();
            AndroidUtilities.cancelRunOnUIThread(this.hideActionBarRunnable);
            if (isPlaying) {
                pauseVideoOrWeb();
            } else {
                if (!this.isCurrentVideo) {
                    if (Math.abs(this.videoPlayerSeekbar.getProgress() - this.videoTimelineView.getRightProgress()) < 0.01f || ((videoPlayer = this.videoPlayer) != null && videoPlayer.getCurrentPosition() == this.videoPlayer.getDuration())) {
                        seekVideoOrWebToProgress(0.0f);
                    }
                    scheduleActionBarHide();
                } else if (Math.abs(this.videoTimelineView.getProgress() - this.videoTimelineView.getRightProgress()) < 0.01f || ((videoPlayer2 = this.videoPlayer) != null && videoPlayer2.getCurrentPosition() == this.videoPlayer.getDuration())) {
                    seekVideoOrWebToProgress(this.videoTimelineView.getLeftProgress());
                }
                playVideoOrWeb();
            }
            this.containerView.invalidate();
        }
    }

    public final String getFileName(int index) {
        if (index < 0) {
            return null;
        }
        if (!this.secureDocuments.isEmpty()) {
            if (index >= this.secureDocuments.size()) {
                return null;
            }
            SecureDocument secureDocument = this.secureDocuments.get(index);
            return secureDocument.secureFile.dc_id + "_" + secureDocument.secureFile.id + ".jpg";
        }
        if (!this.imagesArrLocations.isEmpty() || !this.imagesArr.isEmpty()) {
            if (!this.imagesArrLocations.isEmpty()) {
                if (index >= this.imagesArrLocations.size()) {
                    return null;
                }
                ImageLocation imageLocation = this.imagesArrLocations.get(index);
                ImageLocation imageLocation2 = this.imagesArrLocationsVideo.get(index);
                if (imageLocation == null) {
                    return null;
                }
                if (imageLocation2 != null && imageLocation2 != imageLocation) {
                    return ((TLRPC.FileLocation) imageLocation2.location).volume_id + "_" + ((TLRPC.FileLocation) imageLocation2.location).local_id + ".mp4";
                }
                return ((TLRPC.FileLocation) imageLocation.location).volume_id + "_" + ((TLRPC.FileLocation) imageLocation.location).local_id + ".jpg";
            }
            if (index >= this.imagesArr.size()) {
                return null;
            }
            return FileLoader.getMessageFileName(this.imagesArr.get(index).messageOwner);
        }
        if (!this.imagesArrLocals.isEmpty()) {
            if (index >= this.imagesArrLocals.size()) {
                return null;
            }
            Object obj = this.imagesArrLocals.get(index);
            if (obj instanceof MediaController.SearchImage) {
                return ((MediaController.SearchImage) obj).getAttachName();
            }
            if (obj instanceof TLRPC.BotInlineResult) {
                TLRPC.BotInlineResult botInlineResult = (TLRPC.BotInlineResult) obj;
                TLRPC.Document document = botInlineResult.document;
                if (document != null) {
                    return FileLoader.getAttachFileName(document);
                }
                TLRPC.Photo photo = botInlineResult.photo;
                if (photo != null) {
                    return FileLoader.getAttachFileName(FileLoader.getClosestPhotoSizeWithSize(photo.sizes, AndroidUtilities.getPhotoSize()));
                }
                if (botInlineResult.content instanceof TLRPC.TL_webDocument) {
                    StringBuilder sb = new StringBuilder();
                    sb.append(Utilities.MD5(botInlineResult.content.url));
                    sb.append(".");
                    TLRPC.WebDocument webDocument = botInlineResult.content;
                    sb.append(ImageLoader.getHttpUrlExtension(webDocument.url, FileLoader.getMimeTypePart(webDocument.mime_type)));
                    return sb.toString();
                }
            }
        } else {
            PageBlocksAdapter pageBlocksAdapter = this.pageBlocksAdapter;
            if (pageBlocksAdapter != null) {
                return pageBlocksAdapter.getFileName(index);
            }
        }
        return null;
    }

    public final ImageLocation getImageLocation(int index, long[] size) {
        if (index < 0) {
            return null;
        }
        if (!this.secureDocuments.isEmpty()) {
            if (index >= this.secureDocuments.size()) {
                return null;
            }
            if (size != null) {
                size[0] = this.secureDocuments.get(index).secureFile.size;
            }
            return ImageLocation.getForSecureDocument(this.secureDocuments.get(index));
        }
        if (!this.imagesArrLocations.isEmpty()) {
            if (index >= this.imagesArrLocations.size()) {
                return null;
            }
            if (size != null && this.imagesArrLocationsSizes.get(index) != null) {
                size[0] = this.imagesArrLocationsSizes.get(index).longValue();
            }
            return this.imagesArrLocationsVideo.get(index);
        }
        if (this.imagesArr.isEmpty() || index >= this.imagesArr.size()) {
            return null;
        }
        MessageObject messageObject = this.imagesArr.get(index);
        TLRPC.Message message = messageObject.messageOwner;
        if (message instanceof TLRPC.TL_messageService) {
            if (message.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                return null;
            }
            TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
            if (closestPhotoSizeWithSize != null) {
                if (size != null) {
                    size[0] = closestPhotoSizeWithSize.size;
                    if (size[0] == 0) {
                        size[0] = -1;
                    }
                }
                return ImageLocation.getForObject(closestPhotoSizeWithSize, messageObject.photoThumbsObject);
            }
            if (size != null) {
                size[0] = -1;
            }
        } else if (((MessageObject.getMedia(message) instanceof TLRPC.TL_messageMediaPhoto) && MessageObject.getMedia(messageObject.messageOwner).photo != null) || ((MessageObject.getMedia(messageObject.messageOwner) instanceof TLRPC.TL_messageMediaWebPage) && MessageObject.getMedia(messageObject.messageOwner).webpage != null)) {
            if (messageObject.isGif()) {
                return ImageLocation.getForDocument(messageObject.getDocument());
            }
            TLRPC.PhotoSize closestPhotoSizeWithSize2 = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize(), false, (TLRPC.PhotoSize) null, true);
            if (closestPhotoSizeWithSize2 != null) {
                if (size != null) {
                    size[0] = closestPhotoSizeWithSize2.size;
                    if (size[0] == 0) {
                        size[0] = -1;
                    }
                }
                return ImageLocation.getForObject(closestPhotoSizeWithSize2, messageObject.photoThumbsObject);
            }
            if (size != null) {
                size[0] = -1;
            }
        } else {
            if (MessageObject.getMedia(messageObject.messageOwner) instanceof TLRPC.TL_messageMediaInvoice) {
                return ImageLocation.getForWebFile(WebFile.createWithWebDocument(MessageObject.getMedia(messageObject.messageOwner).webPhoto));
            }
            if (messageObject.getDocument() != null) {
                TLRPC.Document document = messageObject.getDocument();
                if (this.sharedMediaType == 5) {
                    return ImageLocation.getForDocument(document);
                }
                if (MessageObject.isDocumentHasThumb(messageObject.getDocument())) {
                    TLRPC.PhotoSize closestPhotoSizeWithSize3 = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
                    if (size != null && closestPhotoSizeWithSize3 != null) {
                        size[0] = closestPhotoSizeWithSize3.size;
                        if (size[0] == 0) {
                            size[0] = -1;
                        }
                    }
                    return ImageLocation.getForDocument(closestPhotoSizeWithSize3, document);
                }
            }
        }
        return null;
    }

    public final TLObject getFileLocation(int index, long[] size) {
        if (index < 0) {
            return null;
        }
        if (!this.secureDocuments.isEmpty()) {
            if (index >= this.secureDocuments.size()) {
                return null;
            }
            if (size != null) {
                size[0] = this.secureDocuments.get(index).secureFile.size;
            }
            return this.secureDocuments.get(index);
        }
        if (!this.imagesArrLocations.isEmpty()) {
            if (index >= this.imagesArrLocations.size()) {
                return null;
            }
            if (size != null && this.imagesArrLocationsSizes.get(index) != null) {
                size[0] = this.imagesArrLocationsSizes.get(index).longValue();
            }
            if (this.imagesArrLocationsVideo.get(index) != null) {
                return this.imagesArrLocationsVideo.get(index).location;
            }
            return null;
        }
        if (this.imagesArr.isEmpty() || index >= this.imagesArr.size()) {
            return null;
        }
        MessageObject messageObject = this.imagesArr.get(index);
        TLRPC.Message message = messageObject.messageOwner;
        if (message instanceof TLRPC.TL_messageService) {
            TLRPC.MessageAction messageAction = message.action;
            if (messageAction instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                return messageAction.newUserPhoto.photo_big;
            }
            TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
            if (closestPhotoSizeWithSize != null) {
                if (size != null) {
                    size[0] = closestPhotoSizeWithSize.size;
                    if (size[0] == 0) {
                        size[0] = -1;
                    }
                }
                return closestPhotoSizeWithSize;
            }
            if (size != null) {
                size[0] = -1;
            }
        } else if (((MessageObject.getMedia(message) instanceof TLRPC.TL_messageMediaPhoto) && MessageObject.getMedia(messageObject.messageOwner).photo != null) || ((MessageObject.getMedia(messageObject.messageOwner) instanceof TLRPC.TL_messageMediaWebPage) && MessageObject.getMedia(messageObject.messageOwner).webpage != null)) {
            TLRPC.PhotoSize closestPhotoSizeWithSize2 = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize(), false, (TLRPC.PhotoSize) null, true);
            if (closestPhotoSizeWithSize2 != null) {
                if (size != null) {
                    size[0] = closestPhotoSizeWithSize2.size;
                    if (size[0] == 0) {
                        size[0] = -1;
                    }
                }
                return closestPhotoSizeWithSize2;
            }
            if (size != null) {
                size[0] = -1;
            }
        } else {
            if (MessageObject.getMedia(messageObject.messageOwner) instanceof TLRPC.TL_messageMediaInvoice) {
                return ((TLRPC.MessageMedia) MessageObject.getMedia(messageObject.messageOwner)).photo;
            }
            if (messageObject.getDocument() != null && MessageObject.isDocumentHasThumb(messageObject.getDocument())) {
                TLRPC.PhotoSize closestPhotoSizeWithSize3 = FileLoader.getClosestPhotoSizeWithSize(messageObject.getDocument().thumbs, 90);
                if (size != null) {
                    size[0] = closestPhotoSizeWithSize3.size;
                    if (size[0] == 0) {
                        size[0] = -1;
                    }
                }
                return closestPhotoSizeWithSize3;
            }
        }
        return null;
    }

    public final void updateSelectedCount() {
        PhotoViewerProvider photoViewerProvider = this.placeProvider;
        if (photoViewerProvider == null) {
            return;
        }
        int selectedCount = photoViewerProvider.getSelectedCount();
        this.photosCounterView.setCount(selectedCount);
        if (selectedCount == 0) {
            togglePhotosListView(false, true);
        }
    }

    public final boolean isCurrentAvatarSet() {
        int i;
        if (this.currentAvatarLocation != null && (i = this.currentIndex) >= 0 && i < this.avatarsArr.size()) {
            TLRPC.Photo photo = this.avatarsArr.get(this.currentIndex);
            ImageLocation imageLocation = this.imagesArrLocations.get(this.currentIndex);
            if (photo instanceof TLRPC.TL_photoEmpty) {
                photo = null;
            }
            if (photo != null) {
                int size = photo.sizes.size();
                for (int i2 = 0; i2 < size; i2++) {
                    TLRPC.FileLocation fileLocation = ((TLRPC.PhotoSize) photo.sizes.get(i2)).location;
                    if (fileLocation != null) {
                        int i3 = fileLocation.local_id;
                        TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated = this.currentAvatarLocation.location;
                        if (i3 == ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated).local_id && fileLocation.volume_id == ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated).volume_id) {
                            return true;
                        }
                    }
                }
            } else if (imageLocation != null) {
                TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated2 = imageLocation.location;
                int i4 = ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated2).local_id;
                TLRPC.TL_fileLocationToBeDeprecated tL_fileLocationToBeDeprecated3 = this.currentAvatarLocation.location;
                if (i4 == ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated3).local_id && ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated2).volume_id == ((TLRPC.FileLocation) tL_fileLocationToBeDeprecated3).volume_id) {
                    return true;
                }
            }
        }
        return false;
    }

    public final void setItemVisible(View itemView, boolean visible, boolean animate) {
        setItemVisible(itemView, visible, animate, 1.0f);
    }

    public final void setItemVisible(final View itemView, final boolean visible, boolean animate, float maxAlpha) {
        Boolean bool = this.actionBarItemsVisibility.get(itemView);
        if (bool == null || bool.booleanValue() != visible) {
            this.actionBarItemsVisibility.put(itemView, Boolean.valueOf(visible));
            itemView.animate().cancel();
            float f = (visible ? 1.0f : 0.0f) * maxAlpha;
            if (animate && bool != null) {
                if (visible) {
                    itemView.setVisibility(0);
                }
                itemView.animate().alpha(f).setDuration(100L).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.this.lambda$setItemVisible$86(valueAnimator);
                    }
                }).setInterpolator(new LinearInterpolator()).withEndAction(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.this.lambda$setItemVisible$87(visible, itemView);
                    }
                }).start();
            } else {
                itemView.setVisibility(visible ? 0 : 8);
                itemView.setAlpha(f);
                updateActionBarTitlePadding();
            }
        }
    }

    public void lambda$setItemVisible$86(ValueAnimator valueAnimator) {
        updateActionBarTitlePadding();
    }

    public void lambda$setItemVisible$87(boolean z, View view) {
        if (!z) {
            view.setVisibility(8);
        }
        updateActionBarTitlePadding();
    }

    public final void onPhotoShow(final org.telegram.messenger.MessageObject r28, final org.telegram.tgnet.TLRPC.FileLocation r29, org.telegram.messenger.ImageLocation r30, org.telegram.messenger.ImageLocation r31, final java.util.ArrayList<org.telegram.messenger.MessageObject> r32, final java.util.ArrayList<org.telegram.messenger.SecureDocument> r33, final java.util.List<java.lang.Object> r34, int r35, final org.telegram.ui.PhotoViewer.PlaceProviderObject r36) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onPhotoShow(org.telegram.messenger.MessageObject, org.telegram.tgnet.TLRPC$FileLocation, org.telegram.messenger.ImageLocation, org.telegram.messenger.ImageLocation, java.util.ArrayList, java.util.ArrayList, java.util.List, int, org.telegram.ui.PhotoViewer$PlaceProviderObject):void");
    }

    public static int lambda$onPhotoShow$88(MessageObject messageObject, MessageObject messageObject2) {
        return messageObject.getId() - messageObject2.getId();
    }

    public final boolean canSendMediaToParentChatActivity() {
        TLRPC.Chat chat;
        ChatActivity chatActivity = this.parentChatActivity;
        return (chatActivity == null || (chatActivity.currentUser == null && ((chat = chatActivity.currentChat) == null || ChatObject.isNotInChat(chat) || (!ChatObject.canSendPhoto(this.parentChatActivity.currentChat) && !ChatObject.canSendVideo(this.parentChatActivity.currentChat))))) ? false : true;
    }

    public final void setDoubleTapEnabled(boolean value) {
        this.doubleTapEnabled = value;
        this.gestureDetector.setOnDoubleTapListener(value ? this : null);
    }

    public final void setImages() {
        if (this.animationInProgress == 0) {
            setIndexToImage(this.centerImage, this.currentIndex, null);
            setIndexToPaintingOverlay(this.currentIndex, this.paintingOverlay);
            setIndexToImage(this.rightImage, this.currentIndex + 1, this.rightCropTransform);
            setIndexToPaintingOverlay(this.currentIndex + 1, this.rightPaintingOverlay);
            setIndexToImage(this.leftImage, this.currentIndex - 1, this.leftCropTransform);
            setIndexToPaintingOverlay(this.currentIndex - 1, this.leftPaintingOverlay);
        }
    }

    public final void setIsAboutToSwitchToIndex(final int r43, boolean r44, boolean r45) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.setIsAboutToSwitchToIndex(int, boolean, boolean):void");
    }

    public void lambda$setIsAboutToSwitchToIndex$89(int i, TranslateController translateController, MessageObject messageObject, String str) {
        if (i != this.switchingToIndex) {
            return;
        }
        this.captionDetectedLanguage = str;
        if (translateController.isContextTranslateEnabled() && translateController.canTranslatePhoto(messageObject, this.captionDetectedLanguage)) {
            if (this.captionTranslated) {
                this.menuItem.showSubItem(22);
                this.menuItem.hideSubItem(21);
                return;
            } else {
                this.menuItem.showSubItem(21);
                this.menuItem.hideSubItem(22);
                return;
            }
        }
        this.menuItem.hideSubItem(21);
        this.menuItem.hideSubItem(22);
    }

    public final void updateCaptionTranslated() {
        int i;
        MessageObject messageObject;
        TLRPC.Message message;
        if (this.imagesArr.isEmpty() || (i = this.switchingToIndex) < 0 || i >= this.imagesArr.size() || (messageObject = this.imagesArr.get(this.switchingToIndex)) == null) {
            return;
        }
        if (this.captionTranslated && (message = messageObject.messageOwner) != null && message.translatedText != null && TextUtils.equals(message.translatedToLanguage, TranslateAlert2.getToLanguage())) {
            setCurrentCaption(messageObject, postProcessTranslated(messageObject), false, true);
        } else {
            setCurrentCaption(messageObject, messageObject.caption, this.captionTranslated, true);
        }
    }

    public final CharSequence postProcessTranslated(MessageObject messageObject) {
        if (messageObject == null || messageObject.messageOwner == null) {
            return "";
        }
        Spannable replaceAnimatedEmoji = MessageObject.replaceAnimatedEmoji(Emoji.replaceEmoji(new SpannableStringBuilder(messageObject.messageOwner.translatedText.text), Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false), messageObject.messageOwner.translatedText.entities, Theme.chat_msgTextPaint.getFontMetricsInt(), false);
        if (MessageObject.containsUrls(replaceAnimatedEmoji)) {
            try {
                AndroidUtilities.addLinksSafe(replaceAnimatedEmoji, 5, false, true);
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        MessageObject.addUrlsByPattern(messageObject.isOutOwner(), replaceAnimatedEmoji, true, 0, 0, true);
        MessageObject.addEntitiesToText(replaceAnimatedEmoji, messageObject.messageOwner.translatedText.entities, messageObject.isOutOwner(), true, true, true);
        if (messageObject.isVideo()) {
            MessageObject.addUrlsByPattern(messageObject.isOutOwner(), replaceAnimatedEmoji, true, 3, (int) messageObject.getDuration(), false);
        } else if (messageObject.isMusic() || messageObject.isVoice()) {
            MessageObject.addUrlsByPattern(messageObject.isOutOwner(), replaceAnimatedEmoji, true, 4, (int) messageObject.getDuration(), false);
        }
        return replaceAnimatedEmoji;
    }

    public void enableStickerMode(TLRPC.Document document, boolean empty, Utilities.Callback2<String, TLRPC.InputDocument> customHandler) {
        this.replacedSticker = document;
        this.stickerEmpty = empty;
        this.stickerEmptySent = false;
        this.customStickerHandler = customHandler;
        this.rotate = 0.0f;
        this.animateToRotate = 0.0f;
        if (this.stickerMakerView != null) {
            BlurButton blurButton = this.outlineBtn;
            if (blurButton != null) {
                blurButton.setActive(false, false);
            }
            this.stickerMakerView.clean();
            ArrayList<String> arrayList = this.selectedEmojis;
            if (arrayList != null) {
                arrayList.clear();
            }
        }
        if (this.replacedSticker != null) {
            ArrayList<String> arrayList2 = this.selectedEmojis;
            if (arrayList2 == null) {
                this.selectedEmojis = new ArrayList<>();
            } else {
                arrayList2.clear();
            }
            ArrayList findStickerEmoticons = MessageObject.findStickerEmoticons(document, Integer.valueOf(this.currentAccount));
            if (findStickerEmoticons != null) {
                this.selectedEmojis.addAll(findStickerEmoticons);
            }
        }
        BlurButton blurButton2 = this.cutOutBtn;
        if (blurButton2 != null) {
            blurButton2.clean();
        }
        showStickerMode(true, false);
        ImageView imageView = this.tuneItem;
        if (imageView != null) {
            imageView.setAlpha(this.stickerEmpty ? 0.4f : 1.0f);
        }
    }

    public void prepareSegmentImage() {
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView == null || this.sendPhotoType != 11) {
            return;
        }
        if (this.stickerEmpty) {
            stickerMakerView.clean();
        } else {
            stickerMakerView.segmentImage(this.centerImage.getBitmap(), this.centerImage.getOrientation(), getContainerViewWidth(), getContainerViewHeight(), new Utilities.Callback() {
                public final void run(Object obj) {
                    PhotoViewer.this.lambda$prepareSegmentImage$90((StickerMakerView.SegmentedObject) obj);
                }
            });
        }
    }

    public void lambda$prepareSegmentImage$90(StickerMakerView.SegmentedObject segmentedObject) {
        try {
            boolean z = !TextUtils.isEmpty(((MediaController.MediaEditState) this.imagesArrLocals.get(this.currentIndex)).filterPath);
            this.stickerMakerView.setSegmentedState(true, segmentedObject);
            this.centerImage.setImageBitmap(this.stickerMakerView.getSegmentedImage(this.centerImage.getBitmap(), z, this.centerImage.getOrientation()));
            this.cutOutBtn.setUndoCutState(true);
            showStickerMode(true, true, true);
            this.cutOutBtn.post(new PhotoViewer$$ExternalSyntheticLambda77(this));
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public final void showStickerMode(boolean show, boolean animated) {
        showStickerMode(show, show, animated);
    }

    public final void showStickerMode(boolean show, boolean buttonsShow, boolean animated) {
        if (!animated) {
            this.stickerMakerView.animate().setListener(null).cancel();
            this.stickerMakerView.setVisibility(show ? 0 : 8);
            this.stickerMakerView.setAlpha(this.pickerView.getAlpha());
            this.stickerMakerBackgroundView.animate().setListener(null).cancel();
            this.stickerMakerBackgroundView.setVisibility(show ? 0 : 8);
            this.stickerMakerBackgroundView.setAlpha(show ? 1.0f : 0.0f);
        } else if (show && this.stickerMakerView.getTag() == null) {
            this.stickerMakerView.animate().setListener(null).cancel();
            this.stickerMakerBackgroundView.animate().setListener(null).cancel();
            if (this.stickerMakerView.getVisibility() != 0) {
                this.stickerMakerView.setVisibility(0);
                this.stickerMakerView.animate().alpha(1.0f).start();
                this.stickerMakerBackgroundView.setVisibility(0);
                this.stickerMakerBackgroundView.animate().alpha(1.0f).start();
            }
        } else if (!show && this.stickerMakerView.getTag() != null) {
            this.stickerMakerView.animate().setListener(null).cancel();
            this.stickerMakerView.animate().alpha(0.0f).setListener(new HideViewAfterAnimation(this.stickerMakerView)).start();
            this.stickerMakerBackgroundView.animate().setListener(null).cancel();
            this.stickerMakerBackgroundView.animate().alpha(0.0f).setListener(new HideViewAfterAnimation(this.stickerMakerBackgroundView)).start();
        }
        this.stickerMakerView.setTag(show ? 1 : null);
        boolean z = (!show || this.cutOutBtn.isUndoCutState() || this.stickerEmpty) ? false : true;
        if (!animated) {
            this.cutOutBtn.animate().setListener(null).cancel();
            this.cutOutBtn.setVisibility(z ? 0 : 8);
            this.cutOutBtn.setAlpha(z ? 1.0f : 0.0f);
        } else if (z && this.cutOutBtn.getTag() == null) {
            this.cutOutBtn.animate().setListener(null).cancel();
            if (this.cutOutBtn.getVisibility() != 0) {
                this.cutOutBtn.setVisibility(0);
            }
            this.cutOutBtn.animate().alpha(1.0f).start();
        } else if (!z && this.cutOutBtn.getTag() != null) {
            this.cutOutBtn.animate().setListener(null).cancel();
            this.cutOutBtn.animate().alpha(0.0f).setListener(new HideViewAfterAnimation(this.cutOutBtn)).start();
        }
        this.cutOutBtn.setTag(z ? 1 : null);
        showEditStickerMode(show && this.cutOutBtn.isUndoCutState() && !this.stickerEmpty, animated);
        this.stickerMakerView.setOutlineVisible(show && this.cutOutBtn.isUndoCutState() && this.outlineBtn.isActive() && !this.eraseBtn.isActive() && !this.restoreBtn.isActive());
        boolean z2 = show && this.cutOutBtn.isUndoCutState() && !this.eraseBtn.isActive() && !this.restoreBtn.isActive();
        if (!animated) {
            this.outlineBtn.animate().setListener(null).cancel();
            this.outlineBtn.setVisibility(z2 ? 0 : 8);
            this.outlineBtn.setAlpha(z2 ? 1.0f : 0.0f);
            this.outlineBtn.setScaleX(z2 ? 1.0f : 0.8f);
            this.outlineBtn.setScaleY(z2 ? 1.0f : 0.8f);
        } else if (z2 && this.outlineBtn.getTag() == null) {
            this.outlineBtn.animate().setListener(null).cancel();
            if (this.outlineBtn.getVisibility() != 0) {
                this.outlineBtn.setVisibility(0);
            }
            this.outlineBtn.animate().alpha(1.0f).scaleX(1.0f).scaleY(1.0f).setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT).setDuration(400L).start();
        } else if (!z2 && this.outlineBtn.getTag() != null) {
            this.outlineBtn.animate().setListener(null).cancel();
            this.outlineBtn.animate().alpha(0.0f).scaleX(0.8f).scaleY(0.8f).setListener(new HideViewAfterAnimation(this.outlineBtn)).setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT).setDuration(400L).start();
        }
        this.outlineBtn.setTag(z2 ? 1 : null);
    }

    public final void showEditStickerMode(boolean show, boolean animated) {
        StickerMakerView stickerMakerView;
        MaskPaintView maskPaintView;
        boolean z = true;
        if (!show || (stickerMakerView = this.stickerMakerView) == null || (stickerMakerView.empty && !stickerMakerView.overriddenPaths() && ((maskPaintView = this.maskPaintView) == null || !maskPaintView.canUndo()))) {
            z = false;
        }
        if (!animated) {
            this.undoBtn.animate().setListener(null).cancel();
            this.undoBtn.setVisibility(z ? 0 : 8);
            this.undoBtn.setAlpha(z ? 1.0f : 0.0f);
            this.undoBtn.setScaleX(z ? 1.0f : 0.8f);
            this.undoBtn.setScaleY(z ? 1.0f : 0.8f);
        } else if (z && this.undoBtn.getTag() == null) {
            this.undoBtn.animate().setListener(null).cancel();
            if (this.undoBtn.getVisibility() != 0) {
                this.undoBtn.setVisibility(0);
                this.undoBtn.animate().alpha(1.0f).scaleX(1.0f).scaleY(1.0f).setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT).setDuration(400L).start();
            }
        } else if (!z && this.undoBtn.getTag() != null) {
            this.undoBtn.animate().setListener(null).cancel();
            this.undoBtn.animate().alpha(0.0f).scaleX(0.8f).scaleY(0.8f).setListener(new HideViewAfterAnimation(this.undoBtn)).setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT).setDuration(400L).start();
        }
        this.undoBtn.setTag(z ? r1 : null);
        if (!animated) {
            this.eraseBtn.animate().setListener(null).cancel();
            this.eraseBtn.setVisibility(show ? 0 : 8);
            this.eraseBtn.setAlpha(show ? 1.0f : 0.0f);
            this.eraseBtn.setScaleX(show ? 1.0f : 0.8f);
            this.eraseBtn.setScaleY(show ? 1.0f : 0.8f);
            this.restoreBtn.animate().setListener(null).cancel();
            this.restoreBtn.setVisibility(show ? 0 : 8);
            this.restoreBtn.setAlpha(show ? 1.0f : 0.0f);
            this.restoreBtn.setScaleX(show ? 1.0f : 0.8f);
            this.restoreBtn.setScaleY(show ? 1.0f : 0.8f);
        } else if (show && this.eraseBtn.getTag() == null) {
            this.eraseBtn.animate().setListener(null).cancel();
            this.restoreBtn.animate().setListener(null).cancel();
            if (this.eraseBtn.getVisibility() != 0) {
                this.eraseBtn.setVisibility(0);
                ViewPropertyAnimator scaleY = this.eraseBtn.animate().alpha(1.0f).scaleX(1.0f).scaleY(1.0f);
                TimeInterpolator timeInterpolator = CubicBezierInterpolator.EASE_OUT_QUINT;
                scaleY.setInterpolator(timeInterpolator).setDuration(400L).start();
                this.restoreBtn.setVisibility(0);
                this.restoreBtn.animate().alpha(1.0f).scaleX(1.0f).scaleY(1.0f).setInterpolator(timeInterpolator).setDuration(400L).start();
            }
        } else if (!show && this.eraseBtn.getTag() != null) {
            this.eraseBtn.animate().setListener(null).cancel();
            ViewPropertyAnimator listener = this.eraseBtn.animate().alpha(0.0f).scaleX(0.8f).scaleY(0.8f).setListener(new HideViewAfterAnimation(this.eraseBtn));
            TimeInterpolator timeInterpolator2 = CubicBezierInterpolator.EASE_OUT_QUINT;
            listener.setInterpolator(timeInterpolator2).setDuration(400L).start();
            this.restoreBtn.animate().setListener(null).cancel();
            this.restoreBtn.animate().alpha(0.0f).scaleX(0.8f).scaleY(0.8f).setListener(new HideViewAfterAnimation(this.restoreBtn)).setInterpolator(timeInterpolator2).setDuration(400L).start();
        }
        this.eraseBtn.setTag(show ? 1 : null);
    }

    public final void updateImageDate(long date) {
        this.actionBarContainer.setSubtitle(date != 0 ? LocaleController.formatDateAudio(date, false) : "", true);
    }

    public final void showEditCaption(boolean show, boolean animated) {
        if (!animated) {
            this.captionEdit.animate().setListener(null).cancel();
            this.captionEdit.setVisibility(show ? 0 : 8);
            this.captionEdit.setTranslationY(0.0f);
            this.captionEdit.setAlpha(this.pickerView.getAlpha());
        } else if (show && this.captionEdit.getTag() == null) {
            if (this.captionEdit.getVisibility() != 0) {
                this.captionEdit.setVisibility(0);
                this.captionEdit.setAlpha(this.pickerView.getAlpha());
                this.captionEdit.setTranslationY(AndroidUtilities.dp(58.0f));
            }
            ObjectAnimator objectAnimator = this.captionAnimator;
            if (objectAnimator != null) {
                objectAnimator.removeAllListeners();
                this.captionAnimator.cancel();
            }
            CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
            ObjectAnimator ofFloat = ObjectAnimator.ofFloat(captionPhotoViewer, (Property<CaptionPhotoViewer, Float>) View.TRANSLATION_Y, captionPhotoViewer.getTranslationY(), 0.0f);
            this.captionAnimator = ofFloat;
            ofFloat.setDuration(220L);
            this.captionAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
            this.captionAnimator.start();
        } else if (!show && this.captionEdit.getTag() != null) {
            ObjectAnimator objectAnimator2 = this.captionAnimator;
            if (objectAnimator2 != null) {
                objectAnimator2.removeAllListeners();
                this.captionAnimator.cancel();
            }
            CaptionPhotoViewer captionPhotoViewer2 = this.captionEdit;
            ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(captionPhotoViewer2, (Property<CaptionPhotoViewer, Float>) View.TRANSLATION_Y, captionPhotoViewer2.getTranslationY(), AndroidUtilities.dp(58.0f));
            this.captionAnimator = ofFloat2;
            ofFloat2.addListener(new HideViewAfterAnimation(this.captionEdit));
            this.captionAnimator.setDuration(220L);
            this.captionAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
            this.captionAnimator.start();
        }
        this.captionEdit.setTag(show ? 1 : null);
    }

    public final void showVideoTimeline(boolean show, boolean animated) {
        if (!animated) {
            this.videoTimelineViewContainer.animate().setListener(null).cancel();
            this.videoTimelineViewContainer.setVisibility(show ? 0 : 8);
            this.videoTimelineView.setTranslationY(0.0f);
            this.videoTimelineViewContainer.setAlpha(this.pickerView.getAlpha());
        } else if (show && this.videoTimelineViewContainer.getTag() == null) {
            if (this.videoTimelineViewContainer.getVisibility() != 0) {
                this.videoTimelineViewContainer.setVisibility(0);
                this.videoTimelineViewContainer.setAlpha(this.pickerView.getAlpha());
                this.videoTimelineView.setTranslationY(AndroidUtilities.dp(58.0f));
            }
            ObjectAnimator objectAnimator = this.videoTimelineAnimator;
            if (objectAnimator != null) {
                objectAnimator.removeAllListeners();
                this.videoTimelineAnimator.cancel();
            }
            VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
            ObjectAnimator ofFloat = ObjectAnimator.ofFloat(videoTimelinePlayView, (Property<VideoTimelinePlayView, Float>) View.TRANSLATION_Y, videoTimelinePlayView.getTranslationY(), 0.0f);
            this.videoTimelineAnimator = ofFloat;
            ofFloat.setDuration(220L);
            this.videoTimelineAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
            this.videoTimelineAnimator.start();
        } else if (!show && this.videoTimelineViewContainer.getTag() != null) {
            ObjectAnimator objectAnimator2 = this.videoTimelineAnimator;
            if (objectAnimator2 != null) {
                objectAnimator2.removeAllListeners();
                this.videoTimelineAnimator.cancel();
            }
            VideoTimelinePlayView videoTimelinePlayView2 = this.videoTimelineView;
            ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(videoTimelinePlayView2, (Property<VideoTimelinePlayView, Float>) View.TRANSLATION_Y, videoTimelinePlayView2.getTranslationY(), AndroidUtilities.dp(58.0f));
            this.videoTimelineAnimator = ofFloat2;
            ofFloat2.addListener(new HideViewAfterAnimation(this.videoTimelineViewContainer));
            this.videoTimelineAnimator.setDuration(220L);
            this.videoTimelineAnimator.setInterpolator(CubicBezierInterpolator.DEFAULT);
            this.videoTimelineAnimator.start();
        }
        FrameLayout frameLayout = this.videoTimelineViewContainer;
        if (frameLayout != null && frameLayout.getVisibility() != 8) {
            this.videoTimelineViewContainer.setTranslationY(this.pickerView.getTranslationY() - Math.max(0, this.captionEdit.getEditTextHeight() - AndroidUtilities.dp(46.0f)));
        }
        this.videoTimelineViewContainer.setTag(show ? 1 : null);
    }

    public static TLRPC.FileLocation getFileLocation(ImageLocation location) {
        if (location == null) {
            return null;
        }
        return location.location;
    }

    public static String getFileLocationExt(ImageLocation location) {
        if (location == null || location.imageType != 2) {
            return null;
        }
        return "mp4";
    }

    public final void setImageIndex(int index) {
        setImageIndex(index, true, false);
    }

    public final void setImageIndex(int r34, boolean r35, boolean r36) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.setImageIndex(int, boolean, boolean):void");
    }

    public final void resetIndexForDeferredImageLoading() {
        Object mark = this.centerImage.getMark();
        if (mark == null || !mark.equals(1)) {
            return;
        }
        setIndexToImage(this.centerImage, this.currentIndex, null);
    }

    public final void setCurrentCaption(MessageObject messageObject, final CharSequence _caption, boolean translating, boolean animated) {
        int i;
        boolean z;
        TLRPC.Message message;
        int i2;
        CharSequence cloneSpans = AnimatedEmojiSpan.cloneSpans(_caption, 3);
        showEditCaption(this.editing, animated);
        if (!this.editing) {
            if (this.sendPhotoType != 1) {
                this.captionEdit.setVisibility(8);
                if (this.needCaptionLayout) {
                    if (this.captionTextViewSwitcher.getParent() != this.pickerView) {
                        FrameLayout frameLayout = this.captionContainer;
                        if (frameLayout != null) {
                            frameLayout.removeView(this.captionTextViewSwitcher);
                        }
                        this.captionTextViewSwitcher.setMeasureAllChildren(false);
                        this.pickerView.addView((View) this.captionTextViewSwitcher, LayoutHelper.createFrame(-1, -2.0f, 83, 0.0f, 0.0f, 76.0f, 48.0f));
                    }
                } else {
                    if (this.captionScrollView == null) {
                        FrameLayout frameLayout2 = new FrameLayout(this.containerView.getContext());
                        this.captionContainer = frameLayout2;
                        this.captionTextViewSwitcher.setContainer(frameLayout2);
                        CaptionScrollView captionScrollView = new CaptionScrollView(this.containerView.getContext(), this.captionTextViewSwitcher, this.captionContainer) {
                            @Override
                            public boolean isStatusBarVisible() {
                                return Build.VERSION.SDK_INT >= 21 && !PhotoViewer.this.inBubbleMode;
                            }

                            public void invalidate() {
                                super/*android.widget.FrameLayout*/.invalidate();
                                if (PhotoViewer.this.isActionBarVisible) {
                                    int scrollY = getScrollY();
                                    float translationY = PhotoViewer.this.captionTextViewSwitcher.getTranslationY();
                                    boolean z2 = scrollY == 0 && translationY == 0.0f;
                                    boolean z3 = scrollY == 0 && translationY == 0.0f;
                                    if (!z2) {
                                        int y = PhotoViewer.this.photoProgressViews[0].getY() + PhotoViewer.this.photoProgressViews[0].size;
                                        int top = (((PhotoViewer.this.captionContainer.getTop() + ((int) translationY)) - scrollY) + ((isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight())) - AndroidUtilities.dp(12.0f);
                                        z3 = top > ((int) PhotoViewer.this.fullscreenButton[0].getY()) + AndroidUtilities.dp(32.0f);
                                        z2 = top > y;
                                    }
                                    if (PhotoViewer.this.allowShowFullscreenButton) {
                                        if (PhotoViewer.this.fullscreenButton[0].getTag() != null && ((Integer) PhotoViewer.this.fullscreenButton[0].getTag()).intValue() == 3 && z3) {
                                            PhotoViewer.this.fullscreenButton[0].setTag(2);
                                            PhotoViewer.this.fullscreenButton[0].animate().alpha(1.0f).setDuration(150L).setListener(new AnimatorListenerAdapter() {
                                                @Override
                                                public void onAnimationEnd(Animator animation) {
                                                    PhotoViewer.this.fullscreenButton[0].setTag(null);
                                                }
                                            }).start();
                                        } else if (PhotoViewer.this.fullscreenButton[0].getTag() == null && !z3) {
                                            PhotoViewer.this.fullscreenButton[0].setTag(3);
                                            PhotoViewer.this.fullscreenButton[0].animate().alpha(0.0f).setListener(null).setDuration(150L).start();
                                        }
                                    }
                                    PhotoViewer.this.photoProgressViews[0].setIndexedAlpha(2, z2 ? 1.0f : 0.0f, true);
                                }
                            }
                        };
                        this.captionScrollView = captionScrollView;
                        this.captionTextViewSwitcher.setScrollView(captionScrollView);
                        this.captionContainer.setClipChildren(false);
                        this.captionScrollView.addView(this.captionContainer, new ViewGroup.LayoutParams(-1, -2));
                        this.containerView.addView(this.captionScrollView, LayoutHelper.createFrame(-1, -1, 80));
                    }
                    if (this.captionTextViewSwitcher.getParent() != this.captionContainer) {
                        this.pickerView.removeView(this.captionTextViewSwitcher);
                        this.captionTextViewSwitcher.setMeasureAllChildren(true);
                        this.captionContainer.addView((View) this.captionTextViewSwitcher, -1, -2);
                        this.videoPreviewFrame.bringToFront();
                    }
                }
                boolean isEmpty = TextUtils.isEmpty(cloneSpans);
                boolean isEmpty2 = TextUtils.isEmpty(this.captionTextViewSwitcher.getCurrentView().getText());
                CaptionTextViewSwitcher captionTextViewSwitcher = this.captionTextViewSwitcher;
                TextView nextView = animated ? captionTextViewSwitcher.getNextView() : captionTextViewSwitcher.getCurrentView();
                if (this.isCurrentVideo) {
                    if (nextView.getMaxLines() != 1) {
                        this.captionTextViewSwitcher.getCurrentView().setMaxLines(1);
                        this.captionTextViewSwitcher.getNextView().setMaxLines(1);
                        this.captionTextViewSwitcher.getCurrentView().setSingleLine(true);
                        this.captionTextViewSwitcher.getNextView().setSingleLine(true);
                        this.captionTextViewSwitcher.getCurrentView().setEllipsize(TextUtils.TruncateAt.END);
                        this.captionTextViewSwitcher.getNextView().setEllipsize(TextUtils.TruncateAt.END);
                    }
                } else {
                    int maxLines = nextView.getMaxLines();
                    if (maxLines == 1) {
                        this.captionTextViewSwitcher.getCurrentView().setSingleLine(false);
                        this.captionTextViewSwitcher.getNextView().setSingleLine(false);
                    }
                    if (this.needCaptionLayout) {
                        Point point = AndroidUtilities.displaySize;
                        i = point.x > point.y ? 5 : 10;
                    } else {
                        i = Integer.MAX_VALUE;
                    }
                    if (maxLines != i) {
                        this.captionTextViewSwitcher.getCurrentView().setMaxLines(i);
                        this.captionTextViewSwitcher.getNextView().setMaxLines(i);
                        this.captionTextViewSwitcher.getCurrentView().setEllipsize(null);
                        this.captionTextViewSwitcher.getNextView().setEllipsize(null);
                    }
                }
                nextView.setScrollX(0);
                boolean z2 = this.needCaptionLayout;
                this.dontChangeCaptionPosition = !z2 && animated && isEmpty;
                if (!z2) {
                    this.captionScrollView.dontChangeTopMargin = false;
                }
                if (animated && (i2 = Build.VERSION.SDK_INT) >= 19) {
                    if (i2 >= 23) {
                        TransitionManager.endTransitions(z2 ? this.pickerView : this.captionScrollView);
                    }
                    if (this.needCaptionLayout) {
                        TransitionSet transitionSet = new TransitionSet();
                        transitionSet.setOrdering(0);
                        transitionSet.addTransition(new ChangeBounds());
                        transitionSet.addTransition(new Fade(2));
                        transitionSet.addTransition(new Fade(1));
                        transitionSet.setDuration(200L);
                        TransitionManager.beginDelayedTransition(this.pickerView, transitionSet);
                    } else {
                        TransitionSet duration = new TransitionSet().addTransition(new AnonymousClass70(2, isEmpty2, isEmpty)).addTransition(new AnonymousClass69(1, isEmpty2, isEmpty)).setDuration(200L);
                        if (!isEmpty2) {
                            this.captionScrollView.dontChangeTopMargin = true;
                            duration.addTransition(new AnonymousClass71());
                        }
                        if (isEmpty2 && !isEmpty) {
                            duration.addTarget((View) this.captionTextViewSwitcher);
                        }
                        TransitionManager.beginDelayedTransition(this.captionScrollView, duration);
                    }
                    z = true;
                } else {
                    this.captionTextViewSwitcher.getCurrentView().setText((CharSequence) null);
                    CaptionScrollView captionScrollView2 = this.captionScrollView;
                    if (captionScrollView2 != null) {
                        captionScrollView2.scrollTo(0, 0);
                    }
                    z = false;
                }
                if (!isEmpty) {
                    Theme.createChatResources(null, true);
                    if (messageObject == null || !this.captionTranslated || (message = messageObject.messageOwner) == null || message.translatedText == null || !TextUtils.equals(message.translatedToLanguage, TranslateAlert2.getToLanguage())) {
                        if (messageObject != null && !messageObject.messageOwner.entities.isEmpty()) {
                            SpannableString spannableString = new SpannableString(cloneSpans);
                            messageObject.addEntitiesToText(spannableString, true, false);
                            if (messageObject.isVideo() || this.playGifAsVideo) {
                                MessageObject.addUrlsByPattern(messageObject.isOutOwner(), spannableString, false, 3, (int) messageObject.getDuration(), false);
                            }
                            cloneSpans = Emoji.replaceEmoji(spannableString, nextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20.0f), false);
                        } else {
                            cloneSpans = Emoji.replaceEmoji(new SpannableStringBuilder(cloneSpans), nextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20.0f), false);
                        }
                    }
                    this.captionTextViewSwitcher.setTag(cloneSpans);
                    try {
                        this.captionTextViewSwitcher.setText(cloneSpans, animated, this.lastCaptionTranslating != translating);
                        CaptionScrollView captionScrollView3 = this.captionScrollView;
                        if (captionScrollView3 != null) {
                            captionScrollView3.updateTopMargin();
                        }
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                    nextView.setScrollY(0);
                    nextView.setTextColor(-1);
                    this.captionTextViewSwitcher.setVisibility(this.isActionBarVisible && (!this.isCurrentVideo || this.pickerView.getVisibility() == 0 || this.pageBlocksAdapter != null) ? 0 : 4);
                } else if (this.needCaptionLayout) {
                    this.captionTextViewSwitcher.setText(LocaleController.getString("AddCaption", R.string.AddCaption), animated);
                    this.captionTextViewSwitcher.getCurrentView().setTextColor(-1291845633);
                    this.captionTextViewSwitcher.setTag("empty");
                    this.captionTextViewSwitcher.setVisibility(0);
                } else {
                    this.captionTextViewSwitcher.setText((CharSequence) null, animated);
                    this.captionTextViewSwitcher.getCurrentView().setTextColor(-1);
                    this.captionTextViewSwitcher.setVisibility(4, !z || isEmpty2);
                    this.captionTextViewSwitcher.setTag(null);
                }
                if (this.captionTextViewSwitcher.getCurrentView() instanceof CaptionTextView) {
                    ((CaptionTextView) this.captionTextViewSwitcher.getCurrentView()).setLoading(translating);
                }
                this.lastCaptionTranslating = !isEmpty && translating;
                if (this.muteItemAvailable) {
                    this.photoQualityLayout.setVisibility(8);
                }
                if (this.photoQualityLayout.getVisibility() == 0) {
                    setCaptionPosition();
                    if (this.placeProvider.canCaptureMorePhotos()) {
                        return;
                    }
                    this.imagesArrLocals.size();
                    return;
                }
                return;
            }
        }
        this.captionEdit.setText(cloneSpans);
        this.captionTextViewSwitcher.setVisibility(8);
    }

    public class AnonymousClass70 extends Fade {
        public final boolean val$isCaptionEmpty;
        public final boolean val$isCurrentCaptionEmpty;

        public AnonymousClass70(int fadingMode, final boolean val$isCurrentCaptionEmpty, final boolean val$isCaptionEmpty) {
            super(fadingMode);
            this.val$isCurrentCaptionEmpty = val$isCurrentCaptionEmpty;
            this.val$isCaptionEmpty = val$isCaptionEmpty;
        }

        @Override
        public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
            Animator onDisappear = super.onDisappear(sceneRoot, view, startValues, endValues);
            if (!this.val$isCurrentCaptionEmpty && this.val$isCaptionEmpty && view == PhotoViewer.this.captionTextViewSwitcher) {
                onDisappear.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewer.this.captionScrollView.setVisibility(4);
                        PhotoViewer.this.captionScrollView.backgroundAlpha = 1.0f;
                    }
                });
                ((ObjectAnimator) onDisappear).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.AnonymousClass70.this.lambda$onDisappear$0(valueAnimator);
                    }
                });
            }
            return onDisappear;
        }

        public void lambda$onDisappear$0(ValueAnimator valueAnimator) {
            PhotoViewer.this.captionScrollView.backgroundAlpha = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            PhotoViewer.this.captionScrollView.invalidate();
        }
    }

    public class AnonymousClass69 extends Fade {
        public final boolean val$isCaptionEmpty;
        public final boolean val$isCurrentCaptionEmpty;

        public AnonymousClass69(int fadingMode, final boolean val$isCurrentCaptionEmpty, final boolean val$isCaptionEmpty) {
            super(fadingMode);
            this.val$isCurrentCaptionEmpty = val$isCurrentCaptionEmpty;
            this.val$isCaptionEmpty = val$isCaptionEmpty;
        }

        @Override
        public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues) {
            Animator onAppear = super.onAppear(sceneRoot, view, startValues, endValues);
            if (this.val$isCurrentCaptionEmpty && !this.val$isCaptionEmpty && view == PhotoViewer.this.captionTextViewSwitcher) {
                onAppear.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewer.this.captionScrollView.backgroundAlpha = 1.0f;
                    }
                });
                ((ObjectAnimator) onAppear).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.AnonymousClass69.this.lambda$onAppear$0(valueAnimator);
                    }
                });
            }
            return onAppear;
        }

        public void lambda$onAppear$0(ValueAnimator valueAnimator) {
            PhotoViewer.this.captionScrollView.backgroundAlpha = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            PhotoViewer.this.captionScrollView.invalidate();
        }
    }

    public class AnonymousClass71 extends Transition {
        public AnonymousClass71() {
        }

        @Override
        public void captureStartValues(TransitionValues transitionValues) {
            if (transitionValues.view == PhotoViewer.this.captionScrollView) {
                transitionValues.values.put("scrollY", Integer.valueOf(PhotoViewer.this.captionScrollView.getScrollY()));
            }
        }

        @Override
        public void captureEndValues(TransitionValues transitionValues) {
            if (transitionValues.view == PhotoViewer.this.captionTextViewSwitcher) {
                transitionValues.values.put("translationY", Integer.valueOf(PhotoViewer.this.captionScrollView.getPendingMarginTopDiff()));
            }
        }

        @Override
        public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
            int intValue;
            if (startValues.view == PhotoViewer.this.captionScrollView) {
                ValueAnimator ofInt = ValueAnimator.ofInt(((Integer) startValues.values.get("scrollY")).intValue(), 0);
                ofInt.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        PhotoViewer.this.captionTextViewSwitcher.getNextView().setText((CharSequence) null);
                        PhotoViewer.this.captionScrollView.applyPendingTopMargin();
                    }

                    @Override
                    public void onAnimationStart(Animator animation) {
                        PhotoViewer.this.captionScrollView.stopScrolling();
                    }
                });
                ofInt.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                        PhotoViewer.AnonymousClass71.this.lambda$createAnimator$0(valueAnimator);
                    }
                });
                return ofInt;
            }
            if (endValues.view != PhotoViewer.this.captionTextViewSwitcher || (intValue = ((Integer) endValues.values.get("translationY")).intValue()) == 0) {
                return null;
            }
            ObjectAnimator ofFloat = ObjectAnimator.ofFloat(PhotoViewer.this.captionTextViewSwitcher, (Property<CaptionTextViewSwitcher, Float>) View.TRANSLATION_Y, 0.0f, intValue);
            ofFloat.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    PhotoViewer.this.captionTextViewSwitcher.setTranslationY(0.0f);
                }
            });
            return ofFloat;
        }

        public void lambda$createAnimator$0(ValueAnimator valueAnimator) {
            PhotoViewer.this.captionScrollView.scrollTo(0, ((Integer) valueAnimator.getAnimatedValue()).intValue());
        }
    }

    public final void setCaptionHwLayerEnabled(boolean enabled) {
        if (this.captionHwLayerEnabled != enabled) {
            this.captionHwLayerEnabled = enabled;
            this.captionTextViewSwitcher.setLayerType(2, null);
            this.captionTextViewSwitcher.getCurrentView().setLayerType(2, null);
            this.captionTextViewSwitcher.getNextView().setLayerType(2, null);
        }
    }

    public final void changeTranslateLanguage() {
        PlusUtils.showLanguageSelector(this.parentActivity, (String) null, new PlusUtils.TranslateCallBack() {
            public void onProviderChanged(int i) {
                PlusUtils.TranslateCallBack.-CC.$default$onProviderChanged(this, i);
            }

            public void onSuccess(String translation) {
            }

            public void onChanged(String toLang) {
                if (TextUtils.isEmpty(toLang)) {
                    return;
                }
                PhotoViewer.this.translationChatLang = toLang;
                PlusSettings.saveChatTranslationLanguage(PhotoViewer.this.parentChatActivity.getDialogId(), toLang);
                PhotoViewer.this.sendPopupLayout = null;
                PhotoViewer.this.translateMessage();
            }
        }, false, false);
    }

    public final void translateMessage() {
        if (this.captionEdit.getTag() != null) {
            return;
        }
        BaseTranslationEngine.translate(((CaptionContainerView) this.captionEdit).editText.getText().toString(), this.translationChatLang, new BaseTranslationEngine.TranslateCallBack() {
            public void onError(Exception error) {
            }

            public void onSuccess(String translation, String fl, String tl) {
                onSuccess(translation);
            }

            public void onSuccess(String translation) {
                PhotoViewer.this.captionEdit.setText(translation);
                PhotoViewer.this.captionEdit.setTag(1);
                PhotoViewer.this.closeCaptionEnter(true);
            }
        });
    }

    public final void setCaptionPosition() {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) this.captionTextViewSwitcher.getLayoutParams();
        layoutParams.bottomMargin = AndroidUtilities.dp(48 + ((this.photoQualityLayout.getVisibility() == 0 && Theme.plusShowPhotoQualityBar) ? this.photoQualityLayoutSize : 0));
        this.captionTextViewSwitcher.setLayoutParams(layoutParams);
    }

    public final void checkProgress(final int a, boolean scroll, final boolean animated) {
        final File file;
        File file2;
        MessageObject messageObject;
        boolean shouldIndexAutoPlayed;
        boolean z;
        File pathToAttach;
        File pathToAttach2;
        boolean z2;
        File file3;
        boolean z3;
        FileLoader.FileResolver fileResolver;
        AnimatedFileDrawable animatedFileDrawable;
        int i = this.currentIndex;
        int i2 = a == 1 ? i + 1 : a == 2 ? i - 1 : i;
        boolean z4 = false;
        if (this.currentFileNames[a] != null) {
            boolean hasBitmap = (a == 0 && i == 0 && (animatedFileDrawable = this.currentAnimation) != null) ? animatedFileDrawable.hasBitmap() : false;
            FileLoader.FileResolver fileResolver2 = null;
            if (this.currentMessageObject != null) {
                if (i2 < 0 || i2 >= this.imagesArr.size()) {
                    this.photoProgressViews[a].setBackgroundState(-1, animated, true);
                    return;
                }
                MessageObject messageObject2 = this.imagesArr.get(i2);
                boolean shouldMessageObjectAutoPlayed = shouldMessageObjectAutoPlayed(messageObject2);
                if (this.sharedMediaType == 1 && !messageObject2.canPreviewDocument()) {
                    this.photoProgressViews[a].setBackgroundState(-1, animated, true);
                    return;
                }
                file2 = !TextUtils.isEmpty(messageObject2.messageOwner.attachPath) ? new File(messageObject2.messageOwner.attachPath) : null;
                if ((MessageObject.getMedia(messageObject2.messageOwner) instanceof TLRPC.TL_messageMediaWebPage) && MessageObject.getMedia(messageObject2.messageOwner).webpage != null && MessageObject.getMedia(messageObject2.messageOwner).webpage.document == null) {
                    final TLObject fileLocation = getFileLocation(i2, null);
                    fileResolver = new FileLoader.FileResolver() {
                        public final File getFile() {
                            File lambda$checkProgress$91;
                            lambda$checkProgress$91 = PhotoViewer.this.lambda$checkProgress$91(fileLocation);
                            return lambda$checkProgress$91;
                        }
                    };
                } else {
                    final TLRPC.Message message = messageObject2.messageOwner;
                    fileResolver = new FileLoader.FileResolver() {
                        public final File getFile() {
                            File lambda$checkProgress$92;
                            lambda$checkProgress$92 = PhotoViewer.this.lambda$checkProgress$92(message);
                            return lambda$checkProgress$92;
                        }
                    };
                }
                if (messageObject2.isVideo() || this.playGifAsVideo) {
                    z2 = SharedConfig.streamMedia && messageObject2.canStreamVideo() && !DialogObject.isEncryptedDialog(messageObject2.getDialogId());
                    shouldIndexAutoPlayed = shouldMessageObjectAutoPlayed;
                    file = null;
                    fileResolver2 = fileResolver;
                    z = true;
                } else {
                    shouldIndexAutoPlayed = shouldMessageObjectAutoPlayed;
                    file = null;
                    fileResolver2 = fileResolver;
                    z2 = false;
                    z = false;
                }
                messageObject = messageObject2;
            } else {
                if (this.currentBotInlineResult != null) {
                    if (i2 < 0 || i2 >= this.imagesArrLocals.size()) {
                        this.photoProgressViews[a].setBackgroundState(-1, animated, true);
                        return;
                    }
                    TLRPC.BotInlineResult botInlineResult = (TLRPC.BotInlineResult) this.imagesArrLocals.get(i2);
                    if (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(botInlineResult.document)) {
                        if (botInlineResult.document != null) {
                            file3 = FileLoader.getInstance(this.currentAccount).getPathToAttach(botInlineResult.document);
                        } else if (botInlineResult.content instanceof TLRPC.TL_webDocument) {
                            file3 = new File(FileLoader.getDirectory(4), Utilities.MD5(botInlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(botInlineResult.content.url, "mp4"));
                        } else {
                            file3 = null;
                        }
                        z3 = true;
                    } else {
                        if (botInlineResult.document != null) {
                            file3 = new File(FileLoader.getDirectory(3), this.currentFileNames[a]);
                        } else {
                            file3 = botInlineResult.photo != null ? new File(FileLoader.getDirectory(0), this.currentFileNames[a]) : null;
                        }
                        z3 = false;
                    }
                    file = new File(FileLoader.getDirectory(4), this.currentFileNames[a]);
                    file2 = file3;
                    z = z3;
                    messageObject = null;
                    shouldIndexAutoPlayed = false;
                } else {
                    if (this.currentFileLocation != null) {
                        if (i2 < 0 || i2 >= this.imagesArrLocationsVideo.size()) {
                            this.photoProgressViews[a].setBackgroundState(-1, animated, true);
                            return;
                        }
                        ImageLocation imageLocation = this.imagesArrLocationsVideo.get(i2);
                        if (imageLocation != null) {
                            pathToAttach = FileLoader.getInstance(this.currentAccount).getPathToAttach(imageLocation.location, getFileLocationExt(imageLocation), false);
                            pathToAttach2 = FileLoader.getInstance(this.currentAccount).getPathToAttach(imageLocation.location, getFileLocationExt(imageLocation), true);
                        } else {
                            pathToAttach2 = null;
                            pathToAttach = null;
                        }
                    } else if (this.currentSecureDocument != null) {
                        if (i2 < 0 || i2 >= this.secureDocuments.size()) {
                            this.photoProgressViews[a].setBackgroundState(-1, animated, true);
                            return;
                        } else {
                            SecureDocument secureDocument = this.secureDocuments.get(i2);
                            pathToAttach = FileLoader.getInstance(this.currentAccount).getPathToAttach(secureDocument, true);
                            pathToAttach2 = FileLoader.getInstance(this.currentAccount).getPathToAttach(secureDocument, false);
                        }
                    } else if (this.currentPathObject != null) {
                        file2 = new File(FileLoader.getDirectory(3), this.currentFileNames[a]);
                        file = new File(FileLoader.getDirectory(4), this.currentFileNames[a]);
                        messageObject = null;
                        shouldIndexAutoPlayed = false;
                        z2 = false;
                        z = false;
                    } else {
                        PageBlocksAdapter pageBlocksAdapter = this.pageBlocksAdapter;
                        if (pageBlocksAdapter != null) {
                            File file4 = pageBlocksAdapter.getFile(i2);
                            boolean z5 = this.pageBlocksAdapter.isVideo(i2) || this.pageBlocksAdapter.isHardwarePlayer(i2);
                            shouldIndexAutoPlayed = shouldIndexAutoPlayed(i2);
                            file2 = file4;
                            z = z5;
                            file = null;
                            messageObject = null;
                        } else {
                            file = null;
                            file2 = null;
                            messageObject = null;
                            shouldIndexAutoPlayed = false;
                            z2 = false;
                            z = false;
                        }
                    }
                    file = pathToAttach2;
                    file2 = pathToAttach;
                    messageObject = null;
                    shouldIndexAutoPlayed = false;
                    z2 = false;
                    z = false;
                }
                z2 = false;
            }
            boolean z6 = !(a == 0 && this.dontAutoPlay) && shouldIndexAutoPlayed;
            final boolean z7 = hasBitmap;
            final File file5 = file2;
            final FileLoader.FileResolver fileResolver3 = fileResolver2;
            final MessageObject messageObject3 = messageObject;
            final boolean z8 = z2;
            final boolean z9 = z;
            final boolean z10 = z6;
            Utilities.globalQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.this.lambda$checkProgress$94(z7, file5, file, fileResolver3, a, messageObject3, z8, z9, z10, animated);
                }
            });
            return;
        }
        if (!this.imagesArrLocals.isEmpty() && i2 >= 0 && i2 < this.imagesArrLocals.size()) {
            Object obj = this.imagesArrLocals.get(i2);
            if (obj instanceof MediaController.PhotoEntry) {
                z4 = ((MediaController.PhotoEntry) obj).isVideo;
            }
        }
        if (z4) {
            this.photoProgressViews[a].setBackgroundState(3, animated, true);
        } else {
            this.photoProgressViews[a].setBackgroundState(-1, animated, true);
        }
    }

    public File lambda$checkProgress$91(TLObject tLObject) {
        return FileLoader.getInstance(this.currentAccount).getPathToAttach(tLObject, true);
    }

    public File lambda$checkProgress$92(TLRPC.Message message) {
        return FileLoader.getInstance(this.currentAccount).getPathToMessage(message);
    }

    public void lambda$checkProgress$94(boolean z, final File file, File file2, FileLoader.FileResolver fileResolver, final int i, MessageObject messageObject, final boolean z2, final boolean z3, final boolean z4, final boolean z5) {
        final File file3;
        ChatActivity chatActivity;
        TLRPC.Document document;
        boolean exists = (z || file == null) ? z : file.exists();
        if (file2 == null && fileResolver != null) {
            file3 = fileResolver.getFile();
        } else {
            r2 = fileResolver != null ? fileResolver.getFile() : null;
            file3 = file2;
        }
        if (!exists && file3 != null) {
            exists = file3.exists();
        }
        if (!exists && r2 != null) {
            exists = r2.exists();
        }
        final boolean z6 = exists;
        if (!z6 && i != 0 && messageObject != null && z2 && DownloadController.getInstance(this.currentAccount).canDownloadMedia(messageObject.messageOwner) != 0 && (((chatActivity = this.parentChatActivity) == null || chatActivity.getCurrentEncryptedChat() == null) && !messageObject.shouldEncryptPhotoOrVideo() && (document = messageObject.getDocument()) != null)) {
            FileLoader.getInstance(this.currentAccount).loadFile(document, messageObject, 0, 10);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$checkProgress$93(i, file, file3, z6, z2, z3, z4, z5);
            }
        });
    }

    public void lambda$checkProgress$93(int i, File file, File file2, boolean z, boolean z2, boolean z3, boolean z4, boolean z5) {
        boolean z6 = false;
        if (this.shownControlsByEnd && !this.actionBarWasShownBeforeByEnd && this.isPlaying) {
            this.photoProgressViews[i].setBackgroundState(3, false, false);
            return;
        }
        if ((file != null || file2 != null) && (z || z2)) {
            if (i != 0 || !this.isPlaying) {
                if (z3 && (!z4 || (i == 0 && this.playerWasPlaying))) {
                    this.photoProgressViews[i].setBackgroundState(3, z5, true);
                } else {
                    this.photoProgressViews[i].setBackgroundState(-1, z5, true);
                }
            }
            if (i == 0 && !this.menuItem.isSubMenuShowing()) {
                if (!z) {
                    if (!FileLoader.getInstance(this.currentAccount).isLoadingFile(this.currentFileNames[i])) {
                        this.menuItem.hideSubItem(7);
                    } else {
                        this.menuItem.showSubItem(7);
                    }
                } else {
                    this.menuItem.hideSubItem(7);
                }
            }
        } else {
            if (z3) {
                if (!FileLoader.getInstance(this.currentAccount).isLoadingFile(this.currentFileNames[i])) {
                    this.photoProgressViews[i].setBackgroundState(2, false, true);
                } else {
                    this.photoProgressViews[i].setBackgroundState(1, false, true);
                }
            } else {
                this.photoProgressViews[i].setBackgroundState(0, z5, true);
            }
            Float fileProgress = ImageLoader.getInstance().getFileProgress(this.currentFileNames[i]);
            if (fileProgress == null) {
                fileProgress = Float.valueOf(0.0f);
            }
            this.photoProgressViews[i].setProgress(fileProgress.floatValue(), false);
        }
        if (i == 0) {
            if (!this.isEmbedVideo && (!this.imagesArrLocals.isEmpty() || (this.currentFileNames[0] != null && this.photoProgressViews[0].backgroundState != 0))) {
                z6 = true;
            }
            this.canZoom = z6;
        }
    }

    public int getSelectionLength() {
        CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
        if (((CaptionContainerView) captionPhotoViewer).editText != null) {
            return captionPhotoViewer.getSelectionLength();
        }
        return 0;
    }

    public final void setIndexToPaintingOverlay(int index, PaintingOverlay paintingOverlay) {
        String str;
        ArrayList arrayList;
        boolean z;
        if (paintingOverlay == null) {
            return;
        }
        paintingOverlay.reset();
        paintingOverlay.setVisibility(8);
        if (this.imagesArrLocals.isEmpty() || index < 0 || index >= this.imagesArrLocals.size()) {
            return;
        }
        Object obj = this.imagesArrLocals.get(index);
        if (obj instanceof MediaController.PhotoEntry) {
            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj;
            boolean z2 = photoEntry.isVideo;
            String str2 = ((MediaController.MediaEditState) photoEntry).paintPath;
            arrayList = ((MediaController.MediaEditState) photoEntry).mediaEntities;
            z = z2;
            str = str2;
        } else {
            if (obj instanceof MediaController.SearchImage) {
                MediaController.SearchImage searchImage = (MediaController.SearchImage) obj;
                String str3 = ((MediaController.MediaEditState) searchImage).paintPath;
                arrayList = ((MediaController.MediaEditState) searchImage).mediaEntities;
                str = str3;
            } else {
                str = null;
                arrayList = null;
            }
            z = false;
        }
        paintingOverlay.setVisibility(0);
        paintingOverlay.setData(str, arrayList, z, false, this.sendPhotoType != 11);
    }

    public final void setIndexToImage(org.telegram.messenger.ImageReceiver r35, int r36, org.telegram.ui.Components.Crop.CropTransform r37) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.setIndexToImage(org.telegram.messenger.ImageReceiver, int, org.telegram.ui.Components.Crop.CropTransform):void");
    }

    public static boolean isShowingImage(MessageObject object) {
        boolean z;
        if (Instance != null && !Instance.pipAnimationInProgress && Instance.isVisible && !Instance.disableShowCheck && object != null) {
            MessageObject messageObject = Instance.currentMessageObject;
            if (messageObject == null && Instance.placeProvider != null) {
                messageObject = Instance.placeProvider.getEditingMessageObject();
            }
            if (messageObject != null && messageObject.getId() == object.getId() && messageObject.getDialogId() == object.getDialogId()) {
                z = true;
                if (z && PipInstance != null) {
                    return PipInstance.isVisible && !PipInstance.disableShowCheck && object != null && PipInstance.currentMessageObject != null && PipInstance.currentMessageObject.getId() == object.getId() && PipInstance.currentMessageObject.getDialogId() == object.getDialogId();
                }
            }
        }
        z = false;
        return z ? z : z;
    }

    public static boolean isPlayingMessageInPip(MessageObject object) {
        return (PipInstance == null || object == null || PipInstance.currentMessageObject == null || PipInstance.currentMessageObject.getId() != object.getId() || PipInstance.currentMessageObject.getDialogId() != object.getDialogId()) ? false : true;
    }

    public static boolean isPlayingMessage(MessageObject object) {
        return (Instance == null || Instance.pipAnimationInProgress || !Instance.isVisible || object == null || Instance.currentMessageObject == null || Instance.currentMessageObject.getId() != object.getId() || Instance.currentMessageObject.getDialogId() != object.getDialogId()) ? false : true;
    }

    public static boolean isShowingImage(TLRPC.FileLocation object) {
        if (Instance == null || !Instance.isVisible || Instance.disableShowCheck || object == null) {
            return false;
        }
        return (Instance.currentFileLocation != null && object.local_id == ((TLRPC.FileLocation) Instance.currentFileLocation.location).local_id && object.volume_id == ((TLRPC.FileLocation) Instance.currentFileLocation.location).volume_id && object.dc_id == Instance.currentFileLocation.dc_id) || (Instance.currentFileLocationVideo != null && object.local_id == ((TLRPC.FileLocation) Instance.currentFileLocationVideo.location).local_id && object.volume_id == ((TLRPC.FileLocation) Instance.currentFileLocationVideo.location).volume_id && object.dc_id == Instance.currentFileLocationVideo.dc_id);
    }

    public static boolean isShowingImage(TLRPC.BotInlineResult object) {
        return (Instance == null || !Instance.isVisible || Instance.disableShowCheck || object == null || Instance.currentBotInlineResult == null || object.id != Instance.currentBotInlineResult.id) ? false : true;
    }

    public static boolean isShowingImage(String object) {
        return (Instance == null || !Instance.isVisible || Instance.disableShowCheck || object == null || !object.equals(Instance.currentPathObject)) ? false : true;
    }

    public void setParentChatActivity(ChatActivity chatActivity) {
        this.parentChatActivity = chatActivity;
    }

    public void setMaxSelectedPhotos(int value, boolean order) {
        this.maxSelectedPhotos = value;
        this.allowOrder = order;
    }

    public void checkCurrentImageVisibility() {
        PlaceProviderObject placeProviderObject = this.currentPlaceObject;
        if (placeProviderObject != null) {
            placeProviderObject.imageReceiver.setVisible(true, true);
        }
        PhotoViewerProvider photoViewerProvider = this.placeProvider;
        PlaceProviderObject placeForPhoto = photoViewerProvider == null ? null : photoViewerProvider.getPlaceForPhoto(this.currentMessageObject, getFileLocation(this.currentFileLocation), this.currentIndex, false);
        this.currentPlaceObject = placeForPhoto;
        if (placeForPhoto != null) {
            placeForPhoto.imageReceiver.setVisible(false, true);
        }
    }

    public boolean openPhoto(final MessageObject messageObject, ChatActivity chatActivity, long dialogId, long mergeDialogId, long topicId, final PhotoViewerProvider provider) {
        return openPhoto(messageObject, null, null, null, null, null, null, 0, provider, chatActivity, dialogId, mergeDialogId, topicId, true, null, null);
    }

    public boolean openPhoto(final MessageObject messageObject, int embedSeekTime, ChatActivity chatActivity, long dialogId, long mergeDialogId, long topicId, final PhotoViewerProvider provider) {
        return openPhoto(messageObject, null, null, null, null, null, null, 0, provider, chatActivity, dialogId, mergeDialogId, topicId, true, null, Integer.valueOf(embedSeekTime));
    }

    public boolean openPhoto(final MessageObject messageObject, long dialogId, long mergeDialogId, long topicId, final PhotoViewerProvider provider, boolean fullScreenVideo) {
        return openPhoto(messageObject, null, null, null, null, null, null, 0, provider, null, dialogId, mergeDialogId, topicId, fullScreenVideo, null, null);
    }

    public boolean openPhoto(final TLRPC.FileLocation fileLocation, final PhotoViewerProvider provider) {
        return openPhoto(null, fileLocation, null, null, null, null, null, 0, provider, null, 0L, 0L, 0L, true, null, null);
    }

    public boolean openPhotoWithVideo(final TLRPC.FileLocation fileLocation, ImageLocation videoLocation, final PhotoViewerProvider provider) {
        return openPhoto(null, fileLocation, null, videoLocation, null, null, null, 0, provider, null, 0L, 0L, 0L, true, null, null);
    }

    public boolean openPhoto(final TLRPC.FileLocation fileLocation, final ImageLocation imageLocation, final PhotoViewerProvider provider) {
        return openPhoto(null, fileLocation, imageLocation, null, null, null, null, 0, provider, null, 0L, 0L, 0L, true, null, null);
    }

    public boolean openPhoto(final ArrayList<MessageObject> messages, final int index, long dialogId, long mergeDialogId, long topicId, final PhotoViewerProvider provider) {
        return openPhoto(messages.get(index), null, null, null, messages, null, null, index, provider, null, dialogId, mergeDialogId, topicId, true, null, null);
    }

    public boolean openPhoto(final ArrayList<SecureDocument> documents, final int index, final PhotoViewerProvider provider) {
        return openPhoto(null, null, null, null, null, documents, null, index, provider, null, 0L, 0L, 0L, true, null, null);
    }

    public boolean openPhoto(int index, PageBlocksAdapter pageBlocksAdapter, PhotoViewerProvider provider) {
        return openPhoto(null, null, null, null, null, null, null, index, provider, null, 0L, 0L, 0L, true, pageBlocksAdapter, null);
    }

    public boolean openPhotoForSelect(final ArrayList<Object> photos, final int index, int type, boolean documentsPicker, final PhotoViewerProvider provider, ChatActivity chatActivity) {
        return openPhotoForSelect(null, null, photos, index, type, documentsPicker, provider, chatActivity);
    }

    public boolean openPhotoForSelect(final TLRPC.FileLocation fileLocation, final ImageLocation imageLocation, final ArrayList<Object> photos, final int index, int type, boolean documentsPicker, final PhotoViewerProvider provider, ChatActivity chatActivity) {
        this.isDocumentsPicker = documentsPicker;
        ImageView imageView = this.pickerViewSendButton;
        if (imageView != null) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
            if (type == 4 || type == 5) {
                this.pickerViewSendButton.setImageResource(R.drawable.msg_input_send_mini);
                layoutParams.bottomMargin = AndroidUtilities.dp(7.33f);
            } else if (type == 1 || type == 3 || type == 10 || type == 11) {
                this.pickerViewSendButton.setImageResource(R.drawable.floating_check);
                this.pickerViewSendButton.setPadding(0, AndroidUtilities.dp(1.0f), 0, 0);
                layoutParams.bottomMargin = AndroidUtilities.dp(7.33f);
            } else {
                this.pickerViewSendButton.setImageResource(R.drawable.msg_input_send_mini);
                layoutParams.bottomMargin = AndroidUtilities.dp(2.33f);
            }
            this.pickerViewSendButton.setLayoutParams(layoutParams);
        }
        if (type != 11 && this.stickerMakerView != null) {
            this.stickerEmpty = false;
            ImageView imageView2 = this.tuneItem;
            if (imageView2 != null) {
                imageView2.setAlpha(1.0f);
            }
            BlurButton blurButton = this.outlineBtn;
            if (blurButton != null) {
                blurButton.setActive(false, false);
            }
            this.stickerMakerView.clean();
            ArrayList<String> arrayList = this.selectedEmojis;
            if (arrayList != null) {
                arrayList.clear();
            }
        }
        if (this.sendPhotoType != 1 && type == 1 && this.isVisible) {
            this.sendPhotoType = type;
            this.doneButtonPressed = false;
            this.actionBarContainer.setTitle("");
            this.actionBarContainer.setSubtitle("", false);
            this.placeProvider = provider;
            this.mergeDialogId = 0L;
            this.currentDialogId = 0L;
            this.selectedPhotosAdapter.notifyDataSetChanged();
            this.pageBlocksAdapter = null;
            if (this.velocityTracker == null) {
                this.velocityTracker = VelocityTracker.obtain();
            }
            this.isVisible = true;
            this.isVisibleOrAnimating = true;
            togglePhotosListView(false, false);
            this.openedFullScreenVideo = false;
            createCropView();
            toggleActionBar(false, false);
            this.seekToProgressPending2 = 0.0f;
            this.skipFirstBufferingProgress = false;
            this.playerInjected = false;
            makeFocusable();
            this.backgroundDrawable.setAlpha(255);
            this.containerView.setAlpha(1.0f);
            onPhotoShow(null, fileLocation, imageLocation, null, null, null, photos, index, null);
            initCropView();
            setCropBitmap();
            return true;
        }
        this.sendPhotoType = type;
        if (type == 11) {
            this.navigationBar.setBackgroundColor(-16777216);
        }
        return openPhoto(null, fileLocation, imageLocation, null, null, null, photos, index, provider, chatActivity, 0L, 0L, 0L, true, null, null);
    }

    public void setTitle(CharSequence title) {
        PhotoViewerActionBarContainer photoViewerActionBarContainer = this.actionBarContainer;
        this.customTitle = title;
        photoViewerActionBarContainer.setTitle(title);
        toggleActionBar(true, false);
    }

    public final void openCurrentPhotoInPaintModeForSelect() {
        final File file;
        final MessageObject messageObject;
        final boolean z;
        final boolean z2;
        if (canSendMediaToParentChatActivity()) {
            MessageObject messageObject2 = this.currentMessageObject;
            File file2 = null;
            if (messageObject2 != null) {
                boolean z3 = messageObject2.canEditMedia() && !this.currentMessageObject.isDocument();
                boolean isVideo = this.currentMessageObject.isVideo();
                if (!TextUtils.isEmpty(this.currentMessageObject.messageOwner.attachPath)) {
                    File file3 = new File(this.currentMessageObject.messageOwner.attachPath);
                    if (file3.exists()) {
                        file2 = file3;
                    }
                }
                if (file2 == null) {
                    file2 = FileLoader.getInstance(this.currentAccount).getPathToMessage(this.currentMessageObject.messageOwner);
                }
                messageObject = messageObject2;
                file = file2;
                z2 = z3;
                z = isVideo;
            } else {
                file = null;
                messageObject = null;
                z = false;
                z2 = false;
            }
            if (file != null && file.exists()) {
                this.savedState = new SavedState(this.currentIndex, new ArrayList(this.imagesArr), this.placeProvider);
                toggleActionBar(false, true, new ActionBarToggleParams().enableStatusBarAnimation(false));
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.this.lambda$openCurrentPhotoInPaintModeForSelect$95(file, z, messageObject, z2);
                    }
                }, r0.animationDuration);
                return;
            }
            showDownloadAlert();
        }
    }

    public void lambda$openCurrentPhotoInPaintModeForSelect$95(File file, boolean z, final MessageObject messageObject, final boolean z2) {
        Pair imageOrientation = AndroidUtilities.getImageOrientation(file);
        int i = this.lastImageId;
        this.lastImageId = i - 1;
        final MediaController.PhotoEntry orientation = new MediaController.PhotoEntry(0, i, 0L, file.getAbsolutePath(), z ? 0 : ((Integer) imageOrientation.first).intValue(), z, 0, 0, 0L).setOrientation(imageOrientation);
        this.sendPhotoType = 2;
        this.doneButtonPressed = false;
        final PhotoViewerProvider photoViewerProvider = this.placeProvider;
        this.placeProvider = new EmptyPhotoViewerProvider() {
            public final ImageReceiver.BitmapHolder thumbHolder;

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

            {
                this.thumbHolder = PhotoViewer.this.centerImage.getBitmapSafe();
            }

            @Override
            public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject2, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
                PhotoViewerProvider photoViewerProvider2 = photoViewerProvider;
                if (photoViewerProvider2 != null) {
                    return photoViewerProvider2.getPlaceForPhoto(messageObject, null, 0, needPreview);
                }
                return null;
            }

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

            @Override
            public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean forceDocument) {
                sendMedia(videoEditedInfo, notify, scheduleDate, false, forceDocument);
            }

            @Override
            public void replaceButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
                MediaController.PhotoEntry photoEntry = orientation;
                if (((MediaController.MediaEditState) photoEntry).isCropped || ((MediaController.MediaEditState) photoEntry).isPainted || ((MediaController.MediaEditState) photoEntry).isFiltered || videoEditedInfo != null || !TextUtils.isEmpty(((MediaController.MediaEditState) photoEntry).caption)) {
                    sendMedia(videoEditedInfo, false, 0, true, false);
                }
            }

            @Override
            public boolean canReplace(int index) {
                return photoViewerProvider != null && z2;
            }

            @Override
            public MessageObject getEditingMessageObject() {
                return messageObject;
            }

            public final void sendMedia(VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate, boolean replace, boolean forceDocument) {
                if (PhotoViewer.this.parentChatActivity != null) {
                    MessageObject messageObject2 = replace ? messageObject : null;
                    if (messageObject2 != null && !TextUtils.isEmpty(((MediaController.MediaEditState) orientation).caption)) {
                        MediaController.PhotoEntry photoEntry = orientation;
                        messageObject2.editingMessage = ((MediaController.MediaEditState) photoEntry).caption;
                        messageObject2.editingMessageEntities = ((MediaController.MediaEditState) photoEntry).entities;
                    }
                    MediaController.PhotoEntry photoEntry2 = orientation;
                    if (photoEntry2.isVideo) {
                        if (videoEditedInfo != null) {
                            AccountInstance accountInstance = PhotoViewer.this.parentChatActivity.getAccountInstance();
                            String str = orientation.path;
                            long dialogId = PhotoViewer.this.parentChatActivity.getDialogId();
                            MessageObject replyMessage = PhotoViewer.this.parentChatActivity.getReplyMessage();
                            MessageObject threadMessage = PhotoViewer.this.parentChatActivity.getThreadMessage();
                            ChatActivity.ReplyQuote replyQuote = PhotoViewer.this.parentChatActivity.getReplyQuote();
                            MediaController.PhotoEntry photoEntry3 = orientation;
                            SendMessagesHelper.prepareSendingVideo(accountInstance, str, videoEditedInfo, dialogId, replyMessage, threadMessage, (TL_stories.StoryItem) null, replyQuote, ((MediaController.MediaEditState) photoEntry3).entities, ((MediaController.MediaEditState) photoEntry3).ttl, messageObject2, notify, scheduleDate, forceDocument, photoEntry3.hasSpoiler, ((MediaController.MediaEditState) photoEntry3).caption, PhotoViewer.this.parentChatActivity.quickReplyShortcut, PhotoViewer.this.parentChatActivity.getQuickReplyId(), 0L);
                            return;
                        }
                        AccountInstance accountInstance2 = PhotoViewer.this.parentChatActivity.getAccountInstance();
                        String str2 = orientation.path;
                        long dialogId2 = PhotoViewer.this.parentChatActivity.getDialogId();
                        MessageObject replyMessage2 = PhotoViewer.this.parentChatActivity.getReplyMessage();
                        MessageObject threadMessage2 = PhotoViewer.this.parentChatActivity.getThreadMessage();
                        ChatActivity.ReplyQuote replyQuote2 = PhotoViewer.this.parentChatActivity.getReplyQuote();
                        MediaController.PhotoEntry photoEntry4 = orientation;
                        SendMessagesHelper.prepareSendingVideo(accountInstance2, str2, (VideoEditedInfo) null, dialogId2, replyMessage2, threadMessage2, (TL_stories.StoryItem) null, replyQuote2, ((MediaController.MediaEditState) photoEntry4).entities, ((MediaController.MediaEditState) photoEntry4).ttl, messageObject2, notify, scheduleDate, forceDocument, photoEntry4.hasSpoiler, ((MediaController.MediaEditState) photoEntry4).caption, PhotoViewer.this.parentChatActivity.quickReplyShortcut, PhotoViewer.this.parentChatActivity.getQuickReplyId(), 0L);
                        return;
                    }
                    if (((MediaController.MediaEditState) photoEntry2).imagePath != null) {
                        AccountInstance accountInstance3 = PhotoViewer.this.parentChatActivity.getAccountInstance();
                        MediaController.PhotoEntry photoEntry5 = orientation;
                        String str3 = ((MediaController.MediaEditState) photoEntry5).imagePath;
                        String str4 = ((MediaController.MediaEditState) photoEntry5).thumbPath;
                        long dialogId3 = PhotoViewer.this.parentChatActivity.getDialogId();
                        MessageObject replyMessage3 = PhotoViewer.this.parentChatActivity.getReplyMessage();
                        MessageObject threadMessage3 = PhotoViewer.this.parentChatActivity.getThreadMessage();
                        ChatActivity.ReplyQuote replyQuote3 = PhotoViewer.this.parentChatActivity.getReplyQuote();
                        MediaController.PhotoEntry photoEntry6 = orientation;
                        SendMessagesHelper.prepareSendingPhoto(accountInstance3, str3, str4, (Uri) null, dialogId3, replyMessage3, threadMessage3, (TL_stories.StoryItem) null, replyQuote3, ((MediaController.MediaEditState) photoEntry6).entities, ((MediaController.MediaEditState) photoEntry6).stickers, (InputContentInfoCompat) null, ((MediaController.MediaEditState) photoEntry6).ttl, messageObject2, videoEditedInfo, notify, scheduleDate, 0, forceDocument, ((MediaController.MediaEditState) photoEntry6).caption, PhotoViewer.this.parentChatActivity.quickReplyShortcut, PhotoViewer.this.parentChatActivity.getQuickReplyId(), 0L);
                        return;
                    }
                    if (photoEntry2.path != null) {
                        AccountInstance accountInstance4 = PhotoViewer.this.parentChatActivity.getAccountInstance();
                        MediaController.PhotoEntry photoEntry7 = orientation;
                        String str5 = photoEntry7.path;
                        String str6 = ((MediaController.MediaEditState) photoEntry7).thumbPath;
                        long dialogId4 = PhotoViewer.this.parentChatActivity.getDialogId();
                        MessageObject replyMessage4 = PhotoViewer.this.parentChatActivity.getReplyMessage();
                        MessageObject threadMessage4 = PhotoViewer.this.parentChatActivity.getThreadMessage();
                        ChatActivity.ReplyQuote replyQuote4 = PhotoViewer.this.parentChatActivity.getReplyQuote();
                        MediaController.PhotoEntry photoEntry8 = orientation;
                        SendMessagesHelper.prepareSendingPhoto(accountInstance4, str5, str6, (Uri) null, dialogId4, replyMessage4, threadMessage4, (TL_stories.StoryItem) null, replyQuote4, ((MediaController.MediaEditState) photoEntry8).entities, ((MediaController.MediaEditState) photoEntry8).stickers, (InputContentInfoCompat) null, ((MediaController.MediaEditState) photoEntry8).ttl, messageObject2, videoEditedInfo, notify, scheduleDate, 0, forceDocument, ((MediaController.MediaEditState) photoEntry8).caption, PhotoViewer.this.parentChatActivity.quickReplyShortcut, PhotoViewer.this.parentChatActivity.getQuickReplyId(), 0L);
                    }
                }
            }
        };
        this.selectedPhotosAdapter.notifyDataSetChanged();
        if (this.velocityTracker == null) {
            this.velocityTracker = VelocityTracker.obtain();
        }
        this.aboutToSwitchTo = 3;
        togglePhotosListView(false, false);
        toggleActionBar(true, false);
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity != null && chatActivity.getChatActivityEnterView() != null && this.parentChatActivity.isKeyboardVisible()) {
            this.parentChatActivity.getChatActivityEnterView().closeKeyboard();
        } else {
            makeFocusable();
        }
        this.backgroundDrawable.setAlpha(255);
        this.containerView.setAlpha(1.0f);
        onPhotoShow(null, null, null, null, null, null, Collections.singletonList(orientation), 0, null);
        this.pickerView.setTranslationY(AndroidUtilities.dp(this.isCurrentVideo ? 154.0f : 96.0f));
        this.pickerViewSendButton.setTranslationY(AndroidUtilities.dp(this.isCurrentVideo ? 154.0f : 96.0f));
        this.actionBar.setTranslationY(-r0.getHeight());
        this.captionTextViewSwitcher.setTranslationY(AndroidUtilities.dp(this.isCurrentVideo ? 154.0f : 96.0f));
        createPaintView();
        switchToPaintMode();
        this.aboutToSwitchTo = 0;
    }

    public final boolean checkAnimation() {
        if (this.animationInProgress != 0) {
            invalidateBlur();
            if (Math.abs(this.transitionAnimationStartTime - System.currentTimeMillis()) >= 500) {
                Runnable runnable = this.animationEndRunnable;
                if (runnable != null) {
                    runnable.run();
                    this.animationEndRunnable = null;
                }
                this.animationInProgress = 0;
            }
        }
        return this.animationInProgress != 0;
    }

    public final void setCropBitmap() {
        VideoEditTextureView videoEditTextureView;
        if (this.cropInitied || this.sendPhotoType != 1) {
            return;
        }
        if (!this.isCurrentVideo || ((videoEditTextureView = this.videoTextureView) != null && videoEditTextureView.getVideoWidth() > 0 && videoEditTextureView.getVideoHeight() > 0)) {
            this.cropInitied = true;
            Bitmap bitmap = this.centerImage.getBitmap();
            int orientation = this.centerImage.getOrientation();
            if (bitmap == null) {
                bitmap = this.animatingImageView.getBitmap();
                orientation = this.animatingImageView.getOrientation();
            }
            Bitmap bitmap2 = bitmap;
            int i = orientation;
            if (bitmap2 == null && this.videoTextureView == null) {
                return;
            }
            this.photoCropView.setBitmap(bitmap2, i, false, false, this.paintingOverlay, this.cropTransform, this.isCurrentVideo ? (VideoEditTextureView) this.videoTextureView : null, this.editState.cropState);
        }
    }

    public final void initCropView() {
        PhotoCropView photoCropView = this.photoCropView;
        if (photoCropView == null) {
            return;
        }
        photoCropView.setBitmap((Bitmap) null, 0, false, false, (PaintingOverlay) null, (CropTransform) null, (VideoEditTextureView) null, (MediaController.CropState) null);
        if (this.sendPhotoType != 1) {
            return;
        }
        this.photoCropView.onAppear();
        this.photoCropView.setVisibility(0);
        this.photoCropView.setAlpha(1.0f);
        this.photoCropView.onAppeared();
        this.padImageForHorizontalInsets = true;
    }

    public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ImageLocation imageLocation, final ImageLocation videoLocation, final ArrayList<MessageObject> messages, final ArrayList<SecureDocument> documents, final ArrayList<Object> photos, final int index, final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId, long topicId, boolean fullScreenVideo, PageBlocksAdapter pageBlocksAdapter, final Integer embedSeekTime) {
        TLRPC.Message message;
        PhotoViewerProvider photoViewerProvider;
        int i = 0;
        if (this.parentActivity != null && !this.isVisible && ((provider != null || !checkAnimation()) && (messageObject != null || fileLocation != null || messages != null || photos != null || documents != null || imageLocation != null || pageBlocksAdapter != null))) {
            PlaceProviderObject placeForPhoto = provider.getPlaceForPhoto(messageObject, fileLocation, index, true);
            if (Build.VERSION.SDK_INT < 21) {
                Rect rect = this.insets;
                rect.top = AndroidUtilities.statusBarHeight;
                rect.bottom = AndroidUtilities.navigationBarHeight;
            }
            WindowManager windowManager = (WindowManager) this.parentActivity.getSystemService("window");
            if (this.attachedToWindow) {
                try {
                    windowManager.removeView(this.windowView);
                    onHideView();
                } catch (Exception unused) {
                }
            }
            try {
                WindowManager.LayoutParams layoutParams = this.windowLayoutParams;
                layoutParams.type = 99;
                if (Build.VERSION.SDK_INT >= 21) {
                    layoutParams.flags = -2147286784;
                } else {
                    layoutParams.flags = 131072;
                }
                if (!(chatActivity == null || chatActivity.getCurrentEncryptedChat() == null) || ((this.avatarsDialogId != 0 && MessagesController.getInstance(this.currentAccount).isChatNoForwards(-this.avatarsDialogId)) || ((messageObject != null && (MessagesController.getInstance(this.currentAccount).isChatNoForwards(messageObject.getChatId()) || ((message = messageObject.messageOwner) != null && message.noforwards))) || (messageObject != null && messageObject.hasRevealedExtendedMedia())))) {
                    this.windowLayoutParams.flags |= 8192;
                } else {
                    this.windowLayoutParams.flags &= -8193;
                }
                this.windowLayoutParams.softInputMode = 272;
                this.windowView.setFocusable(false);
                this.containerView.setFocusable(false);
                windowManager.addView(this.windowView, this.windowLayoutParams);
                onShowView();
                this.hasCaptionForAllMedia = false;
                this.doneButtonPressed = false;
                this.closePhotoAfterSelect = true;
                this.allowShowFullscreenButton = true;
                this.usedSurfaceView = false;
                this.parentChatActivity = chatActivity;
                this.lastTitle = null;
                this.isEmbedVideo = embedSeekTime != null;
                this.actionBarContainer.setTitle("");
                this.actionBarContainer.setSubtitle("", false);
                PhotoCountView photoCountView = this.countView;
                if (photoCountView != null) {
                    photoCountView.set(0, 0, false);
                    this.countView.updateShow(false, false);
                }
                this.actionBar.setTitleScrollNonFitText(false);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.fileLoadFailed);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.fileLoaded);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.customStickerCreated);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.fileLoadProgressChanged);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.mediaCountDidLoad);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.mediaDidLoad);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.dialogPhotosUpdate);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.messagesDeleted);
                NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiLoaded);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.filePreparingFailed);
                NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.fileNewChunkAvailable);
                this.placeProvider = provider;
                this.mergeDialogId = mDialogId;
                this.currentDialogId = dialogId;
                this.currentFilterTag = chatActivity != null ? chatActivity.getFilterTag() : null;
                this.currentFilterQuery = chatActivity != null ? chatActivity.getFilterQuery() : null;
                this.currentFiltered = chatActivity != null && chatActivity.isFiltered();
                this.topicId = topicId;
                this.selectedPhotosAdapter.notifyDataSetChanged();
                this.pageBlocksAdapter = pageBlocksAdapter;
                this.setAvatarFor = null;
                if (this.velocityTracker == null) {
                    this.velocityTracker = VelocityTracker.obtain();
                }
                this.isVisible = true;
                this.isVisibleOrAnimating = true;
                togglePhotosListView(false, false);
                boolean z = !fullScreenVideo;
                this.openedFullScreenVideo = z;
                if (z) {
                    toggleActionBar(false, false);
                } else if (this.sendPhotoType == 1) {
                    createCropView();
                    toggleActionBar(false, false);
                } else {
                    toggleActionBar(true, false);
                }
                this.windowView.setClipChildren(false);
                this.navigationBar.setVisibility(0);
                this.seekToProgressPending2 = 0.0f;
                this.skipFirstBufferingProgress = false;
                this.playerInjected = false;
                if (placeForPhoto != null) {
                    this.disableShowCheck = true;
                    this.animationInProgress = 1;
                    if (messageObject != null) {
                        AnimatedFileDrawable animation = placeForPhoto.allowTakeAnimation ? placeForPhoto.imageReceiver.getAnimation() : null;
                        this.currentAnimation = animation;
                        if (animation != null) {
                            if (messageObject.isVideo() || this.playGifAsVideo) {
                                placeForPhoto.imageReceiver.setAllowStartAnimation(false);
                                placeForPhoto.imageReceiver.stopAnimation();
                                if (MediaController.getInstance().isPlayingMessage(messageObject)) {
                                    this.seekToProgressPending2 = messageObject.audioProgress;
                                }
                                this.skipFirstBufferingProgress = this.injectingVideoPlayer == null && !FileLoader.getInstance(messageObject.currentAccount).isLoadingVideo(messageObject.getDocument(), true) && (this.currentAnimation.hasBitmap() || !FileLoader.getInstance(messageObject.currentAccount).isLoadingVideo(messageObject.getDocument(), false));
                                this.currentAnimation = null;
                            } else if (messageObject.getWebPagePhotos((ArrayList) null, (ArrayList) null).size() > 1) {
                                this.currentAnimation = null;
                            }
                        }
                    } else if (pageBlocksAdapter != null) {
                        this.currentAnimation = placeForPhoto.imageReceiver.getAnimation();
                    }
                    float f = 0.0f;
                    onPhotoShow(messageObject, fileLocation, imageLocation, videoLocation, messages, documents, photos, index, placeForPhoto);
                    if (this.sendPhotoType == 1) {
                        this.photoCropView.setVisibility(0);
                        this.photoCropView.setAlpha(0.0f);
                        this.photoCropView.setFreeform(false);
                    }
                    RectF drawRegion = placeForPhoto.imageReceiver.getDrawRegion();
                    float f2 = drawRegion.left;
                    float f3 = drawRegion.top;
                    int orientation = placeForPhoto.imageReceiver.getOrientation();
                    int animatedOrientation = placeForPhoto.imageReceiver.getAnimatedOrientation();
                    if (animatedOrientation != 0) {
                        orientation = animatedOrientation;
                    }
                    ClippingImageView[] animatingImageViews = getAnimatingImageViews(placeForPhoto);
                    this.clippingImageProgress = 1.0f;
                    for (int i2 = 0; i2 < animatingImageViews.length; i2++) {
                        animatingImageViews[i2].setAnimationValues(this.animationValues);
                        animatingImageViews[i2].setVisibility(0);
                        animatingImageViews[i2].setRadius(placeForPhoto.radius);
                        animatingImageViews[i2].setOrientation(orientation, placeForPhoto.imageReceiver.getInvert());
                        animatingImageViews[i2].setImageBitmap(placeForPhoto.thumb);
                    }
                    initCropView();
                    if (this.sendPhotoType == 1) {
                        this.photoCropView.setAspectRatio(1.0f);
                    }
                    ViewGroup.LayoutParams layoutParams2 = this.animatingImageView.getLayoutParams();
                    layoutParams2.width = (int) drawRegion.width();
                    int height = (int) drawRegion.height();
                    layoutParams2.height = height;
                    if (layoutParams2.width <= 0) {
                        layoutParams2.width = 100;
                    }
                    if (height <= 0) {
                        layoutParams2.height = 100;
                    }
                    while (i < animatingImageViews.length) {
                        if (animatingImageViews.length > 1) {
                            animatingImageViews[i].setAlpha(f);
                        } else {
                            animatingImageViews[i].setAlpha(1.0f);
                        }
                        animatingImageViews[i].setPivotX(f);
                        animatingImageViews[i].setPivotY(f);
                        animatingImageViews[i].setScaleX(placeForPhoto.scale);
                        animatingImageViews[i].setScaleY(placeForPhoto.scale);
                        animatingImageViews[i].setTranslationX(placeForPhoto.viewX + (drawRegion.left * placeForPhoto.scale));
                        animatingImageViews[i].setTranslationY(placeForPhoto.viewY + (drawRegion.top * placeForPhoto.scale));
                        animatingImageViews[i].setLayoutParams(layoutParams2);
                        i++;
                        f = 0.0f;
                    }
                    this.windowView.getViewTreeObserver().addOnPreDrawListener(new AnonymousClass75(animatingImageViews, layoutParams2, f2, placeForPhoto, f3, provider, photos, embedSeekTime));
                } else {
                    if (photos != null && this.sendPhotoType != 3 && ((photoViewerProvider = this.placeProvider) == null || !photoViewerProvider.closeKeyboard())) {
                        makeFocusable();
                    }
                    this.containerView.setAlpha(1.0f);
                    onPhotoShow(messageObject, fileLocation, imageLocation, videoLocation, messages, documents, photos, index, placeForPhoto);
                    initCropView();
                    setCropBitmap();
                    ChatActivity chatActivity2 = this.parentChatActivity;
                    if (chatActivity2 != null) {
                        UndoView undoView = chatActivity2.getUndoView();
                        if (undoView != null) {
                            undoView.hide(false, 1);
                        }
                        this.parentChatActivity.getFragmentView().invalidate();
                    }
                    this.windowView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                        @Override
                        public boolean onPreDraw() {
                            PhotoViewer.this.windowView.getViewTreeObserver().removeOnPreDrawListener(this);
                            PhotoViewer.this.actionBar.setTranslationY(-AndroidUtilities.dp(32.0f));
                            ViewPropertyAnimator duration = PhotoViewer.this.actionBar.animate().alpha(1.0f).translationY(0.0f).setDuration(150L);
                            TimeInterpolator timeInterpolator = CubicBezierInterpolator.DEFAULT;
                            duration.setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.checkImageView.setTranslationY(-AndroidUtilities.dp(32.0f));
                            PhotoViewer.this.checkImageView.animate().alpha(1.0f).translationY(0.0f).setDuration(150L).setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.photosCounterView.setTranslationY(-AndroidUtilities.dp(32.0f));
                            PhotoViewer.this.photosCounterView.animate().alpha(1.0f).translationY(0.0f).setDuration(150L).setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.pickerView.setTranslationY(AndroidUtilities.dp(32.0f));
                            PhotoViewer.this.pickerView.animate().alpha(1.0f).setDuration(150L).setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.pickerViewSendButton.setTranslationY(AndroidUtilities.dp(32.0f));
                            PhotoViewer.this.pickerViewSendButton.setAlpha(0.0f);
                            PhotoViewer.this.pickerViewSendButton.animate().alpha(1.0f).translationY(0.0f).setDuration(150L).setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.videoPreviewFrame.setTranslationY(AndroidUtilities.dp(32.0f));
                            PhotoViewer.this.videoPreviewFrame.animate().alpha(1.0f).translationY(0.0f).setDuration(150L).setInterpolator(timeInterpolator).start();
                            PhotoViewer.this.containerView.setAlpha(0.0f);
                            PhotoViewer.this.backgroundDrawable.setAlpha(0);
                            PhotoViewer.this.animationInProgress = 4;
                            PhotoViewer.this.containerView.invalidate();
                            AnimatorSet animatorSet = new AnimatorSet();
                            ObjectAnimator duration2 = ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.TRANSLATION_Y, PhotoViewer.this.pickerView.getTranslationY(), 0.0f).setDuration(220L);
                            duration2.setInterpolator(timeInterpolator);
                            ObjectAnimator duration3 = ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.ALPHA, 1.0f).setDuration(220L);
                            duration3.setInterpolator(timeInterpolator);
                            animatorSet.playTogether(ObjectAnimator.ofFloat(PhotoViewer.this.containerView, (Property<FrameLayoutDrawer, Float>) View.ALPHA, 0.0f, 1.0f).setDuration(220L), ObjectAnimator.ofFloat(PhotoViewer.this.navigationBar, (Property<View, Float>) View.ALPHA, 0.0f, 1.0f).setDuration(220L), duration2, duration3);
                            animatorSet.addListener(new AnimatorListenerAdapter() {
                                @Override
                                public void onAnimationStart(Animator animation2) {
                                    super.onAnimationStart(animation2);
                                    PhotoViewerProvider photoViewerProvider2 = provider;
                                    if (photoViewerProvider2 != null) {
                                        photoViewerProvider2.onPreOpen();
                                    }
                                }

                                @Override
                                public void onAnimationEnd(Animator animation2) {
                                    super.onAnimationEnd(animation2);
                                    PhotoViewer.this.animationInProgress = 0;
                                    PhotoViewer.this.invalidateBlur();
                                    PhotoViewer.this.backgroundDrawable.setAlpha(255);
                                    PhotoViewer.this.containerView.invalidate();
                                    PhotoViewer.this.pickerView.setTranslationY(0.0f);
                                    if (PhotoViewer.this.isEmbedVideo) {
                                        AnonymousClass76 anonymousClass76 = AnonymousClass76.this;
                                        PhotoViewer.this.initEmbedVideo(embedSeekTime.intValue());
                                    }
                                    PhotoViewerProvider photoViewerProvider2 = provider;
                                    if (photoViewerProvider2 != null) {
                                        photoViewerProvider2.onOpen();
                                    }
                                }
                            });
                            animatorSet.start();
                            return true;
                        }
                    });
                }
                AccessibilityManager accessibilityManager = (AccessibilityManager) this.parentActivity.getSystemService("accessibility");
                if (accessibilityManager.isTouchExplorationEnabled()) {
                    AccessibilityEvent obtain = AccessibilityEvent.obtain();
                    obtain.setEventType(16384);
                    obtain.getText().add(LocaleController.getString("AccDescrPhotoViewer", R.string.AccDescrPhotoViewer));
                    accessibilityManager.sendAccessibilityEvent(obtain);
                }
                return true;
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        return false;
    }

    public class AnonymousClass75 implements ViewTreeObserver.OnPreDrawListener {
        public final ClippingImageView[] val$animatingImageViews;
        public final Integer val$embedSeekTime;
        public final ViewGroup.LayoutParams val$layoutParams;
        public final float val$left;
        public final PlaceProviderObject val$object;
        public final ArrayList val$photos;
        public final PhotoViewerProvider val$provider;
        public final float val$top;

        public AnonymousClass75(final ClippingImageView[] val$animatingImageViews, final ViewGroup.LayoutParams val$layoutParams, final float val$left, final PlaceProviderObject val$object, final float val$top, final PhotoViewerProvider val$provider, final ArrayList val$photos, final Integer val$embedSeekTime) {
            this.val$animatingImageViews = val$animatingImageViews;
            this.val$layoutParams = val$layoutParams;
            this.val$left = val$left;
            this.val$object = val$object;
            this.val$top = val$top;
            this.val$provider = val$provider;
            this.val$photos = val$photos;
            this.val$embedSeekTime = val$embedSeekTime;
        }

        @Override
        public boolean onPreDraw() {
            float f;
            float f2;
            float measuredWidth;
            ClippingImageView[] clippingImageViewArr;
            int i;
            View[] viewArr = this.val$animatingImageViews;
            if (viewArr.length > 1) {
                viewArr[1].setAlpha(1.0f);
                this.val$animatingImageViews[1].setAdditionalTranslationX(-PhotoViewer.this.getLeftInset());
            }
            View[] viewArr2 = this.val$animatingImageViews;
            viewArr2[0].setTranslationX(viewArr2[0].getTranslationX() + PhotoViewer.this.getLeftInset());
            PhotoViewer.this.windowView.getViewTreeObserver().removeOnPreDrawListener(this);
            if (PhotoViewer.this.sendPhotoType == 1) {
                float f3 = PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0;
                float measuredHeight = (PhotoViewer.this.photoCropView.getMeasuredHeight() - AndroidUtilities.dp(64.0f)) - f3;
                float measuredWidth2 = PhotoViewer.this.photoCropView.getMeasuredWidth() / 2.0f;
                float f4 = f3 + (measuredHeight / 2.0f);
                float min = (Math.min(PhotoViewer.this.photoCropView.getMeasuredWidth(), measuredHeight) - (AndroidUtilities.dp(16.0f) * 2)) / 2.0f;
                float f5 = f4 - min;
                ViewGroup.LayoutParams layoutParams = this.val$layoutParams;
                float f6 = (f4 + min) - f5;
                f = Math.max(((measuredWidth2 + min) - (measuredWidth2 - min)) / layoutParams.width, f6 / layoutParams.height);
                f2 = f5 + ((f6 - (this.val$layoutParams.height * f)) / 2.0f);
                measuredWidth = ((((PhotoViewer.this.windowView.getMeasuredWidth() - PhotoViewer.this.getLeftInset()) - PhotoViewer.this.getRightInset()) - (this.val$layoutParams.width * f)) / 2.0f) + PhotoViewer.this.getLeftInset();
            } else {
                float min2 = Math.min(PhotoViewer.this.windowView.getMeasuredWidth() / this.val$layoutParams.width, (AndroidUtilities.displaySize.y + (PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0)) / this.val$layoutParams.height);
                if (PhotoViewer.this.sendPhotoType == 11) {
                    min2 *= PhotoViewer.this.scale1();
                }
                f = min2;
                f2 = ((AndroidUtilities.displaySize.y + (PhotoViewer.this.isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0)) - (this.val$layoutParams.height * f)) / 2.0f;
                measuredWidth = (PhotoViewer.this.windowView.getMeasuredWidth() - (this.val$layoutParams.width * f)) / 2.0f;
                PhotoViewer.this.rotate = 0.0f;
                PhotoViewer.this.animateToRotate = 0.0f;
            }
            int abs = (int) Math.abs(this.val$left - this.val$object.imageReceiver.getImageX());
            int abs2 = (int) Math.abs(this.val$top - this.val$object.imageReceiver.getImageY());
            if (this.val$object.imageReceiver.isAspectFit()) {
                abs = 0;
            }
            int[] iArr = new int[2];
            this.val$object.parentView.getLocationInWindow(iArr);
            int i2 = iArr[1];
            int i3 = Build.VERSION.SDK_INT;
            float f7 = i2 - ((i3 >= 21 || PhotoViewer.this.inBubbleMode) ? 0 : AndroidUtilities.statusBarHeight);
            int i4 = this.val$object.viewY;
            float f8 = this.val$top;
            int i5 = (int) ((f7 - (i4 + f8)) + r13.clipTopAddition);
            if (i5 < 0) {
                i5 = 0;
            }
            int height = (int) ((((i4 + f8) + this.val$layoutParams.height) - ((iArr[1] + r13.parentView.getHeight()) - ((i3 >= 21 || PhotoViewer.this.inBubbleMode) ? 0 : AndroidUtilities.statusBarHeight))) + this.val$object.clipBottomAddition);
            if (height < 0) {
                height = 0;
            }
            int max = Math.max(i5, abs2);
            int max2 = Math.max(height, abs2);
            PhotoViewer.this.animationValues[0][0] = PhotoViewer.this.animatingImageView.getScaleX();
            PhotoViewer.this.animationValues[0][1] = PhotoViewer.this.animatingImageView.getScaleY();
            PhotoViewer.this.animationValues[0][2] = PhotoViewer.this.animatingImageView.getTranslationX();
            PhotoViewer.this.animationValues[0][3] = PhotoViewer.this.animatingImageView.getTranslationY();
            float f9 = abs;
            PhotoViewer.this.animationValues[0][4] = this.val$object.scale * f9;
            PhotoViewer.this.animationValues[0][5] = max * this.val$object.scale;
            PhotoViewer.this.animationValues[0][6] = max2 * this.val$object.scale;
            int[] radius = PhotoViewer.this.animatingImageView.getRadius();
            for (int i6 = 0; i6 < 4; i6++) {
                PhotoViewer.this.animationValues[0][i6 + 7] = radius != null ? radius[i6] : 0.0f;
            }
            PhotoViewer.this.animationValues[0][11] = abs2 * this.val$object.scale;
            PhotoViewer.this.animationValues[0][12] = f9 * this.val$object.scale;
            PhotoViewer.this.animationValues[1][0] = f;
            PhotoViewer.this.animationValues[1][1] = f;
            PhotoViewer.this.animationValues[1][2] = measuredWidth;
            PhotoViewer.this.animationValues[1][3] = f2;
            PhotoViewer.this.animationValues[1][4] = 0.0f;
            PhotoViewer.this.animationValues[1][5] = 0.0f;
            PhotoViewer.this.animationValues[1][6] = 0.0f;
            PhotoViewer.this.animationValues[1][7] = 0.0f;
            PhotoViewer.this.animationValues[1][8] = 0.0f;
            PhotoViewer.this.animationValues[1][9] = 0.0f;
            PhotoViewer.this.animationValues[1][10] = 0.0f;
            PhotoViewer.this.animationValues[1][11] = 0.0f;
            PhotoViewer.this.animationValues[1][12] = 0.0f;
            int i7 = 0;
            while (true) {
                ClippingImageView[] clippingImageViewArr2 = this.val$animatingImageViews;
                if (i7 >= clippingImageViewArr2.length) {
                    break;
                }
                clippingImageViewArr2[i7].setAnimationProgress(0.0f);
                i7++;
            }
            PhotoViewer.this.backgroundDrawable.setAlpha(0);
            PhotoViewer.this.containerView.setAlpha(0.0f);
            PhotoViewer.this.navigationBar.setAlpha(0.0f);
            PhotoViewerProvider photoViewerProvider = this.val$provider;
            if (photoViewerProvider != null) {
                photoViewerProvider.onPreOpen();
            }
            PhotoViewer photoViewer = PhotoViewer.this;
            final ClippingImageView[] clippingImageViewArr3 = this.val$animatingImageViews;
            final ArrayList arrayList = this.val$photos;
            final Integer num = this.val$embedSeekTime;
            final PhotoViewerProvider photoViewerProvider2 = this.val$provider;
            photoViewer.animationEndRunnable = new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass75.this.lambda$onPreDraw$0(clippingImageViewArr3, arrayList, num, photoViewerProvider2);
                }
            };
            if (!PhotoViewer.this.openedFullScreenVideo) {
                final AnimatorSet animatorSet = new AnimatorSet();
                int i8 = PhotoViewer.this.sendPhotoType != 1 ? 2 : 3;
                ClippingImageView[] clippingImageViewArr4 = this.val$animatingImageViews;
                ArrayList arrayList2 = new ArrayList(i8 + clippingImageViewArr4.length + (clippingImageViewArr4.length > 1 ? 1 : 0));
                int i9 = 0;
                while (true) {
                    clippingImageViewArr = this.val$animatingImageViews;
                    if (i9 >= clippingImageViewArr.length) {
                        break;
                    }
                    ObjectAnimator ofFloat = ObjectAnimator.ofFloat(clippingImageViewArr[i9], (Property<ClippingImageView, Float>) AnimationProperties.CLIPPING_IMAGE_VIEW_PROGRESS, 0.0f, 1.0f);
                    if (i9 == 0) {
                        ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                            @Override
                            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                                PhotoViewer.AnonymousClass75.this.lambda$onPreDraw$1(valueAnimator);
                            }
                        });
                    }
                    arrayList2.add(ofFloat);
                    i9++;
                }
                if (clippingImageViewArr.length > 1) {
                    i = 2;
                    arrayList2.add(ObjectAnimator.ofFloat(PhotoViewer.this.animatingImageView, (Property<ClippingImageView, Float>) View.ALPHA, 0.0f, 1.0f));
                } else {
                    i = 2;
                }
                int[] iArr2 = new int[i];
                
                iArr2[0] = 0;
                iArr2[1] = 255;
                arrayList2.add(ObjectAnimator.ofInt(PhotoViewer.this.backgroundDrawable, (Property<BackgroundDrawable, Integer>) AnimationProperties.COLOR_DRAWABLE_ALPHA, iArr2));
                float[] fArr = new float[i];
                
                fArr[0] = 0.0f;
                fArr[1] = 1.0f;
                arrayList2.add(ObjectAnimator.ofFloat(PhotoViewer.this.containerView, (Property<FrameLayoutDrawer, Float>) View.ALPHA, fArr));
                float[] fArr2 = new float[i];
                
                fArr2[0] = 0.0f;
                fArr2[1] = 1.0f;
                arrayList2.add(ObjectAnimator.ofFloat(PhotoViewer.this.navigationBar, (Property<View, Float>) View.ALPHA, fArr2));
                if (PhotoViewer.this.sendPhotoType == 1) {
                    float[] fArr3 = new float[i];
                    
                    fArr3[0] = 0.0f;
                    fArr3[1] = 1.0f;
                    arrayList2.add(ObjectAnimator.ofFloat(PhotoViewer.this.photoCropView, (Property<PhotoCropView, Float>) View.ALPHA, fArr3));
                }
                animatorSet.playTogether(arrayList2);
                animatorSet.setDuration(200L);
                animatorSet.addListener(new AnonymousClass1());
                PhotoViewer.this.containerView.setLayerType(2, null);
                PhotoViewer.this.setCaptionHwLayerEnabled(false);
                PhotoViewer.this.transitionAnimationStartTime = System.currentTimeMillis();
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass75.this.lambda$onPreDraw$2(animatorSet);
                    }
                });
            } else {
                if (PhotoViewer.this.animationEndRunnable != null) {
                    PhotoViewer.this.animationEndRunnable.run();
                    PhotoViewer.this.animationEndRunnable = null;
                }
                PhotoViewer.this.containerView.setAlpha(1.0f);
                PhotoViewer.this.backgroundDrawable.setAlpha(255);
                int i10 = 0;
                while (true) {
                    ClippingImageView[] clippingImageViewArr5 = this.val$animatingImageViews;
                    if (i10 >= clippingImageViewArr5.length) {
                        break;
                    }
                    clippingImageViewArr5[i10].setAnimationProgress(1.0f);
                    i10++;
                }
                if (PhotoViewer.this.sendPhotoType == 1) {
                    PhotoViewer.this.photoCropView.setAlpha(1.0f);
                }
            }
            BackgroundDrawable backgroundDrawable = PhotoViewer.this.backgroundDrawable;
            final PlaceProviderObject placeProviderObject = this.val$object;
            backgroundDrawable.drawRunnable = new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass75.this.lambda$onPreDraw$3(placeProviderObject);
                }
            };
            if (PhotoViewer.this.parentChatActivity != null && PhotoViewer.this.parentChatActivity.getFragmentView() != null) {
                UndoView undoView = PhotoViewer.this.parentChatActivity.getUndoView();
                if (undoView != null) {
                    undoView.hide(false, 1);
                }
                PhotoViewer.this.parentChatActivity.getFragmentView().invalidate();
            }
            return true;
        }

        public void lambda$onPreDraw$0(ClippingImageView[] clippingImageViewArr, ArrayList arrayList, Integer num, PhotoViewerProvider photoViewerProvider) {
            PhotoViewer.this.animationEndRunnable = null;
            if (PhotoViewer.this.containerView == null || PhotoViewer.this.windowView == null) {
                return;
            }
            PhotoViewer.this.containerView.setLayerType(0, null);
            PhotoViewer.this.animationInProgress = 0;
            PhotoViewer.this.invalidateBlur();
            PhotoViewer.this.transitionAnimationStartTime = 0L;
            PhotoViewer.this.leftCropState = null;
            PhotoViewer.this.leftCropTransform.setViewTransform(false);
            PhotoViewer.this.rightCropState = null;
            PhotoViewer.this.rightCropTransform.setViewTransform(false);
            PhotoViewer.this.setImages();
            PhotoViewer.this.setCropBitmap();
            PhotoViewer.this.containerView.invalidate();
            for (ClippingImageView clippingImageView : clippingImageViewArr) {
                clippingImageView.setVisibility(8);
            }
            if (PhotoViewer.this.showAfterAnimation != null) {
                PhotoViewer.this.showAfterAnimation.imageReceiver.setVisible(true, true);
            }
            if (PhotoViewer.this.hideAfterAnimation != null) {
                PhotoViewer.this.hideAfterAnimation.imageReceiver.setVisible(false, true);
            }
            if (arrayList != null && PhotoViewer.this.sendPhotoType != 3 && PhotoViewer.this.sendPhotoType != 1 && (PhotoViewer.this.placeProvider == null || !PhotoViewer.this.placeProvider.closeKeyboard())) {
                PhotoViewer.this.makeFocusable();
            }
            if (PhotoViewer.this.videoPlayer != null && PhotoViewer.this.videoPlayer.isPlaying() && PhotoViewer.this.isCurrentVideo && !PhotoViewer.this.imagesArrLocals.isEmpty()) {
                PhotoViewer photoViewer = PhotoViewer.this;
                photoViewer.seekAnimatedStickersTo(photoViewer.videoPlayer.getCurrentPosition());
                PhotoViewer.this.playOrStopAnimatedStickers(true);
            }
            if (PhotoViewer.this.isEmbedVideo) {
                PhotoViewer.this.initEmbedVideo(num.intValue());
            }
            if (photoViewerProvider != null) {
                photoViewerProvider.onOpen();
            }
        }

        public void lambda$onPreDraw$1(ValueAnimator valueAnimator) {
            PhotoViewer.this.clippingImageProgress = 1.0f - ((Float) valueAnimator.getAnimatedValue()).floatValue();
            PhotoViewer.this.invalidateBlur();
        }

        public class AnonymousClass1 extends AnimatorListenerAdapter {
            public AnonymousClass1() {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.AnonymousClass75.AnonymousClass1.this.lambda$onAnimationEnd$0();
                    }
                });
            }

            public void lambda$onAnimationEnd$0() {
                PhotoViewer.this.transitionNotificationLocker.unlock();
                if (PhotoViewer.this.animationEndRunnable != null) {
                    PhotoViewer.this.animationEndRunnable.run();
                    PhotoViewer.this.animationEndRunnable = null;
                }
                PhotoViewer.this.setCaptionHwLayerEnabled(true);
            }
        }

        public void lambda$onPreDraw$2(AnimatorSet animatorSet) {
            PhotoViewer.this.transitionNotificationLocker.lock();
            animatorSet.start();
        }

        public void lambda$onPreDraw$3(PlaceProviderObject placeProviderObject) {
            PhotoViewer.this.disableShowCheck = false;
            placeProviderObject.imageReceiver.setVisible(false, true);
        }
    }

    public final void initEmbedVideo(int embedSeekTime) {
        if (this.isEmbedVideo) {
            PhotoViewerWebView photoViewerWebView = new PhotoViewerWebView(this, this.parentActivity, this.pipItem) {
                public Rect rect = new Rect();

                public void processTouch(MotionEvent event) {
                }

                public void drawBlackBackground(Canvas canvas, int w, int h) {
                    Bitmap bitmap = PhotoViewer.this.centerImage.getBitmap();
                    if (bitmap != null) {
                        float min = Math.min(w / bitmap.getWidth(), h / bitmap.getHeight());
                        int width = (int) (bitmap.getWidth() * min);
                        int height = (int) (bitmap.getHeight() * min);
                        int i = (h - height) / 2;
                        int i2 = (w - width) / 2;
                        this.rect.set(i2, i, width + i2, height + i);
                        canvas.drawBitmap(bitmap, (Rect) null, this.rect, (Paint) null);
                    }
                }
            };
            this.photoViewerWebView = photoViewerWebView;
            photoViewerWebView.init(embedSeekTime, MessageObject.getMedia(this.currentMessageObject.messageOwner).webpage);
            this.photoViewerWebView.setPlaybackSpeed(this.currentVideoSpeed);
            this.containerView.addView(this.photoViewerWebView, 0, LayoutHelper.createFrame(-1, -1.0f));
            if (this.photoViewerWebView.isControllable()) {
                setVideoPlayerControlVisible(true, true);
            }
            this.videoPlayerSeekbar.clearTimestamps();
            updateVideoPlayerTime();
            this.shouldSavePositionForCurrentVideo = null;
            this.shouldSavePositionForCurrentVideoShortTerm = null;
            this.lastSaveTime = 0L;
            this.seekToProgressPending = this.seekToProgressPending2;
            this.videoPlayerSeekbar.setProgress(0.0f);
            this.videoTimelineView.setProgress(0.0f);
            this.videoPlayerSeekbar.setBufferedProgress(0.0f);
        }
    }

    public final void makeFocusable() {
        if (Build.VERSION.SDK_INT >= 21) {
            this.windowLayoutParams.flags = -2147417856;
        } else {
            this.windowLayoutParams.flags = 0;
        }
        this.windowLayoutParams.softInputMode = 272;
        try {
            ((WindowManager) this.parentActivity.getSystemService("window")).updateViewLayout(this.windowView, this.windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
        }
        this.windowView.setFocusable(true);
        this.containerView.setFocusable(true);
    }

    public final void requestAdjustToNothing() {
        this.windowLayoutParams.softInputMode = 48;
        try {
            ((WindowManager) this.parentActivity.getSystemService("window")).updateViewLayout(this.windowView, this.windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public final void requestAdjust() {
        this.windowLayoutParams.softInputMode = 272;
        try {
            ((WindowManager) this.parentActivity.getSystemService("window")).updateViewLayout(this.windowView, this.windowLayoutParams);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public void injectVideoPlayerToMediaController() {
        if (this.videoPlayer.isPlaying()) {
            if (this.playerLooping) {
                this.videoPlayer.setLooping(false);
            }
            MediaController.getInstance().injectVideoPlayer(this.videoPlayer, this.currentMessageObject);
            this.videoPlayer = null;
        }
    }

    public void closePhoto(boolean r29, boolean r30) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.closePhoto(boolean, boolean):void");
    }

    public void lambda$closePhoto$96(MaskPaintView maskPaintView) {
        maskPaintView.shutdown();
        this.containerView.removeView(this.maskPaintView);
    }

    public void lambda$closePhoto$97(ValueAnimator valueAnimator) {
        this.clippingImageProgress = ((Float) valueAnimator.getAnimatedValue()).floatValue();
        invalidateBlur();
    }

    public void lambda$closePhoto$98(ValueAnimator valueAnimator) {
        this.clippingImageProgress = ((Float) valueAnimator.getAnimatedValue()).floatValue();
    }

    public void lambda$closePhoto$99(PlaceProviderObject placeProviderObject) {
        ArrayList<Object> arrayList;
        this.animationEndRunnable = null;
        this.containerView.setLayerType(0, null);
        this.animationInProgress = 0;
        invalidateBlur();
        onPhotoClosed(placeProviderObject);
        MediaController.getInstance().tryResumePausedAudio();
        if (!this.stickerEmpty || this.stickerEmptySent || (arrayList = this.imagesArrLocals) == null) {
            return;
        }
        Iterator<Object> it = arrayList.iterator();
        while (it.hasNext()) {
            Object next = it.next();
            if (next instanceof MediaController.PhotoEntry) {
                ((MediaController.PhotoEntry) next).deleteAll();
            }
        }
    }

    public class AnonymousClass78 extends AnimatorListenerAdapter {
        public AnonymousClass78() {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass78.this.lambda$onAnimationEnd$0();
                }
            });
        }

        public void lambda$onAnimationEnd$0() {
            if (PhotoViewer.this.animationEndRunnable != null) {
                PhotoViewer.this.animationEndRunnable.run();
                PhotoViewer.this.animationEndRunnable = null;
            }
        }
    }

    public void lambda$closePhoto$100(ValueAnimator valueAnimator) {
        this.clippingImageProgress = ((Float) valueAnimator.getAnimatedValue()).floatValue();
    }

    public void lambda$closePhoto$101(PlaceProviderObject placeProviderObject) {
        ArrayList<Object> arrayList;
        this.animationEndRunnable = null;
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
        if (sizeNotifierFrameLayoutPhoto == null) {
            return;
        }
        sizeNotifierFrameLayoutPhoto.setLayerType(0, null);
        this.animationInProgress = 0;
        onPhotoClosed(placeProviderObject);
        this.containerView.setScaleX(1.0f);
        this.containerView.setScaleY(1.0f);
        MediaController.getInstance().tryResumePausedAudio();
        if (!this.stickerEmpty || this.stickerEmptySent || (arrayList = this.imagesArrLocals) == null) {
            return;
        }
        Iterator<Object> it = arrayList.iterator();
        while (it.hasNext()) {
            Object next = it.next();
            if (next instanceof MediaController.PhotoEntry) {
                ((MediaController.PhotoEntry) next).deleteAll();
            }
        }
    }

    public final ClippingImageView[] getAnimatingImageViews(PlaceProviderObject object) {
        int i = (AndroidUtilities.isTablet() || object == null || object.animatingImageView == null) ? 0 : 1;
        ClippingImageView[] clippingImageViewArr = new ClippingImageView[i + 1];
        clippingImageViewArr[0] = this.animatingImageView;
        if (i != 0) {
            ClippingImageView clippingImageView = object.animatingImageView;
            clippingImageViewArr[1] = clippingImageView;
            clippingImageView.setAdditionalTranslationY(object.animatingImageViewYOffset);
        }
        return clippingImageViewArr;
    }

    public final void removeObservers() {
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.fileLoadFailed);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.fileLoaded);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.customStickerCreated);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.fileLoadProgressChanged);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.mediaCountDidLoad);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.mediaDidLoad);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.dialogPhotosUpdate);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.messagesDeleted);
        NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiLoaded);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.filePreparingFailed);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.fileNewChunkAvailable);
        ConnectionsManager.getInstance(this.currentAccount).cancelRequestsForGuid(this.classGuid);
    }

    public void destroyPhotoViewer() {
        if (this.parentActivity == null || this.windowView == null) {
            return;
        }
        if (PipVideoOverlay.isVisible()) {
            PipVideoOverlay.dismiss();
        }
        removeObservers();
        releasePlayer(false);
        try {
            if (this.windowView.getParent() != null) {
                ((WindowManager) this.parentActivity.getSystemService("window")).removeViewImmediate(this.windowView);
                onHideView();
            }
            this.windowView = null;
        } catch (Exception e) {
            FileLog.e(e);
        }
        ImageReceiver.BitmapHolder bitmapHolder = this.currentThumb;
        if (bitmapHolder != null) {
            bitmapHolder.release();
            this.currentThumb = null;
        }
        this.animatingImageView.setImageBitmap((ImageReceiver.BitmapHolder) null);
        if (this == PipInstance) {
            PipInstance = null;
        } else {
            Instance = null;
        }
        onHideView();
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.photoQualityChanged);
    }

    public final void onPhotoClosed(final PlaceProviderObject object) {
        if (this.doneButtonPressed) {
            releasePlayer(true);
        }
        MessageObject messageObject = this.currentMessageObject;
        if (messageObject != null && !messageObject.putInDownloadsStore) {
            FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.currentMessageObject.getDocument());
        }
        this.isVisible = false;
        this.isVisibleOrAnimating = false;
        this.cropInitied = false;
        this.disableShowCheck = true;
        this.currentMessageObject = null;
        this.currentBotInlineResult = null;
        this.currentFileLocation = null;
        this.currentFileLocationVideo = null;
        this.currentSecureDocument = null;
        this.currentPageBlock = null;
        this.currentPathObject = null;
        this.dialogPhotos = null;
        if (this.videoPlayerControlFrameLayout != null) {
            setVideoPlayerControlVisible(false, false);
        }
        CaptionScrollView captionScrollView = this.captionScrollView;
        if (captionScrollView != null) {
            captionScrollView.reset();
        }
        this.sendPhotoType = 0;
        this.isDocumentsPicker = false;
        ImageReceiver.BitmapHolder bitmapHolder = this.currentThumb;
        if (bitmapHolder != null) {
            bitmapHolder.release();
            this.currentThumb = null;
        }
        this.parentAlert = null;
        AnimatedFileDrawable animatedFileDrawable = this.currentAnimation;
        if (animatedFileDrawable != null) {
            animatedFileDrawable.removeSecondParentView(this.containerView);
            this.currentAnimation = null;
        }
        for (int i = 0; i < 3; i++) {
            PhotoProgressView[] photoProgressViewArr = this.photoProgressViews;
            if (photoProgressViewArr[i] != null) {
                photoProgressViewArr[i].setBackgroundState(-1, false, true);
            }
        }
        requestVideoPreview(0);
        VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
        if (videoTimelinePlayView != null) {
            videoTimelinePlayView.destroy();
        }
        this.hintView.hide(false, 0);
        this.centerImage.setImageBitmap((Bitmap) null);
        this.centerBlur.destroy();
        this.leftImage.setImageBitmap((Bitmap) null);
        this.leftBlur.destroy();
        this.rightImage.setImageBitmap((Bitmap) null);
        this.rightBlur.destroy();
        this.containerView.post(new Runnable() {
            @Override
            public final void run() {
                PhotoViewer.this.lambda$onPhotoClosed$102(object);
            }
        });
        PhotoViewerProvider photoViewerProvider = this.placeProvider;
        if (photoViewerProvider != null) {
            photoViewerProvider.willHidePhotoViewer();
        }
        this.groupedPhotosListView.clear();
        PhotoViewerProvider photoViewerProvider2 = this.placeProvider;
        if (photoViewerProvider2 != null) {
            photoViewerProvider2.onClose();
        }
        this.placeProvider = null;
        this.selectedPhotosAdapter.notifyDataSetChanged();
        this.pageBlocksAdapter = null;
        this.disableShowCheck = false;
        this.shownControlsByEnd = false;
        this.videoCutStart = 0.0f;
        this.videoCutEnd = 1.0f;
        if (object != null) {
            object.imageReceiver.setVisible(true, true);
        }
        ChatActivity chatActivity = this.parentChatActivity;
        if (chatActivity != null) {
            chatActivity.getFragmentView().invalidate();
        }
        Bitmap bitmap = this.videoFrameBitmap;
        if (bitmap != null) {
            bitmap.recycle();
            this.videoFrameBitmap = null;
        }
    }

    public void lambda$onPhotoClosed$102(PlaceProviderObject placeProviderObject) {
        ClippingImageView clippingImageView;
        this.animatingImageView.setImageBitmap((ImageReceiver.BitmapHolder) null);
        if (placeProviderObject != null && !AndroidUtilities.isTablet() && (clippingImageView = placeProviderObject.animatingImageView) != null) {
            clippingImageView.setImageBitmap((ImageReceiver.BitmapHolder) null);
        }
        try {
            if (this.windowView.getParent() != null) {
                ((WindowManager) this.parentActivity.getSystemService("window")).removeView(this.windowView);
                onHideView();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    public final void redraw(final int count) {
        if (count < 6) {
            SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
            if (sizeNotifierFrameLayoutPhoto != null) {
                sizeNotifierFrameLayoutPhoto.invalidate();
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.this.lambda$redraw$103(count);
                    }
                }, 100L);
                return;
            }
            return;
        }
        this.qualityBar.requestLayout();
    }

    public void lambda$redraw$103(int i) {
        redraw(i + 1);
    }

    public void onResume() {
        redraw(0);
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            videoPlayer.seekTo(videoPlayer.getCurrentPosition() + 1);
            if (this.playerLooping) {
                this.videoPlayer.setLooping(true);
            }
        }
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.onResume();
        }
    }

    public void onPause() {
        if (this.currentAnimation != null) {
            closePhoto(false, false);
            return;
        }
        if (this.lastTitle != null) {
            closeCaptionEnter(true);
        }
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer == null || !this.playerLooping) {
            return;
        }
        videoPlayer.setLooping(false);
    }

    public boolean isVisible() {
        return this.isVisible && this.placeProvider != null;
    }

    public final void updateMinMax(float scale) {
        AspectRatioFrameLayout aspectRatioFrameLayout = this.aspectRatioFrameLayout;
        if (aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == 0 && this.textureUploaded) {
            View view = this.usedSurfaceView ? this.videoSurfaceView : this.videoTextureView;
            scale *= Math.min(getContainerViewWidth() / view.getMeasuredWidth(), getContainerViewHeight() / view.getMeasuredHeight());
        }
        float imageWidth = this.centerImage.getImageWidth();
        float imageHeight = this.centerImage.getImageHeight();
        MediaController.CropState cropState = this.editState.cropState;
        if (cropState != null) {
            imageWidth *= cropState.cropPw;
            imageHeight *= cropState.cropPh;
        }
        int containerViewWidth = this.sendPhotoType == 11 ? (int) (imageWidth * scale) : ((int) ((imageWidth * scale) - getContainerViewWidth())) / 2;
        int containerViewHeight = this.sendPhotoType == 11 ? (int) (imageHeight * scale) : ((int) ((imageHeight * scale) - getContainerViewHeight())) / 2;
        if (containerViewWidth > 0) {
            this.minX = -containerViewWidth;
            this.maxX = containerViewWidth;
        } else {
            this.maxX = 0.0f;
            this.minX = 0.0f;
        }
        if (containerViewHeight > 0) {
            this.minY = -containerViewHeight;
            this.maxY = containerViewHeight;
        } else {
            this.maxY = 0.0f;
            this.minY = 0.0f;
        }
        LPhotoPaintView lPhotoPaintView = this.photoPaintView;
        if (lPhotoPaintView != null) {
            lPhotoPaintView.updateZoom(scale <= 1.1f);
        }
    }

    public final int getAdditionX(int mode) {
        if (mode == 1 || (mode == 0 && this.sendPhotoType == 1)) {
            return AndroidUtilities.dp(16.0f);
        }
        if (mode == 0 || mode == 4 || mode == 3) {
            return 0;
        }
        return AndroidUtilities.dp(14.0f);
    }

    public final int getAdditionY(int mode) {
        if (mode < 0) {
            return 0;
        }
        if (mode == 1 || (mode == 0 && this.sendPhotoType == 1)) {
            return AndroidUtilities.dp(16.0f) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
        }
        if (mode == 3 && this.photoPaintView != null) {
            return AndroidUtilities.dp(8.0f) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0) + this.photoPaintView.getAdditionalTop();
        }
        if (mode == 0 || mode == 4) {
            return 0;
        }
        return AndroidUtilities.dp(14.0f) + (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0);
    }

    public final int getContainerViewWidth() {
        return getContainerViewWidth(this.currentEditMode);
    }

    public final int getContainerViewWidth(int mode) {
        int dp;
        int width = this.containerView.getWidth();
        if (mode == 1 || (mode == 0 && this.sendPhotoType == 1)) {
            dp = AndroidUtilities.dp(32.0f);
        } else {
            if (mode == 0 || mode == 4 || mode == 3) {
                return width;
            }
            dp = AndroidUtilities.dp(28.0f);
        }
        return width - dp;
    }

    public final int getContainerViewHeight() {
        return getContainerViewHeight(this.currentEditMode);
    }

    public final int getContainerViewHeight(int mode) {
        return getContainerViewHeight(false, mode);
    }

    public final int getContainerViewHeight(boolean trueHeight, int mode) {
        int measuredHeight;
        int dp;
        if (trueHeight || this.inBubbleMode) {
            measuredHeight = this.containerView.getMeasuredHeight();
        } else {
            measuredHeight = AndroidUtilities.displaySize.y;
            if ((mode == 0 || mode == 4) && this.sendPhotoType != 1 && isStatusBarVisible()) {
                measuredHeight += AndroidUtilities.statusBarHeight;
            }
        }
        if ((mode == 0 && this.sendPhotoType == 1) || mode == 1) {
            dp = AndroidUtilities.dp(144.0f);
        } else if (mode == 2) {
            dp = AndroidUtilities.dp(214.0f);
        } else {
            if (mode != 3) {
                return measuredHeight;
            }
            dp = AndroidUtilities.dp(48.0f) + this.photoPaintView.getAdditionalBottom() + ActionBar.getCurrentActionBarHeight() + this.photoPaintView.getAdditionalTop();
        }
        return measuredHeight - dp;
    }

    public final boolean onTouchEvent(android.view.MotionEvent r21) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onTouchEvent(android.view.MotionEvent):boolean");
    }

    public final void checkMinMax(boolean r6) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.checkMinMax(boolean):void");
    }

    public final void goToNext() {
        float containerViewWidth = this.scale != 1.0f ? ((getContainerViewWidth() - this.centerImage.getImageWidth()) / 2.0f) * this.scale : 0.0f;
        this.switchImageAfterAnimation = 1;
        animateTo(this.scale, ((this.minX - getContainerViewWidth()) - containerViewWidth) - (AndroidUtilities.dp(30.0f) / 2), this.translationY, false);
    }

    public final void goToPrev() {
        float containerViewWidth = this.scale != 1.0f ? ((getContainerViewWidth() - this.centerImage.getImageWidth()) / 2.0f) * this.scale : 0.0f;
        this.switchImageAfterAnimation = 2;
        animateTo(this.scale, this.maxX + getContainerViewWidth() + containerViewWidth + (AndroidUtilities.dp(30.0f) / 2), this.translationY, false);
    }

    public final void cancelMoveZoomAnimation() {
        AnimatorSet animatorSet = this.imageMoveAnimation;
        if (animatorSet == null) {
            return;
        }
        float f = this.scale;
        float f2 = this.animateToScale - f;
        float f3 = this.animationValue;
        float f4 = f + (f2 * f3);
        float f5 = this.translationX;
        float f6 = f5 + ((this.animateToX - f5) * f3);
        float f7 = this.translationY;
        float f8 = f7 + ((this.animateToY - f7) * f3);
        float f9 = this.rotate;
        float f10 = f9 + ((this.animateToRotate - f9) * f3);
        animatorSet.cancel();
        this.scale = f4;
        this.translationX = f6;
        this.translationY = f8;
        this.animationStartTime = 0L;
        this.rotate = f10;
        updateMinMax(f4);
        this.zoomAnimation = false;
        this.containerView.invalidate();
    }

    public void zoomOut() {
        animateTo(1.0f, 0.0f, 0.0f, false);
    }

    public final void animateTo(float newScale, float newTx, float newTy, boolean isZoom) {
        animateTo(newScale, newTx, newTy, isZoom, 250);
    }

    public final void animateTo(float newScale, float newTx, float newTy, boolean isZoom, int duration) {
        if (this.scale == newScale && this.translationX == newTx && this.translationY == newTy) {
            return;
        }
        this.zoomAnimation = isZoom;
        this.animateToScale = newScale;
        this.animateToX = newTx;
        this.animateToY = newTy;
        this.animationStartTime = System.currentTimeMillis();
        AnimatorSet animatorSet = new AnimatorSet();
        this.imageMoveAnimation = animatorSet;
        animatorSet.playTogether(ObjectAnimator.ofFloat(this, (Property<PhotoViewer, Float>) AnimationProperties.PHOTO_VIEWER_ANIMATION_VALUE, 0.0f, 1.0f));
        this.imageMoveAnimation.setInterpolator(this.interpolator);
        this.imageMoveAnimation.setDuration(duration);
        this.imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                PhotoViewer.this.imageMoveAnimation = null;
                PhotoViewer.this.containerView.invalidate();
            }
        });
        this.imageMoveAnimation.start();
    }

    public int getCurrentIndex() {
        return this.currentIndex;
    }

    public List<Object> getImagesArrLocals() {
        return this.imagesArrLocals;
    }

    @Keep
    public void setAnimationValue(float value) {
        this.animationValue = value;
        this.containerView.invalidate();
        invalidateBlur();
    }

    @Keep
    public float getAnimationValue() {
        return this.animationValue;
    }

    public final void switchToNextIndex(int add, boolean init) {
        if (this.currentMessageObject != null) {
            releasePlayer(false);
            FileLoader.getInstance(this.currentAccount).cancelLoadFile(this.currentMessageObject.getDocument());
        } else if (this.currentPageBlock != null) {
            TLRPC.Document media = this.pageBlocksAdapter.getMedia(this.currentIndex);
            if (media instanceof TLRPC.Document) {
                releasePlayer(false);
                FileLoader.getInstance(this.currentAccount).cancelLoadFile(media);
            }
        }
        GroupedPhotosListView groupedPhotosListView = this.groupedPhotosListView;
        if (groupedPhotosListView != null) {
            groupedPhotosListView.setAnimateBackground(true);
        }
        this.playerAutoStarted = false;
        setImageIndex(this.currentIndex + add, init, true);
        if (shouldMessageObjectAutoPlayed(this.currentMessageObject) || shouldIndexAutoPlayed(this.currentIndex)) {
            this.playerAutoStarted = true;
            onActionClick(true);
            checkProgress(0, false, true);
        }
        checkFullscreenButton();
    }

    public final boolean shouldMessageObjectAutoPlayed(MessageObject messageObject) {
        return messageObject != null && messageObject.isVideo() && (messageObject.mediaExists || messageObject.attachPathExists || (messageObject.canStreamVideo() && SharedConfig.streamMedia)) && SharedConfig.isAutoplayVideo();
    }

    public final boolean shouldIndexAutoPlayed(int index) {
        File file;
        PageBlocksAdapter pageBlocksAdapter = this.pageBlocksAdapter;
        if (pageBlocksAdapter != null) {
            return (pageBlocksAdapter.isVideo(index) || this.pageBlocksAdapter.isHardwarePlayer(index)) && SharedConfig.isAutoplayVideo() && (file = this.pageBlocksAdapter.getFile(index)) != null && file.exists();
        }
        return false;
    }

    public final float getCropFillScale(boolean rotated) {
        ImageReceiver imageReceiver = this.centerImage;
        int bitmapHeight = rotated ? imageReceiver.getBitmapHeight() : imageReceiver.getBitmapWidth();
        int bitmapWidth = rotated ? this.centerImage.getBitmapWidth() : this.centerImage.getBitmapHeight();
        float min = Math.min(this.photoCropView.getMeasuredWidth(), (this.photoCropView.getMeasuredHeight() - AndroidUtilities.dp(64.0f)) - (isStatusBarVisible() ? AndroidUtilities.statusBarHeight : 0)) - (AndroidUtilities.dp(16.0f) * 2);
        return Math.max(min / bitmapHeight, min / bitmapWidth);
    }

    public final boolean isStatusBarVisible() {
        return Build.VERSION.SDK_INT >= 21 && !this.inBubbleMode;
    }

    @android.annotation.SuppressLint({"NewApi", "DrawAllocation"})
    public final void onDraw(android.graphics.Canvas r46) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onDraw(android.graphics.Canvas):void");
    }

    public void lambda$onDraw$104() {
        switchToNextIndex(1, false);
    }

    public void lambda$onDraw$105() {
        switchToNextIndex(-1, false);
    }

    public void lambda$onDraw$106() {
        checkChangedTextureView(false);
        PipVideoOverlay.dismiss(true, true);
    }

    public final void drawFancyShadows(Canvas canvas) {
        float f;
        if (this.fancyShadows) {
            if (SharedConfig.photoViewerBlur) {
                AnimatedFloat animatedFloat = this.blurAlpha;
                int i = this.animationInProgress;
                f = animatedFloat.set(i == 0 || i == 2 || i == 3);
            } else {
                f = 1.0f;
            }
            if (f <= 0.0f) {
                return;
            }
            int currentActionBarHeight = ((int) (AndroidUtilities.statusBarHeight * 1.5f)) + ActionBar.getCurrentActionBarHeight();
            int height = AndroidUtilities.navigationBarHeight + this.pickerView.getHeight() + (this.captionEdit.getVisibility() == 0 ? (this.captionEdit.getEditTextHeightClosedKeyboard() / 2) + AndroidUtilities.dp(20.0f) : 0);
            if (this.clipFancyShadows == null) {
                this.clipFancyShadows = new Path();
                Paint paint = new Paint(1);
                this.topFancyShadowPaint = paint;
                paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
                Paint paint2 = new Paint(1);
                this.bottomFancyShadowPaint = paint2;
                paint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
                this.topFancyShadow = new LinearGradient(0.0f, 0.0f, 0.0f, 16.0f, new int[]{-16777216, 0}, new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP);
                this.bottomFancyShadow = new LinearGradient(0.0f, 0.0f, 0.0f, 16.0f, new int[]{0, -16777216}, new float[]{0.0f, 1.0f}, Shader.TileMode.CLAMP);
                this.topFancyShadowMatrix = new Matrix();
                this.bottomFancyShadowMatrix = new Matrix();
                this.topFancyShadowPaint.setShader(this.topFancyShadow);
                this.bottomFancyShadowPaint.setShader(this.bottomFancyShadow);
            }
            canvas.saveLayerAlpha(0.0f, 0.0f, this.containerView.getWidth(), this.containerView.getHeight() + AndroidUtilities.navigationBarHeight, (int) (f * (this.backgroundDrawable.getAlpha() - 127) * 2.007874f), 31);
            this.clipFancyShadows.rewind();
            float f2 = currentActionBarHeight;
            this.clipFancyShadows.addRect(0.0f, 0.0f, this.containerView.getWidth(), f2, Path.Direction.CW);
            this.clipFancyShadows.addRect(0.0f, (this.containerView.getHeight() + AndroidUtilities.navigationBarHeight) - height, this.containerView.getWidth(), this.containerView.getHeight() + AndroidUtilities.navigationBarHeight, Path.Direction.CW);
            canvas.clipPath(this.clipFancyShadows);
            canvas.drawColor(-16777216);
            drawCaptionBlur(canvas, this.shadowBlurer, 0, 0, true, true, false);
            canvas.save();
            this.topFancyShadowMatrix.reset();
            this.topFancyShadowMatrix.postScale(1.0f, f2 / 16.0f);
            this.topFancyShadow.setLocalMatrix(this.topFancyShadowMatrix);
            this.topFancyShadowPaint.setAlpha(208);
            canvas.drawRect(0.0f, 0.0f, this.containerView.getWidth(), f2, this.topFancyShadowPaint);
            this.bottomFancyShadowMatrix.reset();
            this.bottomFancyShadowMatrix.postScale(1.0f, height / 16.0f);
            this.bottomFancyShadowMatrix.postTranslate(0.0f, (this.containerView.getHeight() - height) + AndroidUtilities.navigationBarHeight);
            this.bottomFancyShadow.setLocalMatrix(this.bottomFancyShadowMatrix);
            this.bottomFancyShadowPaint.setAlpha(187);
            canvas.drawRect(0.0f, (this.containerView.getHeight() + AndroidUtilities.navigationBarHeight) - height, this.containerView.getWidth(), this.containerView.getHeight() + AndroidUtilities.navigationBarHeight, this.bottomFancyShadowPaint);
            canvas.restore();
            canvas.restore();
        }
    }

    public final void drawCenterImageInternal(android.graphics.Canvas r7, float r8, float r9) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.drawCenterImageInternal(android.graphics.Canvas, float, float):void");
    }

    public final void drawProgress(android.graphics.Canvas r9, float r10, float r11, float r12, float r13) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.drawProgress(android.graphics.Canvas, float, float, float, float):void");
    }

    public final int[] applyCrop(android.graphics.Canvas r23, int r24, int r25, int r26, int r27, float r28, org.telegram.ui.Components.Crop.CropTransform r29, org.telegram.messenger.MediaController.CropState r30) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.applyCrop(android.graphics.Canvas, int, int, int, int, float, org.telegram.ui.Components.Crop.CropTransform, org.telegram.messenger.MediaController$CropState):int[]");
    }

    public final void onActionClick(boolean r11) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onActionClick(boolean):void");
    }

    public boolean onDown(MotionEvent e) {
        if (!this.doubleTap && this.checkImageView.getVisibility() != 0) {
            boolean[] zArr = this.drawPressedDrawable;
            if (!zArr[0] && !zArr[1]) {
                float x = e.getX();
                if (x < Math.min(135, this.containerView.getMeasuredWidth() / 8)) {
                    if (this.leftImage.hasImageSet()) {
                        this.drawPressedDrawable[0] = true;
                        this.containerView.invalidate();
                    }
                } else if (x > this.containerView.getMeasuredWidth() - r0 && this.rightImage.hasImageSet()) {
                    this.drawPressedDrawable[1] = true;
                    this.containerView.invalidate();
                }
            }
        }
        return false;
    }

    public boolean canDoubleTap(MotionEvent e) {
        MessageObject messageObject;
        PhotoViewerWebView photoViewerWebView;
        if (this.checkImageView.getVisibility() == 0) {
            return true;
        }
        boolean[] zArr = this.drawPressedDrawable;
        if (zArr[0] || zArr[1]) {
            return true;
        }
        float x = e.getX();
        if ((x < Math.min(135, this.containerView.getMeasuredWidth() / 8) || x > this.containerView.getMeasuredWidth() - r3) && (messageObject = this.currentMessageObject) != null) {
            return (messageObject.isVideo() || this.playGifAsVideo || ((photoViewerWebView = this.photoViewerWebView) != null && photoViewerWebView.isControllable())) && SystemClock.elapsedRealtime() - this.lastPhotoSetTime >= 500 && canDoubleTapSeekVideo(e);
        }
        return true;
    }

    public final void hidePressedDrawables() {
        boolean[] zArr = this.drawPressedDrawable;
        zArr[1] = false;
        zArr[0] = false;
        this.containerView.invalidate();
    }

    public void onUp(MotionEvent e) {
        hidePressedDrawables();
    }

    public boolean onSingleTapUp(MotionEvent e) {
        if (!this.canZoom && !this.doubleTapEnabled) {
            return onSingleTapConfirmed(e);
        }
        SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
        if (sizeNotifierFrameLayoutPhoto != null && sizeNotifierFrameLayoutPhoto.getTag() != null && this.photoProgressViews[0] != null) {
            float x = e.getX();
            float y = e.getY();
            if ((x < ((float) (getContainerViewWidth() - AndroidUtilities.dp(100.0f))) / 2.0f || x > ((float) (getContainerViewWidth() + AndroidUtilities.dp(100.0f))) / 2.0f || y < ((float) (getContainerViewHeight() - AndroidUtilities.dp(100.0f))) / 2.0f || y > ((float) (getContainerViewHeight() + AndroidUtilities.dp(100.0f))) / 2.0f) ? false : onSingleTapConfirmed(e)) {
                this.discardTap = true;
                return true;
            }
        }
        return false;
    }

    public void onLongPress() {
        boolean z;
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer == null || !this.videoPlayerControlVisible || this.scale > 1.1f) {
            return;
        }
        long currentPosition = videoPlayer.getCurrentPosition();
        long duration = this.videoPlayer.getDuration();
        if (currentPosition == -9223372036854775807L || duration < 15000) {
            return;
        }
        float f = this.longPressX;
        int containerViewWidth = getContainerViewWidth() / 3;
        if (f >= containerViewWidth * 2) {
            z = true;
        } else if (f >= containerViewWidth) {
            return;
        } else {
            z = false;
        }
        this.videoPlayerRewinder.startRewind(this.videoPlayer, z, this.currentVideoSpeed);
    }

    public VideoPlayerRewinder getVideoPlayerRewinder() {
        return this.videoPlayerRewinder;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (this.scale == 1.0f || this.sendPhotoType == 11) {
            return false;
        }
        this.scroller.abortAnimation();
        this.scroller.fling(Math.round(this.translationX), Math.round(this.translationY), Math.round(velocityX), Math.round(velocityY), (int) this.minX, (int) this.maxX, (int) this.minY, (int) this.maxY);
        this.containerView.postInvalidate();
        return false;
    }

    public boolean onSingleTapConfirmed(MotionEvent e) {
        PhotoViewerWebView photoViewerWebView;
        MessageObject messageObject;
        if (this.discardTap) {
            return false;
        }
        float x = e.getX();
        float y = e.getY();
        if (this.checkImageView.getVisibility() != 0 && !PlusSettings.discardMediaTap && SharedConfig.nextMediaTap && this.sendPhotoType != 11 && y > ActionBar.getCurrentActionBarHeight() + AndroidUtilities.statusBarHeight + AndroidUtilities.dp(40.0f)) {
            if (x < Math.min(135, this.containerView.getMeasuredWidth() / 8)) {
                if (this.leftImage.hasImageSet()) {
                    switchToNextIndex(-1, true);
                    return true;
                }
            } else if (x > this.containerView.getMeasuredWidth() - r3 && this.rightImage.hasImageSet()) {
                switchToNextIndex(1, true);
                return true;
            }
        }
        PhotoViewerWebView photoViewerWebView2 = this.photoViewerWebView;
        if (photoViewerWebView2 != null && photoViewerWebView2.isControllable() && this.isActionBarVisible) {
            WebView webView = this.photoViewerWebView.getWebView();
            if (x >= webView.getX() && x <= webView.getX() + webView.getWidth() && y >= webView.getY() && y <= webView.getY() + webView.getHeight()) {
                MotionEvent obtain = MotionEvent.obtain(e);
                obtain.setAction(0);
                obtain.offsetLocation(-webView.getX(), -webView.getY());
                webView.dispatchTouchEvent(obtain);
                obtain.setAction(1);
                webView.dispatchTouchEvent(obtain);
                obtain.recycle();
                scheduleActionBarHide();
                return true;
            }
        }
        if (this.containerView.getTag() != null) {
            AspectRatioFrameLayout aspectRatioFrameLayout = this.aspectRatioFrameLayout;
            boolean z = (aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == 0) || ((photoViewerWebView = this.photoViewerWebView) != null && photoViewerWebView.isControllable());
            if (this.sharedMediaType == 1 && (messageObject = this.currentMessageObject) != null) {
                if (!messageObject.canPreviewDocument()) {
                    float containerViewHeight = (getContainerViewHeight() - AndroidUtilities.dp(360.0f)) / 2.0f;
                    if (y >= containerViewHeight && y <= containerViewHeight + AndroidUtilities.dp(360.0f)) {
                        onActionClick(true);
                        return true;
                    }
                }
            } else {
                PhotoProgressView[] photoProgressViewArr = this.photoProgressViews;
                if (photoProgressViewArr[0] != null && this.containerView != null) {
                    int i = photoProgressViewArr[0].backgroundState;
                    if (x >= (getContainerViewWidth() - AndroidUtilities.dp(100.0f)) / 2.0f && x <= (getContainerViewWidth() + AndroidUtilities.dp(100.0f)) / 2.0f && y >= (getContainerViewHeight() - AndroidUtilities.dp(100.0f)) / 2.0f && y <= (getContainerViewHeight() + AndroidUtilities.dp(100.0f)) / 2.0f) {
                        if (z) {
                            if ((i == 3 || i == 4) && this.photoProgressViews[0].isVisible()) {
                                this.manuallyPaused = true;
                                toggleVideoPlayer();
                                return true;
                            }
                        } else if (i > 0 && i <= 3) {
                            onActionClick(true);
                            checkProgress(0, false, true);
                            return true;
                        }
                    }
                }
            }
            PhotoViewerWebView photoViewerWebView3 = this.photoViewerWebView;
            if (photoViewerWebView3 == null || !photoViewerWebView3.isControllable() || this.photoViewerWebView.isPlaying() || !this.isActionBarVisible) {
                toggleActionBar(!this.isActionBarVisible, true);
            }
        } else {
            int i2 = this.sendPhotoType;
            if (i2 == 0 || i2 == 4) {
                if (this.isCurrentVideo) {
                    VideoPlayer videoPlayer = this.videoPlayer;
                    if (videoPlayer != null && !this.muteVideo && i2 != 1) {
                        videoPlayer.setVolume(1.0f);
                    }
                    this.manuallyPaused = true;
                    toggleVideoPlayer();
                } else {
                    this.checkImageView.performClick();
                }
            } else {
                TLRPC.BotInlineResult botInlineResult = this.currentBotInlineResult;
                if (botInlineResult != null && (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(this.currentBotInlineResult.document))) {
                    int i3 = this.photoProgressViews[0].backgroundState;
                    if (i3 > 0 && i3 <= 3 && x >= (getContainerViewWidth() - AndroidUtilities.dp(100.0f)) / 2.0f && x <= (getContainerViewWidth() + AndroidUtilities.dp(100.0f)) / 2.0f && y >= (getContainerViewHeight() - AndroidUtilities.dp(100.0f)) / 2.0f && y <= (getContainerViewHeight() + AndroidUtilities.dp(100.0f)) / 2.0f) {
                        onActionClick(true);
                        checkProgress(0, false, true);
                        return true;
                    }
                } else if (this.sendPhotoType == 2 && this.isCurrentVideo) {
                    this.manuallyPaused = true;
                    toggleVideoPlayer();
                }
            }
        }
        return true;
    }

    public final boolean canDoubleTapSeekVideo(MotionEvent e) {
        PhotoViewerWebView photoViewerWebView;
        if (this.videoPlayer == null && ((photoViewerWebView = this.photoViewerWebView) == null || !photoViewerWebView.isControllable())) {
            return false;
        }
        boolean z = e.getX() >= ((float) ((getContainerViewWidth() / 3) * 2));
        long currentVideoPosition = getCurrentVideoPosition();
        long videoDuration = getVideoDuration();
        if (currentVideoPosition == -9223372036854775807L || videoDuration <= 15000) {
            return false;
        }
        return !z || videoDuration - currentVideoPosition > 10000;
    }

    public boolean onDoubleTap(android.view.MotionEvent r17) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.onDoubleTap(android.view.MotionEvent):boolean");
    }

    public class QualityChooseView extends View {
        public int circleSize;
        public int gapSize;
        public String hightQualityDescription;
        public int lineSize;
        public String lowQualityDescription;
        public Paint paint;
        public int sideSide;
        public int startMovingQuality;
        public TextPaint textPaint;

        public QualityChooseView(Context context) {
            super(context);
            this.paint = new Paint(1);
            TextPaint textPaint = new TextPaint(1);
            this.textPaint = textPaint;
            textPaint.setTextSize(AndroidUtilities.dp(14.0f));
            this.textPaint.setColor(-3289651);
            this.lowQualityDescription = LocaleController.getString("AccDescrVideoCompressLow", R.string.AccDescrVideoCompressLow);
            this.hightQualityDescription = LocaleController.getString("AccDescrVideoCompressHigh", R.string.AccDescrVideoCompressHigh);
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            float x = event.getX();
            if (event.getAction() == 0) {
                this.startMovingQuality = PhotoViewer.this.selectedCompression;
                getParent().requestDisallowInterceptTouchEvent(true);
            }
            if (event.getAction() == 0 || event.getAction() == 2) {
                int i = 0;
                while (true) {
                    if (i >= PhotoViewer.this.compressionsCount) {
                        break;
                    }
                    int i2 = this.sideSide;
                    int i3 = this.lineSize;
                    int i4 = this.gapSize;
                    int i5 = this.circleSize;
                    int i6 = i2 + (((i4 * 2) + i3 + i5) * i) + (i5 / 2);
                    int i7 = (i3 / 2) + (i5 / 2) + i4;
                    if (x <= i6 - i7 || x >= i6 + i7) {
                        i++;
                    } else if (PhotoViewer.this.selectedCompression != i) {
                        PhotoViewer.this.selectedCompression = i;
                        PhotoViewer.this.didChangedCompressionLevel(false);
                        invalidate();
                    }
                }
            } else if (event.getAction() == 1 || event.getAction() == 3) {
                if (PhotoViewer.this.selectedCompression != this.startMovingQuality) {
                    PhotoViewer.this.requestVideoPreview(1);
                }
                PhotoViewer.this.moving = false;
            }
            return true;
        }

        @Override
        public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            this.circleSize = AndroidUtilities.dp(8.0f);
            this.gapSize = AndroidUtilities.dp(2.0f);
            this.sideSide = AndroidUtilities.dp(18.0f);
        }

        @Override
        public void onDraw(Canvas canvas) {
            if (PhotoViewer.this.compressionsCount != 1) {
                this.lineSize = (((getMeasuredWidth() - (this.circleSize * PhotoViewer.this.compressionsCount)) - (this.gapSize * ((PhotoViewer.this.compressionsCount * 2) - 2))) - (this.sideSide * 2)) / (PhotoViewer.this.compressionsCount - 1);
            } else {
                this.lineSize = ((getMeasuredWidth() - (this.circleSize * PhotoViewer.this.compressionsCount)) - (this.gapSize * 2)) - (this.sideSide * 2);
            }
            int measuredHeight = (getMeasuredHeight() / 2) + AndroidUtilities.dp(6.0f);
            int i = 0;
            while (i < PhotoViewer.this.compressionsCount) {
                int i2 = this.sideSide;
                int i3 = this.lineSize + (this.gapSize * 2);
                int i4 = this.circleSize;
                int i5 = i2 + ((i3 + i4) * i) + (i4 / 2);
                if (i <= PhotoViewer.this.selectedCompression) {
                    this.paint.setColor(-11292945);
                } else {
                    this.paint.setColor(1728053247);
                }
                canvas.drawCircle(i5, measuredHeight, i == PhotoViewer.this.selectedCompression ? AndroidUtilities.dp(6.0f) : this.circleSize / 2, this.paint);
                if (i != 0) {
                    canvas.drawRect((i == PhotoViewer.this.selectedCompression + 1 ? AndroidUtilities.dpf2(2.0f) : 0.0f) + (((i5 - (this.circleSize / 2)) - this.gapSize) - this.lineSize), measuredHeight - AndroidUtilities.dp(1.0f), (r0 + this.lineSize) - (i == PhotoViewer.this.selectedCompression ? AndroidUtilities.dpf2(2.0f) : 0.0f), AndroidUtilities.dp(2.0f) + measuredHeight, this.paint);
                }
                i++;
            }
            canvas.drawText(this.lowQualityDescription, this.sideSide, measuredHeight - AndroidUtilities.dp(16.0f), this.textPaint);
            canvas.drawText(this.hightQualityDescription, (getMeasuredWidth() - this.sideSide) - this.textPaint.measureText(this.hightQualityDescription), measuredHeight - AndroidUtilities.dp(16.0f), this.textPaint);
        }
    }

    public void updateMuteButton() {
        VideoPlayer videoPlayer = this.videoPlayer;
        if (videoPlayer != null) {
            videoPlayer.setMute(this.muteVideo);
        }
        if (!this.videoConvertSupported) {
            this.muteItem.setEnabled(false);
            this.muteItem.setClickable(false);
            this.muteItem.animate().alpha(0.5f).setDuration(180L).start();
            this.videoTimelineView.setMode(0);
            return;
        }
        this.muteItem.setEnabled(true);
        this.muteItem.setClickable(true);
        this.muteItem.animate().alpha(1.0f).setDuration(180L).start();
        if (this.muteVideo) {
            if (this.customTitle == null) {
                this.actionBarContainer.setSubtitle(LocaleController.getString("SoundMuted", R.string.SoundMuted));
            }
            this.muteItem.setImageResource(R.drawable.video_send_mute);
            if (this.compressItem.getTag() != null) {
                this.compressItem.setAlpha(0.5f);
                this.compressItem.setEnabled(false);
            }
            if (this.sendPhotoType == 1) {
                this.videoTimelineView.setMaxProgressDiff(9600.0f / this.videoDuration);
                this.videoTimelineView.setMode(1);
                updateVideoInfo();
            } else {
                this.videoTimelineView.setMaxProgressDiff(1.0f);
                this.videoTimelineView.setMode(0);
            }
            this.muteItem.setContentDescription(LocaleController.getString("NoSound", R.string.NoSound));
            return;
        }
        this.actionBarContainer.setSubtitle(this.currentSubtitle);
        this.muteItem.setImageResource(R.drawable.video_send_unmute);
        this.muteItem.setContentDescription(LocaleController.getString("Sound", R.string.Sound));
        if (this.compressItem.getTag() != null) {
            this.compressItem.setAlpha(1.0f);
            this.compressItem.setEnabled(true);
        }
        this.videoTimelineView.setMaxProgressDiff(1.0f);
        this.videoTimelineView.setMode(0);
    }

    public final void didChangedCompressionLevel(boolean request) {
        SharedPreferences.Editor edit = MessagesController.getGlobalMainSettings().edit();
        edit.putInt(String.format("compress_video_%d", Integer.valueOf(this.compressionsCount)), this.selectedCompression);
        edit.commit();
        updateWidthHeightBitrateForCompression();
        updateVideoInfo();
        if (request) {
            requestVideoPreview(1);
        }
    }

    public final void calculateEstimatedVideoSize(boolean needEncoding, boolean isMute) {
        if (needEncoding) {
            long j = (long) (((isMute ? 0L : this.audioFramesSize) + this.videoFramesSize) * (this.estimatedDuration / this.videoDuration));
            this.estimatedSize = j;
            this.estimatedSize = j + ((j / 32768) * 16);
            return;
        }
        float f = this.originalSize;
        long j2 = this.estimatedDuration;
        float f2 = this.videoDuration;
        long j3 = (long) (f * (j2 / f2));
        this.estimatedSize = j3;
        if (isMute) {
            this.estimatedSize = j3 - ((long) (this.audioFramesSize * (j2 / f2)));
        }
    }

    public final boolean needEncoding() {
        EditState editState = this.editState;
        ArrayList<VideoEditedInfo.MediaEntity> arrayList = null;
        if (editState.croppedPaintPath != null) {
            ArrayList<VideoEditedInfo.MediaEntity> arrayList2 = editState.croppedMediaEntities;
            if (arrayList2 != null && !arrayList2.isEmpty()) {
                arrayList = this.editState.croppedMediaEntities;
            }
        } else {
            ArrayList<VideoEditedInfo.MediaEntity> arrayList3 = editState.mediaEntities;
            if (arrayList3 != null && !arrayList3.isEmpty()) {
                arrayList = this.editState.mediaEntities;
            }
        }
        EditState editState2 = this.editState;
        String str = editState2.croppedPaintPath;
        if (str == null) {
            str = editState2.paintPath;
        }
        if (!this.isH264Video || this.videoCutStart != 0.0f || this.rotationValue != 0 || this.resultWidth != this.originalWidth || this.resultHeight != this.originalHeight) {
            return true;
        }
        EditState editState3 = this.editState;
        return (editState3.cropState == null && arrayList == null && str == null && editState3.savedFilterState == null && this.sendPhotoType != 1) ? false : true;
    }

    public final void updateVideoInfo() {
        int i;
        if (this.actionBar == null) {
            return;
        }
        if (this.compressionsCount == 0) {
            this.actionBarContainer.setSubtitle(null);
            return;
        }
        this.compressItem.setState(this.videoConvertSupported && this.compressionsCount > 1, this.muteVideo, Math.min(this.resultWidth, this.resultHeight));
        this.itemsLayout.requestLayout();
        this.estimatedDuration = (long) Math.ceil((this.videoTimelineView.getRightProgress() - this.videoTimelineView.getLeftProgress()) * this.videoDuration);
        this.videoCutStart = this.videoTimelineView.getLeftProgress();
        this.videoCutEnd = this.videoTimelineView.getRightProgress();
        int i2 = this.rotationValue;
        int i3 = (i2 == 90 || i2 == 270) ? this.resultHeight : this.resultWidth;
        int i4 = this.rotationValue;
        int i5 = (i4 == 90 || i4 == 270) ? this.resultWidth : this.resultHeight;
        boolean needEncoding = needEncoding();
        if (this.muteVideo) {
            if (this.sendPhotoType == 1) {
                long j = this.estimatedDuration;
                i = j <= 2000 ? 2600000 : j <= 5000 ? 2200000 : 1560000;
            } else {
                i = 921600;
            }
            long j2 = (long) ((i / 8) * (this.estimatedDuration / 1000.0f));
            this.estimatedSize = j2;
            this.estimatedSize = j2 + ((j2 / 32768) * 16);
        } else {
            calculateEstimatedVideoSize(needEncoding, this.sendPhotoType == 1);
        }
        float f = this.videoCutStart;
        if (f == 0.0f) {
            this.startTime = -1L;
        } else {
            this.startTime = ((long) (f * this.videoDuration)) * 1000;
        }
        float f2 = this.videoCutEnd;
        if (f2 == 1.0f) {
            this.endTime = -1L;
        } else {
            this.endTime = ((long) (f2 * this.videoDuration)) * 1000;
        }
        this.currentSubtitle = String.format("%s, %s", String.format("%dx%d", Integer.valueOf(i3), Integer.valueOf(i5)), String.format("%s, ~%s", AndroidUtilities.formatShortDuration((int) (this.estimatedDuration / 1000)), AndroidUtilities.formatFileSize(this.estimatedSize)));
        this.actionBar.beginDelayedTransition();
        if (this.customTitle == null) {
            this.actionBarContainer.setSubtitle(this.muteVideo ? LocaleController.getString("SoundMuted", R.string.SoundMuted) : this.currentSubtitle);
        }
    }

    public final void requestVideoPreview(int request) {
        if (this.videoPreviewMessageObject != null) {
            MediaController.getInstance().cancelVideoConvert(this.videoPreviewMessageObject);
        }
        boolean z = this.requestingPreview && !this.tryStartRequestPreviewOnFinish;
        this.requestingPreview = false;
        this.loadInitialVideo = false;
        this.progressView.setVisibility(4);
        if (request == 1) {
            if (this.resultHeight == this.originalHeight && this.resultWidth == this.originalWidth) {
                this.tryStartRequestPreviewOnFinish = false;
                PhotoProgressView[] photoProgressViewArr = this.photoProgressViews;
                photoProgressViewArr[0].setProgress(0.0f, photoProgressViewArr[0].backgroundState == 0 || this.photoProgressViews[0].previousBackgroundState == 0);
                this.photoProgressViews[0].setBackgroundState(3, false, true);
                if (!z) {
                    preparePlayer(this.currentPlayingVideoFile, false, false, this.editState.savedFilterState);
                    this.videoPlayer.seekTo((long) (this.videoTimelineView.getLeftProgress() * this.videoDuration));
                } else {
                    this.loadInitialVideo = true;
                }
            } else {
                releasePlayer(false);
                if (this.videoPreviewMessageObject == null) {
                    TLRPC.TL_message tL_message = new TLRPC.TL_message();
                    ((TLRPC.Message) tL_message).id = 0;
                    ((TLRPC.Message) tL_message).message = "";
                    ((TLRPC.Message) tL_message).media = new TLRPC.TL_messageMediaEmpty();
                    ((TLRPC.Message) tL_message).action = new TLRPC.TL_messageActionEmpty();
                    ((TLRPC.Message) tL_message).dialog_id = this.currentDialogId;
                    MessageObject messageObject = new MessageObject(UserConfig.selectedAccount, tL_message, false, false);
                    this.videoPreviewMessageObject = messageObject;
                    messageObject.messageOwner.attachPath = new File(FileLoader.getDirectory(4), "video_preview.mp4").getAbsolutePath();
                    this.videoPreviewMessageObject.videoEditedInfo = new VideoEditedInfo();
                    VideoEditedInfo videoEditedInfo = this.videoPreviewMessageObject.videoEditedInfo;
                    videoEditedInfo.rotationValue = this.rotationValue;
                    videoEditedInfo.originalWidth = this.originalWidth;
                    this.videoPreviewMessageObject.videoEditedInfo.originalHeight = this.originalHeight;
                    VideoEditedInfo videoEditedInfo2 = this.videoPreviewMessageObject.videoEditedInfo;
                    videoEditedInfo2.framerate = this.videoFramerate;
                    videoEditedInfo2.originalPath = this.currentPlayingVideoFile.getPath();
                }
                VideoEditedInfo videoEditedInfo3 = this.videoPreviewMessageObject.videoEditedInfo;
                long j = this.startTime;
                videoEditedInfo3.startTime = j;
                long j2 = this.endTime;
                videoEditedInfo3.endTime = j2;
                if (j == -1) {
                    j = 0;
                }
                if (j2 == -1) {
                    j2 = (long) (this.videoDuration * 1000.0f);
                }
                if (j2 - j > 5000000) {
                    videoEditedInfo3.endTime = j + 5000000;
                }
                videoEditedInfo3.bitrate = this.bitrate;
                this.videoPreviewMessageObject.videoEditedInfo.resultWidth = this.resultWidth;
                this.videoPreviewMessageObject.videoEditedInfo.resultHeight = this.resultHeight;
                VideoEditedInfo videoEditedInfo4 = this.videoPreviewMessageObject.videoEditedInfo;
                videoEditedInfo4.needUpdateProgress = true;
                videoEditedInfo4.originalDuration = (long) (this.videoDuration * 1000.0f);
                if (!MediaController.getInstance().scheduleVideoConvert(this.videoPreviewMessageObject, true, true)) {
                    this.tryStartRequestPreviewOnFinish = true;
                }
                this.requestingPreview = true;
                PhotoProgressView[] photoProgressViewArr2 = this.photoProgressViews;
                photoProgressViewArr2[0].setProgress(0.0f, photoProgressViewArr2[0].backgroundState == 0 || this.photoProgressViews[0].previousBackgroundState == 0);
                this.photoProgressViews[0].setBackgroundState(0, false, true);
            }
        } else {
            this.tryStartRequestPreviewOnFinish = false;
            this.photoProgressViews[0].setBackgroundState(3, false, true);
            if (request == 2) {
                preparePlayer(this.currentPlayingVideoFile, false, false, this.editState.savedFilterState);
                this.videoPlayer.seekTo((long) (this.videoTimelineView.getLeftProgress() * this.videoDuration));
            }
        }
        this.containerView.invalidate();
    }

    public final Size calculateResultVideoSize() {
        int round;
        int i;
        if (this.compressionsCount == 1) {
            return new Size(this.originalWidth, this.originalHeight);
        }
        int i2 = this.selectedCompression;
        float f = (i2 != 0 ? i2 != 1 ? i2 != 2 ? 1920.0f : 1280.0f : 854.0f : 480.0f) / (this.originalWidth > this.originalHeight ? this.originalWidth : this.originalHeight);
        if (this.selectedCompression == this.compressionsCount - 1 && f >= 1.0f) {
            i = this.originalWidth;
            round = this.originalHeight;
        } else {
            int round2 = Math.round((this.originalWidth * f) / 2.0f) * 2;
            round = Math.round((this.originalHeight * f) / 2.0f) * 2;
            i = round2;
        }
        return new Size(i, round);
    }

    public final void prepareRealEncoderBitrate() {
        if (this.bitrate == 0 || this.sendPhotoType == 1) {
            return;
        }
        Size calculateResultVideoSize = calculateResultVideoSize();
        if (calculateResultVideoSize.getWidth() == this.originalWidth && calculateResultVideoSize.getHeight() == this.originalHeight) {
            MediaController.extractRealEncoderBitrate(calculateResultVideoSize.getWidth(), calculateResultVideoSize.getHeight(), this.originalBitrate, false);
        } else {
            MediaController.extractRealEncoderBitrate(calculateResultVideoSize.getWidth(), calculateResultVideoSize.getHeight(), MediaController.makeVideoBitrate(this.originalHeight, this.originalWidth, this.originalBitrate, calculateResultVideoSize.getHeight(), calculateResultVideoSize.getWidth()), false);
        }
    }

    public final void updateWidthHeightBitrateForCompression() {
        int extractRealEncoderBitrate;
        if (this.compressionsCount <= 0) {
            return;
        }
        if (this.selectedCompression >= this.compressionsCount) {
            this.selectedCompression = this.compressionsCount - 1;
        }
        if (this.sendPhotoType == 1) {
            float max = Math.max(800.0f / this.originalWidth, 800.0f / this.originalHeight);
            this.resultWidth = Math.round((this.originalWidth * max) / 2.0f) * 2;
            this.resultHeight = Math.round((this.originalHeight * max) / 2.0f) * 2;
        } else {
            Size calculateResultVideoSize = calculateResultVideoSize();
            this.resultWidth = calculateResultVideoSize.getWidth();
            this.resultHeight = calculateResultVideoSize.getHeight();
        }
        if (this.bitrate != 0) {
            if (this.sendPhotoType == 1) {
                this.bitrate = 1560000;
                extractRealEncoderBitrate = this.bitrate;
            } else if (this.resultWidth == this.originalWidth && this.resultHeight == this.originalHeight) {
                this.bitrate = this.originalBitrate;
                extractRealEncoderBitrate = MediaController.extractRealEncoderBitrate(this.resultWidth, this.resultHeight, this.bitrate, false);
            } else {
                this.bitrate = MediaController.makeVideoBitrate(this.originalHeight, this.originalWidth, this.originalBitrate, this.resultHeight, this.resultWidth);
                extractRealEncoderBitrate = MediaController.extractRealEncoderBitrate(this.resultWidth, this.resultHeight, this.bitrate, false);
            }
            this.videoFramesSize = (long) (((extractRealEncoderBitrate / 8) * this.videoDuration) / 1000.0f);
        }
    }

    public final void showQualityView(final boolean show) {
        TextureView textureView;
        if (show && this.textureUploaded && this.videoSizeSet && !this.changingTextureView && (textureView = this.videoTextureView) != null) {
            this.videoFrameBitmap = textureView.getBitmap();
        }
        if (show) {
            this.previousCompression = this.selectedCompression;
        }
        AnimatorSet animatorSet = this.qualityChooseViewAnimation;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        this.qualityChooseViewAnimation = new AnimatorSet();
        if (show) {
            if (this.fancyShadows) {
                this.navigationBar.setVisibility(0);
                this.navigationBar.setAlpha(this.sendPhotoType == 11 ? 1.0f : 0.0f);
                this.navigationBar.setBackgroundColor(this.sendPhotoType == 11 ? 1711276032 : 2130706432);
            }
            this.qualityChooseView.setTag(1);
            AnimatorSet animatorSet2 = this.qualityChooseViewAnimation;
            Animator[] animatorArr = new Animator[4];
            FrameLayout frameLayout = this.pickerView;
            Property property = View.TRANSLATION_Y;
            float[] fArr = new float[2];
            fArr[0] = 0.0f;
            fArr[1] = frameLayout.getHeight() + this.captionEdit.getEditTextHeight() + (this.isCurrentVideo ? AndroidUtilities.dp(58.0f) : 0);
            animatorArr[0] = ObjectAnimator.ofFloat(frameLayout, (Property<FrameLayout, Float>) property, fArr);
            animatorArr[1] = ObjectAnimator.ofFloat(this.pickerView, (Property<FrameLayout, Float>) View.ALPHA, 0.0f);
            animatorArr[2] = ObjectAnimator.ofFloat(this.pickerViewSendButton, (Property<ImageView, Float>) View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(158.0f));
            View view = this.navigationBar;
            Property property2 = View.ALPHA;
            float[] fArr2 = new float[2];
            fArr2[0] = this.fancyShadows ? 0.0f : 1.0f;
            fArr2[1] = 1.0f;
            animatorArr[3] = ObjectAnimator.ofFloat(view, (Property<View, Float>) property2, fArr2);
            animatorSet2.playTogether(animatorArr);
        } else {
            this.qualityChooseView.setTag(null);
            AnimatorSet animatorSet3 = this.qualityChooseViewAnimation;
            Animator[] animatorArr2 = new Animator[3];
            animatorArr2[0] = ObjectAnimator.ofFloat(this.qualityChooseView, (Property<QualityChooseView, Float>) View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(166.0f));
            animatorArr2[1] = ObjectAnimator.ofFloat(this.qualityPicker, (Property<PickerBottomLayoutViewer, Float>) View.TRANSLATION_Y, 0.0f, AndroidUtilities.dp(166.0f));
            View view2 = this.navigationBar;
            Property property3 = View.ALPHA;
            float[] fArr3 = new float[2];
            fArr3[0] = 1.0f;
            fArr3[1] = this.fancyShadows ? 0.0f : 1.0f;
            animatorArr2[2] = ObjectAnimator.ofFloat(view2, (Property<View, Float>) property3, fArr3);
            animatorSet3.playTogether(animatorArr2);
        }
        this.qualityChooseViewAnimation.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (animation.equals(PhotoViewer.this.qualityChooseViewAnimation)) {
                    PhotoViewer.this.qualityChooseViewAnimation = new AnimatorSet();
                    if (show) {
                        PhotoViewer.this.qualityChooseView.setVisibility(0);
                        PhotoViewer.this.qualityPicker.setVisibility(0);
                        PhotoViewer.this.qualityChooseViewAnimation.playTogether(ObjectAnimator.ofFloat(PhotoViewer.this.qualityChooseView, (Property<QualityChooseView, Float>) View.TRANSLATION_Y, 0.0f), ObjectAnimator.ofFloat(PhotoViewer.this.qualityPicker, (Property<PickerBottomLayoutViewer, Float>) View.TRANSLATION_Y, 0.0f));
                    } else {
                        if (PhotoViewer.this.fancyShadows) {
                            PhotoViewer.this.navigationBar.setVisibility(8);
                            PhotoViewer.this.navigationBar.setAlpha(0.0f);
                            PhotoViewer.this.navigationBar.setBackgroundColor(PhotoViewer.this.sendPhotoType == 11 ? -16777216 : 2130706432);
                        }
                        PhotoViewer.this.qualityChooseView.setVisibility(4);
                        PhotoViewer.this.qualityPicker.setVisibility(4);
                        PhotoViewer.this.qualityChooseViewAnimation.playTogether(ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.TRANSLATION_Y, 0.0f), ObjectAnimator.ofFloat(PhotoViewer.this.pickerView, (Property<FrameLayout, Float>) View.ALPHA, 1.0f), ObjectAnimator.ofFloat(PhotoViewer.this.pickerViewSendButton, (Property<ImageView, Float>) View.TRANSLATION_Y, 0.0f));
                    }
                    PhotoViewer.this.qualityChooseViewAnimation.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation2) {
                            if (animation2.equals(PhotoViewer.this.qualityChooseViewAnimation)) {
                                PhotoViewer.this.qualityChooseViewAnimation = null;
                            }
                        }
                    });
                    PhotoViewer.this.qualityChooseViewAnimation.setDuration(200L);
                    PhotoViewer.this.qualityChooseViewAnimation.setInterpolator(AndroidUtilities.decelerateInterpolator);
                    PhotoViewer.this.qualityChooseViewAnimation.start();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                PhotoViewer.this.qualityChooseViewAnimation = null;
            }
        });
        this.qualityChooseViewAnimation.setDuration(200L);
        this.qualityChooseViewAnimation.setInterpolator(AndroidUtilities.accelerateInterpolator);
        this.qualityChooseViewAnimation.start();
        if (this.muteItem.getVisibility() == 0) {
            this.muteItem.animate().scaleX(show ? 0.25f : 1.0f).scaleY(show ? 0.25f : 1.0f).alpha(show ? 0.0f : 1.0f).setDuration(200L);
        }
    }

    public final void processOpenVideo(final String videoPath, boolean muted, float start, float end, final int compressQuality) {
        if (this.currentLoadingVideoRunnable != null) {
            Utilities.globalQueue.cancelRunnable(this.currentLoadingVideoRunnable);
            this.currentLoadingVideoRunnable = null;
        }
        this.videoTimelineView.setVideoPath(videoPath, start, end);
        this.videoPreviewMessageObject = null;
        boolean z = true;
        if (!muted && this.sendPhotoType != 1) {
            z = false;
        }
        this.muteVideo = z;
        this.compressionsCount = -1;
        this.rotationValue = 0;
        this.videoFramerate = 25;
        this.originalSize = new File(videoPath).length();
        DispatchQueue dispatchQueue = Utilities.globalQueue;
        AnonymousClass84 anonymousClass84 = new AnonymousClass84(videoPath, compressQuality);
        this.currentLoadingVideoRunnable = anonymousClass84;
        dispatchQueue.postRunnable(anonymousClass84);
    }

    public class AnonymousClass84 implements Runnable {
        public final int val$compressQuality;
        public final String val$videoPath;

        public AnonymousClass84(final String val$videoPath, final int val$compressQuality) {
            this.val$videoPath = val$videoPath;
            this.val$compressQuality = val$compressQuality;
        }

        @Override
        public void run() {
            if (PhotoViewer.this.currentLoadingVideoRunnable != this) {
                return;
            }
            int videoBitrate = MediaController.getVideoBitrate(this.val$videoPath);
            final int[] iArr = new int[11];
            AnimatedFileDrawable.getVideoInfo(this.val$videoPath, iArr);
            boolean z = false;
            boolean z2 = iArr[10] != 0;
            PhotoViewer photoViewer = PhotoViewer.this;
            if (iArr[0] != 0 && (!z2 || iArr[9] != 0)) {
                z = true;
            }
            photoViewer.videoConvertSupported = z;
            PhotoViewer photoViewer2 = PhotoViewer.this;
            if (videoBitrate == -1) {
                videoBitrate = iArr[3];
            }
            photoViewer2.bitrate = videoBitrate;
            photoViewer2.originalBitrate = videoBitrate;
            if (PhotoViewer.this.videoConvertSupported) {
                PhotoViewer photoViewer3 = PhotoViewer.this;
                int i = iArr[1];
                photoViewer3.originalWidth = i;
                photoViewer3.resultWidth = i;
                PhotoViewer photoViewer4 = PhotoViewer.this;
                int i2 = iArr[2];
                photoViewer4.originalHeight = i2;
                photoViewer4.resultHeight = i2;
                PhotoViewer photoViewer5 = PhotoViewer.this;
                photoViewer5.updateCompressionsCount(photoViewer5.originalWidth, PhotoViewer.this.originalHeight);
                PhotoViewer photoViewer6 = PhotoViewer.this;
                int i3 = this.val$compressQuality;
                if (i3 == -1) {
                    i3 = photoViewer6.selectCompression();
                }
                photoViewer6.selectedCompression = i3;
                PhotoViewer.this.prepareRealEncoderBitrate();
                PhotoViewer.this.isH264Video = MediaController.isH264Video(this.val$videoPath);
            }
            if (PhotoViewer.this.currentLoadingVideoRunnable != this) {
                return;
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PhotoViewer.AnonymousClass84.this.lambda$run$0(this, iArr);
                }
            });
        }

        public void lambda$run$0(Runnable runnable, int[] iArr) {
            if (PhotoViewer.this.parentActivity == null || runnable != PhotoViewer.this.currentLoadingVideoRunnable) {
                return;
            }
            PhotoViewer.this.currentLoadingVideoRunnable = null;
            PhotoViewer.this.audioFramesSize = iArr[5];
            PhotoViewer.this.videoDuration = iArr[4];
            PhotoViewer.this.videoFramerate = iArr[7];
            PhotoViewer.this.videoFramesSize = (long) (((r5.bitrate / 8) * PhotoViewer.this.videoDuration) / 1000.0f);
            if (PhotoViewer.this.videoConvertSupported) {
                PhotoViewer.this.rotationValue = iArr[8];
                PhotoViewer.this.updateWidthHeightBitrateForCompression();
                if (PhotoViewer.this.selectedCompression > PhotoViewer.this.compressionsCount - 1) {
                    PhotoViewer photoViewer = PhotoViewer.this;
                    photoViewer.selectedCompression = photoViewer.compressionsCount - 1;
                }
                PhotoViewer.this.compressItem.setState(PhotoViewer.this.compressionsCount > 1, PhotoViewer.this.muteVideo, Math.min(PhotoViewer.this.resultWidth, PhotoViewer.this.resultHeight));
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("compressionsCount = " + PhotoViewer.this.compressionsCount + " w = " + PhotoViewer.this.originalWidth + " h = " + PhotoViewer.this.originalHeight + " r = " + PhotoViewer.this.rotationValue);
                }
                PhotoViewer.this.qualityChooseView.invalidate();
            } else {
                PhotoViewer.this.compressItem.setState(false, PhotoViewer.this.muteVideo, Math.min(PhotoViewer.this.resultWidth, PhotoViewer.this.resultHeight));
                PhotoViewer.this.compressionsCount = 0;
            }
            PhotoViewer.this.updateVideoInfo();
            PhotoViewer.this.updateMuteButton();
        }
    }

    public final int selectCompression() {
        if (this.originalSize > 1048576000) {
            return this.compressionsCount - 1;
        }
        SharedPreferences globalMainSettings = MessagesController.getGlobalMainSettings();
        int i = this.compressionsCount;
        while (i < 5) {
            int i2 = globalMainSettings.getInt(String.format(Locale.US, "compress_video_%d", Integer.valueOf(i)), -1);
            if (i2 >= 0) {
                return Math.min(i2, 4);
            }
            i++;
        }
        return Math.min(4, Math.round(DownloadController.getInstance(this.currentAccount).getMaxVideoBitrate() / (100.0f / i)) - 1);
    }

    public final void updateCompressionsCount(int h, int w) {
        int max = Math.max(h, w);
        if (max > 1280) {
            this.compressionsCount = 4;
            return;
        }
        if (max > 854) {
            this.compressionsCount = 3;
        } else if (max > 640) {
            this.compressionsCount = 2;
        } else {
            this.compressionsCount = 1;
        }
    }

    public final void updateAccessibilityOverlayVisibility() {
        if (this.playButtonAccessibilityOverlay != null) {
            int i = this.photoProgressViews[0].backgroundState;
            if (this.photoProgressViews[0].isVisible() && (i == 3 || i == 4 || i == 2 || i == 1)) {
                if (i == 3) {
                    this.playButtonAccessibilityOverlay.setContentDescription(LocaleController.getString("AccActionPlay", R.string.AccActionPlay));
                } else if (i == 2) {
                    this.playButtonAccessibilityOverlay.setContentDescription(LocaleController.getString("AccActionDownload", R.string.AccActionDownload));
                } else if (i == 1) {
                    this.playButtonAccessibilityOverlay.setContentDescription(LocaleController.getString("AccActionCancelDownload", R.string.AccActionCancelDownload));
                } else {
                    this.playButtonAccessibilityOverlay.setContentDescription(LocaleController.getString("AccActionPause", R.string.AccActionPause));
                }
                this.playButtonAccessibilityOverlay.setVisibility(0);
                return;
            }
            this.playButtonAccessibilityOverlay.setVisibility(4);
        }
    }

    public class ListAdapter extends RecyclerListView.SelectionAdapter {
        public Context mContext;

        public int getItemViewType(int i) {
            return 0;
        }

        public boolean isEnabled(RecyclerView.ViewHolder holder) {
            return false;
        }

        public ListAdapter(Context context) {
            this.mContext = context;
        }

        public int getItemCount() {
            if (PhotoViewer.this.placeProvider == null || PhotoViewer.this.placeProvider.getSelectedPhotosOrder() == null) {
                return 0;
            }
            return PhotoViewer.this.placeProvider.getSelectedPhotosOrder().size();
        }

        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            PhotoPickerPhotoCell photoPickerPhotoCell = new PhotoPickerPhotoCell(this.mContext);
            photoPickerPhotoCell.checkFrame.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PhotoViewer.ListAdapter.this.lambda$onCreateViewHolder$0(view);
                }
            });
            return new RecyclerListView.Holder(photoPickerPhotoCell);
        }

        public void lambda$onCreateViewHolder$0(View view) {
            Object tag = ((View) view.getParent()).getTag();
            int indexOf = PhotoViewer.this.imagesArrLocals.indexOf(tag);
            if (indexOf >= 0) {
                int photoChecked = PhotoViewer.this.placeProvider.setPhotoChecked(indexOf, PhotoViewer.this.getCurrentVideoEditedInfo());
                boolean isPhotoChecked = PhotoViewer.this.placeProvider.isPhotoChecked(indexOf);
                if (indexOf == PhotoViewer.this.currentIndex) {
                    PhotoViewer.this.checkImageView.setChecked(-1, isPhotoChecked, true);
                }
                if (photoChecked >= 0) {
                    PhotoViewer.this.selectedPhotosAdapter.notifyItemRemoved(photoChecked);
                    if (photoChecked == 0) {
                        PhotoViewer.this.selectedPhotosAdapter.notifyItemChanged(0);
                    }
                }
                PhotoViewer.this.updateSelectedCount();
                return;
            }
            int photoUnchecked = PhotoViewer.this.placeProvider.setPhotoUnchecked(tag);
            if (photoUnchecked >= 0) {
                PhotoViewer.this.selectedPhotosAdapter.notifyItemRemoved(photoUnchecked);
                if (photoUnchecked == 0) {
                    PhotoViewer.this.selectedPhotosAdapter.notifyItemChanged(0);
                }
                PhotoViewer.this.updateSelectedCount();
            }
        }

        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            PhotoPickerPhotoCell photoPickerPhotoCell = (PhotoPickerPhotoCell) holder.itemView;
            photoPickerPhotoCell.setItemWidth(AndroidUtilities.dp(85.0f), position != 0 ? AndroidUtilities.dp(6.0f) : 0);
            BackupImageView backupImageView = photoPickerPhotoCell.imageView;
            backupImageView.setOrientation(0, true);
            Object obj = PhotoViewer.this.placeProvider.getSelectedPhotos().get(PhotoViewer.this.placeProvider.getSelectedPhotosOrder().get(position));
            if (obj instanceof MediaController.PhotoEntry) {
                MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) obj;
                photoPickerPhotoCell.setTag(photoEntry);
                photoPickerPhotoCell.videoInfoContainer.setVisibility(4);
                String str = ((MediaController.MediaEditState) photoEntry).thumbPath;
                if (str != null) {
                    backupImageView.setImage(str, (String) null, this.mContext.getResources().getDrawable(R.drawable.nophotos));
                } else if (photoEntry.path != null) {
                    backupImageView.setOrientation(photoEntry.orientation, photoEntry.invert, true);
                    if (photoEntry.isVideo) {
                        photoPickerPhotoCell.videoInfoContainer.setVisibility(0);
                        photoPickerPhotoCell.videoTextView.setText(AndroidUtilities.formatShortDuration(photoEntry.duration));
                        backupImageView.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, (String) null, this.mContext.getResources().getDrawable(R.drawable.nophotos));
                    } else {
                        backupImageView.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, (String) null, this.mContext.getResources().getDrawable(R.drawable.nophotos));
                    }
                } else {
                    backupImageView.setImageResource(R.drawable.nophotos);
                }
                photoPickerPhotoCell.setChecked(-1, true, false);
                photoPickerPhotoCell.checkBox.setVisibility(0);
                return;
            }
            if (obj instanceof MediaController.SearchImage) {
                MediaController.SearchImage searchImage = (MediaController.SearchImage) obj;
                photoPickerPhotoCell.setTag(searchImage);
                photoPickerPhotoCell.setImage(searchImage);
                photoPickerPhotoCell.videoInfoContainer.setVisibility(4);
                photoPickerPhotoCell.setChecked(-1, true, false);
                photoPickerPhotoCell.checkBox.setVisibility(0);
            }
        }
    }

    public class FirstFrameView extends ImageView {
        public VideoPlayer currentVideoPlayer;
        public ValueAnimator fadeAnimator;
        public final TimeInterpolator fadeInterpolator;
        public boolean gettingFrame;
        public int gettingFrameIndex;
        public boolean gotError;
        public boolean hasFrame;

        public FirstFrameView(Context context) {
            super(context);
            this.gettingFrameIndex = 0;
            this.gettingFrame = false;
            this.hasFrame = false;
            this.gotError = false;
            this.fadeInterpolator = CubicBezierInterpolator.EASE_IN;
            setAlpha(0.0f);
        }

        public void clear() {
            this.hasFrame = false;
            this.gotError = false;
            if (this.gettingFrame) {
                this.gettingFrameIndex++;
                this.gettingFrame = false;
            }
            setImageResource(android.R.color.transparent);
        }

        public void checkFromPlayer(VideoPlayer videoPlayer) {
            if (this.currentVideoPlayer != videoPlayer) {
                this.gotError = false;
                clear();
            }
            if (videoPlayer != null && !videoPlayer.isHDR()) {
                long duration = videoPlayer.getDuration() - videoPlayer.getCurrentPosition();
                if (!this.hasFrame && !this.gotError && !this.gettingFrame && duration < 5250.0f) {
                    final Uri currentUri = videoPlayer.getCurrentUri();
                    final int i = this.gettingFrameIndex + 1;
                    this.gettingFrameIndex = i;
                    Utilities.globalQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            PhotoViewer.FirstFrameView.this.lambda$checkFromPlayer$2(currentUri, i);
                        }
                    });
                    this.gettingFrame = true;
                }
            }
            this.currentVideoPlayer = videoPlayer;
        }

        public void lambda$checkFromPlayer$2(Uri uri, final int i) {
            try {
                File file = new File(uri.getPath());
                int i2 = UserConfig.selectedAccount;
                Point point = AndroidUtilities.displaySize;
                AnimatedFileDrawable animatedFileDrawable = new AnimatedFileDrawable(file, true, 0L, 0, (TLRPC.Document) null, (ImageLocation) null, (Object) null, 0L, i2, false, point.x, point.y, (BitmapsCache.CacheOptions) null);
                final Bitmap frameAtTime = animatedFileDrawable.getFrameAtTime(0L);
                animatedFileDrawable.recycle();
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.FirstFrameView.this.lambda$checkFromPlayer$0(i, frameAtTime);
                    }
                });
            } catch (Throwable th) {
                FileLog.e(th);
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PhotoViewer.FirstFrameView.this.lambda$checkFromPlayer$1();
                    }
                });
            }
        }

        public void lambda$checkFromPlayer$0(int i, Bitmap bitmap) {
            if (i == this.gettingFrameIndex) {
                setImageBitmap(bitmap);
                this.hasFrame = true;
                this.gettingFrame = false;
            }
        }

        public void lambda$checkFromPlayer$1() {
            this.gotError = true;
        }

        public final void updateAlpha() {
            if (PhotoViewer.this.videoPlayer == null || PhotoViewer.this.videoPlayer.getDuration() == -9223372036854775807L) {
                ValueAnimator valueAnimator = this.fadeAnimator;
                if (valueAnimator != null) {
                    valueAnimator.cancel();
                    this.fadeAnimator = null;
                }
                setAlpha(0.0f);
                return;
            }
            long max = Math.max(0L, PhotoViewer.this.videoPlayer.getDuration() - PhotoViewer.this.videoPlayer.getCurrentPosition());
            float max2 = 1.0f - Math.max(Math.min(max / 250.0f, 1.0f), 0.0f);
            if (max2 <= 0.0f) {
                ValueAnimator valueAnimator2 = this.fadeAnimator;
                if (valueAnimator2 != null) {
                    valueAnimator2.cancel();
                    this.fadeAnimator = null;
                }
                setAlpha(0.0f);
                return;
            }
            if (PhotoViewer.this.videoPlayer.isPlaying()) {
                if (this.fadeAnimator == null) {
                    ValueAnimator ofFloat = ValueAnimator.ofFloat(max2, 1.0f);
                    this.fadeAnimator = ofFloat;
                    ofFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public final void onAnimationUpdate(ValueAnimator valueAnimator3) {
                            PhotoViewer.FirstFrameView.this.lambda$updateAlpha$3(valueAnimator3);
                        }
                    });
                    this.fadeAnimator.setDuration(max);
                    this.fadeAnimator.setInterpolator(this.fadeInterpolator);
                    this.fadeAnimator.start();
                    setAlpha(max2);
                    return;
                }
                return;
            }
            ValueAnimator valueAnimator3 = this.fadeAnimator;
            if (valueAnimator3 != null) {
                valueAnimator3.cancel();
                this.fadeAnimator = null;
            }
            setAlpha(max2);
        }

        public void lambda$updateAlpha$3(ValueAnimator valueAnimator) {
            setAlpha(((Float) valueAnimator.getAnimatedValue()).floatValue());
        }
    }

    public final int getThemedColor(int key) {
        Theme.ResourcesProvider resourcesProvider = this.resourcesProvider;
        if (resourcesProvider != null) {
            return resourcesProvider.getColor(key);
        }
        return Theme.getColor(key);
    }

    public static boolean BLUR_RENDERNODE() {
        return Build.VERSION.SDK_INT >= 31 && SharedConfig.useNewBlur && SharedConfig.getDevicePerformanceClass() >= 2;
    }

    public final void drawCaptionBlur(android.graphics.Canvas r44, org.telegram.ui.Components.BlurringShader.StoryBlurDrawer r45, int r46, int r47, boolean r48, boolean r49, boolean r50) {
        throw new UnsupportedOperationException("Method not decompiled: org.telegram.ui.PhotoViewer.drawCaptionBlur(android.graphics.Canvas, org.telegram.ui.Components.BlurringShader$StoryBlurDrawer, int, int, boolean, boolean, boolean):void");
    }

    public final void cancelStickerClippingMode() {
        if (this.sendPhotoType == 11 && this.cutOutBtn.isCancelState()) {
            this.cutOutBtn.setCutOutState(true);
            showEditStickerMode(true, true);
            this.stickerMakerView.disableClippingMode();
            this.containerView.invalidate();
        }
    }

    public final void invalidateBlur() {
        StickerMakerView stickerMakerView = this.stickerMakerView;
        if (stickerMakerView == null || !stickerMakerView.isThanosInProgress) {
            CaptionPhotoViewer captionPhotoViewer = this.captionEdit;
            if (captionPhotoViewer != null) {
                captionPhotoViewer.invalidateBlur();
            }
            BlurButton blurButton = this.cutOutBtn;
            if (blurButton != null) {
                blurButton.invalidateBlur();
            }
            BlurButton blurButton2 = this.eraseBtn;
            if (blurButton2 != null) {
                blurButton2.invalidateBlur();
            }
            BlurButton blurButton3 = this.restoreBtn;
            if (blurButton3 != null) {
                blurButton3.invalidateBlur();
            }
            BlurButton blurButton4 = this.undoBtn;
            if (blurButton4 != null) {
                blurButton4.invalidateBlur();
            }
            BlurButton blurButton5 = this.outlineBtn;
            if (blurButton5 != null) {
                blurButton5.invalidateBlur();
            }
            VideoTimelinePlayView videoTimelinePlayView = this.videoTimelineView;
            if (videoTimelinePlayView != null) {
                videoTimelinePlayView.invalidateBlur();
            }
            SizeNotifierFrameLayoutPhoto sizeNotifierFrameLayoutPhoto = this.containerView;
            if (sizeNotifierFrameLayoutPhoto != null) {
                sizeNotifierFrameLayoutPhoto.invalidate();
            }
        }
    }

    public class BlurButton extends StickerCutOutBtn {
        public boolean active;
        public final AnimatedFloat activeFloat;
        public final Path path;

        public BlurButton() {
            super(PhotoViewer.this.stickerMakerView, PhotoViewer.this.activityContext, PhotoViewer.this.resourcesProvider, PhotoViewer.this.blurManager);
            this.path = new Path();
            this.activeFloat = new AnimatedFloat(this, 0L, 420L, CubicBezierInterpolator.EASE_OUT_QUINT);
        }

        @Override
        public void onDraw(Canvas canvas) {
            canvas.save();
            this.path.rewind();
            this.path.addRoundRect(this.bounds, AndroidUtilities.dp(this.rad), AndroidUtilities.dp(this.rad), Path.Direction.CW);
            canvas.clipPath(this.path);
            canvas.translate(-getX(), -getY());
            if (this == PhotoViewer.this.eraseBtn || this == PhotoViewer.this.restoreBtn) {
                canvas.translate(-PhotoViewer.this.btnLayout.getX(), -PhotoViewer.this.btnLayout.getY());
            }
            PhotoViewer.this.drawCaptionBlur(canvas, this.blurDrawer, -13948117, 855638016, false, true, false);
            float f = this.activeFloat.set(this.active);
            if (f > 0.0f) {
                canvas.drawColor(Theme.multAlpha(-1, f));
            }
            setTextColor(ColorUtils.blendARGB(-1, -16777216, f));
            canvas.restore();
            super.onDraw(canvas);
        }

        public void onDrawForeground(Canvas canvas) {
            canvas.save();
            canvas.clipPath(this.path);
            super/*android.widget.FrameLayout*/.onDrawForeground(canvas);
            canvas.restore();
        }

        public void setActive(boolean active, boolean animated) {
            this.active = active;
            if (!animated) {
                this.activeFloat.set(active, true);
            }
            invalidate();
        }

        public boolean isActive() {
            return this.active;
        }
    }

    public final void applyTransformToOutline(Canvas canvas) {
        float f;
        float f2;
        float f3;
        float f4;
        float f5;
        float f6;
        float f7;
        if (this.imageMoveAnimation != null) {
            f2 = AndroidUtilities.lerp(this.mirror, this.animateToMirror, this.animationValue);
            f = AndroidUtilities.lerp(this.scale, this.animateToScale, this.animationValue);
            f3 = AndroidUtilities.lerp(this.rotate, this.animateToRotate, this.animationValue);
            f4 = AndroidUtilities.lerp(this.translationY, this.animateToY, this.animationValue);
            f5 = AndroidUtilities.lerp(this.translationX, this.animateToX, this.animationValue);
        } else {
            f = this.scale;
            f2 = this.mirror;
            f3 = this.rotate;
            f4 = this.translationY;
            f5 = this.translationX;
            if (this.animationStartTime != 0) {
                f5 = this.animateToX;
                f4 = this.animateToY;
                f = this.animateToScale;
            }
        }
        int containerViewWidth = getContainerViewWidth();
        int containerViewHeight = getContainerViewHeight();
        canvas.translate(getAdditionX(this.currentEditMode), getAdditionY(this.currentEditMode));
        canvas.translate(f5, f4 + (this.currentEditMode != 3 ? this.currentPanTranslationY : 0.0f));
        canvas.scale(f, f);
        canvas.rotate(f3);
        int bitmapWidth = this.centerImage.getBitmapWidth();
        int bitmapHeight = this.centerImage.getBitmapHeight();
        float f8 = containerViewWidth;
        float f9 = bitmapWidth;
        float f10 = f8 / f9;
        float f11 = containerViewHeight;
        float f12 = bitmapHeight;
        float f13 = f11 / f12;
        float min = Math.min(f10, f13);
        int orientation = this.cropTransform.getOrientation();
        if (orientation == 90 || orientation == 270) {
            bitmapHeight = bitmapWidth;
            bitmapWidth = bitmapHeight;
        }
        float cropPw = this.cropTransform.getCropPw();
        float cropPh = this.cropTransform.getCropPh();
        float f14 = bitmapWidth;
        float f15 = bitmapHeight;
        float f16 = (int) ((cropPw + ((1.0f - cropPw) * 0.0f)) * f14);
        float f17 = f8 / f16;
        float f18 = (int) ((cropPh + ((1.0f - cropPh) * 0.0f)) * f15);
        if (f17 * f18 > f11) {
            f17 = f11 / f18;
        }
        float f19 = f2;
        if (this.sendPhotoType != 1 && ((this.currentEditMode != 1 || this.switchingToMode == 0) && this.editState.cropState != null)) {
            float f20 = f16 * f17;
            float f21 = f18 * f17;
            if (f10 * f12 > f11) {
                f10 = f13;
            }
            float f22 = f20 + ((((f9 * f10) / f) - f20) * 0.0f);
            float f23 = f21 + ((((f12 * f10) / f) - f21) * 0.0f);
            canvas.clipRect((-f22) / 2.0f, (-f23) / 2.0f, f22 / 2.0f, f23 / 2.0f);
        }
        if (this.sendPhotoType == 1 || this.cropTransform.hasViewTransform()) {
            TextureView textureView = this.videoTextureView;
            if (textureView != null) {
                MediaController.CropState cropState = this.editState.cropState;
                textureView.setScaleX((cropState == null || !cropState.mirrored) ? 1.0f : -1.0f);
                FirstFrameView firstFrameView = this.firstFrameView;
                if (firstFrameView != null) {
                    firstFrameView.setScaleX(this.videoTextureView.getScaleX());
                }
            }
            MediaController.CropState cropState2 = this.editState.cropState;
            if (cropState2 != null) {
                f7 = cropState2.cropScale;
                f6 = 1.0f;
            } else {
                f6 = 1.0f;
                f7 = 1.0f;
            }
            float f24 = ((f17 / min) / (((f7 - f6) * 0.0f) + f6)) * f7;
            canvas.translate(this.cropTransform.getCropAreaX() * f6, this.cropTransform.getCropAreaY() * f6);
            canvas.scale(f24, f24);
            canvas.translate(this.cropTransform.getCropPx() * f14 * min * f6, this.cropTransform.getCropPy() * f15 * min * f6);
            float rotation = this.cropTransform.getRotation() + orientation;
            if (rotation > 180.0f) {
                rotation -= 360.0f;
            }
            canvas.rotate(rotation);
        }
        boolean z = false;
        if (!this.imagesArrLocals.isEmpty()) {
            MediaController.CropState cropState3 = this.editState.cropState;
            z = cropState3 != null && cropState3.mirrored;
        }
        if (z) {
            canvas.scale(-1.0f, 1.0f);
        }
        if (f19 > 0.0f) {
            canvas.scale(1.0f - (f19 * 2.0f), 1.0f);
            canvas.skew(0.0f, 4.0f * f19 * (1.0f - f19) * 0.25f);
        }
    }

    public final void applyTransformToMatrix(Matrix matrix) {
        float f;
        float f2;
        float f3;
        float f4;
        float f5;
        if (this.imageMoveAnimation != null) {
            f2 = AndroidUtilities.lerp(this.mirror, this.animateToMirror, this.animationValue);
            f = AndroidUtilities.lerp(this.scale, this.animateToScale, this.animationValue);
            f3 = AndroidUtilities.lerp(this.rotate, this.animateToRotate, this.animationValue);
            f4 = AndroidUtilities.lerp(this.translationY, this.animateToY, this.animationValue);
            f5 = AndroidUtilities.lerp(this.translationX, this.animateToX, this.animationValue);
        } else {
            f = this.scale;
            f2 = this.mirror;
            f3 = this.rotate;
            f4 = this.translationY;
            f5 = this.translationX;
            if (this.animationStartTime != 0) {
                f5 = this.animateToX;
                f4 = this.animateToY;
                f = this.animateToScale;
            }
        }
        int containerViewWidth = getContainerViewWidth();
        int containerViewHeight = getContainerViewHeight();
        matrix.preTranslate(f5, f4 + (this.currentEditMode != 3 ? this.currentPanTranslationY : 0.0f));
        matrix.preScale(f, f);
        matrix.preRotate(f3);
        int bitmapWidth = this.centerImage.getBitmapWidth();
        int bitmapHeight = this.centerImage.getBitmapHeight();
        float f6 = containerViewWidth;
        float f7 = containerViewHeight;
        float min = Math.min(f6 / bitmapWidth, f7 / bitmapHeight);
        int orientation = this.cropTransform.getOrientation();
        if (orientation == 90 || orientation == 270) {
            bitmapHeight = bitmapWidth;
            bitmapWidth = bitmapHeight;
        }
        float cropPw = this.cropTransform.getCropPw();
        float cropPh = this.cropTransform.getCropPh();
        float f8 = bitmapWidth;
        float f9 = bitmapHeight;
        float f10 = f6 / ((int) ((cropPw + ((1.0f - cropPw) * 0.0f)) * f8));
        float f11 = (int) ((cropPh + ((1.0f - cropPh) * 0.0f)) * f9);
        if (f10 * f11 > f7) {
            f10 = f7 / f11;
        }
        if (this.sendPhotoType == 1 || this.cropTransform.hasViewTransform()) {
            TextureView textureView = this.videoTextureView;
            if (textureView != null) {
                MediaController.CropState cropState = this.editState.cropState;
                textureView.setScaleX((cropState == null || !cropState.mirrored) ? 1.0f : -1.0f);
                FirstFrameView firstFrameView = this.firstFrameView;
                if (firstFrameView != null) {
                    firstFrameView.setScaleX(this.videoTextureView.getScaleX());
                }
            }
            MediaController.CropState cropState2 = this.editState.cropState;
            float f12 = cropState2 != null ? cropState2.cropScale : 1.0f;
            float f13 = f12 * ((f10 / min) / (((f12 - 1.0f) * 0.0f) + 1.0f));
            matrix.preTranslate(this.cropTransform.getCropAreaX() * 1.0f, this.cropTransform.getCropAreaY() * 1.0f);
            matrix.preScale(f13, f13);
            matrix.preTranslate(this.cropTransform.getCropPx() * f8 * min * 1.0f, this.cropTransform.getCropPy() * f9 * min * 1.0f);
            float rotation = this.cropTransform.getRotation() + orientation;
            if (rotation > 180.0f) {
                rotation -= 360.0f;
            }
            matrix.preRotate(rotation);
        }
        boolean z = false;
        if (!this.imagesArrLocals.isEmpty()) {
            MediaController.CropState cropState3 = this.editState.cropState;
            z = cropState3 != null && cropState3.mirrored;
        }
        if (z) {
            matrix.preScale(-1.0f, 1.0f);
        }
        if (f2 > 0.0f) {
            matrix.preScale(1.0f - (2.0f * f2), 1.0f);
            matrix.preSkew(0.0f, 4.0f * f2 * (1.0f - f2) * 0.25f);
        }
    }
}