2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.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).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
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
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.app.Activity;
|
2016-01-11 18:19:48 +01:00
|
|
|
import android.app.AlertDialog;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.content.Context;
|
2016-01-11 18:19:48 +01:00
|
|
|
import android.content.DialogInterface;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.content.SharedPreferences;
|
2014-06-20 02:18:13 +02:00
|
|
|
import android.database.DataSetObserver;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.RectF;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2015-06-29 19:12:11 +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;
|
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;
|
2013-10-25 17:19:00 +02:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-10-29 18:10:07 +01:00
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.widget.AbsListView;
|
2015-08-13 11:23:31 +02:00
|
|
|
import android.widget.AdapterView;
|
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;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ViewProxy;
|
|
|
|
import org.telegram.messenger.Emoji;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.messenger.EmojiData;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.query.StickersQuery;
|
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;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
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;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Cells.StickerEmojiCell;
|
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.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
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);
|
|
|
|
void onStickerSelected(TLRPC.Document sticker);
|
2015-12-09 19:27:52 +01:00
|
|
|
void onStickersSettingsClick();
|
2016-01-11 18:19:48 +01:00
|
|
|
void onGifSelected(TLRPC.Document gif);
|
|
|
|
void onGifTab(boolean opened);
|
|
|
|
void onStickersTab(boolean opened);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +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;
|
|
|
|
}
|
|
|
|
private static final ViewTreeObserver.OnScrollChangedListener NOP = new ViewTreeObserver.OnScrollChangedListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollChanged() {
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View view) {
|
|
|
|
sendEmoji(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setOnLongClickListener(new OnLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
String code = (String) view.getTag();
|
|
|
|
if (EmojiData.emojiColoredMap.containsKey(code)) {
|
|
|
|
touched = true;
|
|
|
|
touchedX = lastX;
|
|
|
|
touchedY = lastY;
|
|
|
|
|
|
|
|
String color = emojiColor.get(code);
|
|
|
|
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(code, 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;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setBackgroundResource(R.drawable.list_selector);
|
|
|
|
setScaleType(ImageView.ScaleType.CENTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendEmoji(String override) {
|
|
|
|
String code = override != null ? override : (String) getTag();
|
|
|
|
if (override == null) {
|
|
|
|
if (pager.getCurrentItem() != 0) {
|
|
|
|
String color = emojiColor.get(code);
|
|
|
|
if (color != null) {
|
|
|
|
code += color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Integer count = emojiUseHistory.get(code);
|
|
|
|
if (count == null) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
if (count == 0 && emojiUseHistory.size() > 50) {
|
|
|
|
for (int a = recentEmoji.size() - 1; a >= 0; a--) {
|
|
|
|
String emoji = recentEmoji.get(a);
|
|
|
|
emojiUseHistory.remove(emoji);
|
|
|
|
recentEmoji.remove(a);
|
|
|
|
if (emojiUseHistory.size() <= 50) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
emojiUseHistory.put(code, ++count);
|
|
|
|
if (pager.getCurrentItem() != 0) {
|
|
|
|
sortEmoji();
|
|
|
|
}
|
|
|
|
saveRecentEmoji();
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
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) {
|
|
|
|
emojiColor.put(code, color);
|
|
|
|
code += color;
|
|
|
|
} else {
|
|
|
|
emojiColor.remove(code);
|
|
|
|
}
|
|
|
|
setImageDrawable(Emoji.getEmojiBigDrawable(code));
|
|
|
|
sendEmoji(null);
|
|
|
|
saveEmojiColors();
|
|
|
|
} else {
|
|
|
|
sendEmoji(code + (color != null ? color : ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
code += "\uD83C";
|
|
|
|
switch (a) {
|
|
|
|
case 1:
|
|
|
|
code += "\uDFFB";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
code += "\uDFFC";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
code += "\uDFFD";
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
code += "\uDFFE";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
code += "\uDFFF";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Drawable drawable = Emoji.getEmojiBigDrawable(code);
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setBounds(x, y, x + emojiSize, y + emojiSize);
|
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
private ArrayList<EmojiGridAdapter> adapters = new ArrayList<>();
|
2015-10-29 18:10:07 +01:00
|
|
|
private HashMap<String, Integer> emojiUseHistory = new HashMap<>();
|
|
|
|
private static HashMap<String, String> emojiColor = new HashMap<>();
|
|
|
|
private ArrayList<String> recentEmoji = new ArrayList<>();
|
2016-03-06 02:49:31 +01:00
|
|
|
private ArrayList<Long> newRecentStickers = new ArrayList<>();
|
2015-06-29 19:12:11 +02:00
|
|
|
private ArrayList<TLRPC.Document> recentStickers = new ArrayList<>();
|
|
|
|
private ArrayList<TLRPC.TL_messages_stickerSet> stickerSets = new ArrayList<>();
|
2016-01-11 18:19:48 +01:00
|
|
|
private ArrayList<MediaController.SearchImage> recentImages;
|
|
|
|
private boolean loadingRecent;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private int[] icons = {
|
|
|
|
R.drawable.ic_emoji_recent,
|
|
|
|
R.drawable.ic_emoji_smile,
|
|
|
|
R.drawable.ic_emoji_flower,
|
|
|
|
R.drawable.ic_emoji_bell,
|
|
|
|
R.drawable.ic_emoji_car,
|
2015-05-03 13:48:36 +02:00
|
|
|
R.drawable.ic_emoji_symbol,
|
|
|
|
R.drawable.ic_emoji_sticker};
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
private Listener listener;
|
|
|
|
private ViewPager pager;
|
|
|
|
private FrameLayout recentsWrap;
|
2015-06-29 19:12:11 +02:00
|
|
|
private FrameLayout stickersWrap;
|
2015-04-09 20:00:14 +02:00
|
|
|
private ArrayList<GridView> views = new ArrayList<>();
|
2015-05-03 13:48:36 +02:00
|
|
|
private ImageView backspaceButton;
|
2015-06-29 19:12:11 +02:00
|
|
|
private StickersGridAdapter stickersGridAdapter;
|
|
|
|
private LinearLayout pagerSlidingTabStripContainer;
|
|
|
|
private ScrollSlidingTabStrip scrollSlidingTabStrip;
|
2015-08-13 11:23:31 +02:00
|
|
|
private GridView stickersGridView;
|
2016-01-11 18:19:48 +01:00
|
|
|
private TextView stickersEmptyView;
|
|
|
|
private RecyclerListView gifsGridView;
|
|
|
|
private FlowLayoutManager flowLayoutManager;
|
|
|
|
private GifsAdapter gifsAdapter;
|
2015-08-13 11:23:31 +02:00
|
|
|
private AdapterView.OnItemClickListener stickersOnItemClickListener;
|
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;
|
|
|
|
private int gifTabBum = -2;
|
|
|
|
private boolean switchToGifTab;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
2016-03-06 02:49:31 +01: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;
|
2015-05-21 23:27:27 +02:00
|
|
|
private boolean showStickers;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean showGifs;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean loadingRecentGifs;
|
|
|
|
private long lastGifLoadTime;
|
|
|
|
|
|
|
|
public EmojiView(boolean needStickers, boolean needGif, final Context context) {
|
2015-05-03 13:48:36 +02:00
|
|
|
super(context);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
showStickers = needStickers;
|
2016-01-11 18:19:48 +01:00
|
|
|
showGifs = needGif;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
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);
|
|
|
|
views.add(gridView);
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(i - 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
gridView.setAdapter(emojiGridAdapter);
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7);
|
|
|
|
adapters.add(emojiGridAdapter);
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (showStickers) {
|
|
|
|
StickersQuery.checkStickers();
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersGridView = new GridView(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
2016-03-06 02:49:31 +01:00
|
|
|
boolean result = StickerPreviewViewer.getInstance().onInterceptTouchEvent(event, stickersGridView, EmojiView.this.getMeasuredHeight());
|
|
|
|
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) {
|
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
super.setVisibility(GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
};
|
|
|
|
stickersGridView.setSelector(R.drawable.transparent);
|
|
|
|
stickersGridView.setColumnWidth(AndroidUtilities.dp(72));
|
|
|
|
stickersGridView.setNumColumns(-1);
|
|
|
|
stickersGridView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
|
|
|
|
stickersGridView.setClipToPadding(false);
|
|
|
|
views.add(stickersGridView);
|
2015-05-03 13:48:36 +02:00
|
|
|
stickersGridAdapter = new StickersGridAdapter(context);
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersGridView.setAdapter(stickersGridAdapter);
|
|
|
|
stickersGridView.setOnTouchListener(new OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
2016-03-06 02:49:31 +01:00
|
|
|
return StickerPreviewViewer.getInstance().onTouch(event, stickersGridView, EmojiView.this.getMeasuredHeight(), stickersOnItemClickListener);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
stickersOnItemClickListener = new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long i) {
|
|
|
|
if (!(view instanceof StickerEmojiCell)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
StickerPreviewViewer.getInstance().reset();
|
2015-08-13 11:23:31 +02:00
|
|
|
StickerEmojiCell cell = (StickerEmojiCell) view;
|
|
|
|
if (cell.isDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cell.disable();
|
|
|
|
TLRPC.Document document = cell.getSticker();
|
2016-03-06 02:49:31 +01:00
|
|
|
int index = newRecentStickers.indexOf(document.id);
|
|
|
|
if (index == -1) {
|
|
|
|
newRecentStickers.add(0, document.id);
|
|
|
|
if (newRecentStickers.size() > 20) {
|
|
|
|
newRecentStickers.remove(newRecentStickers.size() - 1);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (index != 0) {
|
|
|
|
newRecentStickers.remove(index);
|
|
|
|
newRecentStickers.add(0, document.id);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
saveRecentStickers();
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickerSelected(document);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
stickersGridView.setOnItemClickListener(stickersOnItemClickListener);
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(stickersGridView, 0xfff5f6f7);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
stickersWrap = new FrameLayout(context);
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersWrap.addView(stickersGridView);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
if (needGif) {
|
|
|
|
gifsGridView = new RecyclerListView(context);
|
|
|
|
gifsGridView.setLayoutManager(flowLayoutManager = new FlowLayoutManager() {
|
|
|
|
|
|
|
|
private Size size = new Size();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Size getSizeForItem(int i) {
|
|
|
|
TLRPC.Document document = recentImages.get(i).document;
|
|
|
|
size.width = document.thumb != null && document.thumb.w != 0 ? document.thumb.w : 100;
|
|
|
|
size.height = document.thumb != null && document.thumb.h != 0 ? document.thumb.h : 100;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Build.VERSION.SDK_INT >= 9) {
|
|
|
|
gifsGridView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
|
|
|
|
}
|
|
|
|
gifsGridView.setAdapter(gifsAdapter = new GifsAdapter(context));
|
|
|
|
gifsGridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(View view, int position) {
|
|
|
|
if (position < 0 || position >= recentImages.size() || listener == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.Document document = recentImages.get(position).document;
|
|
|
|
listener.onStickerSelected(document);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
gifsGridView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemClick(View view, int position) {
|
|
|
|
if (position < 0 || position >= recentImages.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final MediaController.SearchImage searchImage = recentImages.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(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
recentImages.remove(searchImage);
|
|
|
|
TLRPC.TL_messages_saveGif req = new TLRPC.TL_messages_saveGif();
|
|
|
|
req.id = new TLRPC.TL_inputDocument();
|
|
|
|
req.id.id = searchImage.document.id;
|
|
|
|
req.id.access_hash = searchImage.document.access_hash;
|
|
|
|
req.unsave = true;
|
|
|
|
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
|
|
|
@Override
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
MessagesStorage.getInstance().removeWebRecent(searchImage);
|
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (recentImages.isEmpty()) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2016-03-06 02:49:31 +01:00
|
|
|
builder.show().setCanceledOnTouchOutside(true);
|
2016-01-11 18:19:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
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);
|
|
|
|
stickersEmptyView.setTextColor(0xff888888);
|
|
|
|
stickersWrap.addView(stickersEmptyView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
|
|
|
stickersGridView.setEmptyView(stickersEmptyView);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) {
|
|
|
|
|
|
|
|
boolean startedScroll;
|
|
|
|
float lastX;
|
|
|
|
float lastTranslateX;
|
|
|
|
boolean first = true;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
lastX = ev.getX();
|
|
|
|
}
|
|
|
|
float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip);
|
|
|
|
if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) {
|
|
|
|
if (!startedScroll && lastX - ev.getX() < 0) {
|
|
|
|
if (pager.beginFakeDrag()) {
|
|
|
|
startedScroll = true;
|
|
|
|
lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip);
|
|
|
|
}
|
|
|
|
} else if (startedScroll && lastX - ev.getX() > 0) {
|
|
|
|
if (pager.isFakeDragging()) {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (startedScroll) {
|
|
|
|
int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX);
|
|
|
|
try {
|
|
|
|
pager.fakeDragBy(dx);
|
|
|
|
lastTranslateX = newTranslationX;
|
|
|
|
} catch (Exception e) {
|
|
|
|
try {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
} catch (Exception e2) {
|
|
|
|
//don't promt
|
|
|
|
}
|
|
|
|
startedScroll = false;
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastX = ev.getX();
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
first = true;
|
|
|
|
if (startedScroll) {
|
|
|
|
pager.endFakeDrag();
|
|
|
|
startedScroll = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return startedScroll || super.onTouchEvent(ev);
|
|
|
|
}
|
|
|
|
return super.onTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
|
|
|
|
scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7);
|
|
|
|
scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
|
2015-07-22 20:56:37 +02:00
|
|
|
scrollSlidingTabStrip.setVisibility(INVISIBLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));
|
|
|
|
ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x);
|
|
|
|
updateStickerTabs();
|
|
|
|
scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() {
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int page) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (gifsGridView != null) {
|
|
|
|
if (page == gifTabBum + 1) {
|
|
|
|
if (gifsGridView.getVisibility() != VISIBLE) {
|
|
|
|
listener.onGifTab(true);
|
|
|
|
showGifTab();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
listener.onGifTab(false);
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getCount() != 0 ? GONE : VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (page == 0) {
|
|
|
|
pager.setCurrentItem(0);
|
|
|
|
return;
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
if (page == gifTabBum + 1) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (page == recentTabBum + 1) {
|
|
|
|
views.get(6).setSelection(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
int index = page - 1 - stickersTabOffset;
|
2015-12-09 19:27:52 +01:00
|
|
|
if (index == stickerSets.size()) {
|
|
|
|
if (listener != null) {
|
|
|
|
listener.onStickersSettingsClick();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if (index >= stickerSets.size()) {
|
|
|
|
index = stickerSets.size() - 1;
|
|
|
|
}
|
|
|
|
views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index)));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
stickersGridView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
2016-01-11 18:19:48 +01:00
|
|
|
checkStickersScroll(firstVisibleItem);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setBackgroundColor(0xfff5f6f7);
|
2013-10-25 17:19:00 +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());
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStripContainer = new LinearLayout(context) {
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
if (getParent() != null) {
|
|
|
|
getParent().requestDisallowInterceptTouchEvent(true);
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(ev);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7);
|
|
|
|
addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48));
|
|
|
|
|
|
|
|
PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context);
|
|
|
|
pagerSlidingTabStrip.setViewPager(pager);
|
|
|
|
pagerSlidingTabStrip.setShouldExpand(true);
|
|
|
|
pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2));
|
|
|
|
pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1));
|
|
|
|
pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2);
|
|
|
|
pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7);
|
|
|
|
pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f));
|
|
|
|
pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageSelected(int position) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
2015-06-29 19:12:11 +02:00
|
|
|
pagerSlidingTabStripContainer.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);
|
|
|
|
backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace);
|
|
|
|
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
|
|
|
|
|
|
|
View view = new View(context);
|
|
|
|
view.setBackgroundColor(0xffe2e5e7);
|
2015-06-29 19:12:11 +02:00
|
|
|
frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
recentsWrap = new FrameLayout(context);
|
|
|
|
recentsWrap.addView(views.get(0));
|
|
|
|
|
|
|
|
TextView textView = new TextView(context);
|
|
|
|
textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
|
|
|
|
textView.setTextSize(18);
|
|
|
|
textView.setTextColor(0xff888888);
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
recentsWrap.addView(textView);
|
|
|
|
views.get(0).setEmptyView(textView);
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
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);
|
|
|
|
pickerViewPopup.getContentView().setOnKeyListener(new OnKeyListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && pickerViewPopup != null && pickerViewPopup.isShowing()) {
|
|
|
|
pickerViewPopup.dismiss();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
loadRecents();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private void showGifTab() {
|
|
|
|
gifsGridView.setVisibility(VISIBLE);
|
|
|
|
stickersGridView.setVisibility(GONE);
|
|
|
|
stickersEmptyView.setVisibility(GONE);
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(gifTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkStickersScroll(int firstVisibleItem) {
|
|
|
|
if (stickersGridView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (stickersGridView.getVisibility() != VISIBLE) {
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(gifTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = stickersGridView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = stickersGridView.getChildAt(a);
|
|
|
|
if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) {
|
|
|
|
firstVisibleItem++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private void onPageScrolled(int position, int width, int positionOffsetPixels) {
|
|
|
|
if (scrollSlidingTabStrip == null) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (ViewProxy.getTranslationX(pagerSlidingTabStripContainer) != margin) {
|
|
|
|
ViewProxy.setTranslationX(pagerSlidingTabStripContainer, margin);
|
|
|
|
ViewProxy.setTranslationX(scrollSlidingTabStrip, width + margin);
|
2015-07-22 20:56:37 +02:00
|
|
|
scrollSlidingTabStrip.setVisibility(margin < 0 ? VISIBLE : INVISIBLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
if (margin <= -width) {
|
|
|
|
pagerSlidingTabStripContainer.clearAnimation();
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(GONE);
|
|
|
|
} else {
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (Build.VERSION.SDK_INT < 11 && pagerSlidingTabStripContainer.getVisibility() == GONE) {
|
|
|
|
pagerSlidingTabStripContainer.clearAnimation();
|
|
|
|
pagerSlidingTabStripContainer.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private void postBackspaceRunnable(final int time) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (!backspacePressed) {
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
backspaceOnce = true;
|
|
|
|
postBackspaceRunnable(Math.max(50, time - 100));
|
|
|
|
}
|
|
|
|
}, time);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private String convert(long paramLong) {
|
|
|
|
String str = "";
|
|
|
|
for (int i = 0; ; i++) {
|
|
|
|
if (i >= 4) {
|
|
|
|
return str;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
int j = (int) (0xFFFF & paramLong >> 16 * (3 - i));
|
2013-10-25 17:19:00 +02:00
|
|
|
if (j != 0) {
|
2015-05-03 13:48:36 +02:00
|
|
|
str = str + (char) j;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private void saveRecentEmoji() {
|
|
|
|
SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
2015-10-29 18:10:07 +01:00
|
|
|
for (HashMap.Entry<String, Integer> entry : emojiUseHistory.entrySet()) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (stringBuilder.length() != 0) {
|
|
|
|
stringBuilder.append(",");
|
|
|
|
}
|
|
|
|
stringBuilder.append(entry.getKey());
|
|
|
|
stringBuilder.append("=");
|
|
|
|
stringBuilder.append(entry.getValue());
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
preferences.edit().putString("emojis2", stringBuilder.toString()).commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void saveEmojiColors() {
|
|
|
|
SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
for (HashMap.Entry<String, String> entry : emojiColor.entrySet()) {
|
|
|
|
if (stringBuilder.length() != 0) {
|
|
|
|
stringBuilder.append(",");
|
|
|
|
}
|
|
|
|
stringBuilder.append(entry.getKey());
|
|
|
|
stringBuilder.append("=");
|
|
|
|
stringBuilder.append(entry.getValue());
|
|
|
|
}
|
|
|
|
preferences.edit().putString("color", stringBuilder.toString()).commit();
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void saveRecentStickers() {
|
2015-08-13 11:23:31 +02:00
|
|
|
SharedPreferences.Editor editor = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).edit();
|
2015-05-21 23:27:27 +02:00
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < newRecentStickers.size(); a++) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (stringBuilder.length() != 0) {
|
|
|
|
stringBuilder.append(",");
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
stringBuilder.append(newRecentStickers.get(a));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
editor.putString("stickers2", stringBuilder.toString());
|
2015-08-13 11:23:31 +02:00
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public void switchToGifRecent() {
|
|
|
|
pager.setCurrentItem(6);
|
|
|
|
if (gifTabBum >= 0 && !recentImages.isEmpty()) {
|
|
|
|
scrollSlidingTabStrip.selectTab(gifTabBum + 1);
|
|
|
|
} else {
|
|
|
|
switchToGifTab = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private void sortEmoji() {
|
|
|
|
recentEmoji.clear();
|
2015-10-29 18:10:07 +01:00
|
|
|
for (HashMap.Entry<String, Integer> entry : emojiUseHistory.entrySet()) {
|
2015-08-13 11:23:31 +02:00
|
|
|
recentEmoji.add(entry.getKey());
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
Collections.sort(recentEmoji, new Comparator<String>() {
|
2015-08-13 11:23:31 +02:00
|
|
|
@Override
|
2015-10-29 18:10:07 +01:00
|
|
|
public int compare(String lhs, String rhs) {
|
2015-08-13 11:23:31 +02:00
|
|
|
Integer count1 = emojiUseHistory.get(lhs);
|
|
|
|
Integer count2 = emojiUseHistory.get(rhs);
|
|
|
|
if (count1 == null) {
|
|
|
|
count1 = 0;
|
|
|
|
}
|
|
|
|
if (count2 == null) {
|
|
|
|
count2 = 0;
|
|
|
|
}
|
|
|
|
if (count1 > count2) {
|
|
|
|
return -1;
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
while (recentEmoji.size() > 50) {
|
|
|
|
recentEmoji.remove(recentEmoji.size() - 1);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private void sortStickers() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (StickersQuery.getStickerSets().isEmpty()) {
|
|
|
|
recentStickers.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
recentStickers.clear();
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < newRecentStickers.size(); a++) {
|
|
|
|
TLRPC.Document sticker = StickersQuery.getStickerById(newRecentStickers.get(a));
|
2015-06-29 19:12:11 +02:00
|
|
|
if (sticker != null) {
|
|
|
|
recentStickers.add(sticker);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
while (recentStickers.size() > 20) {
|
|
|
|
recentStickers.remove(recentStickers.size() - 1);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (newRecentStickers.size() != recentStickers.size()) {
|
|
|
|
newRecentStickers.clear();
|
|
|
|
for (int a = 0; a < recentStickers.size(); a++) {
|
|
|
|
newRecentStickers.add(recentStickers.get(a).id);
|
|
|
|
}
|
|
|
|
saveRecentStickers();
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateStickerTabs() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (scrollSlidingTabStrip == null) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
recentTabBum = -2;
|
|
|
|
gifTabBum = -2;
|
|
|
|
|
|
|
|
stickersTabOffset = 0;
|
|
|
|
int lastPosition = scrollSlidingTabStrip.getCurrentPosition();
|
2015-06-29 19:12:11 +02:00
|
|
|
scrollSlidingTabStrip.removeTabs();
|
2016-01-11 18:19:48 +01:00
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_smiles_smile);
|
|
|
|
|
|
|
|
if (showGifs && recentImages != null && !recentImages.isEmpty()) {
|
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_smiles_gif);
|
|
|
|
gifTabBum = stickersTabOffset;
|
|
|
|
stickersTabOffset++;
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (!recentStickers.isEmpty()) {
|
2016-01-11 18:19:48 +01:00
|
|
|
recentTabBum = stickersTabOffset;
|
|
|
|
stickersTabOffset++;
|
2015-06-29 19:12:11 +02:00
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_smiles_recent);
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
stickerSets.clear();
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = StickersQuery.getStickerSets();
|
|
|
|
for (int a = 0; a < packs.size(); a++) {
|
|
|
|
TLRPC.TL_messages_stickerSet pack = packs.get(a);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (pack.set.disabled || 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
|
|
|
}
|
|
|
|
for (int a = 0; a < stickerSets.size(); a++) {
|
|
|
|
scrollSlidingTabStrip.addStickerTab(stickerSets.get(a).documents.get(0));
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-12-09 19:27:52 +01:00
|
|
|
scrollSlidingTabStrip.addIconTab(R.drawable.ic_settings);
|
2015-06-29 19:12:11 +02:00
|
|
|
scrollSlidingTabStrip.updateTabStyles();
|
2016-01-11 18:19:48 +01:00
|
|
|
if (lastPosition != 0) {
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(lastPosition, lastPosition);
|
|
|
|
}
|
|
|
|
if (switchToGifTab) {
|
|
|
|
if (gifTabBum >= 0 && gifsGridView.getVisibility() != VISIBLE) {
|
|
|
|
showGifTab();
|
|
|
|
}
|
|
|
|
switchToGifTab = false;
|
|
|
|
}
|
|
|
|
if (gifTabBum == -2 && gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
listener.onGifTab(false);
|
|
|
|
gifsGridView.setVisibility(GONE);
|
|
|
|
stickersGridView.setVisibility(VISIBLE);
|
|
|
|
stickersEmptyView.setVisibility(stickersGridAdapter.getCount() != 0 ? GONE : VISIBLE);
|
|
|
|
} else if (gifTabBum != -2) {
|
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE) {
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(gifTabBum + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
} else {
|
|
|
|
scrollSlidingTabStrip.onPageScrolled(stickersGridAdapter.getTabForPosition(stickersGridView.getFirstVisiblePosition()) + 1, (recentTabBum > 0 ? recentTabBum : stickersTabOffset) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addRecentGif(MediaController.SearchImage searchImage) {
|
|
|
|
if (searchImage == null || searchImage.document == null || recentImages == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean wasEmpty = recentImages.isEmpty();
|
|
|
|
for (int a = 0; a < recentImages.size(); a++) {
|
|
|
|
MediaController.SearchImage image = recentImages.get(a);
|
|
|
|
if (image.id.equals(searchImage.id)) {
|
|
|
|
recentImages.remove(a);
|
|
|
|
recentImages.add(0, image);
|
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recentImages.add(0, searchImage);
|
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
if (wasEmpty) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void loadRecents() {
|
|
|
|
SharedPreferences preferences = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE);
|
2016-01-11 18:19:48 +01:00
|
|
|
lastGifLoadTime = preferences.getLong("lastGifLoadTime", 0);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
String str;
|
2015-10-29 18:10:07 +01:00
|
|
|
try {
|
|
|
|
emojiUseHistory.clear();
|
|
|
|
if (preferences.contains("emojis")) {
|
|
|
|
str = preferences.getString("emojis", "");
|
2015-08-13 11:23:31 +02:00
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
2015-10-29 18:10:07 +01:00
|
|
|
for (String arg : args) {
|
|
|
|
String[] args2 = arg.split("=");
|
|
|
|
long value = Long.parseLong(args2[0]);
|
|
|
|
String string = "";
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
char ch = (char) value;
|
|
|
|
string = String.valueOf(ch) + string;
|
|
|
|
value >>= 16;
|
|
|
|
if (value == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (string.length() > 0) {
|
|
|
|
emojiUseHistory.put(string, Integer.parseInt(args2[1]));
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
preferences.edit().remove("emojis").commit();
|
|
|
|
saveRecentEmoji();
|
|
|
|
} else {
|
|
|
|
str = preferences.getString("emojis2", "");
|
2015-08-13 11:23:31 +02:00
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
|
|
|
for (String arg : args) {
|
|
|
|
String[] args2 = arg.split("=");
|
2015-10-29 18:10:07 +01:00
|
|
|
emojiUseHistory.put(args2[0], Integer.parseInt(args2[1]));
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
if (emojiUseHistory.isEmpty()) {
|
|
|
|
String[] newRecent = new String[]{
|
|
|
|
"\uD83D\uDE02", "\uD83D\uDE18", "\u2764", "\uD83D\uDE0D", "\uD83D\uDE0A", "\uD83D\uDE01",
|
|
|
|
"\uD83D\uDC4D", "\u263A", "\uD83D\uDE14", "\uD83D\uDE04", "\uD83D\uDE2D", "\uD83D\uDC8B",
|
|
|
|
"\uD83D\uDE12", "\uD83D\uDE33", "\uD83D\uDE1C", "\uD83D\uDE48", "\uD83D\uDE09", "\uD83D\uDE03",
|
|
|
|
"\uD83D\uDE22", "\uD83D\uDE1D", "\uD83D\uDE31", "\uD83D\uDE21", "\uD83D\uDE0F", "\uD83D\uDE1E",
|
|
|
|
"\uD83D\uDE05", "\uD83D\uDE1A", "\uD83D\uDE4A", "\uD83D\uDE0C", "\uD83D\uDE00", "\uD83D\uDE0B",
|
|
|
|
"\uD83D\uDE06", "\uD83D\uDC4C", "\uD83D\uDE10", "\uD83D\uDE15"};
|
|
|
|
for (int i = 0; i < newRecent.length; i++) {
|
|
|
|
emojiUseHistory.put(newRecent[i], newRecent.length - i);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
saveRecentEmoji();
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
sortEmoji();
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
str = preferences.getString("color", "");
|
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < args.length; a++) {
|
|
|
|
String arg = args[a];
|
2015-10-29 18:10:07 +01:00
|
|
|
String[] args2 = arg.split("=");
|
|
|
|
emojiColor.put(args2[0], args2[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (showStickers) {
|
|
|
|
try {
|
2016-03-06 02:49:31 +01:00
|
|
|
newRecentStickers.clear();
|
2015-05-21 23:27:27 +02:00
|
|
|
str = preferences.getString("stickers", "");
|
|
|
|
if (str != null && str.length() > 0) {
|
|
|
|
String[] args = str.split(",");
|
2016-03-06 02:49:31 +01:00
|
|
|
final HashMap<Long, Integer> stickersUseHistory = new HashMap<>();
|
|
|
|
for (int a = 0; a < args.length; a++) {
|
|
|
|
String arg = args[a];
|
2015-05-21 23:27:27 +02:00
|
|
|
String[] args2 = arg.split("=");
|
2016-03-06 02:49:31 +01:00
|
|
|
Long key = Long.parseLong(args2[0]);
|
|
|
|
stickersUseHistory.put(key, Integer.parseInt(args2[1]));
|
|
|
|
newRecentStickers.add(key);
|
|
|
|
}
|
|
|
|
Collections.sort(newRecentStickers, new Comparator<Long>() {
|
|
|
|
@Override
|
|
|
|
public int compare(Long lhs, Long rhs) {
|
|
|
|
Integer count1 = stickersUseHistory.get(lhs);
|
|
|
|
Integer count2 = stickersUseHistory.get(rhs);
|
|
|
|
if (count1 == null) {
|
|
|
|
count1 = 0;
|
|
|
|
}
|
|
|
|
if (count2 == null) {
|
|
|
|
count2 = 0;
|
|
|
|
}
|
|
|
|
if (count1 > count2) {
|
|
|
|
return -1;
|
|
|
|
} else if (count1 < count2) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
preferences.edit().remove("stickers").commit();
|
|
|
|
saveRecentStickers();
|
|
|
|
} else {
|
|
|
|
str = preferences.getString("stickers2", "");
|
|
|
|
String[] args = str.split(",");
|
|
|
|
for (int a = 0; a < args.length; a++) {
|
|
|
|
newRecentStickers.add(Long.parseLong(args[a]));
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
sortStickers();
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2015-05-21 23:27:27 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2015-06-29 19:12:11 +02:00
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) pagerSlidingTabStripContainer.getLayoutParams();
|
|
|
|
FrameLayout.LayoutParams layoutParams1 = null;
|
|
|
|
layoutParams.width = View.MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
if (scrollSlidingTabStrip != null) {
|
|
|
|
layoutParams1 = (FrameLayout.LayoutParams) scrollSlidingTabStrip.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) {
|
2015-07-22 20:56:37 +02:00
|
|
|
if (scrollSlidingTabStrip != null && layoutParams1 != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
onPageScrolled(pager.getCurrentItem(), layoutParams.width, 0);
|
|
|
|
scrollSlidingTabStrip.setLayoutParams(layoutParams1);
|
|
|
|
}
|
|
|
|
pagerSlidingTabStripContainer.setLayoutParams(layoutParams);
|
|
|
|
oldWidth = layoutParams.width;
|
|
|
|
}
|
|
|
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void invalidateViews() {
|
|
|
|
for (GridView gridView : views) {
|
|
|
|
if (gridView != null) {
|
|
|
|
gridView.invalidateViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.stickersDidLoaded);
|
2016-01-11 18:19:48 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
|
2016-03-06 02:49:31 +01:00
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
updateStickerTabs();
|
|
|
|
reloadStickersAdapter();
|
|
|
|
}
|
|
|
|
});
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadGifRecent() {
|
|
|
|
if (showGifs && gifsAdapter != null && !loadingRecent) {
|
|
|
|
MessagesStorage.getInstance().loadWebRecent(2);
|
|
|
|
loadingRecent = true;
|
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) {
|
|
|
|
sortEmoji();
|
|
|
|
adapters.get(0).notifyDataSetChanged();
|
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.stickersDidLoaded);
|
2016-01-11 18:19:48 +01:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
|
2015-08-13 11:23:31 +02:00
|
|
|
sortStickers();
|
|
|
|
updateStickerTabs();
|
|
|
|
reloadStickersAdapter();
|
2016-01-11 18:19:48 +01:00
|
|
|
if (gifsGridView != null && gifsGridView.getVisibility() == VISIBLE && listener != null) {
|
|
|
|
listener.onGifTab(true);
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
loadGifRecent();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public void onDestroy() {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (stickersGridAdapter != null) {
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.stickersDidLoaded);
|
2016-01-11 18:19:48 +01:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
|
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-01-11 18:19:48 +01:00
|
|
|
private int calcGifsHash(ArrayList<MediaController.SearchImage> arrayList) {
|
|
|
|
if (arrayList == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
long acc = 0;
|
|
|
|
for (int a = 0; a < Math.min(200, arrayList.size()); a++) {
|
|
|
|
MediaController.SearchImage searchImage = arrayList.get(a);
|
|
|
|
if (searchImage.document == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int high_id = (int) (searchImage.document.id >> 32);
|
|
|
|
int lower_id = (int) searchImage.document.id;
|
|
|
|
acc = ((acc * 20261) + 0x80000000L + high_id) % 0x80000000L;
|
|
|
|
acc = ((acc * 20261) + 0x80000000L + lower_id) % 0x80000000L;
|
|
|
|
}
|
|
|
|
return (int) acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadRecentGif() {
|
|
|
|
if (loadingRecentGifs || Math.abs(System.currentTimeMillis() - lastGifLoadTime) < 60 * 60 * 1000) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
loadingRecentGifs = true;
|
|
|
|
TLRPC.TL_messages_getSavedGifs req = new TLRPC.TL_messages_getSavedGifs();
|
|
|
|
req.hash = calcGifsHash(recentImages);
|
|
|
|
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
|
|
|
@Override
|
|
|
|
public void run(final TLObject response, TLRPC.TL_error error) {
|
|
|
|
ArrayList<MediaController.SearchImage> arrayList = null;
|
|
|
|
if (response instanceof TLRPC.TL_messages_savedGifs) {
|
|
|
|
arrayList = new ArrayList<>();
|
|
|
|
TLRPC.TL_messages_savedGifs res = (TLRPC.TL_messages_savedGifs) response;
|
|
|
|
int size = res.gifs.size();
|
|
|
|
for (int a = 0; a < size; a++) {
|
|
|
|
MediaController.SearchImage searchImage = new MediaController.SearchImage();
|
|
|
|
searchImage.type = 2;
|
|
|
|
searchImage.document = res.gifs.get(a);
|
|
|
|
searchImage.date = size - a;
|
|
|
|
searchImage.id = "" + searchImage.document.id;
|
|
|
|
arrayList.add(searchImage);
|
|
|
|
MessagesStorage.getInstance().putWebRecent(arrayList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final ArrayList<MediaController.SearchImage> arrayListFinal = arrayList;
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (arrayListFinal != null) {
|
|
|
|
boolean wasEmpty = recentImages.isEmpty();
|
|
|
|
recentImages = arrayListFinal;
|
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
lastGifLoadTime = System.currentTimeMillis();
|
|
|
|
SharedPreferences.Editor editor = getContext().getSharedPreferences("emoji", Activity.MODE_PRIVATE).edit();
|
|
|
|
editor.putLong("lastGifLoadTime", lastGifLoadTime).commit();
|
|
|
|
if (wasEmpty && !recentImages.isEmpty()) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingRecentGifs = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
|
|
|
if (id == NotificationCenter.stickersDidLoaded) {
|
2015-06-29 19:12:11 +02:00
|
|
|
updateStickerTabs();
|
2015-08-13 11:23:31 +02:00
|
|
|
reloadStickersAdapter();
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (id == NotificationCenter.recentImagesDidLoaded) {
|
|
|
|
if ((Integer) args[0] == 2) {
|
|
|
|
int previousCount = recentImages != null ? recentImages.size() : 0;
|
|
|
|
recentImages = (ArrayList<MediaController.SearchImage>) args[1];
|
|
|
|
loadingRecent = false;
|
2016-03-06 02:49:31 +01:00
|
|
|
if (gifsAdapter != null) {
|
|
|
|
gifsAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (previousCount != recentImages.size()) {
|
|
|
|
updateStickerTabs();
|
|
|
|
}
|
|
|
|
loadRecentGif();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class StickersGridAdapter extends BaseAdapter {
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private Context context;
|
|
|
|
private int stickersPerRow;
|
|
|
|
private HashMap<Integer, TLRPC.TL_messages_stickerSet> rowStartPack = new HashMap<>();
|
|
|
|
private HashMap<TLRPC.TL_messages_stickerSet, Integer> packStartRow = new HashMap<>();
|
|
|
|
private HashMap<Integer, TLRPC.Document> cache = new HashMap<>();
|
|
|
|
private int totalItems;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
public StickersGridAdapter(Context context) {
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public long getItemId(int i) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return NO_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPositionForPack(TLRPC.TL_messages_stickerSet stickerSet) {
|
|
|
|
return packStartRow.get(stickerSet) * stickersPerRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int position) {
|
|
|
|
return cache.get(position) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (cache.get(position) != null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTabForPosition(int position) {
|
|
|
|
if (stickersPerRow == 0) {
|
|
|
|
int width = getMeasuredWidth();
|
|
|
|
if (width == 0) {
|
|
|
|
width = AndroidUtilities.displaySize.x;
|
|
|
|
}
|
|
|
|
stickersPerRow = width / AndroidUtilities.dp(72);
|
|
|
|
}
|
|
|
|
int row = position / stickersPerRow;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = rowStartPack.get(row);
|
|
|
|
if (pack == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return recentTabBum;
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
return stickerSets.indexOf(pack) + stickersTabOffset;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
2015-06-29 19:12:11 +02:00
|
|
|
TLRPC.Document sticker = cache.get(i);
|
|
|
|
if (sticker != null) {
|
|
|
|
if (view == null) {
|
|
|
|
view = new StickerEmojiCell(context) {
|
|
|
|
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(82), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
((StickerEmojiCell) view).setSticker(sticker, false);
|
|
|
|
} else {
|
|
|
|
if (view == null) {
|
|
|
|
view = new EmptyCell(context);
|
|
|
|
}
|
|
|
|
if (i == totalItems) {
|
|
|
|
int row = (i - 1) / stickersPerRow;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = rowStartPack.get(row);
|
|
|
|
if (pack == null) {
|
|
|
|
((EmptyCell) view).setHeight(1);
|
|
|
|
} else {
|
|
|
|
int height = pager.getHeight() - (int) Math.ceil(pack.documents.size() / (float) stickersPerRow) * AndroidUtilities.dp(82);
|
|
|
|
((EmptyCell) view).setHeight(height > 0 ? height : 1);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
} else {
|
|
|
|
((EmptyCell) view).setHeight(AndroidUtilities.dp(82));
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
rowStartPack.clear();
|
|
|
|
packStartRow.clear();
|
|
|
|
cache.clear();
|
|
|
|
totalItems = 0;
|
|
|
|
ArrayList<TLRPC.TL_messages_stickerSet> packs = stickerSets;
|
|
|
|
for (int a = -1; a < packs.size(); a++) {
|
|
|
|
ArrayList<TLRPC.Document> documents;
|
|
|
|
TLRPC.TL_messages_stickerSet pack = null;
|
|
|
|
int startRow = totalItems / stickersPerRow;
|
|
|
|
if (a == -1) {
|
|
|
|
documents = recentStickers;
|
|
|
|
} else {
|
|
|
|
pack = packs.get(a);
|
|
|
|
documents = pack.documents;
|
|
|
|
packStartRow.put(pack, startRow);
|
|
|
|
}
|
|
|
|
if (documents.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int count = (int) Math.ceil(documents.size() / (float) stickersPerRow);
|
|
|
|
for (int b = 0; b < documents.size(); b++) {
|
|
|
|
cache.put(b + totalItems, documents.get(b));
|
|
|
|
}
|
|
|
|
totalItems += count * stickersPerRow;
|
|
|
|
for (int b = 0; b < count; b++) {
|
|
|
|
rowStartPack.put(startRow + b, pack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
@Override
|
|
|
|
public void unregisterDataSetObserver(DataSetObserver observer) {
|
|
|
|
if (observer != null) {
|
|
|
|
super.unregisterDataSetObserver(observer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (emojiPage == -1) {
|
|
|
|
return recentEmoji.size();
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
return EmojiData.dataColored[emojiPage].length;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public Object getItem(int i) {
|
2013-10-25 17:19:00 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 15:37:26 +02:00
|
|
|
public View getView(int i, 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) {
|
2015-10-29 18:10:07 +01:00
|
|
|
coloredCode = code = recentEmoji.get(i);
|
2015-08-13 11:23:31 +02:00
|
|
|
} else {
|
2015-10-29 18:10:07 +01:00
|
|
|
coloredCode = code = EmojiData.dataColored[emojiPage][i];
|
|
|
|
String color = emojiColor.get(code);
|
|
|
|
if (color != null) {
|
|
|
|
coloredCode += color;
|
|
|
|
}
|
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;
|
|
|
|
if (position == 0) {
|
|
|
|
view = recentsWrap;
|
|
|
|
} else if (position == 6) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public int getCount() {
|
2014-11-17 23:04:31 +01:00
|
|
|
return views.size();
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPageIconResId(int paramInt) {
|
2014-11-17 23:04:31 +01:00
|
|
|
return icons[paramInt];
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public Object instantiateItem(ViewGroup viewGroup, int position) {
|
|
|
|
View view;
|
|
|
|
if (position == 0) {
|
|
|
|
view = recentsWrap;
|
|
|
|
} else if (position == 6) {
|
|
|
|
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
|
|
|
|
|
|
|
private class GifsAdapter extends RecyclerView.Adapter {
|
|
|
|
|
|
|
|
private class Holder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
public Holder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public GifsAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
return recentImages.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
|
|
|
ContextLinkCell view = new ContextLinkCell(mContext);
|
|
|
|
return new Holder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
|
|
|
|
MediaController.SearchImage photoEntry = recentImages.get(i);
|
|
|
|
if (photoEntry.document != null) {
|
|
|
|
((ContextLinkCell) viewHolder.itemView).setGif(photoEntry.document, flowLayoutManager.getRowOfIndex(i) != flowLayoutManager.getRowCount() - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|