2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2013-10-25 17:19:00 +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.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
2014-12-01 18:56:31 +01:00
|
|
|
package org.telegram.ui.Components;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.annotation.TargetApi;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.Context;
|
2014-06-20 02:18:13 +02:00
|
|
|
import android.database.DataSetObserver;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.graphics.Canvas;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.graphics.Outline;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.graphics.Paint;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.graphics.RectF;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.drawable.ShapeDrawable;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.os.Build;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.support.v4.view.PagerAdapter;
|
|
|
|
import android.support.v4.view.ViewPager;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.text.Editable;
|
2017-12-08 18:35:59 +01:00
|
|
|
import android.text.SpannableStringBuilder;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.text.TextWatcher;
|
|
|
|
import android.util.LongSparseArray;
|
|
|
|
import android.util.SparseArray;
|
|
|
|
import android.util.SparseIntArray;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.util.TypedValue;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.HapticFeedbackConstants;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.view.KeyEvent;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.view.MotionEvent;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.view.VelocityTracker;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
2017-07-23 14:56:38 +02:00
|
|
|
import android.view.ViewConfiguration;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.ViewGroup;
|
2016-10-11 13:57:01 +02:00
|
|
|
import android.view.ViewOutlineProvider;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.GridView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.widget.PopupWindow;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.DataQuery;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.Emoji;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.messenger.EmojiData;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.EmojiSuggestion;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2013-10-25 17:19:00 +02:00
|
|
|
import org.telegram.messenger.R;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.messenger.support.widget.GridLayoutManager;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.ui.Cells.ContextLinkCell;
|
2015-06-29 19:12:11 +02:00
|
|
|
import org.telegram.ui.Cells.EmptyCell;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.ui.Cells.FeaturedStickerSetInfoCell;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Cells.StickerEmojiCell;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.ui.Cells.StickerSetGroupInfoCell;
|
|
|
|
import org.telegram.ui.Cells.StickerSetNameCell;
|
2015-08-13 11:23:31 +02:00
|
|
|
import org.telegram.ui.StickerPreviewViewer;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
import java.lang.reflect.Field;
|
2013-10-25 17:19:00 +02:00
|
|
|
import java.util.ArrayList;
|
2015-05-21 23:27:27 +02:00
|
|
|
import java.util.HashMap;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public class EmojiView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public interface Listener {
|
|
|
|
boolean onBackspace();
|
|
|
|
void onEmojiSelected(String emoji);
|
2019-01-23 18:03:33 +01:00
|
|
|
void onStickerSelected(TLRPC.Document sticker, Object parent);
|
2015-12-09 19:27:52 +01:00
|
|
|
void onStickersSettingsClick();
|
2017-12-08 18:35:59 +01:00
|
|
|
void onStickersGroupClick(int chatId);
|
2019-01-23 18:03:33 +01:00
|
|
|
void onGifSelected(TLRPC.Document gif, Object parent);
|
2016-01-11 18:19:48 +01:00
|
|
|
void onGifTab(boolean opened);
|
|
|
|
void onStickersTab(boolean opened);
|
2016-03-16 13:26:32 +01:00
|
|
|
void onClearEmojiRecent();
|
2017-03-31 01:58:05 +02:00
|
|
|
void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet);
|
2016-10-11 13:57:01 +02:00
|
|
|
void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet);
|
|
|
|
void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet);
|
2018-07-30 04:07:02 +02:00
|
|
|
void onSearchOpenClose(boolean open);
|
|
|
|
boolean isSearchOpened();
|
|
|
|
boolean isExpanded();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public interface DragListener{
|
|
|
|
void onDragStart();
|
|
|
|
void onDragEnd(float velocity);
|
|
|
|
void onDragCancel();
|
|
|
|
void onDrag(int offset);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private StickerPreviewViewer.StickerPreviewViewerDelegate stickerPreviewViewerDelegate = new StickerPreviewViewer.StickerPreviewViewerDelegate() {
|
|
|
|
@Override
|
2019-01-23 18:03:33 +01:00
|
|
|
public void sendSticker(TLRPC.Document sticker, Object parent) {
|
|
|
|
listener.onStickerSelected(sticker, parent);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean needSend() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public void openSet(TLRPC.InputStickerSet set) {
|
|
|
|
if (set == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
listener.onShowStickerSet(null, set);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private static final Field superListenerField;
|
|
|
|
static {
|
|
|
|
Field f = null;
|
|
|
|
try {
|
|
|
|
f = PopupWindow.class.getDeclaredField("mOnScrollChangedListener");
|
|
|
|
f.setAccessible(true);
|
|
|
|
} catch (NoSuchFieldException e) {
|
|
|
|
/* ignored */
|
|
|
|
}
|
|
|
|
superListenerField = f;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
private static final ViewTreeObserver.OnScrollChangedListener NOP = () -> {
|
|
|
|
/* do nothing */
|
2015-10-29 18:10:07 +01:00
|
|
|
};
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private static String addColorToCode(String code, String color) {
|
|
|
|
String end = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
int length = code.length();
|
|
|
|
if (length > 2 && code.charAt(code.length() - 2) == '\u200D') {
|
2016-10-11 13:57:01 +02:00
|
|
|
end = code.substring(code.length() - 2);
|
|
|
|
code = code.substring(0, code.length() - 2);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (length > 3 && code.charAt(code.length() - 3) == '\u200D') {
|
2017-03-31 01:58:05 +02:00
|
|
|
end = code.substring(code.length() - 3);
|
|
|
|
code = code.substring(0, code.length() - 3);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
code += color;
|
|
|
|
if (end != null) {
|
|
|
|
code += end;
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void addEmojiToRecent(String code) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (!Emoji.isValidEmoji(code)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.addRecentEmoji(code);
|
|
|
|
if (getVisibility() != VISIBLE || pager.getCurrentItem() != 0) {
|
|
|
|
Emoji.sortEmoji();
|
|
|
|
}
|
|
|
|
Emoji.saveRecentEmoji();
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private class ImageViewEmoji extends ImageView {
|
|
|
|
|
|
|
|
private boolean touched;
|
|
|
|
private float lastX;
|
|
|
|
private float lastY;
|
|
|
|
private float touchedX;
|
|
|
|
private float touchedY;
|
|
|
|
|
|
|
|
public ImageViewEmoji(Context context) {
|
|
|
|
super(context);
|
2019-01-23 18:03:33 +01:00
|
|
|
setOnClickListener(v -> sendEmoji(null));
|
|
|
|
setOnLongClickListener(view -> {
|
|
|
|
String code = (String) view.getTag();
|
|
|
|
|
|
|
|
String color = null;
|
|
|
|
|
|
|
|
String toCheck = code.replace("\uD83C\uDFFB", "");
|
|
|
|
if (toCheck != code) {
|
|
|
|
color = "\uD83C\uDFFB";
|
|
|
|
}
|
|
|
|
if (color == null) {
|
|
|
|
toCheck = code.replace("\uD83C\uDFFC", "");
|
|
|
|
if (toCheck != code) {
|
|
|
|
color = "\uD83C\uDFFC";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color == null) {
|
|
|
|
toCheck = code.replace("\uD83C\uDFFD", "");
|
|
|
|
if (toCheck != code) {
|
|
|
|
color = "\uD83C\uDFFD";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color == null) {
|
|
|
|
toCheck = code.replace("\uD83C\uDFFE", "");
|
|
|
|
if (toCheck != code) {
|
|
|
|
color = "\uD83C\uDFFE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (color == null) {
|
|
|
|
toCheck = code.replace("\uD83C\uDFFF", "");
|
|
|
|
if (toCheck != code) {
|
|
|
|
color = "\uD83C\uDFFF";
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
if (EmojiData.emojiColoredMap.containsKey(toCheck)) {
|
|
|
|
touched = true;
|
|
|
|
touchedX = lastX;
|
|
|
|
touchedY = lastY;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
if (color == null && pager.getCurrentItem() != 0) {
|
|
|
|
color = Emoji.emojiColor.get(toCheck);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
|
|
|
|
if (color != null) {
|
|
|
|
switch (color) {
|
|
|
|
case "\uD83C\uDFFB":
|
|
|
|
pickerView.setSelection(1);
|
|
|
|
break;
|
|
|
|
case "\uD83C\uDFFC":
|
|
|
|
pickerView.setSelection(2);
|
|
|
|
break;
|
|
|
|
case "\uD83C\uDFFD":
|
|
|
|
pickerView.setSelection(3);
|
|
|
|
break;
|
|
|
|
case "\uD83C\uDFFE":
|
|
|
|
pickerView.setSelection(4);
|
|
|
|
break;
|
|
|
|
case "\uD83C\uDFFF":
|
|
|
|
pickerView.setSelection(5);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pickerView.setSelection(0);
|
|
|
|
}
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
int x = emojiSize * pickerView.getSelection() + AndroidUtilities.dp(4 * pickerView.getSelection() - (AndroidUtilities.isTablet() ? 5 : 1));
|
|
|
|
if (location[0] - x < AndroidUtilities.dp(5)) {
|
|
|
|
x += (location[0] - x) - AndroidUtilities.dp(5);
|
|
|
|
} else if (location[0] - x + popupWidth > AndroidUtilities.displaySize.x - AndroidUtilities.dp(5)) {
|
|
|
|
x += (location[0] - x + popupWidth) - (AndroidUtilities.displaySize.x - AndroidUtilities.dp(5));
|
|
|
|
}
|
|
|
|
int xOffset = -x;
|
|
|
|
int yOffset = view.getTop() < 0 ? view.getTop() : 0;
|
|
|
|
|
|
|
|
pickerView.setEmoji(toCheck, AndroidUtilities.dp(AndroidUtilities.isTablet() ? 30 : 22) - xOffset + (int) AndroidUtilities.dpf2(0.5f));
|
|
|
|
|
|
|
|
pickerViewPopup.setFocusable(true);
|
|
|
|
pickerViewPopup.showAsDropDown(view, xOffset, -view.getMeasuredHeight() - popupHeight + (view.getMeasuredHeight() - emojiSize) / 2 - yOffset);
|
|
|
|
view.getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
return true;
|
|
|
|
} else if (pager.getCurrentItem() == 0) {
|
|
|
|
listener.onClearEmojiRecent();
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return false;
|
2015-10-29 18:10:07 +01:00
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
2015-10-29 18:10:07 +01:00
|
|
|
setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendEmoji(String override) {
|
|
|
|
String code = override != null ? override : (String) getTag();
|
2017-12-08 18:35:59 +01:00
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder();
|
|
|
|
builder.append(code);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (override == null) {
|
|
|
|
if (pager.getCurrentItem() != 0) {
|
2017-12-08 18:35:59 +01:00
|
|
|
String color = Emoji.emojiColor.get(code);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (color != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
code = addColorToCode(code, color);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
addEmojiToRecent(code);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (listener != null) {
|
|
|
|
listener.onEmojiSelected(Emoji.fixEmoji(code));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onEmojiSelected(Emoji.fixEmoji(override));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
setMeasuredDimension(View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(widthMeasureSpec));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (touched) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
if (pickerViewPopup != null && pickerViewPopup.isShowing()) {
|
|
|
|
pickerViewPopup.dismiss();
|
|
|
|
|
|
|
|
String color = null;
|
|
|
|
switch (pickerView.getSelection()) {
|
|
|
|
case 1:
|
|
|
|
color = "\uD83C\uDFFB";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
color = "\uD83C\uDFFC";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
color = "\uD83C\uDFFD";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
color = "\uD83C\uDFFE";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
color = "\uD83C\uDFFF";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
String code = (String) getTag();
|
|
|
|
if (pager.getCurrentItem() != 0) {
|
|
|
|
if (color != null) {
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.emojiColor.put(code, color);
|
2016-10-11 13:57:01 +02:00
|
|
|
code = addColorToCode(code, color);
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.emojiColor.remove(code);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
setImageDrawable(Emoji.getEmojiBigDrawable(code));
|
|
|
|
sendEmoji(null);
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.saveEmojiColors();
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
code = code.replace("\uD83C\uDFFB", "")
|
|
|
|
.replace("\uD83C\uDFFC", "")
|
|
|
|
.replace("\uD83C\uDFFD", "")
|
|
|
|
.replace("\uD83C\uDFFE", "")
|
|
|
|
.replace("\uD83C\uDFFF", "");
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
if (color != null) {
|
|
|
|
sendEmoji(addColorToCode(code, color));
|
|
|
|
} else {
|
|
|
|
sendEmoji(code);
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
touched = false;
|
|
|
|
touchedX = -10000;
|
|
|
|
touchedY = -10000;
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
boolean ignore = false;
|
|
|
|
if (touchedX != -10000) {
|
|
|
|
if (Math.abs(touchedX - event.getX()) > AndroidUtilities.getPixelsInCM(0.2f, true) || Math.abs(touchedY - event.getY()) > AndroidUtilities.getPixelsInCM(0.2f, false)) {
|
|
|
|
touchedX = -10000;
|
|
|
|
touchedY = -10000;
|
|
|
|
} else {
|
|
|
|
ignore = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ignore) {
|
|
|
|
getLocationOnScreen(location);
|
|
|
|
float x = location[0] + event.getX();
|
|
|
|
pickerView.getLocationOnScreen(location);
|
|
|
|
x -= location[0] + AndroidUtilities.dp(3);
|
|
|
|
int position = (int) (x / (emojiSize + AndroidUtilities.dp(4)));
|
|
|
|
if (position < 0) {
|
|
|
|
position = 0;
|
|
|
|
} else if (position > 5) {
|
|
|
|
position = 5;
|
|
|
|
}
|
|
|
|
pickerView.setSelection(position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastX = event.getX();
|
|
|
|
lastY = event.getY();
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class EmojiPopupWindow extends PopupWindow {
|
|
|
|
|
|
|
|
private ViewTreeObserver.OnScrollChangedListener mSuperScrollListener;
|
|
|
|
private ViewTreeObserver mViewTreeObserver;
|
|
|
|
|
|
|
|
public EmojiPopupWindow() {
|
|
|
|
super();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiPopupWindow(Context context) {
|
|
|
|
super(context);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiPopupWindow(int width, int height) {
|
|
|
|
super(width, height);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiPopupWindow(View contentView) {
|
|
|
|
super(contentView);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiPopupWindow(View contentView, int width, int height, boolean focusable) {
|
|
|
|
super(contentView, width, height, focusable);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiPopupWindow(View contentView, int width, int height) {
|
|
|
|
super(contentView, width, height);
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void init() {
|
|
|
|
if (superListenerField != null) {
|
|
|
|
try {
|
|
|
|
mSuperScrollListener = (ViewTreeObserver.OnScrollChangedListener) superListenerField.get(this);
|
|
|
|
superListenerField.set(this, NOP);
|
|
|
|
} catch (Exception e) {
|
|
|
|
mSuperScrollListener = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unregisterListener() {
|
|
|
|
if (mSuperScrollListener != null && mViewTreeObserver != null) {
|
|
|
|
if (mViewTreeObserver.isAlive()) {
|
|
|
|
mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
|
|
|
|
}
|
|
|
|
mViewTreeObserver = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void registerListener(View anchor) {
|
|
|
|
if (mSuperScrollListener != null) {
|
|
|
|
ViewTreeObserver vto = (anchor.getWindowToken() != null) ? anchor.getViewTreeObserver() : null;
|
|
|
|
if (vto != mViewTreeObserver) {
|
|
|
|
if (mViewTreeObserver != null && mViewTreeObserver.isAlive()) {
|
|
|
|
mViewTreeObserver.removeOnScrollChangedListener(mSuperScrollListener);
|
|
|
|
}
|
|
|
|
if ((mViewTreeObserver = vto) != null) {
|
|
|
|
vto.addOnScrollChangedListener(mSuperScrollListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showAsDropDown(View anchor, int xoff, int yoff) {
|
|
|
|
try {
|
|
|
|
super.showAsDropDown(anchor, xoff, yoff);
|
|
|
|
registerListener(anchor);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(View anchor, int xoff, int yoff, int width, int height) {
|
|
|
|
super.update(anchor, xoff, yoff, width, height);
|
|
|
|
registerListener(anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(View anchor, int width, int height) {
|
|
|
|
super.update(anchor, width, height);
|
|
|
|
registerListener(anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void showAtLocation(View parent, int gravity, int x, int y) {
|
|
|
|
super.showAtLocation(parent, gravity, x, y);
|
|
|
|
unregisterListener();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismiss() {
|
|
|
|
setFocusable(false);
|
|
|
|
try {
|
|
|
|
super.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
//don't promt
|
|
|
|
}
|
|
|
|
unregisterListener();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class EmojiColorPickerView extends View {
|
|
|
|
|
|
|
|
private Drawable backgroundDrawable;
|
|
|
|
private Drawable arrowDrawable;
|
|
|
|
private String currentEmoji;
|
|
|
|
private int arrowX;
|
|
|
|
private int selection;
|
|
|
|
private Paint rectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
private RectF rect = new RectF();
|
|
|
|
|
|
|
|
public void setEmoji(String emoji, int arrowPosition) {
|
|
|
|
currentEmoji = emoji;
|
|
|
|
arrowX = arrowPosition;
|
|
|
|
rectPaint.setColor(0x2f000000);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getEmoji() {
|
|
|
|
return currentEmoji;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSelection(int position) {
|
|
|
|
if (selection == position) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
selection = position;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getSelection() {
|
|
|
|
return selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public EmojiColorPickerView(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
backgroundDrawable = getResources().getDrawable(R.drawable.stickers_back_all);
|
|
|
|
arrowDrawable = getResources().getDrawable(R.drawable.stickers_back_arrow);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(AndroidUtilities.isTablet() ? 60 : 52));
|
|
|
|
backgroundDrawable.draw(canvas);
|
|
|
|
|
|
|
|
arrowDrawable.setBounds(arrowX - AndroidUtilities.dp(9), AndroidUtilities.dp(AndroidUtilities.isTablet() ? 55.5f : 47.5f), arrowX + AndroidUtilities.dp(9), AndroidUtilities.dp((AndroidUtilities.isTablet() ? 55.5f : 47.5f) + 8));
|
|
|
|
arrowDrawable.draw(canvas);
|
|
|
|
|
|
|
|
if (currentEmoji != null) {
|
|
|
|
String code;
|
|
|
|
for (int a = 0; a < 6; a++) {
|
|
|
|
int x = emojiSize * a + AndroidUtilities.dp(5 + 4 * a);
|
|
|
|
int y = AndroidUtilities.dp(9);
|
|
|
|
if (selection == a) {
|
|
|
|
rect.set(x, y - (int) AndroidUtilities.dpf2(3.5f), x + emojiSize, y + emojiSize + AndroidUtilities.dp(3));
|
|
|
|
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), rectPaint);
|
|
|
|
}
|
|
|
|
code = currentEmoji;
|
|
|
|
if (a != 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
String color;
|
2015-10-29 18:10:07 +01:00
|
|
|
switch (a) {
|
|
|
|
case 1:
|
2016-10-11 13:57:01 +02:00
|
|
|
color = "\uD83C\uDFFB";
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2016-10-11 13:57:01 +02:00
|
|
|
color = "\uD83C\uDFFC";
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2016-10-11 13:57:01 +02:00
|
|
|
color = "\uD83C\uDFFD";
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2016-10-11 13:57:01 +02:00
|
|
|
color = "\uD83C\uDFFE";
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2016-10-11 13:57:01 +02:00
|
|
|
color = "\uD83C\uDFFF";
|
2015-10-29 18:10:07 +01:00
|
|
|
break;
|
2016-10-11 13:57:01 +02:00
|
|
|
default:
|
|
|
|
color = "";
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
code = addColorToCode(code, color);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
Drawable drawable = Emoji.getEmojiBigDrawable(code);
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setBounds(x, y, x + emojiSize, y + emojiSize);
|
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int searchFieldHeight;
|
|
|
|
|
|
|
|
private int currentAccount = UserConfig.selectedAccount;
|
2015-04-09 20:00:14 +02:00
|
|
|
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<>();
|
2015-06-29 19:12:11 +02:00
|
|
|
private ArrayList<TLRPC.TL_messages_stickerSet> stickerSets = new ArrayList<>();
|
2017-12-08 18:35:59 +01:00
|
|
|
private int groupStickerPackNum;
|
|
|
|
private int groupStickerPackPosition;
|
|
|
|
private boolean groupStickersHidden;
|
|
|
|
private TLRPC.TL_messages_stickerSet groupStickerSet;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private ArrayList<TLRPC.Document> recentGifs = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.Document> recentStickers = new ArrayList<>();
|
2017-12-08 18:35:59 +01:00
|
|
|
private ArrayList<TLRPC.Document> favouriteStickers = new ArrayList<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private Paint dotPaint;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private Drawable[] icons;
|
2018-07-30 04:07:02 +02:00
|
|
|
private Drawable stickersDrawable;
|
|
|
|
|
|
|
|
private boolean firstAttach = true;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private Listener listener;
|
|
|
|
private ViewPager pager;
|
2015-06-29 19:12:11 +02:00
|
|
|
private FrameLayout stickersWrap;
|
2016-10-11 13:57:01 +02:00
|
|
|
private ArrayList<View> views = new ArrayList<>();
|
|
|
|
private ArrayList<GridView> emojiGrids = new ArrayList<>();
|
2015-05-03 13:48:36 +02:00
|
|
|
private ImageView backspaceButton;
|
2018-07-30 04:07:02 +02:00
|
|
|
private View shadowLine;
|
|
|
|
private TextView noRecentTextView;
|
2015-06-29 19:12:11 +02:00
|
|
|
private StickersGridAdapter stickersGridAdapter;
|
2018-07-30 04:07:02 +02:00
|
|
|
private StickersSearchGridAdapter stickersSearchGridAdapter;
|
2016-10-11 13:57:01 +02:00
|
|
|
private LinearLayout emojiTab;
|
|
|
|
private ScrollSlidingTabStrip stickersTab;
|
|
|
|
private RecyclerListView stickersGridView;
|
|
|
|
private GridLayoutManager stickersLayoutManager;
|
2016-01-11 18:19:48 +01:00
|
|
|
private TextView stickersEmptyView;
|
|
|
|
private RecyclerListView gifsGridView;
|
2016-05-25 23:49:47 +02:00
|
|
|
private ExtendedGridLayoutManager flowLayoutManager;
|
2016-01-11 18:19:48 +01:00
|
|
|
private GifsAdapter gifsAdapter;
|
2016-10-11 13:57:01 +02:00
|
|
|
private RecyclerListView trendingGridView;
|
|
|
|
private GridLayoutManager trendingLayoutManager;
|
|
|
|
private TrendingGridAdapter trendingGridAdapter;
|
|
|
|
private RecyclerListView.OnItemClickListener stickersOnItemClickListener;
|
|
|
|
private PagerSlidingTabStrip pagerSlidingTabStrip;
|
2017-07-08 18:32:04 +02:00
|
|
|
private TextView mediaBanTooltip;
|
2017-07-23 14:56:38 +02:00
|
|
|
private DragListener dragListener;
|
2018-07-30 04:07:02 +02:00
|
|
|
private FrameLayout searchEditTextContainer;
|
|
|
|
private View searchBackground;
|
|
|
|
private ImageView searchIconImageView;
|
|
|
|
private ImageView clearSearchImageView;
|
|
|
|
private CloseProgressDrawable2 progressDrawable;
|
|
|
|
private EditTextBoldCursor searchEditText;
|
|
|
|
private AnimatorSet searchAnimation;
|
|
|
|
private TextView stickersCounter;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
private int currentChatId;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private LongSparseArray<TLRPC.StickerSetCovered> installingStickerSets = new LongSparseArray<>();
|
|
|
|
private LongSparseArray<TLRPC.StickerSetCovered> removingStickerSets = new LongSparseArray<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean trendingLoaded;
|
2017-03-31 01:58:05 +02:00
|
|
|
private int featuredStickersHash;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private int currentPage;
|
2016-03-06 02:49:31 +01:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private EmojiColorPickerView pickerView;
|
|
|
|
private EmojiPopupWindow pickerViewPopup;
|
|
|
|
private int popupWidth;
|
|
|
|
private int popupHeight;
|
|
|
|
private int emojiSize;
|
|
|
|
private int location[] = new int[2];
|
2016-01-11 18:19:48 +01:00
|
|
|
private int stickersTabOffset;
|
|
|
|
private int recentTabBum = -2;
|
2017-12-08 18:35:59 +01:00
|
|
|
private int favTabBum = -2;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int gifTabNum = -2;
|
|
|
|
private int trendingTabNum = -2;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean switchToGifTab;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private TLRPC.ChatFull info;
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean isLayout;
|
|
|
|
private int currentBackgroundType = -1;
|
|
|
|
private Object outlineProvider;
|
2019-01-23 18:03:33 +01:00
|
|
|
private boolean forseMultiwindowLayout;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private int oldWidth;
|
|
|
|
private int lastNotifyWidth;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean backspacePressed;
|
|
|
|
private boolean backspaceOnce;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean showGifs;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private int minusDy;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public EmojiView(boolean needStickers, boolean needGif, final Context context, final TLRPC.ChatFull chatFull) {
|
2015-05-03 13:48:36 +02:00
|
|
|
super(context);
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
searchFieldHeight = AndroidUtilities.dp(64);
|
|
|
|
|
|
|
|
stickersDrawable = context.getResources().getDrawable(R.drawable.ic_smiles2_stickers);
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.setDrawableColorByKey(stickersDrawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
icons = new Drawable[] {
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_recent, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_smile, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_nature, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_food, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_car, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
Theme.createEmojiIconSelectorDrawable(context, R.drawable.ic_smiles2_objects, Theme.getColor(Theme.key_chat_emojiPanelIcon), Theme.getColor(Theme.key_chat_emojiPanelIconSelected)),
|
|
|
|
stickersDrawable
|
|
|
|
};
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
showGifs = needGif;
|
2017-12-08 18:35:59 +01:00
|
|
|
info = chatFull;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
dotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending));
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
outlineProvider = new ViewOutlineProvider() {
|
|
|
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
|
@Override
|
|
|
|
public void getOutline(View view, Outline outline) {
|
|
|
|
outline.setRoundRect(view.getPaddingLeft(), view.getPaddingTop(), view.getMeasuredWidth() - view.getPaddingRight(), view.getMeasuredHeight() - view.getPaddingBottom(), AndroidUtilities.dp(6));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
for (int i = 0; i < EmojiData.dataColored.length + 1; i++) {
|
2015-05-03 13:48:36 +02:00
|
|
|
GridView gridView = new GridView(context);
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
gridView.setColumnWidth(AndroidUtilities.dp(60));
|
|
|
|
} else {
|
|
|
|
gridView.setColumnWidth(AndroidUtilities.dp(45));
|
|
|
|
}
|
|
|
|
gridView.setNumColumns(-1);
|
2015-08-13 11:23:31 +02:00
|
|
|
EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1);
|
2016-10-11 13:57:01 +02:00
|
|
|
gridView.setAdapter(emojiGridAdapter);
|
2015-05-03 13:48:36 +02:00
|
|
|
adapters.add(emojiGridAdapter);
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiGrids.add(gridView);
|
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
|
|
|
frameLayout.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));
|
|
|
|
|
|
|
|
views.add(frameLayout);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (needStickers) {
|
|
|
|
stickersWrap = new FrameLayout(context);
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
DataQuery.getInstance(currentAccount).checkStickers(DataQuery.TYPE_IMAGE);
|
|
|
|
DataQuery.getInstance(currentAccount).checkFeaturedStickers();
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersGridView = new RecyclerListView(context) {
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
boolean ignoreLayout;
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
2017-03-31 01:58:05 +02:00
|
|
|
boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickerPreviewViewerDelegate);
|
2016-03-06 02:49:31 +01:00
|
|
|
return super.onInterceptTouchEvent(event) || result;
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE || trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) {
|
2016-01-11 18:19:48 +01:00
|
|
|
super.setVisibility(GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
|
|
|
if (firstAttach && stickersGridAdapter.getItemCount() > 0) {
|
|
|
|
ignoreLayout = true;
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(1, 0);
|
|
|
|
firstAttach = false;
|
|
|
|
ignoreLayout = false;
|
|
|
|
}
|
|
|
|
super.onLayout(changed, l, t, r, b);
|
|
|
|
checkSearchFieldScroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (ignoreLayout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.requestLayout();
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
};
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
stickersGridView.setLayoutManager(stickersLayoutManager = new GridLayoutManager(context, 5));
|
|
|
|
stickersLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
|
@Override
|
|
|
|
public int getSpanSize(int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (stickersGridView.getAdapter() == stickersGridAdapter) {
|
|
|
|
if (position == 0) {
|
|
|
|
return stickersGridAdapter.stickersPerRow;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (position != stickersGridAdapter.totalItems) {
|
|
|
|
Object object = stickersGridAdapter.cache.get(position);
|
|
|
|
if (object == null || stickersGridAdapter.cache.get(position) instanceof TLRPC.Document) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stickersGridAdapter.stickersPerRow;
|
|
|
|
} else {
|
|
|
|
if (position != stickersSearchGridAdapter.totalItems) {
|
|
|
|
Object object = stickersSearchGridAdapter.cache.get(position);
|
|
|
|
if (object == null || stickersSearchGridAdapter.cache.get(position) instanceof TLRPC.Document) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stickersGridAdapter.stickersPerRow;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(4 + 48), 0, 0);
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersGridView.setClipToPadding(false);
|
2016-10-11 13:57:01 +02:00
|
|
|
views.add(stickersWrap);
|
2018-07-30 04:07:02 +02:00
|
|
|
stickersSearchGridAdapter = new StickersSearchGridAdapter(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersGridView.setAdapter(stickersGridAdapter = new StickersGridAdapter(context));
|
2019-01-23 18:03:33 +01:00
|
|
|
stickersGridView.setOnTouchListener((v, event) -> StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener, stickerPreviewViewerDelegate));
|
|
|
|
stickersOnItemClickListener = (view, position) -> {
|
|
|
|
if (stickersGridView.getAdapter() == stickersSearchGridAdapter) {
|
|
|
|
TLRPC.StickerSetCovered pack = stickersSearchGridAdapter.positionsToSets.get(position);
|
|
|
|
if (pack != null) {
|
|
|
|
listener.onShowStickerSet(pack.set, null);
|
2015-08-13 11:23:31 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!(view instanceof StickerEmojiCell)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
StickerPreviewViewer.getInstance().reset();
|
|
|
|
StickerEmojiCell cell = (StickerEmojiCell) view;
|
|
|
|
if (cell.isDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cell.disable();
|
|
|
|
listener.onStickerSelected(cell.getSticker(), cell.getParentObject());
|
2015-08-13 11:23:31 +02:00
|
|
|
};
|
|
|
|
stickersGridView.setOnItemClickListener(stickersOnItemClickListener);
|
2017-03-31 01:58:05 +02:00
|
|
|
stickersGridView.setGlowColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersWrap.addView(stickersGridView);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
searchEditTextContainer = new FrameLayout(context);
|
|
|
|
searchEditTextContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
stickersWrap.addView(searchEditTextContainer, new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, searchFieldHeight));
|
|
|
|
|
|
|
|
searchBackground = new View(context);
|
|
|
|
searchBackground.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), Theme.getColor(Theme.key_chat_emojiSearchBackground)));
|
|
|
|
searchEditTextContainer.addView(searchBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.LEFT | Gravity.TOP, 14, 14, 14, 0));
|
|
|
|
|
|
|
|
searchIconImageView = new ImageView(context);
|
|
|
|
searchIconImageView.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
searchIconImageView.setImageResource(R.drawable.sticker_search);
|
|
|
|
searchIconImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
searchEditTextContainer.addView(searchIconImageView, LayoutHelper.createFrame(36, 36, Gravity.LEFT | Gravity.TOP, 14, 14, 0, 0));
|
|
|
|
|
|
|
|
clearSearchImageView = new ImageView(context);
|
|
|
|
clearSearchImageView.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
clearSearchImageView.setImageDrawable(progressDrawable = new CloseProgressDrawable2());
|
|
|
|
clearSearchImageView.setScaleX(0.1f);
|
|
|
|
clearSearchImageView.setScaleY(0.1f);
|
|
|
|
clearSearchImageView.setAlpha(0.0f);
|
|
|
|
clearSearchImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
searchEditTextContainer.addView(clearSearchImageView, LayoutHelper.createFrame(36, 36, Gravity.RIGHT | Gravity.TOP, 14, 14, 14, 0));
|
2019-01-23 18:03:33 +01:00
|
|
|
clearSearchImageView.setOnClickListener(v -> {
|
|
|
|
searchEditText.setText("");
|
|
|
|
AndroidUtilities.showKeyboard(searchEditText);
|
2018-07-30 04:07:02 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
searchEditText = new EditTextBoldCursor(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
if (!listener.isSearchOpened()) {
|
|
|
|
if (searchAnimation != null) {
|
|
|
|
searchAnimation.cancel();
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
if (listener != null && listener.isExpanded()) {
|
|
|
|
searchAnimation = new AnimatorSet();
|
|
|
|
searchAnimation.playTogether(ObjectAnimator.ofFloat(stickersTab, "translationY", -AndroidUtilities.dp(47)),
|
|
|
|
ObjectAnimator.ofFloat(stickersGridView, "translationY", -AndroidUtilities.dp(48)),
|
|
|
|
ObjectAnimator.ofFloat(searchEditTextContainer, "translationY", AndroidUtilities.dp(0)));
|
|
|
|
searchAnimation.setDuration(200);
|
|
|
|
searchAnimation.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
|
|
|
|
searchAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(searchAnimation)) {
|
|
|
|
stickersGridView.setTranslationY(0);
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(searchAnimation)) {
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
searchAnimation.start();
|
|
|
|
} else {
|
|
|
|
searchEditTextContainer.setTranslationY(AndroidUtilities.dp(0));
|
|
|
|
stickersTab.setTranslationY(-AndroidUtilities.dp(47));
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listener.onSearchOpenClose(true);
|
|
|
|
searchEditText.requestFocus();
|
|
|
|
AndroidUtilities.showKeyboard(searchEditText);
|
|
|
|
}
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
searchEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
|
|
|
searchEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
|
|
|
|
searchEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
searchEditText.setBackgroundDrawable(null);
|
|
|
|
searchEditText.setPadding(0, 0, 0, 0);
|
|
|
|
searchEditText.setMaxLines(1);
|
|
|
|
searchEditText.setLines(1);
|
|
|
|
searchEditText.setSingleLine(true);
|
|
|
|
searchEditText.setImeOptions(EditorInfo.IME_ACTION_SEARCH | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
|
|
|
searchEditText.setHint(LocaleController.getString("SearchStickersHint", R.string.SearchStickersHint));
|
|
|
|
searchEditText.setCursorColor(Theme.getColor(Theme.key_featuredStickers_addedIcon));
|
|
|
|
searchEditText.setCursorSize(AndroidUtilities.dp(20));
|
|
|
|
searchEditText.setCursorWidth(1.5f);
|
|
|
|
searchEditTextContainer.addView(searchEditText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 40, Gravity.LEFT | Gravity.TOP, 16 + 30, 12, 16 + 30, 0));
|
|
|
|
searchEditText.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) {
|
|
|
|
boolean show = searchEditText.length() > 0;
|
|
|
|
boolean showed = clearSearchImageView.getAlpha() != 0;
|
|
|
|
if (show != showed) {
|
|
|
|
clearSearchImageView.animate()
|
|
|
|
.alpha(show ? 1.0f : 0.0f)
|
|
|
|
.setDuration(150)
|
|
|
|
.scaleX(show ? 1.0f : 0.1f)
|
|
|
|
.scaleY(show ? 1.0f : 0.1f)
|
|
|
|
.start();
|
|
|
|
}
|
|
|
|
stickersSearchGridAdapter.search(searchEditText.getText().toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingGridView = new RecyclerListView(context);
|
|
|
|
trendingGridView.setItemAnimator(null);
|
|
|
|
trendingGridView.setLayoutAnimation(null);
|
|
|
|
trendingGridView.setLayoutManager(trendingLayoutManager = new GridLayoutManager(context, 5) {
|
|
|
|
@Override
|
|
|
|
public boolean supportsPredictiveItemAnimations() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
trendingLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
|
@Override
|
|
|
|
public int getSpanSize(int position) {
|
|
|
|
if (trendingGridAdapter.cache.get(position) instanceof Integer || position == trendingGridAdapter.totalItems) {
|
|
|
|
return trendingGridAdapter.stickersPerRow;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
trendingGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
checkStickersTabY(recyclerView, dy);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
trendingGridView.setClipToPadding(false);
|
|
|
|
trendingGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
|
|
|
|
trendingGridView.setAdapter(trendingGridAdapter = new TrendingGridAdapter(context));
|
2019-01-23 18:03:33 +01:00
|
|
|
trendingGridView.setOnItemClickListener((view, position) -> {
|
|
|
|
TLRPC.StickerSetCovered pack = trendingGridAdapter.positionsToSets.get(position);
|
|
|
|
if (pack != null) {
|
|
|
|
listener.onShowStickerSet(pack.set, null);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
trendingGridAdapter.notifyDataSetChanged();
|
2017-03-31 01:58:05 +02:00
|
|
|
trendingGridView.setGlowColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingGridView.setVisibility(GONE);
|
|
|
|
stickersWrap.addView(trendingGridView);
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
if (needGif) {
|
|
|
|
gifsGridView = new RecyclerListView(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
gifsGridView.setClipToPadding(false);
|
|
|
|
gifsGridView.setPadding(0, AndroidUtilities.dp(48), 0, 0);
|
2016-05-25 23:49:47 +02:00
|
|
|
gifsGridView.setLayoutManager(flowLayoutManager = new ExtendedGridLayoutManager(context, 100) {
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
private Size size = new Size();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Size getSizeForItem(int i) {
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.Document document = recentGifs.get(i);
|
2019-01-23 18:03:33 +01:00
|
|
|
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
|
|
|
|
size.width = thumb != null && thumb.w != 0 ? thumb.w : 100;
|
|
|
|
size.height = thumb != null && thumb.h != 0 ? thumb.h : 100;
|
2016-01-11 18:19:48 +01:00
|
|
|
for (int b = 0; b < document.attributes.size(); b++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(b);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
size.width = attribute.w;
|
|
|
|
size.height = attribute.h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
});
|
2016-05-25 23:49:47 +02:00
|
|
|
flowLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
|
|
|
@Override
|
|
|
|
public int getSpanSize(int position) {
|
|
|
|
return flowLayoutManager.getSpanSizeForItem(position);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
gifsGridView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
|
|
|
@Override
|
|
|
|
public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
|
|
|
outRect.left = 0;
|
|
|
|
outRect.top = 0;
|
|
|
|
outRect.bottom = 0;
|
|
|
|
int position = parent.getChildAdapterPosition(view);
|
|
|
|
if (!flowLayoutManager.isFirstRow(position)) {
|
|
|
|
outRect.top = AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
outRect.right = flowLayoutManager.isLastInRow(position) ? 0 : AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
});
|
2016-06-24 12:27:15 +02:00
|
|
|
gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
2016-01-11 18:19:48 +01:00
|
|
|
gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context));
|
2016-10-11 13:57:01 +02:00
|
|
|
gifsGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
checkStickersTabY(recyclerView, dy);
|
|
|
|
}
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
gifsGridView.setOnItemClickListener((view, position) -> {
|
|
|
|
if (position < 0 || position >= recentGifs.size() || listener == null) {
|
|
|
|
return;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
listener.onGifSelected(recentGifs.get(position), "gif");
|
2016-01-11 18:19:48 +01:00
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
gifsGridView.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (position < 0 || position >= recentGifs.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final TLRPC.Document searchImage = recentGifs.get(position);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("DeleteGif", R.string.DeleteGif));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK).toUpperCase(), (dialogInterface, i) -> {
|
|
|
|
DataQuery.getInstance(currentAccount).removeRecentGif(searchImage);
|
|
|
|
recentGifs = DataQuery.getInstance(currentAccount).getRecentGifs();
|
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (recentGifs.isEmpty()) {
|
|
|
|
updateStickerTabs();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
|
|
|
return true;
|
2016-01-11 18:19:48 +01:00
|
|
|
});
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
stickersWrap.addView(gifsGridView);
|
|
|
|
}
|
|
|
|
|
|
|
|
stickersEmptyView = new TextView(context);
|
|
|
|
stickersEmptyView.setText(LocaleController.getString("NoStickers", R.string.NoStickers));
|
|
|
|
stickersEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
2017-03-31 01:58:05 +02:00
|
|
|
stickersEmptyView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelEmptyText));
|
2018-07-30 04:07:02 +02:00
|
|
|
stickersEmptyView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
|
2016-01-11 18:19:48 +01:00
|
|
|
stickersGridView.setEmptyView(stickersEmptyView);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab = new ScrollSlidingTabStrip(context) {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
boolean startedScroll;
|
|
|
|
float lastX;
|
|
|
|
float lastTranslateX;
|
|
|
|
boolean first = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
final int touchslop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
|
2017-07-23 14:56:38 +02:00
|
|
|
float downX, downY;
|
|
|
|
boolean draggingVertically, draggingHorizontally;
|
|
|
|
VelocityTracker vTracker;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
draggingVertically = draggingHorizontally = false;
|
|
|
|
downX = ev.getRawX();
|
|
|
|
downY = ev.getRawY();
|
|
|
|
} else {
|
|
|
|
if (!draggingVertically && !draggingHorizontally && dragListener != null) {
|
|
|
|
if (Math.abs(ev.getRawY() - downY) >= touchslop) {
|
|
|
|
draggingVertically = true;
|
|
|
|
downY = ev.getRawY();
|
|
|
|
dragListener.onDragStart();
|
|
|
|
if (startedScroll) {
|
2017-07-23 14:56:38 +02:00
|
|
|
pager.endFakeDrag();
|
2017-12-08 18:35:59 +01:00
|
|
|
startedScroll = false;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
lastX = ev.getX();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
draggingVertically = draggingHorizontally = false;
|
|
|
|
downX = ev.getRawX();
|
|
|
|
downY = ev.getRawY();
|
|
|
|
} else {
|
|
|
|
if (!draggingVertically && !draggingHorizontally && dragListener != null) {
|
|
|
|
if (Math.abs(ev.getRawX() - downX) >= touchslop) {
|
|
|
|
draggingHorizontally = true;
|
|
|
|
} else if (Math.abs(ev.getRawY() - downY) >= touchslop) {
|
|
|
|
draggingVertically = true;
|
|
|
|
downY = ev.getRawY();
|
2017-07-23 14:56:38 +02:00
|
|
|
dragListener.onDragStart();
|
2017-12-08 18:35:59 +01:00
|
|
|
if (startedScroll) {
|
2017-07-23 14:56:38 +02:00
|
|
|
pager.endFakeDrag();
|
2017-12-08 18:35:59 +01:00
|
|
|
startedScroll = false;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (draggingVertically) {
|
|
|
|
if (vTracker == null) {
|
|
|
|
vTracker = VelocityTracker.obtain();
|
|
|
|
}
|
2017-07-23 14:56:38 +02:00
|
|
|
vTracker.addMovement(ev);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
|
2017-07-23 14:56:38 +02:00
|
|
|
vTracker.computeCurrentVelocity(1000);
|
2017-12-08 18:35:59 +01:00
|
|
|
float velocity = vTracker.getYVelocity();
|
2017-07-23 14:56:38 +02:00
|
|
|
vTracker.recycle();
|
2017-12-08 18:35:59 +01:00
|
|
|
vTracker = null;
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_UP) {
|
2017-07-23 14:56:38 +02:00
|
|
|
dragListener.onDragEnd(velocity);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
2017-07-23 14:56:38 +02:00
|
|
|
dragListener.onDragCancel();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
first = true;
|
|
|
|
draggingVertically = draggingHorizontally = false;
|
|
|
|
} else {
|
|
|
|
dragListener.onDrag(Math.round(ev.getRawY() - downY));
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
float newTranslationX = stickersTab.getTranslationX();
|
|
|
|
if (stickersTab.getScrollX() == 0 && newTranslationX == 0) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!startedScroll && lastX - ev.getX() < 0) {
|
|
|
|
if (pager.beginFakeDrag()) {
|
|
|
|
startedScroll = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
lastTranslateX = stickersTab.getTranslationX();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (startedScroll && lastX - ev.getX() > 0) {
|
|
|
|
if (pager.isFakeDragging()) {
|
|
|
|
pager.endFakeDrag();
|
2015-06-29 19:12:11 +02:00
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
if (startedScroll) {
|
|
|
|
int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
|
|
|
|
try {
|
|
|
|
pager.fakeDragBy(dx);
|
|
|
|
lastTranslateX = newTranslationX;
|
|
|
|
} catch (Exception e) {
|
|
|
|
try {
|
2015-06-29 19:12:11 +02:00
|
|
|
pager.endFakeDrag();
|
2016-06-24 12:27:15 +02:00
|
|
|
} catch (Exception e2) {
|
|
|
|
//don't promt
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
startedScroll = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
lastX = ev.getX();
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
first = true;
|
2017-12-08 18:35:59 +01:00
|
|
|
draggingVertically = draggingHorizontally = false;
|
2016-06-24 12:27:15 +02:00
|
|
|
if (startedScroll) {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return startedScroll || super.onTouchEvent(ev);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
};
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab.setUnderlineHeight(AndroidUtilities.dp(1));
|
2017-03-31 01:58:05 +02:00
|
|
|
stickersTab.setIndicatorColor(Theme.getColor(Theme.key_chat_emojiPanelStickerPackSelector));
|
|
|
|
stickersTab.setUnderlineColor(Theme.getColor(Theme.key_chat_emojiPanelStickerPackSelector));
|
|
|
|
stickersTab.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab.setVisibility(INVISIBLE);
|
|
|
|
addView(stickersTab, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
|
|
|
|
stickersTab.setTranslationX(AndroidUtilities.displaySize.x);
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2019-01-23 18:03:33 +01:00
|
|
|
stickersTab.setDelegate(page -> {
|
|
|
|
if (gifsGridView != null) {
|
|
|
|
if (page == gifTabNum + 1) {
|
|
|
|
if (gifsGridView.getVisibility() != VISIBLE) {
|
|
|
|
listener.onGifTab(true);
|
|
|
|
showGifTab();
|
|
|
|
}
|
|
|
|
} else if (page == trendingTabNum + 1) {
|
|
|
|
if (trendingGridView.getVisibility() != VISIBLE) {
|
|
|
|
showTrendingTab();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
listener.onGifTab(false);
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
|
|
|
searchEditTextContainer.setVisibility(VISIBLE);
|
|
|
|
int vis = stickersGridView.getVisibility();
|
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
|
|
|
|
checkScroll();
|
|
|
|
saveNewPage();
|
|
|
|
} else if (trendingGridView.getVisibility() == VISIBLE) {
|
|
|
|
trendingGridView.setVisibility(GONE);
|
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
|
|
|
searchEditTextContainer.setVisibility(VISIBLE);
|
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
|
|
|
|
saveNewPage();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
if (page == 0) {
|
|
|
|
pager.setCurrentItem(0);
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (page == gifTabNum + 1 || page == trendingTabNum + 1) {
|
|
|
|
return;
|
|
|
|
} else if (page == recentTabBum + 1) {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(stickersGridAdapter.getPositionForPack("recent"), 0);
|
|
|
|
checkStickersTabY(null, 0);
|
|
|
|
stickersTab.onPageScrolled(recentTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
return;
|
|
|
|
} else if (page == favTabBum + 1) {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(stickersGridAdapter.getPositionForPack("fav"), 0);
|
|
|
|
checkStickersTabY(null, 0);
|
|
|
|
stickersTab.onPageScrolled(favTabBum + 1, (favTabBum > 0 ? favTabBum : stickersTabOffset) + 1);
|
2015-12-09 19:27:52 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
int index = page - 1 - stickersTabOffset;
|
|
|
|
if (index >= stickerSets.size()) {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersSettingsClick();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (index >= stickerSets.size()) {
|
|
|
|
index = stickerSets.size() - 1;
|
|
|
|
}
|
|
|
|
firstAttach = false;
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(stickersGridAdapter.getPositionForPack(stickerSets.get(index)), 0);
|
|
|
|
checkStickersTabY(null, 0);
|
|
|
|
checkScroll();
|
2015-06-29 19:12:11 +02:00
|
|
|
});
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersGridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
|
|
|
|
AndroidUtilities.hideKeyboard(searchEditText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
2016-10-11 13:57:01 +02:00
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
checkScroll();
|
|
|
|
checkStickersTabY(recyclerView, dy);
|
2018-07-30 04:07:02 +02:00
|
|
|
checkSearchFieldScroll();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
pager = new ViewPager(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
2015-05-03 13:48:36 +02:00
|
|
|
pager.setAdapter(new EmojiPagesAdapter());
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab = new LinearLayout(context) {
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
addView(emojiTab, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStrip.setViewPager(pager);
|
|
|
|
pagerSlidingTabStrip.setShouldExpand(true);
|
|
|
|
pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2));
|
|
|
|
pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
|
2017-03-31 01:58:05 +02:00
|
|
|
pagerSlidingTabStrip.setIndicatorColor(Theme.getColor(Theme.key_chat_emojiPanelIconSelector));
|
|
|
|
pagerSlidingTabStrip.setUnderlineColor(Theme.getColor(Theme.key_chat_emojiPanelShadowLine));
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
2016-10-11 13:57:01 +02:00
|
|
|
EmojiView.this.onPageScrolled(position, getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), positionOffsetPixels);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
2016-10-11 13:57:01 +02:00
|
|
|
saveNewPage();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageScrollStateChanged(int state) {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
FrameLayout frameLayout = new FrameLayout(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab.addView(frameLayout, LayoutHelper.createLinear(52, 48));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
backspaceButton = new ImageView(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
backspacePressed = true;
|
|
|
|
backspaceOnce = false;
|
|
|
|
postBackspaceRunnable(350);
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
backspacePressed = false;
|
|
|
|
if (!backspaceOnce) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (listener != null && listener.onBackspace()) {
|
2015-05-03 13:48:36 +02:00
|
|
|
backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onTouchEvent(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
backspaceButton.setImageResource(R.drawable.ic_smiles_backspace);
|
2017-03-31 01:58:05 +02:00
|
|
|
backspaceButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelBackspace), PorterDuff.Mode.MULTIPLY));
|
2015-05-03 13:48:36 +02:00
|
|
|
backspaceButton.setScaleType(ImageView.ScaleType.CENTER);
|
2015-06-29 19:12:11 +02:00
|
|
|
frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
shadowLine = new View(context);
|
|
|
|
shadowLine.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelShadowLine));
|
|
|
|
frameLayout.addView(shadowLine, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));
|
|
|
|
|
|
|
|
noRecentTextView = new TextView(context);
|
|
|
|
noRecentTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
|
|
|
|
noRecentTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
noRecentTextView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelEmptyText));
|
|
|
|
noRecentTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
noRecentTextView.setGravity(Gravity.CENTER);
|
|
|
|
noRecentTextView.setClickable(false);
|
|
|
|
noRecentTextView.setFocusable(false);
|
|
|
|
((FrameLayout) views.get(0)).addView(noRecentTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 48, 0, 0));
|
|
|
|
emojiGrids.get(0).setEmptyView(noRecentTextView);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
addView(pager, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
mediaBanTooltip = new CorrectlyMeasuringTextView(context);
|
|
|
|
mediaBanTooltip.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(3), Theme.getColor(Theme.key_chat_gifSaveHintBackground)));
|
|
|
|
mediaBanTooltip.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
|
|
|
|
mediaBanTooltip.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(7), AndroidUtilities.dp(8), AndroidUtilities.dp(7));
|
|
|
|
mediaBanTooltip.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
mediaBanTooltip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
|
|
|
mediaBanTooltip.setVisibility(INVISIBLE);
|
|
|
|
addView(mediaBanTooltip, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.TOP, 30, 48 + 5, 5, 0));
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
emojiSize = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 40 : 32);
|
|
|
|
pickerView = new EmojiColorPickerView(context);
|
|
|
|
pickerViewPopup = new EmojiPopupWindow(pickerView, popupWidth = AndroidUtilities.dp((AndroidUtilities.isTablet() ? 40 : 32) * 6 + 10 + 4 * 5), popupHeight = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 64 : 56));
|
|
|
|
pickerViewPopup.setOutsideTouchable(true);
|
|
|
|
pickerViewPopup.setClippingEnabled(true);
|
|
|
|
pickerViewPopup.setInputMethodMode(EmojiPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
|
|
|
pickerViewPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
|
|
|
|
pickerViewPopup.getContentView().setFocusableInTouchMode(true);
|
2019-01-23 18:03:33 +01:00
|
|
|
pickerViewPopup.getContentView().setOnKeyListener((v, keyCode, event) -> {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) {
|
|
|
|
pickerViewPopup.dismiss();
|
|
|
|
return true;
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return false;
|
2015-10-29 18:10:07 +01:00
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
currentPage = MessagesController.getGlobalEmojiSettings().getInt("selected_page", 0);
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.loadRecentEmoji();
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void showSearchField(boolean show) {
|
|
|
|
int position = stickersLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (show) {
|
|
|
|
if (position == 1 || position == 2) {
|
|
|
|
stickersLayoutManager.scrollToPosition(0);
|
|
|
|
stickersTab.setTranslationY(0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (position == 0) {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideSearchKeyboard() {
|
|
|
|
AndroidUtilities.hideKeyboard(searchEditText);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void closeSearch(boolean animated) {
|
|
|
|
closeSearch(animated, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void closeSearch(boolean animated, long scrollToSet) {
|
|
|
|
if (searchAnimation != null) {
|
|
|
|
searchAnimation.cancel();
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
searchEditText.setText("");
|
|
|
|
if (scrollToSet != -1) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = DataQuery.getInstance(currentAccount).getStickerSetById(scrollToSet);
|
|
|
|
if (set != null) {
|
|
|
|
int pos = stickersGridAdapter.getPositionForPack(set);
|
|
|
|
if (pos >= 0) {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(pos, AndroidUtilities.dp(48 + 12));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
searchAnimation = new AnimatorSet();
|
|
|
|
searchAnimation.playTogether(ObjectAnimator.ofFloat(stickersTab, "translationY", 0),
|
|
|
|
ObjectAnimator.ofFloat(stickersGridView, "translationY", AndroidUtilities.dp(48) - searchFieldHeight),
|
|
|
|
ObjectAnimator.ofFloat(searchEditTextContainer, "translationY", AndroidUtilities.dp(48) - searchFieldHeight));
|
|
|
|
searchAnimation.setDuration(200);
|
|
|
|
searchAnimation.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
|
|
|
|
searchAnimation.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animation.equals(searchAnimation)) {
|
|
|
|
int pos = stickersLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
int firstVisPos = stickersLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
int top = 0;
|
|
|
|
if (firstVisPos != RecyclerView.NO_POSITION) {
|
|
|
|
View firstVisView = stickersLayoutManager.findViewByPosition(firstVisPos);
|
|
|
|
top = (int) (firstVisView.getTop() + stickersGridView.getTranslationY());
|
|
|
|
}
|
|
|
|
stickersGridView.setTranslationY(0);
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(48 + 4), 0, 0);
|
|
|
|
if (firstVisPos != RecyclerView.NO_POSITION) {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(firstVisPos, top - stickersGridView.getPaddingTop());
|
|
|
|
}
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animation.equals(searchAnimation)) {
|
|
|
|
searchAnimation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
searchAnimation.start();
|
|
|
|
} else {
|
|
|
|
stickersLayoutManager.scrollToPositionWithOffset(1, 0);
|
|
|
|
searchEditTextContainer.setTranslationY(AndroidUtilities.dp(48) - searchFieldHeight);
|
|
|
|
stickersTab.setTranslationY(0);
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(48 + 4), 0, 0);
|
|
|
|
listener.onSearchOpenClose(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void checkStickersTabY(View list, int dy) {
|
|
|
|
if (list == null) {
|
|
|
|
stickersTab.setTranslationY(minusDy = 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (list.getVisibility() != VISIBLE) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (listener != null && listener.isSearchOpened()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dy > 0 && stickersGridView != null && stickersGridView.getVisibility() == VISIBLE) {
|
|
|
|
RecyclerView.ViewHolder holder = stickersGridView.findViewHolderForAdapterPosition(0);
|
|
|
|
if (holder != null && holder.itemView.getTop() + searchFieldHeight >= stickersGridView.getPaddingTop()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
minusDy -= dy;
|
|
|
|
if (minusDy > 0) {
|
|
|
|
minusDy = 0;
|
|
|
|
} else if (minusDy < -AndroidUtilities.dp(48 * 6)) {
|
|
|
|
minusDy = -AndroidUtilities.dp(48 * 6);
|
|
|
|
}
|
|
|
|
stickersTab.setTranslationY(Math.max(-AndroidUtilities.dp(47), minusDy));
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private void checkSearchFieldScroll() {
|
|
|
|
if (stickersGridView == null || listener != null && listener.isSearchOpened()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
RecyclerView.ViewHolder holder = stickersGridView.findViewHolderForAdapterPosition(0);
|
|
|
|
if (holder != null) {
|
|
|
|
searchEditTextContainer.setTranslationY(holder.itemView.getTop());
|
|
|
|
} else {
|
|
|
|
searchEditTextContainer.setTranslationY(-searchFieldHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void checkScroll() {
|
|
|
|
int firstVisibleItem = stickersLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (firstVisibleItem == RecyclerView.NO_POSITION) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (stickersGridView == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
int firstTab;
|
|
|
|
if (favTabBum > 0) {
|
|
|
|
firstTab = favTabBum;
|
|
|
|
} else if (recentTabBum > 0) {
|
|
|
|
firstTab = recentTabBum;
|
|
|
|
} else {
|
|
|
|
firstTab = stickersTabOffset;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (stickersGridView.getVisibility() != VISIBLE) {
|
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() != VISIBLE) {
|
|
|
|
gifsGridView.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
if (stickersEmptyView != null && stickersEmptyView.getVisibility() == VISIBLE) {
|
|
|
|
stickersEmptyView.setVisibility(GONE);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
stickersTab.onPageScrolled(gifTabNum + 1, firstTab + 1);
|
2017-03-31 01:58:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
stickersTab.onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, firstTab + 1);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void saveNewPage() {
|
|
|
|
int newPage;
|
|
|
|
if (pager.getCurrentItem() == 6) {
|
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
newPage = 2;
|
|
|
|
} else {
|
|
|
|
newPage = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newPage = 0;
|
|
|
|
}
|
|
|
|
if (currentPage != newPage) {
|
|
|
|
currentPage = newPage;
|
2018-07-30 04:07:02 +02:00
|
|
|
MessagesController.getGlobalEmojiSettings().edit().putInt("selected_page", newPage).commit();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:26:32 +01:00
|
|
|
public void clearRecentEmoji() {
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.clearRecentEmoji();
|
2016-03-16 13:26:32 +01:00
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void showTrendingTab() {
|
|
|
|
trendingGridView.setVisibility(VISIBLE);
|
|
|
|
stickersGridView.setVisibility(GONE);
|
2018-07-30 04:07:02 +02:00
|
|
|
firstAttach = true;
|
|
|
|
searchEditTextContainer.setVisibility(GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersEmptyView.setVisibility(GONE);
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
stickersTab.onPageScrolled(trendingTabNum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
saveNewPage();
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private void showGifTab() {
|
|
|
|
gifsGridView.setVisibility(VISIBLE);
|
|
|
|
stickersGridView.setVisibility(GONE);
|
2018-07-30 04:07:02 +02:00
|
|
|
firstAttach = true;
|
|
|
|
searchEditTextContainer.setVisibility(GONE);
|
2016-01-11 18:19:48 +01:00
|
|
|
stickersEmptyView.setVisibility(GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingGridView.setVisibility(GONE);
|
|
|
|
stickersTab.onPageScrolled(gifTabNum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
saveNewPage();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void onPageScrolled(int position, int width, int positionOffsetPixels) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickersTab == null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
int margin = 0;
|
|
|
|
if (position == 5) {
|
|
|
|
margin = -positionOffsetPixels;
|
2016-01-11 18:19:48 +01:00
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersTab(positionOffsetPixels != 0);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else if (position == 6) {
|
|
|
|
margin = -width;
|
2016-01-11 18:19:48 +01:00
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersTab(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersTab(false);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (emojiTab.getTranslationX() != margin) {
|
|
|
|
emojiTab.setTranslationX(margin);
|
|
|
|
stickersTab.setTranslationX(width + margin);
|
|
|
|
stickersTab.setVisibility(margin < 0 ? VISIBLE : INVISIBLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void postBackspaceRunnable(final int time) {
|
2019-01-23 18:03:33 +01:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (!backspacePressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (listener != null && listener.onBackspace()) {
|
|
|
|
backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
backspaceOnce = true;
|
|
|
|
postBackspaceRunnable(Math.max(50, time - 100));
|
2015-05-03 13:48:36 +02:00
|
|
|
}, time);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public void switchToGifRecent() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (gifTabNum >= 0 && !recentGifs.isEmpty()) {
|
|
|
|
stickersTab.selectTab(gifTabNum + 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
switchToGifTab = true;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
pager.setCurrentItem(6);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void updateStickerTabs() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickersTab == null) {
|
2016-03-06 02:49:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
recentTabBum = -2;
|
2017-12-08 18:35:59 +01:00
|
|
|
favTabBum = -2;
|
2016-10-11 13:57:01 +02:00
|
|
|
gifTabNum = -2;
|
|
|
|
trendingTabNum = -2;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
stickersTabOffset = 0;
|
2016-10-11 13:57:01 +02:00
|
|
|
int lastPosition = stickersTab.getCurrentPosition();
|
|
|
|
stickersTab.removeTabs();
|
2017-03-31 01:58:05 +02:00
|
|
|
Drawable drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles2_smile);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersTab.addIconTab(drawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
if (showGifs && !recentGifs.isEmpty()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles_gif);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersTab.addIconTab(drawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
gifTabNum = stickersTabOffset;
|
|
|
|
stickersTabOffset++;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<Long> unread = DataQuery.getInstance(currentAccount).getUnreadStickerSets();
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null && trendingGridAdapter.getItemCount() != 0 && !unread.isEmpty()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles_trend);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersCounter = stickersTab.addIconTabWithCounter(drawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingTabNum = stickersTabOffset;
|
2016-01-11 18:19:48 +01:00
|
|
|
stickersTabOffset++;
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersCounter.setText(String.format("%d", unread.size()));
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
if (!favouriteStickers.isEmpty()) {
|
|
|
|
favTabBum = stickersTabOffset;
|
|
|
|
stickersTabOffset++;
|
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.staredstickerstab);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersTab.addIconTab(drawable);
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!recentStickers.isEmpty()) {
|
2016-01-11 18:19:48 +01:00
|
|
|
recentTabBum = stickersTabOffset;
|
|
|
|
stickersTabOffset++;
|
2017-03-31 01:58:05 +02:00
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles2_recent);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersTab.addIconTab(drawable);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
stickerSets.clear();
|
2017-12-08 18:35:59 +01:00
|
|
|
groupStickerSet = null;
|
|
|
|
groupStickerPackPosition = -1;
|
|
|
|
groupStickerPackNum = -10;
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = DataQuery.getInstance(currentAccount).getStickerSets(DataQuery.TYPE_IMAGE);
|
2015-06-29 19:12:11 +02:00
|
|
|
for (int a = 0; a < packs.size(); a++) {
|
|
|
|
TLRPC.TL_messages_stickerSet pack = packs.get(a);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (pack.set.archived || pack.documents == null || pack.documents.isEmpty()) {
|
2015-06-29 19:12:11 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stickerSets.add(pack);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (info != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
long hiddenStickerSetId = MessagesController.getEmojiSettings(currentAccount).getLong("group_hide_stickers_" + info.id, -1);
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(info.id);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (chat == null || info.stickerset == null || !ChatObject.hasAdminRights(chat)) {
|
|
|
|
groupStickersHidden = hiddenStickerSetId != -1;
|
|
|
|
} else if (info.stickerset != null) {
|
|
|
|
groupStickersHidden = hiddenStickerSetId == info.stickerset.id;
|
|
|
|
}
|
|
|
|
if (info.stickerset != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.TL_messages_stickerSet pack = DataQuery.getInstance(currentAccount).getGroupStickerSetById(info.stickerset);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (pack != null && pack.documents != null && !pack.documents.isEmpty() && pack.set != null) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = new TLRPC.TL_messages_stickerSet();
|
|
|
|
set.documents = pack.documents;
|
|
|
|
set.packs = pack.packs;
|
|
|
|
set.set = pack.set;
|
|
|
|
if (groupStickersHidden) {
|
|
|
|
groupStickerPackNum = stickerSets.size();
|
|
|
|
stickerSets.add(set);
|
|
|
|
} else {
|
|
|
|
groupStickerPackNum = 0;
|
|
|
|
stickerSets.add(0, set);
|
|
|
|
}
|
|
|
|
groupStickerSet = info.can_set_stickers ? set : null;
|
|
|
|
}
|
|
|
|
} else if (info.can_set_stickers) {
|
|
|
|
TLRPC.TL_messages_stickerSet pack = new TLRPC.TL_messages_stickerSet();
|
|
|
|
if (groupStickersHidden) {
|
|
|
|
groupStickerPackNum = stickerSets.size();
|
|
|
|
stickerSets.add(pack);
|
|
|
|
} else {
|
|
|
|
groupStickerPackNum = 0;
|
|
|
|
stickerSets.add(0, pack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
for (int a = 0; a < stickerSets.size(); a++) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (a == groupStickerPackNum) {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(info.id);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (chat == null) {
|
|
|
|
stickerSets.remove(0);
|
|
|
|
a--;
|
|
|
|
} else {
|
|
|
|
stickersTab.addStickerTab(chat);
|
|
|
|
}
|
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
TLRPC.TL_messages_stickerSet stickerSet = stickerSets.get(a);
|
|
|
|
stickersTab.addStickerTab(stickerSet.documents.get(0), stickerSet);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null && trendingGridAdapter.getItemCount() != 0 && unread.isEmpty()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles_trend);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingTabNum = stickersTabOffset + stickerSets.size();
|
2017-03-31 01:58:05 +02:00
|
|
|
stickersTab.addIconTab(drawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
drawable = getContext().getResources().getDrawable(R.drawable.ic_smiles_settings);
|
|
|
|
Theme.setDrawableColorByKey(drawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
stickersTab.addIconTab(drawable);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab.updateTabStyles();
|
2016-01-11 18:19:48 +01:00
|
|
|
if (lastPosition != 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab.onPageScrolled(lastPosition, lastPosition);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
if (switchToGifTab) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (gifTabNum >= 0 && gifsGridView.getVisibility() != VISIBLE) {
|
2016-01-11 18:19:48 +01:00
|
|
|
showGifTab();
|
2016-05-25 23:49:47 +02:00
|
|
|
switchToGifTab = false;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
checkPanels();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkPanels() {
|
|
|
|
if (stickersTab == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (trendingTabNum == -2 && trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) {
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
trendingGridView.setVisibility(GONE);
|
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
2018-07-30 04:07:02 +02:00
|
|
|
searchEditTextContainer.setVisibility(VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
|
|
|
|
}
|
|
|
|
if (gifTabNum == -2 && gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
2016-01-11 18:19:48 +01:00
|
|
|
listener.onGifTab(false);
|
|
|
|
gifsGridView.setVisibility(GONE);
|
2016-10-11 13:57:01 +02:00
|
|
|
trendingGridView.setVisibility(GONE);
|
2016-01-11 18:19:48 +01:00
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
2018-07-30 04:07:02 +02:00
|
|
|
searchEditTextContainer.setVisibility(VISIBLE);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getItemCount() != 0 ? GONE : VISIBLE);
|
|
|
|
} else if (gifTabNum != -2) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersTab.onPageScrolled(gifTabNum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
} else if (trendingGridView != null && trendingGridView.getVisibility() == VISIBLE) {
|
|
|
|
stickersTab.onPageScrolled(trendingTabNum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
int position = stickersLayoutManager.findFirstVisibleItemPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
2017-12-08 18:35:59 +01:00
|
|
|
int firstTab;
|
|
|
|
if (favTabBum > 0) {
|
|
|
|
firstTab = favTabBum;
|
|
|
|
} else if (recentTabBum > 0) {
|
|
|
|
firstTab = recentTabBum;
|
|
|
|
} else {
|
|
|
|
firstTab = stickersTabOffset;
|
|
|
|
}
|
|
|
|
stickersTab.onPageScrolled(stickersGridAdapter.getTabForPosition(position) + 1, firstTab + 1);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
public void addRecentSticker(TLRPC.Document document) {
|
|
|
|
if (document == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
DataQuery.getInstance(currentAccount).addRecentSticker(DataQuery.TYPE_IMAGE, null, document, (int) (System.currentTimeMillis() / 1000), false);
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean wasEmpty = recentStickers.isEmpty();
|
2018-07-30 04:07:02 +02:00
|
|
|
recentStickers = DataQuery.getInstance(currentAccount).getRecentStickers(DataQuery.TYPE_IMAGE);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (wasEmpty) {
|
|
|
|
updateStickerTabs();
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void addRecentGif(TLRPC.Document document) {
|
|
|
|
if (document == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean wasEmpty = recentGifs.isEmpty();
|
2018-07-30 04:07:02 +02:00
|
|
|
recentGifs = DataQuery.getInstance(currentAccount).getRecentGifs();
|
2016-01-11 18:19:48 +01:00
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (wasEmpty) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void requestLayout() {
|
|
|
|
if (isLayout) {
|
|
|
|
return;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
super.requestLayout();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void updateUIColors() {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (AndroidUtilities.isInMultiwindow || forseMultiwindowLayout) {
|
2018-07-30 04:07:02 +02:00
|
|
|
getBackground().setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelBackground), PorterDuff.Mode.MULTIPLY));
|
|
|
|
} else {
|
|
|
|
setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
emojiTab.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchEditTextContainer != null) {
|
|
|
|
searchEditTextContainer.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
}
|
|
|
|
if (dotPaint != null) {
|
|
|
|
dotPaint.setColor(Theme.getColor(Theme.key_chat_emojiPanelNewTrending));
|
|
|
|
}
|
|
|
|
if (stickersGridView != null) {
|
|
|
|
stickersGridView.setGlowColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
}
|
|
|
|
if (trendingGridView != null) {
|
|
|
|
trendingGridView.setGlowColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
}
|
|
|
|
if (stickersEmptyView != null) {
|
|
|
|
stickersEmptyView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelEmptyText));
|
|
|
|
}
|
|
|
|
if (stickersTab != null) {
|
|
|
|
stickersTab.setIndicatorColor(Theme.getColor(Theme.key_chat_emojiPanelStickerPackSelector));
|
|
|
|
stickersTab.setUnderlineColor(Theme.getColor(Theme.key_chat_emojiPanelStickerPackSelector));
|
|
|
|
stickersTab.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
}
|
|
|
|
if (pagerSlidingTabStrip != null) {
|
|
|
|
pagerSlidingTabStrip.setIndicatorColor(Theme.getColor(Theme.key_chat_emojiPanelIconSelector));
|
|
|
|
pagerSlidingTabStrip.setUnderlineColor(Theme.getColor(Theme.key_chat_emojiPanelShadowLine));
|
|
|
|
}
|
|
|
|
if (backspaceButton != null) {
|
|
|
|
backspaceButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelBackspace), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
if (searchIconImageView != null) {
|
|
|
|
clearSearchImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelIcon), PorterDuff.Mode.MULTIPLY));
|
|
|
|
}
|
|
|
|
if (shadowLine != null) {
|
|
|
|
shadowLine.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelShadowLine));
|
|
|
|
}
|
|
|
|
if (noRecentTextView != null) {
|
|
|
|
noRecentTextView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelEmptyText));
|
|
|
|
}
|
|
|
|
if (mediaBanTooltip != null) {
|
|
|
|
((ShapeDrawable) mediaBanTooltip.getBackground()).getPaint().setColor(Theme.getColor(Theme.key_chat_gifSaveHintBackground));
|
|
|
|
mediaBanTooltip.setTextColor(Theme.getColor(Theme.key_chat_gifSaveHintText));
|
|
|
|
}
|
|
|
|
if (stickersCounter != null) {
|
|
|
|
stickersCounter.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelBadgeText));
|
|
|
|
Theme.setDrawableColor(stickersCounter.getBackground(), Theme.getColor(Theme.key_chat_emojiPanelBadgeBackground));
|
|
|
|
stickersCounter.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Theme.setDrawableColorByKey(stickersDrawable, Theme.key_chat_emojiPanelIcon);
|
|
|
|
for (int a = 0; a < icons.length - 1; a++) {
|
|
|
|
Theme.setEmojiDrawableColor(icons[a], Theme.getColor(Theme.key_chat_emojiPanelIcon), false);
|
|
|
|
Theme.setEmojiDrawableColor(icons[a], Theme.getColor(Theme.key_chat_emojiPanelIconSelected), true);
|
|
|
|
}
|
|
|
|
if (searchBackground != null) {
|
|
|
|
Theme.setDrawableColorByKey(searchBackground.getBackground(), Theme.key_chat_emojiSearchBackground);
|
|
|
|
searchBackground.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2016-10-11 13:57:01 +02:00
|
|
|
isLayout = true;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (AndroidUtilities.isInMultiwindow || forseMultiwindowLayout) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentBackgroundType != 1) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
setOutlineProvider((ViewOutlineProvider) outlineProvider);
|
|
|
|
setClipToOutline(true);
|
|
|
|
setElevation(AndroidUtilities.dp(2));
|
|
|
|
}
|
|
|
|
setBackgroundResource(R.drawable.smiles_popup);
|
2017-03-31 01:58:05 +02:00
|
|
|
getBackground().setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelBackground), PorterDuff.Mode.MULTIPLY));
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab.setBackgroundDrawable(null);
|
|
|
|
currentBackgroundType = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (currentBackgroundType != 0) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
setOutlineProvider(null);
|
|
|
|
setClipToOutline(false);
|
|
|
|
setElevation(0);
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
|
|
|
emojiTab.setBackgroundColor(Theme.getColor(Theme.key_chat_emojiPanelBackground));
|
2016-10-11 13:57:01 +02:00
|
|
|
currentBackgroundType = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emojiTab.getLayoutParams();
|
2015-06-29 19:12:11 +02:00
|
|
|
FrameLayout.LayoutParams layoutParams1 = null;
|
|
|
|
layoutParams.width = View.MeasureSpec.getSize(widthMeasureSpec);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickersTab != null) {
|
|
|
|
layoutParams1 = (FrameLayout.LayoutParams) stickersTab.getLayoutParams();
|
2015-07-22 20:56:37 +02:00
|
|
|
if (layoutParams1 != null) {
|
|
|
|
layoutParams1.width = layoutParams.width;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
if (layoutParams.width != oldWidth) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (stickersTab != null && layoutParams1 != null) {
|
|
|
|
onPageScrolled(pager.getCurrentItem(), layoutParams.width - getPaddingLeft() - getPaddingRight(), 0);
|
|
|
|
stickersTab.setLayoutParams(layoutParams1);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
emojiTab.setLayoutParams(layoutParams);
|
2015-06-29 19:12:11 +02:00
|
|
|
oldWidth = layoutParams.width;
|
|
|
|
}
|
|
|
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY));
|
2016-10-11 13:57:01 +02:00
|
|
|
isLayout = false;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
if (lastNotifyWidth != right - left) {
|
|
|
|
lastNotifyWidth = right - left;
|
2015-08-13 11:23:31 +02:00
|
|
|
reloadStickersAdapter();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private void reloadStickersAdapter() {
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null) {
|
|
|
|
trendingGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (stickersSearchGridAdapter != null) {
|
|
|
|
stickersSearchGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
if (StickerPreviewViewer.getInstance().isVisible()) {
|
|
|
|
StickerPreviewViewer.getInstance().close();
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
StickerPreviewViewer.getInstance().reset();
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void setListener(Listener value) {
|
|
|
|
listener = value;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setDragListener(DragListener dragListener) {
|
|
|
|
this.dragListener = dragListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChatInfo(TLRPC.ChatFull chatInfo) {
|
|
|
|
info = chatInfo;
|
|
|
|
updateStickerTabs();
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public void invalidateViews() {
|
2016-10-11 13:57:01 +02:00
|
|
|
for (int a = 0; a < emojiGrids.size(); a++) {
|
|
|
|
emojiGrids.get(a).invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setForseMultiwindowLayout(boolean value) {
|
|
|
|
forseMultiwindowLayout = value;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void onOpen(boolean forceEmoji) {
|
|
|
|
if (stickersTab != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (currentPage != 0 && currentChatId != 0) {
|
|
|
|
currentPage = 0;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (currentPage == 0 || forceEmoji) {
|
|
|
|
if (pager.getCurrentItem() == 6) {
|
|
|
|
pager.setCurrentItem(0, !forceEmoji);
|
|
|
|
}
|
|
|
|
} else if (currentPage == 1) {
|
|
|
|
if (pager.getCurrentItem() != 6) {
|
|
|
|
pager.setCurrentItem(6);
|
|
|
|
}
|
|
|
|
if (stickersTab.getCurrentPosition() == gifTabNum + 1) {
|
|
|
|
if (recentTabBum >= 0) {
|
|
|
|
stickersTab.selectTab(recentTabBum + 1);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (favTabBum >= 0) {
|
|
|
|
stickersTab.selectTab(favTabBum + 1);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (gifTabNum >= 0) {
|
|
|
|
stickersTab.selectTab(gifTabNum + 2);
|
|
|
|
} else {
|
|
|
|
stickersTab.selectTab(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (currentPage == 2) {
|
|
|
|
if (pager.getCurrentItem() != 6) {
|
|
|
|
pager.setCurrentItem(6);
|
|
|
|
}
|
|
|
|
if (stickersTab.getCurrentPosition() != gifTabNum + 1) {
|
|
|
|
if (gifTabNum >= 0 && !recentGifs.isEmpty()) {
|
|
|
|
stickersTab.selectTab(gifTabNum + 1);
|
|
|
|
} else {
|
|
|
|
switchToGifTab = true;
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
if (stickersGridAdapter != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.stickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recentImagesDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.featuredStickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.groupStickersDidLoad);
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
updateStickerTabs();
|
|
|
|
reloadStickersAdapter();
|
2016-03-06 02:49:31 +01:00
|
|
|
});
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
super.setVisibility(visibility);
|
2015-08-13 11:23:31 +02:00
|
|
|
if (visibility != GONE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
Emoji.sortEmoji();
|
2015-08-13 11:23:31 +02:00
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
if (stickersGridAdapter != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.stickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recentDocumentsDidLoad);
|
2015-08-13 11:23:31 +02:00
|
|
|
updateStickerTabs();
|
|
|
|
reloadStickersAdapter();
|
2016-01-11 18:19:48 +01:00
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE && listener != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
listener.onGifTab(pager != null && pager.getCurrentItem() >= 6);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null) {
|
|
|
|
trendingLoaded = false;
|
|
|
|
trendingGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
checkDocuments(true);
|
|
|
|
checkDocuments(false);
|
2018-07-30 04:07:02 +02:00
|
|
|
DataQuery.getInstance(currentAccount).loadRecents(DataQuery.TYPE_IMAGE, true, true, false);
|
|
|
|
DataQuery.getInstance(currentAccount).loadRecents(DataQuery.TYPE_IMAGE, false, true, false);
|
|
|
|
DataQuery.getInstance(currentAccount).loadRecents(DataQuery.TYPE_FAVE, false, true, false);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public int getCurrentPage() {
|
|
|
|
return currentPage;
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public void onDestroy() {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (stickersGridAdapter != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.emojiDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.stickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recentDocumentsDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.featuredStickersDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.groupStickersDidLoad);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
2015-10-29 18:10:07 +01:00
|
|
|
if (pickerViewPopup != null && pickerViewPopup.isShowing()) {
|
|
|
|
pickerViewPopup.dismiss();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void checkDocuments(boolean isGif) {
|
|
|
|
if (isGif) {
|
|
|
|
int previousCount = recentGifs.size();
|
2018-07-30 04:07:02 +02:00
|
|
|
recentGifs = DataQuery.getInstance(currentAccount).getRecentGifs();
|
2016-10-11 13:57:01 +02:00
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (previousCount != recentGifs.size()) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
int previousCount = recentStickers.size();
|
2017-12-08 18:35:59 +01:00
|
|
|
int previousCount2 = favouriteStickers.size();
|
2018-07-30 04:07:02 +02:00
|
|
|
recentStickers = DataQuery.getInstance(currentAccount).getRecentStickers(DataQuery.TYPE_IMAGE);
|
|
|
|
favouriteStickers = DataQuery.getInstance(currentAccount).getRecentStickers(DataQuery.TYPE_FAVE);
|
2017-12-08 18:35:59 +01:00
|
|
|
for (int a = 0; a < favouriteStickers.size(); a++) {
|
|
|
|
TLRPC.Document favSticker = favouriteStickers.get(a);
|
|
|
|
for (int b = 0; b < recentStickers.size(); b++) {
|
|
|
|
TLRPC.Document recSticker = recentStickers.get(b);
|
|
|
|
if (recSticker.dc_id == favSticker.dc_id && recSticker.id == favSticker.id) {
|
|
|
|
recentStickers.remove(b);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (previousCount != recentStickers.size() || previousCount2 != favouriteStickers.size()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
updateStickerTabs();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
checkPanels();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void setStickersBanned(boolean value, int chatId) {
|
|
|
|
if (value) {
|
|
|
|
currentChatId = chatId;
|
|
|
|
} else {
|
|
|
|
currentChatId = 0;
|
|
|
|
}
|
|
|
|
View view = pagerSlidingTabStrip.getTab(6);
|
|
|
|
if (view != null) {
|
|
|
|
view.setAlpha(currentChatId != 0 ? 0.5f : 1.0f);
|
|
|
|
if (currentChatId != 0 && pager.getCurrentItem() == 6) {
|
|
|
|
pager.setCurrentItem(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showStickerBanHint() {
|
|
|
|
if (mediaBanTooltip.getVisibility() == VISIBLE) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(currentChatId);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (chat == null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
String text;
|
|
|
|
if (!ChatObject.hasAdminRights(chat) && chat.default_banned_rights != null && chat.default_banned_rights.send_stickers) {
|
|
|
|
mediaBanTooltip.setText(LocaleController.getString("GlobalAttachStickersRestricted", R.string.GlobalAttachStickersRestricted));
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (chat.banned_rights == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (AndroidUtilities.isBannedForever(chat.banned_rights)) {
|
|
|
|
mediaBanTooltip.setText(LocaleController.getString("AttachStickersRestrictedForever", R.string.AttachStickersRestrictedForever));
|
|
|
|
} else {
|
|
|
|
mediaBanTooltip.setText(LocaleController.formatString("AttachStickersRestricted", R.string.AttachStickersRestricted, LocaleController.formatDateForBan(chat.banned_rights.until_date)));
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
mediaBanTooltip.setVisibility(View.VISIBLE);
|
|
|
|
AnimatorSet AnimatorSet = new AnimatorSet();
|
|
|
|
AnimatorSet.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(mediaBanTooltip, "alpha", 0.0f, 1.0f)
|
|
|
|
);
|
|
|
|
AnimatorSet.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
2019-01-23 18:03:33 +01:00
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (mediaBanTooltip == null) {
|
|
|
|
return;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
AnimatorSet AnimatorSet1 = new AnimatorSet();
|
|
|
|
AnimatorSet1.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(mediaBanTooltip, "alpha", 0.0f)
|
|
|
|
);
|
|
|
|
AnimatorSet1.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation1) {
|
|
|
|
if (mediaBanTooltip != null) {
|
|
|
|
mediaBanTooltip.setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AnimatorSet1.setDuration(300);
|
|
|
|
AnimatorSet1.start();
|
2017-07-08 18:32:04 +02:00
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AnimatorSet.setDuration(300);
|
|
|
|
AnimatorSet.start();
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void updateVisibleTrendingSets() {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (trendingGridAdapter == null || trendingGridAdapter == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
int count = trendingGridView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = trendingGridView.getChildAt(a);
|
|
|
|
if (child instanceof FeaturedStickerSetInfoCell) {
|
|
|
|
RecyclerListView.Holder holder = (RecyclerListView.Holder) trendingGridView.getChildViewHolder(child);
|
|
|
|
if (holder == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) child;
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<Long> unreadStickers = DataQuery.getInstance(currentAccount).getUnreadStickerSets();
|
2017-03-31 01:58:05 +02:00
|
|
|
TLRPC.StickerSetCovered stickerSetCovered = cell.getStickerSet();
|
|
|
|
boolean unread = unreadStickers != null && unreadStickers.contains(stickerSetCovered.set.id);
|
|
|
|
cell.setStickerSet(stickerSetCovered, unread);
|
|
|
|
if (unread) {
|
2018-07-30 04:07:02 +02:00
|
|
|
DataQuery.getInstance(currentAccount).markFaturedStickersByIdAsRead(stickerSetCovered.set.id);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean installing = installingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
|
|
|
boolean removing = removingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
if (installing || removing) {
|
|
|
|
if (installing && cell.isInstalled()) {
|
|
|
|
installingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
installing = false;
|
|
|
|
} else if (removing && !cell.isInstalled()) {
|
|
|
|
removingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
removing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cell.setDrawProgress(installing || removing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e(e);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public boolean areThereAnyStickers() {
|
|
|
|
return stickersGridAdapter != null && stickersGridAdapter.getItemCount() > 0;
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@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.stickersDidLoad) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if ((Integer) args[0] == DataQuery.TYPE_IMAGE) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null) {
|
|
|
|
if (trendingLoaded) {
|
|
|
|
updateVisibleTrendingSets();
|
|
|
|
} else {
|
|
|
|
trendingGridAdapter.notifyDataSetChanged();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
updateStickerTabs();
|
|
|
|
reloadStickersAdapter();
|
|
|
|
checkPanels();
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.recentDocumentsDidLoad) {
|
2016-10-11 13:57:01 +02:00
|
|
|
boolean isGif = (Boolean) args[0];
|
2017-12-08 18:35:59 +01:00
|
|
|
int type = (Integer) args[1];
|
2018-07-30 04:07:02 +02:00
|
|
|
if (isGif || type == DataQuery.TYPE_IMAGE || type == DataQuery.TYPE_FAVE) {
|
2016-10-11 13:57:01 +02:00
|
|
|
checkDocuments(isGif);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.featuredStickersDidLoad) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingGridAdapter != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (featuredStickersHash != DataQuery.getInstance(currentAccount).getFeaturesStickersHashWithoutUnread()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
trendingLoaded = false;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (trendingLoaded) {
|
|
|
|
updateVisibleTrendingSets();
|
|
|
|
} else {
|
|
|
|
trendingGridAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pagerSlidingTabStrip != null) {
|
|
|
|
int count = pagerSlidingTabStrip.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
pagerSlidingTabStrip.getChildAt(a).invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateStickerTabs();
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.groupStickersDidLoad) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (info != null && info.stickerset != null && info.stickerset.id == (Long) args[0]) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.emojiDidLoad) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (stickersGridView != null) {
|
|
|
|
int count = stickersGridView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = stickersGridView.getChildAt(a);
|
|
|
|
if (child instanceof StickerSetNameCell) {
|
|
|
|
child.invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class TrendingGridAdapter extends RecyclerListView.SelectionAdapter {
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private int stickersPerRow;
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseArray<Object> cache = new SparseArray<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
private ArrayList<TLRPC.StickerSetCovered> sets = new ArrayList<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseArray<TLRPC.StickerSetCovered> positionsToSets = new SparseArray<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
private int totalItems;
|
|
|
|
|
|
|
|
public TrendingGridAdapter(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return totalItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return cache.get(i);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
Object object = cache.get(position);
|
|
|
|
if (object != null) {
|
|
|
|
if (object instanceof TLRPC.Document) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view = null;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
view = new StickerEmojiCell(context) {
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(82), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
view = new EmptyCell(context);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
view = new FeaturedStickerSetInfoCell(context, 17);
|
2019-01-23 18:03:33 +01:00
|
|
|
((FeaturedStickerSetInfoCell) view).setAddOnClickListener(v -> {
|
|
|
|
FeaturedStickerSetInfoCell parent1 = (FeaturedStickerSetInfoCell) v.getParent();
|
|
|
|
TLRPC.StickerSetCovered pack = parent1.getStickerSet();
|
|
|
|
if (installingStickerSets.indexOfKey(pack.set.id) >= 0 || removingStickerSets.indexOfKey(pack.set.id) >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parent1.isInstalled()) {
|
|
|
|
removingStickerSets.put(pack.set.id, pack);
|
|
|
|
listener.onStickerSetRemove(parent1.getStickerSet());
|
|
|
|
} else {
|
|
|
|
installingStickerSets.put(pack.set.id, pack);
|
|
|
|
listener.onStickerSetAdd(parent1.getStickerSet());
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
parent1.setDrawProgress(true);
|
2016-10-11 13:57:01 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0:
|
|
|
|
TLRPC.Document sticker = (TLRPC.Document) cache.get(position);
|
2019-01-23 18:03:33 +01:00
|
|
|
((StickerEmojiCell) holder.itemView).setSticker(sticker, positionsToSets.get(position), false);
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
((EmptyCell) holder.itemView).setHeight(AndroidUtilities.dp(82));
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<Long> unreadStickers = DataQuery.getInstance(currentAccount).getUnreadStickerSets();
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.StickerSetCovered stickerSetCovered = sets.get((Integer) cache.get(position));
|
|
|
|
boolean unread = unreadStickers != null && unreadStickers.contains(stickerSetCovered.set.id);
|
|
|
|
FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) holder.itemView;
|
|
|
|
cell.setStickerSet(stickerSetCovered, unread);
|
|
|
|
if (unread) {
|
2018-07-30 04:07:02 +02:00
|
|
|
DataQuery.getInstance(currentAccount).markFaturedStickersByIdAsRead(stickerSetCovered.set.id);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
boolean installing = installingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
|
|
|
boolean removing = removingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (installing || removing) {
|
|
|
|
if (installing && cell.isInstalled()) {
|
|
|
|
installingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
installing = false;
|
|
|
|
} else if (removing && !cell.isInstalled()) {
|
|
|
|
removingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
removing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cell.setDrawProgress(installing || removing);
|
|
|
|
break;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
int smallSide = AndroidUtilities.displaySize.x;
|
|
|
|
int leftSide = smallSide * 35 / 100;
|
|
|
|
if (leftSide < AndroidUtilities.dp(320)) {
|
|
|
|
leftSide = AndroidUtilities.dp(320);
|
|
|
|
}
|
|
|
|
width = smallSide - leftSide;
|
|
|
|
} else {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
if (width == 0) {
|
|
|
|
width = 1080;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
stickersPerRow = Math.max(1, width / AndroidUtilities.dp(72));
|
|
|
|
trendingLayoutManager.setSpanCount(stickersPerRow);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (trendingLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
cache.clear();
|
|
|
|
positionsToSets.clear();
|
|
|
|
sets.clear();
|
|
|
|
totalItems = 0;
|
|
|
|
int num = 0;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
ArrayList<TLRPC.StickerSetCovered> packs = DataQuery.getInstance(currentAccount).getFeaturedStickerSets();
|
2016-10-11 13:57:01 +02:00
|
|
|
|
|
|
|
for (int a = 0; a < packs.size(); a++) {
|
|
|
|
TLRPC.StickerSetCovered pack = packs.get(a);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (DataQuery.getInstance(currentAccount).isStickerPackInstalled(pack.set.id) || pack.covers.isEmpty() && pack.cover == null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
continue;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
sets.add(pack);
|
|
|
|
positionsToSets.put(totalItems, pack);
|
|
|
|
cache.put(totalItems++, num++);
|
|
|
|
int startRow = totalItems / stickersPerRow;
|
|
|
|
int count;
|
|
|
|
if (!pack.covers.isEmpty()) {
|
|
|
|
count = (int) Math.ceil(pack.covers.size() / (float) stickersPerRow);
|
|
|
|
for (int b = 0; b < pack.covers.size(); b++) {
|
|
|
|
cache.put(b + totalItems, pack.covers.get(b));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
count = 1;
|
|
|
|
cache.put(totalItems, pack.cover);
|
|
|
|
}
|
|
|
|
for (int b = 0; b < count * stickersPerRow; b++) {
|
|
|
|
positionsToSets.put(totalItems + b, pack);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
totalItems += count * stickersPerRow;
|
|
|
|
}
|
|
|
|
if (totalItems != 0) {
|
|
|
|
trendingLoaded = true;
|
2018-07-30 04:07:02 +02:00
|
|
|
featuredStickersHash = DataQuery.getInstance(currentAccount).getFeaturesStickersHashWithoutUnread();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
super.notifyDataSetChanged();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class StickersGridAdapter extends RecyclerListView.SelectionAdapter {
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private Context context;
|
|
|
|
private int stickersPerRow;
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseArray<Object> rowStartPack = new SparseArray<>();
|
2017-12-08 18:35:59 +01:00
|
|
|
private HashMap<Object, Integer> packStartPosition = new HashMap<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseArray<Object> cache = new SparseArray<>();
|
2019-01-23 18:03:33 +01:00
|
|
|
private SparseArray<Object> cacheParents = new SparseArray<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseIntArray positionToRow = new SparseIntArray();
|
2015-06-29 19:12:11 +02:00
|
|
|
private int totalItems;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public StickersGridAdapter(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2015-06-29 19:12:11 +02:00
|
|
|
return totalItems != 0 ? totalItems + 1 : 0;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Object getItem(int i) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return cache.get(i);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public int getPositionForPack(Object pack) {
|
|
|
|
Integer pos = packStartPosition.get(pack);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (pos == null) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
return pos;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (position == 0) {
|
|
|
|
return 4;
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
Object object = cache.get(position);
|
|
|
|
if (object != null) {
|
|
|
|
if (object instanceof TLRPC.Document) {
|
|
|
|
return 0;
|
|
|
|
} else if (object instanceof String) {
|
|
|
|
return 3;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTabForPosition(int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (position == 0) {
|
|
|
|
position = 1;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (stickersPerRow == 0) {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
stickersPerRow = width / AndroidUtilities.dp(72);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
int row = positionToRow.get(position, Integer.MIN_VALUE);
|
|
|
|
if (row == Integer.MIN_VALUE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return stickerSets.size() - 1 + stickersTabOffset;
|
|
|
|
}
|
|
|
|
Object pack = rowStartPack.get(row);
|
|
|
|
if (pack instanceof String) {
|
|
|
|
if ("recent".equals(pack)) {
|
|
|
|
return recentTabBum;
|
|
|
|
} else {
|
|
|
|
return favTabBum;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TLRPC.TL_messages_stickerSet set = (TLRPC.TL_messages_stickerSet) pack;
|
|
|
|
int idx = stickerSets.indexOf(set);
|
|
|
|
return idx + stickersTabOffset;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view = null;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2015-06-29 19:12:11 +02:00
|
|
|
view = new StickerEmojiCell(context) {
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(82), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2015-06-29 19:12:11 +02:00
|
|
|
view = new EmptyCell(context);
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
2017-12-08 18:35:59 +01:00
|
|
|
case 2:
|
|
|
|
view = new StickerSetNameCell(context);
|
2019-01-23 18:03:33 +01:00
|
|
|
((StickerSetNameCell) view).setOnIconClickListener(v -> {
|
|
|
|
if (groupStickerSet != null) {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersGroupClick(info.id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MessagesController.getEmojiSettings(currentAccount).edit().putLong("group_hide_stickers_" + info.id, info.stickerset != null ? info.stickerset.id : 0).commit();
|
|
|
|
updateStickerTabs();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
stickersGridAdapter.notifyDataSetChanged();
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
view = new StickerSetGroupInfoCell(context);
|
2019-01-23 18:03:33 +01:00
|
|
|
((StickerSetGroupInfoCell) view).setAddOnClickListener(v -> {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersGroupClick(info.id);
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
break;
|
2018-07-30 04:07:02 +02:00
|
|
|
case 4:
|
|
|
|
view = new View(context);
|
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, searchFieldHeight));
|
|
|
|
break;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
2017-12-08 18:35:59 +01:00
|
|
|
case 0: {
|
|
|
|
TLRPC.Document sticker = (TLRPC.Document) cache.get(position);
|
|
|
|
StickerEmojiCell cell = (StickerEmojiCell) holder.itemView;
|
2019-01-23 18:03:33 +01:00
|
|
|
cell.setSticker(sticker, cacheParents.get(position), false);
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setRecent(recentStickers.contains(sticker) || favouriteStickers.contains(sticker));
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
EmptyCell cell = (EmptyCell) holder.itemView;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (position == totalItems) {
|
2018-07-30 04:07:02 +02:00
|
|
|
int row = positionToRow.get(position - 1, Integer.MIN_VALUE);
|
|
|
|
if (row == Integer.MIN_VALUE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setHeight(1);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
Object pack = rowStartPack.get(row);
|
|
|
|
if (pack instanceof TLRPC.TL_messages_stickerSet) {
|
|
|
|
documents = ((TLRPC.TL_messages_stickerSet) pack).documents;
|
|
|
|
} else if (pack instanceof String) {
|
|
|
|
if ("recent".equals(pack)) {
|
|
|
|
documents = recentStickers;
|
|
|
|
} else {
|
|
|
|
documents = favouriteStickers;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
documents = null;
|
|
|
|
}
|
|
|
|
if (documents == null) {
|
|
|
|
cell.setHeight(1);
|
|
|
|
} else {
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
cell.setHeight(AndroidUtilities.dp(8));
|
|
|
|
} else {
|
|
|
|
int height = pager.getHeight() - (int) Math.ceil(documents.size() / (float) stickersPerRow) * AndroidUtilities.dp(82);
|
|
|
|
cell.setHeight(height > 0 ? height : 1);
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setHeight(AndroidUtilities.dp(82));
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
break;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
StickerSetNameCell cell = (StickerSetNameCell) holder.itemView;
|
|
|
|
if (position == groupStickerPackPosition) {
|
|
|
|
int icon;
|
|
|
|
if (groupStickersHidden && groupStickerSet == null) {
|
|
|
|
icon = 0;
|
|
|
|
} else {
|
|
|
|
icon = groupStickerSet != null ? R.drawable.stickersclose : R.drawable.stickerset_close;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = info != null ? MessagesController.getInstance(currentAccount).getChat(info.id) : null;
|
2017-12-08 18:35:59 +01:00
|
|
|
cell.setText(LocaleController.formatString("CurrentGroupStickers", R.string.CurrentGroupStickers, chat != null ? chat.title : "Group Stickers"), icon);
|
|
|
|
} else {
|
|
|
|
Object object = cache.get(position);
|
|
|
|
if (object instanceof TLRPC.TL_messages_stickerSet) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = (TLRPC.TL_messages_stickerSet) object;
|
|
|
|
if (set.set != null) {
|
|
|
|
cell.setText(set.set.title, 0);
|
|
|
|
}
|
|
|
|
} else if (object == recentStickers) {
|
|
|
|
cell.setText(LocaleController.getString("RecentStickers", R.string.RecentStickers), 0);
|
|
|
|
} else if (object == favouriteStickers) {
|
|
|
|
cell.setText(LocaleController.getString("FavoriteStickers", R.string.FavoriteStickers), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
StickerSetGroupInfoCell cell = (StickerSetGroupInfoCell) holder.itemView;
|
|
|
|
cell.setIsLast(position == totalItems - 1);
|
|
|
|
break;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
stickersPerRow = width / AndroidUtilities.dp(72);
|
2016-10-11 13:57:01 +02:00
|
|
|
stickersLayoutManager.setSpanCount(stickersPerRow);
|
2015-06-29 19:12:11 +02:00
|
|
|
rowStartPack.clear();
|
2017-12-08 18:35:59 +01:00
|
|
|
packStartPosition.clear();
|
|
|
|
positionToRow.clear();
|
2015-06-29 19:12:11 +02:00
|
|
|
cache.clear();
|
|
|
|
totalItems = 0;
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = stickerSets;
|
2017-12-08 18:35:59 +01:00
|
|
|
int startRow = 0;
|
2018-07-30 04:07:02 +02:00
|
|
|
for (int a = -3; a < packs.size(); a++) {
|
2015-06-29 19:12:11 +02:00
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = null;
|
2019-01-23 18:03:33 +01:00
|
|
|
String key;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (a == -3) {
|
|
|
|
cache.put(totalItems++, "search");
|
|
|
|
startRow++;
|
|
|
|
continue;
|
|
|
|
} else if (a == -2) {
|
2017-12-08 18:35:59 +01:00
|
|
|
documents = favouriteStickers;
|
2019-01-23 18:03:33 +01:00
|
|
|
packStartPosition.put(key = "fav", totalItems);
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (a == -1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
documents = recentStickers;
|
2019-01-23 18:03:33 +01:00
|
|
|
packStartPosition.put(key = "recent", totalItems);
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
2019-01-23 18:03:33 +01:00
|
|
|
key = null;
|
2015-06-29 19:12:11 +02:00
|
|
|
pack = packs.get(a);
|
|
|
|
documents = pack.documents;
|
2017-12-08 18:35:59 +01:00
|
|
|
packStartPosition.put(pack, totalItems);
|
|
|
|
}
|
|
|
|
if (a == groupStickerPackNum) {
|
|
|
|
groupStickerPackPosition = totalItems;
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
rowStartPack.put(startRow, pack);
|
|
|
|
positionToRow.put(totalItems, startRow++);
|
|
|
|
rowStartPack.put(startRow, pack);
|
|
|
|
positionToRow.put(totalItems + 1, startRow++);
|
|
|
|
cache.put(totalItems++, pack);
|
|
|
|
cache.put(totalItems++, "group");
|
|
|
|
continue;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int count = (int) Math.ceil(documents.size() / (float) stickersPerRow);
|
2017-12-08 18:35:59 +01:00
|
|
|
if (pack != null) {
|
|
|
|
cache.put(totalItems, pack);
|
|
|
|
} else {
|
|
|
|
cache.put(totalItems, documents);
|
|
|
|
}
|
|
|
|
positionToRow.put(totalItems, startRow);
|
2015-06-29 19:12:11 +02:00
|
|
|
for (int b = 0; b < documents.size(); b++) {
|
2019-01-23 18:03:33 +01:00
|
|
|
int num = 1 + b + totalItems;
|
|
|
|
cache.put(num, documents.get(b));
|
|
|
|
if (pack != null) {
|
|
|
|
cacheParents.put(num, pack);
|
|
|
|
} else {
|
|
|
|
cacheParents.put(num, key);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
positionToRow.put(1 + b + totalItems, startRow + 1 + b / stickersPerRow);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
for (int b = 0; b < count + 1; b++) {
|
|
|
|
if (pack != null) {
|
|
|
|
rowStartPack.put(startRow + b, pack);
|
|
|
|
} else {
|
|
|
|
rowStartPack.put(startRow + b, a == -1 ? "recent" : "fav");
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
totalItems += count * stickersPerRow + 1;
|
|
|
|
startRow += count + 1;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private class EmojiGridAdapter extends BaseAdapter {
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private int emojiPage;
|
|
|
|
|
|
|
|
public EmojiGridAdapter(int page) {
|
|
|
|
emojiPage = page;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-10-25 17:19:00 +02:00
|
|
|
public int getCount() {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (emojiPage == -1) {
|
2017-12-08 18:35:59 +01:00
|
|
|
return Emoji.recentEmoji.size();
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
return EmojiData.dataColored[emojiPage].length;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup paramViewGroup) {
|
2015-10-29 18:10:07 +01:00
|
|
|
ImageViewEmoji imageView = (ImageViewEmoji) view;
|
2014-09-28 15:37:26 +02:00
|
|
|
if (imageView == null) {
|
2015-10-29 18:10:07 +01:00
|
|
|
imageView = new ImageViewEmoji(getContext());
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
String code;
|
|
|
|
String coloredCode;
|
2015-08-13 11:23:31 +02:00
|
|
|
if (emojiPage == -1) {
|
2017-12-08 18:35:59 +01:00
|
|
|
coloredCode = code = Emoji.recentEmoji.get(position);
|
2015-08-13 11:23:31 +02:00
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
coloredCode = code = EmojiData.dataColored[emojiPage][position];
|
2017-12-08 18:35:59 +01:00
|
|
|
String color = Emoji.emojiColor.get(code);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (color != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
coloredCode = addColorToCode(coloredCode, color);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
imageView.setImageDrawable(Emoji.getEmojiBigDrawable(coloredCode));
|
2015-08-13 11:23:31 +02:00
|
|
|
imageView.setTag(code);
|
2014-09-28 15:37:26 +02:00
|
|
|
return imageView;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private class EmojiPagesAdapter extends PagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public void destroyItem(ViewGroup viewGroup, int position, Object object) {
|
|
|
|
View view;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (position == 6) {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = stickersWrap;
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = views.get(position);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
viewGroup.removeView(view);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
@Override
|
|
|
|
public boolean canScrollToTab(int position) {
|
|
|
|
if (position == 6 && currentChatId != 0) {
|
|
|
|
showStickerBanHint();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public int getCount() {
|
2014-11-17 23:04:31 +01:00
|
|
|
return views.size();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public Drawable getPageIconDrawable(int position) {
|
|
|
|
return icons[position];
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
@Override
|
|
|
|
public void customOnDraw(Canvas canvas, int position) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (position == 6 && !DataQuery.getInstance(currentAccount).getUnreadStickerSets().isEmpty() && dotPaint != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int x = canvas.getWidth() / 2 + AndroidUtilities.dp(4 + 5);
|
|
|
|
int y = canvas.getHeight() / 2 - AndroidUtilities.dp(13 - 5);
|
|
|
|
canvas.drawCircle(x, y, AndroidUtilities.dp(5), dotPaint);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public Object instantiateItem(ViewGroup viewGroup, int position) {
|
|
|
|
View view;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (position == 6) {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = stickersWrap;
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
view = views.get(position);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
viewGroup.addView(view);
|
|
|
|
return view;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public boolean isViewFromObject(View view, Object object) {
|
|
|
|
return view == object;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2014-06-20 02:18:13 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class GifsAdapter extends RecyclerListView.SelectionAdapter {
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public GifsAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2016-10-11 13:57:01 +02:00
|
|
|
return recentGifs.size();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
|
|
ContextLinkCell view = new ContextLinkCell(mContext);
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
2016-10-11 13:57:01 +02:00
|
|
|
TLRPC.Document document = recentGifs.get(i);
|
|
|
|
if (document != null) {
|
|
|
|
((ContextLinkCell) viewHolder.itemView).setGif(document, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
private class StickersSearchGridAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
|
|
|
private Context context;
|
|
|
|
private SparseArray<Object> rowStartPack = new SparseArray<>();
|
|
|
|
private SparseArray<Object> cache = new SparseArray<>();
|
2019-01-23 18:03:33 +01:00
|
|
|
private SparseArray<Object> cacheParent = new SparseArray<>();
|
2018-07-30 04:07:02 +02:00
|
|
|
private SparseIntArray positionToRow = new SparseIntArray();
|
|
|
|
private int totalItems;
|
|
|
|
|
|
|
|
private ArrayList<TLRPC.StickerSetCovered> serverPacks = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.TL_messages_stickerSet> localPacks = new ArrayList<>();
|
|
|
|
private HashMap<TLRPC.TL_messages_stickerSet, Boolean> localPacksByShortName = new HashMap<>();
|
|
|
|
private HashMap<TLRPC.TL_messages_stickerSet, Integer> localPacksByName = new HashMap<>();
|
|
|
|
private HashMap<ArrayList<TLRPC.Document>, String> emojiStickers = new HashMap<>();
|
|
|
|
private ArrayList<ArrayList<TLRPC.Document>> emojiArrays = new ArrayList<>();
|
|
|
|
private SparseArray<TLRPC.StickerSetCovered> positionsToSets = new SparseArray<>();
|
|
|
|
|
|
|
|
private int reqId;
|
|
|
|
private int reqId2;
|
|
|
|
|
|
|
|
boolean cleared;
|
|
|
|
private String searchQuery;
|
|
|
|
private Runnable searchRunnable = new Runnable() {
|
|
|
|
|
|
|
|
private void clear() {
|
|
|
|
if (cleared) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cleared = true;
|
|
|
|
emojiStickers.clear();
|
|
|
|
emojiArrays.clear();
|
|
|
|
localPacks.clear();
|
|
|
|
serverPacks.clear();
|
|
|
|
localPacksByShortName.clear();
|
|
|
|
localPacksByName.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (TextUtils.isEmpty(searchQuery)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
progressDrawable.startAnimation();
|
|
|
|
cleared = false;
|
|
|
|
|
|
|
|
final ArrayList<TLRPC.Document> emojiStickersArray = new ArrayList<>(0);
|
|
|
|
final LongSparseArray<TLRPC.Document> emojiStickersMap = new LongSparseArray<>(0);
|
|
|
|
HashMap<String, ArrayList<TLRPC.Document>> allStickers = DataQuery.getInstance(currentAccount).getAllStickers();
|
|
|
|
if (searchQuery.length() <= 14) {
|
|
|
|
CharSequence emoji = searchQuery;
|
|
|
|
int length = emoji.length();
|
|
|
|
for (int a = 0; a < length; a++) {
|
|
|
|
if (a < length - 1 && (emoji.charAt(a) == 0xD83C && emoji.charAt(a + 1) >= 0xDFFB && emoji.charAt(a + 1) <= 0xDFFF || emoji.charAt(a) == 0x200D && (emoji.charAt(a + 1) == 0x2640 || emoji.charAt(a + 1) == 0x2642))) {
|
|
|
|
emoji = TextUtils.concat(emoji.subSequence(0, a), emoji.subSequence(a + 2, emoji.length()));
|
|
|
|
length -= 2;
|
|
|
|
a--;
|
|
|
|
} else if (emoji.charAt(a) == 0xfe0f) {
|
|
|
|
emoji = TextUtils.concat(emoji.subSequence(0, a), emoji.subSequence(a + 1, emoji.length()));
|
|
|
|
length--;
|
|
|
|
a--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ArrayList<TLRPC.Document> newStickers = allStickers != null ? allStickers.get(emoji.toString()) : null;
|
|
|
|
if (newStickers != null && !newStickers.isEmpty()) {
|
|
|
|
clear();
|
|
|
|
emojiStickersArray.addAll(newStickers);
|
|
|
|
for (int a = 0, size = newStickers.size(); a < size; a++) {
|
|
|
|
TLRPC.Document document = newStickers.get(a);
|
|
|
|
emojiStickersMap.put(document.id, document);
|
|
|
|
}
|
|
|
|
emojiStickers.put(emojiStickersArray, searchQuery);
|
|
|
|
emojiArrays.add(emojiStickersArray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allStickers != null && !allStickers.isEmpty() && searchQuery.length() > 1) {
|
|
|
|
Object[] suggestions = Emoji.getSuggestion(searchQuery.startsWith(":") ? searchQuery : ":" + searchQuery);
|
|
|
|
if (suggestions != null) {
|
|
|
|
for (int a = 0, size = Math.min(10, suggestions.length); a < size; a++) {
|
|
|
|
EmojiSuggestion suggestion = (EmojiSuggestion) suggestions[a];
|
|
|
|
suggestion.emoji = suggestion.emoji.replace("\ufe0f", "");
|
|
|
|
ArrayList<TLRPC.Document> newStickers = allStickers != null ? allStickers.get(suggestion.emoji) : null;
|
|
|
|
if (newStickers != null && !newStickers.isEmpty()) {
|
|
|
|
clear();
|
|
|
|
if (!emojiStickers.containsKey(newStickers)) {
|
|
|
|
emojiStickers.put(newStickers, suggestion.emoji);
|
|
|
|
emojiArrays.add(newStickers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> local = DataQuery.getInstance(currentAccount).getStickerSets(DataQuery.TYPE_IMAGE);
|
|
|
|
int index;
|
|
|
|
for (int a = 0, size = local.size(); a < size; a++) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = local.get(a);
|
|
|
|
if ((index = set.set.title.toLowerCase().indexOf(searchQuery)) >= 0) {
|
|
|
|
if (index == 0 || set.set.title.charAt(index - 1) == ' ') {
|
|
|
|
clear();
|
|
|
|
localPacks.add(set);
|
|
|
|
localPacksByName.put(set, index);
|
|
|
|
}
|
|
|
|
} else if (set.set.short_name != null && (index = set.set.short_name.toLowerCase().indexOf(searchQuery)) >= 0) {
|
|
|
|
if (index == 0 || set.set.short_name.charAt(index - 1) == ' ') {
|
|
|
|
clear();
|
|
|
|
localPacks.add(set);
|
|
|
|
localPacksByShortName.put(set, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
local = DataQuery.getInstance(currentAccount).getStickerSets(DataQuery.TYPE_FEATURED);
|
|
|
|
for (int a = 0, size = local.size(); a < size; a++) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = local.get(a);
|
|
|
|
if ((index = set.set.title.toLowerCase().indexOf(searchQuery)) >= 0) {
|
|
|
|
if (index == 0 || set.set.title.charAt(index - 1) == ' ') {
|
|
|
|
clear();
|
|
|
|
localPacks.add(set);
|
|
|
|
localPacksByName.put(set, index);
|
|
|
|
}
|
|
|
|
} else if (set.set.short_name != null && (index = set.set.short_name.toLowerCase().indexOf(searchQuery)) >= 0) {
|
|
|
|
if (index == 0 || set.set.short_name.charAt(index - 1) == ' ') {
|
|
|
|
clear();
|
|
|
|
localPacks.add(set);
|
|
|
|
localPacksByShortName.put(set, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((!localPacks.isEmpty() || !emojiStickers.isEmpty()) && stickersGridView.getAdapter() != stickersSearchGridAdapter) {
|
|
|
|
stickersGridView.setAdapter(stickersSearchGridAdapter);
|
|
|
|
}
|
|
|
|
final TLRPC.TL_messages_searchStickerSets req = new TLRPC.TL_messages_searchStickerSets();
|
|
|
|
req.q = searchQuery;
|
2019-01-23 18:03:33 +01:00
|
|
|
reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
|
|
|
|
if (response instanceof TLRPC.TL_messages_foundStickerSets) {
|
|
|
|
AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (req.q.equals(searchQuery)) {
|
|
|
|
clear();
|
|
|
|
progressDrawable.stopAnimation();
|
|
|
|
reqId = 0;
|
|
|
|
if (stickersGridView.getAdapter() != stickersSearchGridAdapter) {
|
|
|
|
stickersGridView.setAdapter(stickersSearchGridAdapter);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
TLRPC.TL_messages_foundStickerSets res = (TLRPC.TL_messages_foundStickerSets) response;
|
|
|
|
serverPacks.addAll(res.sets);
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
});
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Emoji.isValidEmoji(searchQuery)) {
|
|
|
|
final TLRPC.TL_messages_getStickers req2 = new TLRPC.TL_messages_getStickers();
|
|
|
|
req2.emoticon = searchQuery;
|
|
|
|
req2.hash = 0;
|
2019-01-23 18:03:33 +01:00
|
|
|
reqId2 = ConnectionsManager.getInstance(currentAccount).sendRequest(req2, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
|
|
|
if (req2.emoticon.equals(searchQuery)) {
|
|
|
|
reqId2 = 0;
|
|
|
|
if (!(response instanceof TLRPC.TL_messages_stickers)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.TL_messages_stickers res = (TLRPC.TL_messages_stickers) response;
|
|
|
|
int oldCount = emojiStickersArray.size();
|
|
|
|
for (int a = 0, size = res.stickers.size(); a < size; a++) {
|
|
|
|
TLRPC.Document document = res.stickers.get(a);
|
|
|
|
if (emojiStickersMap.indexOfKey(document.id) >= 0) {
|
|
|
|
continue;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
emojiStickersArray.add(document);
|
|
|
|
}
|
|
|
|
int newCount = emojiStickersArray.size();
|
|
|
|
if (oldCount != newCount) {
|
|
|
|
emojiStickers.put(emojiStickersArray, searchQuery);
|
|
|
|
if (oldCount == 0) {
|
|
|
|
emojiArrays.add(emojiStickersArray);
|
|
|
|
}
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
}));
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public StickersSearchGridAdapter(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
if (totalItems != 1) {
|
|
|
|
return totalItems + 1;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return cache.get(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void search(String text) {
|
|
|
|
if (reqId != 0) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
|
|
|
|
reqId = 0;
|
|
|
|
}
|
|
|
|
if (reqId2 != 0) {
|
|
|
|
ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId2, true);
|
|
|
|
reqId2 = 0;
|
|
|
|
}
|
|
|
|
if (TextUtils.isEmpty(text)) {
|
|
|
|
searchQuery = null;
|
|
|
|
localPacks.clear();
|
|
|
|
emojiStickers.clear();
|
|
|
|
serverPacks.clear();
|
|
|
|
if (stickersGridView.getAdapter() != stickersGridAdapter) {
|
|
|
|
stickersGridView.setAdapter(stickersGridAdapter);
|
|
|
|
}
|
|
|
|
notifyDataSetChanged();
|
|
|
|
} else {
|
|
|
|
searchQuery = text.toLowerCase();
|
|
|
|
}
|
|
|
|
AndroidUtilities.cancelRunOnUIThread(searchRunnable);
|
|
|
|
AndroidUtilities.runOnUIThread(searchRunnable, 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (position == 0) {
|
|
|
|
return 4;
|
|
|
|
} else if (position == 1 && totalItems == 1) {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
Object object = cache.get(position);
|
|
|
|
if (object != null) {
|
|
|
|
if (object instanceof TLRPC.Document) {
|
|
|
|
return 0;
|
|
|
|
} else if (object instanceof TLRPC.StickerSetCovered) {
|
|
|
|
return 3;
|
|
|
|
} else {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view = null;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
|
|
|
view = new StickerEmojiCell(context) {
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(82), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
view = new EmptyCell(context);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
view = new StickerSetNameCell(context);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
view = new FeaturedStickerSetInfoCell(context, 17);
|
2019-01-23 18:03:33 +01:00
|
|
|
((FeaturedStickerSetInfoCell) view).setAddOnClickListener(v -> {
|
|
|
|
FeaturedStickerSetInfoCell parent1 = (FeaturedStickerSetInfoCell) v.getParent();
|
|
|
|
TLRPC.StickerSetCovered pack = parent1.getStickerSet();
|
|
|
|
if (installingStickerSets.indexOfKey(pack.set.id) >= 0 || removingStickerSets.indexOfKey(pack.set.id) >= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (parent1.isInstalled()) {
|
|
|
|
removingStickerSets.put(pack.set.id, pack);
|
|
|
|
listener.onStickerSetRemove(parent1.getStickerSet());
|
|
|
|
} else {
|
|
|
|
installingStickerSets.put(pack.set.id, pack);
|
|
|
|
listener.onStickerSetAdd(parent1.getStickerSet());
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
parent1.setDrawProgress(true);
|
2018-07-30 04:07:02 +02:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
view = new View(context);
|
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, searchFieldHeight));
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
FrameLayout frameLayout = new FrameLayout(context) {
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int height = stickersGridView.getMeasuredHeight();
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) ((height - searchFieldHeight - AndroidUtilities.dp(8)) / 3 * 1.7f), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ImageView imageView = new ImageView(context);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
imageView.setImageResource(R.drawable.stickers_none);
|
|
|
|
imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_emojiPanelEmptyText), PorterDuff.Mode.MULTIPLY));
|
|
|
|
frameLayout.addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 0, 0, 48));
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("NoStickersFound", R.string.NoStickersFound));
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
|
|
|
|
textView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelEmptyText));
|
|
|
|
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 30, 0, 0));
|
|
|
|
|
|
|
|
view = frameLayout;
|
|
|
|
view.setLayoutParams(new RecyclerView.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0: {
|
|
|
|
TLRPC.Document sticker = (TLRPC.Document) cache.get(position);
|
|
|
|
StickerEmojiCell cell = (StickerEmojiCell) holder.itemView;
|
2019-01-23 18:03:33 +01:00
|
|
|
cell.setSticker(sticker, cacheParent.get(position), false);
|
2018-07-30 04:07:02 +02:00
|
|
|
cell.setRecent(recentStickers.contains(sticker) || favouriteStickers.contains(sticker));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1: {
|
|
|
|
EmptyCell cell = (EmptyCell) holder.itemView;
|
|
|
|
if (position == totalItems) {
|
|
|
|
int row = positionToRow.get(position - 1, Integer.MIN_VALUE);
|
|
|
|
if (row == Integer.MIN_VALUE) {
|
|
|
|
cell.setHeight(1);
|
|
|
|
} else {
|
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
Object pack = rowStartPack.get(row);
|
|
|
|
if (pack instanceof TLRPC.TL_messages_stickerSet) {
|
|
|
|
documents = ((TLRPC.TL_messages_stickerSet) pack).documents;
|
|
|
|
} else if (pack instanceof ArrayList) {
|
|
|
|
documents = (ArrayList<TLRPC.Document>) pack;
|
|
|
|
} else {
|
|
|
|
documents = null;
|
|
|
|
}
|
|
|
|
if (documents == null) {
|
|
|
|
cell.setHeight(1);
|
|
|
|
} else {
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
cell.setHeight(AndroidUtilities.dp(8));
|
|
|
|
} else {
|
|
|
|
int height = pager.getHeight() - (int) Math.ceil(documents.size() / (float) stickersGridAdapter.stickersPerRow) * AndroidUtilities.dp(82);
|
|
|
|
cell.setHeight(height > 0 ? height : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cell.setHeight(AndroidUtilities.dp(82));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2: {
|
|
|
|
StickerSetNameCell cell = (StickerSetNameCell) holder.itemView;
|
|
|
|
Object object = cache.get(position);
|
|
|
|
if (object instanceof TLRPC.TL_messages_stickerSet) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = (TLRPC.TL_messages_stickerSet) object;
|
|
|
|
if (!TextUtils.isEmpty(searchQuery) && localPacksByShortName.containsKey(set)) {
|
|
|
|
if (set.set != null) {
|
|
|
|
cell.setText(set.set.title, 0);
|
|
|
|
}
|
|
|
|
cell.setUrl(set.set.short_name, searchQuery.length());
|
|
|
|
} else {
|
|
|
|
Integer start = localPacksByName.get(set);
|
|
|
|
if (set.set != null && start != null) {
|
|
|
|
cell.setText(set.set.title, 0, start, !TextUtils.isEmpty(searchQuery) ? searchQuery.length() : 0);
|
|
|
|
}
|
|
|
|
cell.setUrl(null, 0);
|
|
|
|
}
|
|
|
|
} else if (object instanceof ArrayList) {
|
|
|
|
cell.setText(emojiStickers.get(object), 0);
|
|
|
|
cell.setUrl(null, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3: {
|
|
|
|
TLRPC.StickerSetCovered stickerSetCovered = (TLRPC.StickerSetCovered) cache.get(position);
|
|
|
|
FeaturedStickerSetInfoCell cell = (FeaturedStickerSetInfoCell) holder.itemView;
|
|
|
|
boolean installing = installingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
|
|
|
boolean removing = removingStickerSets.indexOfKey(stickerSetCovered.set.id) >= 0;
|
|
|
|
if (installing || removing) {
|
|
|
|
if (installing && cell.isInstalled()) {
|
|
|
|
installingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
installing = false;
|
|
|
|
} else if (removing && !cell.isInstalled()) {
|
|
|
|
removingStickerSets.remove(stickerSetCovered.set.id);
|
|
|
|
removing = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cell.setDrawProgress(installing || removing);
|
|
|
|
int idx = TextUtils.isEmpty(searchQuery) ? -1 : stickerSetCovered.set.title.toLowerCase().indexOf(searchQuery);
|
|
|
|
if (idx >= 0) {
|
|
|
|
cell.setStickerSet(stickerSetCovered, false, idx, searchQuery.length());
|
|
|
|
} else {
|
|
|
|
cell.setStickerSet(stickerSetCovered, false);
|
|
|
|
if (!TextUtils.isEmpty(searchQuery) && stickerSetCovered.set.short_name.toLowerCase().startsWith(searchQuery)) {
|
|
|
|
cell.setUrl(stickerSetCovered.set.short_name, searchQuery.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyDataSetChanged() {
|
|
|
|
rowStartPack.clear();
|
|
|
|
positionToRow.clear();
|
|
|
|
cache.clear();
|
|
|
|
positionsToSets.clear();
|
|
|
|
totalItems = 0;
|
|
|
|
int startRow = 0;
|
|
|
|
for (int a = -1, serverSize = serverPacks.size(), localSize = localPacks.size(), emojiSize = emojiArrays.size(); a < serverSize + localSize + emojiSize; a++) {
|
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
Object pack = null;
|
2019-01-23 18:03:33 +01:00
|
|
|
String key;
|
2018-07-30 04:07:02 +02:00
|
|
|
if (a == -1) {
|
|
|
|
cache.put(totalItems++, "search");
|
|
|
|
startRow++;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
int idx = a;
|
|
|
|
if (idx < localSize) {
|
|
|
|
TLRPC.TL_messages_stickerSet set = localPacks.get(idx);
|
|
|
|
documents = set.documents;
|
|
|
|
pack = set;
|
|
|
|
} else {
|
|
|
|
idx -= localSize;
|
|
|
|
if (idx < emojiSize) {
|
|
|
|
documents = emojiArrays.get(idx);
|
|
|
|
} else {
|
|
|
|
idx -= emojiSize;
|
|
|
|
TLRPC.StickerSetCovered set = serverPacks.get(idx);
|
|
|
|
documents = set.covers;
|
|
|
|
pack = set;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int count = (int) Math.ceil(documents.size() / (float) stickersGridAdapter.stickersPerRow);
|
|
|
|
if (pack != null) {
|
|
|
|
cache.put(totalItems, pack);
|
|
|
|
} else {
|
|
|
|
cache.put(totalItems, documents);
|
|
|
|
}
|
|
|
|
if (a >= localSize && pack instanceof TLRPC.StickerSetCovered) {
|
|
|
|
positionsToSets.put(totalItems, (TLRPC.StickerSetCovered) pack);
|
|
|
|
}
|
|
|
|
positionToRow.put(totalItems, startRow);
|
|
|
|
for (int b = 0, size = documents.size(); b < size; b++) {
|
2019-01-23 18:03:33 +01:00
|
|
|
int num = 1 + b + totalItems;
|
|
|
|
cache.put(num, documents.get(b));
|
|
|
|
if (pack != null) {
|
|
|
|
cacheParent.put(num, pack);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
positionToRow.put(1 + b + totalItems, startRow + 1 + b / stickersGridAdapter.stickersPerRow);
|
|
|
|
if (a >= localSize && pack instanceof TLRPC.StickerSetCovered) {
|
|
|
|
positionsToSets.put(1 + b + totalItems, (TLRPC.StickerSetCovered) pack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int b = 0; b < count + 1; b++) {
|
|
|
|
if (pack != null) {
|
|
|
|
rowStartPack.put(startRow + b, pack);
|
|
|
|
} else {
|
|
|
|
rowStartPack.put(startRow + b, documents);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalItems += count * stickersGridAdapter.stickersPerRow + 1;
|
|
|
|
startRow += count + 1;
|
|
|
|
}
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|