package com.example.administrator.zhapp.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

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

import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.administrator.zhapp.BuildConfig;

/**
 * Created by Administrator on 2016/9/icon5.
 */
public abstract class BaseFragment extends Fragment {

    public static final int CX_FLAG = 0;//查询的状态码
    public static final int SC_FLAG = 1;//上传的状态码

    public abstract int getContentViewId();

    public Activity mActivity;
    public View view;
    public Context context;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
        mActivity = getActivity();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        this.context = null;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(getContentViewId(), container, false);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        initData();
    }

    /**
     * 初始化视图
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    public void showToast(String msg) {
        Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
    }

    public void showToast(int strId) {
        Toast.makeText(getContext(), strId, Toast.LENGTH_SHORT).show();
    }

    public void showLog(String logText) {
        if (BuildConfig.LOG_ERROR) {
            if (TextUtils.isEmpty(logText)) {
                Log.i("app", "logText is null");
            } else {
                Log.i("app", logText);
            }
        }
    }
}
