2014-06-12 03:13:15 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-06-12 03:13:15 +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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-06-12 03:13:15 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.annotation.SuppressLint;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.app.Activity;
|
2014-06-12 03:13:15 +02:00
|
|
|
import android.content.Context;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Outline;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
import android.graphics.RectF;
|
2019-08-22 01:53:26 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.os.Build;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.text.Editable;
|
|
|
|
import android.text.InputFilter;
|
|
|
|
import android.text.TextPaint;
|
2019-01-23 18:03:33 +01:00
|
|
|
import android.text.TextUtils;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.text.TextWatcher;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.view.Gravity;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.view.HapticFeedbackConstants;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.MotionEvent;
|
2014-06-12 03:13:15 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.view.ViewOutlineProvider;
|
2014-06-12 03:13:15 +02:00
|
|
|
import android.view.WindowManager;
|
2020-07-26 10:03:38 +02:00
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.view.animation.DecelerateInterpolator;
|
|
|
|
import android.view.animation.OvershootInterpolator;
|
2020-07-26 10:03:38 +02:00
|
|
|
import android.widget.Button;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.widget.ImageView;
|
2019-12-31 14:08:08 +01:00
|
|
|
import android.widget.TextView;
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2020-02-13 19:26:53 +01:00
|
|
|
import org.telegram.messenger.SharedConfig;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.UserObject;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.messenger.VideoEditedInfo;
|
2014-06-12 03:13:15 +02:00
|
|
|
import org.telegram.messenger.R;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuSubItem;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarPopupWindow;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2014-11-13 21:10:14 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Cells.DividerCell;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.Cells.PhotoAttachPhotoCell;
|
2019-12-31 14:08:08 +01:00
|
|
|
import org.telegram.ui.Cells.SharedDocumentCell;
|
|
|
|
import org.telegram.ui.Cells.TextCell;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.Components.AlertsCreator;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.Components.CombinedDrawable;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.Components.EditTextBoldCursor;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.Components.EditTextEmoji;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.EmptyTextProgressView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RadialProgressView;
|
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerViewItemRangeSelector;
|
|
|
|
import org.telegram.ui.Components.SizeNotifierFrameLayout;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public class PhotoPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface PhotoPickerActivityDelegate {
|
|
|
|
void selectedPhotosChanged();
|
2019-09-10 12:56:11 +02:00
|
|
|
void actionButtonPressed(boolean canceled, boolean notify, int scheduleDate);
|
|
|
|
void onCaptionChanged(CharSequence caption);
|
2019-12-31 14:08:08 +01:00
|
|
|
default void onOpenInPressed() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface PhotoPickerActivitySearchDelegate {
|
|
|
|
void shouldSearchText(String text);
|
|
|
|
void shouldClearRecentSearch();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private int type;
|
2017-12-08 18:35:59 +01:00
|
|
|
private HashMap<Object, Object> selectedPhotos;
|
|
|
|
private ArrayList<Object> selectedPhotosOrder;
|
2019-09-10 12:56:11 +02:00
|
|
|
private CharSequence caption;
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean allowIndices;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
private ArrayList<MediaController.SearchImage> searchResult = new ArrayList<>();
|
|
|
|
private HashMap<String, MediaController.SearchImage> searchResultKeys = new HashMap<>();
|
|
|
|
private HashMap<String, MediaController.SearchImage> searchResultUrls = new HashMap<>();
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private ArrayList<String> recentSearches = new ArrayList<>();
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private boolean searching;
|
2019-05-14 14:08:05 +02:00
|
|
|
private boolean imageSearchEndReached = true;
|
2015-01-02 23:15:07 +01:00
|
|
|
private String lastSearchString;
|
2018-07-30 04:07:02 +02:00
|
|
|
private String nextImagesSearchOffset;
|
|
|
|
private int imageReqId;
|
2016-01-11 18:19:48 +01:00
|
|
|
private int lastSearchToken;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean allowCaption;
|
|
|
|
private boolean searchingUser;
|
|
|
|
private String lastSearchImageString;
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private int maxSelectedPhotos;
|
2019-08-22 01:53:26 +02:00
|
|
|
private boolean allowOrder = true;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
private MediaController.AlbumEntry selectedAlbum;
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2014-06-12 03:13:15 +02:00
|
|
|
private ListAdapter listAdapter;
|
2017-03-31 01:58:05 +02:00
|
|
|
private GridLayoutManager layoutManager;
|
|
|
|
private EmptyTextProgressView emptyView;
|
2015-01-02 23:15:07 +01:00
|
|
|
private ActionBarMenuItem searchItem;
|
2019-12-31 14:08:08 +01:00
|
|
|
private ActionBarMenuSubItem showAsListItem;
|
2019-09-10 12:56:11 +02:00
|
|
|
private int itemSize = 100;
|
2015-01-02 23:15:07 +01:00
|
|
|
private boolean sendPressed;
|
2019-01-23 18:03:33 +01:00
|
|
|
private int selectPhotoType;
|
2015-05-03 13:48:36 +02:00
|
|
|
private ChatActivity chatActivity;
|
2019-09-10 12:56:11 +02:00
|
|
|
private RecyclerViewItemRangeSelector itemRangeSelector;
|
|
|
|
private int alertOnlyOnce;
|
|
|
|
private boolean shouldSelect;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private boolean listSort;
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
protected FrameLayout frameLayout2;
|
|
|
|
protected FrameLayout writeButtonContainer;
|
|
|
|
protected View selectedCountView;
|
|
|
|
protected View shadow;
|
|
|
|
protected EditTextEmoji commentTextView;
|
|
|
|
private ImageView writeButton;
|
|
|
|
private Drawable writeButtonDrawable;
|
|
|
|
private SizeNotifierFrameLayout sizeNotifierFrameLayout;
|
|
|
|
private int itemsPerRow = 3;
|
|
|
|
private TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
private RectF rect = new RectF();
|
|
|
|
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
private AnimatorSet animatorSet;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private boolean isDocumentsPicker;
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private ActionBarPopupWindow sendPopupWindow;
|
|
|
|
private ActionBarPopupWindow.ActionBarPopupWindowLayout sendPopupLayout;
|
|
|
|
private ActionBarMenuSubItem[] itemCells;
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private String initialSearchString;
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
private boolean needsBottomLayout = true;
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private final static int change_sort = 1;
|
|
|
|
private final static int open_in = 2;
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
private PhotoPickerActivityDelegate delegate;
|
2019-12-31 14:08:08 +01:00
|
|
|
private PhotoPickerActivitySearchDelegate searchDelegate;
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private PhotoViewer.PhotoViewerProvider provider = new PhotoViewer.EmptyPhotoViewerProvider() {
|
|
|
|
@Override
|
|
|
|
public boolean scaleToFill() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-03-03 21:40:48 +01:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (cell != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
BackupImageView imageView = cell.getImageView();
|
2019-05-14 14:08:05 +02:00
|
|
|
int[] coords = new int[2];
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.getLocationInWindow(coords);
|
2017-12-08 18:35:59 +01:00
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
|
|
|
object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
|
|
|
|
object.parentView = listView;
|
2019-09-10 12:56:11 +02:00
|
|
|
object.imageReceiver = imageView.getImageReceiver();
|
2018-07-30 04:07:02 +02:00
|
|
|
object.thumb = object.imageReceiver.getBitmapSafe();
|
2019-09-10 12:56:11 +02:00
|
|
|
object.scale = cell.getScale();
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.showCheck(false);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (cell != null) {
|
|
|
|
if (selectedAlbum != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
BackupImageView imageView = cell.getImageView();
|
|
|
|
imageView.setOrientation(0, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
if (photoEntry.thumbPath != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.setImage(photoEntry.thumbPath, null, Theme.chat_attachEmptyDrawable);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (photoEntry.path != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.setOrientation(photoEntry.orientation, true);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (photoEntry.isVideo) {
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, Theme.chat_attachEmptyDrawable);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, Theme.chat_attachEmptyDrawable);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-10 12:56:11 +02:00
|
|
|
imageView.setImageDrawable(Theme.chat_attachEmptyDrawable);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
cell.setPhotoEntry(searchResult.get(index), true, false);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean allowCaption() {
|
|
|
|
return allowCaption;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public ImageReceiver.BitmapHolder getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = getCellForIndex(index);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (cell != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
return cell.getImageView().getImageReceiver().getBitmapSafe();
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
|
|
|
if (view.getTag() == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
2017-12-08 18:35:59 +01:00
|
|
|
int num = (Integer) view.getTag();
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (num < 0 || num >= selectedAlbum.photos.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (num < 0 || num >= searchResult.size()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num == index) {
|
|
|
|
cell.showCheck(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2019-09-10 12:56:11 +02:00
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.showCheck(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) {
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
return !(index < 0 || index >= selectedAlbum.photos.size()) && selectedPhotos.containsKey(selectedAlbum.photos.get(index).imageId);
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
return !(index < 0 || index >= searchResult.size()) && selectedPhotos.containsKey(searchResult.get(index).id);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Override
|
|
|
|
public int setPhotoUnchecked(Object object) {
|
|
|
|
Object key = null;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
key = ((MediaController.PhotoEntry) object).imageId;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
key = ((MediaController.SearchImage) object).id;
|
|
|
|
}
|
|
|
|
if (key == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (selectedPhotos.containsKey(key)) {
|
|
|
|
selectedPhotos.remove(key);
|
|
|
|
int position = selectedPhotosOrder.indexOf(key);
|
|
|
|
if (position >= 0) {
|
|
|
|
selectedPhotosOrder.remove(position);
|
|
|
|
}
|
|
|
|
if (allowIndices) {
|
|
|
|
updateCheckedPhotoIndices();
|
|
|
|
}
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
|
|
|
public int setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) {
|
|
|
|
boolean add = true;
|
|
|
|
int num;
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (index < 0 || index >= selectedAlbum.photos.size()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
if ((num = addToSelectedPhotos(photoEntry, -1)) == -1) {
|
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
|
|
|
num = selectedPhotosOrder.indexOf(photoEntry.imageId);
|
|
|
|
} else {
|
|
|
|
add = false;
|
|
|
|
photoEntry.editedInfo = null;
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (index < 0 || index >= searchResult.size()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
MediaController.SearchImage photoEntry = searchResult.get(index);
|
2017-12-08 18:35:59 +01:00
|
|
|
if ((num = addToSelectedPhotos(photoEntry, -1)) == -1) {
|
2020-06-04 18:47:15 +02:00
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
2017-12-08 18:35:59 +01:00
|
|
|
num = selectedPhotosOrder.indexOf(photoEntry.id);
|
|
|
|
} else {
|
|
|
|
add = false;
|
2020-06-04 18:47:15 +02:00
|
|
|
photoEntry.editedInfo = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
|
|
|
int tag = (Integer) view.getTag();
|
|
|
|
if (tag == index) {
|
2019-09-10 12:56:11 +02:00
|
|
|
((PhotoAttachPhotoCell) view).setChecked(allowIndices ? num : -1, add, false);
|
2017-12-08 18:35:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
updatePhotosButton(add ? 1 : 2);
|
2017-12-08 18:35:59 +01:00
|
|
|
delegate.selectedPhotosChanged();
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean cancelButtonPressed() {
|
2019-09-10 12:56:11 +02:00
|
|
|
delegate.actionButtonPressed(true, true, 0);
|
2017-12-08 18:35:59 +01:00
|
|
|
finishFragment();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() {
|
|
|
|
return selectedPhotos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolean notify, int scheduleDate) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedPhotos.isEmpty()) {
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (index < 0 || index >= selectedAlbum.photos.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
photoEntry.editedInfo = videoEditedInfo;
|
|
|
|
addToSelectedPhotos(photoEntry, -1);
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (index < 0 || index >= searchResult.size()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
MediaController.SearchImage searchImage = searchResult.get(index);
|
|
|
|
searchImage.editedInfo = videoEditedInfo;
|
|
|
|
addToSelectedPhotos(searchImage, -1);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(notify, scheduleDate);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<Object> getSelectedPhotosOrder() {
|
|
|
|
return selectedPhotosOrder;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public HashMap<Object, Object> getSelectedPhotos() {
|
|
|
|
return selectedPhotos;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public PhotoPickerActivity(int type, MediaController.AlbumEntry selectedAlbum, HashMap<Object, Object> selectedPhotos, ArrayList<Object> selectedPhotosOrder, int selectPhotoType, boolean allowCaption, ChatActivity chatActivity) {
|
2015-01-02 23:15:07 +01:00
|
|
|
super();
|
|
|
|
this.selectedAlbum = selectedAlbum;
|
|
|
|
this.selectedPhotos = selectedPhotos;
|
2017-12-08 18:35:59 +01:00
|
|
|
this.selectedPhotosOrder = selectedPhotosOrder;
|
2015-01-02 23:15:07 +01:00
|
|
|
this.type = type;
|
2019-01-23 18:03:33 +01:00
|
|
|
this.selectPhotoType = selectPhotoType;
|
2015-05-03 13:48:36 +02:00
|
|
|
this.chatActivity = chatActivity;
|
2016-10-11 13:57:01 +02:00
|
|
|
this.allowCaption = allowCaption;
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
if (selectedAlbum == null) {
|
|
|
|
loadRecentSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDocumentsPicker(boolean value) {
|
|
|
|
isDocumentsPicker = value;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
|
2014-06-12 03:13:15 +02:00
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
|
|
|
|
if (imageReqId != 0) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
|
|
|
|
imageReqId = 0;
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
if (commentTextView != null) {
|
|
|
|
commentTextView.onDestroy();
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-06-12 03:13:15 +02:00
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2019-12-31 14:08:08 +01:00
|
|
|
listSort = false;
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
actionBar.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
actionBar.setTitleColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
actionBar.setItemsColor(Theme.getColor(Theme.key_dialogTextBlack), false);
|
|
|
|
actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_dialogButtonSelector), false);
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
actionBar.setTitle(selectedAlbum.bucketName);
|
|
|
|
} else if (type == 0) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
|
|
|
|
} else if (type == 1) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
|
|
|
|
}
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (id == change_sort) {
|
|
|
|
listSort = !listSort;
|
|
|
|
if (listSort) {
|
|
|
|
listView.setPadding(0, 0, 0, AndroidUtilities.dp(48));
|
|
|
|
} else {
|
|
|
|
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
|
|
|
|
}
|
2020-04-24 11:21:58 +02:00
|
|
|
listView.stopScroll();
|
|
|
|
layoutManager.scrollToPositionWithOffset(0, 0);
|
2019-12-31 14:08:08 +01:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
} else if (id == open_in) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onOpenInPressed();
|
|
|
|
}
|
|
|
|
finishFragment();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
if (isDocumentsPicker) {
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
|
2020-06-04 18:47:15 +02:00
|
|
|
menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onShowSubMenu() {
|
|
|
|
showAsListItem.setText(listSort ? LocaleController.getString("ShowAsGrid", R.string.ShowAsGrid) : LocaleController.getString("ShowAsList", R.string.ShowAsList));
|
|
|
|
showAsListItem.setIcon(listSort ? R.drawable.msg_media : R.drawable.msg_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onHideSubMenu() {
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
});
|
|
|
|
showAsListItem = menuItem.addSubItem(change_sort, R.drawable.msg_list, LocaleController.getString("ShowAsList", R.string.ShowAsList));
|
|
|
|
menuItem.addSubItem(open_in, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
public boolean canCollapseSearch() {
|
2015-04-09 20:00:14 +02:00
|
|
|
finishFragment();
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
if (editText.getText().length() == 0) {
|
2015-01-02 23:15:07 +01:00
|
|
|
searchResult.clear();
|
|
|
|
searchResultKeys.clear();
|
2015-04-09 20:00:14 +02:00
|
|
|
lastSearchString = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
imageSearchEndReached = true;
|
2015-04-09 20:00:14 +02:00
|
|
|
searching = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (imageReqId != 0) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
|
|
|
|
imageReqId = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
|
2015-01-02 23:15:07 +01:00
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-09 20:00:14 +02:00
|
|
|
public void onSearchPressed(EditText editText) {
|
2019-01-23 18:03:33 +01:00
|
|
|
processSearch(editText);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
});
|
2019-08-22 01:53:26 +02:00
|
|
|
EditTextBoldCursor editText = searchItem.getSearchField();
|
|
|
|
editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
editText.setCursorColor(Theme.getColor(Theme.key_dialogTextBlack));
|
|
|
|
editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
if (type == 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (type == 1) {
|
2019-01-23 18:03:33 +01:00
|
|
|
searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2015-03-26 18:34:47 +01:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
private int lastNotifyWidth;
|
|
|
|
private boolean ignoreLayout;
|
|
|
|
private int lastItemSize;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int totalHeight = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
itemsPerRow = 4;
|
|
|
|
} else if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
|
|
|
|
itemsPerRow = 4;
|
|
|
|
} else {
|
|
|
|
itemsPerRow = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ignoreLayout = true;
|
|
|
|
itemSize = (availableWidth - AndroidUtilities.dp(6 * 2) - AndroidUtilities.dp(5 * 2)) / itemsPerRow;
|
|
|
|
|
|
|
|
if (lastItemSize != itemSize) {
|
|
|
|
lastItemSize = itemSize;
|
|
|
|
AndroidUtilities.runOnUIThread(() -> listAdapter.notifyDataSetChanged());
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (listSort) {
|
|
|
|
layoutManager.setSpanCount(1);
|
|
|
|
} else {
|
|
|
|
layoutManager.setSpanCount(itemSize * itemsPerRow + AndroidUtilities.dp(5) * (itemsPerRow - 1));
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
ignoreLayout = false;
|
|
|
|
onMeasureInternal(widthMeasureSpec, MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMeasureInternal(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
setMeasuredDimension(widthSize, heightSize);
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
int kbHeight = measureKeyboardHeight();
|
2020-02-13 19:26:53 +01:00
|
|
|
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : kbHeight;
|
2019-09-10 12:56:11 +02:00
|
|
|
if (keyboardSize <= AndroidUtilities.dp(20)) {
|
|
|
|
if (!AndroidUtilities.isInMultiwindow && commentTextView != null && frameLayout2.getParent() == this) {
|
|
|
|
heightSize -= commentTextView.getEmojiPadding();
|
|
|
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
if (kbHeight > AndroidUtilities.dp(20) && commentTextView != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
ignoreLayout = true;
|
|
|
|
commentTextView.hideEmojiView();
|
|
|
|
ignoreLayout = false;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
if (SharedConfig.smoothKeyboard && commentTextView != null && commentTextView.isPopupShowing()) {
|
2020-09-30 15:48:47 +02:00
|
|
|
fragmentView.setTranslationY(0);
|
2020-02-13 19:26:53 +01:00
|
|
|
listView.setTranslationY(0);
|
|
|
|
emptyView.setTranslationY(0);
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View child = getChildAt(i);
|
|
|
|
if (child == null || child.getVisibility() == GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (commentTextView != null && commentTextView.isPopupView(child)) {
|
|
|
|
if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
|
|
|
|
} else {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
if (lastNotifyWidth != r - l) {
|
|
|
|
lastNotifyWidth = r - l;
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final int count = getChildCount();
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
|
2020-02-13 19:26:53 +01:00
|
|
|
int paddingBottom = commentTextView != null && frameLayout2.getParent() == this && keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
|
2019-09-10 12:56:11 +02:00
|
|
|
setBottomClip(paddingBottom);
|
|
|
|
|
|
|
|
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:
|
|
|
|
childLeft = (r - l) - width - lp.rightMargin - getPaddingRight();
|
|
|
|
break;
|
|
|
|
case Gravity.LEFT:
|
|
|
|
default:
|
|
|
|
childLeft = lp.leftMargin + getPaddingLeft();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (verticalGravity) {
|
|
|
|
case Gravity.TOP:
|
|
|
|
childTop = lp.topMargin + getPaddingTop();
|
|
|
|
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 (commentTextView != null && commentTextView.isPopupView(child)) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
childTop = getMeasuredHeight() - child.getMeasuredHeight();
|
|
|
|
} else {
|
2020-02-13 19:26:53 +01:00
|
|
|
childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
child.layout(childLeft, childTop, childLeft + width, childTop + height);
|
|
|
|
}
|
|
|
|
|
|
|
|
notifyHeightChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (ignoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
sizeNotifierFrameLayout.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
fragmentView = sizeNotifierFrameLayout;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
2019-09-10 12:56:11 +02:00
|
|
|
listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setClipToPadding(false);
|
|
|
|
listView.setHorizontalScrollBarEnabled(false);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setItemAnimator(null);
|
|
|
|
listView.setLayoutAnimation(null);
|
|
|
|
listView.setLayoutManager(layoutManager = new GridLayoutManager(context, 4) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2019-09-10 12:56:11 +02:00
|
|
|
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public int getSpanSize(int position) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (listAdapter.getItemViewType(position) == 1 || listSort || selectedAlbum == null && TextUtils.isEmpty(lastSearchString)) {
|
|
|
|
return layoutManager.getSpanCount();
|
|
|
|
} else {
|
|
|
|
return itemSize + (position % itemsPerRow != itemsPerRow - 1 ? AndroidUtilities.dp(5) : 0);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
});
|
2019-09-10 12:56:11 +02:00
|
|
|
sizeNotifierFrameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
2019-08-22 01:53:26 +02:00
|
|
|
listView.setGlowColor(Theme.getColor(Theme.key_dialogBackground));
|
2019-01-23 18:03:33 +01:00
|
|
|
listView.setOnItemClickListener((view, position) -> {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (selectedAlbum == null && searchResult.isEmpty()) {
|
|
|
|
if (position < recentSearches.size()) {
|
|
|
|
String text = recentSearches.get(position);
|
|
|
|
if (searchDelegate != null) {
|
|
|
|
searchDelegate.shouldSearchText(text);
|
|
|
|
} else {
|
|
|
|
searchItem.getSearchField().setText(text);
|
|
|
|
searchItem.getSearchField().setSelection(text.length());
|
|
|
|
processSearch(searchItem.getSearchField());
|
|
|
|
}
|
|
|
|
} else if (position == recentSearches.size() + 1) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("ClearSearchAlertTitle", R.string.ClearSearchAlertTitle));
|
|
|
|
builder.setMessage(LocaleController.getString("ClearSearchAlert", R.string.ClearSearchAlert));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> {
|
|
|
|
if (searchDelegate != null) {
|
|
|
|
searchDelegate.shouldClearRecentSearch();
|
|
|
|
} else {
|
|
|
|
clearRecentSearch();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
AlertDialog dialog = builder.create();
|
|
|
|
showDialog(dialog);
|
|
|
|
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
|
|
|
if (button != null) {
|
|
|
|
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
ArrayList<Object> arrayList;
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
arrayList = (ArrayList) selectedAlbum.photos;
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
arrayList = (ArrayList) searchResult;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (position < 0 || position >= arrayList.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (searchItem != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (listSort) {
|
|
|
|
onListItemClick(view, arrayList.get(position));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
int type;
|
2020-07-26 10:03:38 +02:00
|
|
|
if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR || selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR_VIDEO) {
|
2019-12-31 14:08:08 +01:00
|
|
|
type = PhotoViewer.SELECT_TYPE_AVATAR;
|
2020-07-26 10:03:38 +02:00
|
|
|
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_WALLPAPER) {
|
2019-12-31 14:08:08 +01:00
|
|
|
type = PhotoViewer.SELECT_TYPE_WALLPAPER;
|
2020-07-26 10:03:38 +02:00
|
|
|
} else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_QR) {
|
2019-12-31 14:08:08 +01:00
|
|
|
type = PhotoViewer.SELECT_TYPE_QR;
|
|
|
|
} else if (chatActivity == null) {
|
|
|
|
type = 4;
|
|
|
|
} else {
|
|
|
|
type = 0;
|
|
|
|
}
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
|
|
|
|
PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, type, isDocumentsPicker, provider, chatActivity);
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2020-07-26 10:03:38 +02:00
|
|
|
if (maxSelectedPhotos != 1) {
|
|
|
|
listView.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (listSort) {
|
|
|
|
onListItemClick(view, selectedAlbum.photos.get(position));
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
itemRangeSelector.setIsActive(view, true, position, shouldSelect = !cell.isChecked());
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
itemRangeSelector = new RecyclerViewItemRangeSelector(new RecyclerViewItemRangeSelector.RecyclerViewItemRangeSelectorDelegate() {
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return listAdapter.getItemCount();
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
@Override
|
|
|
|
public void setSelected(View view, int index, boolean selected) {
|
|
|
|
if (selected != shouldSelect || !(view instanceof PhotoAttachPhotoCell)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
cell.callDelegate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSelected(int index) {
|
|
|
|
Object key;
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
key = photoEntry.imageId;
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
MediaController.SearchImage photoEntry = searchResult.get(index);
|
2019-09-10 12:56:11 +02:00
|
|
|
key = photoEntry.id;
|
|
|
|
}
|
|
|
|
return selectedPhotos.containsKey(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isIndexSelectable(int index) {
|
|
|
|
return listAdapter.getItemViewType(index) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartStopSelection(boolean start) {
|
|
|
|
alertOnlyOnce = start ? 1 : 0;
|
|
|
|
if (start) {
|
|
|
|
parentLayout.requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
listView.hideSelector(true);
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
});
|
2020-07-26 10:03:38 +02:00
|
|
|
if (maxSelectedPhotos != 1) {
|
|
|
|
listView.addOnItemTouchListener(itemRangeSelector);
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
emptyView = new EmptyTextProgressView(context);
|
2019-12-31 14:08:08 +01:00
|
|
|
emptyView.setTextColor(0xff93999d);
|
2019-08-22 01:53:26 +02:00
|
|
|
emptyView.setProgressBarColor(0xff527da3);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (selectedAlbum != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
emptyView.setShowAtCenter(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
emptyView.setShowAtTop(true);
|
|
|
|
emptyView.setPadding(0, AndroidUtilities.dp(200), 0, 0);
|
|
|
|
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL ? 0 : 48));
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
if (selectedAlbum == null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
|
|
|
if (visibleItemCount > 0) {
|
|
|
|
int totalItemCount = layoutManager.getItemCount();
|
|
|
|
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (!imageSearchEndReached) {
|
|
|
|
searchImages(type == 1, lastSearchString, nextImagesSearchOffset, true);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
}
|
|
|
|
});
|
2014-06-12 03:13:15 +02:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
if (selectedAlbum == null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
if (needsBottomLayout) {
|
2019-09-10 12:56:11 +02:00
|
|
|
shadow = new View(context);
|
|
|
|
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
|
|
|
|
shadow.setTranslationY(AndroidUtilities.dp(48));
|
|
|
|
sizeNotifierFrameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
|
|
|
|
|
|
|
|
frameLayout2 = new FrameLayout(context);
|
|
|
|
frameLayout2.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
frameLayout2.setVisibility(View.INVISIBLE);
|
|
|
|
frameLayout2.setTranslationY(AndroidUtilities.dp(48));
|
|
|
|
sizeNotifierFrameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
|
|
|
|
frameLayout2.setOnTouchListener((v, event) -> true);
|
|
|
|
|
|
|
|
if (commentTextView != null) {
|
|
|
|
commentTextView.onDestroy();
|
|
|
|
}
|
|
|
|
commentTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, null, EditTextEmoji.STYLE_DIALOG);
|
|
|
|
InputFilter[] inputFilters = new InputFilter[1];
|
|
|
|
inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength);
|
|
|
|
commentTextView.setFilters(inputFilters);
|
|
|
|
commentTextView.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
|
|
|
|
commentTextView.onResume();
|
|
|
|
EditTextBoldCursor editText = commentTextView.getEditText();
|
|
|
|
editText.setMaxLines(1);
|
|
|
|
editText.setSingleLine(true);
|
|
|
|
frameLayout2.addView(commentTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 84, 0));
|
|
|
|
if (caption != null) {
|
|
|
|
commentTextView.setText(caption);
|
|
|
|
}
|
|
|
|
commentTextView.getEditText().addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onCaptionChanged(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
writeButtonContainer = new FrameLayout(context) {
|
|
|
|
@Override
|
|
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
|
|
|
super.onInitializeAccessibilityNodeInfo(info);
|
|
|
|
info.setText(LocaleController.formatPluralString("AccDescrSendPhotos", selectedPhotos.size()));
|
|
|
|
info.setClassName(Button.class.getName());
|
|
|
|
info.setLongClickable(true);
|
|
|
|
info.setClickable(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
writeButtonContainer.setFocusable(true);
|
|
|
|
writeButtonContainer.setFocusableInTouchMode(true);
|
2019-09-10 12:56:11 +02:00
|
|
|
writeButtonContainer.setVisibility(View.INVISIBLE);
|
|
|
|
writeButtonContainer.setScaleX(0.2f);
|
|
|
|
writeButtonContainer.setScaleY(0.2f);
|
|
|
|
writeButtonContainer.setAlpha(0.0f);
|
2019-12-31 14:08:08 +01:00
|
|
|
sizeNotifierFrameLayout.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
|
|
|
|
|
|
|
|
writeButton = new ImageView(context);
|
|
|
|
writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_dialogFloatingButton), Theme.getColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
|
|
|
|
if (Build.VERSION.SDK_INT < 21) {
|
|
|
|
Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
|
|
|
|
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
|
|
|
|
CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, writeButtonDrawable, 0, 0);
|
|
|
|
combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
|
|
|
|
writeButtonDrawable = combinedDrawable;
|
|
|
|
}
|
|
|
|
writeButton.setBackgroundDrawable(writeButtonDrawable);
|
|
|
|
writeButton.setImageResource(R.drawable.attach_send);
|
2020-07-26 10:03:38 +02:00
|
|
|
writeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
|
2019-12-31 14:08:08 +01:00
|
|
|
writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
writeButton.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
writeButton.setOutlineProvider(new ViewOutlineProvider() {
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
writeButtonContainer.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
|
|
|
|
writeButton.setOnClickListener(v -> {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (chatActivity != null && chatActivity.isInScheduleMode()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
|
2019-09-10 12:56:11 +02:00
|
|
|
} else {
|
|
|
|
sendSelectedPhotos(true, 0);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
2019-12-31 14:08:08 +01:00
|
|
|
writeButton.setOnLongClickListener(view -> {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (chatActivity == null || maxSelectedPhotos == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TLRPC.Chat chat = chatActivity.getCurrentChat();
|
|
|
|
TLRPC.User user = chatActivity.getCurrentUser();
|
|
|
|
|
|
|
|
if (sendPopupLayout == null) {
|
|
|
|
sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
|
|
|
|
sendPopupLayout.setAnimationEnabled(false);
|
|
|
|
sendPopupLayout.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
|
|
|
private android.graphics.Rect popupRect = new android.graphics.Rect();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
|
|
|
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
v.getHitRect(popupRect);
|
|
|
|
if (!popupRect.contains((int) event.getX(), (int) event.getY())) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
|
|
|
|
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
sendPopupLayout.setShowedFromBotton(false);
|
|
|
|
|
|
|
|
itemCells = new ActionBarMenuSubItem[2];
|
|
|
|
for (int a = 0; a < 2; a++) {
|
2020-09-30 15:48:47 +02:00
|
|
|
if (a == 0 && !chatActivity.canScheduleMessage() || a == 1 && UserObject.isUserSelf(user)) {
|
2019-09-10 12:56:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int num = a;
|
|
|
|
itemCells[a] = new ActionBarMenuSubItem(getParentActivity());
|
|
|
|
if (num == 0) {
|
|
|
|
if (UserObject.isUserSelf(user)) {
|
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
|
|
|
|
} else {
|
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
|
|
|
|
}
|
|
|
|
} else if (num == 1) {
|
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
|
|
|
|
}
|
|
|
|
itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
sendPopupLayout.addView(itemCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
2019-09-10 12:56:11 +02:00
|
|
|
itemCells[a].setOnClickListener(v -> {
|
|
|
|
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
if (num == 0) {
|
2019-12-31 14:08:08 +01:00
|
|
|
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
|
2019-09-10 12:56:11 +02:00
|
|
|
} else if (num == 1) {
|
|
|
|
sendSelectedPhotos(true, 0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
sendPopupLayout.setupRadialSelectors(Theme.getColor(Theme.key_dialogButtonSelector));
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
|
|
|
|
sendPopupWindow.setAnimationEnabled(false);
|
|
|
|
sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
|
|
|
|
sendPopupWindow.setOutsideTouchable(true);
|
|
|
|
sendPopupWindow.setClippingEnabled(true);
|
|
|
|
sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
|
|
|
sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
|
|
|
|
sendPopupWindow.getContentView().setFocusableInTouchMode(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
|
|
|
|
sendPopupWindow.setFocusable(true);
|
|
|
|
int[] location = new int[2];
|
|
|
|
view.getLocationInWindow(location);
|
|
|
|
sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(8), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(2));
|
|
|
|
sendPopupWindow.dimBehind();
|
|
|
|
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
textPaint.setTextSize(AndroidUtilities.dp(12));
|
|
|
|
textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
|
|
|
|
selectedCountView = new View(context) {
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
String text = String.format("%d", Math.max(1, selectedPhotosOrder.size()));
|
|
|
|
int textSize = (int) Math.ceil(textPaint.measureText(text));
|
|
|
|
int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
|
|
|
|
int cx = getMeasuredWidth() / 2;
|
|
|
|
int cy = getMeasuredHeight() / 2;
|
|
|
|
|
|
|
|
textPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBoxCheck));
|
|
|
|
paint.setColor(Theme.getColor(Theme.key_dialogBackground));
|
|
|
|
rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
|
|
|
|
canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
|
|
|
|
|
|
|
|
paint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
|
|
|
|
rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
|
|
|
|
canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
|
|
|
|
|
|
|
|
canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
selectedCountView.setAlpha(0.0f);
|
|
|
|
selectedCountView.setScaleX(0.2f);
|
|
|
|
selectedCountView.setScaleY(0.2f);
|
2019-12-31 14:08:08 +01:00
|
|
|
sizeNotifierFrameLayout.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
|
2020-07-26 10:03:38 +02:00
|
|
|
if (selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL) {
|
2019-09-10 12:56:11 +02:00
|
|
|
commentTextView.setVisibility(View.GONE);
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
allowIndices = (selectedAlbum != null || type == 0 || type == 1) && allowOrder;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
listView.setEmptyView(emptyView);
|
2019-09-10 12:56:11 +02:00
|
|
|
updatePhotosButton(0);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
@Override
|
2020-09-30 15:48:47 +02:00
|
|
|
protected void onPanTranslationUpdate(float y) {
|
2020-02-13 19:26:53 +01:00
|
|
|
if (listView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (commentTextView.isPopupShowing()) {
|
|
|
|
fragmentView.setTranslationY(y);
|
|
|
|
listView.setTranslationY(0);
|
|
|
|
emptyView.setTranslationY(0);
|
|
|
|
} else {
|
|
|
|
listView.setTranslationY(y);
|
|
|
|
emptyView.setTranslationY(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
public void setLayoutViews(FrameLayout f2, FrameLayout button, View count, View s, EditTextEmoji emoji) {
|
|
|
|
frameLayout2 = f2;
|
|
|
|
writeButtonContainer = button;
|
|
|
|
commentTextView = emoji;
|
|
|
|
selectedCountView = count;
|
|
|
|
shadow = s;
|
2019-08-22 01:53:26 +02:00
|
|
|
needsBottomLayout = false;
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private void applyCaption() {
|
|
|
|
if (commentTextView == null || commentTextView.length() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Object imageId = selectedPhotosOrder.get(0);
|
|
|
|
Object entry = selectedPhotos.get(imageId);
|
|
|
|
if (entry instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) entry;
|
|
|
|
photoEntry.caption = commentTextView.getText().toString();
|
|
|
|
} else if (entry instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) entry;
|
|
|
|
searchImage.caption = commentTextView.getText().toString();
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void onListItemClick(View view, Object item) {
|
|
|
|
boolean add;
|
|
|
|
if (addToSelectedPhotos(item, -1) == -1) {
|
|
|
|
add = true;
|
|
|
|
} else {
|
|
|
|
add = false;
|
|
|
|
}
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
|
|
|
Integer index = (Integer) view.getTag();
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
SharedDocumentCell cell = (SharedDocumentCell) view;
|
|
|
|
cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId) >= 0, true);
|
|
|
|
}
|
|
|
|
updatePhotosButton(add ? 1 : 2);
|
|
|
|
delegate.selectedPhotosChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearRecentSearch() {
|
|
|
|
recentSearches.clear();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
saveRecentSearch();
|
|
|
|
}
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
if (commentTextView != null) {
|
|
|
|
commentTextView.onResume();
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (searchItem != null) {
|
2015-09-24 22:52:02 +02:00
|
|
|
searchItem.openSearch(true);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!TextUtils.isEmpty(initialSearchString)) {
|
|
|
|
searchItem.setSearchFieldText(initialSearchString, false);
|
|
|
|
initialSearchString = null;
|
|
|
|
processSearch(searchItem.getSearchField());
|
|
|
|
}
|
2020-02-13 19:26:53 +01:00
|
|
|
getParentActivity().getWindow().setSoftInputMode(SharedConfig.smoothKeyboard ? WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN : WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (id == NotificationCenter.closeChats) {
|
2014-06-12 03:13:15 +02:00
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public RecyclerListView getListView() {
|
|
|
|
return listView;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
public void setCaption(CharSequence text) {
|
|
|
|
caption = text;
|
|
|
|
if (commentTextView != null) {
|
|
|
|
commentTextView.setText(caption);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setInitialSearchString(String text) {
|
|
|
|
initialSearchString = text;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void saveRecentSearch() {
|
|
|
|
SharedPreferences.Editor editor = ApplicationLoader.applicationContext.getSharedPreferences("web_recent_search", Activity.MODE_PRIVATE).edit();
|
|
|
|
editor.clear();
|
|
|
|
editor.putInt("count", recentSearches.size());
|
|
|
|
for (int a = 0, N = recentSearches.size(); a < N; a++) {
|
|
|
|
editor.putString("recent" + a, recentSearches.get(a));
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void loadRecentSearch() {
|
|
|
|
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("web_recent_search", Activity.MODE_PRIVATE);
|
|
|
|
int count = preferences.getInt("count", 0);
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
String str = preferences.getString("recent" + a, null);
|
|
|
|
if (str == null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
recentSearches.add(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private void processSearch(EditText editText) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (editText.getText().length() == 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
String text = editText.getText().toString();
|
|
|
|
for (int a = 0, N = recentSearches.size(); a < N; a++) {
|
|
|
|
String str = recentSearches.get(a);
|
|
|
|
if (str.equalsIgnoreCase(text)) {
|
|
|
|
recentSearches.remove(a);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recentSearches.add(0, text);
|
|
|
|
while (recentSearches.size() > 20) {
|
|
|
|
recentSearches.remove(recentSearches.size() - 1);
|
|
|
|
}
|
|
|
|
saveRecentSearch();
|
2019-01-23 18:03:33 +01:00
|
|
|
searchResult.clear();
|
|
|
|
searchResultKeys.clear();
|
2019-05-14 14:08:05 +02:00
|
|
|
imageSearchEndReached = true;
|
2019-12-31 14:08:08 +01:00
|
|
|
searchImages(type == 1, text, "", true);
|
|
|
|
lastSearchString = text;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (lastSearchString.length() == 0) {
|
|
|
|
lastSearchString = null;
|
2019-12-31 14:08:08 +01:00
|
|
|
emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
|
|
|
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
}
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private boolean showCommentTextView(boolean show, boolean animated) {
|
|
|
|
if (commentTextView == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (show == (frameLayout2.getTag() != null)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (animatorSet != null) {
|
|
|
|
animatorSet.cancel();
|
|
|
|
}
|
|
|
|
frameLayout2.setTag(show ? 1 : null);
|
|
|
|
if (commentTextView.getEditText().isFocused()) {
|
|
|
|
AndroidUtilities.hideKeyboard(commentTextView.getEditText());
|
|
|
|
}
|
|
|
|
commentTextView.hidePopup(true);
|
|
|
|
if (show) {
|
|
|
|
frameLayout2.setVisibility(View.VISIBLE);
|
|
|
|
writeButtonContainer.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
animatorSet = new AnimatorSet();
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
|
|
animators.add(ObjectAnimator.ofFloat(writeButtonContainer, View.SCALE_X, show ? 1.0f : 0.2f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(writeButtonContainer, View.SCALE_Y, show ? 1.0f : 0.2f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(writeButtonContainer, View.ALPHA, show ? 1.0f : 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(selectedCountView, View.SCALE_X, show ? 1.0f : 0.2f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(selectedCountView, View.SCALE_Y, show ? 1.0f : 0.2f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(selectedCountView, View.ALPHA, show ? 1.0f : 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(frameLayout2, View.TRANSLATION_Y, show ? 0 : AndroidUtilities.dp(48)));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(shadow, View.TRANSLATION_Y, show ? 0 : AndroidUtilities.dp(48)));
|
|
|
|
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.setInterpolator(new DecelerateInterpolator());
|
|
|
|
animatorSet.setDuration(180);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(animatorSet)) {
|
|
|
|
if (!show) {
|
|
|
|
frameLayout2.setVisibility(View.INVISIBLE);
|
|
|
|
writeButtonContainer.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
animatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(animatorSet)) {
|
|
|
|
animatorSet = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
writeButtonContainer.setScaleX(show ? 1.0f : 0.2f);
|
|
|
|
writeButtonContainer.setScaleY(show ? 1.0f : 0.2f);
|
|
|
|
writeButtonContainer.setAlpha(show ? 1.0f : 0.0f);
|
|
|
|
selectedCountView.setScaleX(show ? 1.0f : 0.2f);
|
|
|
|
selectedCountView.setScaleY(show ? 1.0f : 0.2f);
|
|
|
|
selectedCountView.setAlpha(show ? 1.0f : 0.0f);
|
|
|
|
frameLayout2.setTranslationY(show ? 0 : AndroidUtilities.dp(48));
|
|
|
|
shadow.setTranslationY(show ? 0 : AndroidUtilities.dp(48));
|
|
|
|
if (!show) {
|
|
|
|
frameLayout2.setVisibility(View.INVISIBLE);
|
|
|
|
writeButtonContainer.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public void setMaxSelectedPhotos(int value, boolean order) {
|
2018-07-30 04:07:02 +02:00
|
|
|
maxSelectedPhotos = value;
|
2019-08-22 01:53:26 +02:00
|
|
|
allowOrder = order;
|
2019-09-10 12:56:11 +02:00
|
|
|
if (value > 0 && type == 1) {
|
2019-08-22 01:53:26 +02:00
|
|
|
maxSelectedPhotos = 1;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void updateCheckedPhotoIndices() {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!allowIndices) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2019-09-10 12:56:11 +02:00
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
2019-12-31 14:08:08 +01:00
|
|
|
Integer index = (Integer) view.getTag();
|
2018-07-30 04:07:02 +02:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
cell.setNum(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.imageId) : -1);
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
MediaController.SearchImage photoEntry = searchResult.get(index);
|
2018-07-30 04:07:02 +02:00
|
|
|
cell.setNum(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.id) : -1);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (view instanceof SharedDocumentCell) {
|
|
|
|
Integer index = (Integer) view.getTag();
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
SharedDocumentCell cell = (SharedDocumentCell) view;
|
|
|
|
cell.setChecked(selectedPhotosOrder.indexOf(photoEntry.imageId) != 0, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private PhotoAttachPhotoCell getCellForIndex(int index) {
|
2014-06-12 03:13:15 +02:00
|
|
|
int count = listView.getChildCount();
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2019-09-10 12:56:11 +02:00
|
|
|
if (view instanceof PhotoAttachPhotoCell) {
|
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
|
|
|
|
int num = (Integer) cell.getTag();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (num < 0 || num >= selectedAlbum.photos.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (num < 0 || num >= searchResult.size()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num == index) {
|
|
|
|
return cell;
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
return null;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private int addToSelectedPhotos(Object object, int index) {
|
|
|
|
Object key = null;
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
key = ((MediaController.PhotoEntry) object).imageId;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
key = ((MediaController.SearchImage) object).id;
|
|
|
|
}
|
|
|
|
if (key == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (selectedPhotos.containsKey(key)) {
|
|
|
|
selectedPhotos.remove(key);
|
|
|
|
int position = selectedPhotosOrder.indexOf(key);
|
|
|
|
if (position >= 0) {
|
|
|
|
selectedPhotosOrder.remove(position);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (allowIndices) {
|
|
|
|
updateCheckedPhotoIndices();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (index >= 0) {
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
((MediaController.PhotoEntry) object).reset();
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
((MediaController.SearchImage) object).reset();
|
|
|
|
}
|
|
|
|
provider.updatePhotoAtIndex(index);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
return position;
|
|
|
|
} else {
|
|
|
|
selectedPhotos.put(key, object);
|
|
|
|
selectedPhotosOrder.add(key);
|
|
|
|
return -1;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 18:10:07 +01:00
|
|
|
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
if (isOpen && searchItem != null) {
|
2015-01-02 23:15:07 +01:00
|
|
|
AndroidUtilities.showKeyboard(searchItem.getSearchField());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
@Override
|
|
|
|
public boolean onBackPressed() {
|
|
|
|
if (commentTextView != null && commentTextView.isPopupShowing()) {
|
|
|
|
commentTextView.hidePopup(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
public void updatePhotosButton(int animated) {
|
|
|
|
int count = selectedPhotos.size();
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
selectedCountView.setPivotX(0);
|
|
|
|
selectedCountView.setPivotY(0);
|
|
|
|
showCommentTextView(false, animated != 0);
|
|
|
|
} else {
|
|
|
|
selectedCountView.invalidate();
|
|
|
|
if (!showCommentTextView(true, animated != 0) && animated != 0) {
|
|
|
|
selectedCountView.setPivotX(AndroidUtilities.dp(21));
|
|
|
|
selectedCountView.setPivotY(AndroidUtilities.dp(12));
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
animatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(selectedCountView, View.SCALE_X, animated == 1 ? 1.1f : 0.9f, 1.0f),
|
|
|
|
ObjectAnimator.ofFloat(selectedCountView, View.SCALE_Y, animated == 1 ? 1.1f : 0.9f, 1.0f));
|
|
|
|
animatorSet.setInterpolator(new OvershootInterpolator());
|
|
|
|
animatorSet.setDuration(180);
|
|
|
|
animatorSet.start();
|
|
|
|
} else {
|
|
|
|
selectedCountView.setPivotX(0);
|
|
|
|
selectedCountView.setPivotY(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private void updateSearchInterface() {
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (searching && searchResult.isEmpty()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
emptyView.showProgress();
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
emptyView.showTextView();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private void searchBotUser(boolean gif) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (searchingUser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
searchingUser = true;
|
|
|
|
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
|
2019-05-14 14:08:05 +02:00
|
|
|
req.username = gif ? MessagesController.getInstance(currentAccount).gifSearchBot : MessagesController.getInstance(currentAccount).imageSearchBot;
|
2019-01-23 18:03:33 +01:00
|
|
|
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
if (response != null) {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
|
|
|
|
MessagesController.getInstance(currentAccount).putUsers(res.users, false);
|
|
|
|
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
|
|
|
|
MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, true, true);
|
|
|
|
String str = lastSearchImageString;
|
|
|
|
lastSearchImageString = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
searchImages(gif, str, "", false);
|
2019-01-23 18:03:33 +01:00
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private void searchImages(boolean gif, final String query, final String offset, boolean searchUser) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (searching) {
|
|
|
|
searching = false;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (imageReqId != 0) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
|
|
|
|
imageReqId = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
lastSearchImageString = query;
|
|
|
|
searching = true;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(gif ? MessagesController.getInstance(currentAccount).gifSearchBot : MessagesController.getInstance(currentAccount).imageSearchBot);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!(object instanceof TLRPC.User)) {
|
|
|
|
if (searchUser) {
|
2019-05-14 14:08:05 +02:00
|
|
|
searchBotUser(gif);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.User user = (TLRPC.User) object;
|
|
|
|
|
|
|
|
TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults();
|
|
|
|
req.query = query == null ? "" : query;
|
|
|
|
req.bot = MessagesController.getInstance(currentAccount).getInputUser(user);
|
|
|
|
req.offset = offset;
|
|
|
|
|
|
|
|
if (chatActivity != null) {
|
|
|
|
long dialogId = chatActivity.getDialogId();
|
|
|
|
int lower_id = (int) dialogId;
|
|
|
|
int high_id = (int) (dialogId >> 32);
|
|
|
|
if (lower_id != 0) {
|
|
|
|
req.peer = MessagesController.getInstance(currentAccount).getInputPeer(lower_id);
|
|
|
|
} else {
|
|
|
|
req.peer = new TLRPC.TL_inputPeerEmpty();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
req.peer = new TLRPC.TL_inputPeerEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
final int token = ++lastSearchToken;
|
2019-01-23 18:03:33 +01:00
|
|
|
imageReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (token != lastSearchToken) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int addedCount = 0;
|
2019-02-08 03:30:32 +01:00
|
|
|
int oldCount = searchResult.size();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (response != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response;
|
|
|
|
nextImagesSearchOffset = res.next_offset;
|
|
|
|
|
|
|
|
for (int a = 0, count = res.results.size(); a < count; a++) {
|
|
|
|
TLRPC.BotInlineResult result = res.results.get(a);
|
2019-05-14 14:08:05 +02:00
|
|
|
if (!gif && !"photo".equals(result.type) || gif && !"gif".equals(result.type)) {
|
2019-01-23 18:03:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (searchResultKeys.containsKey(result.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
MediaController.SearchImage image = new MediaController.SearchImage();
|
|
|
|
|
|
|
|
if (gif && result.document != null) {
|
|
|
|
for (int b = 0; b < result.document.attributes.size(); b++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = result.document.attributes.get(b);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
image.width = attribute.w;
|
|
|
|
image.height = attribute.h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image.document = result.document;
|
|
|
|
image.size = 0;
|
|
|
|
if (result.photo != null && result.document != null) {
|
2019-09-10 12:56:11 +02:00
|
|
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(result.photo.sizes, itemSize, true);
|
2019-05-14 14:08:05 +02:00
|
|
|
if (size != null) {
|
|
|
|
result.document.thumbs.add(size);
|
|
|
|
result.document.flags |= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!gif && result.photo != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(result.photo.sizes, AndroidUtilities.getPhotoSize());
|
|
|
|
TLRPC.PhotoSize size2 = FileLoader.getClosestPhotoSizeWithSize(result.photo.sizes, 320);
|
|
|
|
if (size == null) {
|
|
|
|
continue;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
image.width = size.w;
|
|
|
|
image.height = size.h;
|
|
|
|
image.photoSize = size;
|
|
|
|
image.photo = result.photo;
|
|
|
|
image.size = size.size;
|
|
|
|
image.thumbPhotoSize = size2;
|
2019-01-23 18:03:33 +01:00
|
|
|
} else {
|
|
|
|
if (result.content == null) {
|
|
|
|
continue;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
for (int b = 0; b < result.content.attributes.size(); b++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = result.content.attributes.get(b);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
|
2019-05-14 14:08:05 +02:00
|
|
|
image.width = attribute.w;
|
|
|
|
image.height = attribute.h;
|
2019-01-23 18:03:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (result.thumb != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
image.thumbUrl = result.thumb.url;
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
image.thumbUrl = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
image.imageUrl = result.content.url;
|
|
|
|
image.size = gif ? 0 : result.content.size;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
image.id = result.id;
|
|
|
|
image.type = gif ? 1 : 0;
|
2019-09-10 12:56:11 +02:00
|
|
|
image.inlineResult = result;
|
|
|
|
image.params = new HashMap<>();
|
|
|
|
image.params.put("id", result.id);
|
|
|
|
image.params.put("query_id", "" + res.query_id);
|
|
|
|
image.params.put("bot_name", user.username);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
searchResult.add(image);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
searchResultKeys.put(image.id, image);
|
2019-01-23 18:03:33 +01:00
|
|
|
addedCount++;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
imageSearchEndReached = oldCount == searchResult.size() || nextImagesSearchOffset == null;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
searching = false;
|
|
|
|
if (addedCount != 0) {
|
2019-02-08 03:30:32 +01:00
|
|
|
listAdapter.notifyItemRangeInserted(oldCount, addedCount);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (imageSearchEndReached) {
|
2019-01-23 18:03:33 +01:00
|
|
|
listAdapter.notifyItemRemoved(searchResult.size() - 1);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (searching && searchResult.isEmpty()) {
|
2019-01-23 18:03:33 +01:00
|
|
|
emptyView.showProgress();
|
|
|
|
} else {
|
|
|
|
emptyView.showTextView();
|
|
|
|
}
|
|
|
|
}));
|
2018-07-30 04:07:02 +02:00
|
|
|
ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(imageReqId, classGuid);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public void setDelegate(PhotoPickerActivityDelegate photoPickerActivityDelegate) {
|
|
|
|
delegate = photoPickerActivityDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSearchDelegate(PhotoPickerActivitySearchDelegate photoPickerActivitySearchDelegate) {
|
|
|
|
searchDelegate = photoPickerActivitySearchDelegate;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private void sendSelectedPhotos(boolean notify, int scheduleDate) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (selectedPhotos.isEmpty() || delegate == null || sendPressed) {
|
2014-06-12 03:13:15 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
applyCaption();
|
2014-06-12 21:55:13 +02:00
|
|
|
sendPressed = true;
|
2019-09-10 12:56:11 +02:00
|
|
|
delegate.actionButtonPressed(false, notify, scheduleDate);
|
2020-07-26 10:03:38 +02:00
|
|
|
if (selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_WALLPAPER) {
|
2019-01-23 18:03:33 +01:00
|
|
|
finishFragment();
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (selectedAlbum == null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (TextUtils.isEmpty(lastSearchString)) {
|
|
|
|
return holder.getItemViewType() == 3;
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
return holder.getAdapterPosition() < searchResult.size();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (selectedAlbum == null) {
|
2019-08-22 01:53:26 +02:00
|
|
|
if (searchResult.isEmpty()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (TextUtils.isEmpty(lastSearchString)) {
|
|
|
|
return recentSearches.isEmpty() ? 0 : recentSearches.size() + 2;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
|
|
|
return searchResult.size() + (imageSearchEndReached ? 0 : 1);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
return selectedAlbum.photos.size();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = new PhotoAttachPhotoCell(mContext);
|
|
|
|
cell.setDelegate(new PhotoAttachPhotoCell.PhotoAttachPhotoCellDelegate() {
|
|
|
|
|
|
|
|
private void checkSlowMode() {
|
|
|
|
if (allowOrder && chatActivity != null) {
|
|
|
|
TLRPC.Chat chat = chatActivity.getCurrentChat();
|
|
|
|
if (chat != null && !ChatObject.hasAdminRights(chat) && chat.slowmode_enabled) {
|
|
|
|
if (alertOnlyOnce != 2) {
|
2019-08-22 01:53:26 +02:00
|
|
|
AlertsCreator.showSimpleAlert(PhotoPickerActivity.this, LocaleController.getString("Slowmode", R.string.Slowmode), LocaleController.getString("SlowmodeSelectSendError", R.string.SlowmodeSelectSendError));
|
2019-09-10 12:56:11 +02:00
|
|
|
if (alertOnlyOnce == 1) {
|
|
|
|
alertOnlyOnce = 2;
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckClick(PhotoAttachPhotoCell v) {
|
|
|
|
int index = (Integer) v.getTag();
|
|
|
|
boolean added;
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
added = !selectedPhotos.containsKey(photoEntry.imageId);
|
|
|
|
if (added && maxSelectedPhotos > 0 && selectedPhotos.size() >= maxSelectedPhotos) {
|
|
|
|
checkSlowMode();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int num = allowIndices && added ? selectedPhotosOrder.size() : -1;
|
|
|
|
v.setChecked(num, added, true);
|
|
|
|
addToSelectedPhotos(photoEntry, index);
|
2014-06-12 03:13:15 +02:00
|
|
|
} else {
|
2019-09-10 12:56:11 +02:00
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2019-12-31 14:08:08 +01:00
|
|
|
MediaController.SearchImage photoEntry = searchResult.get(index);
|
2019-09-10 12:56:11 +02:00
|
|
|
added = !selectedPhotos.containsKey(photoEntry.id);
|
|
|
|
if (added && maxSelectedPhotos > 0 && selectedPhotos.size() >= maxSelectedPhotos) {
|
|
|
|
checkSlowMode();
|
|
|
|
return;
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
int num = allowIndices && added ? selectedPhotosOrder.size() : -1;
|
|
|
|
v.setChecked(num, added, true);
|
|
|
|
addToSelectedPhotos(photoEntry, index);
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
updatePhotosButton(added ? 1 : 2);
|
|
|
|
delegate.selectedPhotosChanged();
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
});
|
2020-07-26 10:03:38 +02:00
|
|
|
cell.getCheckFrame().setVisibility(selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL ? View.GONE : View.VISIBLE);
|
2017-03-31 01:58:05 +02:00
|
|
|
view = cell;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
FrameLayout frameLayout = new FrameLayout(mContext);
|
|
|
|
view = frameLayout;
|
2019-12-31 14:08:08 +01:00
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
2017-03-31 01:58:05 +02:00
|
|
|
RadialProgressView progressBar = new RadialProgressView(mContext);
|
2019-08-22 01:53:26 +02:00
|
|
|
progressBar.setProgressColor(0xff527da3);
|
2017-03-31 01:58:05 +02:00
|
|
|
frameLayout.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
break;
|
2019-12-31 14:08:08 +01:00
|
|
|
case 2:
|
2020-09-30 15:48:47 +02:00
|
|
|
view = new SharedDocumentCell(mContext, SharedDocumentCell.VIEW_TYPE_PICKER);
|
2019-12-31 14:08:08 +01:00
|
|
|
break;
|
|
|
|
case 3: {
|
|
|
|
view = new TextCell(mContext, 23, true);
|
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
default: {
|
|
|
|
view = new DividerCell(mContext);
|
|
|
|
break;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
case 0: {
|
2019-09-10 12:56:11 +02:00
|
|
|
PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) holder.itemView;
|
|
|
|
cell.setItemSize(itemSize);
|
|
|
|
|
|
|
|
BackupImageView imageView = cell.getImageView();
|
2017-03-31 01:58:05 +02:00
|
|
|
cell.setTag(position);
|
|
|
|
boolean showing;
|
|
|
|
imageView.setOrientation(0, true);
|
|
|
|
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(position);
|
2019-09-10 12:56:11 +02:00
|
|
|
cell.setPhotoEntry(photoEntry, true, false);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setChecked(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.imageId) : -1, selectedPhotos.containsKey(photoEntry.imageId), false);
|
2018-07-30 04:07:02 +02:00
|
|
|
showing = PhotoViewer.isShowingImage(photoEntry.path);
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
MediaController.SearchImage photoEntry = searchResult.get(position);
|
2019-09-10 12:56:11 +02:00
|
|
|
cell.setPhotoEntry(photoEntry, true, false);
|
|
|
|
cell.getVideoInfoContainer().setVisibility(View.INVISIBLE);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setChecked(allowIndices ? selectedPhotosOrder.indexOf(photoEntry.id) : -1, selectedPhotos.containsKey(photoEntry.id), false);
|
2018-07-30 04:07:02 +02:00
|
|
|
showing = PhotoViewer.isShowingImage(photoEntry.getPathToAttach());
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
imageView.getImageReceiver().setVisible(!showing, true);
|
2020-07-26 10:03:38 +02:00
|
|
|
cell.getCheckBox().setVisibility(selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL || showing ? View.GONE : View.VISIBLE);
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
case 1: {
|
2017-03-31 01:58:05 +02:00
|
|
|
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
|
|
|
if (params != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
params.width = LayoutHelper.MATCH_PARENT;
|
2019-09-10 12:56:11 +02:00
|
|
|
params.height = itemSize;
|
2017-03-31 01:58:05 +02:00
|
|
|
holder.itemView.setLayoutParams(params);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(position);
|
|
|
|
SharedDocumentCell documentCell = (SharedDocumentCell) holder.itemView;
|
|
|
|
documentCell.setPhotoEntry(photoEntry);
|
|
|
|
documentCell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
|
|
|
|
documentCell.setTag(position);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
TextCell cell = (TextCell) holder.itemView;
|
|
|
|
if (position < recentSearches.size()) {
|
|
|
|
cell.setTextAndIcon(recentSearches.get(position), R.drawable.menu_recent, false);
|
|
|
|
} else {
|
|
|
|
cell.setTextAndIcon(LocaleController.getString("ClearRecentHistory", R.string.ClearRecentHistory), R.drawable.menu_clear_recent, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-12-31 14:08:08 +01:00
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (listSort) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
return 0;
|
|
|
|
} else if (searchResult.isEmpty()) {
|
|
|
|
return position == recentSearches.size() ? 4 : 3;
|
|
|
|
} else if (position < searchResult.size()) {
|
2015-01-02 23:15:07 +01:00
|
|
|
return 0;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
return 1;
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
|
|
|
|
@Override
|
2020-04-24 11:21:58 +02:00
|
|
|
public ArrayList<ThemeDescription> getThemeDescriptions() {
|
|
|
|
ArrayList<ThemeDescription> themeDescriptions = new ArrayList<>();
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(sizeNotifierFrameLayout, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_dialogBackground));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_dialogBackground));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_dialogTextBlack));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_dialogTextBlack));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_dialogButtonSelector));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCH, null, null, null, null, Theme.key_dialogTextBlack));
|
|
|
|
themeDescriptions.add(new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCHPLACEHOLDER, null, null, null, null, Theme.key_chat_messagePanelHint));
|
|
|
|
themeDescriptions.add(new ThemeDescription(searchItem != null ? searchItem.getSearchField() : null, ThemeDescription.FLAG_CURSORCOLOR, null, null, null, null, Theme.key_dialogTextBlack));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_dialogBackground));
|
|
|
|
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{View.class}, null, new Drawable[]{Theme.chat_attachEmptyDrawable}, null, Theme.key_chat_attachEmptyImage));
|
|
|
|
themeDescriptions.add(new ThemeDescription(listView, 0, new Class[]{View.class}, null, null, null, Theme.key_chat_attachPhotoBackground));
|
|
|
|
|
|
|
|
return themeDescriptions;
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2014-06-12 03:13:15 +02:00
|
|
|
}
|