package net.iquesoft.project.seed.presentation.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;

import net.iquesoft.project.seed.presentation.di.HasComponent;
import net.iquesoft.project.seed.presentation.navigation.Navigator;
import net.iquesoft.project.seed.utils.ToastMaker;

import javax.inject.Inject;

public abstract class BaseFragment extends Fragment {

    @Inject
    Navigator navigator;
    android.support.v4.app.FragmentManager fragmentManager;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initializeInjection();
    }

    /**
     * Shows a {@link android.widget.Toast} message.
     *
     * @param message An string representing a message to be shown.
     */
    protected void showToast(String message) {
        ToastMaker.showMessage(getActivity(), message);
    }

    abstract void initializeInjection();

    /**
     * Gets a component for dependency injection by its type.
     */
    @SuppressWarnings("unchecked")
    protected <C> C getComponent(Class<C> componentType) {
        return componentType.cast(((HasComponent<C>) getActivity()).getComponent());
    }

}
