2020-09-30 15:48:47 +02:00
|
|
|
package org.telegram.ui.Components;
|
|
|
|
|
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.content.Context;
|
2020-12-23 08:48:30 +01:00
|
|
|
import android.util.TypedValue;
|
2020-09-30 15:48:47 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2022-03-11 17:49:54 +01:00
|
|
|
import org.telegram.messenger.DocumentObject;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
|
|
|
import org.telegram.messenger.MediaDataController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2022-03-11 17:49:54 +01:00
|
|
|
import org.telegram.messenger.SvgHelper;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
|
|
|
|
public class StickerEmptyView extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
public final static int STICKER_TYPE_NO_CONTACTS = 0;
|
2021-11-05 11:06:49 +01:00
|
|
|
public final static int STICKER_TYPE_SEARCH = 1;
|
|
|
|
public final static int STICKER_TYPE_DONE = 2;
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
private LinearLayout linearLayout;
|
2020-12-23 08:48:30 +01:00
|
|
|
public BackupImageView stickerView;
|
2020-09-30 15:48:47 +02:00
|
|
|
private RadialProgressView progressBar;
|
|
|
|
public final TextView title;
|
|
|
|
public final TextView subtitle;
|
|
|
|
private boolean progressShowing;
|
2021-09-20 07:54:41 +02:00
|
|
|
private final Theme.ResourcesProvider resourcesProvider;
|
2020-09-30 15:48:47 +02:00
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
private int stickerType;
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public final View progressView;
|
|
|
|
|
|
|
|
int keyboardSize;
|
|
|
|
|
|
|
|
int currentAccount = UserConfig.selectedAccount;
|
|
|
|
|
2021-03-19 11:25:58 +01:00
|
|
|
boolean preventMoving;
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
Runnable showProgressRunnable = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (progressView != null) {
|
|
|
|
if (progressView.getVisibility() != View.VISIBLE) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
progressView.setAlpha(0f);
|
|
|
|
}
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.animate().alpha(1f).setDuration(150).start();
|
|
|
|
} else {
|
|
|
|
progressBar.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(150).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-12-23 08:48:30 +01:00
|
|
|
private boolean animateLayoutChange;
|
2020-09-30 15:48:47 +02:00
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
public StickerEmptyView(@NonNull Context context, View progressView, int type) {
|
2021-09-20 07:54:41 +02:00
|
|
|
this(context, progressView, type, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public StickerEmptyView(@NonNull Context context, View progressView, int type, Theme.ResourcesProvider resourcesProvider) {
|
2020-09-30 15:48:47 +02:00
|
|
|
super(context);
|
2021-09-20 07:54:41 +02:00
|
|
|
this.resourcesProvider = resourcesProvider;
|
2020-09-30 15:48:47 +02:00
|
|
|
this.progressView = progressView;
|
2020-12-23 08:48:30 +01:00
|
|
|
stickerType = type;
|
2020-09-30 15:48:47 +02:00
|
|
|
|
|
|
|
linearLayout = new LinearLayout(context) {
|
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
if (getVisibility() == View.GONE && visibility == View.VISIBLE) {
|
|
|
|
setSticker();
|
|
|
|
stickerView.getImageReceiver().startAnimation();
|
|
|
|
} else if (visibility == View.GONE) {
|
|
|
|
stickerView.getImageReceiver().clearImage();
|
|
|
|
}
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
stickerView = new BackupImageView(context);
|
|
|
|
stickerView.setOnClickListener(view -> stickerView.getImageReceiver().startAnimation());
|
|
|
|
|
|
|
|
title = new TextView(context);
|
|
|
|
|
|
|
|
title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
title.setTag(Theme.key_windowBackgroundWhiteBlackText);
|
2021-09-20 07:54:41 +02:00
|
|
|
title.setTextColor(getThemedColor(Theme.key_windowBackgroundWhiteBlackText));
|
2020-12-23 08:48:30 +01:00
|
|
|
title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
2020-09-30 15:48:47 +02:00
|
|
|
title.setGravity(Gravity.CENTER);
|
|
|
|
|
|
|
|
subtitle = new TextView(context);
|
|
|
|
subtitle.setTag(Theme.key_windowBackgroundWhiteGrayText);
|
2021-09-20 07:54:41 +02:00
|
|
|
subtitle.setTextColor(getThemedColor(Theme.key_windowBackgroundWhiteGrayText));
|
2020-12-23 08:48:30 +01:00
|
|
|
subtitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
|
2020-09-30 15:48:47 +02:00
|
|
|
subtitle.setGravity(Gravity.CENTER);
|
|
|
|
|
|
|
|
linearLayout.addView(stickerView, LayoutHelper.createLinear(130, 130, Gravity.CENTER_HORIZONTAL));
|
|
|
|
linearLayout.addView(title, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 12, 0, 0));
|
|
|
|
linearLayout.addView(subtitle, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL, 0, 8, 0, 0));
|
|
|
|
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 56, 0, 56, 30));
|
|
|
|
|
|
|
|
if (progressView == null) {
|
2021-09-20 07:54:41 +02:00
|
|
|
progressBar = new RadialProgressView(context, resourcesProvider);
|
2020-09-30 15:48:47 +02:00
|
|
|
progressBar.setAlpha(0);
|
|
|
|
progressBar.setScaleY(0.5f);
|
|
|
|
progressBar.setScaleX(0.5f);
|
|
|
|
addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
private int lastH;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
2021-03-19 11:25:58 +01:00
|
|
|
if ((animateLayoutChange || preventMoving) && lastH > 0 && lastH != getMeasuredHeight()) {
|
2020-12-23 08:48:30 +01:00
|
|
|
float y = (lastH - getMeasuredHeight()) / 2f;
|
|
|
|
linearLayout.setTranslationY(linearLayout.getTranslationY() + y);
|
2021-03-19 11:25:58 +01:00
|
|
|
if (!preventMoving) {
|
|
|
|
linearLayout.animate().translationY(0).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(250);
|
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
if (progressBar != null) {
|
|
|
|
progressBar.setTranslationY(progressBar.getTranslationY() + y);
|
2021-03-19 11:25:58 +01:00
|
|
|
if (!preventMoving) {
|
|
|
|
progressBar.animate().translationY(0).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(250);
|
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lastH = getMeasuredHeight();
|
|
|
|
}
|
|
|
|
|
2022-03-11 17:49:54 +01:00
|
|
|
String colorKey1 = Theme.key_emptyListPlaceholder;
|
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
public void setColors(String titleKey, String subtitleKey, String key1, String key2) {
|
|
|
|
title.setTag(titleKey);
|
2021-09-20 07:54:41 +02:00
|
|
|
title.setTextColor(getThemedColor(titleKey));
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
subtitle.setTag(subtitleKey);
|
2021-09-20 07:54:41 +02:00
|
|
|
subtitle.setTextColor(getThemedColor(subtitleKey));
|
2022-03-11 17:49:54 +01:00
|
|
|
colorKey1 = key1;
|
2020-12-23 08:48:30 +01:00
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
@Override
|
|
|
|
public void setVisibility(int visibility) {
|
|
|
|
if (getVisibility() != visibility) {
|
|
|
|
if (visibility == VISIBLE) {
|
|
|
|
if (progressShowing) {
|
|
|
|
linearLayout.animate().alpha(0f).scaleY(0.8f).scaleX(0.8f).setDuration(150).start();
|
2020-12-23 08:48:30 +01:00
|
|
|
progressView.setVisibility(VISIBLE);
|
|
|
|
progressView.setAlpha(1f);
|
|
|
|
//showProgressRunnable.run();
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
|
|
|
linearLayout.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(150).start();
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.animate().setListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}).alpha(0f).setDuration(150).start();
|
|
|
|
} else {
|
|
|
|
progressBar.animate().alpha(0f).scaleY(0.5f).scaleX(0.5f).setDuration(150).start();
|
|
|
|
}
|
|
|
|
stickerView.getImageReceiver().startAnimation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.setVisibility(visibility);
|
|
|
|
if (getVisibility() == VISIBLE) {
|
|
|
|
setSticker();
|
|
|
|
} else {
|
2020-12-23 08:48:30 +01:00
|
|
|
lastH = 0;
|
2020-09-30 15:48:47 +02:00
|
|
|
linearLayout.setAlpha(0f);
|
|
|
|
linearLayout.setScaleX(0.8f);
|
|
|
|
linearLayout.setScaleY(0.8f);
|
|
|
|
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.animate().setListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}).alpha(0f).setDuration(150).start();
|
|
|
|
} else {
|
|
|
|
progressBar.setAlpha(0f);
|
|
|
|
progressBar.setScaleX(0.5f);
|
|
|
|
progressBar.setScaleY(0.5f);
|
|
|
|
}
|
|
|
|
stickerView.getImageReceiver().stopAnimation();
|
|
|
|
stickerView.getImageReceiver().clearImage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
if (getVisibility() == VISIBLE) {
|
|
|
|
setSticker();
|
|
|
|
}
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.diceStickersDidLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.diceStickersDidLoad);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSticker() {
|
2021-11-05 11:06:49 +01:00
|
|
|
String imageFilter = null;
|
|
|
|
TLRPC.Document document = null;
|
|
|
|
TLRPC.TL_messages_stickerSet set = null;
|
|
|
|
if (stickerType == STICKER_TYPE_DONE) {
|
|
|
|
document = MediaDataController.getInstance(currentAccount).getEmojiAnimatedSticker("\uD83D\uDC4D");
|
|
|
|
} else {
|
|
|
|
set = MediaDataController.getInstance(currentAccount).getStickerSetByName(AndroidUtilities.STICKERS_PLACEHOLDER_PACK_NAME);
|
|
|
|
if (set == null) {
|
|
|
|
set = MediaDataController.getInstance(currentAccount).getStickerSetByEmojiOrName(AndroidUtilities.STICKERS_PLACEHOLDER_PACK_NAME);
|
|
|
|
}
|
|
|
|
if (set != null && set.documents.size() >= 2) {
|
|
|
|
document = set.documents.get(stickerType);
|
|
|
|
}
|
|
|
|
imageFilter = "130_130";
|
2020-09-30 15:48:47 +02:00
|
|
|
}
|
2022-03-11 17:49:54 +01:00
|
|
|
|
2021-11-05 11:06:49 +01:00
|
|
|
if (document != null) {
|
2022-03-11 17:49:54 +01:00
|
|
|
SvgHelper.SvgDrawable svgThumb = DocumentObject.getSvgThumb(document.thumbs, colorKey1, 0.2f);
|
|
|
|
if (svgThumb != null) {
|
|
|
|
svgThumb.overrideWidthAndHeight(512, 512);
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
ImageLocation imageLocation = ImageLocation.getForDocument(document);
|
2022-03-11 17:49:54 +01:00
|
|
|
stickerView.setImage(imageLocation, imageFilter, "tgs", svgThumb, set);
|
|
|
|
if (stickerType == 9) {
|
|
|
|
stickerView.getImageReceiver().setAutoRepeat(1);
|
|
|
|
} else {
|
|
|
|
stickerView.getImageReceiver().setAutoRepeat(2);
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
2021-09-20 07:54:41 +02:00
|
|
|
MediaDataController.getInstance(currentAccount).loadStickersByEmojiOrName(AndroidUtilities.STICKERS_PLACEHOLDER_PACK_NAME, false, set == null);
|
2022-03-11 17:49:54 +01:00
|
|
|
stickerView.getImageReceiver().clearImage();
|
2020-09-30 15:48:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
|
|
|
if (id == NotificationCenter.diceStickersDidLoad) {
|
|
|
|
String name = (String) args[0];
|
2021-09-20 07:54:41 +02:00
|
|
|
if (AndroidUtilities.STICKERS_PLACEHOLDER_PACK_NAME.equals(name) && getVisibility() == VISIBLE) {
|
2020-09-30 15:48:47 +02:00
|
|
|
setSticker();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setKeyboardHeight(int keyboardSize, boolean animated) {
|
|
|
|
if (this.keyboardSize != keyboardSize) {
|
|
|
|
if (getVisibility() != View.VISIBLE) {
|
|
|
|
animated = false;
|
|
|
|
}
|
|
|
|
this.keyboardSize = keyboardSize;
|
|
|
|
float y = -(keyboardSize >> 1) + (keyboardSize > 0 ? AndroidUtilities.dp(20) : 0);
|
|
|
|
if (animated) {
|
|
|
|
linearLayout.animate().translationY(y).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(250);
|
|
|
|
if (progressBar != null) {
|
|
|
|
progressBar.animate().translationY(y).setInterpolator(CubicBezierInterpolator.DEFAULT).setDuration(250);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
linearLayout.setTranslationY(y);
|
|
|
|
if (progressBar != null) {
|
|
|
|
progressBar.setTranslationY(y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showProgress(boolean show) {
|
|
|
|
showProgress(show, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showProgress(boolean show, boolean animated) {
|
|
|
|
if (progressShowing != show) {
|
|
|
|
progressShowing = show;
|
|
|
|
if (getVisibility() != View.VISIBLE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
if (show) {
|
|
|
|
linearLayout.animate().alpha(0f).scaleY(0.8f).scaleX(0.8f).setDuration(150).start();
|
|
|
|
showProgressRunnable.run();
|
|
|
|
} else {
|
|
|
|
linearLayout.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(150).start();
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.animate().setListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}).alpha(0).setDuration(150).start();
|
|
|
|
} else {
|
|
|
|
progressBar.animate().alpha(0f).scaleY(0.5f).scaleX(0.5f).setDuration(150).start();
|
|
|
|
}
|
|
|
|
stickerView.getImageReceiver().startAnimation();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (show) {
|
|
|
|
linearLayout.animate().cancel();
|
|
|
|
linearLayout.setAlpha(0);
|
|
|
|
linearLayout.setScaleX(0.8f);
|
|
|
|
linearLayout.setScaleY(0.8f);
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.setAlpha(1);
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
progressBar.setAlpha(1f);
|
|
|
|
progressBar.setScaleX(1f);
|
|
|
|
progressBar.setScaleY(1f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
linearLayout.animate().cancel();
|
|
|
|
linearLayout.setAlpha(1f);
|
|
|
|
linearLayout.setScaleX(1f);
|
|
|
|
linearLayout.setScaleY(1f);
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.animate().setListener(null).cancel();
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
progressBar.setAlpha(0f);
|
|
|
|
progressBar.setScaleX(0.5f);
|
|
|
|
progressBar.setScaleY(0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
|
|
|
|
public void setAnimateLayoutChange(boolean animate) {
|
|
|
|
this.animateLayoutChange = animate;
|
|
|
|
}
|
2021-03-19 11:25:58 +01:00
|
|
|
|
|
|
|
public void setPreventMoving(boolean preventMoving) {
|
|
|
|
this.preventMoving = preventMoving;
|
|
|
|
if (!preventMoving) {
|
|
|
|
linearLayout.setTranslationY(0);
|
|
|
|
if (progressBar != null) {
|
|
|
|
progressBar.setTranslationY(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-20 07:54:41 +02:00
|
|
|
|
|
|
|
private int getThemedColor(String key) {
|
|
|
|
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
|
|
|
|
return color != null ? color : Theme.getColor(key);
|
|
|
|
}
|
2022-03-11 17:49:54 +01:00
|
|
|
|
|
|
|
public void setStickerType(int stickerType) {
|
|
|
|
if (this.stickerType != stickerType) {
|
|
|
|
this.stickerType = stickerType;
|
|
|
|
setSticker();
|
|
|
|
}
|
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
}
|