2014-06-07 01:35:21 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2014-06-07 01:35:21 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2014-06-07 01:35:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.Manifest;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.Animator;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.animation.AnimatorListenerAdapter;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2014-06-12 03:13:15 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.app.Activity;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.app.Dialog;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.content.Context;
|
2015-02-26 02:32:51 +01:00
|
|
|
import android.content.DialogInterface;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.content.Intent;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.content.SharedPreferences;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.content.pm.PackageManager;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.graphics.Bitmap;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.graphics.BitmapFactory;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.graphics.Canvas;
|
2014-10-28 18:07:44 +01:00
|
|
|
import android.graphics.Paint;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.graphics.PixelFormat;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2014-08-22 16:24:33 +02:00
|
|
|
import android.graphics.Rect;
|
2014-10-28 18:07:44 +01:00
|
|
|
import android.graphics.RectF;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.graphics.SurfaceTexture;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.graphics.drawable.ColorDrawable;
|
2014-10-24 15:43:45 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.media.MediaCodecInfo;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.net.Uri;
|
2015-02-26 02:32:51 +01:00
|
|
|
import android.os.Build;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.os.Bundle;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.support.v4.content.FileProvider;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.text.Layout;
|
2016-03-06 02:49:31 +01:00
|
|
|
import android.text.SpannableStringBuilder;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.text.StaticLayout;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.text.TextPaint;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.text.TextUtils;
|
2015-02-26 02:32:51 +01:00
|
|
|
import android.util.TypedValue;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.view.ActionMode;
|
|
|
|
import android.view.ContextThemeWrapper;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.view.GestureDetector;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.view.Gravity;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.KeyEvent;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.view.MotionEvent;
|
2014-06-12 03:13:15 +02:00
|
|
|
import android.view.Surface;
|
2016-06-24 12:27:15 +02:00
|
|
|
import android.view.TextureView;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.view.VelocityTracker;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.view.WindowInsets;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.view.WindowManager;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.view.animation.OvershootInterpolator;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.widget.FrameLayout;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.widget.ImageView;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.widget.LinearLayout;
|
2014-06-21 23:46:11 +02:00
|
|
|
import android.widget.Scroller;
|
2014-06-11 01:05:54 +02:00
|
|
|
import android.widget.TextView;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
import com.coremedia.iso.IsoFile;
|
|
|
|
import com.coremedia.iso.boxes.Box;
|
|
|
|
import com.coremedia.iso.boxes.MediaBox;
|
|
|
|
import com.coremedia.iso.boxes.MediaHeaderBox;
|
|
|
|
import com.coremedia.iso.boxes.SampleSizeBox;
|
|
|
|
import com.coremedia.iso.boxes.TrackBox;
|
|
|
|
import com.coremedia.iso.boxes.TrackHeaderBox;
|
|
|
|
import com.googlecode.mp4parser.util.Matrix;
|
|
|
|
import com.googlecode.mp4parser.util.Path;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.BuildConfig;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2017-07-23 14:56:38 +02:00
|
|
|
import org.telegram.messenger.ContactsController;
|
2016-03-06 02:49:31 +01:00
|
|
|
import org.telegram.messenger.Emoji;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.EmojiSuggestion;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.ImageLoader;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.SendMessagesHelper;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.UserObject;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.VideoEditedInfo;
|
|
|
|
import org.telegram.messenger.exoplayer2.C;
|
|
|
|
import org.telegram.messenger.exoplayer2.ExoPlayer;
|
|
|
|
import org.telegram.messenger.exoplayer2.ui.AspectRatioFrameLayout;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.query.SharedMediaQuery;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-06-11 01:05:54 +02:00
|
|
|
import org.telegram.messenger.FileLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2014-06-07 01:35:21 +02:00
|
|
|
import org.telegram.messenger.R;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-06-11 01:05:54 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessageObject;
|
2014-10-28 18:07:44 +01:00
|
|
|
import org.telegram.messenger.Utilities;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2017-07-23 14:56:38 +02:00
|
|
|
import org.telegram.ui.ActionBar.BottomSheet;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Adapters.MentionsAdapter;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Cells.CheckBoxCell;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Cells.PhotoPickerPhotoCell;
|
2016-06-24 12:27:15 +02:00
|
|
|
import org.telegram.ui.Components.AnimatedFileDrawable;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.ChatAttachAlert;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Components.CheckBox;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.ClippingImageView;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Components.CubicBezierInterpolator;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-07-23 14:56:38 +02:00
|
|
|
import org.telegram.ui.Components.NumberPicker;
|
2015-02-26 02:32:51 +01:00
|
|
|
import org.telegram.ui.Components.PhotoCropView;
|
|
|
|
import org.telegram.ui.Components.PhotoFilterView;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Components.PhotoPaintView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.PhotoViewerCaptionEnterView;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Components.PickerBottomLayoutViewer;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RadialProgressView;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2016-06-24 12:27:15 +02:00
|
|
|
import org.telegram.ui.Components.SeekBar;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Components.SizeNotifierFrameLayoutPhoto;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Components.StickersAlert;
|
2016-06-24 12:27:15 +02:00
|
|
|
import org.telegram.ui.Components.VideoPlayer;
|
2017-07-23 14:56:38 +02:00
|
|
|
import org.telegram.ui.Components.VideoTimelinePlayView;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
2015-02-26 02:32:51 +01:00
|
|
|
import java.util.Date;
|
2014-06-11 01:05:54 +02:00
|
|
|
import java.util.HashMap;
|
2017-03-31 01:58:05 +02:00
|
|
|
import java.util.List;
|
2014-06-12 03:13:15 +02:00
|
|
|
import java.util.Locale;
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-06-11 01:05:54 +02:00
|
|
|
public class PhotoViewer implements NotificationCenter.NotificationCenterDelegate, GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private int classGuid;
|
|
|
|
private PhotoViewerProvider placeProvider;
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean isVisible;
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean muteVideo;
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private int slideshowMessageId;
|
|
|
|
private String nameOverride;
|
|
|
|
private int dateOverride;
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private Activity parentActivity;
|
2016-04-22 15:49:00 +02:00
|
|
|
private Context actvityContext;
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2014-06-07 01:35:21 +02:00
|
|
|
private ActionBar actionBar;
|
|
|
|
private boolean isActionBarVisible = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean isPhotosListViewVisible;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private static Drawable[] progressDrawables;
|
2014-10-24 15:43:45 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private WindowManager.LayoutParams windowLayoutParams;
|
2014-06-12 17:53:20 +02:00
|
|
|
private FrameLayoutDrawer containerView;
|
2016-10-11 13:57:01 +02:00
|
|
|
private FrameLayout windowView;
|
2014-06-11 01:05:54 +02:00
|
|
|
private ClippingImageView animatingImageView;
|
|
|
|
private FrameLayout bottomLayout;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private TextView dateTextView;
|
|
|
|
private ActionBarMenuItem menuItem;
|
2017-12-08 18:35:59 +01:00
|
|
|
private ActionBarMenuItem sendItem;
|
2016-10-11 13:57:01 +02:00
|
|
|
private ActionBarMenuItem masksItem;
|
2015-02-26 02:32:51 +01:00
|
|
|
private ImageView shareButton;
|
2015-05-03 13:48:36 +02:00
|
|
|
private BackgroundDrawable backgroundDrawable = new BackgroundDrawable(0xff000000);
|
2016-10-11 13:57:01 +02:00
|
|
|
private Paint blackPaint = new Paint();
|
2015-01-02 23:15:07 +01:00
|
|
|
private CheckBox checkImageView;
|
2017-07-23 14:56:38 +02:00
|
|
|
private CounterView photosCounterView;
|
|
|
|
private FrameLayout pickerView;
|
|
|
|
private ImageView pickerViewSendButton;
|
|
|
|
private LinearLayout itemsLayout;
|
2016-10-11 13:57:01 +02:00
|
|
|
private PickerBottomLayoutViewer editorDoneLayout;
|
2017-03-31 01:58:05 +02:00
|
|
|
private TextView resetButton;
|
|
|
|
private PhotoProgressView photoProgressViews[] = new PhotoProgressView[3];
|
2016-10-11 13:57:01 +02:00
|
|
|
private ImageView paintItem;
|
|
|
|
private ImageView cropItem;
|
|
|
|
private ImageView tuneItem;
|
2017-07-23 14:56:38 +02:00
|
|
|
private ImageView timeItem;
|
2017-03-31 01:58:05 +02:00
|
|
|
private ImageView muteItem;
|
|
|
|
private ImageView compressItem;
|
2017-12-08 18:35:59 +01:00
|
|
|
private GroupedPhotosListView groupedPhotosListView;
|
|
|
|
private RecyclerListView selectedPhotosListView;
|
|
|
|
private ListAdapter selectedPhotosAdapter;
|
2017-07-08 18:32:04 +02:00
|
|
|
private AnimatorSet compressItemAnimation;
|
2017-07-23 14:56:38 +02:00
|
|
|
private boolean isCurrentVideo;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet currentActionBarAnimation;
|
2017-12-08 18:35:59 +01:00
|
|
|
private AnimatorSet currentListViewAnimation;
|
2015-02-26 02:32:51 +01:00
|
|
|
private PhotoCropView photoCropView;
|
|
|
|
private PhotoFilterView photoFilterView;
|
2016-10-11 13:57:01 +02:00
|
|
|
private PhotoPaintView photoPaintView;
|
2015-05-03 13:48:36 +02:00
|
|
|
private AlertDialog visibleDialog;
|
|
|
|
private TextView captionTextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
private ChatAttachAlert parentAlert;
|
2015-05-03 13:48:36 +02:00
|
|
|
private PhotoViewerCaptionEnterView captionEditText;
|
2014-06-11 01:05:54 +02:00
|
|
|
private boolean canShowBottom = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int sendPhotoType;
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean needCaptionLayout;
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatedFileDrawable currentAnimation;
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean allowShare;
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private TextView hintTextView;
|
|
|
|
private Runnable hintHideRunnable;
|
|
|
|
private AnimatorSet hintAnimation;
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private Object lastInsets;
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean doneButtonPressed;
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private AspectRatioFrameLayout aspectRatioFrameLayout;
|
|
|
|
private TextureView videoTextureView;
|
|
|
|
private VideoPlayer videoPlayer;
|
|
|
|
private FrameLayout videoPlayerControlFrameLayout;
|
|
|
|
private ImageView videoPlayButton;
|
|
|
|
private TextView videoPlayerTime;
|
|
|
|
private SeekBar videoPlayerSeekbar;
|
|
|
|
private boolean textureUploaded;
|
|
|
|
private boolean videoCrossfadeStarted;
|
|
|
|
private float videoCrossfadeAlpha;
|
|
|
|
private long videoCrossfadeAlphaLastTime;
|
|
|
|
private boolean isPlaying;
|
|
|
|
private Runnable updateProgressRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (videoPlayer != null) {
|
|
|
|
if (isCurrentVideo) {
|
|
|
|
if (!videoTimelineView.isDragging()) {
|
|
|
|
float progress = videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration();
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
if (progress >= videoTimelineView.getRightProgress()) {
|
|
|
|
videoPlayer.pause();
|
|
|
|
videoTimelineView.setProgress(0);
|
|
|
|
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration()));
|
|
|
|
containerView.invalidate();
|
|
|
|
} else {
|
|
|
|
progress -= videoTimelineView.getLeftProgress();
|
|
|
|
if (progress < 0) {
|
|
|
|
progress = 0;
|
|
|
|
}
|
|
|
|
progress /= (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress());
|
|
|
|
if (progress > 1) {
|
|
|
|
progress = 1;
|
|
|
|
}
|
|
|
|
videoTimelineView.setProgress(progress);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
} else {
|
|
|
|
videoTimelineView.setProgress(progress);
|
|
|
|
}
|
|
|
|
updateVideoPlayerTime();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!videoPlayerSeekbar.isDragging()) {
|
|
|
|
float progress = videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration();
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
if (progress >= videoTimelineView.getRightProgress()) {
|
|
|
|
videoPlayer.pause();
|
|
|
|
videoPlayerSeekbar.setProgress(0);
|
|
|
|
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration()));
|
|
|
|
containerView.invalidate();
|
|
|
|
} else {
|
|
|
|
progress -= videoTimelineView.getLeftProgress();
|
|
|
|
if (progress < 0) {
|
|
|
|
progress = 0;
|
|
|
|
}
|
|
|
|
progress /= (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress());
|
|
|
|
if (progress > 1) {
|
|
|
|
progress = 1;
|
|
|
|
}
|
|
|
|
videoPlayerSeekbar.setProgress(progress);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
videoPlayerSeekbar.setProgress(progress);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerControlFrameLayout.invalidate();
|
|
|
|
updateVideoPlayerTime();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isPlaying) {
|
2017-03-31 01:58:05 +02:00
|
|
|
AndroidUtilities.runOnUIThread(updateProgressRunnable);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
private float animationValues[][] = new float[2][8];
|
|
|
|
|
|
|
|
private ChatActivity parentChatActivity;
|
|
|
|
private MentionsAdapter mentionsAdapter;
|
2016-01-11 18:19:48 +01:00
|
|
|
private RecyclerListView mentionListView;
|
|
|
|
private LinearLayoutManager mentionLayoutManager;
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet mentionListAnimation;
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean allowMentions;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private int animationInProgress;
|
|
|
|
private long transitionAnimationStartTime;
|
|
|
|
private Runnable animationEndRunnable;
|
2014-06-13 20:26:05 +02:00
|
|
|
private PlaceProviderObject showAfterAnimation;
|
|
|
|
private PlaceProviderObject hideAfterAnimation;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean disableShowCheck;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private String lastTitle;
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private int currentEditMode;
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private ImageReceiver leftImage = new ImageReceiver();
|
|
|
|
private ImageReceiver centerImage = new ImageReceiver();
|
|
|
|
private ImageReceiver rightImage = new ImageReceiver();
|
|
|
|
private int currentIndex;
|
|
|
|
private MessageObject currentMessageObject;
|
2017-03-31 01:58:05 +02:00
|
|
|
private File currentPlayingVideoFile;
|
2016-10-11 13:57:01 +02:00
|
|
|
private TLRPC.BotInlineResult currentBotInlineResult;
|
2014-06-11 01:05:54 +02:00
|
|
|
private TLRPC.FileLocation currentFileLocation;
|
2014-10-28 18:07:44 +01:00
|
|
|
private String currentFileNames[] = new String[3];
|
2014-06-11 01:05:54 +02:00
|
|
|
private PlaceProviderObject currentPlaceObject;
|
2014-06-12 03:13:15 +02:00
|
|
|
private String currentPathObject;
|
2017-03-31 01:58:05 +02:00
|
|
|
private Bitmap currentThumb;
|
|
|
|
private boolean ignoreDidSetImage;
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean fromCamera;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private int avatarsDialogId;
|
2017-07-08 18:32:04 +02:00
|
|
|
private boolean isEvent;
|
2014-06-11 01:05:54 +02:00
|
|
|
private long currentDialogId;
|
2015-11-26 22:04:02 +01:00
|
|
|
private long mergeDialogId;
|
2014-06-11 01:05:54 +02:00
|
|
|
private int totalImagesCount;
|
2015-11-26 22:04:02 +01:00
|
|
|
private int totalImagesCountMerge;
|
2014-06-11 01:05:54 +02:00
|
|
|
private boolean isFirstLoading;
|
|
|
|
private boolean needSearchImageInArr;
|
|
|
|
private boolean loadingMoreImages;
|
2015-11-26 22:04:02 +01:00
|
|
|
private boolean endReached[] = new boolean[] {false, true};
|
2014-06-11 01:05:54 +02:00
|
|
|
private boolean opennedFromMedia;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean attachedToWindow;
|
|
|
|
|
|
|
|
private boolean wasLayout;
|
|
|
|
private boolean dontResetZoomOnFirstLayout;
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean draggingDown;
|
2014-06-11 01:05:54 +02:00
|
|
|
private float dragY;
|
2016-03-06 02:49:31 +01:00
|
|
|
private float translationX;
|
|
|
|
private float translationY;
|
2014-06-11 01:05:54 +02:00
|
|
|
private float scale = 1;
|
|
|
|
private float animateToX;
|
|
|
|
private float animateToY;
|
|
|
|
private float animateToScale;
|
2015-02-26 02:32:51 +01:00
|
|
|
private float animationValue;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean applying;
|
2014-06-11 01:05:54 +02:00
|
|
|
private long animationStartTime;
|
2016-06-24 12:27:15 +02:00
|
|
|
private AnimatorSet imageMoveAnimation;
|
|
|
|
private AnimatorSet changeModeAnimation;
|
2014-06-11 01:05:54 +02:00
|
|
|
private GestureDetector gestureDetector;
|
2014-11-19 02:23:46 +01:00
|
|
|
private DecelerateInterpolator interpolator = new DecelerateInterpolator(1.5f);
|
2016-03-06 02:49:31 +01:00
|
|
|
private float pinchStartDistance;
|
2014-06-11 01:05:54 +02:00
|
|
|
private float pinchStartScale = 1;
|
|
|
|
private float pinchCenterX;
|
|
|
|
private float pinchCenterY;
|
|
|
|
private float pinchStartX;
|
|
|
|
private float pinchStartY;
|
|
|
|
private float moveStartX;
|
|
|
|
private float moveStartY;
|
|
|
|
private float minX;
|
|
|
|
private float maxX;
|
|
|
|
private float minY;
|
|
|
|
private float maxY;
|
|
|
|
private boolean canZoom = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean changingPage;
|
|
|
|
private boolean zooming;
|
|
|
|
private boolean moving;
|
|
|
|
private boolean doubleTap;
|
|
|
|
private boolean invalidCoords;
|
2014-06-11 01:05:54 +02:00
|
|
|
private boolean canDragDown = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean zoomAnimation;
|
|
|
|
private boolean discardTap;
|
|
|
|
private int switchImageAfterAnimation;
|
|
|
|
private VelocityTracker velocityTracker;
|
|
|
|
private Scroller scroller;
|
|
|
|
|
|
|
|
private boolean bottomTouchEnabled = true;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<MessageObject> imagesArrTemp = new ArrayList<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
private HashMap<Integer, MessageObject>[] imagesByIdsTemp = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<MessageObject> imagesArr = new ArrayList<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
private HashMap<Integer, MessageObject>[] imagesByIds = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<TLRPC.FileLocation> imagesArrLocations = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.Photo> avatarsArr = new ArrayList<>();
|
|
|
|
private ArrayList<Integer> imagesArrLocationsSizes = new ArrayList<>();
|
|
|
|
private ArrayList<Object> imagesArrLocals = new ArrayList<>();
|
2014-08-22 16:24:33 +02:00
|
|
|
private TLRPC.FileLocation currentUserAvatarLocation = null;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private final static int gallery_menu_save = 1;
|
|
|
|
private final static int gallery_menu_showall = 2;
|
|
|
|
private final static int gallery_menu_send = 3;
|
2017-12-08 18:35:59 +01:00
|
|
|
private final static int gallery_menu_showinchat = 4;
|
2015-02-26 02:32:51 +01:00
|
|
|
private final static int gallery_menu_delete = 6;
|
2016-06-24 12:27:15 +02:00
|
|
|
private final static int gallery_menu_share = 10;
|
|
|
|
private final static int gallery_menu_openin = 11;
|
2016-10-11 13:57:01 +02:00
|
|
|
private final static int gallery_menu_masks = 13;
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private static DecelerateInterpolator decelerateInterpolator;
|
|
|
|
private static Paint progressPaint;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private class GroupedPhotosListView extends View implements GestureDetector.OnGestureListener {
|
|
|
|
|
|
|
|
private Paint backgroundPaint = new Paint();
|
|
|
|
private ArrayList<ImageReceiver> unusedReceivers = new ArrayList<>();
|
|
|
|
private ArrayList<ImageReceiver> imagesToDraw = new ArrayList<>();
|
|
|
|
private ArrayList<TLObject> currentPhotos = new ArrayList<>();
|
|
|
|
private ArrayList<Object> currentObjects = new ArrayList<>();
|
|
|
|
private int currentImage;
|
|
|
|
private long currentGroupId;
|
|
|
|
private int itemWidth;
|
|
|
|
private int itemHeight;
|
|
|
|
private int itemY;
|
|
|
|
private int itemSpacing;
|
|
|
|
private int drawDx;
|
|
|
|
private float moveLineProgress;
|
|
|
|
private float currentItemProgress = 1.0f;
|
|
|
|
private float nextItemProgress = 0.0f;
|
|
|
|
private int nextImage;
|
|
|
|
private long lastUpdateTime;
|
|
|
|
private boolean moving;
|
|
|
|
private boolean animateAllLine;
|
|
|
|
private int animateToDX;
|
|
|
|
private int animateToDXStart;
|
|
|
|
private int animateToItem = -1;
|
|
|
|
private Scroller scroll;
|
|
|
|
private GestureDetector gestureDetector;
|
|
|
|
private boolean scrolling;
|
|
|
|
private boolean stopedScrolling;
|
|
|
|
private boolean ignoreChanges;
|
|
|
|
private int nextPhotoScrolling = -1;
|
|
|
|
|
|
|
|
public GroupedPhotosListView(Context context) {
|
|
|
|
super(context);
|
|
|
|
gestureDetector = new GestureDetector(context, this);
|
|
|
|
scroll = new Scroller(context);
|
|
|
|
itemWidth = AndroidUtilities.dp(42);
|
|
|
|
itemHeight = AndroidUtilities.dp(56);
|
|
|
|
itemSpacing = AndroidUtilities.dp(1);
|
|
|
|
itemY = AndroidUtilities.dp(3);
|
|
|
|
backgroundPaint.setColor(0x7f000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
currentPhotos.clear();
|
|
|
|
currentObjects.clear();
|
|
|
|
imagesToDraw.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void fillList() {
|
|
|
|
if (ignoreChanges) {
|
|
|
|
ignoreChanges = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean changed = false;
|
|
|
|
int newCount = 0;
|
|
|
|
Object currentObject = null;
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
|
|
|
TLRPC.FileLocation location = imagesArrLocations.get(currentIndex);
|
|
|
|
newCount = imagesArrLocations.size();
|
|
|
|
currentObject = location;
|
|
|
|
} else if (!imagesArr.isEmpty()) {
|
|
|
|
MessageObject messageObject = imagesArr.get(currentIndex);
|
|
|
|
currentObject = messageObject;
|
|
|
|
if (messageObject.messageOwner.grouped_id != currentGroupId) {
|
|
|
|
changed = true;
|
|
|
|
currentGroupId = messageObject.messageOwner.grouped_id;
|
|
|
|
} else {
|
|
|
|
int max = Math.min(currentIndex + 10, imagesArr.size());
|
|
|
|
for (int a = currentIndex; a < max; a++) {
|
|
|
|
MessageObject object = imagesArr.get(a);
|
|
|
|
if (slideshowMessageId != 0 || object.messageOwner.grouped_id == currentGroupId) {
|
|
|
|
newCount++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int min = Math.max(currentIndex - 10, 0);
|
|
|
|
for (int a = currentIndex - 1; a >= min; a--) {
|
|
|
|
MessageObject object = imagesArr.get(a);
|
|
|
|
if (slideshowMessageId != 0 || object.messageOwner.grouped_id == currentGroupId) {
|
|
|
|
newCount++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!changed) {
|
|
|
|
if (newCount != currentPhotos.size() || currentObjects.indexOf(currentObject) == -1) {
|
|
|
|
changed = true;
|
|
|
|
} else {
|
|
|
|
int newImageIndex = currentObjects.indexOf(currentObject);
|
|
|
|
if (currentImage != newImageIndex && newImageIndex != -1) {
|
|
|
|
if (animateAllLine) {
|
|
|
|
nextImage = animateToItem = newImageIndex;
|
|
|
|
animateToDX = (currentImage - newImageIndex) * (itemWidth + itemSpacing);
|
|
|
|
moving = true;
|
|
|
|
animateAllLine = false;
|
|
|
|
lastUpdateTime = System.currentTimeMillis();
|
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
fillImages(true, (currentImage - newImageIndex) * (itemWidth + itemSpacing));
|
|
|
|
currentImage = newImageIndex;
|
|
|
|
moving = false;
|
|
|
|
}
|
|
|
|
drawDx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
animateAllLine = false;
|
|
|
|
currentPhotos.clear();
|
|
|
|
currentObjects.clear();
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
|
|
|
currentObjects.addAll(imagesArrLocations);
|
|
|
|
currentPhotos.addAll(imagesArrLocations);
|
|
|
|
currentImage = currentIndex;
|
|
|
|
animateToItem = -1;
|
|
|
|
} else if (!imagesArr.isEmpty()) {
|
|
|
|
if (currentGroupId != 0 || slideshowMessageId != 0) {
|
|
|
|
int max = Math.min(currentIndex + 10, imagesArr.size());
|
|
|
|
for (int a = currentIndex; a < max; a++) {
|
|
|
|
MessageObject object = imagesArr.get(a);
|
|
|
|
if (slideshowMessageId != 0 || object.messageOwner.grouped_id == currentGroupId) {
|
|
|
|
currentObjects.add(object);
|
|
|
|
currentPhotos.add(FileLoader.getClosestPhotoSizeWithSize(object.photoThumbs, 56, true));
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentImage = 0;
|
|
|
|
animateToItem = -1;
|
|
|
|
int min = Math.max(currentIndex - 10, 0);
|
|
|
|
for (int a = currentIndex - 1; a >= min; a--) {
|
|
|
|
MessageObject object = imagesArr.get(a);
|
|
|
|
if (slideshowMessageId != 0 || object.messageOwner.grouped_id == currentGroupId) {
|
|
|
|
currentObjects.add(0, object);
|
|
|
|
currentPhotos.add(0, FileLoader.getClosestPhotoSizeWithSize(object.photoThumbs, 56, true));
|
|
|
|
currentImage++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentPhotos.size() == 1) {
|
|
|
|
currentPhotos.clear();
|
|
|
|
currentObjects.clear();
|
|
|
|
}
|
|
|
|
fillImages(false, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMoveProgress(float progress) {
|
|
|
|
if (scrolling || animateToItem >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (progress > 0) {
|
|
|
|
nextImage = currentImage - 1;
|
|
|
|
} else {
|
|
|
|
nextImage = currentImage + 1;
|
|
|
|
}
|
|
|
|
if (nextImage >= 0 && nextImage < currentPhotos.size()) {
|
|
|
|
currentItemProgress = 1.0f - Math.abs(progress);
|
|
|
|
} else {
|
|
|
|
currentItemProgress = 1.0f;
|
|
|
|
}
|
|
|
|
nextItemProgress = 1.0f - currentItemProgress;
|
|
|
|
moving = progress != 0;
|
|
|
|
invalidate();
|
|
|
|
if (currentPhotos.isEmpty() || progress < 0 && currentImage == currentPhotos.size() - 1 || progress > 0 && currentImage == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
drawDx = (int) (progress * (itemWidth + itemSpacing));
|
|
|
|
fillImages(true, drawDx);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ImageReceiver getFreeReceiver() {
|
|
|
|
ImageReceiver receiver;
|
|
|
|
if (unusedReceivers.isEmpty()) {
|
|
|
|
receiver = new ImageReceiver(this);
|
|
|
|
} else {
|
|
|
|
receiver = unusedReceivers.get(0);
|
|
|
|
unusedReceivers.remove(0);
|
|
|
|
}
|
|
|
|
imagesToDraw.add(receiver);
|
|
|
|
return receiver;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fillImages(boolean move, int dx) {
|
|
|
|
if (!move && !imagesToDraw.isEmpty()) {
|
|
|
|
unusedReceivers.addAll(imagesToDraw);
|
|
|
|
imagesToDraw.clear();
|
|
|
|
moving = false;
|
|
|
|
moveLineProgress = 1.0f;
|
|
|
|
currentItemProgress = 1.0f;
|
|
|
|
nextItemProgress = 0.0f;
|
|
|
|
}
|
|
|
|
invalidate();
|
|
|
|
if (getMeasuredWidth() == 0 || currentPhotos.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
int startX = getMeasuredWidth() / 2 - itemWidth / 2;
|
|
|
|
|
|
|
|
int addRightIndex;
|
|
|
|
int addLeftIndex;
|
|
|
|
if (move) {
|
|
|
|
addRightIndex = Integer.MIN_VALUE;
|
|
|
|
addLeftIndex = Integer.MAX_VALUE;
|
|
|
|
int count = imagesToDraw.size();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ImageReceiver receiver = imagesToDraw.get(a);
|
|
|
|
int num = receiver.getParam();
|
|
|
|
int x = startX + (num - currentImage) * (itemWidth + itemSpacing) + dx;
|
|
|
|
if (x > width || x + itemWidth < 0) {
|
|
|
|
unusedReceivers.add(receiver);
|
|
|
|
imagesToDraw.remove(a);
|
|
|
|
count--;
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
addLeftIndex = Math.min(addLeftIndex, num - 1);
|
|
|
|
addRightIndex = Math.max(addRightIndex, num + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addRightIndex = currentImage;
|
|
|
|
addLeftIndex = currentImage - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addRightIndex != Integer.MIN_VALUE) {
|
|
|
|
int count = currentPhotos.size();
|
|
|
|
for (int a = addRightIndex; a < count; a++) {
|
|
|
|
int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx;
|
|
|
|
if (x < width) {
|
|
|
|
TLObject location = currentPhotos.get(a);
|
|
|
|
if (location instanceof TLRPC.PhotoSize) {
|
|
|
|
location = ((TLRPC.PhotoSize) location).location;
|
|
|
|
}
|
|
|
|
ImageReceiver receiver = getFreeReceiver();
|
|
|
|
receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
|
|
|
|
receiver.setImage(null, null, null, null, (TLRPC.FileLocation) location, "80_80", 0, null, 1);
|
|
|
|
receiver.setParam(a);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (addLeftIndex != Integer.MAX_VALUE) {
|
|
|
|
for (int a = addLeftIndex; a >= 0; a--) {
|
|
|
|
int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx + itemWidth;
|
|
|
|
if (x > 0) {
|
|
|
|
TLObject location = currentPhotos.get(a);
|
|
|
|
if (location instanceof TLRPC.PhotoSize) {
|
|
|
|
location = ((TLRPC.PhotoSize) location).location;
|
|
|
|
}
|
|
|
|
ImageReceiver receiver = getFreeReceiver();
|
|
|
|
receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
|
|
|
|
receiver.setImage(null, null, null, null, (TLRPC.FileLocation) location, "80_80", 0, null, 1);
|
|
|
|
receiver.setParam(a);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDown(MotionEvent e) {
|
|
|
|
if (!scroll.isFinished()) {
|
|
|
|
scroll.abortAnimation();
|
|
|
|
}
|
|
|
|
animateToItem = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapUp(MotionEvent e) {
|
|
|
|
stopScrolling();
|
|
|
|
int count = imagesToDraw.size();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ImageReceiver receiver = imagesToDraw.get(a);
|
|
|
|
if (receiver.isInsideImage(e.getX(), e.getY())) {
|
|
|
|
int num = receiver.getParam();
|
|
|
|
if (num < 0 || num >= currentObjects.size()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
MessageObject messageObject = (MessageObject) currentObjects.get(num);
|
|
|
|
int idx = imagesArr.indexOf(messageObject);
|
|
|
|
if (currentIndex == idx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
moveLineProgress = 1.0f;
|
|
|
|
animateAllLine = true;
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(idx, false);
|
|
|
|
} else if (!imagesArrLocations.isEmpty()) {
|
|
|
|
TLRPC.FileLocation location = (TLRPC.FileLocation) currentObjects.get(num);
|
|
|
|
int idx = imagesArrLocations.indexOf(location);
|
|
|
|
if (currentIndex == idx) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
moveLineProgress = 1.0f;
|
|
|
|
animateAllLine = true;
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(idx, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAfterScroll() {
|
|
|
|
int indexChange = 0;
|
|
|
|
int dx = drawDx;
|
|
|
|
if (Math.abs(dx) > itemWidth / 2 + itemSpacing) {
|
|
|
|
if (dx > 0) {
|
|
|
|
dx -= itemWidth / 2 + itemSpacing;
|
|
|
|
indexChange++;
|
|
|
|
} else {
|
|
|
|
dx += itemWidth / 2 + itemSpacing;
|
|
|
|
indexChange--;
|
|
|
|
}
|
|
|
|
indexChange += dx / (itemWidth + itemSpacing * 2);
|
|
|
|
}
|
|
|
|
nextPhotoScrolling = currentImage - indexChange;
|
|
|
|
if (currentIndex != nextPhotoScrolling && nextPhotoScrolling >= 0 && nextPhotoScrolling < currentPhotos.size()) {
|
|
|
|
Object photo = currentObjects.get(nextPhotoScrolling);
|
|
|
|
int nextPhoto = -1;
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
MessageObject messageObject = (MessageObject) photo;
|
|
|
|
nextPhoto = imagesArr.indexOf(messageObject);
|
|
|
|
} else if (!imagesArrLocations.isEmpty()) {
|
|
|
|
TLRPC.FileLocation location = (TLRPC.FileLocation) photo;
|
|
|
|
nextPhoto = imagesArrLocations.indexOf(location);
|
|
|
|
}
|
|
|
|
if (nextPhoto >= 0) {
|
|
|
|
ignoreChanges = true;
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(nextPhoto, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!scrolling) {
|
|
|
|
scrolling = true;
|
|
|
|
stopedScrolling = false;
|
|
|
|
}
|
|
|
|
fillImages(true, drawDx);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
|
|
|
drawDx -= distanceX;
|
|
|
|
int min = getMinScrollX();
|
|
|
|
int max = getMaxScrollX();
|
|
|
|
if (drawDx < min) {
|
|
|
|
drawDx = min;
|
|
|
|
} else if (drawDx > max) {
|
|
|
|
drawDx = max;
|
|
|
|
}
|
|
|
|
updateAfterScroll();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLongPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
|
|
|
scroll.abortAnimation();
|
|
|
|
if (currentPhotos.size() >= 10) {
|
|
|
|
scroll.fling(drawDx, 0, Math.round(velocityX), 0, getMinScrollX(), getMaxScrollX(), 0, 0);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void stopScrolling() {
|
|
|
|
scrolling = false;
|
|
|
|
if (!scroll.isFinished()) {
|
|
|
|
scroll.abortAnimation();
|
|
|
|
}
|
|
|
|
if (nextPhotoScrolling >= 0 && nextPhotoScrolling < currentObjects.size()) {
|
|
|
|
stopedScrolling = true;
|
|
|
|
|
|
|
|
nextImage = animateToItem = nextPhotoScrolling;
|
|
|
|
animateToDX = (currentImage - nextPhotoScrolling) * (itemWidth + itemSpacing);
|
|
|
|
animateToDXStart = drawDx;
|
|
|
|
moveLineProgress = 1.0f;
|
|
|
|
nextPhotoScrolling = -1;
|
|
|
|
}
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
boolean result = gestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
|
|
|
|
if (scrolling && event.getAction() == MotionEvent.ACTION_UP && scroll.isFinished()) {
|
|
|
|
stopScrolling();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getMinScrollX() {
|
|
|
|
return -(currentPhotos.size() - currentImage - 1) * (itemWidth + itemSpacing * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getMaxScrollX() {
|
|
|
|
return currentImage * (itemWidth + itemSpacing * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
fillImages(false, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (imagesToDraw.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
|
|
|
|
int count = imagesToDraw.size();
|
|
|
|
|
|
|
|
int moveX = drawDx;
|
|
|
|
|
|
|
|
int maxItemWidth = (int) (itemWidth * 2.0f);
|
|
|
|
int padding = AndroidUtilities.dp(8);
|
|
|
|
|
|
|
|
TLObject object = currentPhotos.get(currentImage);
|
|
|
|
int trueWidth;
|
|
|
|
int currentPaddings;
|
|
|
|
if (object instanceof TLRPC.PhotoSize) {
|
|
|
|
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) object;
|
|
|
|
trueWidth = Math.max(itemWidth, (int) (photoSize.w * (itemHeight / (float) photoSize.h)));
|
|
|
|
} else {
|
|
|
|
trueWidth = itemHeight;
|
|
|
|
}
|
|
|
|
trueWidth = Math.min(maxItemWidth, trueWidth);
|
|
|
|
currentPaddings = (int) (padding * 2 * currentItemProgress);
|
|
|
|
trueWidth = itemWidth + (int) ((trueWidth - itemWidth) * currentItemProgress) + currentPaddings;
|
|
|
|
|
|
|
|
int nextTrueWidth;
|
|
|
|
int nextPaddings;
|
|
|
|
if (nextImage >= 0 && nextImage < currentPhotos.size()) {
|
|
|
|
object = currentPhotos.get(nextImage);
|
|
|
|
if (object instanceof TLRPC.PhotoSize) {
|
|
|
|
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) object;
|
|
|
|
nextTrueWidth = Math.max(itemWidth, (int) (photoSize.w * (itemHeight / (float) photoSize.h)));
|
|
|
|
} else {
|
|
|
|
nextTrueWidth = itemHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nextTrueWidth = itemWidth;
|
|
|
|
}
|
|
|
|
nextTrueWidth = Math.min(maxItemWidth, nextTrueWidth);
|
|
|
|
nextPaddings = (int) (padding * 2 * nextItemProgress);
|
|
|
|
moveX += (nextTrueWidth + nextPaddings - itemWidth) / 2 * nextItemProgress * (nextImage > currentImage ? -1 : 1);
|
|
|
|
nextTrueWidth = itemWidth + (int) ((nextTrueWidth - itemWidth) * nextItemProgress) + nextPaddings;
|
|
|
|
|
|
|
|
int startX = (getMeasuredWidth() - trueWidth) / 2;
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
ImageReceiver receiver = imagesToDraw.get(a);
|
|
|
|
int num = receiver.getParam();
|
|
|
|
if (num == currentImage) {
|
|
|
|
receiver.setImageX(startX + moveX + currentPaddings / 2);
|
|
|
|
receiver.setImageWidth(trueWidth - currentPaddings);
|
|
|
|
} else {
|
|
|
|
if (nextImage < currentImage) {
|
|
|
|
if (num < currentImage) {
|
|
|
|
if (num <= nextImage) {
|
|
|
|
receiver.setImageX(startX + (receiver.getParam() - currentImage + 1) * (itemWidth + itemSpacing) - (nextTrueWidth + itemSpacing) + moveX);
|
|
|
|
} else {
|
|
|
|
receiver.setImageX(startX + (receiver.getParam() - currentImage) * (itemWidth + itemSpacing) + moveX);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
receiver.setImageX(startX + trueWidth + itemSpacing + (receiver.getParam() - currentImage - 1) * (itemWidth + itemSpacing) + moveX);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (num < currentImage) {
|
|
|
|
receiver.setImageX(startX + (receiver.getParam() - currentImage) * (itemWidth + itemSpacing) + moveX);
|
|
|
|
} else {
|
|
|
|
if (num <= nextImage) {
|
|
|
|
receiver.setImageX(startX + trueWidth + itemSpacing + (receiver.getParam() - currentImage - 1) * (itemWidth + itemSpacing) + moveX);
|
|
|
|
} else {
|
|
|
|
receiver.setImageX(startX + trueWidth + itemSpacing + (receiver.getParam() - currentImage - 2) * (itemWidth + itemSpacing) + (nextTrueWidth + itemSpacing) + moveX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num == nextImage) {
|
|
|
|
receiver.setImageWidth(nextTrueWidth - nextPaddings);
|
|
|
|
receiver.setImageX(receiver.getImageX() + nextPaddings / 2);
|
|
|
|
} else {
|
|
|
|
receiver.setImageWidth(itemWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
receiver.draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
long newTime = System.currentTimeMillis();
|
|
|
|
long dt = newTime - lastUpdateTime;
|
|
|
|
if (dt > 17) {
|
|
|
|
dt = 17;
|
|
|
|
}
|
|
|
|
lastUpdateTime = newTime;
|
|
|
|
if (animateToItem >= 0) {
|
|
|
|
if (moveLineProgress > 0.0f) {
|
|
|
|
moveLineProgress -= dt / 200.0f;
|
|
|
|
if (animateToItem == currentImage) {
|
|
|
|
if (currentItemProgress < 1.0f) {
|
|
|
|
currentItemProgress += dt / 200.0f;
|
|
|
|
if (currentItemProgress > 1.0f) {
|
|
|
|
currentItemProgress = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawDx = animateToDXStart + (int) Math.ceil(currentItemProgress * (animateToDX - animateToDXStart));
|
|
|
|
} else {
|
|
|
|
nextItemProgress = CubicBezierInterpolator.EASE_OUT.getInterpolation(1.0f - moveLineProgress);
|
|
|
|
if (stopedScrolling) {
|
|
|
|
if (currentItemProgress > 0.0f) {
|
|
|
|
currentItemProgress -= dt / 200.0f;
|
|
|
|
if (currentItemProgress < 0.0f) {
|
|
|
|
currentItemProgress = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawDx = animateToDXStart + (int) Math.ceil(nextItemProgress * (animateToDX - animateToDXStart));
|
|
|
|
} else {
|
|
|
|
currentItemProgress = CubicBezierInterpolator.EASE_OUT.getInterpolation(moveLineProgress);
|
|
|
|
drawDx = (int) Math.ceil(nextItemProgress * animateToDX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (moveLineProgress <= 0) {
|
|
|
|
currentImage = animateToItem;
|
|
|
|
moveLineProgress = 1.0f;
|
|
|
|
currentItemProgress = 1.0f;
|
|
|
|
nextItemProgress = 0.0f;
|
|
|
|
moving = false;
|
|
|
|
stopedScrolling = false;
|
|
|
|
drawDx = 0;
|
|
|
|
animateToItem = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fillImages(true, drawDx);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
if (scrolling && currentItemProgress > 0.0f) {
|
|
|
|
currentItemProgress -= dt / 200.0f;
|
|
|
|
if (currentItemProgress < 0.0f) {
|
|
|
|
currentItemProgress = 0.0f;
|
|
|
|
}
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
if (!scroll.isFinished()) {
|
|
|
|
if (scroll.computeScrollOffset()) {
|
|
|
|
drawDx = scroll.getCurrX();
|
|
|
|
updateAfterScroll();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
if (scroll.isFinished()) {
|
|
|
|
stopScrolling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private class BackgroundDrawable extends ColorDrawable {
|
|
|
|
|
|
|
|
private Runnable drawRunnable;
|
2017-03-31 01:58:05 +02:00
|
|
|
private boolean allowDrawContent;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public BackgroundDrawable(int color) {
|
|
|
|
super(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAlpha(int alpha) {
|
|
|
|
if (parentActivity instanceof LaunchActivity) {
|
2017-03-31 01:58:05 +02:00
|
|
|
allowDrawContent = !isVisible || alpha != 255;
|
|
|
|
((LaunchActivity) parentActivity).drawerLayoutContainer.setAllowDrawContent(allowDrawContent);
|
|
|
|
if (parentAlert != null) {
|
|
|
|
if (!allowDrawContent) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (parentAlert != null) {
|
|
|
|
parentAlert.setAllowDrawContent(allowDrawContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 50);
|
|
|
|
} else {
|
|
|
|
if (parentAlert != null) {
|
|
|
|
parentAlert.setAllowDrawContent(allowDrawContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
super.setAlpha(alpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(Canvas canvas) {
|
|
|
|
super.draw(canvas);
|
|
|
|
if (getAlpha() != 0) {
|
|
|
|
if (drawRunnable != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
AndroidUtilities.runOnUIThread(drawRunnable);
|
2015-05-03 13:48:36 +02:00
|
|
|
drawRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
private class CounterView extends View {
|
|
|
|
|
|
|
|
private StaticLayout staticLayout;
|
|
|
|
private TextPaint textPaint;
|
|
|
|
private Paint paint;
|
|
|
|
private int width;
|
|
|
|
private int height;
|
|
|
|
private RectF rect;
|
|
|
|
private int currentCount = 0;
|
2017-12-08 18:35:59 +01:00
|
|
|
private float rotation;
|
2017-07-23 14:56:38 +02:00
|
|
|
|
|
|
|
public CounterView(Context context) {
|
|
|
|
super(context);
|
|
|
|
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
textPaint.setTextSize(AndroidUtilities.dp(18));
|
|
|
|
textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textPaint.setColor(0xffffffff);
|
|
|
|
|
|
|
|
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
paint.setColor(0xffffffff);
|
|
|
|
paint.setStrokeWidth(AndroidUtilities.dp(2));
|
|
|
|
paint.setStyle(Paint.Style.STROKE);
|
2017-12-08 18:35:59 +01:00
|
|
|
paint.setStrokeJoin(Paint.Join.ROUND);
|
2017-07-23 14:56:38 +02:00
|
|
|
|
|
|
|
rect = new RectF();
|
|
|
|
|
|
|
|
setCount(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setScaleX(float scaleX) {
|
|
|
|
super.setScaleX(scaleX);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
|
|
|
public void setRotationX(float rotationX) {
|
|
|
|
rotation = rotationX;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getRotationX() {
|
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public void setCount(int value) {
|
|
|
|
staticLayout = new StaticLayout("" + Math.max(1, value), textPaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
width = (int) Math.ceil(staticLayout.getLineWidth(0));
|
|
|
|
height = staticLayout.getLineBottom(0);
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
if (value == 0) {
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleX", 0.0f),
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleY", 0.0f),
|
|
|
|
ObjectAnimator.ofInt(paint, "alpha", 0),
|
|
|
|
ObjectAnimator.ofInt(textPaint, "alpha", 0));
|
|
|
|
animatorSet.setInterpolator(new DecelerateInterpolator());
|
|
|
|
} else if (currentCount == 0) {
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleX", 0.0f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleY", 0.0f, 1.0f),
|
|
|
|
ObjectAnimator.ofInt(paint, "alpha", 0, 255),
|
|
|
|
ObjectAnimator.ofInt(textPaint, "alpha", 0, 255));
|
|
|
|
animatorSet.setInterpolator(new DecelerateInterpolator());
|
|
|
|
} else if (value < currentCount) {
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleX", 1.1f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleY", 1.1f, 1.0f));
|
|
|
|
animatorSet.setInterpolator(new OvershootInterpolator());
|
|
|
|
} else {
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleX", 0.9f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(this, "scaleY", 0.9f, 1.0f));
|
|
|
|
animatorSet.setInterpolator(new OvershootInterpolator());
|
|
|
|
}
|
|
|
|
|
|
|
|
animatorSet.setDuration(180);
|
|
|
|
animatorSet.start();
|
|
|
|
requestLayout();
|
|
|
|
currentCount = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(Math.max(width + AndroidUtilities.dp(20), AndroidUtilities.dp(30)), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(40), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
int cy = getMeasuredHeight() / 2;
|
2017-12-08 18:35:59 +01:00
|
|
|
paint.setAlpha(255);
|
2017-07-23 14:56:38 +02:00
|
|
|
rect.set(AndroidUtilities.dp(1), cy - AndroidUtilities.dp(14), getMeasuredWidth() - AndroidUtilities.dp(1), cy + AndroidUtilities.dp(14));
|
|
|
|
canvas.drawRoundRect(rect, AndroidUtilities.dp(15), AndroidUtilities.dp(15), paint);
|
|
|
|
if (staticLayout != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
textPaint.setAlpha((int) ((1.0f - rotation) * 255));
|
2017-07-23 14:56:38 +02:00
|
|
|
canvas.save();
|
2017-12-08 18:35:59 +01:00
|
|
|
canvas.translate((getMeasuredWidth() - width) / 2, (getMeasuredHeight() - height) / 2 + AndroidUtilities.dpf2(0.2f) + rotation * AndroidUtilities.dp(5));
|
2017-07-23 14:56:38 +02:00
|
|
|
staticLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
2017-12-08 18:35:59 +01:00
|
|
|
paint.setAlpha((int) (rotation * 255));
|
|
|
|
int cx = (int) rect.centerX();
|
|
|
|
cy = (int) rect.centerY();
|
|
|
|
cy -= AndroidUtilities.dp(5) * (1.0f - rotation) + AndroidUtilities.dp(3.0f);
|
|
|
|
canvas.drawLine(cx + AndroidUtilities.dp(0.5f), cy - AndroidUtilities.dp(0.5f), cx - AndroidUtilities.dp(6), cy + AndroidUtilities.dp(6), paint);
|
|
|
|
canvas.drawLine(cx - AndroidUtilities.dp(0.5f), cy - AndroidUtilities.dp(0.5f), cx + AndroidUtilities.dp(6), cy + AndroidUtilities.dp(6), paint);
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class PhotoProgressView {
|
2014-10-28 18:07:44 +01:00
|
|
|
|
|
|
|
private long lastUpdateTime = 0;
|
|
|
|
private float radOffset = 0;
|
|
|
|
private float currentProgress = 0;
|
|
|
|
private float animationProgressStart = 0;
|
|
|
|
private long currentProgressTime = 0;
|
|
|
|
private float animatedProgressValue = 0;
|
|
|
|
private RectF progressRect = new RectF();
|
|
|
|
private int backgroundState = -1;
|
|
|
|
private View parent = null;
|
|
|
|
private int size = AndroidUtilities.dp(64);
|
2014-10-30 22:27:41 +01:00
|
|
|
private int previousBackgroundState = -2;
|
|
|
|
private float animatedAlphaValue = 1.0f;
|
2015-01-02 23:15:07 +01:00
|
|
|
private float alpha = 1.0f;
|
|
|
|
private float scale = 1.0f;
|
2014-10-28 18:07:44 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public PhotoProgressView(Context context, View parentView) {
|
2014-10-28 18:07:44 +01:00
|
|
|
if (decelerateInterpolator == null) {
|
2015-01-02 23:15:07 +01:00
|
|
|
decelerateInterpolator = new DecelerateInterpolator(1.5f);
|
2014-10-28 18:07:44 +01:00
|
|
|
progressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
progressPaint.setStyle(Paint.Style.STROKE);
|
|
|
|
progressPaint.setStrokeCap(Paint.Cap.ROUND);
|
2016-04-22 15:49:00 +02:00
|
|
|
progressPaint.setStrokeWidth(AndroidUtilities.dp(3));
|
2014-10-28 18:07:44 +01:00
|
|
|
progressPaint.setColor(0xffffffff);
|
|
|
|
}
|
|
|
|
parent = parentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAnimation() {
|
|
|
|
long newTime = System.currentTimeMillis();
|
|
|
|
long dt = newTime - lastUpdateTime;
|
|
|
|
lastUpdateTime = newTime;
|
|
|
|
|
2014-10-30 22:27:41 +01:00
|
|
|
if (animatedProgressValue != 1) {
|
|
|
|
radOffset += 360 * dt / 3000.0f;
|
|
|
|
float progressDiff = currentProgress - animationProgressStart;
|
|
|
|
if (progressDiff > 0) {
|
|
|
|
currentProgressTime += dt;
|
|
|
|
if (currentProgressTime >= 300) {
|
|
|
|
animatedProgressValue = currentProgress;
|
|
|
|
animationProgressStart = currentProgress;
|
|
|
|
currentProgressTime = 0;
|
|
|
|
} else {
|
|
|
|
animatedProgressValue = animationProgressStart + progressDiff * decelerateInterpolator.getInterpolation(currentProgressTime / 300.0f);
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2014-10-30 22:27:41 +01:00
|
|
|
parent.invalidate();
|
|
|
|
}
|
|
|
|
if (animatedProgressValue >= 1 && previousBackgroundState != -2) {
|
|
|
|
animatedAlphaValue -= dt / 200.0f;
|
|
|
|
if (animatedAlphaValue <= 0) {
|
|
|
|
animatedAlphaValue = 0.0f;
|
|
|
|
previousBackgroundState = -2;
|
|
|
|
}
|
|
|
|
parent.invalidate();
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-10-28 18:07:44 +01:00
|
|
|
public void setProgress(float value, boolean animated) {
|
|
|
|
if (!animated) {
|
|
|
|
animatedProgressValue = value;
|
|
|
|
animationProgressStart = value;
|
|
|
|
} else {
|
|
|
|
animationProgressStart = animatedProgressValue;
|
|
|
|
}
|
|
|
|
currentProgress = value;
|
|
|
|
currentProgressTime = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-30 22:27:41 +01:00
|
|
|
public void setBackgroundState(int state, boolean animated) {
|
2014-10-28 18:07:44 +01:00
|
|
|
lastUpdateTime = System.currentTimeMillis();
|
2014-10-30 22:27:41 +01:00
|
|
|
if (animated && backgroundState != state) {
|
|
|
|
previousBackgroundState = backgroundState;
|
|
|
|
animatedAlphaValue = 1.0f;
|
|
|
|
} else {
|
|
|
|
previousBackgroundState = -2;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
backgroundState = state;
|
|
|
|
parent.invalidate();
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void setAlpha(float value) {
|
|
|
|
alpha = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScale(float value) {
|
|
|
|
scale = value;
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:07:44 +01:00
|
|
|
public void onDraw(Canvas canvas) {
|
2015-02-01 19:51:02 +01:00
|
|
|
int sizeScaled = (int) (size * scale);
|
2015-05-03 13:48:36 +02:00
|
|
|
int x = (getContainerViewWidth() - sizeScaled) / 2;
|
|
|
|
int y = (getContainerViewHeight() - sizeScaled) / 2;
|
2014-10-28 18:07:44 +01:00
|
|
|
|
2014-10-30 22:27:41 +01:00
|
|
|
if (previousBackgroundState >= 0 && previousBackgroundState < 4) {
|
|
|
|
Drawable drawable = progressDrawables[previousBackgroundState];
|
|
|
|
if (drawable != null) {
|
2015-02-01 19:51:02 +01:00
|
|
|
drawable.setAlpha((int) (255 * animatedAlphaValue * alpha));
|
2015-01-02 23:15:07 +01:00
|
|
|
drawable.setBounds(x, y, x + sizeScaled, y + sizeScaled);
|
2014-10-30 22:27:41 +01:00
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
|
|
|
|
2014-10-30 22:27:41 +01:00
|
|
|
if (backgroundState >= 0 && backgroundState < 4) {
|
|
|
|
Drawable drawable = progressDrawables[backgroundState];
|
|
|
|
if (drawable != null) {
|
|
|
|
if (previousBackgroundState != -2) {
|
2015-02-01 19:51:02 +01:00
|
|
|
drawable.setAlpha((int) (255 * (1.0f - animatedAlphaValue) * alpha));
|
2014-10-30 22:27:41 +01:00
|
|
|
} else {
|
2015-02-01 19:51:02 +01:00
|
|
|
drawable.setAlpha((int) (255 * alpha));
|
2014-10-30 22:27:41 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
drawable.setBounds(x, y, x + sizeScaled, y + sizeScaled);
|
2014-10-30 22:27:41 +01:00
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backgroundState == 0 || backgroundState == 1 || previousBackgroundState == 0 || previousBackgroundState == 1) {
|
2016-04-22 15:49:00 +02:00
|
|
|
int diff = AndroidUtilities.dp(4);
|
2014-10-30 22:27:41 +01:00
|
|
|
if (previousBackgroundState != -2) {
|
2015-02-01 19:51:02 +01:00
|
|
|
progressPaint.setAlpha((int) (255 * animatedAlphaValue * alpha));
|
2014-10-30 22:27:41 +01:00
|
|
|
} else {
|
2015-02-01 19:51:02 +01:00
|
|
|
progressPaint.setAlpha((int) (255 * alpha));
|
2014-10-30 22:27:41 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
progressRect.set(x + diff, y + diff, x + sizeScaled - diff, y + sizeScaled - diff);
|
2014-10-28 18:07:44 +01:00
|
|
|
canvas.drawArc(progressRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint);
|
|
|
|
updateAnimation();
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
public static class PlaceProviderObject {
|
|
|
|
public ImageReceiver imageReceiver;
|
|
|
|
public int viewX;
|
|
|
|
public int viewY;
|
|
|
|
public View parentView;
|
|
|
|
public Bitmap thumb;
|
2016-06-24 12:27:15 +02:00
|
|
|
public int dialogId;
|
2014-06-11 01:05:54 +02:00
|
|
|
public int index;
|
|
|
|
public int size;
|
2014-11-17 03:44:57 +01:00
|
|
|
public int radius;
|
2015-10-29 18:10:07 +01:00
|
|
|
public int clipBottomAddition;
|
2015-11-26 22:04:02 +01:00
|
|
|
public int clipTopAddition;
|
2015-10-29 18:10:07 +01:00
|
|
|
public float scale = 1.0f;
|
2017-07-08 18:32:04 +02:00
|
|
|
public boolean isEvent;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public static class EmptyPhotoViewerProvider implements PhotoViewerProvider {
|
|
|
|
@Override
|
|
|
|
public PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-12-08 18:35:59 +01:00
|
|
|
public int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) {
|
|
|
|
return -1;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 18:10:07 +01:00
|
|
|
public boolean cancelButtonPressed() {
|
|
|
|
return true;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
|
|
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean allowCaption() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean scaleToFill() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toggleGroupPhotosEnabled() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<Object> getSelectedPhotosOrder() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HashMap<Object, Object> getSelectedPhotos() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canScrollAway() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean allowGroupPhotos() {
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface PhotoViewerProvider {
|
|
|
|
PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
void willHidePhotoViewer();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
boolean isPhotoChecked(int index);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
boolean cancelButtonPressed();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
int getSelectedCount();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
void updatePhotoAtIndex(int index);
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean allowCaption();
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean scaleToFill();
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
void toggleGroupPhotosEnabled();
|
|
|
|
|
|
|
|
ArrayList<Object> getSelectedPhotosOrder();
|
|
|
|
|
|
|
|
HashMap<Object, Object> getSelectedPhotos();
|
|
|
|
|
|
|
|
boolean canScrollAway();
|
|
|
|
|
|
|
|
boolean allowGroupPhotos();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private class FrameLayoutDrawer extends SizeNotifierFrameLayoutPhoto {
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private Paint paint = new Paint();
|
|
|
|
|
2014-06-12 17:53:20 +02:00
|
|
|
public FrameLayoutDrawer(Context context) {
|
|
|
|
super(context);
|
|
|
|
setWillNotDraw(false);
|
2016-10-11 13:57:01 +02:00
|
|
|
paint.setColor(0x33000000);
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
setMeasuredDimension(widthSize, heightSize);
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
measureChildWithMargins(captionEditText, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
int inputFieldHeight = captionEditText.getMeasuredHeight();
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View child = getChildAt(i);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (child.getVisibility() == GONE || child == captionEditText) {
|
2015-06-29 19:12:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (child == aspectRatioFrameLayout) {
|
|
|
|
int heightSpec = MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0), MeasureSpec.EXACTLY);
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightSpec, 0);
|
|
|
|
} else if (captionEditText.isPopupView(child)) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (AndroidUtilities.isInMultiwindow) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(320), heightSize - inputFieldHeight - AndroidUtilities.statusBarHeight), MeasureSpec.EXACTLY));
|
|
|
|
} else {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - inputFieldHeight - AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
final int count = getChildCount();
|
2016-10-11 13:57:01 +02:00
|
|
|
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? captionEditText.getEmojiPadding() : 0;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
|
|
|
|
|
|
|
|
final int width = child.getMeasuredWidth();
|
|
|
|
final int height = child.getMeasuredHeight();
|
|
|
|
|
|
|
|
int childLeft;
|
|
|
|
int childTop;
|
|
|
|
|
|
|
|
int gravity = lp.gravity;
|
|
|
|
if (gravity == -1) {
|
|
|
|
gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
|
|
|
|
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
|
|
|
|
|
|
|
|
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
|
|
|
|
case Gravity.CENTER_HORIZONTAL:
|
|
|
|
childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.RIGHT:
|
2017-03-31 01:58:05 +02:00
|
|
|
childLeft = (r - l - width) - lp.rightMargin;
|
2015-06-29 19:12:11 +02:00
|
|
|
break;
|
|
|
|
case Gravity.LEFT:
|
|
|
|
default:
|
|
|
|
childLeft = lp.leftMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (verticalGravity) {
|
|
|
|
case Gravity.TOP:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.CENTER_VERTICAL:
|
|
|
|
childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
|
|
|
|
break;
|
|
|
|
case Gravity.BOTTOM:
|
|
|
|
childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
childTop = lp.topMargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child == mentionListView) {
|
2017-03-31 01:58:05 +02:00
|
|
|
childTop -= captionEditText.getMeasuredHeight();
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (captionEditText.isPopupView(child)) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (AndroidUtilities.isInMultiwindow) {
|
|
|
|
childTop = captionEditText.getTop() - child.getMeasuredHeight() + AndroidUtilities.dp(1);
|
|
|
|
} else {
|
|
|
|
childTop = captionEditText.getBottom();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (child == selectedPhotosListView) {
|
|
|
|
childTop = actionBar.getMeasuredHeight();
|
|
|
|
} else if (child == captionTextView) {
|
|
|
|
if (!groupedPhotosListView.currentPhotos.isEmpty()) {
|
|
|
|
childTop -= groupedPhotosListView.getMeasuredHeight();
|
|
|
|
}
|
|
|
|
} else if (hintTextView != null && child == hintTextView) {
|
|
|
|
childTop = selectedPhotosListView.getBottom() + AndroidUtilities.dp(3);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
child.layout(childLeft, childTop, childLeft + width, childTop + height);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
notifyHeightChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
2017-03-31 01:58:05 +02:00
|
|
|
PhotoViewer.this.onDraw(canvas);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && AndroidUtilities.statusBarHeight != 0) {
|
|
|
|
canvas.drawRect(0, 0, getMeasuredWidth(), AndroidUtilities.statusBarHeight, paint);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (child == mentionListView || child == captionEditText) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (!captionEditText.isPopupShowing() && captionEditText.getEmojiPadding() == 0 && (AndroidUtilities.usingHardwareInput && captionEditText.getTag() == null || getKeyboardHeight() == 0)) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (child == pickerView || child == captionTextView || muteItem.getVisibility() == VISIBLE && child == bottomLayout) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int paddingBottom = getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow ? captionEditText.getEmojiPadding() : 0;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (captionEditText.isPopupShowing() || AndroidUtilities.usingHardwareInput && captionEditText.getTag() != null || getKeyboardHeight() > 0 || paddingBottom != 0) {
|
|
|
|
bottomTouchEnabled = false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
bottomTouchEnabled = true;
|
|
|
|
}
|
|
|
|
} else if (child == checkImageView || child == photosCounterView) {
|
|
|
|
if (captionEditText.getTag() != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
bottomTouchEnabled = false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
bottomTouchEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
try {
|
|
|
|
return child != aspectRatioFrameLayout && super.drawChild(canvas, child, drawingTime);
|
|
|
|
} catch (Throwable ignore) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@SuppressLint("StaticFieldLeak")
|
2014-06-07 01:35:21 +02:00
|
|
|
private static volatile PhotoViewer Instance = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2014-06-07 01:35:21 +02:00
|
|
|
public static PhotoViewer getInstance() {
|
|
|
|
PhotoViewer localInstance = Instance;
|
|
|
|
if (localInstance == null) {
|
|
|
|
synchronized (PhotoViewer.class) {
|
|
|
|
localInstance = Instance;
|
|
|
|
if (localInstance == null) {
|
|
|
|
Instance = localInstance = new PhotoViewer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return localInstance;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public PhotoViewer() {
|
|
|
|
blackPaint.setColor(0xff000000);
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
if (id == NotificationCenter.FileDidFailedLoad) {
|
2015-02-01 19:51:02 +01:00
|
|
|
String location = (String) args[0];
|
2014-10-28 18:07:44 +01:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setProgress(1.0f, true);
|
2014-10-30 22:27:41 +01:00
|
|
|
checkProgress(a, true);
|
2014-10-28 18:07:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.FileDidLoaded) {
|
2015-02-01 19:51:02 +01:00
|
|
|
String location = (String) args[0];
|
2014-10-28 18:07:44 +01:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setProgress(1.0f, true);
|
2014-10-30 22:27:41 +01:00
|
|
|
checkProgress(a, true);
|
2017-07-23 14:56:38 +02:00
|
|
|
if (a == 0 && (currentMessageObject != null && currentMessageObject.isVideo() || currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document)))) {
|
2016-06-24 12:27:15 +02:00
|
|
|
onActionClick(false);
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.FileLoadProgressChanged) {
|
2015-02-01 19:51:02 +01:00
|
|
|
String location = (String) args[0];
|
2014-10-28 18:07:44 +01:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (currentFileNames[a] != null && currentFileNames[a].equals(location)) {
|
|
|
|
Float progress = (Float) args[1];
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setProgress(progress, true);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (id == NotificationCenter.dialogPhotosLoaded) {
|
2017-12-08 18:35:59 +01:00
|
|
|
int guid = (Integer) args[3];
|
2016-06-24 12:27:15 +02:00
|
|
|
int did = (Integer) args[0];
|
|
|
|
if (avatarsDialogId == did && classGuid == guid) {
|
2017-12-08 18:35:59 +01:00
|
|
|
boolean fromCache = (Boolean) args[2];
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
int setToImage = -1;
|
2017-12-08 18:35:59 +01:00
|
|
|
ArrayList<TLRPC.Photo> photos = (ArrayList<TLRPC.Photo>) args[4];
|
2014-06-11 01:05:54 +02:00
|
|
|
if (photos.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
imagesArrLocations.clear();
|
|
|
|
imagesArrLocationsSizes.clear();
|
2014-08-22 16:24:33 +02:00
|
|
|
avatarsArr.clear();
|
2016-05-25 23:49:47 +02:00
|
|
|
for (int a = 0; a < photos.size(); a++) {
|
|
|
|
TLRPC.Photo photo = photos.get(a);
|
2015-03-26 18:34:47 +01:00
|
|
|
if (photo == null || photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
|
2014-06-11 01:05:54 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-10-01 21:55:24 +02:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640);
|
2014-06-11 01:05:54 +02:00
|
|
|
if (sizeFull != null) {
|
2016-05-25 23:49:47 +02:00
|
|
|
if (setToImage == -1 && currentFileLocation != null) {
|
|
|
|
for (int b = 0; b < photo.sizes.size(); b++) {
|
|
|
|
TLRPC.PhotoSize size = photo.sizes.get(b);
|
2014-06-14 10:36:01 +02:00
|
|
|
if (size.location.local_id == currentFileLocation.local_id && size.location.volume_id == currentFileLocation.volume_id) {
|
|
|
|
setToImage = imagesArrLocations.size();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
imagesArrLocations.add(sizeFull.location);
|
|
|
|
imagesArrLocationsSizes.add(sizeFull.size);
|
2014-08-22 16:24:33 +02:00
|
|
|
avatarsArr.add(photo);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
if (!avatarsArr.isEmpty()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
2014-08-22 16:24:33 +02:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
needSearchImageInArr = false;
|
|
|
|
currentIndex = -1;
|
|
|
|
if (setToImage != -1) {
|
|
|
|
setImageIndex(setToImage, true);
|
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
avatarsArr.add(0, new TLRPC.TL_photoEmpty());
|
2014-06-13 20:26:05 +02:00
|
|
|
imagesArrLocations.add(0, currentFileLocation);
|
2014-06-14 10:36:01 +02:00
|
|
|
imagesArrLocationsSizes.add(0, 0);
|
2014-06-11 01:05:54 +02:00
|
|
|
setImageIndex(0, true);
|
|
|
|
}
|
|
|
|
if (fromCache) {
|
2017-12-08 18:35:59 +01:00
|
|
|
MessagesController.getInstance().loadDialogPhotos(avatarsDialogId, 80, 0, false, classGuid);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.mediaCountDidLoaded) {
|
2015-02-01 19:51:02 +01:00
|
|
|
long uid = (Long) args[0];
|
2015-11-26 22:04:02 +01:00
|
|
|
if (uid == currentDialogId || uid == mergeDialogId) {
|
|
|
|
if (uid == currentDialogId) {
|
|
|
|
totalImagesCount = (Integer) args[1];
|
2015-12-09 19:27:52 +01:00
|
|
|
/*if ((Boolean) args[2]) {
|
2015-11-26 22:04:02 +01:00
|
|
|
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, false);
|
2015-12-09 19:27:52 +01:00
|
|
|
}*/
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (uid == mergeDialogId) {
|
|
|
|
totalImagesCountMerge = (Integer) args[1];
|
2015-12-09 19:27:52 +01:00
|
|
|
/*if ((Boolean) args[2]) {
|
2015-11-26 22:04:02 +01:00
|
|
|
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, false);
|
2015-12-09 19:27:52 +01:00
|
|
|
}*/
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
if (needSearchImageInArr && isFirstLoading) {
|
|
|
|
isFirstLoading = false;
|
|
|
|
loadingMoreImages = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedMediaQuery.loadMedia(currentDialogId, 80, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (!imagesArr.isEmpty()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (opennedFromMedia) {
|
2015-11-26 22:04:02 +01:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
} else if (id == NotificationCenter.mediaDidLoaded) {
|
2015-02-01 19:51:02 +01:00
|
|
|
long uid = (Long) args[0];
|
2015-09-24 22:52:02 +02:00
|
|
|
int guid = (Integer) args[3];
|
2015-11-26 22:04:02 +01:00
|
|
|
if ((uid == currentDialogId || uid == mergeDialogId) && guid == classGuid) {
|
2014-06-11 01:05:54 +02:00
|
|
|
loadingMoreImages = false;
|
2015-11-26 22:04:02 +01:00
|
|
|
int loadIndex = uid == currentDialogId ? 0 : 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[2];
|
2015-11-26 22:04:02 +01:00
|
|
|
endReached[loadIndex] = (Boolean) args[5];
|
2014-06-11 01:05:54 +02:00
|
|
|
if (needSearchImageInArr) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (arr.isEmpty() && (loadIndex != 0 || mergeDialogId == 0)) {
|
2014-06-11 01:05:54 +02:00
|
|
|
needSearchImageInArr = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int foundIndex = -1;
|
|
|
|
|
|
|
|
MessageObject currentMessage = imagesArr.get(currentIndex);
|
|
|
|
|
|
|
|
int added = 0;
|
2015-11-26 22:04:02 +01:00
|
|
|
for (int a = 0; a < arr.size(); a++) {
|
|
|
|
MessageObject message = arr.get(a);
|
|
|
|
if (!imagesByIdsTemp[loadIndex].containsKey(message.getId())) {
|
|
|
|
imagesByIdsTemp[loadIndex].put(message.getId(), message);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
imagesArrTemp.add(message);
|
2015-03-19 00:09:45 +01:00
|
|
|
if (message.getId() == currentMessage.getId()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
foundIndex = added;
|
|
|
|
}
|
|
|
|
added++;
|
|
|
|
} else {
|
|
|
|
added++;
|
|
|
|
imagesArrTemp.add(0, message);
|
2015-03-19 00:09:45 +01:00
|
|
|
if (message.getId() == currentMessage.getId()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
foundIndex = arr.size() - added;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (added == 0 && (loadIndex != 0 || mergeDialogId == 0)) {
|
2014-06-11 01:05:54 +02:00
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 22:04:02 +01:00
|
|
|
totalImagesCountMerge = 0;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (foundIndex != -1) {
|
|
|
|
imagesArr.clear();
|
|
|
|
imagesArr.addAll(imagesArrTemp);
|
2015-11-26 22:04:02 +01:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
imagesByIds[a].clear();
|
|
|
|
imagesByIds[a].putAll(imagesByIdsTemp[a]);
|
|
|
|
imagesByIdsTemp[a].clear();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
imagesArrTemp.clear();
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
currentIndex = -1;
|
2014-07-23 01:27:00 +02:00
|
|
|
if (foundIndex >= imagesArr.size()) {
|
|
|
|
foundIndex = imagesArr.size() - 1;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
setImageIndex(foundIndex, true);
|
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
int loadFromMaxId;
|
|
|
|
if (opennedFromMedia) {
|
|
|
|
loadFromMaxId = imagesArrTemp.isEmpty() ? 0 : imagesArrTemp.get(imagesArrTemp.size() - 1).getId();
|
|
|
|
if (loadIndex == 0 && endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArrTemp.isEmpty() && imagesArrTemp.get(imagesArrTemp.size() - 1).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
loadFromMaxId = imagesArrTemp.isEmpty() ? 0 : imagesArrTemp.get(0).getId();
|
|
|
|
if (loadIndex == 0 && endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArrTemp.isEmpty() && imagesArrTemp.get(0).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!endReached[loadIndex]) {
|
2014-06-11 01:05:54 +02:00
|
|
|
loadingMoreImages = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (opennedFromMedia) {
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int added = 0;
|
|
|
|
for (MessageObject message : arr) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (!imagesByIds[loadIndex].containsKey(message.getId())) {
|
2014-06-11 01:05:54 +02:00
|
|
|
added++;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
imagesArr.add(message);
|
|
|
|
} else {
|
|
|
|
imagesArr.add(0, message);
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
imagesByIds[loadIndex].put(message.getId(), message);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (opennedFromMedia) {
|
|
|
|
if (added == 0) {
|
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 22:04:02 +01:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (added != 0) {
|
|
|
|
int index = currentIndex;
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(index + added, true);
|
|
|
|
} else {
|
|
|
|
totalImagesCount = imagesArr.size();
|
2015-11-26 22:04:02 +01:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoaded) {
|
|
|
|
if (captionTextView != null) {
|
|
|
|
captionTextView.invalidate();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (id == NotificationCenter.FilePreparingFailed) {
|
|
|
|
MessageObject messageObject = (MessageObject) args[0];
|
|
|
|
if (loadInitialVideo) {
|
|
|
|
loadInitialVideo = false;
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
preparePlayer(currentPlayingVideoFile, false, false);
|
|
|
|
} else if (tryStartRequestPreviewOnFinish) {
|
|
|
|
releasePlayer();
|
|
|
|
tryStartRequestPreviewOnFinish = !MediaController.getInstance().scheduleVideoConvert(videoPreviewMessageObject, true);
|
|
|
|
} else if (messageObject == videoPreviewMessageObject) {
|
|
|
|
requestingPreview = false;
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.FileNewChunkAvailable) {
|
|
|
|
MessageObject messageObject = (MessageObject) args[0];
|
|
|
|
if (messageObject == videoPreviewMessageObject) {
|
|
|
|
String finalPath = (String) args[1];
|
|
|
|
long finalSize = (Long) args[2];
|
|
|
|
if (finalSize != 0) {
|
|
|
|
requestingPreview = false;
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
preparePlayer(new File(finalPath), false, true);
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private void onSharePressed() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (parentActivity == null || !allowShare) {
|
2016-06-24 12:27:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
File f = null;
|
|
|
|
boolean isVideo = false;
|
|
|
|
|
|
|
|
if (currentMessageObject != null) {
|
|
|
|
isVideo = currentMessageObject.isVideo();
|
|
|
|
/*if (currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
AndroidUtilities.openUrl(parentActivity, currentMessageObject.messageOwner.media.webpage.url);
|
|
|
|
return;
|
|
|
|
}*/
|
2017-03-31 01:58:05 +02:00
|
|
|
if (!TextUtils.isEmpty(currentMessageObject.messageOwner.attachPath)) {
|
|
|
|
f = new File(currentMessageObject.messageOwner.attachPath);
|
|
|
|
if (!f.exists()) {
|
|
|
|
f = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f == null) {
|
|
|
|
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (currentFileLocation != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0 || isEvent);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (f.exists()) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
if (isVideo) {
|
|
|
|
intent.setType("video/mp4");
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (currentMessageObject != null) {
|
|
|
|
intent.setType(currentMessageObject.getMimeType());
|
|
|
|
} else {
|
|
|
|
intent.setType("image/jpeg");
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
try {
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(parentActivity, BuildConfig.APPLICATION_ID + ".provider", f));
|
|
|
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
} catch (Exception ignore) {
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
|
|
|
parentActivity.startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
|
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
|
|
|
|
showAlertDialog(builder);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void setScaleToFill() {
|
|
|
|
float bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
float containerWidth = getContainerViewWidth();
|
|
|
|
float bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
float containerHeight = getContainerViewHeight();
|
|
|
|
float scaleFit = Math.min(containerHeight / bitmapHeight, containerWidth / bitmapWidth);
|
|
|
|
float width = (int) (bitmapWidth * scaleFit);
|
|
|
|
float height = (int) (bitmapHeight * scaleFit);
|
|
|
|
scale = Math.max(containerWidth / width, containerHeight / height);
|
|
|
|
updateMinMax(scale);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void setParentAlert(ChatAttachAlert alert) {
|
|
|
|
parentAlert = alert;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void setParentActivity(final Activity activity) {
|
2014-07-03 16:55:04 +02:00
|
|
|
if (parentActivity == activity) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
parentActivity = activity;
|
2016-04-22 15:49:00 +02:00
|
|
|
actvityContext = new ContextThemeWrapper(parentActivity, R.style.Theme_TMessages);
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-10-24 15:43:45 +02:00
|
|
|
if (progressDrawables == null) {
|
|
|
|
progressDrawables = new Drawable[4];
|
2014-10-28 18:07:44 +01:00
|
|
|
progressDrawables[0] = parentActivity.getResources().getDrawable(R.drawable.circle_big);
|
|
|
|
progressDrawables[1] = parentActivity.getResources().getDrawable(R.drawable.cancel_big);
|
|
|
|
progressDrawables[2] = parentActivity.getResources().getDrawable(R.drawable.load_big);
|
|
|
|
progressDrawables[3] = parentActivity.getResources().getDrawable(R.drawable.play_big);
|
2014-10-24 15:43:45 +02:00
|
|
|
}
|
|
|
|
|
2014-06-21 23:46:11 +02:00
|
|
|
scroller = new Scroller(activity);
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
windowView = new FrameLayout(activity) {
|
|
|
|
|
|
|
|
private Runnable attachRunnable;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
return isVisible && super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return isVisible && PhotoViewer.this.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
|
|
|
boolean result = super.drawChild(canvas, child, drawingTime);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && child == animatingImageView && lastInsets != null) {
|
|
|
|
WindowInsets insets = (WindowInsets) lastInsets;
|
|
|
|
canvas.drawRect(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight() + insets.getSystemWindowInsetBottom(), blackPaint);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
|
|
|
|
WindowInsets insets = (WindowInsets) lastInsets;
|
|
|
|
if (AndroidUtilities.incorrectDisplaySizeFix) {
|
|
|
|
if (heightSize > AndroidUtilities.displaySize.y) {
|
|
|
|
heightSize = AndroidUtilities.displaySize.y;
|
|
|
|
}
|
|
|
|
heightSize += AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
heightSize -= insets.getSystemWindowInsetBottom();
|
|
|
|
widthSize -= insets.getSystemWindowInsetRight();
|
|
|
|
} else {
|
|
|
|
if (heightSize > AndroidUtilities.displaySize.y) {
|
|
|
|
heightSize = AndroidUtilities.displaySize.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setMeasuredDimension(widthSize, heightSize);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
|
|
|
|
widthSize -= ((WindowInsets) lastInsets).getSystemWindowInsetLeft();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
|
|
|
animatingImageView.measure(MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.AT_MOST));
|
|
|
|
containerView.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("DrawAllocation")
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int x = 0;
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && lastInsets != null) {
|
|
|
|
x += ((WindowInsets) lastInsets).getSystemWindowInsetLeft();
|
|
|
|
}
|
|
|
|
animatingImageView.layout(x, 0, x + animatingImageView.getMeasuredWidth(), animatingImageView.getMeasuredHeight());
|
|
|
|
containerView.layout(x, 0, x + containerView.getMeasuredWidth(), containerView.getMeasuredHeight());
|
2016-10-11 13:57:01 +02:00
|
|
|
wasLayout = true;
|
|
|
|
if (changed) {
|
|
|
|
if (!dontResetZoomOnFirstLayout) {
|
|
|
|
scale = 1;
|
|
|
|
translationX = 0;
|
|
|
|
translationY = 0;
|
|
|
|
updateMinMax(scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkImageView != null) {
|
|
|
|
checkImageView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkImageView.getLayoutParams();
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2017-07-23 14:56:38 +02:00
|
|
|
layoutParams.topMargin = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(40)) / 2 + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
checkImageView.setLayoutParams(layoutParams);
|
2017-07-23 14:56:38 +02:00
|
|
|
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) photosCounterView.getLayoutParams();
|
|
|
|
layoutParams.topMargin = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(40)) / 2 + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
|
|
|
photosCounterView.setLayoutParams(layoutParams);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dontResetZoomOnFirstLayout) {
|
|
|
|
setScaleToFill();
|
|
|
|
dontResetZoomOnFirstLayout = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
attachedToWindow = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
attachedToWindow = false;
|
|
|
|
wasLayout = false;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public boolean dispatchKeyEventPreIme(KeyEvent event) {
|
|
|
|
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
|
2015-05-03 13:48:36 +02:00
|
|
|
closeCaptionEnter(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PhotoViewer.getInstance().closePhoto(true, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.dispatchKeyEventPreIme(event);
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback, int type) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
View view = parentActivity.findViewById(android.R.id.content);
|
|
|
|
if (view instanceof ViewGroup) {
|
|
|
|
try {
|
|
|
|
return ((ViewGroup) view).startActionModeForChild(originalView, callback, type);
|
|
|
|
} catch (Throwable e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.startActionModeForChild(originalView, callback, type);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
};
|
2014-06-12 17:53:20 +02:00
|
|
|
windowView.setBackgroundDrawable(backgroundDrawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
windowView.setClipChildren(true);
|
2014-06-12 17:53:20 +02:00
|
|
|
windowView.setFocusable(false);
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
animatingImageView = new ClippingImageView(activity);
|
|
|
|
animatingImageView.setAnimationValues(animationValues);
|
|
|
|
windowView.addView(animatingImageView, LayoutHelper.createFrame(40, 40));
|
2014-06-12 17:53:20 +02:00
|
|
|
|
|
|
|
containerView = new FrameLayoutDrawer(activity);
|
2014-06-07 01:35:21 +02:00
|
|
|
containerView.setFocusable(false);
|
2015-05-03 13:48:36 +02:00
|
|
|
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
2017-03-31 01:58:05 +02:00
|
|
|
containerView.setFitsSystemWindows(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
@Override
|
|
|
|
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
2017-03-31 01:58:05 +02:00
|
|
|
WindowInsets oldInsets = (WindowInsets) lastInsets;
|
2016-10-11 13:57:01 +02:00
|
|
|
lastInsets = insets;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (oldInsets == null || !oldInsets.toString().equals(insets.toString())) {
|
|
|
|
windowView.requestLayout();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
return insets.consumeSystemWindowInsets();
|
|
|
|
}
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
containerView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
|
|
|
windowLayoutParams = new WindowManager.LayoutParams();
|
|
|
|
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
|
|
|
|
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
|
|
|
|
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
2016-10-11 13:57:01 +02:00
|
|
|
windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
|
2014-08-29 23:06:04 +02:00
|
|
|
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
|
|
|
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
|
|
|
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
|
|
|
} else {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
|
|
|
actionBar = new ActionBar(activity);
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setTitleColor(0xffffffff);
|
|
|
|
actionBar.setSubtitleColor(0xffffffff);
|
2016-04-22 15:49:00 +02:00
|
|
|
actionBar.setBackgroundColor(Theme.ACTION_BAR_PHOTO_VIEWER_COLOR);
|
2016-10-11 13:57:01 +02:00
|
|
|
actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21);
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, false);
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-07 01:35:21 +02:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (needCaptionLayout && (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible())) {
|
2015-05-03 13:48:36 +02:00
|
|
|
closeCaptionEnter(false);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
closePhoto(true, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (id == gallery_menu_save) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (Build.VERSION.SDK_INT >= 23 && parentActivity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
parentActivity.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 4);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-30 00:48:11 +02:00
|
|
|
File f = null;
|
|
|
|
if (currentMessageObject != null) {
|
|
|
|
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
} else if (currentFileLocation != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0 || isEvent);
|
2014-09-30 00:48:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (f != null && f.exists()) {
|
2016-04-22 15:49:00 +02:00
|
|
|
MediaController.saveFile(f.toString(), parentActivity, currentMessageObject != null && currentMessageObject.isVideo() ? 1 : 0, null, null);
|
2014-11-17 23:04:31 +01:00
|
|
|
} else {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2015-03-19 00:09:45 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
2014-11-17 23:04:31 +01:00
|
|
|
builder.setMessage(LocaleController.getString("PleaseDownload", R.string.PleaseDownload));
|
2015-02-26 02:32:51 +01:00
|
|
|
showAlertDialog(builder);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else if (id == gallery_menu_showall) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (currentDialogId != 0) {
|
2015-02-01 19:51:02 +01:00
|
|
|
disableShowCheck = true;
|
2014-06-11 01:05:54 +02:00
|
|
|
Bundle args2 = new Bundle();
|
|
|
|
args2.putLong("dialog_id", currentDialogId);
|
2016-10-11 13:57:01 +02:00
|
|
|
MediaActivity mediaActivity = new MediaActivity(args2);
|
|
|
|
if (parentChatActivity != null) {
|
|
|
|
mediaActivity.setChatInfo(parentChatActivity.getCurrentChatInfo());
|
|
|
|
}
|
|
|
|
closePhoto(false, false);
|
|
|
|
((LaunchActivity) parentActivity).presentFragment(mediaActivity, false, true);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (id == gallery_menu_showinchat) {
|
|
|
|
if (currentMessageObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
int lower_part = (int) currentDialogId;
|
|
|
|
int high_id = (int) (currentDialogId >> 32);
|
|
|
|
if (lower_part != 0) {
|
|
|
|
if (high_id == 1) {
|
|
|
|
args.putInt("chat_id", lower_part);
|
|
|
|
} else {
|
|
|
|
if (lower_part > 0) {
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_part);
|
|
|
|
if (chat != null && chat.migrated_to != null) {
|
|
|
|
args.putInt("migrated_to", lower_part);
|
|
|
|
lower_part = -chat.migrated_to.channel_id;
|
|
|
|
}
|
|
|
|
args.putInt("chat_id", -lower_part);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args.putInt("enc_id", high_id);
|
|
|
|
}
|
|
|
|
args.putInt("message_id", currentMessageObject.getId());
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
((LaunchActivity) parentActivity).presentFragment(new ChatActivity(args), true, true);
|
|
|
|
currentMessageObject = null;
|
|
|
|
closePhoto(false, false);
|
|
|
|
} else if (id == gallery_menu_send) {
|
|
|
|
if (currentMessageObject == null || parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("onlySelect", true);
|
|
|
|
args.putInt("dialogsType", 3);
|
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
|
|
|
final ArrayList<MessageObject> fmessages = new ArrayList<>();
|
|
|
|
fmessages.add(currentMessageObject);
|
|
|
|
fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSelectDialogs(DialogsActivity fragment, ArrayList<Long> dids, CharSequence message, boolean param) {
|
|
|
|
if (dids.size() > 1 || dids.get(0) == UserConfig.getClientUserId() || message != null) {
|
|
|
|
for (int a = 0; a < dids.size(); a++) {
|
|
|
|
long did = dids.get(a);
|
|
|
|
if (message != null) {
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(message.toString(), did, null, null, true, null, null, null);
|
|
|
|
}
|
|
|
|
SendMessagesHelper.getInstance().sendMessage(fmessages, did);
|
|
|
|
}
|
|
|
|
fragment.finishFragment();
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
long did = dids.get(0);
|
|
|
|
int lower_part = (int) did;
|
|
|
|
int high_part = (int) (did >> 32);
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("scrollToTopOnResume", true);
|
|
|
|
if (lower_part != 0) {
|
|
|
|
if (lower_part > 0) {
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
args.putInt("chat_id", -lower_part);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
args.putInt("enc_id", high_part);
|
|
|
|
}
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
|
|
|
ChatActivity chatActivity = new ChatActivity(args);
|
|
|
|
if (((LaunchActivity) parentActivity).presentFragment(chatActivity, true, false)) {
|
|
|
|
chatActivity.showReplyPanel(true, null, fmessages, null, false);
|
|
|
|
} else {
|
|
|
|
fragment.finishFragment();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
|
|
|
((LaunchActivity) parentActivity).presentFragment(fragment, false, true);
|
|
|
|
closePhoto(false, false);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (id == gallery_menu_delete) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
2016-03-06 02:49:31 +01:00
|
|
|
if (currentMessageObject != null && currentMessageObject.isVideo()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeleteVideo", R.string.AreYouSureDeleteVideo));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentMessageObject != null && currentMessageObject.isGif()) {
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSure", R.string.AreYouSure));
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeletePhoto", R.string.AreYouSureDeletePhoto));
|
|
|
|
}
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
final boolean deleteForAll[] = new boolean[1];
|
|
|
|
if (currentMessageObject != null) {
|
|
|
|
int lower_id = (int) currentMessageObject.getDialogId();
|
|
|
|
if (lower_id != 0) {
|
|
|
|
TLRPC.Chat currentChat;
|
|
|
|
TLRPC.User currentUser;
|
|
|
|
if (lower_id > 0) {
|
|
|
|
currentUser = MessagesController.getInstance().getUser(lower_id);
|
|
|
|
currentChat = null;
|
|
|
|
} else {
|
|
|
|
currentUser = null;
|
|
|
|
currentChat = MessagesController.getInstance().getChat(-lower_id);
|
|
|
|
}
|
|
|
|
if (currentUser != null || !ChatObject.isChannel(currentChat)) {
|
|
|
|
boolean hasOutgoing = false;
|
|
|
|
int currentDate = ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
if (currentUser != null && currentUser.id != UserConfig.getClientUserId() || currentChat != null) {
|
|
|
|
if ((currentMessageObject.messageOwner.action == null || currentMessageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && currentMessageObject.isOut() && (currentDate - currentMessageObject.messageOwner.date) <= 2 * 24 * 60 * 60) {
|
|
|
|
FrameLayout frameLayout = new FrameLayout(parentActivity);
|
|
|
|
CheckBoxCell cell = new CheckBoxCell(parentActivity, true);
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
if (currentChat != null) {
|
|
|
|
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
|
|
|
|
} else {
|
|
|
|
cell.setText(LocaleController.formatString("DeleteForUser", R.string.DeleteForUser, UserObject.getFirstName(currentUser)), "", false, false);
|
|
|
|
}
|
|
|
|
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
|
|
|
|
cell.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
CheckBoxCell cell = (CheckBoxCell) v;
|
|
|
|
deleteForAll[0] = !deleteForAll[0];
|
|
|
|
cell.setChecked(deleteForAll[0], true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setView(frameLayout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MessageObject obj = imagesArr.get(currentIndex);
|
|
|
|
if (obj.isSent()) {
|
2016-06-24 12:27:15 +02:00
|
|
|
closePhoto(false, false);
|
2015-02-26 02:32:51 +01:00
|
|
|
ArrayList<Integer> arr = new ArrayList<>();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (slideshowMessageId != 0) {
|
|
|
|
arr.add(slideshowMessageId);
|
|
|
|
} else {
|
|
|
|
arr.add(obj.getId());
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
TLRPC.EncryptedChat encryptedChat = null;
|
|
|
|
if ((int) obj.getDialogId() == 0 && obj.messageOwner.random_id != 0) {
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
random_ids.add(obj.messageOwner.random_id);
|
|
|
|
encryptedChat = MessagesController.getInstance().getEncryptedChat((int) (obj.getDialogId() >> 32));
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
MessagesController.getInstance().deleteMessages(arr, random_ids, encryptedChat, obj.messageOwner.to_id.channel_id, deleteForAll[0]);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
} else if (!avatarsArr.isEmpty()) {
|
|
|
|
if (currentIndex < 0 || currentIndex >= avatarsArr.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.Photo photo = avatarsArr.get(currentIndex);
|
|
|
|
TLRPC.FileLocation currentLocation = imagesArrLocations.get(currentIndex);
|
|
|
|
if (photo instanceof TLRPC.TL_photoEmpty) {
|
|
|
|
photo = null;
|
|
|
|
}
|
|
|
|
boolean current = false;
|
|
|
|
if (currentUserAvatarLocation != null) {
|
|
|
|
if (photo != null) {
|
|
|
|
for (TLRPC.PhotoSize size : photo.sizes) {
|
|
|
|
if (size.location.local_id == currentUserAvatarLocation.local_id && size.location.volume_id == currentUserAvatarLocation.volume_id) {
|
|
|
|
current = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (currentLocation.local_id == currentUserAvatarLocation.local_id && currentLocation.volume_id == currentUserAvatarLocation.volume_id) {
|
|
|
|
current = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (current) {
|
|
|
|
MessagesController.getInstance().deleteUserPhoto(null);
|
|
|
|
closePhoto(false, false);
|
|
|
|
} else if (photo != null) {
|
|
|
|
TLRPC.TL_inputPhoto inputPhoto = new TLRPC.TL_inputPhoto();
|
|
|
|
inputPhoto.id = photo.id;
|
|
|
|
inputPhoto.access_hash = photo.access_hash;
|
|
|
|
MessagesController.getInstance().deleteUserPhoto(inputPhoto);
|
2016-06-24 12:27:15 +02:00
|
|
|
MessagesStorage.getInstance().clearUserPhoto(avatarsDialogId, photo.id);
|
2015-02-26 02:32:51 +01:00
|
|
|
imagesArrLocations.remove(currentIndex);
|
|
|
|
imagesArrLocationsSizes.remove(currentIndex);
|
|
|
|
avatarsArr.remove(currentIndex);
|
|
|
|
if (imagesArrLocations.isEmpty()) {
|
|
|
|
closePhoto(false, false);
|
|
|
|
} else {
|
|
|
|
int index = currentIndex;
|
|
|
|
if (index >= avatarsArr.size()) {
|
|
|
|
index = avatarsArr.size() - 1;
|
|
|
|
}
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(index, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (id == gallery_menu_share) {
|
|
|
|
onSharePressed();
|
|
|
|
} else if (id == gallery_menu_openin) {
|
|
|
|
try {
|
|
|
|
AndroidUtilities.openForView(currentMessageObject, parentActivity);
|
|
|
|
closePhoto(false, false);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else if (id == gallery_menu_masks) {
|
|
|
|
if (parentActivity == null || currentMessageObject == null || currentMessageObject.messageOwner.media == null || currentMessageObject.messageOwner.media.photo == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StickersAlert stickersAlert = new StickersAlert(parentActivity, currentMessageObject.messageOwner.media.photo);
|
|
|
|
stickersAlert.show();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canOpenMenu() {
|
2014-09-25 05:54:35 +02:00
|
|
|
if (currentMessageObject != null) {
|
|
|
|
File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
if (f.exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (currentFileLocation != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
File f = FileLoader.getPathToAttach(currentFileLocation, avatarsDialogId != 0 || isEvent);
|
2014-06-11 01:05:54 +02:00
|
|
|
if (f.exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
return false;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
masksItem = menu.addItem(gallery_menu_masks, R.drawable.ic_masks_msk1);
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
sendItem = menu.addItem(gallery_menu_send, R.drawable.msg_panel_reply);
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
menuItem = menu.addItem(0, R.drawable.ic_ab_other);
|
2017-12-08 18:35:59 +01:00
|
|
|
menuItem.addSubItem(gallery_menu_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.addSubItem(gallery_menu_showall, LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.addSubItem(gallery_menu_showinchat, LocaleController.getString("ShowInChat", R.string.ShowInChat)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.addSubItem(gallery_menu_share, LocaleController.getString("ShareFile", R.string.ShareFile)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.addSubItem(gallery_menu_save, LocaleController.getString("SaveToGallery", R.string.SaveToGallery)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.addSubItem(gallery_menu_delete, LocaleController.getString("Delete", R.string.Delete)).setTextColor(0xfffafafa);
|
|
|
|
menuItem.redrawPopup(0xf9222222);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
bottomLayout = new FrameLayout(actvityContext);
|
2015-02-26 02:32:51 +01:00
|
|
|
bottomLayout.setBackgroundColor(0x7f000000);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView = new GroupedPhotosListView(actvityContext);
|
|
|
|
containerView.addView(groupedPhotosListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 62, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView = new TextView(actvityContext) {
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return bottomTouchEnabled && super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(8), AndroidUtilities.dp(20), AndroidUtilities.dp(8));
|
|
|
|
captionTextView.setLinkTextColor(0xffffffff);
|
|
|
|
captionTextView.setTextColor(0xffffffff);
|
|
|
|
captionTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
captionTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
|
|
|
|
captionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
captionTextView.setOnClickListener(new View.OnClickListener() {
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-23 14:56:38 +02:00
|
|
|
openCaptionEnter();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[0] = new PhotoProgressView(containerView.getContext(), containerView);
|
|
|
|
photoProgressViews[0].setBackgroundState(0, false);
|
|
|
|
photoProgressViews[1] = new PhotoProgressView(containerView.getContext(), containerView);
|
|
|
|
photoProgressViews[1].setBackgroundState(0, false);
|
|
|
|
photoProgressViews[2] = new PhotoProgressView(containerView.getContext(), containerView);
|
|
|
|
photoProgressViews[2].setBackgroundState(0, false);
|
2014-10-28 18:07:44 +01:00
|
|
|
|
2014-10-22 12:11:47 +02:00
|
|
|
shareButton = new ImageView(containerView.getContext());
|
2015-02-26 02:32:51 +01:00
|
|
|
shareButton.setImageResource(R.drawable.share);
|
2014-06-11 01:05:54 +02:00
|
|
|
shareButton.setScaleType(ImageView.ScaleType.CENTER);
|
2017-03-31 01:58:05 +02:00
|
|
|
shareButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
2015-05-03 13:48:36 +02:00
|
|
|
bottomLayout.addView(shareButton, LayoutHelper.createFrame(50, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
|
2014-06-11 01:05:54 +02:00
|
|
|
shareButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2016-06-24 12:27:15 +02:00
|
|
|
onSharePressed();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
nameTextView = new TextView(containerView.getContext());
|
2015-02-26 02:32:51 +01:00
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2014-06-11 01:05:54 +02:00
|
|
|
nameTextView.setSingleLine(true);
|
|
|
|
nameTextView.setMaxLines(1);
|
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
nameTextView.setTextColor(0xffffffff);
|
2015-02-26 02:32:51 +01:00
|
|
|
nameTextView.setGravity(Gravity.LEFT);
|
2015-05-03 13:48:36 +02:00
|
|
|
bottomLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 5, 60, 0));
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
dateTextView = new TextView(containerView.getContext());
|
2015-02-26 02:32:51 +01:00
|
|
|
dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
2014-06-11 01:05:54 +02:00
|
|
|
dateTextView.setSingleLine(true);
|
|
|
|
dateTextView.setMaxLines(1);
|
|
|
|
dateTextView.setEllipsize(TextUtils.TruncateAt.END);
|
2015-02-26 02:32:51 +01:00
|
|
|
dateTextView.setTextColor(0xffffffff);
|
|
|
|
dateTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
dateTextView.setGravity(Gravity.LEFT);
|
2015-05-03 13:48:36 +02:00
|
|
|
bottomLayout.addView(dateTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 16, 25, 50, 0));
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerSeekbar = new SeekBar(containerView.getContext());
|
|
|
|
videoPlayerSeekbar.setColors(0x66ffffff, 0xffffffff, 0xffffffff);
|
|
|
|
videoPlayerSeekbar.setDelegate(new SeekBar.SeekBarDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onSeekBarDrag(float progress) {
|
|
|
|
if (videoPlayer != null) {
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
progress = videoTimelineView.getLeftProgress() + (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * progress;
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayer.seekTo((int) (progress * videoPlayer.getDuration()));
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
});
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerControlFrameLayout = new FrameLayout(containerView.getContext()) {
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
int x = (int) event.getX();
|
|
|
|
int y = (int) event.getY();
|
|
|
|
if (videoPlayerSeekbar.onTouch(event.getAction(), event.getX() - AndroidUtilities.dp(48), event.getY())) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
invalidate();
|
|
|
|
return true;
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
long duration;
|
|
|
|
if (videoPlayer != null) {
|
|
|
|
duration = videoPlayer.getDuration();
|
|
|
|
if (duration == C.TIME_UNSET) {
|
2016-06-24 12:27:15 +02:00
|
|
|
duration = 0;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
} else {
|
|
|
|
duration = 0;
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
duration /= 1000;
|
|
|
|
int size = (int) Math.ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d", duration / 60, duration % 60, duration / 60, duration % 60)));
|
|
|
|
videoPlayerSeekbar.setSize(getMeasuredWidth() - AndroidUtilities.dp(48 + 16) - size, getMeasuredHeight());
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
float progress = 0;
|
|
|
|
if (videoPlayer != null) {
|
|
|
|
progress = videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration();
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
progress -= videoTimelineView.getLeftProgress();
|
|
|
|
if (progress < 0) {
|
|
|
|
progress = 0;
|
|
|
|
}
|
|
|
|
progress /= (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress());
|
|
|
|
if (progress > 1) {
|
|
|
|
progress = 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerSeekbar.setProgress(progress);
|
|
|
|
videoTimelineView.setProgress(progress);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(AndroidUtilities.dp(48), 0);
|
|
|
|
videoPlayerSeekbar.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
videoPlayerControlFrameLayout.setWillNotDraw(false);
|
|
|
|
bottomLayout.addView(videoPlayerControlFrameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayButton = new ImageView(containerView.getContext());
|
|
|
|
videoPlayButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
videoPlayerControlFrameLayout.addView(videoPlayButton, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
|
|
|
|
videoPlayButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (videoPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isPlaying) {
|
|
|
|
videoPlayer.pause();
|
|
|
|
} else {
|
|
|
|
if (isCurrentVideo) {
|
|
|
|
if (Math.abs(videoTimelineView.getProgress() - 1.0f) < 0.01f || videoPlayer.getCurrentPosition() == videoPlayer.getDuration()) {
|
|
|
|
videoPlayer.seekTo(0);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
|
|
|
if (Math.abs(videoPlayerSeekbar.getProgress() - 1.0f) < 0.01f || videoPlayer.getCurrentPosition() == videoPlayer.getDuration()) {
|
|
|
|
videoPlayer.seekTo(0);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayer.play();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerTime = new TextView(containerView.getContext());
|
|
|
|
videoPlayerTime.setTextColor(0xffffffff);
|
|
|
|
videoPlayerTime.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
videoPlayerTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
|
|
|
|
videoPlayerControlFrameLayout.addView(videoPlayerTime, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 0, 8, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
progressView = new RadialProgressView(parentActivity);
|
|
|
|
progressView.setProgressColor(0xffffffff);
|
|
|
|
progressView.setBackgroundResource(R.drawable.circle_big);
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
containerView.addView(progressView, LayoutHelper.createFrame(54, 54, Gravity.CENTER));
|
|
|
|
|
|
|
|
qualityPicker = new PickerBottomLayoutViewer(parentActivity);
|
|
|
|
qualityPicker.setBackgroundColor(0x7f000000);
|
|
|
|
qualityPicker.updateSelectedCount(0, false);
|
|
|
|
qualityPicker.setTranslationY(AndroidUtilities.dp(120));
|
|
|
|
qualityPicker.doneButton.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
|
|
|
|
containerView.addView(qualityPicker, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM | Gravity.LEFT));
|
|
|
|
qualityPicker.cancelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
selectedCompression = previousCompression;
|
|
|
|
didChangedCompressionLevel(false);
|
|
|
|
showQualityView(false);
|
|
|
|
requestVideoPreview(2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
qualityPicker.doneButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
showQualityView(false);
|
|
|
|
requestVideoPreview(2);
|
|
|
|
}
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
qualityChooseView = new QualityChooseView(parentActivity);
|
|
|
|
qualityChooseView.setTranslationY(AndroidUtilities.dp(120));
|
|
|
|
qualityChooseView.setVisibility(View.INVISIBLE);
|
|
|
|
qualityChooseView.setBackgroundColor(0x7f000000);
|
|
|
|
containerView.addView(qualityChooseView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 70, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 48));
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerView = new FrameLayout(actvityContext) {
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
return bottomTouchEnabled && super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
return bottomTouchEnabled && super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return bottomTouchEnabled && super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
2015-02-01 19:51:02 +01:00
|
|
|
pickerView.setBackgroundColor(0x7f000000);
|
2017-07-23 14:56:38 +02:00
|
|
|
containerView.addView(pickerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));
|
|
|
|
|
|
|
|
videoTimelineView = new VideoTimelinePlayView(parentActivity);
|
|
|
|
videoTimelineView.setDelegate(new VideoTimelinePlayView.VideoTimelineViewDelegate() {
|
2014-06-12 03:13:15 +02:00
|
|
|
@Override
|
2017-07-23 14:56:38 +02:00
|
|
|
public void onLeftProgressChanged(float progress) {
|
|
|
|
if (videoPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (videoPlayer.isPlaying()) {
|
|
|
|
videoPlayer.pause();
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
videoPlayer.seekTo((int) (videoDuration * progress));
|
|
|
|
videoPlayerSeekbar.setProgress(0);
|
|
|
|
videoTimelineView.setProgress(0);
|
|
|
|
updateVideoInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRightProgressChanged(float progress) {
|
|
|
|
if (videoPlayer == null) {
|
|
|
|
return;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (videoPlayer.isPlaying()) {
|
|
|
|
videoPlayer.pause();
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
videoPlayer.seekTo((int) (videoDuration * progress));
|
|
|
|
videoPlayerSeekbar.setProgress(0);
|
|
|
|
videoTimelineView.setProgress(0);
|
|
|
|
updateVideoInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPlayProgressChanged(float progress) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (videoPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayer.seekTo((int) (videoDuration * progress));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didStartDragging() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didStopDragging() {
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
});
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerView.addView(videoTimelineView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 58, Gravity.LEFT | Gravity.TOP, 0, 8, 0, 88));
|
|
|
|
|
|
|
|
pickerViewSendButton = new ImageView(parentActivity);
|
|
|
|
pickerViewSendButton.setScaleType(ImageView.ScaleType.CENTER);
|
2017-12-08 18:35:59 +01:00
|
|
|
Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), 0xff66bffa, 0xff66bffa);
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerViewSendButton.setBackgroundDrawable(drawable);
|
|
|
|
pickerViewSendButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
pickerViewSendButton.setPadding(AndroidUtilities.dp(4), 0, 0, 0);
|
|
|
|
pickerViewSendButton.setImageResource(R.drawable.ic_send);
|
2017-12-08 18:35:59 +01:00
|
|
|
pickerView.addView(pickerViewSendButton, LayoutHelper.createFrame(56, 56, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 14, 14));
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerViewSendButton.setOnClickListener(new View.OnClickListener() {
|
2014-06-12 03:13:15 +02:00
|
|
|
@Override
|
2017-07-23 14:56:38 +02:00
|
|
|
public void onClick(View v) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (placeProvider != null && !doneButtonPressed) {
|
2017-07-08 18:32:04 +02:00
|
|
|
VideoEditedInfo videoEditedInfo = getCurrentVideoEditedInfo();
|
2017-03-31 01:58:05 +02:00
|
|
|
placeProvider.sendButtonPressed(currentIndex, videoEditedInfo);
|
|
|
|
doneButtonPressed = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
closePhoto(false, false);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
itemsLayout = new LinearLayout(parentActivity);
|
2016-10-11 13:57:01 +02:00
|
|
|
itemsLayout.setOrientation(LinearLayout.HORIZONTAL);
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerView.addView(itemsLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 48, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0, 34, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
cropItem = new ImageView(parentActivity);
|
|
|
|
cropItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
cropItem.setImageResource(R.drawable.photo_crop);
|
|
|
|
cropItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
|
|
|
itemsLayout.addView(cropItem, LayoutHelper.createLinear(70, 48));
|
|
|
|
cropItem.setOnClickListener(new View.OnClickListener() {
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-23 14:56:38 +02:00
|
|
|
switchToEditMode(1);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
2017-07-23 14:56:38 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
paintItem = new ImageView(parentActivity);
|
|
|
|
paintItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
paintItem.setImageResource(R.drawable.photo_paint);
|
2017-03-31 01:58:05 +02:00
|
|
|
paintItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
2017-07-23 14:56:38 +02:00
|
|
|
itemsLayout.addView(paintItem, LayoutHelper.createLinear(70, 48));
|
2016-10-11 13:57:01 +02:00
|
|
|
paintItem.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
switchToEditMode(3);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
tuneItem = new ImageView(parentActivity);
|
|
|
|
tuneItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
tuneItem.setImageResource(R.drawable.photo_tools);
|
|
|
|
tuneItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
|
|
|
itemsLayout.addView(tuneItem, LayoutHelper.createLinear(70, 48));
|
|
|
|
tuneItem.setOnClickListener(new View.OnClickListener() {
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-23 14:56:38 +02:00
|
|
|
switchToEditMode(2);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
compressItem = new ImageView(parentActivity);
|
2017-12-08 18:35:59 +01:00
|
|
|
compressItem.setTag(1);
|
2017-03-31 01:58:05 +02:00
|
|
|
compressItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
compressItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
selectedCompression = preferences.getInt("compress_video2", 1);
|
|
|
|
if (selectedCompression <= 0) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_240);
|
|
|
|
} else if (selectedCompression == 1) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_360);
|
|
|
|
} else if (selectedCompression == 2) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_480);
|
|
|
|
} else if (selectedCompression == 3) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_720);
|
|
|
|
} else if (selectedCompression == 4) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_1080);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
itemsLayout.addView(compressItem, LayoutHelper.createLinear(70, 48));
|
2017-03-31 01:58:05 +02:00
|
|
|
compressItem.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
showQualityView(true);
|
|
|
|
requestVideoPreview(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
muteItem = new ImageView(parentActivity);
|
|
|
|
muteItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
muteItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
2017-07-23 14:56:38 +02:00
|
|
|
itemsLayout.addView(muteItem, LayoutHelper.createLinear(70, 48));
|
2017-03-31 01:58:05 +02:00
|
|
|
muteItem.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
muteVideo = !muteVideo;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (muteVideo && !checkImageView.isChecked()) {
|
|
|
|
checkImageView.callOnClick();
|
|
|
|
} else {
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
((MediaController.PhotoEntry) object).editedInfo = getCurrentVideoEditedInfo();
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
updateMuteButton();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
timeItem = new ImageView(parentActivity);
|
|
|
|
timeItem.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
timeItem.setImageResource(R.drawable.photo_timer);
|
|
|
|
timeItem.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
|
|
|
|
itemsLayout.addView(timeItem, LayoutHelper.createLinear(70, 48));
|
|
|
|
timeItem.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity);
|
|
|
|
builder.setUseHardwareLayer(false);
|
|
|
|
LinearLayout linearLayout = new LinearLayout(parentActivity);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
builder.setCustomView(linearLayout);
|
|
|
|
|
|
|
|
TextView titleView = new TextView(parentActivity);
|
|
|
|
titleView.setLines(1);
|
|
|
|
titleView.setSingleLine(true);
|
|
|
|
titleView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
|
|
|
|
titleView.setTextColor(0xffffffff);
|
|
|
|
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
|
|
|
titleView.setPadding(AndroidUtilities.dp(21), AndroidUtilities.dp(8), AndroidUtilities.dp(21), AndroidUtilities.dp(4));
|
|
|
|
titleView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
linearLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
titleView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
titleView = new TextView(parentActivity);
|
|
|
|
titleView.setText(isCurrentVideo ? LocaleController.getString("MessageLifetimeVideo", R.string.MessageLifetimeVideo) : LocaleController.getString("MessageLifetimePhoto", R.string.MessageLifetimePhoto));
|
|
|
|
titleView.setTextColor(0xff808080);
|
|
|
|
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
|
|
|
titleView.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), AndroidUtilities.dp(8));
|
|
|
|
titleView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
linearLayout.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
titleView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
final BottomSheet bottomSheet = builder.create();
|
|
|
|
final NumberPicker numberPicker = new NumberPicker(parentActivity);
|
|
|
|
numberPicker.setMinValue(0);
|
|
|
|
numberPicker.setMaxValue(28);
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
int currentTTL;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
currentTTL = ((MediaController.PhotoEntry) object).ttl;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
currentTTL = ((MediaController.SearchImage) object).ttl;
|
|
|
|
} else {
|
|
|
|
currentTTL = 0;
|
|
|
|
}
|
|
|
|
if (currentTTL == 0) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
numberPicker.setValue(preferences.getInt("self_destruct", 7));
|
|
|
|
} else {
|
|
|
|
if (currentTTL >= 0 && currentTTL < 21) {
|
|
|
|
numberPicker.setValue(currentTTL);
|
|
|
|
} else {
|
|
|
|
numberPicker.setValue(21 + currentTTL / 5 - 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
numberPicker.setTextColor(0xffffffff);
|
|
|
|
numberPicker.setSelectorColor(0xff4d4d4d);
|
|
|
|
numberPicker.setFormatter(new NumberPicker.Formatter() {
|
|
|
|
@Override
|
|
|
|
public String format(int value) {
|
|
|
|
if (value == 0) {
|
|
|
|
return LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever);
|
|
|
|
} else if (value >= 1 && value < 21) {
|
|
|
|
return LocaleController.formatTTLString(value);
|
|
|
|
} else {
|
|
|
|
return LocaleController.formatTTLString((value - 16) * 5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
linearLayout.addView(numberPicker, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
|
|
|
|
FrameLayout buttonsLayout = new FrameLayout(parentActivity) {
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
int count = getChildCount();
|
|
|
|
View positiveButton = null;
|
|
|
|
int width = right - left;
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = getChildAt(a);
|
|
|
|
if ((Integer) child.getTag() == Dialog.BUTTON_POSITIVE) {
|
|
|
|
positiveButton = child;
|
|
|
|
child.layout(width - getPaddingRight() - child.getMeasuredWidth(), getPaddingTop(), width - getPaddingRight() + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
|
|
|
|
} else if ((Integer) child.getTag() == Dialog.BUTTON_NEGATIVE) {
|
|
|
|
int x = width - getPaddingRight() - child.getMeasuredWidth();
|
|
|
|
if (positiveButton != null) {
|
|
|
|
x -= positiveButton.getMeasuredWidth() + AndroidUtilities.dp(8);
|
|
|
|
}
|
|
|
|
child.layout(x, getPaddingTop(), x + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
|
|
|
|
} else {
|
|
|
|
child.layout(getPaddingLeft(), getPaddingTop(), getPaddingLeft() + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
buttonsLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
|
|
|
|
linearLayout.addView(buttonsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52));
|
|
|
|
|
|
|
|
TextView textView = new TextView(parentActivity);
|
|
|
|
textView.setMinWidth(AndroidUtilities.dp(64));
|
|
|
|
textView.setTag(Dialog.BUTTON_POSITIVE);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
textView.setTextColor(0xff49bcf2);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textView.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
|
|
|
|
textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable());
|
|
|
|
textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
|
|
|
|
buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
|
|
|
|
textView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
int value = numberPicker.getValue();
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("self_destruct", value);
|
|
|
|
editor.commit();
|
|
|
|
bottomSheet.dismiss();
|
|
|
|
int seconds;
|
|
|
|
if (value >= 0 && value < 21) {
|
|
|
|
seconds = value;
|
|
|
|
} else {
|
|
|
|
seconds = (value - 16) * 5;
|
|
|
|
}
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
((MediaController.PhotoEntry) object).ttl = seconds;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
((MediaController.SearchImage) object).ttl = seconds;
|
|
|
|
}
|
|
|
|
timeItem.setColorFilter(seconds != 0 ? new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
if (!checkImageView.isChecked()) {
|
|
|
|
checkImageView.callOnClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
textView = new TextView(parentActivity);
|
|
|
|
textView.setMinWidth(AndroidUtilities.dp(64));
|
|
|
|
textView.setTag(Dialog.BUTTON_NEGATIVE);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
textView.setTextColor(0xff49bcf2);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
textView.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
|
|
|
|
textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable());
|
|
|
|
textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
|
|
|
|
buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
|
|
|
|
textView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
bottomSheet.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
bottomSheet.show();
|
|
|
|
bottomSheet.setBackgroundColor(0xff000000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
editorDoneLayout = new PickerBottomLayoutViewer(actvityContext);
|
2015-02-26 02:32:51 +01:00
|
|
|
editorDoneLayout.setBackgroundColor(0x7f000000);
|
|
|
|
editorDoneLayout.updateSelectedCount(0, false);
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(editorDoneLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
|
2015-02-26 02:32:51 +01:00
|
|
|
editorDoneLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
editorDoneLayout.doneButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (currentEditMode == 1 && !photoCropView.isReady()) {
|
|
|
|
return;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
applyCurrentEditMode();
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
2014-06-12 21:55:13 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
resetButton = new TextView(actvityContext);
|
|
|
|
resetButton.setVisibility(View.GONE);
|
|
|
|
resetButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
resetButton.setTextColor(0xffffffff);
|
|
|
|
resetButton.setGravity(Gravity.CENTER);
|
|
|
|
resetButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, 0));
|
|
|
|
resetButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
|
|
|
|
resetButton.setText(LocaleController.getString("Reset", R.string.CropReset).toUpperCase());
|
|
|
|
resetButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
editorDoneLayout.addView(resetButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.CENTER));
|
|
|
|
resetButton.setOnClickListener(new View.OnClickListener() {
|
2016-03-06 02:49:31 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoCropView.reset();
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
gestureDetector = new GestureDetector(containerView.getContext(), this);
|
|
|
|
gestureDetector.setOnDoubleTapListener(this);
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
ImageReceiver.ImageReceiverDelegate imageReceiverDelegate = new ImageReceiver.ImageReceiverDelegate() {
|
|
|
|
@Override
|
|
|
|
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (imageReceiver == centerImage && set && !thumb && currentEditMode == 1 && photoCropView != null) {
|
|
|
|
Bitmap bitmap = imageReceiver.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
photoCropView.setBitmap(bitmap, imageReceiver.getOrientation(), sendPhotoType != 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (imageReceiver == centerImage && set && placeProvider != null && placeProvider.scaleToFill() && !ignoreDidSetImage) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (!wasLayout) {
|
|
|
|
dontResetZoomOnFirstLayout = true;
|
|
|
|
} else {
|
|
|
|
setScaleToFill();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
centerImage.setParentView(containerView);
|
2015-05-03 13:48:36 +02:00
|
|
|
centerImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 23:27:27 +02:00
|
|
|
centerImage.setInvalidateAll(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
centerImage.setDelegate(imageReceiverDelegate);
|
2014-08-22 16:24:33 +02:00
|
|
|
leftImage.setParentView(containerView);
|
2015-05-03 13:48:36 +02:00
|
|
|
leftImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 23:27:27 +02:00
|
|
|
leftImage.setInvalidateAll(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
leftImage.setDelegate(imageReceiverDelegate);
|
2014-08-22 16:24:33 +02:00
|
|
|
rightImage.setParentView(containerView);
|
2015-05-03 13:48:36 +02:00
|
|
|
rightImage.setCrossfadeAlpha((byte) 2);
|
2015-05-21 23:27:27 +02:00
|
|
|
rightImage.setInvalidateAll(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
rightImage.setDelegate(imageReceiverDelegate);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
checkImageView = new CheckBox(containerView.getContext(), R.drawable.selectphoto_large) {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return bottomTouchEnabled && super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
2015-01-02 23:15:07 +01:00
|
|
|
checkImageView.setDrawBackground(true);
|
2017-07-23 14:56:38 +02:00
|
|
|
checkImageView.setHasBorder(true);
|
|
|
|
checkImageView.setSize(40);
|
2015-01-02 23:15:07 +01:00
|
|
|
checkImageView.setCheckOffset(AndroidUtilities.dp(1));
|
2017-12-08 18:35:59 +01:00
|
|
|
checkImageView.setColor(0xff66bffa, 0xffffffff);
|
2014-06-12 03:13:15 +02:00
|
|
|
checkImageView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
containerView.addView(checkImageView, LayoutHelper.createFrame(40, 40, Gravity.RIGHT | Gravity.TOP, 0, rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 10, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
((FrameLayout.LayoutParams) checkImageView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
checkImageView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-12-08 18:35:59 +01:00
|
|
|
setPhotoChecked();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView = new CounterView(parentActivity);
|
|
|
|
containerView.addView(photosCounterView, LayoutHelper.createFrame(40, 40, Gravity.RIGHT | Gravity.TOP, 0, rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90 ? 58 : 68, 66, 0));
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
((FrameLayout.LayoutParams) photosCounterView.getLayoutParams()).topMargin += AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
photosCounterView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (placeProvider == null || placeProvider.getSelectedPhotosOrder() == null || placeProvider.getSelectedPhotosOrder().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
togglePhotosListView(!isPhotosListViewVisible, true);
|
|
|
|
}
|
|
|
|
});
|
2017-07-23 14:56:38 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosListView = new RecyclerListView(parentActivity);
|
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
selectedPhotosListView.setAlpha(0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
|
|
|
|
selectedPhotosListView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
|
|
|
@Override
|
|
|
|
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
|
|
|
int position = parent.getChildAdapterPosition(view);
|
|
|
|
if (view instanceof PhotoPickerPhotoCell && position == 0) {
|
|
|
|
outRect.left = AndroidUtilities.dp(3);
|
|
|
|
} else {
|
|
|
|
outRect.left = 0;
|
|
|
|
}
|
|
|
|
outRect.right = AndroidUtilities.dp(3);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
selectedPhotosListView.setBackgroundColor(0x7f000000);
|
|
|
|
selectedPhotosListView.setPadding(0, AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3));
|
|
|
|
selectedPhotosListView.setLayoutManager(new LinearLayoutManager(parentActivity, LinearLayoutManager.HORIZONTAL, false));
|
|
|
|
selectedPhotosListView.setAdapter(selectedPhotosAdapter = new ListAdapter(parentActivity));
|
|
|
|
containerView.addView(selectedPhotosListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 88, Gravity.LEFT | Gravity.TOP));
|
|
|
|
selectedPhotosListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
if (position == 0 && placeProvider.allowGroupPhotos()) {
|
|
|
|
boolean enabled = MediaController.getInstance().isGroupPhotosEnabled();
|
|
|
|
MediaController.getInstance().toggleGroupPhotosEnabled();
|
|
|
|
placeProvider.toggleGroupPhotosEnabled();
|
|
|
|
ImageView imageView = (ImageView) view;
|
|
|
|
imageView.setColorFilter(!enabled ? new PorterDuffColorFilter(0xff66bffa, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
showHint(false, !enabled);
|
|
|
|
} else {
|
|
|
|
int idx = imagesArrLocals.indexOf(view.getTag());
|
|
|
|
if (idx >= 0) {
|
|
|
|
currentIndex = -1;
|
|
|
|
setImageIndex(idx, false);
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
captionEditText = new PhotoViewerCaptionEnterView(actvityContext, containerView, windowView) {
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
try {
|
|
|
|
return !bottomTouchEnabled && super.dispatchTouchEvent(ev);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
try {
|
|
|
|
return !bottomTouchEnabled && super.onInterceptTouchEvent(ev);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return !bottomTouchEnabled && super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
2015-05-03 13:48:36 +02:00
|
|
|
captionEditText.setDelegate(new PhotoViewerCaptionEnterView.PhotoViewerCaptionEnterViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onCaptionEnter() {
|
|
|
|
closeCaptionEnter(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
public void onTextChanged(CharSequence text) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (mentionsAdapter != null && captionEditText != null && parentChatActivity != null && text != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
mentionsAdapter.searchUsernameOrHashtag(text.toString(), captionEditText.getCursorPosition(), parentChatActivity.messages, false);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onWindowSizeChanged(int size) {
|
2016-01-11 18:19:48 +01:00
|
|
|
int height = AndroidUtilities.dp(36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0));
|
2015-07-22 20:56:37 +02:00
|
|
|
if (size - ActionBar.getCurrentActionBarHeight() * 2 < height) {
|
2015-05-03 13:48:36 +02:00
|
|
|
allowMentions = false;
|
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.VISIBLE) {
|
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allowMentions = true;
|
|
|
|
if (mentionListView != null && mentionListView.getVisibility() == View.INVISIBLE) {
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
containerView.addView(captionEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT));
|
|
|
|
|
|
|
|
mentionListView = new RecyclerListView(actvityContext) {
|
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
return !bottomTouchEnabled && super.dispatchTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
return !bottomTouchEnabled && super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return !bottomTouchEnabled && super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
2016-06-24 12:27:15 +02:00
|
|
|
mentionListView.setTag(5);
|
2016-04-22 15:49:00 +02:00
|
|
|
mentionLayoutManager = new LinearLayoutManager(actvityContext) {
|
2016-01-11 18:19:48 +01:00
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mentionLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
|
|
|
|
mentionListView.setLayoutManager(mentionLayoutManager);
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionListView.setBackgroundColor(0x7f000000);
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListView.setClipToPadding(true);
|
2017-03-31 01:58:05 +02:00
|
|
|
mentionListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(mentionListView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 110, Gravity.LEFT | Gravity.BOTTOM));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
mentionListView.setAdapter(mentionsAdapter = new MentionsAdapter(actvityContext, true, 0, new MentionsAdapter.MentionsAdapterDelegate() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void needChangePanelVisibility(boolean show) {
|
|
|
|
if (show) {
|
2015-06-29 19:12:11 +02:00
|
|
|
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) mentionListView.getLayoutParams();
|
2016-01-11 18:19:48 +01:00
|
|
|
int height = 36 * Math.min(3, mentionsAdapter.getItemCount()) + (mentionsAdapter.getItemCount() > 3 ? 18 : 0);
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams3.height = AndroidUtilities.dp(height);
|
|
|
|
layoutParams3.topMargin = -AndroidUtilities.dp(height);
|
|
|
|
mentionListView.setLayoutParams(layoutParams3);
|
|
|
|
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.VISIBLE) {
|
2016-06-24 12:27:15 +02:00
|
|
|
mentionListView.setAlpha(1.0f);
|
2015-05-03 13:48:36 +02:00
|
|
|
return;
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
mentionLayoutManager.scrollToPositionWithOffset(0, 10000);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (allowMentions) {
|
|
|
|
mentionListView.setVisibility(View.VISIBLE);
|
2016-06-24 12:27:15 +02:00
|
|
|
mentionListAnimation = new AnimatorSet();
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionListAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f, 1.0f)
|
2015-05-03 13:48:36 +02:00
|
|
|
);
|
2017-03-31 01:58:05 +02:00
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
2016-06-24 12:27:15 +02:00
|
|
|
mentionListView.setAlpha(1.0f);
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionListView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mentionListAnimation != null) {
|
|
|
|
mentionListAnimation.cancel();
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mentionListView.getVisibility() == View.GONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (allowMentions) {
|
2016-06-24 12:27:15 +02:00
|
|
|
mentionListAnimation = new AnimatorSet();
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionListAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(mentionListView, "alpha", 0.0f)
|
2015-05-03 13:48:36 +02:00
|
|
|
);
|
2017-03-31 01:58:05 +02:00
|
|
|
mentionListAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (mentionListAnimation != null && mentionListAnimation.equals(animation)) {
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
mentionListAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mentionListAnimation.setDuration(200);
|
|
|
|
mentionListAnimation.start();
|
|
|
|
} else {
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContextSearch(boolean searching) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContextClick(TLRPC.BotInlineResult result) {
|
|
|
|
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}));
|
2016-05-25 23:49:47 +02:00
|
|
|
mentionsAdapter.setAllowNewMentions(false);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
mentionListView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2016-01-11 18:19:48 +01:00
|
|
|
public void onItemClick(View view, int position) {
|
2015-05-03 13:48:36 +02:00
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
int start = mentionsAdapter.getResultStartPosition();
|
|
|
|
int len = mentionsAdapter.getResultLength();
|
|
|
|
if (object instanceof TLRPC.User) {
|
|
|
|
TLRPC.User user = (TLRPC.User) object;
|
|
|
|
if (user != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
captionEditText.replaceWithText(start, len, "@" + user.username + " ", false);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
} else if (object instanceof String) {
|
2017-12-08 18:35:59 +01:00
|
|
|
captionEditText.replaceWithText(start, len, object + " ", false);
|
|
|
|
} else if (object instanceof EmojiSuggestion) {
|
|
|
|
String code = ((EmojiSuggestion) object).emoji;
|
|
|
|
captionEditText.addEmojiToRecent(code);
|
|
|
|
captionEditText.replaceWithText(start, len, code, true);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
mentionListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2016-01-11 18:19:48 +01:00
|
|
|
public boolean onItemClick(View view, int position) {
|
2015-05-03 13:48:36 +02:00
|
|
|
Object object = mentionsAdapter.getItem(position);
|
|
|
|
if (object instanceof String) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
mentionsAdapter.clearRecentHashtags();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void openCaptionEnter() {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (imageMoveAnimation != null || changeModeAnimation != null || currentEditMode != 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
selectedPhotosListView.setEnabled(false);
|
|
|
|
selectedPhotosListView.setAlpha(0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
|
|
|
|
photosCounterView.setRotationX(0.0f);
|
|
|
|
isPhotosListViewVisible = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
captionEditText.setTag(1);
|
2016-10-11 13:57:01 +02:00
|
|
|
captionEditText.openKeyboard();
|
|
|
|
lastTitle = actionBar.getTitle();
|
2017-07-23 14:56:38 +02:00
|
|
|
if (isCurrentVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setTitle(muteVideo ? LocaleController.getString("GifCaption", R.string.GifCaption) : LocaleController.getString("VideoCaption", R.string.VideoCaption));
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("PhotoCaption", R.string.PhotoCaption));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private VideoEditedInfo getCurrentVideoEditedInfo() {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (!isCurrentVideo || currentPlayingVideoFile == null || compressionsCount == 0) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
|
|
|
|
videoEditedInfo.startTime = startTime;
|
|
|
|
videoEditedInfo.endTime = endTime;
|
|
|
|
videoEditedInfo.rotationValue = rotationValue;
|
|
|
|
videoEditedInfo.originalWidth = originalWidth;
|
|
|
|
videoEditedInfo.originalHeight = originalHeight;
|
|
|
|
videoEditedInfo.bitrate = bitrate;
|
|
|
|
videoEditedInfo.originalPath = currentPlayingVideoFile.getAbsolutePath();
|
|
|
|
videoEditedInfo.estimatedSize = estimatedSize;
|
|
|
|
videoEditedInfo.estimatedDuration = estimatedDuration;
|
|
|
|
|
|
|
|
if (!muteVideo && (compressItem.getTag() == null || selectedCompression == compressionsCount - 1)) {
|
|
|
|
videoEditedInfo.resultWidth = originalWidth;
|
|
|
|
videoEditedInfo.resultHeight = originalHeight;
|
|
|
|
videoEditedInfo.bitrate = muteVideo ? -1 : originalBitrate;
|
|
|
|
videoEditedInfo.muted = muteVideo;
|
|
|
|
} else {
|
|
|
|
if (muteVideo) {
|
|
|
|
selectedCompression = 1;
|
|
|
|
updateWidthHeightBitrateForCompression();
|
|
|
|
}
|
|
|
|
videoEditedInfo.resultWidth = resultWidth;
|
|
|
|
videoEditedInfo.resultHeight = resultHeight;
|
|
|
|
videoEditedInfo.bitrate = muteVideo ? -1 : bitrate;
|
|
|
|
videoEditedInfo.muted = muteVideo;
|
|
|
|
}
|
|
|
|
return videoEditedInfo;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private void closeCaptionEnter(boolean apply) {
|
|
|
|
if (currentIndex < 0 || currentIndex >= imagesArrLocals.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (apply) {
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
((MediaController.PhotoEntry) object).caption = captionEditText.getFieldCharSequence();
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
((MediaController.SearchImage) object).caption = captionEditText.getFieldCharSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (captionEditText.getFieldCharSequence().length() != 0 && !placeProvider.isPhotoChecked(currentIndex)) {
|
2017-12-08 18:35:59 +01:00
|
|
|
setPhotoChecked();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
captionEditText.setTag(null);
|
|
|
|
if (lastTitle != null) {
|
|
|
|
actionBar.setTitle(lastTitle);
|
|
|
|
lastTitle = null;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (isCurrentVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setSubtitle(muteVideo ? null : currentSubtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCaptionTextForCurrentPhoto(object);
|
|
|
|
setCurrentCaption(captionEditText.getFieldCharSequence());
|
|
|
|
if (captionEditText.isPopupShowing()) {
|
|
|
|
captionEditText.hidePopup();
|
|
|
|
}
|
|
|
|
captionEditText.closeKeyboard();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private void updateVideoPlayerTime() {
|
|
|
|
String newText;
|
|
|
|
if (videoPlayer == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
newText = String.format("%02d:%02d / %02d:%02d", 0, 0, 0, 0);
|
2016-06-24 12:27:15 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
long current = videoPlayer.getCurrentPosition();
|
2016-10-11 13:57:01 +02:00
|
|
|
long total = videoPlayer.getDuration();
|
2017-03-31 01:58:05 +02:00
|
|
|
if (total != C.TIME_UNSET && current != C.TIME_UNSET) {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
2017-03-31 01:58:05 +02:00
|
|
|
total *= (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress());
|
|
|
|
current -= videoTimelineView.getLeftProgress() * total;
|
|
|
|
if (current > total) {
|
|
|
|
current = total;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
current /= 1000;
|
|
|
|
total /= 1000;
|
2016-06-24 12:27:15 +02:00
|
|
|
newText = String.format("%02d:%02d / %02d:%02d", current / 60, current % 60, total / 60, total % 60);
|
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
newText = String.format("%02d:%02d / %02d:%02d", 0, 0, 0, 0);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!TextUtils.equals(videoPlayerTime.getText(), newText)) {
|
|
|
|
videoPlayerTime.setText(newText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private void preparePlayer(File file, boolean playWhenReady, boolean preview) {
|
|
|
|
if (!preview) {
|
|
|
|
currentPlayingVideoFile = file;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (parentActivity == null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
inPreview = preview;
|
2016-06-24 12:27:15 +02:00
|
|
|
releasePlayer();
|
|
|
|
if (videoTextureView == null) {
|
|
|
|
aspectRatioFrameLayout = new AspectRatioFrameLayout(parentActivity);
|
|
|
|
aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
|
|
|
|
containerView.addView(aspectRatioFrameLayout, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
|
|
|
|
|
|
|
|
videoTextureView = new TextureView(parentActivity);
|
|
|
|
videoTextureView.setOpaque(false);
|
|
|
|
aspectRatioFrameLayout.addView(videoTextureView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
|
|
|
|
}
|
|
|
|
textureUploaded = false;
|
|
|
|
videoCrossfadeStarted = false;
|
|
|
|
videoTextureView.setAlpha(videoCrossfadeAlpha = 0.0f);
|
2016-10-11 13:57:01 +02:00
|
|
|
videoPlayButton.setImageResource(R.drawable.inline_video_play);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (videoPlayer == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
videoPlayer = new VideoPlayer();
|
|
|
|
videoPlayer.setTextureView(videoTextureView);
|
|
|
|
videoPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
|
2016-06-24 12:27:15 +02:00
|
|
|
@Override
|
|
|
|
public void onStateChanged(boolean playWhenReady, int playbackState) {
|
|
|
|
if (videoPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (playbackState != ExoPlayer.STATE_ENDED && playbackState != ExoPlayer.STATE_IDLE) {
|
2016-10-11 13:57:01 +02:00
|
|
|
try {
|
|
|
|
parentActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (playbackState == ExoPlayer.STATE_READY && aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
|
2016-06-24 12:27:15 +02:00
|
|
|
aspectRatioFrameLayout.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (videoPlayer.isPlaying() && playbackState != ExoPlayer.STATE_ENDED) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!isPlaying) {
|
|
|
|
isPlaying = true;
|
|
|
|
videoPlayButton.setImageResource(R.drawable.inline_video_pause);
|
|
|
|
AndroidUtilities.runOnUIThread(updateProgressRunnable);
|
|
|
|
}
|
|
|
|
} else if (isPlaying) {
|
|
|
|
isPlaying = false;
|
|
|
|
videoPlayButton.setImageResource(R.drawable.inline_video_play);
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(updateProgressRunnable);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (playbackState == ExoPlayer.STATE_ENDED) {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (isCurrentVideo) {
|
|
|
|
if (!videoTimelineView.isDragging()) {
|
|
|
|
videoTimelineView.setProgress(0.0f);
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration()));
|
|
|
|
} else {
|
|
|
|
videoPlayer.seekTo(0);
|
|
|
|
}
|
|
|
|
videoPlayer.pause();
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!videoPlayerSeekbar.isDragging()) {
|
|
|
|
videoPlayerSeekbar.setProgress(0.0f);
|
|
|
|
videoPlayerControlFrameLayout.invalidate();
|
|
|
|
if (!inPreview && videoTimelineView.getVisibility() == View.VISIBLE) {
|
|
|
|
videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoPlayer.getDuration()));
|
|
|
|
} else {
|
|
|
|
videoPlayer.seekTo(0);
|
|
|
|
}
|
|
|
|
videoPlayer.pause();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateVideoPlayerTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onError(Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
|
|
|
|
if (aspectRatioFrameLayout != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
|
|
|
|
int temp = width;
|
|
|
|
width = height;
|
|
|
|
height = temp;
|
|
|
|
}
|
|
|
|
aspectRatioFrameLayout.setAspectRatio(height == 0 ? 1 : (width * pixelWidthHeightRatio) / height, unappliedRotationDegrees);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRenderedFirstFrame() {
|
|
|
|
if (!textureUploaded) {
|
|
|
|
textureUploaded = true;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
|
|
|
|
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
});
|
|
|
|
long duration;
|
|
|
|
if (videoPlayer != null) {
|
|
|
|
duration = videoPlayer.getDuration();
|
2017-03-31 01:58:05 +02:00
|
|
|
if (duration == C.TIME_UNSET) {
|
2016-06-24 12:27:15 +02:00
|
|
|
duration = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
duration = 0;
|
|
|
|
}
|
|
|
|
duration /= 1000;
|
|
|
|
int size = (int) Math.ceil(videoPlayerTime.getPaint().measureText(String.format("%02d:%02d / %02d:%02d", duration / 60, duration % 60, duration / 60, duration % 60)));
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
videoPlayer.preparePlayer(Uri.fromFile(file), "other");
|
2017-07-23 14:56:38 +02:00
|
|
|
videoPlayerSeekbar.setProgress(0);
|
|
|
|
videoTimelineView.setProgress(0);
|
|
|
|
if (currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
|
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
|
|
|
bottomLayout.setTranslationY(-AndroidUtilities.dp(48));
|
|
|
|
}
|
|
|
|
videoPlayerControlFrameLayout.setVisibility(isCurrentVideo ? View.GONE : View.VISIBLE);
|
|
|
|
dateTextView.setVisibility(View.GONE);
|
|
|
|
nameTextView.setVisibility(View.GONE);
|
|
|
|
if (allowShare) {
|
|
|
|
shareButton.setVisibility(View.GONE);
|
|
|
|
menuItem.showSubItem(gallery_menu_share);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
videoPlayer.setPlayWhenReady(playWhenReady);
|
2017-03-31 01:58:05 +02:00
|
|
|
inPreview = preview;
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void releasePlayer() {
|
|
|
|
if (videoPlayer != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
videoPlayer.releasePlayer();
|
2016-06-24 12:27:15 +02:00
|
|
|
videoPlayer = null;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
try {
|
|
|
|
parentActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
if (aspectRatioFrameLayout != null) {
|
|
|
|
containerView.removeView(aspectRatioFrameLayout);
|
|
|
|
aspectRatioFrameLayout = null;
|
|
|
|
}
|
|
|
|
if (videoTextureView != null) {
|
|
|
|
videoTextureView = null;
|
|
|
|
}
|
|
|
|
if (isPlaying) {
|
|
|
|
isPlaying = false;
|
|
|
|
videoPlayButton.setImageResource(R.drawable.inline_video_play);
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(updateProgressRunnable);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (!inPreview && !requestingPreview) {
|
2016-06-24 12:27:15 +02:00
|
|
|
videoPlayerControlFrameLayout.setVisibility(View.GONE);
|
|
|
|
dateTextView.setVisibility(View.VISIBLE);
|
|
|
|
nameTextView.setVisibility(View.VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (allowShare) {
|
|
|
|
shareButton.setVisibility(View.VISIBLE);
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void updateCaptionTextForCurrentPhoto(Object object) {
|
|
|
|
CharSequence caption = null;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
caption = ((MediaController.PhotoEntry) object).caption;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (object instanceof TLRPC.BotInlineResult) {
|
|
|
|
//caption = ((TLRPC.BotInlineResult) object).send_message.caption;
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
caption = ((MediaController.SearchImage) object).caption;
|
|
|
|
}
|
|
|
|
if (caption == null || caption.length() == 0) {
|
|
|
|
captionEditText.setFieldText("");
|
|
|
|
} else {
|
|
|
|
captionEditText.setFieldText(caption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void showAlertDialog(AlertDialog.Builder builder) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
try {
|
|
|
|
visibleDialog = builder.show();
|
|
|
|
visibleDialog.setCanceledOnTouchOutside(true);
|
|
|
|
visibleDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
|
@Override
|
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyCurrentEditMode() {
|
|
|
|
Bitmap bitmap = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
ArrayList<TLRPC.InputDocument> stickers = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
MediaController.SavedFilterState savedFilterState = null;
|
|
|
|
boolean removeSavedState = false;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
bitmap = photoCropView.getBitmap();
|
2017-12-08 18:35:59 +01:00
|
|
|
removeSavedState = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
bitmap = photoFilterView.getBitmap();
|
2017-12-08 18:35:59 +01:00
|
|
|
savedFilterState = photoFilterView.getSavedFilterState();
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentEditMode == 3) {
|
|
|
|
bitmap = photoPaintView.getBitmap();
|
|
|
|
stickers = photoPaintView.getMasks();
|
2017-12-08 18:35:59 +01:00
|
|
|
removeSavedState = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
if (bitmap != null) {
|
|
|
|
TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry entry = (MediaController.PhotoEntry) object;
|
|
|
|
entry.imagePath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.dp(120), AndroidUtilities.dp(120), 70, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickers != null) {
|
|
|
|
entry.stickers.addAll(stickers);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
cropItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isCropped = true;
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
tuneItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isFiltered = true;
|
|
|
|
} else if (currentEditMode == 3) {
|
|
|
|
paintItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isPainted = true;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (savedFilterState != null) {
|
|
|
|
entry.savedFilterState = savedFilterState;
|
|
|
|
} else if (removeSavedState) {
|
|
|
|
entry.savedFilterState = null;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage entry = (MediaController.SearchImage) object;
|
|
|
|
entry.imagePath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.dp(120), AndroidUtilities.dp(120), 70, false, 101, 101);
|
|
|
|
if (size != null) {
|
|
|
|
entry.thumbPath = FileLoader.getPathToAttach(size, true).toString();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickers != null) {
|
|
|
|
entry.stickers.addAll(stickers);
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
cropItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isCropped = true;
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
tuneItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isFiltered = true;
|
|
|
|
} else if (currentEditMode == 3) {
|
|
|
|
paintItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
entry.isPainted = true;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (savedFilterState != null) {
|
|
|
|
entry.savedFilterState = savedFilterState;
|
|
|
|
} else if (removeSavedState) {
|
|
|
|
entry.savedFilterState = null;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
if (sendPhotoType == 0 && placeProvider != null) {
|
|
|
|
placeProvider.updatePhotoAtIndex(currentIndex);
|
|
|
|
if (!placeProvider.isPhotoChecked(currentIndex)) {
|
2017-12-08 18:35:59 +01:00
|
|
|
setPhotoChecked();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
float scaleX = photoCropView.getRectSizeX() / (float) getContainerViewWidth();
|
|
|
|
float scaleY = photoCropView.getRectSizeY() / (float) getContainerViewHeight();
|
|
|
|
scale = scaleX > scaleY ? scaleX : scaleY;
|
|
|
|
translationX = photoCropView.getRectX() + photoCropView.getRectSizeX() / 2 - getContainerViewWidth() / 2;
|
|
|
|
translationY = photoCropView.getRectY() + photoCropView.getRectSizeY() / 2 - getContainerViewHeight() / 2;
|
|
|
|
zoomAnimation = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
applying = true;
|
|
|
|
|
|
|
|
photoCropView.onDisappear();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
centerImage.setParentView(null);
|
|
|
|
centerImage.setOrientation(0, true);
|
2017-03-31 01:58:05 +02:00
|
|
|
ignoreDidSetImage = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
centerImage.setImageBitmap(bitmap);
|
2017-03-31 01:58:05 +02:00
|
|
|
ignoreDidSetImage = false;
|
2015-02-26 02:32:51 +01:00
|
|
|
centerImage.setParentView(containerView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void setPhotoChecked() {
|
|
|
|
if (placeProvider != null) {
|
|
|
|
int num = placeProvider.setPhotoChecked(currentIndex, getCurrentVideoEditedInfo());
|
|
|
|
boolean checked = placeProvider.isPhotoChecked(currentIndex);
|
|
|
|
checkImageView.setChecked(checked, true);
|
|
|
|
if (num >= 0) {
|
|
|
|
if (placeProvider.allowGroupPhotos()) {
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
if (checked) {
|
|
|
|
selectedPhotosAdapter.notifyItemInserted(num);
|
|
|
|
selectedPhotosListView.smoothScrollToPosition(num);
|
|
|
|
} else {
|
|
|
|
selectedPhotosAdapter.notifyItemRemoved(num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateSelectedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private void switchToEditMode(final int mode) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (currentEditMode == mode || centerImage.getBitmap() == null || changeModeAnimation != null || imageMoveAnimation != null || photoProgressViews[0].backgroundState != -1 || captionEditText.getTag() != null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mode == 0) {
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(0) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(0) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
if (sendPhotoType == 1 && !applying) {
|
|
|
|
float minSide = Math.min(getContainerViewWidth(), getContainerViewHeight());
|
|
|
|
scaleX = minSide / (float) bitmapWidth;
|
|
|
|
scaleY = minSide / (float) bitmapHeight;
|
|
|
|
float fillScale = scaleX > scaleY ? scaleX : scaleY;
|
|
|
|
|
|
|
|
this.scale = fillScale / scale;
|
|
|
|
animateToScale = this.scale * newScale / fillScale;
|
|
|
|
} else {
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
animateToX = 0;
|
|
|
|
if (currentEditMode == 1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
animateToY = AndroidUtilities.dp(24 + 34);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (currentEditMode == 2) {
|
2017-07-23 14:56:38 +02:00
|
|
|
animateToY = AndroidUtilities.dp(92);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentEditMode == 3) {
|
2017-07-23 14:56:38 +02:00
|
|
|
animateToY = AndroidUtilities.dp(44);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
animateToY -= AndroidUtilities.statusBarHeight / 2;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
imageMoveAnimation = new AnimatorSet();
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
imageMoveAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48)),
|
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
|
|
|
ObjectAnimator.ofFloat(photoCropView, "alpha", 0)
|
2015-02-26 02:32:51 +01:00
|
|
|
);
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
photoFilterView.shutdown();
|
|
|
|
imageMoveAnimation.playTogether(
|
2017-07-23 14:56:38 +02:00
|
|
|
ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY", AndroidUtilities.dp(186)),
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1)
|
2015-02-26 02:32:51 +01:00
|
|
|
);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentEditMode == 3) {
|
|
|
|
photoPaintView.shutdown();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY", AndroidUtilities.dp(126)),
|
2017-07-23 14:56:38 +02:00
|
|
|
ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationY", AndroidUtilities.dp(126)),
|
2016-10-11 13:57:01 +02:00
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1)
|
|
|
|
);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
imageMoveAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
|
|
|
} else if (currentEditMode == 2) {
|
|
|
|
containerView.removeView(photoFilterView);
|
|
|
|
photoFilterView = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentEditMode == 3) {
|
|
|
|
containerView.removeView(photoPaintView);
|
|
|
|
photoPaintView = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
2017-03-31 01:58:05 +02:00
|
|
|
applying = false;
|
2015-02-26 02:32:51 +01:00
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0));
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1));
|
2017-07-23 14:56:38 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "alpha", 1));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
animatorSet.playTogether(arrayList);
|
|
|
|
animatorSet.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
pickerView.setVisibility(View.VISIBLE);
|
|
|
|
actionBar.setVisibility(View.VISIBLE);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.setVisibility(captionTextView.getTag() != null ? View.VISIBLE : View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.VISIBLE);
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView.setVisibility(View.VISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
} else if (mode == 1) {
|
|
|
|
if (photoCropView == null) {
|
2016-04-22 15:49:00 +02:00
|
|
|
photoCropView = new PhotoCropView(actvityContext);
|
2015-02-26 02:32:51 +01:00
|
|
|
photoCropView.setVisibility(View.GONE);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(photoCropView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 48));
|
2015-02-26 02:32:51 +01:00
|
|
|
photoCropView.setDelegate(new PhotoCropView.PhotoCropViewDelegate() {
|
|
|
|
@Override
|
|
|
|
public void needMoveImageTo(float x, float y, float s, boolean animated) {
|
|
|
|
if (animated) {
|
|
|
|
animateTo(s, x, y, true);
|
|
|
|
} else {
|
|
|
|
translationX = x;
|
|
|
|
translationY = y;
|
|
|
|
scale = s;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getBitmap() {
|
|
|
|
return centerImage.getBitmap();
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChange(boolean reset) {
|
|
|
|
resetButton.setVisibility(reset ? View.GONE : View.VISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
});
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
photoCropView.onAppear();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
editorDoneLayout.doneButton.setText(LocaleController.getString("Crop", R.string.Crop));
|
2017-03-31 01:58:05 +02:00
|
|
|
editorDoneLayout.doneButton.setTextColor(0xff51bdf3);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
changeModeAnimation = new AnimatorSet();
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
|
2017-07-23 14:56:38 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "alpha", 1, 0));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, "alpha", 1, 0));
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation.playTogether(arrayList);
|
|
|
|
changeModeAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
changeModeAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
pickerView.setVisibility(View.GONE);
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
selectedPhotosListView.setAlpha(0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
|
|
|
|
photosCounterView.setRotationX(0.0f);
|
|
|
|
selectedPhotosListView.setEnabled(false);
|
|
|
|
isPhotosListViewVisible = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView.setVisibility(View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
final Bitmap bitmap = centerImage.getBitmap();
|
2015-02-26 02:32:51 +01:00
|
|
|
if (bitmap != null) {
|
|
|
|
photoCropView.setBitmap(bitmap, centerImage.getOrientation(), sendPhotoType != 1);
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(1) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(1) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (sendPhotoType == 1) {
|
|
|
|
float minSide = Math.min(getContainerViewWidth(1), getContainerViewHeight(1));
|
|
|
|
newScaleX = minSide / (float) bitmapWidth;
|
|
|
|
newScaleY = minSide / (float) bitmapHeight;
|
|
|
|
newScale = newScaleX > newScaleY ? newScaleX : newScaleY;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
animateToY = -AndroidUtilities.dp(24 + 32) + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
imageMoveAnimation = new AnimatorSet();
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(editorDoneLayout, "translationY", AndroidUtilities.dp(48), 0),
|
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
|
|
|
ObjectAnimator.ofFloat(photoCropView, "alpha", 0, 1)
|
2015-02-26 02:32:51 +01:00
|
|
|
);
|
|
|
|
imageMoveAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
editorDoneLayout.setVisibility(View.VISIBLE);
|
|
|
|
photoCropView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoCropView.onAppeared();
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation.start();
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (mode == 2) {
|
|
|
|
if (photoFilterView == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
MediaController.SavedFilterState state = null;
|
|
|
|
Bitmap bitmap;
|
|
|
|
String originalPath = null;
|
|
|
|
int orientation = 0;
|
|
|
|
if (!imagesArrLocals.isEmpty()) {
|
|
|
|
Object object = imagesArrLocals.get(currentIndex);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry entry = (MediaController.PhotoEntry) object;
|
|
|
|
if (entry.imagePath == null) {
|
|
|
|
originalPath = entry.path;
|
|
|
|
state = entry.savedFilterState;
|
|
|
|
}
|
|
|
|
orientation = entry.orientation;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage entry = (MediaController.SearchImage) object;
|
|
|
|
state = entry.savedFilterState;
|
|
|
|
originalPath = entry.imageUrl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (state == null) {
|
|
|
|
bitmap = centerImage.getBitmap();
|
|
|
|
orientation = centerImage.getOrientation();
|
|
|
|
} else {
|
|
|
|
bitmap = BitmapFactory.decodeFile(originalPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
photoFilterView = new PhotoFilterView(parentActivity, bitmap, orientation, state);
|
2015-06-29 19:12:11 +02:00
|
|
|
containerView.addView(photoFilterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-02-26 02:32:51 +01:00
|
|
|
photoFilterView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
applyCurrentEditMode();
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
photoFilterView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (photoFilterView.hasChanges()) {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
|
|
|
|
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 void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
showAlertDialog(builder);
|
|
|
|
} else {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-23 14:56:38 +02:00
|
|
|
photoFilterView.getToolsView().setTranslationY(AndroidUtilities.dp(186));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
changeModeAnimation = new AnimatorSet();
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
|
2017-07-23 14:56:38 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "alpha", 1, 0));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, "alpha", 1, 0));
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation.playTogether(arrayList);
|
|
|
|
changeModeAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
changeModeAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
pickerView.setVisibility(View.GONE);
|
|
|
|
actionBar.setVisibility(View.GONE);
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
selectedPhotosListView.setAlpha(0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
|
|
|
|
photosCounterView.setRotationX(0.0f);
|
|
|
|
selectedPhotosListView.setEnabled(false);
|
|
|
|
isPhotosListViewVisible = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView.setVisibility(View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(2) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(2) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
2017-07-23 14:56:38 +02:00
|
|
|
animateToY = -AndroidUtilities.dp(92) + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
imageMoveAnimation = new AnimatorSet();
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
2017-07-23 14:56:38 +02:00
|
|
|
ObjectAnimator.ofFloat(photoFilterView.getToolsView(), "translationY", AndroidUtilities.dp(186), 0)
|
2015-02-26 02:32:51 +01:00
|
|
|
);
|
|
|
|
imageMoveAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
photoFilterView.init();
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation.start();
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (mode == 3) {
|
|
|
|
if (photoPaintView == null) {
|
|
|
|
photoPaintView = new PhotoPaintView(parentActivity, centerImage.getBitmap(), centerImage.getOrientation());
|
|
|
|
containerView.addView(photoPaintView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
photoPaintView.getDoneTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
applyCurrentEditMode();
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
photoPaintView.getCancelTextView().setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
photoPaintView.maybeShowDismissalAlert(PhotoViewer.this, parentActivity, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-07-23 14:56:38 +02:00
|
|
|
photoPaintView.getColorPicker().setTranslationY(AndroidUtilities.dp(126));
|
2016-10-11 13:57:01 +02:00
|
|
|
photoPaintView.getToolsView().setTranslationY(AndroidUtilities.dp(126));
|
|
|
|
}
|
|
|
|
|
|
|
|
changeModeAnimation = new AnimatorSet();
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(actionBar, "translationY", 0, -actionBar.getHeight()));
|
|
|
|
|
|
|
|
if (needCaptionLayout) {
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(captionTextView, "translationY", 0, AndroidUtilities.dp(96)));
|
|
|
|
}
|
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", 1, 0));
|
2017-07-23 14:56:38 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "alpha", 1, 0));
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedPhotosListView.getVisibility() == View.VISIBLE) {
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, "alpha", 1, 0));
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
changeModeAnimation.playTogether(arrayList);
|
|
|
|
changeModeAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
changeModeAnimation.addListener(new AnimatorListenerAdapter() {
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
changeModeAnimation = null;
|
|
|
|
pickerView.setVisibility(View.GONE);
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
selectedPhotosListView.setAlpha(0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(-AndroidUtilities.dp(10));
|
|
|
|
photosCounterView.setRotationX(0.0f);
|
|
|
|
selectedPhotosListView.setEnabled(false);
|
|
|
|
isPhotosListViewVisible = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView.setVisibility(View.GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap bitmap = centerImage.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
|
|
|
|
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
|
|
|
float newScaleX = (float) getContainerViewWidth(3) / (float) bitmapWidth;
|
|
|
|
float newScaleY = (float) getContainerViewHeight(3) / (float) bitmapHeight;
|
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float newScale = newScaleX > newScaleY ? newScaleY : newScaleX;
|
|
|
|
|
|
|
|
animateToScale = newScale / scale;
|
|
|
|
animateToX = 0;
|
2017-07-23 14:56:38 +02:00
|
|
|
animateToY = -AndroidUtilities.dp(44) + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight / 2 : 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
animationStartTime = System.currentTimeMillis();
|
|
|
|
zoomAnimation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
imageMoveAnimation = new AnimatorSet();
|
|
|
|
imageMoveAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(PhotoViewer.this, "animationValue", 0, 1),
|
2017-07-23 14:56:38 +02:00
|
|
|
ObjectAnimator.ofFloat(photoPaintView.getColorPicker(), "translationY", AndroidUtilities.dp(126), 0),
|
|
|
|
ObjectAnimator.ofFloat(photoPaintView.getToolsView(), "translationY", AndroidUtilities.dp(126), 0)
|
2016-10-11 13:57:01 +02:00
|
|
|
);
|
|
|
|
imageMoveAnimation.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
photoPaintView.init();
|
|
|
|
imageMoveAnimation = null;
|
|
|
|
currentEditMode = mode;
|
|
|
|
animateToScale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
scale = 1;
|
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
changeModeAnimation.start();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private void toggleCheckImageView(boolean show) {
|
2016-06-24 12:27:15 +02:00
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(pickerView, "alpha", show ? 1.0f : 0.0f));
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(captionTextView, "alpha", show ? 1.0f : 0.0f));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(checkImageView, "alpha", show ? 1.0f : 0.0f));
|
2017-07-23 14:56:38 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "alpha", show ? 1.0f : 0.0f));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
animatorSet.playTogether(arrayList);
|
2015-01-02 23:15:07 +01:00
|
|
|
animatorSet.setDuration(200);
|
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private void toggleActionBar(boolean show, final boolean animated) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (show) {
|
|
|
|
actionBar.setVisibility(View.VISIBLE);
|
|
|
|
if (canShowBottom) {
|
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
isActionBarVisible = show;
|
|
|
|
actionBar.setEnabled(show);
|
|
|
|
bottomLayout.setEnabled(show);
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (animated) {
|
2016-06-24 12:27:15 +02:00
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(actionBar, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(bottomLayout, "alpha", show ? 1.0f : 0.0f));
|
2017-12-08 18:35:59 +01:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(groupedPhotosListView, "alpha", show ? 1.0f : 0.0f));
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionTextView.getTag() != null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
arrayList.add(ObjectAnimator.ofFloat(captionTextView, "alpha", show ? 1.0f : 0.0f));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
currentActionBarAnimation = new AnimatorSet();
|
2015-05-03 13:48:36 +02:00
|
|
|
currentActionBarAnimation.playTogether(arrayList);
|
2014-11-06 22:34:47 +01:00
|
|
|
if (!show) {
|
2017-03-31 01:58:05 +02:00
|
|
|
currentActionBarAnimation.addListener(new AnimatorListenerAdapter() {
|
2014-11-06 22:34:47 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (currentActionBarAnimation != null && currentActionBarAnimation.equals(animation)) {
|
2015-02-01 19:51:02 +01:00
|
|
|
actionBar.setVisibility(View.GONE);
|
|
|
|
if (canShowBottom) {
|
|
|
|
bottomLayout.setVisibility(View.GONE);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
currentActionBarAnimation = null;
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
});
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
currentActionBarAnimation.setDuration(200);
|
|
|
|
currentActionBarAnimation.start();
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2016-06-24 12:27:15 +02:00
|
|
|
actionBar.setAlpha(show ? 1.0f : 0.0f);
|
|
|
|
bottomLayout.setAlpha(show ? 1.0f : 0.0f);
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.setAlpha(show ? 1.0f : 0.0f);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionTextView.getTag() != null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
captionTextView.setAlpha(show ? 1.0f : 0.0f);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
if (!show) {
|
|
|
|
actionBar.setVisibility(View.GONE);
|
|
|
|
if (canShowBottom) {
|
|
|
|
bottomLayout.setVisibility(View.GONE);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionTextView.getTag() != null) {
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void togglePhotosListView(boolean show, final boolean animated) {
|
|
|
|
if (show == isPhotosListViewVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (show) {
|
|
|
|
selectedPhotosListView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
isPhotosListViewVisible = show;
|
|
|
|
selectedPhotosListView.setEnabled(show);
|
|
|
|
|
|
|
|
if (animated) {
|
|
|
|
ArrayList<Animator> arrayList = new ArrayList<>();
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, "alpha", show ? 1.0f : 0.0f));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(selectedPhotosListView, "translationY", show ? 0 : -AndroidUtilities.dp(10)));
|
|
|
|
arrayList.add(ObjectAnimator.ofFloat(photosCounterView, "rotationX", show ? 1.0f : 0.0f));
|
|
|
|
currentListViewAnimation = new AnimatorSet();
|
|
|
|
currentListViewAnimation.playTogether(arrayList);
|
|
|
|
if (!show) {
|
|
|
|
currentListViewAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (currentListViewAnimation != null && currentListViewAnimation.equals(animation)) {
|
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
currentListViewAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
currentListViewAnimation.setDuration(200);
|
|
|
|
currentListViewAnimation.start();
|
|
|
|
} else {
|
|
|
|
selectedPhotosListView.setAlpha(show ? 1.0f : 0.0f);
|
|
|
|
selectedPhotosListView.setTranslationY(show ? 0 : -AndroidUtilities.dp(10));
|
|
|
|
photosCounterView.setRotationX(show ? 1.0f : 0.0f);
|
|
|
|
if (!show) {
|
|
|
|
selectedPhotosListView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:07:44 +01:00
|
|
|
private String getFileName(int index) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (index < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (!imagesArrLocations.isEmpty() || !imagesArr.isEmpty()) {
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (index >= imagesArrLocations.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
TLRPC.FileLocation location = imagesArrLocations.get(index);
|
|
|
|
return location.volume_id + "_" + location.local_id + ".jpg";
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (!imagesArr.isEmpty()) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (index >= imagesArr.size()) {
|
|
|
|
return null;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return FileLoader.getMessageFileName(imagesArr.get(index).messageOwner);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
} else if (!imagesArrLocals.isEmpty()) {
|
|
|
|
if (index >= imagesArrLocals.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = ((MediaController.SearchImage) object);
|
2016-01-11 18:19:48 +01:00
|
|
|
if (searchImage.document != null) {
|
|
|
|
return FileLoader.getAttachFileName(searchImage.document);
|
|
|
|
} else if (searchImage.type != 1 && searchImage.localUrl != null && searchImage.localUrl.length() > 0) {
|
2015-01-02 23:15:07 +01:00
|
|
|
File file = new File(searchImage.localUrl);
|
|
|
|
if (file.exists()) {
|
|
|
|
return file.getName();
|
|
|
|
} else {
|
|
|
|
searchImage.localUrl = "";
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl, "jpg");
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (object instanceof TLRPC.BotInlineResult) {
|
|
|
|
TLRPC.BotInlineResult botInlineResult = (TLRPC.BotInlineResult) object;
|
|
|
|
if (botInlineResult.document != null) {
|
|
|
|
return FileLoader.getAttachFileName(botInlineResult.document);
|
|
|
|
} else if (botInlineResult.photo != null) {
|
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(botInlineResult.photo.sizes, AndroidUtilities.getPhotoSize());
|
|
|
|
return FileLoader.getAttachFileName(sizeFull);
|
|
|
|
} else if (botInlineResult.content_url != null) {
|
|
|
|
return Utilities.MD5(botInlineResult.content_url) + "." + ImageLoader.getHttpUrlExtension(botInlineResult.content_url, "jpg");
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private TLObject getFileLocation(int index, int size[]) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (index < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (!imagesArrLocations.isEmpty()) {
|
|
|
|
if (index >= imagesArrLocations.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
size[0] = imagesArrLocationsSizes.get(index);
|
|
|
|
return imagesArrLocations.get(index);
|
|
|
|
} else if (!imagesArr.isEmpty()) {
|
|
|
|
if (index >= imagesArr.size()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
MessageObject message = imagesArr.get(index);
|
|
|
|
if (message.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
|
|
|
return message.messageOwner.action.newUserPhoto.photo_big;
|
|
|
|
} else {
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
|
2014-06-11 01:05:54 +02:00
|
|
|
if (sizeFull != null) {
|
|
|
|
size[0] = sizeFull.size;
|
2014-06-11 02:22:42 +02:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
return sizeFull.location;
|
2014-06-11 02:22:42 +02:00
|
|
|
} else {
|
|
|
|
size[0] = -1;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null || message.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && message.messageOwner.media.webpage != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
TLRPC.FileLocation location;
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.photoThumbs, AndroidUtilities.getPhotoSize());
|
2014-06-11 01:05:54 +02:00
|
|
|
if (sizeFull != null) {
|
|
|
|
size[0] = sizeFull.size;
|
2014-06-11 02:22:42 +02:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
return sizeFull.location;
|
2014-06-11 02:22:42 +02:00
|
|
|
} else {
|
|
|
|
size[0] = -1;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
|
|
|
|
return ((TLRPC.TL_messageMediaInvoice) message.messageOwner.media).photo;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (message.getDocument() != null && message.getDocument().thumb != null) {
|
|
|
|
size[0] = message.getDocument().thumb.size;
|
2014-06-11 02:22:42 +02:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
return message.getDocument().thumb.location;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
private void updateSelectedCount() {
|
|
|
|
if (placeProvider == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
int count = placeProvider.getSelectedCount();
|
|
|
|
photosCounterView.setCount(count);
|
|
|
|
if (count == 0) {
|
|
|
|
togglePhotosListView(false, true);
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private void onPhotoShow(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, int index, final PlaceProviderObject object) {
|
2014-06-11 01:05:54 +02:00
|
|
|
classGuid = ConnectionsManager.getInstance().generateClassGuid();
|
|
|
|
currentMessageObject = null;
|
|
|
|
currentFileLocation = null;
|
2014-06-12 03:13:15 +02:00
|
|
|
currentPathObject = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
fromCamera = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
currentBotInlineResult = null;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentIndex = -1;
|
2014-10-28 18:07:44 +01:00
|
|
|
currentFileNames[0] = null;
|
|
|
|
currentFileNames[1] = null;
|
|
|
|
currentFileNames[2] = null;
|
2016-06-24 12:27:15 +02:00
|
|
|
avatarsDialogId = 0;
|
2014-06-11 01:05:54 +02:00
|
|
|
totalImagesCount = 0;
|
2015-11-26 22:04:02 +01:00
|
|
|
totalImagesCountMerge = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
currentEditMode = 0;
|
2014-06-11 01:05:54 +02:00
|
|
|
isFirstLoading = true;
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
loadingMoreImages = false;
|
2015-11-26 22:04:02 +01:00
|
|
|
endReached[0] = false;
|
|
|
|
endReached[1] = mergeDialogId == 0;
|
2014-06-11 01:05:54 +02:00
|
|
|
opennedFromMedia = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
needCaptionLayout = false;
|
2014-06-12 03:13:15 +02:00
|
|
|
canShowBottom = true;
|
2017-07-23 14:56:38 +02:00
|
|
|
isCurrentVideo = false;
|
2014-06-11 01:05:54 +02:00
|
|
|
imagesArr.clear();
|
|
|
|
imagesArrLocations.clear();
|
|
|
|
imagesArrLocationsSizes.clear();
|
2014-08-22 16:24:33 +02:00
|
|
|
avatarsArr.clear();
|
2014-06-12 03:13:15 +02:00
|
|
|
imagesArrLocals.clear();
|
2015-11-26 22:04:02 +01:00
|
|
|
for (int a = 0; a < 2; a++) {
|
|
|
|
imagesByIds[a].clear();
|
|
|
|
imagesByIdsTemp[a].clear();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
imagesArrTemp.clear();
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUserAvatarLocation = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
containerView.setPadding(0, 0, 0, 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
currentThumb = object != null ? object.thumb : null;
|
2017-07-08 18:32:04 +02:00
|
|
|
isEvent = object != null && object.isEvent;
|
2014-06-12 03:13:15 +02:00
|
|
|
menuItem.setVisibility(View.VISIBLE);
|
2017-12-08 18:35:59 +01:00
|
|
|
sendItem.setVisibility(View.GONE);
|
2014-06-12 03:13:15 +02:00
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
bottomLayout.setTranslationY(0);
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView.setTranslationY(0);
|
2015-02-26 02:32:51 +01:00
|
|
|
shareButton.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (qualityChooseView != null) {
|
|
|
|
qualityChooseView.setVisibility(View.INVISIBLE);
|
|
|
|
qualityPicker.setVisibility(View.INVISIBLE);
|
|
|
|
qualityChooseView.setTag(null);
|
|
|
|
}
|
|
|
|
if (qualityChooseViewAnimation != null) {
|
|
|
|
qualityChooseViewAnimation.cancel();
|
|
|
|
qualityChooseViewAnimation = null;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = false;
|
2017-12-08 18:35:59 +01:00
|
|
|
slideshowMessageId = 0;
|
|
|
|
nameOverride = null;
|
|
|
|
dateOverride = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
menuItem.hideSubItem(gallery_menu_showall);
|
2017-12-08 18:35:59 +01:00
|
|
|
menuItem.hideSubItem(gallery_menu_showinchat);
|
2016-06-24 12:27:15 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
menuItem.hideSubItem(gallery_menu_openin);
|
|
|
|
actionBar.setTranslationY(0);
|
2017-07-23 14:56:38 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
checkImageView.setAlpha(1.0f);
|
2014-06-12 03:13:15 +02:00
|
|
|
checkImageView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
actionBar.setTitleRightMargin(0);
|
|
|
|
photosCounterView.setAlpha(1.0f);
|
|
|
|
photosCounterView.setVisibility(View.GONE);
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
pickerView.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerView.setAlpha(1.0f);
|
|
|
|
pickerView.setTranslationY(0);
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
paintItem.setVisibility(View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
cropItem.setVisibility(View.GONE);
|
|
|
|
tuneItem.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
timeItem.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
videoTimelineView.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
compressItem.setVisibility(View.GONE);
|
2015-05-03 13:48:36 +02:00
|
|
|
captionEditText.setVisibility(View.GONE);
|
|
|
|
mentionListView.setVisibility(View.GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
muteItem.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setSubtitle(null);
|
2016-10-11 13:57:01 +02:00
|
|
|
masksItem.setVisibility(View.GONE);
|
|
|
|
muteVideo = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
muteItem.setImageResource(R.drawable.volume_on);
|
2015-02-26 02:32:51 +01:00
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
2015-05-03 13:48:36 +02:00
|
|
|
captionTextView.setTag(null);
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (photoCropView != null) {
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (photoFilterView != null) {
|
|
|
|
photoFilterView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2014-10-28 18:07:44 +01:00
|
|
|
for (int a = 0; a < 3; a++) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (photoProgressViews[a] != null) {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, false);
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
if (messageObject != null && messages == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage != null) {
|
|
|
|
TLRPC.WebPage webPage = messageObject.messageOwner.media.webpage;
|
|
|
|
String siteName = webPage.site_name;
|
|
|
|
if (siteName != null) {
|
|
|
|
siteName = siteName.toLowerCase();
|
|
|
|
if (siteName.equals("instagram") || siteName.equals("twitter")) {
|
|
|
|
if (!TextUtils.isEmpty(webPage.author)) {
|
|
|
|
nameOverride = webPage.author;
|
|
|
|
}
|
|
|
|
if (webPage.cached_page instanceof TLRPC.TL_pageFull) {
|
|
|
|
for (int a = 0; a < webPage.cached_page.blocks.size(); a++) {
|
|
|
|
TLRPC.PageBlock block = webPage.cached_page.blocks.get(a);
|
|
|
|
if (block instanceof TLRPC.TL_pageBlockAuthorDate) {
|
|
|
|
dateOverride = ((TLRPC.TL_pageBlockAuthorDate) block).published_date;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ArrayList<MessageObject> arrayList = messageObject.getWebPagePhotos(null, null);
|
|
|
|
if (!arrayList.isEmpty()) {
|
|
|
|
slideshowMessageId = messageObject.getId();
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
imagesArr.addAll(arrayList);
|
|
|
|
totalImagesCount = imagesArr.size();
|
|
|
|
setImageIndex(imagesArr.indexOf(messageObject), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (slideshowMessageId == 0) {
|
|
|
|
imagesArr.add(messageObject);
|
|
|
|
if (currentAnimation != null || messageObject.eventId != 0) {
|
|
|
|
needSearchImageInArr = false;
|
|
|
|
} else if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty)) {
|
|
|
|
needSearchImageInArr = true;
|
|
|
|
imagesByIds[0].put(messageObject.getId(), messageObject);
|
|
|
|
menuItem.showSubItem(gallery_menu_showall);
|
|
|
|
sendItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
setImageIndex(0, true);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else if (fileLocation != null) {
|
2016-06-24 12:27:15 +02:00
|
|
|
avatarsDialogId = object.dialogId;
|
2014-06-11 01:05:54 +02:00
|
|
|
imagesArrLocations.add(fileLocation);
|
|
|
|
imagesArrLocationsSizes.add(object.size);
|
2014-08-22 16:24:33 +02:00
|
|
|
avatarsArr.add(new TLRPC.TL_photoEmpty());
|
2017-07-23 14:56:38 +02:00
|
|
|
shareButton.setVisibility(videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = true;
|
2014-06-11 01:05:54 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_showall);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (shareButton.getVisibility() == View.VISIBLE) {
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
} else {
|
|
|
|
menuItem.showSubItem(gallery_menu_share);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
setImageIndex(0, true);
|
2014-08-22 16:24:33 +02:00
|
|
|
currentUserAvatarLocation = fileLocation;
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (messages != null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
opennedFromMedia = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
menuItem.showSubItem(gallery_menu_showinchat);
|
|
|
|
sendItem.setVisibility(View.VISIBLE);
|
2014-06-11 01:05:54 +02:00
|
|
|
imagesArr.addAll(messages);
|
2015-11-26 22:04:02 +01:00
|
|
|
for (int a = 0; a < imagesArr.size(); a++) {
|
|
|
|
MessageObject message = imagesArr.get(a);
|
|
|
|
imagesByIds[message.getDialogId() == currentDialogId ? 0 : 1].put(message.getId(), message);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
setImageIndex(index, true);
|
2014-06-12 03:13:15 +02:00
|
|
|
} else if (photos != null) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setVisibility(View.VISIBLE);
|
2017-07-23 14:56:38 +02:00
|
|
|
photosCounterView.setVisibility(View.VISIBLE);
|
|
|
|
actionBar.setTitleRightMargin(AndroidUtilities.dp(100));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
menuItem.setVisibility(View.GONE);
|
|
|
|
imagesArrLocals.addAll(photos);
|
2015-02-26 02:32:51 +01:00
|
|
|
Object obj = imagesArrLocals.get(index);
|
2017-03-31 01:58:05 +02:00
|
|
|
boolean allowCaption;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (obj instanceof MediaController.PhotoEntry) {
|
|
|
|
if (((MediaController.PhotoEntry) obj).isVideo) {
|
|
|
|
cropItem.setVisibility(View.GONE);
|
2017-07-23 14:56:38 +02:00
|
|
|
bottomLayout.setVisibility(View.VISIBLE);
|
|
|
|
bottomLayout.setTranslationY(-AndroidUtilities.dp(48));
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
cropItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
allowCaption = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (obj instanceof TLRPC.BotInlineResult) {
|
|
|
|
cropItem.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
allowCaption = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
cropItem.setVisibility(obj instanceof MediaController.SearchImage && ((MediaController.SearchImage) obj).type == 0 ? View.VISIBLE : View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
allowCaption = cropItem.getVisibility() == View.VISIBLE;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (parentChatActivity != null && (parentChatActivity.currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(parentChatActivity.currentEncryptedChat.layer) >= 46)) {
|
2015-05-03 13:48:36 +02:00
|
|
|
mentionsAdapter.setChatInfo(parentChatActivity.info);
|
|
|
|
mentionsAdapter.setNeedUsernames(parentChatActivity.currentChat != null);
|
2016-01-11 18:19:48 +01:00
|
|
|
mentionsAdapter.setNeedBotContext(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
needCaptionLayout = allowCaption && (placeProvider == null || placeProvider != null && placeProvider.allowCaption());
|
2016-10-11 13:57:01 +02:00
|
|
|
captionEditText.setVisibility(needCaptionLayout ? View.VISIBLE : View.GONE);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
captionEditText.onCreate();
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
pickerView.setVisibility(View.VISIBLE);
|
|
|
|
bottomLayout.setVisibility(View.GONE);
|
|
|
|
canShowBottom = false;
|
|
|
|
setImageIndex(index, true);
|
|
|
|
paintItem.setVisibility(cropItem.getVisibility());
|
|
|
|
tuneItem.setVisibility(cropItem.getVisibility());
|
2014-06-12 03:13:15 +02:00
|
|
|
updateSelectedCount();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (currentAnimation == null && !isEvent) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentDialogId != 0 && totalImagesCount == 0) {
|
|
|
|
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
|
|
|
|
if (mergeDialogId != 0) {
|
|
|
|
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
|
|
|
|
}
|
|
|
|
} else if (avatarsDialogId != 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
MessagesController.getInstance().loadDialogPhotos(avatarsDialogId, 80, 0, true, classGuid);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentMessageObject != null && currentMessageObject.isVideo() || currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
|
2016-06-24 12:27:15 +02:00
|
|
|
onActionClick(false);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (!imagesArrLocals.isEmpty()) {
|
|
|
|
Object entry = imagesArrLocals.get(index);
|
|
|
|
CharSequence caption = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
TLRPC.User user = parentChatActivity != null ? parentChatActivity.getCurrentUser() : null;
|
|
|
|
boolean allowTimeItem = parentChatActivity != null && !parentChatActivity.isSecretChat() && user != null && !user.bot;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (entry instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) entry);
|
|
|
|
if (photoEntry.isVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
preparePlayer(new File(photoEntry.path), false, false);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
} else if (allowTimeItem && entry instanceof MediaController.SearchImage) {
|
|
|
|
allowTimeItem = ((MediaController.SearchImage) entry).type == 0;
|
|
|
|
}
|
|
|
|
if (allowTimeItem) {
|
|
|
|
timeItem.setVisibility(View.VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean isMuteVideo() {
|
|
|
|
return muteVideo;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private void setImages() {
|
|
|
|
if (animationInProgress == 0) {
|
|
|
|
setIndexToImage(centerImage, currentIndex);
|
|
|
|
setIndexToImage(rightImage, currentIndex + 1);
|
|
|
|
setIndexToImage(leftImage, currentIndex - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setImageIndex(int index, boolean init) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentIndex == index || placeProvider == null) {
|
2014-06-11 01:05:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!init) {
|
|
|
|
currentThumb = null;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
currentFileNames[0] = getFileName(index);
|
|
|
|
currentFileNames[1] = getFileName(index + 1);
|
|
|
|
currentFileNames[2] = getFileName(index - 1);
|
2014-11-19 16:17:24 +01:00
|
|
|
placeProvider.willSwitchFromPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
|
|
|
int prevIndex = currentIndex;
|
|
|
|
currentIndex = index;
|
2016-03-06 02:49:31 +01:00
|
|
|
boolean isVideo = false;
|
2014-08-29 23:06:04 +02:00
|
|
|
boolean sameImage = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
boolean isInvoice;
|
2017-07-08 18:32:04 +02:00
|
|
|
String videoPath = null;
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
if (!imagesArr.isEmpty()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (currentIndex < 0 || currentIndex >= imagesArr.size()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
closePhoto(false, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
MessageObject newMessageObject = imagesArr.get(currentIndex);
|
|
|
|
sameImage = currentMessageObject != null && currentMessageObject.getId() == newMessageObject.getId();
|
|
|
|
currentMessageObject = newMessageObject;
|
2016-03-06 02:49:31 +01:00
|
|
|
isVideo = currentMessageObject.isVideo();
|
2017-03-31 01:58:05 +02:00
|
|
|
isInvoice = currentMessageObject.isInvoice();
|
|
|
|
if (isInvoice) {
|
|
|
|
masksItem.setVisibility(View.GONE);
|
2015-09-24 22:52:02 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2016-06-24 12:27:15 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_openin);
|
2017-03-31 01:58:05 +02:00
|
|
|
setCurrentCaption(currentMessageObject.messageOwner.media.description);
|
|
|
|
allowShare = false;
|
|
|
|
bottomLayout.setTranslationY(AndroidUtilities.dp(48));
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView.setTranslationY(AndroidUtilities.dp(48));
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
masksItem.setVisibility(currentMessageObject.hasPhotoStickers() && (int) currentMessageObject.getDialogId() != 0 ? View.VISIBLE : View.GONE);
|
|
|
|
if (currentMessageObject.canDeleteMessage(null) && slideshowMessageId == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (isVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
menuItem.showSubItem(gallery_menu_openin);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_openin);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (nameOverride != null) {
|
|
|
|
nameTextView.setText(nameOverride);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (currentMessageObject.isFromUser()) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(currentMessageObject.messageOwner.from_id);
|
|
|
|
if (user != null) {
|
|
|
|
nameTextView.setText(UserObject.getUserName(user));
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(currentMessageObject.messageOwner.to_id.channel_id);
|
|
|
|
if (chat != null) {
|
|
|
|
nameTextView.setText(chat.title);
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
long date;
|
|
|
|
if (dateOverride != 0) {
|
|
|
|
date = (long) dateOverride * 1000;
|
|
|
|
} else {
|
|
|
|
date = (long) currentMessageObject.messageOwner.date * 1000;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
String dateString = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(new Date(date)), LocaleController.getInstance().formatterDay.format(new Date(date)));
|
|
|
|
if (currentFileNames[0] != null && isVideo) {
|
|
|
|
dateTextView.setText(String.format("%s (%s)", dateString, AndroidUtilities.formatFileSize(currentMessageObject.getDocument().size)));
|
|
|
|
} else {
|
|
|
|
dateTextView.setText(dateString);
|
|
|
|
}
|
|
|
|
CharSequence caption = currentMessageObject.caption;
|
|
|
|
setCurrentCaption(caption);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
menuItem.hideSubItem(gallery_menu_save);
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
if (!currentMessageObject.canDeleteMessage(null)) {
|
|
|
|
menuItem.setVisibility(View.GONE);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = true;
|
2016-06-24 12:27:15 +02:00
|
|
|
shareButton.setVisibility(View.VISIBLE);
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachGif", R.string.AttachGif));
|
|
|
|
} else {
|
|
|
|
if (totalImagesCount + totalImagesCountMerge != 0 && !needSearchImageInArr) {
|
|
|
|
if (opennedFromMedia) {
|
|
|
|
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && currentIndex > imagesArr.size() - 5) {
|
|
|
|
int loadFromMaxId = imagesArr.isEmpty() ? 0 : imagesArr.get(imagesArr.size() - 1).getId();
|
|
|
|
int loadIndex = 0;
|
|
|
|
if (endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArr.isEmpty() && imagesArr.get(imagesArr.size() - 1).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2016-06-24 12:27:15 +02:00
|
|
|
loadingMoreImages = true;
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
|
|
|
} else {
|
|
|
|
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && currentIndex < 5) {
|
|
|
|
int loadFromMaxId = imagesArr.isEmpty() ? 0 : imagesArr.get(0).getId();
|
|
|
|
int loadIndex = 0;
|
|
|
|
if (endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
loadIndex = 1;
|
|
|
|
if (!imagesArr.isEmpty() && imagesArr.get(0).getDialogId() != mergeDialogId) {
|
|
|
|
loadFromMaxId = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2016-06-24 12:27:15 +02:00
|
|
|
loadingMoreImages = true;
|
|
|
|
}
|
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (slideshowMessageId == 0 && currentMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentMessageObject.isVideo()) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachVideo", R.string.AttachVideo));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (isInvoice) {
|
|
|
|
actionBar.setTitle(currentMessageObject.messageOwner.media.title);
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if ((int) currentDialogId == 0) {
|
|
|
|
sendItem.setVisibility(View.GONE);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (currentMessageObject.messageOwner.ttl != 0 && currentMessageObject.messageOwner.ttl < 60 * 60) {
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = false;
|
2016-06-24 12:27:15 +02:00
|
|
|
menuItem.hideSubItem(gallery_menu_save);
|
|
|
|
shareButton.setVisibility(View.GONE);
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = true;
|
2016-06-24 12:27:15 +02:00
|
|
|
menuItem.showSubItem(gallery_menu_save);
|
2017-07-23 14:56:38 +02:00
|
|
|
shareButton.setVisibility(videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (shareButton.getVisibility() == View.VISIBLE) {
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
} else {
|
|
|
|
menuItem.showSubItem(gallery_menu_share);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.fillList();
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (!imagesArrLocations.isEmpty()) {
|
2014-08-22 16:24:33 +02:00
|
|
|
nameTextView.setText("");
|
|
|
|
dateTextView.setText("");
|
2016-06-24 12:27:15 +02:00
|
|
|
if (avatarsDialogId == UserConfig.getClientUserId() && !avatarsArr.isEmpty()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
menuItem.showSubItem(gallery_menu_delete);
|
2014-08-22 16:24:33 +02:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
menuItem.hideSubItem(gallery_menu_delete);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
TLRPC.FileLocation old = currentFileLocation;
|
2015-01-02 23:15:07 +01:00
|
|
|
if (index < 0 || index >= imagesArrLocations.size()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
closePhoto(false, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
currentFileLocation = imagesArrLocations.get(index);
|
2014-08-29 23:06:04 +02:00
|
|
|
if (old != null && currentFileLocation != null && old.local_id == currentFileLocation.local_id && old.volume_id == currentFileLocation.volume_id) {
|
|
|
|
sameImage = true;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (isEvent) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, imagesArrLocations.size()));
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
menuItem.showSubItem(gallery_menu_save);
|
2016-10-11 13:57:01 +02:00
|
|
|
allowShare = true;
|
2017-07-23 14:56:38 +02:00
|
|
|
shareButton.setVisibility(videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE ? View.VISIBLE : View.GONE);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (shareButton.getVisibility() == View.VISIBLE) {
|
|
|
|
menuItem.hideSubItem(gallery_menu_share);
|
|
|
|
} else {
|
|
|
|
menuItem.showSubItem(gallery_menu_share);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.fillList();
|
2014-06-12 03:13:15 +02:00
|
|
|
} else if (!imagesArrLocals.isEmpty()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (index < 0 || index >= imagesArrLocals.size()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
closePhoto(false, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
Object object = imagesArrLocals.get(index);
|
2015-05-03 13:48:36 +02:00
|
|
|
CharSequence caption = null;
|
2017-07-23 14:56:38 +02:00
|
|
|
int ttl = 0;
|
|
|
|
boolean isFiltered = false;
|
|
|
|
boolean isPainted = false;
|
|
|
|
boolean isCropped = false;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (object instanceof TLRPC.BotInlineResult) {
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.BotInlineResult botInlineResult = currentBotInlineResult = ((TLRPC.BotInlineResult) object);
|
|
|
|
if (botInlineResult.document != null) {
|
|
|
|
isVideo = MessageObject.isVideoDocument(botInlineResult.document);
|
|
|
|
currentPathObject = FileLoader.getPathToAttach(botInlineResult.document).getAbsolutePath();
|
|
|
|
} else if (botInlineResult.photo != null) {
|
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(botInlineResult.photo.sizes, AndroidUtilities.getPhotoSize());
|
|
|
|
currentPathObject = FileLoader.getPathToAttach(sizeFull).getAbsolutePath();
|
|
|
|
} else if (botInlineResult.content_url != null) {
|
|
|
|
currentPathObject = botInlineResult.content_url;
|
|
|
|
isVideo = botInlineResult.type.equals("video");
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
pickerView.setPadding(0, AndroidUtilities.dp(14), 0, 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
//caption = botInlineResult.send_message.caption;
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
boolean isAnimation = false;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) object);
|
|
|
|
currentPathObject = photoEntry.path;
|
|
|
|
isVideo = photoEntry.isVideo;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
|
|
|
|
if (searchImage.document != null) {
|
|
|
|
currentPathObject = FileLoader.getPathToAttach(searchImage.document, true).getAbsolutePath();
|
|
|
|
} else {
|
|
|
|
currentPathObject = searchImage.imageUrl;
|
|
|
|
}
|
|
|
|
if (searchImage.type == 1) {
|
|
|
|
isAnimation = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isVideo) {
|
|
|
|
muteItem.setVisibility(View.VISIBLE);
|
|
|
|
compressItem.setVisibility(View.VISIBLE);
|
|
|
|
isCurrentVideo = true;
|
|
|
|
boolean isMuted = false;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) object);
|
|
|
|
isMuted = photoEntry.editedInfo != null && photoEntry.editedInfo.muted;
|
|
|
|
}
|
|
|
|
processOpenVideo(currentPathObject, isMuted);
|
|
|
|
videoTimelineView.setVisibility(View.VISIBLE);
|
|
|
|
paintItem.setVisibility(View.GONE);
|
|
|
|
cropItem.setVisibility(View.GONE);
|
|
|
|
tuneItem.setVisibility(View.GONE);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
videoTimelineView.setVisibility(View.GONE);
|
|
|
|
muteItem.setVisibility(View.GONE);
|
|
|
|
isCurrentVideo = false;
|
|
|
|
compressItem.setVisibility(View.GONE);
|
|
|
|
if (isAnimation) {
|
|
|
|
pickerView.setPadding(0, AndroidUtilities.dp(14), 0, 0);
|
|
|
|
paintItem.setVisibility(View.GONE);
|
|
|
|
cropItem.setVisibility(View.GONE);
|
|
|
|
tuneItem.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
if (sendPhotoType != 1) {
|
|
|
|
pickerView.setPadding(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
paintItem.setVisibility(View.VISIBLE);
|
|
|
|
cropItem.setVisibility(View.VISIBLE);
|
|
|
|
tuneItem.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
}
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) object);
|
|
|
|
fromCamera = photoEntry.bucketId == 0 && photoEntry.dateTaken == 0 && imagesArrLocals.size() == 1;
|
|
|
|
caption = photoEntry.caption;
|
|
|
|
videoPath = photoEntry.path;
|
|
|
|
ttl = photoEntry.ttl;
|
|
|
|
isFiltered = photoEntry.isFiltered;
|
|
|
|
isPainted = photoEntry.isPainted;
|
|
|
|
isCropped = photoEntry.isCropped;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
|
|
|
|
caption = searchImage.caption;
|
|
|
|
ttl = searchImage.ttl;
|
|
|
|
isFiltered = searchImage.isFiltered;
|
|
|
|
isPainted = searchImage.isPainted;
|
|
|
|
isCropped = searchImage.isCropped;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
bottomLayout.setVisibility(View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (fromCamera) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (isVideo) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachVideo", R.string.AttachVideo));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, imagesArrLocals.size()));
|
|
|
|
}
|
|
|
|
if (parentChatActivity != null) {
|
|
|
|
TLRPC.Chat chat = parentChatActivity.getCurrentChat();
|
|
|
|
if (chat != null) {
|
|
|
|
actionBar.setTitle(chat.title);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
TLRPC.User user = parentChatActivity.getCurrentUser();
|
|
|
|
if (user != null) {
|
|
|
|
actionBar.setTitle(ContactsController.formatName(user.first_name, user.last_name));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
if (sendPhotoType == 0) {
|
|
|
|
checkImageView.setChecked(placeProvider.isPhotoChecked(currentIndex), false);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
setCurrentCaption(caption);
|
|
|
|
updateCaptionTextForCurrentPhoto(object);
|
2017-07-23 14:56:38 +02:00
|
|
|
timeItem.setColorFilter(ttl != 0 ? new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
paintItem.setColorFilter(isPainted ? new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
cropItem.setColorFilter(isCropped ? new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
tuneItem.setColorFilter(isFiltered ? new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY) : null);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2014-06-13 20:26:05 +02:00
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (currentPlaceObject != null) {
|
2014-06-13 20:26:05 +02:00
|
|
|
if (animationInProgress == 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
currentPlaceObject.imageReceiver.setVisible(true, true);
|
2014-06-13 20:26:05 +02:00
|
|
|
} else {
|
|
|
|
showAfterAnimation = currentPlaceObject;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
currentPlaceObject = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
2014-11-06 22:34:47 +01:00
|
|
|
if (currentPlaceObject != null) {
|
2014-06-13 20:26:05 +02:00
|
|
|
if (animationInProgress == 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
currentPlaceObject.imageReceiver.setVisible(false, true);
|
2014-06-13 20:26:05 +02:00
|
|
|
} else {
|
|
|
|
hideAfterAnimation = currentPlaceObject;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-29 23:06:04 +02:00
|
|
|
if (!sameImage) {
|
|
|
|
draggingDown = false;
|
|
|
|
translationX = 0;
|
|
|
|
translationY = 0;
|
|
|
|
scale = 1;
|
|
|
|
animateToX = 0;
|
|
|
|
animateToY = 0;
|
|
|
|
animateToScale = 1;
|
|
|
|
animationStartTime = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
changeModeAnimation = null;
|
2016-06-24 12:27:15 +02:00
|
|
|
if (aspectRatioFrameLayout != null) {
|
|
|
|
aspectRatioFrameLayout.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
releasePlayer();
|
2014-08-29 23:06:04 +02:00
|
|
|
|
|
|
|
pinchStartDistance = 0;
|
|
|
|
pinchStartScale = 1;
|
|
|
|
pinchCenterX = 0;
|
|
|
|
pinchCenterY = 0;
|
|
|
|
pinchStartX = 0;
|
|
|
|
pinchStartY = 0;
|
|
|
|
moveStartX = 0;
|
|
|
|
moveStartY = 0;
|
|
|
|
zooming = false;
|
|
|
|
moving = false;
|
|
|
|
doubleTap = false;
|
|
|
|
invalidCoords = false;
|
|
|
|
canDragDown = true;
|
|
|
|
changingPage = false;
|
|
|
|
switchImageAfterAnimation = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
canZoom = !imagesArrLocals.isEmpty() || (currentFileNames[0] != null && !isVideo && photoProgressViews[0].backgroundState != 0);
|
2014-08-29 23:06:04 +02:00
|
|
|
updateMinMax(scale);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (isVideo && videoPath != null) {
|
|
|
|
preparePlayer(new File(videoPath), false, false);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
if (prevIndex == -1) {
|
2015-02-01 19:51:02 +01:00
|
|
|
setImages();
|
2014-11-19 02:23:46 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
checkProgress(a, false);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2014-11-19 02:23:46 +01:00
|
|
|
checkProgress(0, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
if (prevIndex > currentIndex) {
|
|
|
|
ImageReceiver temp = rightImage;
|
|
|
|
rightImage = centerImage;
|
|
|
|
centerImage = leftImage;
|
|
|
|
leftImage = temp;
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
PhotoProgressView tempProgress = photoProgressViews[0];
|
|
|
|
photoProgressViews[0] = photoProgressViews[2];
|
|
|
|
photoProgressViews[2] = tempProgress;
|
2014-06-11 01:05:54 +02:00
|
|
|
setIndexToImage(leftImage, currentIndex - 1);
|
2014-11-19 02:23:46 +01:00
|
|
|
|
|
|
|
checkProgress(1, false);
|
|
|
|
checkProgress(2, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (prevIndex < currentIndex) {
|
|
|
|
ImageReceiver temp = leftImage;
|
|
|
|
leftImage = centerImage;
|
|
|
|
centerImage = rightImage;
|
|
|
|
rightImage = temp;
|
2014-11-19 02:23:46 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
PhotoProgressView tempProgress = photoProgressViews[0];
|
|
|
|
photoProgressViews[0] = photoProgressViews[1];
|
|
|
|
photoProgressViews[1] = tempProgress;
|
2014-06-11 01:05:54 +02:00
|
|
|
setIndexToImage(rightImage, currentIndex + 1);
|
|
|
|
|
2014-11-19 02:23:46 +01:00
|
|
|
checkProgress(1, false);
|
|
|
|
checkProgress(2, false);
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void setCurrentCaption(final CharSequence caption) {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (needCaptionLayout) {
|
|
|
|
if (captionTextView.getParent() != pickerView) {
|
|
|
|
captionTextView.setBackgroundDrawable(null);
|
|
|
|
containerView.removeView(captionTextView);
|
|
|
|
pickerView.addView(captionTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 76, 48));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (captionTextView.getParent() != containerView) {
|
|
|
|
captionTextView.setBackgroundColor(0x7f000000);
|
|
|
|
pickerView.removeView(captionTextView);
|
|
|
|
containerView.addView(captionTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isCurrentVideo) {
|
|
|
|
captionTextView.setMaxLines(1);
|
|
|
|
captionTextView.setSingleLine(true);
|
|
|
|
} else {
|
|
|
|
captionTextView.setSingleLine(false);
|
|
|
|
captionTextView.setMaxLines(10);
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(caption)) {
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.createChatResources(null, true);
|
|
|
|
CharSequence str = Emoji.replaceEmoji(new SpannableStringBuilder(caption.toString()), captionTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2016-03-06 02:49:31 +01:00
|
|
|
captionTextView.setTag(str);
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
captionTextView.setText(str);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
captionTextView.setTextColor(0xffffffff);
|
2016-06-24 12:27:15 +02:00
|
|
|
captionTextView.setAlpha(bottomLayout.getVisibility() == View.VISIBLE || pickerView.getVisibility() == View.VISIBLE ? 1.0f : 0.0f);
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView.setVisibility(bottomLayout.getVisibility() == View.VISIBLE || pickerView.getVisibility() == View.VISIBLE ? View.VISIBLE : View.INVISIBLE);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (needCaptionLayout) {
|
2017-07-23 14:56:38 +02:00
|
|
|
captionTextView.setText(LocaleController.getString("AddCaption", R.string.AddCaption));
|
2016-10-11 13:57:01 +02:00
|
|
|
captionTextView.setTag("empty");
|
|
|
|
captionTextView.setVisibility(View.VISIBLE);
|
|
|
|
captionTextView.setTextColor(0xb2ffffff);
|
|
|
|
} else {
|
|
|
|
captionTextView.setTextColor(0xffffffff);
|
|
|
|
captionTextView.setTag(null);
|
|
|
|
captionTextView.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-30 22:27:41 +01:00
|
|
|
private void checkProgress(int a, boolean animated) {
|
2017-07-23 14:56:38 +02:00
|
|
|
int index = currentIndex;
|
|
|
|
if (a == 1) {
|
|
|
|
index += 1;
|
|
|
|
} else if (a == 2) {
|
|
|
|
index -= 1;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
if (currentFileNames[a] != null) {
|
2014-09-25 05:54:35 +02:00
|
|
|
File f = null;
|
2016-03-06 02:49:31 +01:00
|
|
|
boolean isVideo = false;
|
2014-09-25 05:54:35 +02:00
|
|
|
if (currentMessageObject != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (index < 0 || index >= imagesArr.size()) {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, animated);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
MessageObject messageObject = imagesArr.get(index);
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!TextUtils.isEmpty(messageObject.messageOwner.attachPath)) {
|
|
|
|
f = new File(messageObject.messageOwner.attachPath);
|
|
|
|
if (!f.exists()) {
|
|
|
|
f = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (f == null) {
|
|
|
|
f = FileLoader.getPathToMessage(messageObject.messageOwner);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
isVideo = messageObject.isVideo();
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentBotInlineResult != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (index < 0 || index >= imagesArrLocals.size()) {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, animated);
|
|
|
|
return;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.BotInlineResult botInlineResult = (TLRPC.BotInlineResult) imagesArrLocals.get(index);
|
|
|
|
if (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(botInlineResult.document)) {
|
|
|
|
if (botInlineResult.document != null) {
|
|
|
|
f = FileLoader.getPathToAttach(botInlineResult.document);
|
|
|
|
} else if (botInlineResult.content_url != null) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(botInlineResult.content_url) + "." + ImageLoader.getHttpUrlExtension(botInlineResult.content_url, "mp4"));
|
|
|
|
}
|
|
|
|
isVideo = true;
|
|
|
|
} else if (botInlineResult.document != null) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_DOCUMENT), currentFileNames[a]);
|
|
|
|
} else if (botInlineResult.photo != null) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_IMAGE), currentFileNames[a]);
|
|
|
|
}
|
|
|
|
if (f == null || !f.exists()) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), currentFileNames[a]);
|
|
|
|
}
|
2014-09-25 05:54:35 +02:00
|
|
|
} else if (currentFileLocation != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (index < 0 || index >= imagesArrLocations.size()) {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, animated);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
TLRPC.FileLocation location = imagesArrLocations.get(index);
|
2017-07-08 18:32:04 +02:00
|
|
|
f = FileLoader.getPathToAttach(location, avatarsDialogId != 0 || isEvent);
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (currentPathObject != null) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_DOCUMENT), currentFileNames[a]);
|
|
|
|
if (!f.exists()) {
|
|
|
|
f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), currentFileNames[a]);
|
|
|
|
}
|
2014-09-25 05:54:35 +02:00
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
if (f != null && f.exists()) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (isVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setBackgroundState(3, animated);
|
2014-10-28 18:07:44 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setBackgroundState(-1, animated);
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (isVideo) {
|
2014-10-28 18:07:44 +01:00
|
|
|
if (!FileLoader.getInstance().isLoadingFile(currentFileNames[a])) {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setBackgroundState(2, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setBackgroundState(1, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setBackgroundState(0, animated);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
Float progress = ImageLoader.getInstance().getFileProgress(currentFileNames[a]);
|
2014-10-28 18:07:44 +01:00
|
|
|
if (progress == null) {
|
|
|
|
progress = 0.0f;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[a].setProgress(progress, false);
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
|
|
|
if (a == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
canZoom = !imagesArrLocals.isEmpty() || (currentFileNames[0] != null && !isVideo && photoProgressViews[0].backgroundState != 0);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
boolean isLocalVideo = false;
|
|
|
|
if (!imagesArrLocals.isEmpty() && index >= 0 && index < imagesArrLocals.size()) {
|
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) object);
|
|
|
|
isLocalVideo = photoEntry.isVideo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isLocalVideo) {
|
|
|
|
photoProgressViews[a].setBackgroundState(3, animated);
|
|
|
|
} else {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, animated);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setIndexToImage(ImageReceiver imageReceiver, int index) {
|
2015-02-26 02:32:51 +01:00
|
|
|
imageReceiver.setOrientation(0, false);
|
2014-06-12 03:13:15 +02:00
|
|
|
if (!imagesArrLocals.isEmpty()) {
|
2015-02-01 19:51:02 +01:00
|
|
|
imageReceiver.setParentMessageObject(null);
|
2014-06-12 03:13:15 +02:00
|
|
|
if (index >= 0 && index < imagesArrLocals.size()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
Object object = imagesArrLocals.get(index);
|
|
|
|
int size = (int) (AndroidUtilities.getPhotoSize() / AndroidUtilities.density);
|
2014-06-12 03:13:15 +02:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (placeHolder == null) {
|
|
|
|
placeHolder = placeProvider.getThumbForPhoto(null, null, index);
|
|
|
|
}
|
|
|
|
String path = null;
|
2016-01-11 18:19:48 +01:00
|
|
|
TLRPC.Document document = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.FileLocation photo = null;
|
2015-01-02 23:15:07 +01:00
|
|
|
int imageSize = 0;
|
2016-01-11 18:19:48 +01:00
|
|
|
String filter = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean isVideo = false;
|
2015-01-02 23:15:07 +01:00
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
2015-02-26 02:32:51 +01:00
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
|
2017-07-08 18:32:04 +02:00
|
|
|
isVideo = photoEntry.isVideo;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (!photoEntry.isVideo) {
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
path = photoEntry.imagePath;
|
|
|
|
} else {
|
|
|
|
imageReceiver.setOrientation(photoEntry.orientation, false);
|
|
|
|
path = photoEntry.path;
|
|
|
|
}
|
|
|
|
filter = String.format(Locale.US, "%d_%d", size, size);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
|
|
|
path = "vthumb://" + photoEntry.imageId + ":" + photoEntry.path;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (object instanceof TLRPC.BotInlineResult) {
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.BotInlineResult botInlineResult = ((TLRPC.BotInlineResult) object);
|
|
|
|
if (botInlineResult.type.equals("video") || MessageObject.isVideoDocument(botInlineResult.document)) {
|
|
|
|
if (botInlineResult.document != null) {
|
|
|
|
photo = botInlineResult.document.thumb.location;
|
|
|
|
} else {
|
|
|
|
path = botInlineResult.thumb_url;
|
|
|
|
}
|
|
|
|
} else if (botInlineResult.type.equals("gif") && botInlineResult.document != null) {
|
|
|
|
document = botInlineResult.document;
|
|
|
|
imageSize = botInlineResult.document.size;
|
|
|
|
filter = "d";
|
|
|
|
} else if (botInlineResult.photo != null) {
|
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(botInlineResult.photo.sizes, AndroidUtilities.getPhotoSize());
|
|
|
|
photo = sizeFull.location;
|
|
|
|
imageSize = sizeFull.size;
|
|
|
|
filter = String.format(Locale.US, "%d_%d", size, size);
|
|
|
|
} else if (botInlineResult.content_url != null) {
|
|
|
|
if (botInlineResult.type.equals("gif")) {
|
|
|
|
filter = "d";
|
|
|
|
} else {
|
|
|
|
filter = String.format(Locale.US, "%d_%d", size, size);
|
|
|
|
}
|
|
|
|
path = botInlineResult.content_url;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
2015-02-26 02:32:51 +01:00
|
|
|
MediaController.SearchImage photoEntry = (MediaController.SearchImage) object;
|
|
|
|
if (photoEntry.imagePath != null) {
|
|
|
|
path = photoEntry.imagePath;
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (photoEntry.document != null) {
|
|
|
|
document = photoEntry.document;
|
|
|
|
imageSize = photoEntry.document.size;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
|
|
|
path = photoEntry.imageUrl;
|
2016-01-11 18:19:48 +01:00
|
|
|
imageSize = photoEntry.size;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
filter = "d";
|
|
|
|
}
|
|
|
|
if (document != null) {
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setImage(document, null, "d", placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, placeHolder == null ? document.thumb.location : null, String.format(Locale.US, "%d_%d", size, size), imageSize, null, 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (photo != null) {
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setImage(photo, null, filter, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, null, String.format(Locale.US, "%d_%d", size, size), imageSize, null, 0);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2017-07-08 18:32:04 +02:00
|
|
|
imageReceiver.setImage(path, filter, placeHolder != null ? new BitmapDrawable(null, placeHolder) : (isVideo && parentActivity != null ? parentActivity.getResources().getDrawable(R.drawable.nophotos) : null), null, imageSize);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap((Bitmap) null);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
} else {
|
|
|
|
int size[] = new int[1];
|
2017-03-31 01:58:05 +02:00
|
|
|
TLObject fileLocation = getFileLocation(index, size);
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
if (fileLocation != null) {
|
|
|
|
MessageObject messageObject = null;
|
|
|
|
if (!imagesArr.isEmpty()) {
|
|
|
|
messageObject = imagesArr.get(index);
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
imageReceiver.setParentMessageObject(messageObject);
|
|
|
|
if (messageObject != null) {
|
|
|
|
imageReceiver.setShouldGenerateQualityThumb(true);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
if (messageObject != null && messageObject.isVideo()) {
|
2015-02-01 19:51:02 +01:00
|
|
|
imageReceiver.setNeedsQualityThumb(true);
|
2016-03-06 02:49:31 +01:00
|
|
|
if (messageObject.photoThumbs != null && !messageObject.photoThumbs.isEmpty()) {
|
2014-06-12 03:13:15 +02:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.PhotoSize thumbLocation = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100);
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setImage(null, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation.location, "b", 0, null, 1);
|
2014-06-12 03:13:15 +02:00
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (messageObject != null && currentAnimation != null) {
|
|
|
|
imageReceiver.setImageBitmap(currentAnimation);
|
|
|
|
currentAnimation.setSecondParentView(containerView);
|
2014-06-12 03:13:15 +02:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setNeedsQualityThumb(true);
|
2014-06-11 01:05:54 +02:00
|
|
|
Bitmap placeHolder = null;
|
|
|
|
if (currentThumb != null && imageReceiver == centerImage) {
|
|
|
|
placeHolder = currentThumb;
|
|
|
|
}
|
2014-09-30 00:48:11 +02:00
|
|
|
if (size[0] == 0) {
|
|
|
|
size[0] = -1;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.PhotoSize thumbLocation = messageObject != null ? FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100) : null;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (thumbLocation != null && thumbLocation.location == fileLocation) {
|
|
|
|
thumbLocation = null;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setImage(fileLocation, null, null, placeHolder != null ? new BitmapDrawable(null, placeHolder) : null, thumbLocation != null ? thumbLocation.location : null, "b", size[0], null, avatarsDialogId != 0 || isEvent ? 1 : 0);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
imageReceiver.setNeedsQualityThumb(true);
|
2015-02-01 19:51:02 +01:00
|
|
|
imageReceiver.setParentMessageObject(null);
|
2014-06-12 03:13:15 +02:00
|
|
|
if (size[0] == 0) {
|
|
|
|
imageReceiver.setImageBitmap((Bitmap) null);
|
|
|
|
} else {
|
|
|
|
imageReceiver.setImageBitmap(parentActivity.getResources().getDrawable(R.drawable.photoview_placeholder));
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-11 02:22:42 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingImage(MessageObject object) {
|
2015-03-19 00:09:45 +01:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentMessageObject != null && currentMessageObject.getId() == object.getId();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingImage(TLRPC.FileLocation object) {
|
2014-11-06 22:34:47 +01:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentFileLocation != null && object.local_id == currentFileLocation.local_id && object.volume_id == currentFileLocation.volume_id && object.dc_id == currentFileLocation.dc_id;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public boolean isShowingImage(TLRPC.BotInlineResult object) {
|
|
|
|
return isVisible && !disableShowCheck && object != null && currentBotInlineResult != null && object.id == currentBotInlineResult.id;
|
|
|
|
}
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
public boolean isShowingImage(String object) {
|
2014-11-06 22:34:47 +01:00
|
|
|
return isVisible && !disableShowCheck && object != null && currentPathObject != null && object.equals(currentPathObject);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void setParentChatActivity(ChatActivity chatActivity) {
|
|
|
|
parentChatActivity = chatActivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean openPhoto(final MessageObject messageObject, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
|
|
|
|
return openPhoto(messageObject, null, null, null, 0, provider, null, dialogId, mergeDialogId);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean openPhoto(final TLRPC.FileLocation fileLocation, final PhotoViewerProvider provider) {
|
|
|
|
return openPhoto(null, fileLocation, null, null, 0, provider, null, 0, 0);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean openPhoto(final ArrayList<MessageObject> messages, final int index, long dialogId, long mergeDialogId, final PhotoViewerProvider provider) {
|
|
|
|
return openPhoto(messages.get(index), null, messages, null, index, provider, null, dialogId, mergeDialogId);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean openPhotoForSelect(final ArrayList<Object> photos, final int index, int type, final PhotoViewerProvider provider, ChatActivity chatActivity) {
|
2015-02-26 02:32:51 +01:00
|
|
|
sendPhotoType = type;
|
2017-07-23 14:56:38 +02:00
|
|
|
if (pickerViewSendButton != null) {
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) itemsLayout.getLayoutParams();
|
|
|
|
if (sendPhotoType == 1) {
|
|
|
|
pickerView.setPadding(0, AndroidUtilities.dp(14), 0, 0);
|
|
|
|
pickerViewSendButton.setImageResource(R.drawable.bigcheck);
|
|
|
|
pickerViewSendButton.setPadding(0, AndroidUtilities.dp(1), 0, 0);
|
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(16);
|
|
|
|
} else {
|
|
|
|
pickerView.setPadding(0, 0, 0, 0);
|
|
|
|
pickerViewSendButton.setImageResource(R.drawable.ic_send);
|
|
|
|
pickerViewSendButton.setPadding(AndroidUtilities.dp(4), 0, 0, 0);
|
|
|
|
layoutParams.bottomMargin = 0;
|
|
|
|
}
|
|
|
|
itemsLayout.setLayoutParams(layoutParams);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
return openPhoto(null, null, null, photos, index, provider, chatActivity, 0, 0);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
private boolean checkAnimation() {
|
|
|
|
if (animationInProgress != 0) {
|
|
|
|
if (Math.abs(transitionAnimationStartTime - System.currentTimeMillis()) >= 500) {
|
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
|
|
|
animationInProgress = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return animationInProgress != 0;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLocation fileLocation, final ArrayList<MessageObject> messages, final ArrayList<Object> photos, final int index, final PhotoViewerProvider provider, ChatActivity chatActivity, long dialogId, long mDialogId) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (parentActivity == null || isVisible || provider == null && checkAnimation() || messageObject == null && fileLocation == null && messages == null && photos == null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return false;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
final PlaceProviderObject object = provider.getPlaceForPhoto(messageObject, fileLocation, index);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (object == null && photos == null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return false;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
lastInsets = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (attachedToWindow) {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
|
|
|
wm.removeView(windowView);
|
|
|
|
} catch (Exception e) {
|
|
|
|
//don't promt
|
|
|
|
}
|
2014-07-23 01:27:00 +02:00
|
|
|
}
|
|
|
|
|
2014-11-21 11:59:05 +01:00
|
|
|
try {
|
2015-10-29 18:10:07 +01:00
|
|
|
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
|
|
|
|
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
|
|
|
|
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
|
|
|
} else {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
|
|
|
|
}
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
|
2015-10-29 18:10:07 +01:00
|
|
|
windowView.setFocusable(false);
|
|
|
|
containerView.setFocusable(false);
|
2014-11-21 11:59:05 +01:00
|
|
|
wm.addView(windowView, windowLayoutParams);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
return false;
|
2014-11-21 11:59:05 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
doneButtonPressed = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
parentChatActivity = chatActivity;
|
|
|
|
|
2014-11-21 11:59:05 +01:00
|
|
|
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, 1, 1));
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaCountDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
|
2016-06-24 12:27:15 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogPhotosLoaded);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.emojiDidLoaded);
|
2017-03-31 01:58:05 +02:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FilePreparingFailed);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2014-11-21 11:59:05 +01:00
|
|
|
|
|
|
|
placeProvider = provider;
|
2015-11-26 22:04:02 +01:00
|
|
|
mergeDialogId = mDialogId;
|
|
|
|
currentDialogId = dialogId;
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosAdapter.notifyDataSetChanged();
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
if (velocityTracker == null) {
|
|
|
|
velocityTracker = VelocityTracker.obtain();
|
|
|
|
}
|
|
|
|
|
|
|
|
isVisible = true;
|
|
|
|
toggleActionBar(true, false);
|
2017-12-08 18:35:59 +01:00
|
|
|
togglePhotosListView(false, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (object != null) {
|
|
|
|
disableShowCheck = true;
|
|
|
|
animationInProgress = 1;
|
2016-06-24 12:27:15 +02:00
|
|
|
if (messageObject != null) {
|
|
|
|
currentAnimation = object.imageReceiver.getAnimation();
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
final Rect drawRegion = object.imageReceiver.getDrawRegion();
|
|
|
|
int orientation = object.imageReceiver.getOrientation();
|
2016-10-11 13:57:01 +02:00
|
|
|
int animatedOrientation = object.imageReceiver.getAnimatedOrientation();
|
|
|
|
if (animatedOrientation != 0) {
|
|
|
|
orientation = animatedOrientation;
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
animatingImageView.setVisibility(View.VISIBLE);
|
|
|
|
animatingImageView.setRadius(object.radius);
|
|
|
|
animatingImageView.setOrientation(orientation);
|
|
|
|
animatingImageView.setNeedRadius(object.radius != 0);
|
|
|
|
animatingImageView.setImageBitmap(object.thumb);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
animatingImageView.setAlpha(1.0f);
|
|
|
|
animatingImageView.setPivotX(0.0f);
|
|
|
|
animatingImageView.setPivotY(0.0f);
|
|
|
|
animatingImageView.setScaleX(object.scale);
|
|
|
|
animatingImageView.setScaleY(object.scale);
|
|
|
|
animatingImageView.setTranslationX(object.viewX + drawRegion.left * object.scale);
|
|
|
|
animatingImageView.setTranslationY(object.viewY + drawRegion.top * object.scale);
|
2015-02-26 02:32:51 +01:00
|
|
|
final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
2015-10-29 18:10:07 +01:00
|
|
|
layoutParams.width = (drawRegion.right - drawRegion.left);
|
|
|
|
layoutParams.height = (drawRegion.bottom - drawRegion.top);
|
2015-02-26 02:32:51 +01:00
|
|
|
animatingImageView.setLayoutParams(layoutParams);
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
|
2016-10-11 13:57:01 +02:00
|
|
|
float scaleY = (float) (AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
|
2015-05-03 13:48:36 +02:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float width = layoutParams.width * scale;
|
|
|
|
float height = layoutParams.height * scale;
|
|
|
|
float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
|
2016-10-11 13:57:01 +02:00
|
|
|
float yPos = ((AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
|
2015-05-03 13:48:36 +02:00
|
|
|
int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
|
|
|
|
int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());
|
|
|
|
|
|
|
|
int coords2[] = new int[2];
|
|
|
|
object.parentView.getLocationInWindow(coords2);
|
2016-10-11 13:57:01 +02:00
|
|
|
int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight) - (object.viewY + drawRegion.top) + object.clipTopAddition;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (clipTop < 0) {
|
|
|
|
clipTop = 0;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
int clipBottom = (object.viewY + drawRegion.top + layoutParams.height) - (coords2[1] + object.parentView.getHeight() - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)) + object.clipBottomAddition;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (clipBottom < 0) {
|
|
|
|
clipBottom = 0;
|
|
|
|
}
|
|
|
|
clipTop = Math.max(clipTop, clipVertical);
|
|
|
|
clipBottom = Math.max(clipBottom, clipVertical);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
animationValues[0][0] = animatingImageView.getScaleX();
|
|
|
|
animationValues[0][1] = animatingImageView.getScaleY();
|
|
|
|
animationValues[0][2] = animatingImageView.getTranslationX();
|
|
|
|
animationValues[0][3] = animatingImageView.getTranslationY();
|
2015-10-29 18:10:07 +01:00
|
|
|
animationValues[0][4] = clipHorizontal * object.scale;
|
|
|
|
animationValues[0][5] = clipTop * object.scale;
|
|
|
|
animationValues[0][6] = clipBottom * object.scale;
|
2015-05-03 13:48:36 +02:00
|
|
|
animationValues[0][7] = animatingImageView.getRadius();
|
|
|
|
|
|
|
|
animationValues[1][0] = scale;
|
|
|
|
animationValues[1][1] = scale;
|
|
|
|
animationValues[1][2] = xPos;
|
|
|
|
animationValues[1][3] = yPos;
|
|
|
|
animationValues[1][4] = 0;
|
|
|
|
animationValues[1][5] = 0;
|
|
|
|
animationValues[1][6] = 0;
|
|
|
|
animationValues[1][7] = 0;
|
|
|
|
|
|
|
|
animatingImageView.setAnimationProgress(0);
|
|
|
|
backgroundDrawable.setAlpha(0);
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setAlpha(0);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
final AnimatorSet animatorSet = new AnimatorSet();
|
2015-05-03 13:48:36 +02:00
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
|
|
|
|
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0, 255),
|
|
|
|
ObjectAnimator.ofFloat(containerView, "alpha", 0.0f, 1.0f)
|
2015-05-03 13:48:36 +02:00
|
|
|
);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (containerView == null || windowView == null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
animationInProgress = 0;
|
|
|
|
transitionAnimationStartTime = 0;
|
|
|
|
setImages();
|
|
|
|
containerView.invalidate();
|
|
|
|
animatingImageView.setVisibility(View.GONE);
|
|
|
|
if (showAfterAnimation != null) {
|
|
|
|
showAfterAnimation.imageReceiver.setVisible(true, true);
|
|
|
|
}
|
|
|
|
if (hideAfterAnimation != null) {
|
|
|
|
hideAfterAnimation.imageReceiver.setVisible(false, true);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (photos != null && sendPhotoType != 3) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
|
|
|
|
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
|
|
|
} else {
|
|
|
|
windowLayoutParams.flags = 0;
|
|
|
|
}
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
|
2015-10-29 18:10:07 +01:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
|
|
|
wm.updateViewLayout(windowView, windowLayoutParams);
|
|
|
|
windowView.setFocusable(true);
|
|
|
|
containerView.setFocusable(true);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
};
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
animatorSet.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-21 23:27:27 +02:00
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(false);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-06-24 12:27:15 +02:00
|
|
|
NotificationCenter.getInstance().setAllowedNotificationsDutingAnimation(new int[]{NotificationCenter.dialogsNeedReload, NotificationCenter.closeChats, NotificationCenter.mediaCountDidLoaded, NotificationCenter.mediaDidLoaded, NotificationCenter.dialogPhotosLoaded});
|
2015-05-21 23:27:27 +02:00
|
|
|
NotificationCenter.getInstance().setAnimationInProgress(true);
|
2015-05-03 13:48:36 +02:00
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
backgroundDrawable.drawRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
disableShowCheck = false;
|
|
|
|
object.imageReceiver.setVisible(false, true);
|
|
|
|
}
|
|
|
|
};
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (photos != null && sendPhotoType != 3) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
|
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
|
|
|
|
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
|
|
|
|
} else {
|
|
|
|
windowLayoutParams.flags = 0;
|
|
|
|
}
|
|
|
|
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION;
|
2015-10-29 18:10:07 +01:00
|
|
|
wm.updateViewLayout(windowView, windowLayoutParams);
|
|
|
|
windowView.setFocusable(true);
|
|
|
|
containerView.setFocusable(true);
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
backgroundDrawable.setAlpha(255);
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setAlpha(1.0f);
|
2015-02-26 02:32:51 +01:00
|
|
|
onPhotoShow(messageObject, fileLocation, messages, photos, index, object);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
return true;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public void closePhoto(boolean animated, boolean fromEditMode) {
|
|
|
|
if (!fromEditMode && currentEditMode != 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentEditMode == 3 && photoPaintView != null) {
|
|
|
|
photoPaintView.maybeShowDismissalAlert(this, parentActivity, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
switchToEditMode(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
|
|
|
switchToEditMode(0);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
if (qualityChooseView != null && qualityChooseView.getTag() != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
qualityPicker.cancelButton.callOnClick();
|
|
|
|
return;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
try {
|
|
|
|
if (visibleDialog != null) {
|
|
|
|
visibleDialog.dismiss();
|
|
|
|
visibleDialog = null;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode != 0) {
|
|
|
|
if (currentEditMode == 2) {
|
|
|
|
photoFilterView.shutdown();
|
|
|
|
containerView.removeView(photoFilterView);
|
|
|
|
photoFilterView = null;
|
|
|
|
} else if (currentEditMode == 1) {
|
|
|
|
editorDoneLayout.setVisibility(View.GONE);
|
|
|
|
photoCropView.setVisibility(View.GONE);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
currentEditMode = 0;
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
if (parentActivity == null || !isVisible || checkAnimation() || placeProvider == null) {
|
2014-06-07 01:35:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (captionEditText.hideActionMode() && !fromEditMode) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
releasePlayer();
|
2015-05-03 13:48:36 +02:00
|
|
|
captionEditText.onDestroy();
|
|
|
|
parentChatActivity = null;
|
2014-08-22 16:24:33 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidFailedLoad);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileLoadProgressChanged);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaCountDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaDidLoaded);
|
2016-06-24 12:27:15 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.dialogPhotosLoaded);
|
2015-05-03 13:48:36 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.emojiDidLoaded);
|
2017-03-31 01:58:05 +02:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FilePreparingFailed);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.FileNewChunkAvailable);
|
2015-09-24 22:52:02 +02:00
|
|
|
ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
isActionBarVisible = false;
|
|
|
|
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.recycle();
|
|
|
|
velocityTracker = null;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
ConnectionsManager.getInstance().cancelRequestsForGuid(classGuid);
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
final PlaceProviderObject object = placeProvider.getPlaceForPhoto(currentMessageObject, currentFileLocation, currentIndex);
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
if (animated) {
|
2014-06-12 17:53:20 +02:00
|
|
|
animationInProgress = 1;
|
2014-06-07 01:35:21 +02:00
|
|
|
animatingImageView.setVisibility(View.VISIBLE);
|
2014-06-12 21:55:13 +02:00
|
|
|
containerView.invalidate();
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
final ViewGroup.LayoutParams layoutParams = animatingImageView.getLayoutParams();
|
2014-08-22 16:24:33 +02:00
|
|
|
Rect drawRegion = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
int orientation = centerImage.getOrientation();
|
|
|
|
int animatedOrientation = 0;
|
|
|
|
if (object != null && object.imageReceiver != null) {
|
|
|
|
animatedOrientation = object.imageReceiver.getAnimatedOrientation();
|
|
|
|
}
|
|
|
|
if (animatedOrientation != 0) {
|
|
|
|
orientation = animatedOrientation;
|
|
|
|
}
|
|
|
|
animatingImageView.setOrientation(orientation);
|
2014-06-11 01:05:54 +02:00
|
|
|
if (object != null) {
|
2014-11-17 03:44:57 +01:00
|
|
|
animatingImageView.setNeedRadius(object.radius != 0);
|
2014-08-22 16:24:33 +02:00
|
|
|
drawRegion = object.imageReceiver.getDrawRegion();
|
|
|
|
layoutParams.width = drawRegion.right - drawRegion.left;
|
|
|
|
layoutParams.height = drawRegion.bottom - drawRegion.top;
|
2014-06-11 01:05:54 +02:00
|
|
|
animatingImageView.setImageBitmap(object.thumb);
|
|
|
|
} else {
|
2014-11-17 03:44:57 +01:00
|
|
|
animatingImageView.setNeedRadius(false);
|
2014-08-22 16:24:33 +02:00
|
|
|
layoutParams.width = centerImage.getImageWidth();
|
|
|
|
layoutParams.height = centerImage.getImageHeight();
|
2014-06-11 01:05:54 +02:00
|
|
|
animatingImageView.setImageBitmap(centerImage.getBitmap());
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
animatingImageView.setLayoutParams(layoutParams);
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
float scaleX = (float) AndroidUtilities.displaySize.x / layoutParams.width;
|
2016-10-11 13:57:01 +02:00
|
|
|
float scaleY = (float) (AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) / layoutParams.height;
|
2014-06-11 01:05:54 +02:00
|
|
|
float scale2 = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
float width = layoutParams.width * scale * scale2;
|
|
|
|
float height = layoutParams.height * scale * scale2;
|
2014-07-03 00:39:05 +02:00
|
|
|
float xPos = (AndroidUtilities.displaySize.x - width) / 2.0f;
|
2016-10-11 13:57:01 +02:00
|
|
|
float yPos = ((AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0)) - height) / 2.0f;
|
2016-06-24 12:27:15 +02:00
|
|
|
animatingImageView.setTranslationX(xPos + translationX);
|
|
|
|
animatingImageView.setTranslationY(yPos + translationY);
|
|
|
|
animatingImageView.setScaleX(scale * scale2);
|
|
|
|
animatingImageView.setScaleY(scale * scale2);
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
if (object != null) {
|
2014-11-06 22:34:47 +01:00
|
|
|
object.imageReceiver.setVisible(false, true);
|
2014-08-22 16:24:33 +02:00
|
|
|
int clipHorizontal = Math.abs(drawRegion.left - object.imageReceiver.getImageX());
|
|
|
|
int clipVertical = Math.abs(drawRegion.top - object.imageReceiver.getImageY());
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
int coords2[] = new int[2];
|
|
|
|
object.parentView.getLocationInWindow(coords2);
|
2016-10-11 13:57:01 +02:00
|
|
|
int clipTop = coords2[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight) - (object.viewY + drawRegion.top) + object.clipTopAddition;
|
2014-06-11 01:05:54 +02:00
|
|
|
if (clipTop < 0) {
|
|
|
|
clipTop = 0;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
int clipBottom = (object.viewY + drawRegion.top + (drawRegion.bottom - drawRegion.top)) - (coords2[1] + object.parentView.getHeight() - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight)) + object.clipBottomAddition;
|
2014-06-11 01:05:54 +02:00
|
|
|
if (clipBottom < 0) {
|
|
|
|
clipBottom = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
clipTop = Math.max(clipTop, clipVertical);
|
|
|
|
clipBottom = Math.max(clipBottom, clipVertical);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
animationValues[0][0] = animatingImageView.getScaleX();
|
|
|
|
animationValues[0][1] = animatingImageView.getScaleY();
|
|
|
|
animationValues[0][2] = animatingImageView.getTranslationX();
|
|
|
|
animationValues[0][3] = animatingImageView.getTranslationY();
|
2015-05-03 13:48:36 +02:00
|
|
|
animationValues[0][4] = 0;
|
|
|
|
animationValues[0][5] = 0;
|
|
|
|
animationValues[0][6] = 0;
|
|
|
|
animationValues[0][7] = 0;
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
animationValues[1][0] = object.scale;
|
|
|
|
animationValues[1][1] = object.scale;
|
|
|
|
animationValues[1][2] = object.viewX + drawRegion.left * object.scale;
|
|
|
|
animationValues[1][3] = object.viewY + drawRegion.top * object.scale;
|
|
|
|
animationValues[1][4] = clipHorizontal * object.scale;
|
|
|
|
animationValues[1][5] = clipTop * object.scale;
|
|
|
|
animationValues[1][6] = clipBottom * object.scale;
|
2015-05-03 13:48:36 +02:00
|
|
|
animationValues[1][7] = object.radius;
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(animatingImageView, "animationProgress", 0.0f, 1.0f),
|
|
|
|
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimator.ofFloat(containerView, "alpha", 0.0f)
|
2014-06-11 01:05:54 +02:00
|
|
|
);
|
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
int h = (AndroidUtilities.displaySize.y + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0));
|
2014-06-11 01:05:54 +02:00
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimator.ofFloat(animatingImageView, "alpha", 0.0f),
|
2016-10-11 13:57:01 +02:00
|
|
|
ObjectAnimator.ofFloat(animatingImageView, "translationY", translationY >= 0 ? h : -h),
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, "alpha", 0.0f)
|
2014-06-11 01:05:54 +02:00
|
|
|
);
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
animationInProgress = 0;
|
|
|
|
onPhotoClosed(object);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
animatorSet.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2014-06-07 01:35:21 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
});
|
2014-07-03 00:39:05 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
2016-06-24 12:27:15 +02:00
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
2015-02-01 19:51:02 +01:00
|
|
|
animatorSet.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(containerView, "scaleX", 0.9f),
|
|
|
|
ObjectAnimator.ofFloat(containerView, "scaleY", 0.9f),
|
|
|
|
ObjectAnimator.ofInt(backgroundDrawable, "alpha", 0),
|
|
|
|
ObjectAnimator.ofFloat(containerView, "alpha", 0.0f)
|
2015-02-01 19:51:02 +01:00
|
|
|
);
|
2014-06-12 17:53:20 +02:00
|
|
|
animationInProgress = 2;
|
2014-07-03 00:39:05 +02:00
|
|
|
animationEndRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (containerView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
animationInProgress = 0;
|
|
|
|
onPhotoClosed(object);
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.setScaleX(1.0f);
|
|
|
|
containerView.setScaleY(1.0f);
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
};
|
2015-02-01 19:51:02 +01:00
|
|
|
animatorSet.setDuration(200);
|
2017-03-31 01:58:05 +02:00
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2014-06-12 17:53:20 +02:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2014-07-03 00:39:05 +02:00
|
|
|
if (animationEndRunnable != null) {
|
|
|
|
animationEndRunnable.run();
|
|
|
|
animationEndRunnable = null;
|
2014-06-13 00:37:05 +02:00
|
|
|
}
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
|
|
|
});
|
2014-07-03 00:39:05 +02:00
|
|
|
transitionAnimationStartTime = System.currentTimeMillis();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
containerView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
animatorSet.start();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
currentAnimation.setSecondParentView(null);
|
|
|
|
currentAnimation = null;
|
|
|
|
centerImage.setImageBitmap((Drawable) null);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (!placeProvider.canScrollAway()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
placeProvider.cancelButtonPressed();
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2014-07-12 00:14:13 +02:00
|
|
|
public void destroyPhotoViewer() {
|
|
|
|
if (parentActivity == null || windowView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
releasePlayer();
|
2014-07-12 00:14:13 +02:00
|
|
|
try {
|
|
|
|
if (windowView.getParent() != null) {
|
2014-07-23 01:27:00 +02:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2014-07-12 00:14:13 +02:00
|
|
|
wm.removeViewImmediate(windowView);
|
|
|
|
}
|
|
|
|
windowView = null;
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-07-12 00:14:13 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (captionEditText != null) {
|
|
|
|
captionEditText.onDestroy();
|
|
|
|
}
|
2014-07-12 00:14:13 +02:00
|
|
|
Instance = null;
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private void onPhotoClosed(PlaceProviderObject object) {
|
2014-12-04 21:27:06 +01:00
|
|
|
isVisible = false;
|
2014-06-11 02:22:42 +02:00
|
|
|
disableShowCheck = true;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentMessageObject = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
currentBotInlineResult = null;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentFileLocation = null;
|
2014-06-12 03:13:15 +02:00
|
|
|
currentPathObject = null;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentThumb = null;
|
2017-03-31 01:58:05 +02:00
|
|
|
parentAlert = null;
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
currentAnimation.setSecondParentView(null);
|
|
|
|
currentAnimation = null;
|
|
|
|
}
|
2014-10-28 18:07:44 +01:00
|
|
|
for (int a = 0; a < 3; a++) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (photoProgressViews[a] != null) {
|
|
|
|
photoProgressViews[a].setBackgroundState(-1, false);
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
requestVideoPreview(0);
|
|
|
|
if (videoTimelineView != null) {
|
|
|
|
videoTimelineView.destroy();
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
centerImage.setImageBitmap((Bitmap) null);
|
|
|
|
leftImage.setImageBitmap((Bitmap) null);
|
|
|
|
rightImage.setImageBitmap((Bitmap) null);
|
2014-06-11 01:05:54 +02:00
|
|
|
containerView.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-06-11 02:22:42 +02:00
|
|
|
animatingImageView.setImageBitmap(null);
|
2014-06-12 17:53:20 +02:00
|
|
|
try {
|
|
|
|
if (windowView.getParent() != null) {
|
2014-07-23 01:27:00 +02:00
|
|
|
WindowManager wm = (WindowManager) parentActivity.getSystemService(Context.WINDOW_SERVICE);
|
2014-06-12 17:53:20 +02:00
|
|
|
wm.removeView(windowView);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-06-12 17:53:20 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
});
|
2014-06-11 02:22:42 +02:00
|
|
|
if (placeProvider != null) {
|
|
|
|
placeProvider.willHidePhotoViewer();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.clear();
|
2014-06-11 02:22:42 +02:00
|
|
|
placeProvider = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
selectedPhotosAdapter.notifyDataSetChanged();
|
2014-06-11 02:22:42 +02:00
|
|
|
disableShowCheck = false;
|
2014-12-04 21:27:06 +01:00
|
|
|
if (object != null) {
|
|
|
|
object.imageReceiver.setVisible(true, true);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void redraw(final int count) {
|
|
|
|
if (count < 6) {
|
|
|
|
if (containerView != null) {
|
|
|
|
containerView.invalidate();
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
redraw(count + 1);
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onResume() {
|
|
|
|
redraw(0); //workaround for camera bug
|
2017-03-31 01:58:05 +02:00
|
|
|
if (videoPlayer != null) {
|
|
|
|
videoPlayer.seekTo(videoPlayer.getCurrentPosition() + 1);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
public void onPause() {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (currentAnimation != null) {
|
|
|
|
closePhoto(false, false);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lastTitle != null) {
|
2016-05-25 23:49:47 +02:00
|
|
|
closeCaptionEnter(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-07 01:35:21 +02:00
|
|
|
public boolean isVisible() {
|
2015-01-02 23:15:07 +01:00
|
|
|
return isVisible && placeProvider != null;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private void updateMinMax(float scale) {
|
2015-02-26 02:32:51 +01:00
|
|
|
int maxW = (int) (centerImage.getImageWidth() * scale - getContainerViewWidth()) / 2;
|
|
|
|
int maxH = (int) (centerImage.getImageHeight() * scale - getContainerViewHeight()) / 2;
|
2014-06-11 01:05:54 +02:00
|
|
|
if (maxW > 0) {
|
|
|
|
minX = -maxW;
|
|
|
|
maxX = maxW;
|
|
|
|
} else {
|
|
|
|
minX = maxX = 0;
|
|
|
|
}
|
|
|
|
if (maxH > 0) {
|
|
|
|
minY = -maxH;
|
|
|
|
maxY = maxH;
|
|
|
|
} else {
|
|
|
|
minY = maxY = 0;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
maxX += photoCropView.getLimitX();
|
|
|
|
maxY += photoCropView.getLimitY();
|
|
|
|
minX -= photoCropView.getLimitWidth();
|
|
|
|
minY -= photoCropView.getLimitHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getAdditionX() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentEditMode != 0 && currentEditMode != 3) {
|
2015-02-26 02:32:51 +01:00
|
|
|
return AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getAdditionY() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentEditMode == 3) {
|
2017-07-23 14:56:38 +02:00
|
|
|
return AndroidUtilities.dp(8) + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentEditMode != 0) {
|
|
|
|
return AndroidUtilities.dp(14) + (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewWidth() {
|
|
|
|
return getContainerViewWidth(currentEditMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewWidth(int mode) {
|
|
|
|
int width = containerView.getWidth();
|
2016-10-11 13:57:01 +02:00
|
|
|
if (mode != 0 && mode != 3) {
|
2015-02-26 02:32:51 +01:00
|
|
|
width -= AndroidUtilities.dp(28);
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewHeight() {
|
|
|
|
return getContainerViewHeight(currentEditMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getContainerViewHeight(int mode) {
|
2016-10-11 13:57:01 +02:00
|
|
|
int height = AndroidUtilities.displaySize.y;
|
|
|
|
if (mode == 0 && Build.VERSION.SDK_INT >= 21) {
|
|
|
|
height += AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (mode == 1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
height -= AndroidUtilities.dp(48 + 32 + 64);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (mode == 2) {
|
2017-07-23 14:56:38 +02:00
|
|
|
height -= AndroidUtilities.dp(154 + 60);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (mode == 3) {
|
|
|
|
height -= AndroidUtilities.dp(48) + ActionBar.getCurrentActionBarHeight();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
return height;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private boolean onTouchEvent(MotionEvent ev) {
|
2014-06-12 17:53:20 +02:00
|
|
|
if (animationInProgress != 0 || animationStartTime != 0) {
|
2014-11-19 16:17:24 +01:00
|
|
|
return false;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 2) {
|
|
|
|
photoFilterView.onTouch(ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentEditMode == 1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return true;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (captionEditText.isPopupShowing() || captionEditText.isKeyboardVisible()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (ev.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
closeCaptionEnter(true);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 0 && ev.getPointerCount() == 1 && gestureDetector.onTouchEvent(ev)) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (doubleTap) {
|
|
|
|
doubleTap = false;
|
|
|
|
moving = false;
|
|
|
|
zooming = false;
|
|
|
|
checkMinMax(false);
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN || ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
discardTap = false;
|
2014-06-21 23:46:11 +02:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
}
|
2014-11-19 16:17:24 +01:00
|
|
|
if (!draggingDown && !changingPage) {
|
|
|
|
if (canZoom && ev.getPointerCount() == 2) {
|
2014-06-11 01:05:54 +02:00
|
|
|
pinchStartDistance = (float) Math.hypot(ev.getX(1) - ev.getX(0), ev.getY(1) - ev.getY(0));
|
|
|
|
pinchStartScale = scale;
|
|
|
|
pinchCenterX = (ev.getX(0) + ev.getX(1)) / 2.0f;
|
|
|
|
pinchCenterY = (ev.getY(0) + ev.getY(1)) / 2.0f;
|
|
|
|
pinchStartX = translationX;
|
|
|
|
pinchStartY = translationY;
|
|
|
|
zooming = true;
|
|
|
|
moving = false;
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
} else if (ev.getPointerCount() == 1) {
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
dragY = moveStartY = ev.getY();
|
|
|
|
draggingDown = false;
|
|
|
|
canDragDown = true;
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.cancelAnimationRunnable();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
if (canZoom && ev.getPointerCount() == 2 && !draggingDown && zooming && !changingPage) {
|
2015-02-01 19:51:02 +01:00
|
|
|
discardTap = true;
|
|
|
|
scale = (float) Math.hypot(ev.getX(1) - ev.getX(0), ev.getY(1) - ev.getY(0)) / pinchStartDistance * pinchStartScale;
|
2015-02-26 02:32:51 +01:00
|
|
|
translationX = (pinchCenterX - getContainerViewWidth() / 2) - ((pinchCenterX - getContainerViewWidth() / 2) - pinchStartX) * (scale / pinchStartScale);
|
|
|
|
translationY = (pinchCenterY - getContainerViewHeight() / 2) - ((pinchCenterY - getContainerViewHeight() / 2) - pinchStartY) * (scale / pinchStartScale);
|
2014-06-11 01:05:54 +02:00
|
|
|
updateMinMax(scale);
|
|
|
|
containerView.invalidate();
|
|
|
|
} else if (ev.getPointerCount() == 1) {
|
|
|
|
if (velocityTracker != null) {
|
|
|
|
velocityTracker.addMovement(ev);
|
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
float dx = Math.abs(ev.getX() - moveStartX);
|
|
|
|
float dy = Math.abs(ev.getY() - dragY);
|
2015-02-01 19:51:02 +01:00
|
|
|
if (dx > AndroidUtilities.dp(3) || dy > AndroidUtilities.dp(3)) {
|
|
|
|
discardTap = true;
|
2017-07-23 14:56:38 +02:00
|
|
|
if (qualityChooseView != null && qualityChooseView.getVisibility() == View.VISIBLE) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (placeProvider.canScrollAway() && currentEditMode == 0 && canDragDown && !draggingDown && scale == 1 && dy >= AndroidUtilities.dp(30) && dy / 2 > dx) {
|
2014-06-07 01:35:21 +02:00
|
|
|
draggingDown = true;
|
2014-06-11 01:05:54 +02:00
|
|
|
moving = false;
|
2014-06-07 01:35:21 +02:00
|
|
|
dragY = ev.getY();
|
2014-08-29 23:06:04 +02:00
|
|
|
if (isActionBarVisible && canShowBottom) {
|
2014-06-07 01:35:21 +02:00
|
|
|
toggleActionBar(false, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (pickerView.getVisibility() == View.VISIBLE) {
|
2015-02-01 19:51:02 +01:00
|
|
|
toggleActionBar(false, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
togglePhotosListView(false, true);
|
2015-01-02 23:15:07 +01:00
|
|
|
toggleCheckImageView(false);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
return true;
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (draggingDown) {
|
|
|
|
translationY = ev.getY() - dragY;
|
|
|
|
containerView.invalidate();
|
2014-11-19 16:17:24 +01:00
|
|
|
} else if (!invalidCoords && animationStartTime == 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
float moveDx = moveStartX - ev.getX();
|
|
|
|
float moveDy = moveStartY - ev.getY();
|
2015-02-26 02:32:51 +01:00
|
|
|
if (moving || currentEditMode != 0 || scale == 1 && Math.abs(moveDy) + AndroidUtilities.dp(12) < Math.abs(moveDx) || scale != 1) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (!moving) {
|
|
|
|
moveDx = 0;
|
|
|
|
moveDy = 0;
|
|
|
|
moving = true;
|
|
|
|
canDragDown = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
moveStartY = ev.getY();
|
|
|
|
updateMinMax(scale);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (translationX < minX && (currentEditMode != 0 || !rightImage.hasImage()) || translationX > maxX && (currentEditMode != 0 || !leftImage.hasImage())) {
|
2014-06-11 01:05:54 +02:00
|
|
|
moveDx /= 3.0f;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (maxY == 0 && minY == 0 && currentEditMode == 0) {
|
2014-06-21 23:46:11 +02:00
|
|
|
if (translationY - moveDy < minY) {
|
|
|
|
translationY = minY;
|
|
|
|
moveDy = 0;
|
|
|
|
} else if (translationY - moveDy > maxY) {
|
|
|
|
translationY = maxY;
|
|
|
|
moveDy = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (translationY < minY || translationY > maxY) {
|
|
|
|
moveDy /= 3.0f;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
translationX -= moveDx;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (scale != 1 || currentEditMode != 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
translationY -= moveDy;
|
|
|
|
}
|
|
|
|
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
invalidCoords = false;
|
|
|
|
moveStartX = ev.getX();
|
|
|
|
moveStartY = ev.getY();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
} else if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL || ev.getActionMasked() == MotionEvent.ACTION_UP || ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.startAnimationRunnable();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
if (zooming) {
|
|
|
|
invalidCoords = true;
|
|
|
|
if (scale < 1.0f) {
|
|
|
|
updateMinMax(1.0f);
|
2014-06-11 01:33:45 +02:00
|
|
|
animateTo(1.0f, 0, 0, true);
|
2015-02-01 19:51:02 +01:00
|
|
|
} else if (scale > 3.0f) {
|
2015-02-26 02:32:51 +01:00
|
|
|
float atx = (pinchCenterX - getContainerViewWidth() / 2) - ((pinchCenterX - getContainerViewWidth() / 2) - pinchStartX) * (3.0f / pinchStartScale);
|
|
|
|
float aty = (pinchCenterY - getContainerViewHeight() / 2) - ((pinchCenterY - getContainerViewHeight() / 2) - pinchStartY) * (3.0f / pinchStartScale);
|
2014-06-11 01:05:54 +02:00
|
|
|
updateMinMax(3.0f);
|
|
|
|
if (atx < minX) {
|
|
|
|
atx = minX;
|
|
|
|
} else if (atx > maxX) {
|
|
|
|
atx = maxX;
|
|
|
|
}
|
|
|
|
if (aty < minY) {
|
|
|
|
aty = minY;
|
|
|
|
} else if (aty > maxY) {
|
|
|
|
aty = maxY;
|
|
|
|
}
|
2014-06-11 01:33:45 +02:00
|
|
|
animateTo(3.0f, atx, aty, true);
|
|
|
|
} else {
|
|
|
|
checkMinMax(true);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
zooming = false;
|
2014-06-07 01:35:21 +02:00
|
|
|
} else if (draggingDown) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (Math.abs(dragY - ev.getY()) > getContainerViewHeight() / 6.0f) {
|
|
|
|
closePhoto(true, false);
|
2014-06-07 01:35:21 +02:00
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (pickerView.getVisibility() == View.VISIBLE) {
|
2015-02-01 19:51:02 +01:00
|
|
|
toggleActionBar(true, true);
|
2015-01-02 23:15:07 +01:00
|
|
|
toggleCheckImageView(true);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
animateTo(1, 0, 0, false);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
draggingDown = false;
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (moving) {
|
|
|
|
float moveToX = translationX;
|
|
|
|
float moveToY = translationY;
|
|
|
|
updateMinMax(scale);
|
|
|
|
moving = false;
|
|
|
|
canDragDown = true;
|
|
|
|
float velocity = 0;
|
|
|
|
if (velocityTracker != null && scale == 1) {
|
|
|
|
velocityTracker.computeCurrentVelocity(1000);
|
|
|
|
velocity = velocityTracker.getXVelocity();
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 0) {
|
|
|
|
if ((translationX < minX - getContainerViewWidth() / 3 || velocity < -AndroidUtilities.dp(650)) && rightImage.hasImage()) {
|
|
|
|
goToNext();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((translationX > maxX + getContainerViewWidth() / 3 || velocity > AndroidUtilities.dp(650)) && leftImage.hasImage()) {
|
|
|
|
goToPrev();
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (translationX < minX) {
|
|
|
|
moveToX = minX;
|
|
|
|
} else if (translationX > maxX) {
|
|
|
|
moveToX = maxX;
|
|
|
|
}
|
|
|
|
if (translationY < minY) {
|
|
|
|
moveToY = minY;
|
|
|
|
} else if (translationY > maxY) {
|
|
|
|
moveToY = maxY;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
animateTo(scale, moveToX, moveToY, false);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:33:45 +02:00
|
|
|
private void checkMinMax(boolean zoom) {
|
|
|
|
float moveToX = translationX;
|
|
|
|
float moveToY = translationY;
|
|
|
|
updateMinMax(scale);
|
|
|
|
if (translationX < minX) {
|
|
|
|
moveToX = minX;
|
|
|
|
} else if (translationX > maxX) {
|
|
|
|
moveToX = maxX;
|
|
|
|
}
|
|
|
|
if (translationY < minY) {
|
|
|
|
moveToY = minY;
|
|
|
|
} else if (translationY > maxY) {
|
|
|
|
moveToY = maxY;
|
|
|
|
}
|
|
|
|
animateTo(scale, moveToX, moveToY, zoom);
|
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
private void goToNext() {
|
|
|
|
float extra = 0;
|
|
|
|
if (scale != 1) {
|
2015-02-26 02:32:51 +01:00
|
|
|
extra = (getContainerViewWidth() - centerImage.getImageWidth()) / 2 * scale;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
switchImageAfterAnimation = 1;
|
2016-10-11 13:57:01 +02:00
|
|
|
animateTo(scale, minX - getContainerViewWidth() - extra - AndroidUtilities.dp(30) / 2, translationY, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void goToPrev() {
|
|
|
|
float extra = 0;
|
|
|
|
if (scale != 1) {
|
2015-02-26 02:32:51 +01:00
|
|
|
extra = (getContainerViewWidth() - centerImage.getImageWidth()) / 2 * scale;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
switchImageAfterAnimation = 2;
|
2016-10-11 13:57:01 +02:00
|
|
|
animateTo(scale, maxX + getContainerViewWidth() + extra + AndroidUtilities.dp(30) / 2, translationY, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom) {
|
|
|
|
animateTo(newScale, newTx, newTy, isZoom, 250);
|
2014-06-11 01:33:45 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom, int duration) {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (scale == newScale && translationX == newTx && translationY == newTy) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-11 01:33:45 +02:00
|
|
|
zoomAnimation = isZoom;
|
2014-06-11 01:05:54 +02:00
|
|
|
animateToScale = newScale;
|
|
|
|
animateToX = newTx;
|
|
|
|
animateToY = newTy;
|
|
|
|
animationStartTime = System.currentTimeMillis();
|
2016-06-24 12:27:15 +02:00
|
|
|
imageMoveAnimation = new AnimatorSet();
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation.playTogether(
|
2016-06-24 12:27:15 +02:00
|
|
|
ObjectAnimator.ofFloat(this, "animationValue", 0, 1)
|
2015-02-26 02:32:51 +01:00
|
|
|
);
|
|
|
|
imageMoveAnimation.setInterpolator(interpolator);
|
|
|
|
imageMoveAnimation.setDuration(duration);
|
2017-03-31 01:58:05 +02:00
|
|
|
imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
|
2015-02-26 02:32:51 +01:00
|
|
|
@Override
|
2016-06-24 12:27:15 +02:00
|
|
|
public void onAnimationEnd(Animator animation) {
|
2015-02-26 02:32:51 +01:00
|
|
|
imageMoveAnimation = null;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
imageMoveAnimation.start();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public void setAnimationValue(float value) {
|
|
|
|
animationValue = value;
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getAnimationValue() {
|
|
|
|
return animationValue;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void hideHint() {
|
|
|
|
hintAnimation = new AnimatorSet();
|
|
|
|
hintAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(hintTextView, "alpha", 0.0f)
|
|
|
|
);
|
|
|
|
hintAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(hintAnimation)) {
|
|
|
|
hintAnimation = null;
|
|
|
|
hintHideRunnable = null;
|
|
|
|
if (hintTextView != null) {
|
|
|
|
hintTextView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(hintAnimation)) {
|
|
|
|
hintHideRunnable = null;
|
|
|
|
hintHideRunnable = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
hintAnimation.setDuration(300);
|
|
|
|
hintAnimation.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showHint(boolean hide, boolean enabled) {
|
|
|
|
if (containerView == null || hide && hintTextView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (hintTextView == null) {
|
|
|
|
hintTextView = new TextView(containerView.getContext());
|
|
|
|
hintTextView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), Theme.getColor(Theme.key_chat_gifSaveHintBackground)));
|
|
|
|
hintTextView.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
|
|
|
|
hintTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
hintTextView.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(7), AndroidUtilities.dp(8), AndroidUtilities.dp(7));
|
|
|
|
hintTextView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
hintTextView.setAlpha(0.0f);
|
|
|
|
containerView.addView(hintTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 5, 0, 5, 3));
|
|
|
|
}
|
|
|
|
if (hide) {
|
|
|
|
if (hintAnimation != null) {
|
|
|
|
hintAnimation.cancel();
|
|
|
|
hintAnimation = null;
|
|
|
|
}
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(hintHideRunnable);
|
|
|
|
hintHideRunnable = null;
|
|
|
|
hideHint();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hintTextView.setText(enabled ? LocaleController.getString("GroupPhotosHelp", R.string.GroupPhotosHelp) : LocaleController.getString("SinglePhotosHelp", R.string.SinglePhotosHelp));
|
|
|
|
|
|
|
|
if (hintHideRunnable != null) {
|
|
|
|
if (hintAnimation != null) {
|
|
|
|
hintAnimation.cancel();
|
|
|
|
hintAnimation = null;
|
|
|
|
} else {
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(hintHideRunnable);
|
|
|
|
AndroidUtilities.runOnUIThread(hintHideRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
hideHint();
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (hintAnimation != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hintTextView.setVisibility(View.VISIBLE);
|
|
|
|
hintAnimation = new AnimatorSet();
|
|
|
|
hintAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(hintTextView, "alpha", 1.0f)
|
|
|
|
);
|
|
|
|
hintAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(hintAnimation)) {
|
|
|
|
hintAnimation = null;
|
|
|
|
AndroidUtilities.runOnUIThread(hintHideRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
hideHint();
|
|
|
|
}
|
|
|
|
}, 2000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(hintAnimation)) {
|
|
|
|
hintAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
hintAnimation.setDuration(300);
|
|
|
|
hintAnimation.start();
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
@SuppressLint({"NewApi", "DrawAllocation"})
|
2014-06-11 01:05:54 +02:00
|
|
|
private void onDraw(Canvas canvas) {
|
2014-06-12 17:53:20 +02:00
|
|
|
if (animationInProgress == 1 || !isVisible && animationInProgress != 2) {
|
2014-06-11 01:05:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float currentTranslationY;
|
|
|
|
float currentTranslationX;
|
2015-01-02 23:15:07 +01:00
|
|
|
float currentScale;
|
2014-06-11 01:05:54 +02:00
|
|
|
float aty = -1;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (imageMoveAnimation != null) {
|
2014-06-21 23:46:11 +02:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
float ts = scale + (animateToScale - scale) * animationValue;
|
|
|
|
float tx = translationX + (animateToX - translationX) * animationValue;
|
|
|
|
float ty = translationY + (animateToY - translationY) * animationValue;
|
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.setAnimationProgress(animationValue);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
|
|
if (animateToScale == 1 && scale == 1 && translationX == 0) {
|
|
|
|
aty = ty;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
currentScale = ts;
|
|
|
|
currentTranslationY = ty;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentTranslationX = tx;
|
|
|
|
containerView.invalidate();
|
2014-06-07 01:35:21 +02:00
|
|
|
} else {
|
2014-06-11 01:05:54 +02:00
|
|
|
if (animationStartTime != 0) {
|
|
|
|
translationX = animateToX;
|
|
|
|
translationY = animateToY;
|
|
|
|
scale = animateToScale;
|
|
|
|
animationStartTime = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
|
|
|
photoCropView.setAnimationProgress(1);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
updateMinMax(scale);
|
2014-06-11 01:33:45 +02:00
|
|
|
zoomAnimation = false;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-06-21 23:46:11 +02:00
|
|
|
if (!scroller.isFinished()) {
|
|
|
|
if (scroller.computeScrollOffset()) {
|
|
|
|
if (scroller.getStartX() < maxX && scroller.getStartX() > minX) {
|
|
|
|
translationX = scroller.getCurrX();
|
|
|
|
}
|
|
|
|
if (scroller.getStartY() < maxY && scroller.getStartY() > minY) {
|
|
|
|
translationY = scroller.getCurrY();
|
|
|
|
}
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
if (switchImageAfterAnimation != 0) {
|
|
|
|
if (switchImageAfterAnimation == 1) {
|
2017-07-23 14:56:38 +02:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
setImageIndex(currentIndex + 1, false);
|
|
|
|
}
|
|
|
|
});
|
2014-06-11 01:05:54 +02:00
|
|
|
} else if (switchImageAfterAnimation == 2) {
|
2017-07-23 14:56:38 +02:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
setImageIndex(currentIndex - 1, false);
|
|
|
|
}
|
|
|
|
});
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
switchImageAfterAnimation = 0;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
currentScale = scale;
|
|
|
|
currentTranslationY = translationY;
|
2014-06-11 01:05:54 +02:00
|
|
|
currentTranslationX = translationX;
|
|
|
|
if (!moving) {
|
|
|
|
aty = translationY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
if (animationInProgress != 2) {
|
|
|
|
if (currentEditMode == 0 && scale == 1 && aty != -1 && !zoomAnimation) {
|
|
|
|
float maxValue = getContainerViewHeight() / 4.0f;
|
|
|
|
backgroundDrawable.setAlpha((int) Math.max(127, 255 * (1.0f - (Math.min(Math.abs(aty), maxValue) / maxValue))));
|
|
|
|
} else {
|
|
|
|
backgroundDrawable.setAlpha(255);
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
ImageReceiver sideImage = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 0) {
|
|
|
|
if (scale >= 1.0f && !zoomAnimation && !zooming) {
|
|
|
|
if (currentTranslationX > maxX + AndroidUtilities.dp(5)) {
|
|
|
|
sideImage = leftImage;
|
|
|
|
} else if (currentTranslationX < minX - AndroidUtilities.dp(5)) {
|
|
|
|
sideImage = rightImage;
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
groupedPhotosListView.setMoveProgress(0.0f);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
changingPage = sideImage != null;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sideImage == rightImage) {
|
|
|
|
float tranlateX = currentTranslationX;
|
|
|
|
float scaleDiff = 0;
|
|
|
|
float alpha = 1;
|
|
|
|
if (!zoomAnimation && tranlateX < minX) {
|
|
|
|
alpha = Math.min(1.0f, (minX - tranlateX) / canvas.getWidth());
|
|
|
|
scaleDiff = (1.0f - alpha) * 0.3f;
|
2016-10-11 13:57:01 +02:00
|
|
|
tranlateX = -canvas.getWidth() - AndroidUtilities.dp(30) / 2;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
if (sideImage.hasBitmapImage()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.save();
|
2015-02-26 02:32:51 +01:00
|
|
|
canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2);
|
2016-10-11 13:57:01 +02:00
|
|
|
canvas.translate(canvas.getWidth() + AndroidUtilities.dp(30) / 2 + tranlateX, 0);
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.scale(1.0f - scaleDiff, 1.0f - scaleDiff);
|
2015-02-26 02:32:51 +01:00
|
|
|
int bitmapWidth = sideImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = sideImage.getBitmapHeight();
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2015-01-02 23:15:07 +01:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
|
|
|
|
|
|
|
sideImage.setAlpha(alpha);
|
|
|
|
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
sideImage.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.setMoveProgress(-alpha);
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(tranlateX, currentTranslationY / currentScale);
|
2016-10-11 13:57:01 +02:00
|
|
|
canvas.translate((canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale);
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[1].setScale(1.0f - scaleDiff);
|
|
|
|
photoProgressViews[1].setAlpha(alpha);
|
|
|
|
photoProgressViews[1].onDraw(canvas);
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
float translateX = currentTranslationX;
|
2015-01-02 23:15:07 +01:00
|
|
|
float scaleDiff = 0;
|
|
|
|
float alpha = 1;
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!zoomAnimation && translateX > maxX && currentEditMode == 0) {
|
|
|
|
alpha = Math.min(1.0f, (translateX - maxX) / canvas.getWidth());
|
2015-01-02 23:15:07 +01:00
|
|
|
scaleDiff = alpha * 0.3f;
|
|
|
|
alpha = 1.0f - alpha;
|
2016-06-24 12:27:15 +02:00
|
|
|
translateX = maxX;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
boolean drawTextureView = aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == View.VISIBLE;
|
2016-01-11 18:19:48 +01:00
|
|
|
if (centerImage.hasBitmapImage()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.save();
|
2015-02-26 02:32:51 +01:00
|
|
|
canvas.translate(getContainerViewWidth() / 2 + getAdditionX(), getContainerViewHeight() / 2 + getAdditionY());
|
2016-06-24 12:27:15 +02:00
|
|
|
canvas.translate(translateX, currentTranslationY);
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.scale(currentScale - scaleDiff, currentScale - scaleDiff);
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
if (currentEditMode == 1) {
|
2016-06-24 12:27:15 +02:00
|
|
|
photoCropView.setBitmapParams(currentScale, translateX, currentTranslationY);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int bitmapWidth = centerImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = centerImage.getBitmapHeight();
|
2016-06-24 12:27:15 +02:00
|
|
|
if (drawTextureView && textureUploaded) {
|
|
|
|
float scale1 = bitmapWidth / (float) bitmapHeight;
|
|
|
|
float scale2 = videoTextureView.getMeasuredWidth() / (float) videoTextureView.getMeasuredHeight();
|
|
|
|
if (Math.abs(scale1 - scale2) > 0.01f) {
|
|
|
|
bitmapWidth = videoTextureView.getMeasuredWidth();
|
|
|
|
bitmapHeight = videoTextureView.getMeasuredHeight();
|
|
|
|
}
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2014-06-11 01:05:54 +02:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!drawTextureView || !textureUploaded || !videoCrossfadeStarted || videoCrossfadeAlpha != 1.0f) {
|
|
|
|
centerImage.setAlpha(alpha);
|
|
|
|
centerImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
centerImage.draw(canvas);
|
|
|
|
}
|
|
|
|
if (drawTextureView) {
|
|
|
|
if (!videoCrossfadeStarted && textureUploaded) {
|
|
|
|
videoCrossfadeStarted = true;
|
|
|
|
videoCrossfadeAlpha = 0.0f;
|
|
|
|
videoCrossfadeAlphaLastTime = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
canvas.translate(-width / 2, -height / 2);
|
|
|
|
videoTextureView.setAlpha(alpha * videoCrossfadeAlpha);
|
|
|
|
aspectRatioFrameLayout.draw(canvas);
|
|
|
|
if (videoCrossfadeStarted && videoCrossfadeAlpha < 1.0f) {
|
|
|
|
long newUpdateTime = System.currentTimeMillis();
|
|
|
|
long dt = newUpdateTime - videoCrossfadeAlphaLastTime;
|
|
|
|
videoCrossfadeAlphaLastTime = newUpdateTime;
|
2017-07-23 14:56:38 +02:00
|
|
|
videoCrossfadeAlpha += dt / 200.0f;
|
2016-06-24 12:27:15 +02:00
|
|
|
containerView.invalidate();
|
|
|
|
if (videoCrossfadeAlpha > 1.0f) {
|
|
|
|
videoCrossfadeAlpha = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
boolean drawProgress;
|
|
|
|
if (isCurrentVideo) {
|
|
|
|
drawProgress = progressView.getVisibility() != View.VISIBLE && (videoPlayer == null || !videoPlayer.isPlaying());
|
|
|
|
} else {
|
|
|
|
drawProgress = !drawTextureView && videoPlayerControlFrameLayout.getVisibility() != View.VISIBLE;
|
|
|
|
}
|
|
|
|
if (drawProgress) {
|
2016-06-24 12:27:15 +02:00
|
|
|
canvas.save();
|
|
|
|
canvas.translate(translateX, currentTranslationY / currentScale);
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[0].setScale(1.0f - scaleDiff);
|
|
|
|
photoProgressViews[0].setAlpha(alpha);
|
|
|
|
photoProgressViews[0].onDraw(canvas);
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.restore();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
if (sideImage == leftImage) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (sideImage.hasBitmapImage()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.save();
|
2015-02-26 02:32:51 +01:00
|
|
|
canvas.translate(getContainerViewWidth() / 2, getContainerViewHeight() / 2);
|
2016-10-11 13:57:01 +02:00
|
|
|
canvas.translate(-(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2 + currentTranslationX, 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
int bitmapWidth = sideImage.getBitmapWidth();
|
|
|
|
int bitmapHeight = sideImage.getBitmapHeight();
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
float scaleX = (float) getContainerViewWidth() / (float) bitmapWidth;
|
|
|
|
float scaleY = (float) getContainerViewHeight() / (float) bitmapHeight;
|
2015-01-02 23:15:07 +01:00
|
|
|
float scale = scaleX > scaleY ? scaleY : scaleX;
|
|
|
|
int width = (int) (bitmapWidth * scale);
|
|
|
|
int height = (int) (bitmapHeight * scale);
|
2014-10-28 18:07:44 +01:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
sideImage.setAlpha(1.0f);
|
|
|
|
sideImage.setImageCoords(-width / 2, -height / 2, width, height);
|
|
|
|
sideImage.draw(canvas);
|
|
|
|
canvas.restore();
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
groupedPhotosListView.setMoveProgress(1.0f - alpha);
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(currentTranslationX, currentTranslationY / currentScale);
|
2016-10-11 13:57:01 +02:00
|
|
|
canvas.translate(-(canvas.getWidth() * (scale + 1) + AndroidUtilities.dp(30)) / 2, -currentTranslationY / currentScale);
|
2017-03-31 01:58:05 +02:00
|
|
|
photoProgressViews[2].setScale(1.0f);
|
|
|
|
photoProgressViews[2].setAlpha(1.0f);
|
|
|
|
photoProgressViews[2].onDraw(canvas);
|
2015-01-02 23:15:07 +01:00
|
|
|
canvas.restore();
|
2014-10-28 18:07:44 +01:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
private void onActionClick(boolean download) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentMessageObject == null && currentBotInlineResult == null || currentFileNames[0] == null) {
|
2014-06-11 01:05:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
File file = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentMessageObject != null) {
|
|
|
|
if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) {
|
|
|
|
file = new File(currentMessageObject.messageOwner.attachPath);
|
|
|
|
if (!file.exists()) {
|
|
|
|
file = null;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (file == null) {
|
|
|
|
file = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
|
|
|
|
if (!file.exists()) {
|
|
|
|
file = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (currentBotInlineResult != null) {
|
|
|
|
if (currentBotInlineResult.document != null) {
|
|
|
|
file = FileLoader.getPathToAttach(currentBotInlineResult.document);
|
|
|
|
if (!file.exists()) {
|
|
|
|
file = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(currentBotInlineResult.content_url) + "." + ImageLoader.getHttpUrlExtension(currentBotInlineResult.content_url, "mp4"));
|
|
|
|
if (!file.exists()) {
|
|
|
|
file = null;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
if (file == null) {
|
|
|
|
if (download) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentMessageObject != null) {
|
|
|
|
if (!FileLoader.getInstance().isLoadingFile(currentFileNames[0])) {
|
2017-07-23 14:56:38 +02:00
|
|
|
FileLoader.getInstance().loadFile(currentMessageObject.getDocument(), true, 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
FileLoader.getInstance().cancelLoadFile(currentMessageObject.getDocument());
|
|
|
|
}
|
|
|
|
} else if (currentBotInlineResult != null) {
|
|
|
|
if (currentBotInlineResult.document != null) {
|
|
|
|
if (!FileLoader.getInstance().isLoadingFile(currentFileNames[0])) {
|
2017-07-23 14:56:38 +02:00
|
|
|
FileLoader.getInstance().loadFile(currentBotInlineResult.document, true, 0);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
FileLoader.getInstance().cancelLoadFile(currentBotInlineResult.document);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!ImageLoader.getInstance().isLoadingHttpFile(currentBotInlineResult.content_url)) {
|
|
|
|
ImageLoader.getInstance().loadHttpFile(currentBotInlineResult.content_url, "mp4");
|
|
|
|
} else {
|
|
|
|
ImageLoader.getInstance().cancelLoadHttpFile(currentBotInlineResult.content_url);
|
|
|
|
}
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
preparePlayer(file, true, false);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDown(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapUp(MotionEvent e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLongPress(MotionEvent e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
2014-06-21 23:46:11 +02:00
|
|
|
if (scale != 1) {
|
|
|
|
scroller.abortAnimation();
|
|
|
|
scroller.fling(Math.round(translationX), Math.round(translationY), Math.round(velocityX), Math.round(velocityY), (int) minX, (int) maxX, (int) minY, (int) maxY);
|
|
|
|
containerView.postInvalidate();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (discardTap) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
if (canShowBottom) {
|
2017-07-23 14:56:38 +02:00
|
|
|
boolean drawTextureView = aspectRatioFrameLayout != null && aspectRatioFrameLayout.getVisibility() == View.VISIBLE;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (photoProgressViews[0] != null && containerView != null && !drawTextureView) {
|
|
|
|
int state = photoProgressViews[0].backgroundState;
|
2014-10-28 18:07:44 +01:00
|
|
|
if (state > 0 && state <= 3) {
|
|
|
|
float x = e.getX();
|
|
|
|
float y = e.getY();
|
2016-06-24 12:27:15 +02:00
|
|
|
if (x >= (getContainerViewWidth() - AndroidUtilities.dp(100)) / 2.0f && x <= (getContainerViewWidth() + AndroidUtilities.dp(100)) / 2.0f &&
|
|
|
|
y >= (getContainerViewHeight() - AndroidUtilities.dp(100)) / 2.0f && y <= (getContainerViewHeight() + AndroidUtilities.dp(100)) / 2.0f) {
|
|
|
|
onActionClick(true);
|
2014-10-30 22:27:41 +01:00
|
|
|
checkProgress(0, true);
|
2014-10-28 18:07:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
toggleActionBar(!isActionBarVisible, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (sendPhotoType == 0) {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (isCurrentVideo) {
|
|
|
|
videoPlayButton.callOnClick();
|
|
|
|
} else {
|
|
|
|
checkImageView.performClick();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (currentBotInlineResult != null && (currentBotInlineResult.type.equals("video") || MessageObject.isVideoDocument(currentBotInlineResult.document))) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int state = photoProgressViews[0].backgroundState;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (state > 0 && state <= 3) {
|
|
|
|
float x = e.getX();
|
|
|
|
float y = e.getY();
|
|
|
|
if (x >= (getContainerViewWidth() - AndroidUtilities.dp(100)) / 2.0f && x <= (getContainerViewWidth() + AndroidUtilities.dp(100)) / 2.0f &&
|
|
|
|
y >= (getContainerViewHeight() - AndroidUtilities.dp(100)) / 2.0f && y <= (getContainerViewHeight() + AndroidUtilities.dp(100)) / 2.0f) {
|
|
|
|
onActionClick(true);
|
|
|
|
checkProgress(0, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
} else if (sendPhotoType == 2) {
|
|
|
|
if (isCurrentVideo) {
|
|
|
|
videoPlayButton.callOnClick();
|
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTap(MotionEvent e) {
|
|
|
|
if (!canZoom || scale == 1.0f && (translationY != 0 || translationX != 0)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-19 02:23:46 +01:00
|
|
|
if (animationStartTime != 0 || animationInProgress != 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (scale == 1.0f) {
|
2015-02-26 02:32:51 +01:00
|
|
|
float atx = (e.getX() - getContainerViewWidth() / 2) - ((e.getX() - getContainerViewWidth() / 2) - translationX) * (3.0f / scale);
|
|
|
|
float aty = (e.getY() - getContainerViewHeight() / 2) - ((e.getY() - getContainerViewHeight() / 2) - translationY) * (3.0f / scale);
|
2014-06-11 01:05:54 +02:00
|
|
|
updateMinMax(3.0f);
|
|
|
|
if (atx < minX) {
|
|
|
|
atx = minX;
|
|
|
|
} else if (atx > maxX) {
|
|
|
|
atx = maxX;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
if (aty < minY) {
|
|
|
|
aty = minY;
|
|
|
|
} else if (aty > maxY) {
|
|
|
|
aty = maxY;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
animateTo(3.0f, atx, aty, true);
|
2014-06-11 01:05:54 +02:00
|
|
|
} else {
|
2015-01-02 23:15:07 +01:00
|
|
|
animateTo(1.0f, 0, 0, true);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
doubleTap = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
|
|
|
return false;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
// video edit start
|
|
|
|
private QualityChooseView qualityChooseView;
|
|
|
|
private PickerBottomLayoutViewer qualityPicker;
|
|
|
|
private RadialProgressView progressView;
|
2017-07-23 14:56:38 +02:00
|
|
|
private VideoTimelinePlayView videoTimelineView;
|
2017-03-31 01:58:05 +02:00
|
|
|
private AnimatorSet qualityChooseViewAnimation;
|
|
|
|
|
|
|
|
private int selectedCompression;
|
|
|
|
private int compressionsCount = -1;
|
|
|
|
private int previousCompression;
|
|
|
|
|
|
|
|
private int rotationValue;
|
|
|
|
private int originalWidth;
|
|
|
|
private int originalHeight;
|
|
|
|
private int resultWidth;
|
|
|
|
private int resultHeight;
|
|
|
|
private int bitrate;
|
|
|
|
private int originalBitrate;
|
|
|
|
private float videoDuration;
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean videoHasAudio;
|
2017-03-31 01:58:05 +02:00
|
|
|
private long startTime;
|
|
|
|
private long endTime;
|
|
|
|
private long audioFramesSize;
|
|
|
|
private long videoFramesSize;
|
|
|
|
private int estimatedSize;
|
|
|
|
private long estimatedDuration;
|
|
|
|
private long originalSize;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private Runnable currentLoadingVideoRunnable;
|
2017-03-31 01:58:05 +02:00
|
|
|
private MessageObject videoPreviewMessageObject;
|
|
|
|
private boolean tryStartRequestPreviewOnFinish;
|
|
|
|
private boolean loadInitialVideo;
|
|
|
|
private boolean inPreview;
|
|
|
|
private int previewViewEnd;
|
|
|
|
private boolean requestingPreview;
|
|
|
|
|
|
|
|
private String currentSubtitle;
|
|
|
|
|
|
|
|
private class QualityChooseView extends View {
|
|
|
|
|
|
|
|
private Paint paint;
|
|
|
|
private TextPaint textPaint;
|
|
|
|
|
|
|
|
private int circleSize;
|
|
|
|
private int gapSize;
|
|
|
|
private int sideSide;
|
|
|
|
private int lineSize;
|
|
|
|
|
|
|
|
private boolean moving;
|
|
|
|
private boolean startMoving;
|
|
|
|
private float startX;
|
|
|
|
|
|
|
|
private int startMovingQuality;
|
|
|
|
|
|
|
|
public QualityChooseView(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
textPaint.setTextSize(AndroidUtilities.dp(12));
|
|
|
|
textPaint.setColor(0xffcdcdcd);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
float x = event.getX();
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
for (int a = 0; a < compressionsCount; a++) {
|
|
|
|
int cx = sideSide + (lineSize + gapSize * 2 + circleSize) * a + circleSize / 2;
|
|
|
|
if (x > cx - AndroidUtilities.dp(15) && x < cx + AndroidUtilities.dp(15)) {
|
|
|
|
startMoving = a == selectedCompression;
|
|
|
|
startX = x;
|
|
|
|
startMovingQuality = selectedCompression;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (startMoving) {
|
|
|
|
if (Math.abs(startX - x) >= AndroidUtilities.getPixelsInCM(0.5f, true)) {
|
|
|
|
moving = true;
|
|
|
|
startMoving = false;
|
|
|
|
}
|
|
|
|
} else if (moving) {
|
|
|
|
for (int a = 0; a < compressionsCount; a++) {
|
|
|
|
int cx = sideSide + (lineSize + gapSize * 2 + circleSize) * a + circleSize / 2;
|
|
|
|
int diff = lineSize / 2 + circleSize / 2 + gapSize;
|
|
|
|
if (x > cx - diff && x < cx + diff) {
|
|
|
|
if (selectedCompression != a) {
|
|
|
|
selectedCompression = a;
|
|
|
|
didChangedCompressionLevel(false);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
if (!moving) {
|
|
|
|
for (int a = 0; a < compressionsCount; a++) {
|
|
|
|
int cx = sideSide + (lineSize + gapSize * 2 + circleSize) * a + circleSize / 2;
|
|
|
|
if (x > cx - AndroidUtilities.dp(15) && x < cx + AndroidUtilities.dp(15)) {
|
|
|
|
if (selectedCompression != a) {
|
|
|
|
selectedCompression = a;
|
|
|
|
didChangedCompressionLevel(true);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (selectedCompression != startMovingQuality) {
|
|
|
|
requestVideoPreview(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
startMoving = false;
|
|
|
|
moving = false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
circleSize = AndroidUtilities.dp(12);
|
|
|
|
gapSize = AndroidUtilities.dp(2);
|
|
|
|
sideSide = AndroidUtilities.dp(18);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (compressionsCount != 1) {
|
|
|
|
lineSize = (getMeasuredWidth() - circleSize * compressionsCount - gapSize * 8 - sideSide * 2) / (compressionsCount - 1);
|
|
|
|
} else {
|
|
|
|
lineSize = (getMeasuredWidth() - circleSize * compressionsCount - gapSize * 8 - sideSide * 2);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
int cy = getMeasuredHeight() / 2 + AndroidUtilities.dp(6);
|
|
|
|
for (int a = 0; a < compressionsCount; a++) {
|
|
|
|
int cx = sideSide + (lineSize + gapSize * 2 + circleSize) * a + circleSize / 2;
|
|
|
|
if (a <= selectedCompression) {
|
|
|
|
paint.setColor(0xff53aeef);
|
|
|
|
} else {
|
|
|
|
paint.setColor(0x66ffffff);
|
|
|
|
}
|
|
|
|
String text;
|
|
|
|
if (a == compressionsCount - 1) {
|
2017-12-08 18:35:59 +01:00
|
|
|
text = Math.min(originalWidth, originalHeight) + "p";
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (a == 0) {
|
|
|
|
text = "240p";
|
|
|
|
} else if (a == 1) {
|
|
|
|
text = "360p";
|
|
|
|
} else if (a == 2) {
|
|
|
|
text = "480p";
|
|
|
|
} else {
|
|
|
|
text = "720p";
|
|
|
|
}
|
|
|
|
float width = textPaint.measureText(text);
|
|
|
|
canvas.drawCircle(cx, cy, a == selectedCompression ? AndroidUtilities.dp(8) : circleSize / 2, paint);
|
|
|
|
canvas.drawText(text, cx - width / 2, cy - AndroidUtilities.dp(16), textPaint);
|
|
|
|
if (a != 0) {
|
|
|
|
int x = cx - circleSize / 2 - gapSize - lineSize;
|
|
|
|
canvas.drawRect(x, cy - AndroidUtilities.dp(1), x + lineSize, cy + AndroidUtilities.dp(2), paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateMuteButton() {
|
|
|
|
if (videoPlayer != null) {
|
|
|
|
videoPlayer.setMute(muteVideo);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (!videoHasAudio) {
|
|
|
|
muteItem.setEnabled(false);
|
|
|
|
muteItem.setClickable(false);
|
|
|
|
muteItem.setAlpha(0.5f);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
muteItem.setEnabled(true);
|
|
|
|
muteItem.setClickable(true);
|
|
|
|
muteItem.setAlpha(1.0f);
|
|
|
|
if (muteVideo) {
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
muteItem.setImageResource(R.drawable.volume_off);
|
|
|
|
muteItem.setColorFilter(new PorterDuffColorFilter(0xff3dadee, PorterDuff.Mode.MULTIPLY));
|
|
|
|
if (compressItem.getTag() != null) {
|
|
|
|
compressItem.setClickable(false);
|
|
|
|
compressItem.setAlpha(0.5f);
|
|
|
|
compressItem.setEnabled(false);
|
|
|
|
}
|
|
|
|
videoTimelineView.setMaxProgressDiff(30000.0f / videoDuration);
|
|
|
|
} else {
|
|
|
|
muteItem.setColorFilter(null);
|
|
|
|
actionBar.setSubtitle(currentSubtitle);
|
|
|
|
muteItem.setImageResource(R.drawable.volume_on);
|
|
|
|
if (compressItem.getTag() != null) {
|
|
|
|
compressItem.setClickable(true);
|
|
|
|
compressItem.setAlpha(1.0f);
|
|
|
|
compressItem.setEnabled(true);
|
|
|
|
}
|
|
|
|
videoTimelineView.setMaxProgressDiff(1.0f);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void didChangedCompressionLevel(boolean request) {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = preferences.edit();
|
|
|
|
editor.putInt("compress_video2", selectedCompression);
|
|
|
|
editor.commit();
|
|
|
|
updateWidthHeightBitrateForCompression();
|
|
|
|
updateVideoInfo();
|
|
|
|
if (request) {
|
|
|
|
requestVideoPreview(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVideoInfo() {
|
|
|
|
if (actionBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (compressionsCount == 0) {
|
|
|
|
actionBar.setSubtitle(null);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
if (selectedCompression == 0) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_240);
|
|
|
|
} else if (selectedCompression == 1) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_360);
|
|
|
|
} else if (selectedCompression == 2) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_480);
|
|
|
|
} else if (selectedCompression == 3) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_720);
|
|
|
|
} else if (selectedCompression == 4) {
|
|
|
|
compressItem.setImageResource(R.drawable.video_1080);
|
|
|
|
}
|
|
|
|
|
|
|
|
estimatedDuration = (long) Math.ceil((videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * videoDuration);
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (compressItem.getTag() == null || selectedCompression == compressionsCount - 1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
width = rotationValue == 90 || rotationValue == 270 ? originalHeight : originalWidth;
|
|
|
|
height = rotationValue == 90 || rotationValue == 270 ? originalWidth : originalHeight;
|
|
|
|
estimatedSize = (int) (originalSize * ((float) estimatedDuration / videoDuration));
|
|
|
|
} else {
|
|
|
|
width = rotationValue == 90 || rotationValue == 270 ? resultHeight : resultWidth;
|
|
|
|
height = rotationValue == 90 || rotationValue == 270 ? resultWidth : resultHeight;
|
|
|
|
|
|
|
|
estimatedSize = (int) ((audioFramesSize + videoFramesSize) * ((float) estimatedDuration / videoDuration));
|
|
|
|
estimatedSize += estimatedSize / (32 * 1024) * 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (videoTimelineView.getLeftProgress() == 0) {
|
|
|
|
startTime = -1;
|
|
|
|
} else {
|
|
|
|
startTime = (long) (videoTimelineView.getLeftProgress() * videoDuration) * 1000;
|
|
|
|
}
|
|
|
|
if (videoTimelineView.getRightProgress() == 1) {
|
|
|
|
endTime = -1;
|
|
|
|
} else {
|
|
|
|
endTime = (long) (videoTimelineView.getRightProgress() * videoDuration) * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
String videoDimension = String.format("%dx%d", width, height);
|
|
|
|
int minutes = (int) (estimatedDuration / 1000 / 60);
|
|
|
|
int seconds = (int) Math.ceil(estimatedDuration / 1000) - minutes * 60;
|
|
|
|
String videoTimeSize = String.format("%d:%02d, ~%s", minutes, seconds, AndroidUtilities.formatFileSize(estimatedSize));
|
|
|
|
currentSubtitle = String.format("%s, %s", videoDimension, videoTimeSize);
|
|
|
|
actionBar.setSubtitle(muteVideo ? null : currentSubtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void requestVideoPreview(int request) {
|
|
|
|
if (videoPreviewMessageObject != null) {
|
|
|
|
MediaController.getInstance().cancelVideoConvert(videoPreviewMessageObject);
|
|
|
|
}
|
|
|
|
boolean wasRequestingPreview = requestingPreview && !tryStartRequestPreviewOnFinish;
|
|
|
|
requestingPreview = false;
|
|
|
|
loadInitialVideo = false;
|
|
|
|
progressView.setVisibility(View.INVISIBLE);
|
|
|
|
if (request == 1) {
|
|
|
|
if (selectedCompression == compressionsCount - 1) {
|
|
|
|
tryStartRequestPreviewOnFinish = false;
|
|
|
|
if (!wasRequestingPreview) {
|
|
|
|
preparePlayer(currentPlayingVideoFile, false, false);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
loadInitialVideo = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
requestingPreview = true;
|
|
|
|
releasePlayer();
|
|
|
|
if (videoPreviewMessageObject == null) {
|
|
|
|
TLRPC.TL_message message = new TLRPC.TL_message();
|
|
|
|
message.id = 0;
|
|
|
|
message.message = "";
|
|
|
|
message.media = new TLRPC.TL_messageMediaEmpty();
|
|
|
|
message.action = new TLRPC.TL_messageActionEmpty();
|
|
|
|
videoPreviewMessageObject = new MessageObject(message, null, false);
|
|
|
|
videoPreviewMessageObject.messageOwner.attachPath = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), "video_preview.mp4").getAbsolutePath();
|
|
|
|
videoPreviewMessageObject.videoEditedInfo = new VideoEditedInfo();
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.rotationValue = rotationValue;
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.originalWidth = originalWidth;
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.originalHeight = originalHeight;
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.originalPath = currentPlayingVideoFile.getAbsolutePath();
|
|
|
|
}
|
|
|
|
long start = videoPreviewMessageObject.videoEditedInfo.startTime = startTime;
|
|
|
|
long end = videoPreviewMessageObject.videoEditedInfo.endTime = endTime;
|
|
|
|
if (start == -1) {
|
|
|
|
start = 0;
|
|
|
|
}
|
|
|
|
if (end == -1) {
|
|
|
|
end = (long) (videoDuration * 1000);
|
|
|
|
}
|
|
|
|
if (end - start > 5000000) {
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.endTime = start + 5000000;
|
|
|
|
}
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.bitrate = bitrate;
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.resultWidth = resultWidth;
|
|
|
|
videoPreviewMessageObject.videoEditedInfo.resultHeight = resultHeight;
|
|
|
|
if (!MediaController.getInstance().scheduleVideoConvert(videoPreviewMessageObject, true)) {
|
|
|
|
tryStartRequestPreviewOnFinish = true;
|
|
|
|
}
|
|
|
|
requestingPreview = true;
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
tryStartRequestPreviewOnFinish = false;
|
|
|
|
if (request == 2) {
|
|
|
|
preparePlayer(currentPlayingVideoFile, false, false);
|
|
|
|
}
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
containerView.invalidate();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateWidthHeightBitrateForCompression() {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (compressionsCount <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (selectedCompression >= compressionsCount) {
|
|
|
|
selectedCompression = compressionsCount - 1;
|
|
|
|
}
|
|
|
|
if (selectedCompression != compressionsCount - 1) {
|
|
|
|
float maxSize;
|
|
|
|
int targetBitrate;
|
|
|
|
switch (selectedCompression) {
|
|
|
|
case 0:
|
|
|
|
maxSize = 432.0f;
|
|
|
|
targetBitrate = 400000;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
maxSize = 640.0f;
|
|
|
|
targetBitrate = 900000;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
maxSize = 848.0f;
|
|
|
|
targetBitrate = 1100000;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
2017-12-08 18:35:59 +01:00
|
|
|
targetBitrate = 2500000;
|
2017-03-31 01:58:05 +02:00
|
|
|
maxSize = 1280.0f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
float scale = originalWidth > originalHeight ? maxSize / originalWidth : maxSize / originalHeight;
|
|
|
|
resultWidth = Math.round(originalWidth * scale / 2) * 2;
|
|
|
|
resultHeight = Math.round(originalHeight * scale / 2) * 2;
|
|
|
|
if (bitrate != 0) {
|
|
|
|
bitrate = Math.min(targetBitrate, (int) (originalBitrate / scale));
|
|
|
|
videoFramesSize = (long) (bitrate / 8 * videoDuration / 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showQualityView(final boolean show) {
|
|
|
|
if (show) {
|
|
|
|
previousCompression = selectedCompression;
|
|
|
|
}
|
|
|
|
if (qualityChooseViewAnimation != null) {
|
|
|
|
qualityChooseViewAnimation.cancel();
|
|
|
|
}
|
|
|
|
qualityChooseViewAnimation = new AnimatorSet();
|
|
|
|
if (show) {
|
|
|
|
qualityChooseView.setTag(1);
|
|
|
|
qualityChooseViewAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(pickerView, "translationY", 0, AndroidUtilities.dp(152)),
|
|
|
|
ObjectAnimator.ofFloat(bottomLayout, "translationY", -AndroidUtilities.dp(48), AndroidUtilities.dp(104))
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
qualityChooseView.setTag(null);
|
|
|
|
qualityChooseViewAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(qualityChooseView, "translationY", 0, AndroidUtilities.dp(166)),
|
|
|
|
ObjectAnimator.ofFloat(qualityPicker, "translationY", 0, AndroidUtilities.dp(166)),
|
|
|
|
ObjectAnimator.ofFloat(bottomLayout, "translationY", -AndroidUtilities.dp(48), AndroidUtilities.dp(118))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
qualityChooseViewAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (!animation.equals(qualityChooseViewAnimation)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qualityChooseViewAnimation = new AnimatorSet();
|
|
|
|
if (show) {
|
|
|
|
qualityChooseView.setVisibility(View.VISIBLE);
|
|
|
|
qualityPicker.setVisibility(View.VISIBLE);
|
|
|
|
qualityChooseViewAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(qualityChooseView, "translationY", 0),
|
|
|
|
ObjectAnimator.ofFloat(qualityPicker, "translationY", 0),
|
|
|
|
ObjectAnimator.ofFloat(bottomLayout, "translationY", -AndroidUtilities.dp(48))
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
qualityChooseView.setVisibility(View.INVISIBLE);
|
|
|
|
qualityPicker.setVisibility(View.INVISIBLE);
|
|
|
|
qualityChooseViewAnimation.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(pickerView, "translationY", 0),
|
|
|
|
ObjectAnimator.ofFloat(bottomLayout, "translationY", -AndroidUtilities.dp(48))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
qualityChooseViewAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(qualityChooseViewAnimation)) {
|
|
|
|
qualityChooseViewAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
qualityChooseViewAnimation.setDuration(200);
|
|
|
|
qualityChooseViewAnimation.setInterpolator(new AccelerateInterpolator());
|
|
|
|
qualityChooseViewAnimation.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
qualityChooseViewAnimation = null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
qualityChooseViewAnimation.setDuration(200);
|
|
|
|
qualityChooseViewAnimation.setInterpolator(new DecelerateInterpolator());
|
|
|
|
qualityChooseViewAnimation.start();
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void processOpenVideo(final String videoPath, boolean muted) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (currentLoadingVideoRunnable != null) {
|
|
|
|
Utilities.globalQueue.cancelRunnable(currentLoadingVideoRunnable);
|
|
|
|
currentLoadingVideoRunnable = null;
|
|
|
|
}
|
|
|
|
videoPreviewMessageObject = null;
|
|
|
|
setCompressItemEnabled(false, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
muteVideo = muted;
|
2017-07-08 18:32:04 +02:00
|
|
|
videoTimelineView.setVideoPath(videoPath);
|
|
|
|
compressionsCount = -1;
|
2017-07-23 14:56:38 +02:00
|
|
|
rotationValue = 0;
|
2017-07-08 18:32:04 +02:00
|
|
|
File file = new File(videoPath);
|
|
|
|
originalSize = file.length();
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
Utilities.globalQueue.postRunnable(currentLoadingVideoRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (currentLoadingVideoRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TrackHeaderBox trackHeaderBox = null;
|
|
|
|
boolean isAvc = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
2017-07-08 18:32:04 +02:00
|
|
|
IsoFile isoFile = new IsoFile(videoPath);
|
|
|
|
List<Box> boxes = Path.getPaths(isoFile, "/moov/trak/");
|
|
|
|
|
|
|
|
Box boxTest = Path.getPath(isoFile, "/moov/trak/mdia/minf/stbl/stsd/mp4a/");
|
|
|
|
if (boxTest == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
FileLog.d("video hasn't mp4a atom");
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
boxTest = Path.getPath(isoFile, "/moov/trak/mdia/minf/stbl/stsd/avc1/");
|
|
|
|
if (boxTest == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
FileLog.d("video hasn't avc1 atom");
|
2017-07-08 18:32:04 +02:00
|
|
|
isAvc = false;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
audioFramesSize = 0;
|
|
|
|
videoFramesSize = 0;
|
2017-07-08 18:32:04 +02:00
|
|
|
for (int b = 0; b < boxes.size(); b++) {
|
|
|
|
if (currentLoadingVideoRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Box box = boxes.get(b);
|
|
|
|
TrackBox trackBox = (TrackBox) box;
|
|
|
|
long sampleSizes = 0;
|
|
|
|
long trackBitrate = 0;
|
|
|
|
try {
|
|
|
|
MediaBox mediaBox = trackBox.getMediaBox();
|
|
|
|
MediaHeaderBox mediaHeaderBox = mediaBox.getMediaHeaderBox();
|
|
|
|
SampleSizeBox sampleSizeBox = mediaBox.getMediaInformationBox().getSampleTableBox().getSampleSizeBox();
|
|
|
|
long[] sizes = sampleSizeBox.getSampleSizes();
|
|
|
|
for (int a = 0; a < sizes.length; a++) {
|
|
|
|
if (currentLoadingVideoRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sampleSizes += sizes[a];
|
|
|
|
}
|
|
|
|
videoDuration = (float) mediaHeaderBox.getDuration() / (float) mediaHeaderBox.getTimescale();
|
|
|
|
trackBitrate = (int) (sampleSizes * 8 / videoDuration);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
|
|
|
if (currentLoadingVideoRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TrackHeaderBox headerBox = trackBox.getTrackHeaderBox();
|
|
|
|
if (headerBox.getWidth() != 0 && headerBox.getHeight() != 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (trackHeaderBox == null || trackHeaderBox.getWidth() < headerBox.getWidth() || trackHeaderBox.getHeight() < headerBox.getHeight()) {
|
|
|
|
trackHeaderBox = headerBox;
|
|
|
|
originalBitrate = bitrate = (int) (trackBitrate / 100000 * 100000);
|
|
|
|
if (bitrate > 900000) {
|
|
|
|
bitrate = 900000;
|
|
|
|
}
|
|
|
|
videoFramesSize += sampleSizes;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
audioFramesSize += sampleSizes;
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2017-12-08 18:35:59 +01:00
|
|
|
isAvc = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (trackHeaderBox == null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
FileLog.d("video hasn't trackHeaderBox atom");
|
|
|
|
isAvc = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
final boolean isAvcFinal = isAvc;
|
|
|
|
final TrackHeaderBox trackHeaderBoxFinal = trackHeaderBox;
|
|
|
|
if (currentLoadingVideoRunnable != this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentLoadingVideoRunnable = null;
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (parentActivity == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
videoHasAudio = isAvcFinal;
|
|
|
|
if (isAvcFinal) {
|
|
|
|
Matrix matrix = trackHeaderBoxFinal.getMatrix();
|
|
|
|
if (matrix.equals(Matrix.ROTATE_90)) {
|
|
|
|
rotationValue = 90;
|
|
|
|
} else if (matrix.equals(Matrix.ROTATE_180)) {
|
|
|
|
rotationValue = 180;
|
|
|
|
} else if (matrix.equals(Matrix.ROTATE_270)) {
|
|
|
|
rotationValue = 270;
|
|
|
|
} else {
|
|
|
|
rotationValue = 0;
|
|
|
|
}
|
|
|
|
resultWidth = originalWidth = (int) trackHeaderBoxFinal.getWidth();
|
|
|
|
resultHeight = originalHeight = (int) trackHeaderBoxFinal.getHeight();
|
|
|
|
|
|
|
|
videoDuration *= 1000;
|
|
|
|
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
|
|
|
|
selectedCompression = preferences.getInt("compress_video2", 1);
|
|
|
|
if (originalWidth > 1280 || originalHeight > 1280) {
|
|
|
|
compressionsCount = 5;
|
|
|
|
} else if (originalWidth > 848 || originalHeight > 848) {
|
|
|
|
compressionsCount = 4;
|
|
|
|
} else if (originalWidth > 640 || originalHeight > 640) {
|
|
|
|
compressionsCount = 3;
|
|
|
|
} else if (originalWidth > 480 || originalHeight > 480) {
|
|
|
|
compressionsCount = 2;
|
|
|
|
} else {
|
|
|
|
compressionsCount = 1;
|
|
|
|
}
|
|
|
|
updateWidthHeightBitrateForCompression();
|
|
|
|
|
|
|
|
setCompressItemEnabled(compressionsCount > 1, true);
|
|
|
|
FileLog.d("compressionsCount = " + compressionsCount + " w = " + originalWidth + " h = " + originalHeight);
|
|
|
|
if (Build.VERSION.SDK_INT < 18 && compressItem.getTag() != null) {
|
|
|
|
try {
|
|
|
|
MediaCodecInfo codecInfo = MediaController.selectCodec(MediaController.MIME_TYPE);
|
|
|
|
if (codecInfo == null) {
|
|
|
|
FileLog.d("no codec info for " + MediaController.MIME_TYPE);
|
2017-07-08 18:32:04 +02:00
|
|
|
setCompressItemEnabled(false, true);
|
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
String name = codecInfo.getName();
|
|
|
|
if (name.equals("OMX.google.h264.encoder") ||
|
|
|
|
name.equals("OMX.ST.VFM.H264Enc") ||
|
|
|
|
name.equals("OMX.Exynos.avc.enc") ||
|
|
|
|
name.equals("OMX.MARVELL.VIDEO.HW.CODA7542ENCODER") ||
|
|
|
|
name.equals("OMX.MARVELL.VIDEO.H264ENCODER") ||
|
|
|
|
name.equals("OMX.k3.video.encoder.avc") ||
|
|
|
|
name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) {
|
|
|
|
FileLog.d("unsupported encoder = " + name);
|
2017-07-08 18:32:04 +02:00
|
|
|
setCompressItemEnabled(false, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
if (MediaController.selectColorFormat(codecInfo, MediaController.MIME_TYPE) == 0) {
|
|
|
|
FileLog.d("no color format for " + MediaController.MIME_TYPE);
|
|
|
|
setCompressItemEnabled(false, true);
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
setCompressItemEnabled(false, true);
|
|
|
|
FileLog.e(e);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
qualityChooseView.invalidate();
|
|
|
|
} else {
|
|
|
|
compressionsCount = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
updateVideoInfo();
|
|
|
|
updateMuteButton();
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
});
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private void setCompressItemEnabled(boolean enabled, boolean animated) {
|
|
|
|
if (compressItem == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (enabled && compressItem.getTag() != null || !enabled && compressItem.getTag() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
compressItem.setTag(enabled ? 1 : null);
|
|
|
|
compressItem.setEnabled(enabled);
|
|
|
|
compressItem.setClickable(enabled);
|
|
|
|
if (compressItemAnimation != null) {
|
|
|
|
compressItemAnimation.cancel();
|
|
|
|
compressItemAnimation = null;
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
compressItemAnimation = new AnimatorSet();
|
|
|
|
compressItemAnimation.playTogether(ObjectAnimator.ofFloat(compressItem, "alpha", enabled ? 1.0f : 0.5f));
|
|
|
|
compressItemAnimation.setDuration(180);
|
|
|
|
compressItemAnimation.setInterpolator(decelerateInterpolator);
|
|
|
|
compressItemAnimation.start();
|
|
|
|
} else {
|
|
|
|
compressItem.setAlpha(enabled ? 1.0f : 0.5f);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
if (placeProvider != null && placeProvider.getSelectedPhotosOrder() != null) {
|
|
|
|
if (placeProvider.allowGroupPhotos()) {
|
|
|
|
return 1 + placeProvider.getSelectedPhotosOrder().size();
|
|
|
|
} else {
|
|
|
|
return placeProvider.getSelectedPhotosOrder().size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
PhotoPickerPhotoCell cell = new PhotoPickerPhotoCell(mContext, false);
|
|
|
|
cell.checkFrame.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Object photoEntry = ((View) v.getParent()).getTag();
|
|
|
|
int idx = imagesArrLocals.indexOf(photoEntry);
|
|
|
|
if (idx >= 0) {
|
|
|
|
int num = placeProvider.setPhotoChecked(idx, getCurrentVideoEditedInfo());
|
|
|
|
boolean checked = placeProvider.isPhotoChecked(idx);
|
|
|
|
if (idx == currentIndex) {
|
|
|
|
checkImageView.setChecked(false, true);
|
|
|
|
}
|
|
|
|
if (num >= 0) {
|
|
|
|
if (placeProvider.allowGroupPhotos()) {
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
selectedPhotosAdapter.notifyItemRemoved(num);
|
|
|
|
}
|
|
|
|
updateSelectedCount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
view = cell;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
ImageView imageView = new ImageView(mContext) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(66), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
imageView.setImageResource(R.drawable.photos_group);
|
|
|
|
view = imageView;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0: {
|
|
|
|
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) holder.itemView;
|
|
|
|
cell.itemWidth = AndroidUtilities.dp(82);
|
|
|
|
BackupImageView imageView = cell.photoImage;
|
|
|
|
boolean showing;
|
|
|
|
imageView.setOrientation(0, true);
|
|
|
|
ArrayList<Object> order = placeProvider.getSelectedPhotosOrder();
|
|
|
|
if (placeProvider.allowGroupPhotos()) {
|
|
|
|
position--;
|
|
|
|
}
|
|
|
|
Object object = placeProvider.getSelectedPhotos().get(order.get(position));
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
|
|
|
|
cell.setTag(photoEntry);
|
|
|
|
cell.videoInfoContainer.setVisibility(View.INVISIBLE);
|
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
imageView.setOrientation(photoEntry.orientation, true);
|
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
cell.videoInfoContainer.setVisibility(View.VISIBLE);
|
|
|
|
int minutes = photoEntry.duration / 60;
|
|
|
|
int seconds = photoEntry.duration - minutes * 60;
|
|
|
|
cell.videoTextView.setText(String.format("%d:%02d", minutes, seconds));
|
|
|
|
imageView.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else {
|
|
|
|
imageView.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imageView.setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
|
|
|
cell.setChecked(-1, true, false);
|
|
|
|
cell.checkBox.setVisibility(View.VISIBLE);
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage photoEntry = (MediaController.SearchImage) object;
|
|
|
|
cell.setTag(photoEntry);
|
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
|
|
|
|
imageView.setImage(photoEntry.thumbUrl, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.document != null && photoEntry.document.thumb != null) {
|
|
|
|
imageView.setImage(photoEntry.document.thumb.location, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else {
|
|
|
|
imageView.setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
|
|
|
cell.videoInfoContainer.setVisibility(View.INVISIBLE);
|
|
|
|
cell.setChecked(-1, true, false);
|
|
|
|
cell.checkBox.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
ImageView imageView = (ImageView) holder.itemView;
|
|
|
|
imageView.setColorFilter(MediaController.getInstance().isGroupPhotosEnabled() ? new PorterDuffColorFilter(0xff66bffa, PorterDuff.Mode.MULTIPLY) : null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
if (i == 0 && placeProvider.allowGroupPhotos()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|