2015-01-02 23:15:07 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 2.0.x.
|
|
|
|
* 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.
|
2015-01-02 23:15:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
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;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.os.Build;
|
|
|
|
import android.text.InputFilter;
|
|
|
|
import android.text.TextPaint;
|
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;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.view.ViewOutlineProvider;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.FrameLayout;
|
2019-09-10 12:56:11 +02:00
|
|
|
import android.widget.ImageView;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2020-06-25 17:28:44 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2020-06-26 06:54:48 +02:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.messenger.R;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.SendMessagesHelper;
|
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;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
2019-12-31 14:08:08 +01:00
|
|
|
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;
|
2020-06-25 17:28:44 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Cells.PhotoPickerAlbumsCell;
|
2019-09-10 12:56:11 +02:00
|
|
|
import org.telegram.ui.Components.AlertsCreator;
|
|
|
|
import org.telegram.ui.Components.CombinedDrawable;
|
|
|
|
import org.telegram.ui.Components.EditTextBoldCursor;
|
|
|
|
import org.telegram.ui.Components.EditTextEmoji;
|
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.SizeNotifierFrameLayout;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2020-06-25 17:28:44 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2020-06-25 17:28:44 +02:00
|
|
|
import kotlin.Unit;
|
|
|
|
import tw.nekomimi.nekogram.NekoConfig;
|
|
|
|
import tw.nekomimi.nekogram.transtale.TranslateDb;
|
|
|
|
import tw.nekomimi.nekogram.transtale.Translator;
|
|
|
|
import tw.nekomimi.nekogram.transtale.TranslatorKt;
|
|
|
|
import tw.nekomimi.nekogram.utils.AlertUtil;
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public class PhotoAlbumPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface PhotoAlbumPickerActivityDelegate {
|
2019-09-10 12:56:11 +02:00
|
|
|
void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate);
|
2020-06-26 06:54:48 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
void startPhotoSelectActivity();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private CharSequence caption;
|
2017-12-08 18:35:59 +01:00
|
|
|
private HashMap<Object, Object> selectedPhotos = new HashMap<>();
|
|
|
|
private ArrayList<Object> selectedPhotosOrder = new ArrayList<>();
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<MediaController.AlbumEntry> albumsSorted = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private boolean loading = false;
|
|
|
|
|
|
|
|
private int columnsCount = 2;
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2015-01-02 23:15:07 +01:00
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private FrameLayout progressView;
|
|
|
|
private TextView emptyView;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean sendPressed;
|
2019-01-23 18:03:33 +01:00
|
|
|
private int selectPhotoType;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean allowSearchImages = true;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean allowGifs;
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean allowCaption;
|
2015-05-03 13:48:36 +02:00
|
|
|
private ChatActivity chatActivity;
|
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
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private ActionBarPopupWindow sendPopupWindow;
|
|
|
|
private ActionBarPopupWindow.ActionBarPopupWindowLayout sendPopupLayout;
|
|
|
|
private ActionBarMenuSubItem[] itemCells;
|
|
|
|
|
|
|
|
private FrameLayout frameLayout2;
|
|
|
|
private EditTextEmoji commentTextView;
|
|
|
|
private FrameLayout writeButtonContainer;
|
|
|
|
private ImageView writeButton;
|
|
|
|
private Drawable writeButtonDrawable;
|
|
|
|
private SizeNotifierFrameLayout sizeNotifierFrameLayout;
|
|
|
|
private View selectedCountView;
|
|
|
|
private View shadow;
|
|
|
|
private TextPaint textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
private RectF rect = new RectF();
|
|
|
|
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private PhotoAlbumPickerActivityDelegate delegate;
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public PhotoAlbumPickerActivity(int selectPhotoType, boolean allowGifs, boolean allowCaption, ChatActivity chatActivity) {
|
2015-02-26 02:32:51 +01:00
|
|
|
super();
|
2015-05-03 13:48:36 +02:00
|
|
|
this.chatActivity = chatActivity;
|
2019-01-23 18:03:33 +01:00
|
|
|
this.selectPhotoType = selectPhotoType;
|
2016-01-11 18:19:48 +01:00
|
|
|
this.allowGifs = allowGifs;
|
2016-10-11 13:57:01 +02:00
|
|
|
this.allowCaption = allowCaption;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2019-08-22 01:53:26 +02:00
|
|
|
if (selectPhotoType != 0 || !allowSearchImages) {
|
|
|
|
albumsSorted = MediaController.allPhotoAlbums;
|
|
|
|
} else {
|
|
|
|
albumsSorted = MediaController.allMediaAlbums;
|
|
|
|
}
|
|
|
|
loading = albumsSorted == null;
|
2015-01-02 23:15:07 +01:00
|
|
|
MediaController.loadGalleryPhotosAlbums(classGuid);
|
2020-04-24 11:21:58 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.albumsDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
|
2015-01-02 23:15:07 +01:00
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (commentTextView != null) {
|
|
|
|
commentTextView.onDestroy();
|
|
|
|
}
|
2020-04-24 11:21:58 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.albumsDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
|
2015-01-02 23:15:07 +01:00
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
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);
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2015-01-02 23:15:07 +01:00
|
|
|
finishFragment();
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == 1) {
|
|
|
|
if (delegate != null) {
|
|
|
|
finishFragment(false);
|
|
|
|
delegate.startPhotoSelectActivity();
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
} else if (id == 2) {
|
|
|
|
openPhotoPicker(null, 0);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2019-08-22 01:53:26 +02:00
|
|
|
if (allowSearchImages) {
|
|
|
|
menu.addItem(2, R.drawable.ic_ab_search).setContentDescription(LocaleController.getString("Search", R.string.Search));
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
|
|
|
|
menuItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
|
2020-06-25 17:28:44 +02:00
|
|
|
menuItem.addSubItem(1, R.drawable.baseline_open_in_browser_24, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context, SharedConfig.smoothKeyboard) {
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
private int lastNotifyWidth;
|
|
|
|
private boolean ignoreLayout;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(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 keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
|
2019-09-10 12:56:11 +02:00
|
|
|
if (keyboardSize <= AndroidUtilities.dp(20)) {
|
|
|
|
if (!AndroidUtilities.isInMultiwindow) {
|
|
|
|
heightSize -= commentTextView.getEmojiPadding();
|
|
|
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ignoreLayout = true;
|
|
|
|
commentTextView.hideEmojiView();
|
|
|
|
ignoreLayout = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (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 = 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();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
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-07-08 18:32:04 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
|
2015-05-03 13:48:36 +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(4), AndroidUtilities.dp(6), AndroidUtilities.dp(54));
|
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.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setDrawingCacheEnabled(false);
|
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));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
emptyView = new TextView(context);
|
|
|
|
emptyView.setTextColor(0xff808080);
|
|
|
|
emptyView.setTextSize(20);
|
|
|
|
emptyView.setGravity(Gravity.CENTER);
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
|
2019-09-10 12:56:11 +02:00
|
|
|
sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48));
|
2019-01-23 18:03:33 +01:00
|
|
|
emptyView.setOnTouchListener((v, event) -> true);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
progressView = new FrameLayout(context);
|
|
|
|
progressView.setVisibility(View.GONE);
|
2019-09-10 12:56:11 +02:00
|
|
|
sizeNotifierFrameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
RadialProgressView progressBar = new RadialProgressView(context);
|
2019-08-22 01:53:26 +02:00
|
|
|
progressBar.setProgressColor(0xff527da3);
|
|
|
|
progressView.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
|
|
|
|
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));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
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));
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
writeButtonContainer = new FrameLayout(context);
|
|
|
|
writeButtonContainer.setVisibility(View.INVISIBLE);
|
|
|
|
writeButtonContainer.setScaleX(0.2f);
|
|
|
|
writeButtonContainer.setScaleY(0.2f);
|
|
|
|
writeButtonContainer.setAlpha(0.0f);
|
|
|
|
writeButtonContainer.setContentDescription(LocaleController.getString("Send", R.string.Send));
|
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();
|
2020-06-25 17:28:44 +02:00
|
|
|
shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.SRC_IN));
|
2019-12-31 14:08:08 +01:00
|
|
|
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-06-25 17:28:44 +02:00
|
|
|
writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.SRC_IN));
|
2019-12-31 14:08:08 +01:00
|
|
|
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(), (notify, scheduleDate) -> {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, notify, scheduleDate);
|
|
|
|
finishFragment();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, true, 0);
|
|
|
|
finishFragment();
|
|
|
|
}
|
2015-04-09 20:00:14 +02: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 (chatActivity.getCurrentEncryptedChat() != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
2020-06-25 17:28:44 +02:00
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
if (a == 2 && UserObject.isUserSelf(user)) {
|
2019-09-10 12:56:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int num = a;
|
|
|
|
itemCells[a] = new ActionBarMenuSubItem(getParentActivity());
|
|
|
|
if (num == 0) {
|
2020-06-25 17:28:44 +02:00
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("Translate", R.string.Translate), R.drawable.ic_translate);
|
|
|
|
} else if (num == 1) {
|
2019-09-10 12:56:11 +02:00
|
|
|
if (UserObject.isUserSelf(user)) {
|
2020-06-25 17:28:44 +02:00
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.baseline_date_range_24);
|
2019-09-10 12:56:11 +02:00
|
|
|
} else {
|
2020-06-25 17:28:44 +02:00
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.baseline_date_range_24);
|
2019-09-10 12:56:11 +02:00
|
|
|
}
|
2020-06-25 17:28:44 +02:00
|
|
|
} else if (num == 2) {
|
2019-09-10 12:56:11 +02:00
|
|
|
itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
|
|
|
|
}
|
|
|
|
itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
|
|
|
|
|
|
|
|
sendPopupLayout.addView(itemCells[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 0, 48 * a, 0, 0));
|
2020-06-25 17:28:44 +02:00
|
|
|
|
|
|
|
int chatId;
|
|
|
|
if (chat != null) {
|
|
|
|
chatId = chat.id;
|
|
|
|
} else if (user != null) {
|
|
|
|
chatId = user.id;
|
|
|
|
} else {
|
|
|
|
chatId = -1;
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
itemCells[a].setOnClickListener(v -> {
|
|
|
|
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
if (num == 0) {
|
2020-06-25 17:28:44 +02:00
|
|
|
translateComment(TranslateDb.getChatLanguage(chatId, TranslatorKt.getCode2Locale(NekoConfig.translateInputLang)));
|
|
|
|
} else if (num == 1) {
|
2019-12-31 14:08:08 +01:00
|
|
|
AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), (notify, scheduleDate) -> {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, notify, scheduleDate);
|
|
|
|
finishFragment();
|
|
|
|
});
|
2020-06-25 17:28:44 +02:00
|
|
|
} else if (num == 2) {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, true, 0);
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
});
|
2020-06-25 17:28:44 +02:00
|
|
|
itemCells[a].setOnLongClickListener(v -> {
|
|
|
|
if (num == 0) {
|
|
|
|
Translator.showTargetLangSelect(itemCells[num], true, (locale) -> {
|
|
|
|
if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
|
|
|
|
sendPopupWindow.dismiss();
|
|
|
|
}
|
|
|
|
translateComment(locale);
|
|
|
|
TranslateDb.saveChatLanguage(chatId, locale);
|
|
|
|
return Unit.INSTANCE;
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
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));
|
2019-09-10 12:56:11 +02:00
|
|
|
if (selectPhotoType != 0) {
|
|
|
|
commentTextView.setVisibility(View.GONE);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
listView.setEmptyView(emptyView);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
2020-06-25 17:28:44 +02:00
|
|
|
private void translateComment(Locale target) {
|
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
TranslateDb db = TranslateDb.forLocale(target);
|
|
|
|
String origin = commentTextView.getText().toString();
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
if (db.contains(origin)) {
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
String translated = db.query(origin);
|
|
|
|
commentTextView.getEditText().setText(translated);
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
return;
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
}
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
Translator.translate(target, origin, new Translator.Companion.TranslateCallBack() {
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
final AtomicBoolean cancel = new AtomicBoolean();
|
|
|
|
AlertDialog status = AlertUtil.showProgress(getParentActivity());
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
{
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
status.setOnCancelListener((__) -> {
|
|
|
|
cancel.set(true);
|
|
|
|
});
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
status.show();
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
}
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(@NotNull String translation) {
|
|
|
|
status.dismiss();
|
|
|
|
commentTextView.getEditText().setText(translation);
|
|
|
|
}
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
@Override
|
|
|
|
public void onFailed(boolean unsupported, @NotNull String message) {
|
|
|
|
status.dismiss();
|
|
|
|
AlertUtil.showTransFailedDialog(getParentActivity(), unsupported, message, () -> {
|
|
|
|
status = AlertUtil.showProgress(getParentActivity());
|
|
|
|
status.show();
|
|
|
|
Translator.translate(origin, this);
|
|
|
|
});
|
|
|
|
}
|
2020-06-25 17:28:44 +02:00
|
|
|
|
2020-06-26 06:54:48 +02:00
|
|
|
});
|
2020-06-25 17:28:44 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01: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
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
@Override
|
|
|
|
public void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (id == NotificationCenter.albumsDidLoad) {
|
2015-01-02 23:15:07 +01:00
|
|
|
int guid = (Integer) args[0];
|
|
|
|
if (classGuid == guid) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (selectPhotoType != 0 || !allowSearchImages) {
|
2017-07-08 18:32:04 +02:00
|
|
|
albumsSorted = (ArrayList<MediaController.AlbumEntry>) args[2];
|
|
|
|
} else {
|
|
|
|
albumsSorted = (ArrayList<MediaController.AlbumEntry>) args[1];
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (listView != null && listView.getEmptyView() == null) {
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
}
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
|
|
|
removeSelfFromStack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setAllowSearchImages(boolean value) {
|
|
|
|
allowSearchImages = value;
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void setDelegate(PhotoAlbumPickerActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private void sendSelectedPhotos(HashMap<Object, Object> photos, ArrayList<Object> order, boolean notify, int scheduleDate) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (photos.isEmpty() || delegate == null || sendPressed) {
|
2015-01-02 23:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendPressed = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
ArrayList<SendMessagesHelper.SendingMediaInfo> media = new ArrayList<>();
|
|
|
|
for (int a = 0; a < order.size(); a++) {
|
|
|
|
Object object = photos.get(order.get(a));
|
|
|
|
SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
|
|
|
|
media.add(info);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
|
2020-06-04 18:47:15 +02:00
|
|
|
if (photoEntry.imagePath != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
info.path = photoEntry.imagePath;
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
info.path = photoEntry.path;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
info.thumbPath = photoEntry.thumbPath;
|
|
|
|
info.videoEditedInfo = photoEntry.editedInfo;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.isVideo = photoEntry.isVideo;
|
|
|
|
info.caption = photoEntry.caption != null ? photoEntry.caption.toString() : null;
|
2018-07-30 04:07:02 +02:00
|
|
|
info.entities = photoEntry.entities;
|
2020-06-04 18:47:15 +02:00
|
|
|
info.masks = photoEntry.stickers;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.ttl = photoEntry.ttl;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
|
|
|
|
if (searchImage.imagePath != null) {
|
|
|
|
info.path = searchImage.imagePath;
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
info.searchImage = searchImage;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
info.thumbPath = searchImage.thumbPath;
|
|
|
|
info.videoEditedInfo = searchImage.editedInfo;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.caption = searchImage.caption != null ? searchImage.caption.toString() : null;
|
2018-07-30 04:07:02 +02:00
|
|
|
info.entities = searchImage.entities;
|
2020-06-04 18:47:15 +02:00
|
|
|
info.masks = searchImage.stickers;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.ttl = searchImage.ttl;
|
2019-09-10 12:56:11 +02:00
|
|
|
if (searchImage.inlineResult != null && searchImage.type == 1) {
|
|
|
|
info.inlineResult = searchImage.inlineResult;
|
|
|
|
info.params = searchImage.params;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
searchImage.date = (int) (System.currentTimeMillis() / 1000);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
delegate.didSelectPhotos(media, notify, scheduleDate);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
|
|
|
if (listView != null) {
|
|
|
|
ViewTreeObserver obs = listView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
fixLayoutInternal();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return true;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private void applyCaption() {
|
|
|
|
if (commentTextView.length() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int imageId = (Integer) 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private void fixLayoutInternal() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
columnsCount = 2;
|
2015-03-26 18:34:47 +01:00
|
|
|
if (!AndroidUtilities.isTablet() && (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90)) {
|
2015-01-02 23:15:07 +01:00
|
|
|
columnsCount = 4;
|
|
|
|
}
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:56:11 +02:00
|
|
|
private boolean showCommentTextView(boolean show) {
|
|
|
|
if (show == (frameLayout2.getTag() != null)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
} else {
|
|
|
|
frameLayout2.setVisibility(View.INVISIBLE);
|
|
|
|
writeButtonContainer.setVisibility(View.INVISIBLE);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
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));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePhotosButton() {
|
|
|
|
int count = selectedPhotos.size();
|
|
|
|
|
|
|
|
if (count == 0) {
|
|
|
|
selectedCountView.setPivotX(0);
|
|
|
|
selectedCountView.setPivotY(0);
|
|
|
|
showCommentTextView(false);
|
|
|
|
} else {
|
|
|
|
selectedCountView.invalidate();
|
|
|
|
showCommentTextView(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openPhotoPicker(MediaController.AlbumEntry albumEntry, int type) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (albumEntry != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
PhotoPickerActivity fragment = new PhotoPickerActivity(type, albumEntry, selectedPhotos, selectedPhotosOrder, selectPhotoType, allowCaption, chatActivity);
|
2019-09-10 12:56:11 +02:00
|
|
|
fragment.setCaption(caption = commentTextView.getText());
|
2017-12-08 18:35:59 +01:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void selectedPhotosChanged() {
|
2019-09-10 12:56:11 +02:00
|
|
|
updatePhotosButton();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public void actionButtonPressed(boolean canceled, boolean notify, int scheduleDate) {
|
2017-12-08 18:35:59 +01:00
|
|
|
removeSelfFromStack();
|
|
|
|
if (!canceled) {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, notify, scheduleDate);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCaptionChanged(CharSequence text) {
|
|
|
|
commentTextView.setText(caption = text);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
2019-08-22 01:53:26 +02:00
|
|
|
fragment.setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
|
|
|
|
presentFragment(fragment);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
|
|
|
final HashMap<Object, Object> photos = new HashMap<>();
|
|
|
|
final ArrayList<Object> order = new ArrayList<>();
|
2019-08-22 01:53:26 +02:00
|
|
|
if (allowGifs) {
|
2019-12-31 14:08:08 +01:00
|
|
|
PhotoPickerSearchActivity fragment = new PhotoPickerSearchActivity(photos, order, selectPhotoType, allowCaption, chatActivity);
|
2019-09-10 12:56:11 +02:00
|
|
|
fragment.setCaption(caption = commentTextView.getText());
|
2019-08-22 01:53:26 +02:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void selectedPhotosChanged() {
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public void actionButtonPressed(boolean canceled, boolean notify, int scheduleDate) {
|
2019-08-22 01:53:26 +02:00
|
|
|
removeSelfFromStack();
|
|
|
|
if (!canceled) {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(photos, order, notify, scheduleDate);
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCaptionChanged(CharSequence text) {
|
|
|
|
commentTextView.setText(caption = text);
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
});
|
|
|
|
fragment.setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
|
|
|
|
presentFragment(fragment);
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
PhotoPickerActivity fragment = new PhotoPickerActivity(0, albumEntry, photos, order, selectPhotoType, allowCaption, chatActivity);
|
2019-09-10 12:56:11 +02:00
|
|
|
fragment.setCaption(caption = commentTextView.getText());
|
2019-08-22 01:53:26 +02:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void selectedPhotosChanged() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-10 12:56:11 +02:00
|
|
|
public void actionButtonPressed(boolean canceled, boolean notify, int scheduleDate) {
|
2019-08-22 01:53:26 +02:00
|
|
|
removeSelfFromStack();
|
|
|
|
if (!canceled) {
|
2019-09-10 12:56:11 +02:00
|
|
|
sendSelectedPhotos(photos, order, notify, scheduleDate);
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-10 12:56:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCaptionChanged(CharSequence text) {
|
|
|
|
commentTextView.setText(caption = text);
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
});
|
|
|
|
fragment.setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
|
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
2015-01-02 23:15:07 +01: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
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
2019-08-22 01:53:26 +02:00
|
|
|
return albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
2019-08-22 01:53:26 +02:00
|
|
|
PhotoPickerAlbumsCell cell = new PhotoPickerAlbumsCell(mContext);
|
|
|
|
cell.setDelegate(albumEntry -> openPhotoPicker(albumEntry, 0));
|
|
|
|
return new RecyclerListView.Holder(cell);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2019-08-22 01:53:26 +02:00
|
|
|
PhotoPickerAlbumsCell photoPickerAlbumsCell = (PhotoPickerAlbumsCell) holder.itemView;
|
|
|
|
photoPickerAlbumsCell.setAlbumsCount(columnsCount);
|
|
|
|
for (int a = 0; a < columnsCount; a++) {
|
|
|
|
int index = position * columnsCount + a;
|
|
|
|
if (index < albumsSorted.size()) {
|
|
|
|
MediaController.AlbumEntry albumEntry = albumsSorted.get(index);
|
|
|
|
photoPickerAlbumsCell.setAlbum(a, albumEntry);
|
|
|
|
} else {
|
|
|
|
photoPickerAlbumsCell.setAlbum(a, null);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-22 01:53:26 +02:00
|
|
|
photoPickerAlbumsCell.requestLayout();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
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<>();
|
2019-08-22 01:53:26 +02:00
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
themeDescriptions.add(new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_dialogBackground));
|
2019-08-22 01:53:26 +02:00
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
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));
|
2019-08-22 01:53:26 +02:00
|
|
|
|
2020-04-24 11:21:58 +02:00
|
|
|
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
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|