140 lines
4.1 KiB
Java
140 lines
4.1 KiB
Java
package com.xscm.moduleutil.base;
|
|
|
|
import android.app.Activity;
|
|
import android.graphics.Color;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Bundle;
|
|
import android.view.Gravity;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.Window;
|
|
import android.view.WindowManager;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.databinding.DataBindingUtil;
|
|
import androidx.databinding.ViewDataBinding;
|
|
import androidx.fragment.app.DialogFragment;
|
|
|
|
import com.xscm.moduleutil.R;
|
|
import com.xscm.moduleutil.activity.BaseAppCompatActivity;
|
|
import com.xscm.moduleutil.activity.IPresenter;
|
|
import com.xscm.moduleutil.activity.IView;
|
|
|
|
/**
|
|
*@author qx
|
|
*@data 2025/5/29
|
|
*@description: dialogFragement基类
|
|
*/
|
|
public abstract class BaseMvpDialogFragment<P extends IPresenter, VDM extends ViewDataBinding> extends DialogFragment implements IView<Activity> {
|
|
protected VDM mBinding;
|
|
|
|
protected P MvpPre;
|
|
|
|
protected abstract P bindPresenter();
|
|
|
|
protected boolean setDialogWH = true;
|
|
protected boolean isAnimation = true;
|
|
protected boolean mGravityBOTTOM;
|
|
|
|
@Override
|
|
public Activity getSelfActivity() {
|
|
return getActivity();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
// ARouter.getInstance().inject(this);
|
|
mBinding = DataBindingUtil.inflate(inflater, getLayoutId(), container, false);
|
|
mBinding.setLifecycleOwner(this);
|
|
return mBinding.getRoot();
|
|
}
|
|
|
|
@Override
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
super.onViewCreated(view, savedInstanceState);
|
|
MvpPre = bindPresenter();
|
|
if (getArguments() != null) {
|
|
initArgs(getArguments());
|
|
}
|
|
initView();
|
|
initData();
|
|
}
|
|
|
|
|
|
public void initArgs(Bundle arguments) {
|
|
|
|
}
|
|
|
|
protected abstract void initData();
|
|
|
|
protected abstract void initView();
|
|
|
|
protected abstract int getLayoutId();
|
|
|
|
@Override
|
|
public void onStart() {
|
|
super.onStart();
|
|
if (getDialog() != null && setDialogWH) {
|
|
Window window = getDialog().getWindow();
|
|
if (mGravityBOTTOM) {
|
|
window.setGravity(Gravity.BOTTOM);
|
|
}
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
|
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
|
|
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
if (isAnimation) {
|
|
window.setWindowAnimations(R.style.CommonShowDialogBottom);
|
|
}
|
|
// window.getDecorView().setPadding(0, 0, 0, 0);
|
|
initDialogStyle(window);
|
|
}
|
|
}
|
|
|
|
protected void initDialogStyle(Window window) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void showLoadings() {
|
|
if (!isAdded() || getActivity() == null) {
|
|
return;
|
|
}
|
|
if (getActivity() instanceof BaseAppCompatActivity) {
|
|
((BaseAppCompatActivity) getActivity()).showLoading("加载中...");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void showLoadings(String content) {
|
|
if (!isAdded() || getActivity() == null) {
|
|
return;
|
|
}
|
|
if (getActivity() instanceof BaseAppCompatActivity) {
|
|
((BaseAppCompatActivity) getActivity()).showLoading(content);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void disLoadings() {
|
|
if (getActivity() instanceof BaseAppCompatActivity) {
|
|
((BaseAppCompatActivity) getActivity()).disLoading();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onDestroyView() {
|
|
if (mBinding != null) {
|
|
mBinding.unbind();
|
|
}
|
|
if (MvpPre != null) {
|
|
MvpPre.detachView();
|
|
}
|
|
super.onDestroyView();
|
|
}
|
|
}
|