jimu-decompiled/sources/com/ubt/jimu/widgets/LoadingView.java
2025-05-13 19:24:51 +02:00

246 lines
7.2 KiB
Java

package com.ubt.jimu.widgets;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.ubt.jimu.R;
import com.ubt.jimu.base.http.manager.CommunityManager;
import com.ubt.jimu.base.http.manager.Manager;
import com.ubt.jimu.base.http.manager.SubscriberModel;
import com.ubt.jimu.utils.LogUtils;
/* loaded from: classes2.dex */
public class LoadingView extends RelativeLayout {
private LayoutInflater a;
private ImageView b;
private RelativeLayout c;
private RotateAnimation d;
private TextView e;
private ImageView f;
private TextView g;
private Context h;
private int i;
private int j;
private int k;
private boolean l;
private RetryRequest m;
public interface RetryRequest {
void OnRetryListener();
}
public LoadingView(Context context) {
super(context);
this.l = false;
a(context);
}
private void a(Context context) {
this.a = LayoutInflater.from(context);
this.h = context;
View inflate = this.a.inflate(R.layout.loading_common, (ViewGroup) this, false);
this.b = (ImageView) inflate.findViewById(R.id.img_loading);
this.c = (RelativeLayout) inflate.findViewById(R.id.rl_loading);
this.e = (TextView) inflate.findViewById(R.id.tv_loading);
this.f = (ImageView) inflate.findViewById(R.id.img_loading_error);
this.g = (TextView) inflate.findViewById(R.id.tv_net_error);
addView(inflate);
this.c.setOnClickListener(new View.OnClickListener() { // from class: com.ubt.jimu.widgets.g
@Override // android.view.View.OnClickListener
public final void onClick(View view) {
LoadingView.this.a(view);
}
});
}
public void b() {
if (this.l) {
return;
}
this.k++;
if (this.j == this.k) {
setVisibility(8);
this.c.setVisibility(8);
this.f.setVisibility(8);
this.g.setVisibility(8);
this.b.clearAnimation();
RotateAnimation rotateAnimation = this.d;
if (rotateAnimation != null) {
rotateAnimation.cancel();
}
}
}
public void c() {
if (this.d == null) {
this.d = new RotateAnimation(0.0f, 359.0f, 1, 0.5f, 1, 0.5f);
this.d.setRepeatCount(-1);
this.d.setDuration(800L);
this.d.setInterpolator(new LinearInterpolator());
this.d.setRepeatMode(1);
}
setVisibility(0);
this.c.setVisibility(0);
this.f.setVisibility(8);
this.g.setVisibility(8);
this.e.setVisibility(0);
this.b.setVisibility(0);
this.b.startAnimation(this.d);
}
public void d() {
setVisibility(0);
this.c.setVisibility(0);
this.f.setVisibility(0);
this.g.setVisibility(0);
this.e.setVisibility(8);
this.b.setVisibility(8);
this.b.clearAnimation();
this.f.setImageResource(R.drawable.ic_network_error);
this.g.setText(R.string.loading_error);
}
public void e() {
a(R.string.loading_service_error, R.drawable.ic_try_reload);
}
public void f() {
if (this.l) {
return;
}
this.k++;
if (this.j == this.k) {
h();
}
}
public void g() {
if (this.l) {
return;
}
if (this.d == null) {
this.d = new RotateAnimation(0.0f, 359.0f, 1, 0.5f, 1, 0.5f);
this.d.setRepeatCount(-1);
this.d.setDuration(800L);
this.d.setInterpolator(new LinearInterpolator());
this.d.setRepeatMode(1);
this.b.setAnimation(this.d);
}
if (this.j == this.k) {
setVisibility(0);
this.c.setVisibility(0);
this.f.setVisibility(8);
this.g.setVisibility(8);
this.e.setVisibility(0);
this.b.setVisibility(0);
this.b.startAnimation(this.d);
}
this.j++;
}
public void h() {
setVisibility(0);
this.c.setVisibility(0);
this.f.setVisibility(0);
this.g.setVisibility(0);
this.e.setVisibility(8);
this.b.setVisibility(8);
RotateAnimation rotateAnimation = this.d;
if (rotateAnimation != null) {
rotateAnimation.cancel();
}
}
public void setBackgroundViewColor(int i) {
RelativeLayout relativeLayout = this.c;
if (relativeLayout != null) {
relativeLayout.setBackgroundColor(i);
}
}
public void setIsRefresh(boolean z) {
this.l = z;
}
public void setOnRetryListener(RetryRequest retryRequest) {
this.m = retryRequest;
}
public void setServiceLoadingError(int i) {
this.f.setImageResource(i);
}
public void setServiceTextError(int i) {
this.g.setText(this.h.getString(i));
}
public LoadingView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.l = false;
a(context);
}
public LoadingView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.l = false;
a(context);
}
public /* synthetic */ void a(View view) {
RetryRequest retryRequest = this.m;
if (retryRequest != null) {
retryRequest.OnRetryListener();
return;
}
if (this.f.getVisibility() == 0) {
this.j = 0;
this.k = 0;
try {
if (this.i == 0) {
for (SubscriberModel subscriberModel : Manager.mList) {
CommunityManager.create().toSubscribe(subscriberModel.getObservable(), subscriberModel.getSubscriber());
}
return;
}
if (this.i <= Manager.mList.size()) {
for (int size = Manager.mList.size(); size > 0; size--) {
int i = size - 1;
CommunityManager.create().toSubscribe(Manager.mList.get(i).getObservable(), Manager.mList.get(i).getSubscriber());
this.i--;
if (this.i == 0) {
return;
}
}
return;
}
throw new Exception("设置的需要刷新的 条目 比总的请求数要多");
} catch (Exception e) {
LogUtils.c(e.toString());
}
}
}
public void a() {
this.b.clearAnimation();
}
public void a(int i, int i2) {
setVisibility(0);
this.c.setVisibility(0);
this.f.setVisibility(0);
this.g.setVisibility(0);
this.e.setVisibility(8);
this.b.setVisibility(8);
this.b.clearAnimation();
this.f.setImageResource(i2);
this.g.setText(i);
}
}