package com.yyrh.ui.fragment;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageButton;


import com.yyrh.constant.SDKSettings;
import com.yyrh.constant.URLConstants;
import com.yyrh.ui.dialog.WvPageListDialog;
import com.yyrh.utils.ResourceUtil;
import com.yyrh.utils.Utils;

import java.util.HashMap;

public class BaseFragment extends Fragment implements View.OnClickListener {
    private ImageButton btn_kefu;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        btn_kefu = view.findViewById(ResourceUtil.getId(getActivity(),"btn_kefu"));
        if (btn_kefu != null){
            btn_kefu.setOnClickListener(this);
        }

    }

    public void addFragmentToActivity(FragmentManager fragmentManager,
                                      android.app.Fragment fragment, int frameId) {
        Utils.checkNotNull(fragmentManager);
        Utils.checkNotNull(fragment);
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.add(frameId, fragment).addToBackStack(null);
        transaction.commit();
    }

    public void replaceFragmentToActivity(FragmentManager fragmentManager, android.app.Fragment fragment, int frameId) {
        Utils.checkNotNull(fragmentManager);
        Utils.checkNotNull(fragment);

        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(frameId, fragment);
        transaction.commit();
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == ResourceUtil.getId(getActivity(), "btn_kefu")){

            if (!Utils.judgeStrNull(SDKSettings.initConfig.service_center)){


                new WvPageListDialog(getActivity(),ResourceUtil.getStyleId(getActivity(),"hnyy_half_black_dialog"),SDKSettings.initConfig.service_center).show();

            }


        }
    }
}
