package com.npaduch.reminder;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by nolanpaduch on 5/8/14.
 *
 * Fragment to create a new reminder.
 */

public class NewReminderFragment extends Fragment {

    // Communication with main activity
    FragmentCommunicationListener messenger;

    public NewReminderFragment() {
    }

    // Container Activity must implement this interface
    public interface FragmentCommunicationListener {
        public void send(Bundle message);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception
        try {
            messenger = (FragmentCommunicationListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement NewNoteFragment.FragmentCommunicationListener");
        }
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.new_reminder, container, false);

        ReminderCardView myCard = new ReminderCardView(getActivity());
        myCard.description.setText("This is another description, purely to avoid warnings...");

        setHasOptionsMenu(true);

        return rootView;
    }

    @Override
    public void onCreateOptionsMenu(
            Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.new_reminder_fragment, menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
            case R.id.action_cancel_new_reminder:
                Bundle b = new Bundle();
                b.putString("Task","Change Fragment");
                b.putInt("page",MainActivity.REMINDER_LIST);
                messenger.send(b);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    // TODO: Override back button to return to list fragment

}
@@ -301,16 +301,83 @@
 ewGroup;
+%0Aimport android.widget.ArrayAdapter;%0Aimport android.widget.Spinner;
 %0A%0A/**%0A *
@@ -1310,24 +1310,25 @@
     %7D%0A    %7D%0A
+%0A
     @Overrid
@@ -1710,24 +1710,111 @@
 ings...%22);%0A%0A
+        // initialize Spinners with string data%0A        initializeSpinners(rootView);%0A%0A
         setH
@@ -2758,67 +2758,918 @@
  %7D%0A%0A
-    // TODO: Override back button to return to list fragment
+%0A    public  void initializeSpinners(View view)%7B%0A%0A        // locate spinners%0A        Spinner daySpinner = (Spinner) view.findViewById(R.id.newReminderDaySpinner);%0A        Spinner timeSpinner = (Spinner) view.findViewById(R.id.newReminderTimeSpinner);%0A%0A        // setup day spin adapter%0A        ArrayAdapter%3CCharSequence%3E dayAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.spinner_day, android.R.layout.simple_spinner_item);%0A        dayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);%0A        daySpinner.setAdapter(dayAdapter);%0A%0A        // setup time spin adapter%0A        ArrayAdapter%3CCharSequence%3E timeAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.spinner_time, android.R.layout.simple_spinner_item);%0A        timeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);%0A        timeSpinner.setAdapter(timeAdapter);%0A    %7D%0A
 %0A%0A%7D

Initialize spinners on new reminder page