191 lines
5.3 KiB
Java
191 lines
5.3 KiB
Java
package com.ubt.jimu.base.mvp;
|
|
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.fragment.app.Fragment;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.event.MessageEvent;
|
|
import com.ubt.jimu.base.mvp.BaseMvpPresenter;
|
|
import com.ubt.jimu.widgets.JAlertDialog;
|
|
import com.ubtech.view.widget.ToastView;
|
|
import com.ubtrobot.log.ALog;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
/* loaded from: classes.dex */
|
|
public abstract class BaseMvpFragment<P extends BaseMvpPresenter> extends Fragment implements BaseRxView {
|
|
private static final String TAG = "BaseMvpFragment";
|
|
private boolean isInit;
|
|
private boolean isInitData;
|
|
private boolean isVisible;
|
|
private String mCurrentName;
|
|
protected JAlertDialog mJAlertDialog;
|
|
public P mPresenter;
|
|
public View rootView;
|
|
|
|
public abstract P createPresenter();
|
|
|
|
public abstract int getLayoutID();
|
|
|
|
protected void hideLoading() {
|
|
JAlertDialog jAlertDialog = this.mJAlertDialog;
|
|
if (jAlertDialog == null) {
|
|
return;
|
|
}
|
|
try {
|
|
jAlertDialog.dismiss();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.mvp.BaseView
|
|
public void hideLoadingDialog() {
|
|
hideLoading();
|
|
}
|
|
|
|
public void init(View view, Bundle bundle) {
|
|
initView(view, bundle);
|
|
}
|
|
|
|
protected void initData() {
|
|
}
|
|
|
|
protected void initFirstData() {
|
|
if (this.isInitData) {
|
|
return;
|
|
}
|
|
this.isInitData = true;
|
|
initData();
|
|
}
|
|
|
|
public void initView(View view, Bundle bundle) {
|
|
}
|
|
|
|
public boolean isRegistEventBus() {
|
|
return false;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
if (isRegistEventBus()) {
|
|
EventBus.b().c(this);
|
|
}
|
|
if (this.mPresenter == null) {
|
|
this.mPresenter = createPresenter();
|
|
}
|
|
P p = this.mPresenter;
|
|
if (p != null) {
|
|
p.attachModelView(this);
|
|
}
|
|
this.mCurrentName = toString();
|
|
ALog.a(TAG).d(this.mCurrentName + "OnCreate");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
|
|
if (this.rootView == null) {
|
|
this.rootView = layoutInflater.inflate(getLayoutID(), viewGroup, false);
|
|
}
|
|
return this.rootView;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
this.isInitData = false;
|
|
this.isInit = false;
|
|
this.isVisible = false;
|
|
ALog.a(TAG).d(this.mCurrentName + "onDestroy");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDestroyView() {
|
|
super.onDestroyView();
|
|
EventBus.b().d(this);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onDetach() {
|
|
super.onDetach();
|
|
P p = this.mPresenter;
|
|
if (p != null) {
|
|
p.detachView();
|
|
}
|
|
ALog.a(TAG).d(this.mCurrentName + "onDetach");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onPause() {
|
|
super.onPause();
|
|
ALog.a(TAG).d(this.mCurrentName + "OnPause");
|
|
}
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
public void onReceiveMessage(MessageEvent messageEvent) {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onResume() {
|
|
super.onResume();
|
|
ALog.a(TAG).d(this.mCurrentName + "OnResume");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onStop() {
|
|
super.onStop();
|
|
ALog.a(TAG).d(this.mCurrentName + "OnStop");
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void onViewCreated(View view, Bundle bundle) {
|
|
super.onViewCreated(view, bundle);
|
|
init(view, bundle);
|
|
this.isInit = true;
|
|
if (this.isInit && this.isVisible) {
|
|
initFirstData();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void setUserVisibleHint(boolean z) {
|
|
super.setUserVisibleHint(z);
|
|
this.isVisible = z;
|
|
if (this.isVisible && this.isInit) {
|
|
initFirstData();
|
|
}
|
|
}
|
|
|
|
protected void showLoading(String str) {
|
|
JAlertDialog jAlertDialog = this.mJAlertDialog;
|
|
if (jAlertDialog == null) {
|
|
JAlertDialog.Builder builder = new JAlertDialog.Builder(getContext());
|
|
builder.a(R.drawable.ic_loading);
|
|
builder.a(str);
|
|
builder.a(true);
|
|
this.mJAlertDialog = builder.a();
|
|
} else {
|
|
jAlertDialog.a(str);
|
|
}
|
|
this.mJAlertDialog.show();
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.mvp.BaseView
|
|
public void showLoadingDialog(String str) {
|
|
showLoading(str);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.mvp.BaseView
|
|
public void showToast(int i) {
|
|
ToastView.a(getContext(), getResources().getString(i), ToastView.Type.NORMAL).a();
|
|
}
|
|
|
|
public void toast(String str) {
|
|
ToastView.a(getContext(), str, ToastView.Type.NORMAL).a();
|
|
}
|
|
}
|