package com.walkap.x_android.fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.walkap.x_android.R;
import com.walkap.x_android.adapter.SectionsPagerAdapter;
import com.walkap.x_android.fragment.days.FridayFragment;
import com.walkap.x_android.fragment.days.MondayFragment;
import com.walkap.x_android.fragment.days.SaturdayFragment;
import com.walkap.x_android.fragment.days.ThursdayFragment;
import com.walkap.x_android.fragment.days.TuesdayFragment;
import com.walkap.x_android.fragment.days.WednesdayFragment;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link HomeFragment.OnFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends BaseFragment{

    private OnFragmentInteractionListener mListener;

    private final String TAG = "HomeFragment";

    private SectionsPagerAdapter mSectionsPagerAdapter;

    private ViewPager mViewPager;

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

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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
        mViewPager = (ViewPager) rootView.findViewById(R.id.view_pager);
        mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mSectionsPagerAdapter);
        mViewPager.setOffscreenPageLimit(6);
        tabLayout.setupWithViewPager(mViewPager);

        return rootView;
    }

    @Override
    public void onStart(){
        super.onStart();

    }

    // 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(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.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
        void onFragmentInteraction(Uri uri);
    }

}

@@ -433,362 +433,34 @@
 er;%0A
-import com.walkap.x_android.fragment.days.FridayFragment;%0Aimport com.walkap.x_android.fragment.days.MondayFragment;%0Aimport com.walkap.x_android.fragment.days.SaturdayFragment;%0Aimport com.walkap.x_android.fragment.days.ThursdayFragment;%0Aimport com.walkap.x_android.fragment.days.TuesdayFragment;%0Aimport com.walkap.x_android.fragment.days.WednesdayFragment
+%0Aimport java.util.Calendar
 ;%0A%0A/
@@ -1003,24 +1003,143 @@
 ViewPager;%0A%0A
+    private Calendar calendar = Calendar.getInstance();%0A    private int day = calendar.get(Calendar.DAY_OF_WEEK) - 2;%0A%0A
     public H
@@ -1938,16 +1938,16 @@
 mit(6);%0A
-
         
@@ -1985,24 +1985,65 @@
 iewPager);%0A%0A
+        mViewPager.setCurrentItem(day);%0A%0A
         retu

set the current day base on the day of the week