package com.fuban.driver.base;
|
|
import android.content.Intent;
|
import android.os.Bundle;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
|
import androidx.annotation.Nullable;
|
import androidx.fragment.app.FragmentActivity;
|
|
|
import com.fuban.driver.R;
|
import com.fuban.driver.ui.DialogUtil;
|
import com.fuban.driver.utils.EasePopup.EasyPopup;
|
|
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.ThreadMode;
|
|
import cn.sinata.xldutils.fragment.BaseFragment;
|
|
|
/**
|
* MyBaseFragment
|
*
|
* @author Administrator
|
* @date 2018/5/16
|
*/
|
public abstract class MyBaseFragment extends BaseFragment {
|
protected final int PAGE_SIZE = 10;//每页条数
|
protected int pageNumber = 1;//当前第几页
|
public FragmentActivity mContext;
|
public EasyPopup easyPopup;
|
|
@Override
|
protected int getContentViewLayoutID() {
|
return 0;
|
}
|
|
@Override
|
protected void onFirstVisibleToUser() {
|
|
}
|
|
@Override
|
protected void onVisibleToUser() {
|
|
}
|
|
@Override
|
protected void onInvisibleToUser() {
|
|
}
|
|
@Nullable
|
@Override
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
// View view = inflater.inflate(layoutId(),container,false);
|
View view = LayoutInflater.from(getActivity()).inflate(layoutId(),container,false);
|
mContext = getActivity();
|
EventBus.getDefault().register(this);
|
return view;
|
}
|
|
@Override
|
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
super.onViewCreated(view, savedInstanceState);
|
initView();
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
}
|
|
public abstract int layoutId();
|
|
public abstract void initView();
|
|
|
public void startActivity(Class tClass){
|
startActivity(new Intent(mContext,tClass));
|
}
|
|
@Override
|
public void showDialog() {
|
// super.showDialog();
|
if (easyPopup == null){
|
easyPopup = DialogUtil.INSTANCE.getPopupwindow(getActivity(), R.layout.progress_dialog_main);
|
}
|
if (easyPopup.isShowing()){
|
return;
|
}
|
FragmentActivity activity = getActivity();
|
if (activity != null && activity.getWindow() != null) {
|
try {
|
getActivity().getWindow().getDecorView().post(() -> easyPopup.showCenter(getActivity().getWindow().getDecorView()));
|
}catch (Exception e){
|
|
}
|
}
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
if (easyPopup != null && easyPopup.isShowing()){
|
easyPopup.dismiss();
|
}
|
}
|
|
@Override
|
public void dismissDialog() {
|
// super.dismissDialog();?
|
if (easyPopup == null){
|
easyPopup = DialogUtil.INSTANCE.getPopupwindow(getActivity(),R.layout.progress_dialog_main);
|
}
|
easyPopup.dismiss();
|
}
|
|
@Override
|
public void onDestroyView() {
|
super.onDestroyView();
|
EventBus.getDefault().unregister(this);
|
}
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onEventMainThread(BaseEvent event) {
|
|
}
|
}
|