NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/EmptyTextProgressView.java

201 lines
7.3 KiB
Java
Raw Normal View History

2015-05-21 23:27:27 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2015-05-21 23:27:27 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-05-21 23:27:27 +02:00
*/
package org.telegram.ui.Components;
import android.content.Context;
2019-05-14 14:08:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
2015-05-21 23:27:27 +02:00
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
2022-03-11 17:49:54 +01:00
import android.widget.ImageView;
import android.widget.LinearLayout;
2015-05-21 23:27:27 +02:00
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
2015-05-21 23:27:27 +02:00
import org.telegram.messenger.R;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
2015-05-21 23:27:27 +02:00
public class EmptyTextProgressView extends FrameLayout {
2021-09-20 00:10:42 +02:00
private final Theme.ResourcesProvider resourcesProvider;
2015-05-21 23:27:27 +02:00
private TextView textView;
2022-03-11 17:49:54 +01:00
private LinearLayout textViewLayout;
2021-01-28 15:15:51 +01:00
private View progressView;
2022-03-11 17:49:54 +01:00
private RLottieImageView lottieImageView;
2015-05-21 23:27:27 +02:00
private boolean inLayout;
2019-12-31 14:08:08 +01:00
private int showAtPos;
2015-05-21 23:27:27 +02:00
public EmptyTextProgressView(Context context) {
2021-09-20 00:10:42 +02:00
this(context, null, null);
2021-01-28 15:15:51 +01:00
}
public EmptyTextProgressView(Context context, View progressView) {
2021-09-20 00:10:42 +02:00
this(context, progressView, null);
}
public EmptyTextProgressView(Context context, View progressView, Theme.ResourcesProvider resourcesProvider) {
2015-05-21 23:27:27 +02:00
super(context);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2015-05-21 23:27:27 +02:00
2021-01-28 15:15:51 +01:00
if (progressView == null) {
progressView = new RadialProgressView(context);
addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
} else {
addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
}
this.progressView = progressView;
2015-05-21 23:27:27 +02:00
2022-03-11 17:49:54 +01:00
textViewLayout = new LinearLayout(context);
textViewLayout.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
textViewLayout.setGravity(Gravity.CENTER_HORIZONTAL);
textViewLayout.setClipChildren(false);
textViewLayout.setClipToPadding(false);
textViewLayout.setOrientation(LinearLayout.VERTICAL);
lottieImageView = new RLottieImageView(context);
lottieImageView.setScaleType(ImageView.ScaleType.FIT_XY);
lottieImageView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
lottieImageView.setVisibility(GONE);
// lottieImageView.setOnClickListener(v -> {
// if (!lottieImageView.isPlaying()) {
// lottieImageView.setProgress(0.0f);
// lottieImageView.playAnimation();
// }
// });
textViewLayout.addView(lottieImageView, LayoutHelper.createLinear(150, 150, Gravity.CENTER, 0, 0, 0, 20));
2015-05-21 23:27:27 +02:00
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
2021-09-20 00:10:42 +02:00
textView.setTextColor(getThemedColor(Theme.key_emptyListPlaceholder));
2022-03-11 17:49:54 +01:00
textView.setGravity(Gravity.CENTER_HORIZONTAL);
2015-05-21 23:27:27 +02:00
textView.setText(LocaleController.getString("NoResult", R.string.NoResult));
2022-03-11 17:49:54 +01:00
textViewLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
addView(textViewLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
2015-05-21 23:27:27 +02:00
2021-07-15 16:24:57 +02:00
AndroidUtilities.updateViewVisibilityAnimated(textView, false, 2f, false);
AndroidUtilities.updateViewVisibilityAnimated(progressView, false, 1f, false);
2020-07-26 10:03:38 +02:00
2018-08-27 10:33:11 +02:00
setOnTouchListener((v, event) -> true);
2015-05-21 23:27:27 +02:00
}
public void showProgress() {
2021-07-15 16:24:57 +02:00
showProgress(true);
}
public void showProgress(boolean animated) {
AndroidUtilities.updateViewVisibilityAnimated(textView, false, 0.9f, animated);
AndroidUtilities.updateViewVisibilityAnimated(progressView, true, 1f, animated);
2015-05-21 23:27:27 +02:00
}
public void showTextView() {
2021-07-15 16:24:57 +02:00
AndroidUtilities.updateViewVisibilityAnimated(textView, true, 0.9f, true);
AndroidUtilities.updateViewVisibilityAnimated(progressView, false, 1f, true);
2015-05-21 23:27:27 +02:00
}
public void setText(String text) {
textView.setText(text);
}
2017-03-31 01:58:05 +02:00
public void setTextColor(int color) {
textView.setTextColor(color);
}
2022-03-11 17:49:54 +01:00
public void setLottie(int resource, int w, int h) {
lottieImageView.setVisibility(resource != 0 ? VISIBLE : GONE);
if (resource != 0) {
lottieImageView.setAnimation(resource, w, h);
lottieImageView.playAnimation();
}
}
2017-03-31 01:58:05 +02:00
public void setProgressBarColor(int color) {
2021-01-28 15:15:51 +01:00
if (progressView instanceof RadialProgressView) {
((RadialProgressView) progressView).setProgressColor(color);
}
2017-03-31 01:58:05 +02:00
}
2019-05-14 14:08:05 +02:00
public void setTopImage(int resId) {
if (resId == 0) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
} else {
Drawable drawable = getContext().getResources().getDrawable(resId).mutate();
if (drawable != null) {
2021-09-20 11:14:20 +02:00
drawable.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_emptyListPlaceholder), PorterDuff.Mode.SRC_IN));
2019-05-14 14:08:05 +02:00
}
textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
textView.setCompoundDrawablePadding(AndroidUtilities.dp(1));
}
}
2015-10-29 18:10:07 +01:00
public void setTextSize(int size) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
}
2015-05-21 23:27:27 +02:00
public void setShowAtCenter(boolean value) {
2019-12-31 14:08:08 +01:00
showAtPos = value ? 1 : 0;
}
public void setShowAtTop(boolean value) {
showAtPos = value ? 2 : 0;
2015-05-21 23:27:27 +02:00
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
inLayout = true;
int width = r - l;
int height = b - t;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
int x = (width - child.getMeasuredWidth()) / 2;
int y;
2021-07-15 16:24:57 +02:00
if (child == progressView && progressView instanceof FlickerLoadingView) {
2019-07-18 15:01:39 +02:00
y = (height - child.getMeasuredHeight()) / 2 + getPaddingTop();
2021-07-15 16:24:57 +02:00
} else {
if (showAtPos == 2) {
y = (AndroidUtilities.dp(100) - child.getMeasuredHeight()) / 2 + getPaddingTop();
} else if (showAtPos == 1) {
y = (height / 2 - child.getMeasuredHeight()) / 2 + getPaddingTop();
} else {
y = (height - child.getMeasuredHeight()) / 2 + getPaddingTop();
}
2015-05-21 23:27:27 +02:00
}
child.layout(x, y, x + child.getMeasuredWidth(), y + child.getMeasuredHeight());
}
inLayout = false;
}
@Override
public void requestLayout() {
if (!inLayout) {
super.requestLayout();
}
}
2016-05-25 23:49:47 +02:00
@Override
public boolean hasOverlappingRendering() {
return false;
}
2021-09-20 00:10:42 +02:00
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}
2015-05-21 23:27:27 +02:00
}