package xn.hxp.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewbinding.ViewBinding;

import io.reactivex.rxjava3.disposables.Disposable;

public abstract class BaseFragment extends Fragment {
    private BaseFragmentHelp baseFragmentHelp;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return setViewBinding(inflater, container).getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        baseFragmentHelp = new BaseFragmentHelp(this);
        onInit();
    }

    protected abstract ViewBinding setViewBinding(@NonNull LayoutInflater inflater, @Nullable ViewGroup container);

    protected abstract void onInit();

    protected void showLoading(String msg) {
        baseFragmentHelp.showLoading(msg);
    }

    protected void dismissLoading() {
        baseFragmentHelp.dismissLoading();
    }

    public void showToast(String msg) {
        baseFragmentHelp.showToast(msg);
    }

    public void showSuccess(String msg) {
        baseFragmentHelp.showSuccess(msg);
    }

    public void showErr(String msg) {
        baseFragmentHelp.showErr(msg);
    }

    public void showErr(String msg, String hint) {
        baseFragmentHelp.showErr(msg, hint);
    }

    @Override
    public void onDestroyView() {
        if (null != baseFragmentHelp) {
            baseFragmentHelp.onDestroy();
            baseFragmentHelp = null;
        }
        super.onDestroyView();
    }
}
