package com.gh.gamecenter.common.base.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.MotionEvent;

import androidx.annotation.IdRes;
import androidx.annotation.MenuRes;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import com.gh.gamecenter.common.constant.EntranceConsts;

/**
 * Created by khy on 17/10/17.
 */

public abstract class ToolbarFragment extends BaseFragment {

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null && !TextUtils.isEmpty(getArguments().getString(EntranceConsts.KEY_ENTRANCE)))
            mEntrance = getArguments().getString(EntranceConsts.KEY_ENTRANCE);
    }

    protected void setNavigationTitle(String title) {
        if (getActivity() instanceof ToolbarController) {
            ((ToolbarController) getActivity()).setNavigationTitle(title);
        }
    }

    protected void setNavigationTitle(@StringRes int title) {
        if (getActivity() instanceof ToolbarController) {
            ((ToolbarController) getActivity()).setNavigationTitle(title);
        }
    }

    protected void initMenu(@MenuRes int res) {
        if (getActivity() instanceof ToolbarController) {
            ((ToolbarController) getActivity()).setToolbarMenu(res);
        }
    }

    protected MenuItem getItemMenu(@IdRes int res) {
        if (getActivity() instanceof ToolbarController) {
            return ((ToolbarController) getActivity()).getMenuItem(res);
        }
        return null;
    }

    protected void showAdLabel(Boolean isAd) {
        if (getActivity() instanceof ToolbarController) {
            ((ToolbarController) getActivity()).showAdLabel(isAd);
        }
    }

    public void onTouchEvent(MotionEvent event) {

    }

    public void onMenuItemClick(MenuItem menuItem) {

    }

    public boolean onBackPressed() {
        return false;
    }

}
