44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package com.ubtech.view.fragment;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public abstract class LazyLoadFragment extends Fragment {
|
|
private boolean isLoaded;
|
|
protected Activity mActivity;
|
|
|
|
protected void lazyLoad() {
|
|
if (this.isLoaded && getUserVisibleHint()) {
|
|
loadData();
|
|
this.isLoaded = false;
|
|
}
|
|
}
|
|
|
|
protected abstract void loadData();
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onAttach(Context context) {
|
|
super.onAttach(context);
|
|
this.mActivity = (Activity) context;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onViewCreated(View view, Bundle bundle) {
|
|
super.onViewCreated(view, bundle);
|
|
this.isLoaded = true;
|
|
lazyLoad();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void setUserVisibleHint(boolean z) {
|
|
super.setUserVisibleHint(z);
|
|
if (z) {
|
|
lazyLoad();
|
|
}
|
|
}
|
|
}
|