package com.hikapro.backpack.view.fragments;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hikapro.backpack.R;
import com.hikapro.backpack.presenter.Presenter;

/**
 * A simple {@link Fragment} subclass.
 */
public class ShareFragment extends Fragment implements com.hikapro.backpack.view.View.Share {

    private Presenter.Share presenter;
    private com.hikapro.backpack.view.View.ActivityCallback activityCallback;


    public ShareFragment() {
        // Required empty public constructor
    }

    public static ShareFragment construct() {
        ShareFragment ret = new ShareFragment();
        return ret;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            activityCallback = (com.hikapro.backpack.view.View.ActivityCallback) context;
        } catch (ClassCastException e) {
            throw new ClassCastException(context.toString()
                    + " must implement activityCallback");
        }
    }
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            activityCallback = (com.hikapro.backpack.view.View.ActivityCallback) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement activityCallback");
        }
        Log.i(this.toString(), "onAttach");
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        presenter.setView(this);
        View v = presenter.onCreateView(inflater, container, savedInstanceState);
        return v;
    }

    @Override
    public void setPresenter(Presenter.Share presenter) {
        this.presenter = presenter;
    }

    @Override
    public Context getAppContext() {
        return this.getActivity().getApplicationContext();
    }

    @Override
    public Context getActivityContext() {
        return this.getActivity();
    }
}
