package ca.stephenjust.todolist;

import android.app.Activity;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


public class TodoEditFragment extends DialogFragment {
	// TODO: Rename parameter arguments, choose names that match
	// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
	private static final String ARG_ITEM = "todo_item";

	// TODO: Rename and change types of parameters
	private String m_item;

	private OnFragmentInteractionListener mListener;

	private EditText m_editText;
	
	/**
	 * Use this factory method to create a new instance of this fragment using
	 * the provided parameters.
	 * 
	 * @param param1
	 *            Parameter 1.
	 * @param param2
	 *            Parameter 2.
	 * @return A new instance of fragment TodoEditFragment.
	 */
	// TODO: Rename and change types and number of parameters
	public static TodoEditFragment newInstance(String item) {
		TodoEditFragment fragment = new TodoEditFragment();
		Bundle args = new Bundle();
		args.putString(ARG_ITEM, item);
		fragment.setArguments(args);
		return fragment;
	}

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

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		if (getArguments() != null) {
			m_item = getArguments().getString(ARG_ITEM);
		}
		setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Holo_Light_Dialog_MinWidth);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		View view = inflater.inflate(R.layout.fragment_todo_edit, container,
				false);
		m_editText = (EditText) view.findViewById(R.id.editItemText);
		m_editText.setText(m_item);
		Button b = (Button) view.findViewById(R.id.editItemSave);
		b.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mListener != null) {
					Bundle bundle = new Bundle();
					bundle.putString("fragment", "edit");
					bundle.putString("value", m_editText.getText().toString());
					mListener.onFragmentInteraction(bundle);
				}
				dismiss();
			}
			
		});
		
		return view;
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@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 {
		public void onFragmentInteraction(Bundle bundle);
	}

}

@@ -320,189 +320,164 @@
 ;%0A%0A%0A
-public class TodoEditFragment extends DialogFragment %7B%0A%09// TODO: Rename parameter arguments, choose names that match%0A%09// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+/**%0A * Dialog that prompts for the text of a to-do item.%0A * @author Stephen Just%0A *%0A */%0Apublic class TodoEditFragment extends DialogFragment %7B%0A%09// Arguments
 %0A%09pr
@@ -531,56 +531,8 @@
 %22;%0A%0A
-%09// TODO: Rename and change types of parameters%0A
 %09pri
@@ -548,16 +548,14 @@
 ng m
-_i
+I
 tem;%0A
-%0A
 %09pri
@@ -600,17 +600,16 @@
 stener;%0A
-%0A
 %09private
@@ -619,18 +619,17 @@
 itText m
-_e
+E
 ditText;
@@ -761,14 +761,12 @@
 ram 
-param1
+item
 %0A%09 *
@@ -781,65 +781,37 @@
     
-Parameter 1.%0A%09 * @param param2%0A%09 *            Parameter 2
+To-do item text, may be blank
 .%0A%09 
@@ -874,67 +874,8 @@
  */%0A
-%09// TODO: Rename and change types and number of parameters%0A
 %09pub
@@ -1309,18 +1309,17 @@
 ) %7B%0A%09%09%09m
-_i
+I
 tem = ge
@@ -1397,17 +1397,21 @@
 O_TITLE,
- 
+%0A%09%09%09%09
 android.
@@ -1696,26 +1696,25 @@
 %09false);%0A%09%09m
-_e
+E
 ditText = (E
@@ -1763,18 +1763,17 @@
 xt);%0A%09%09m
-_e
+E
 ditText.
@@ -1781,18 +1781,17 @@
 etText(m
-_i
+I
 tem);%0A%09%09
@@ -2081,18 +2081,17 @@
 alue%22, m
-_e
+E
 ditText.
@@ -2185,19 +2185,16 @@
 );%0A%09%09%09%7D%0A
-%09%09%09
 %0A%09%09%7D);%0A%09
@@ -2218,69 +2218,8 @@
 %09%7D%0A%0A
-%09@Override%0A%09public void onResume() %7B%0A%09%09super.onResume();%0A%09%7D%0A%0A
 %09@Ov
@@ -2827,207 +2827,8 @@
 ty.%0A
-%09 * %3Cp%3E%0A%09 * See the Android Training lesson %3Ca href=%0A%09 * %22http://developer.android.com/training/basics/fragments/communicating.html%22%0A%09 * %3ECommunicating with Other Fragments%3C/a%3E for more information.%0A
 %09 */

Clean up TodoEditFragment code.