package any.tv.mobile.gamerstm.fragments;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;

import any.tv.mobile.gamerstm.Application;
import any.tv.mobile.gamerstm.modules.CommentsService;
import any.tv.mobile.gamerstm.modules.GamersService;

/**
 * Created by adin234 on 10/26/15.
 */
public class BaseFragment extends Fragment {
    private OnFragmentInteractionListener mListener;
    protected View mainView;
    protected Context c;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        c = getActivity();
    }

    @Override
    public void onViewCreated(View v, Bundle savedInstanceState) {
        this.mainView = v;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnFragmentInteractionListener) activity;
        } catch (ClassCastException e) {
            //throw new ClassCastException(activity.toString() + " must implement OnFragmentInteractionListener");
        }
    }

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

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        public void onFragmentInteraction(Uri uri);
    }

    public GamersService getGamersService() {
        return ((Application) getActivity().getApplication()).getGamersService();
    }

    public CommentsService getCommentsService() {
        return ((Application) getActivity().getApplication()).getCommentsService();
    }
}
