package ca.ualberta.cs.cmput301t02project.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import ca.ualberta.cs.cmput301t02project.R;
import ca.ualberta.cs.cmput301t02project.controller.CommentController;

/**
 * Allows a user to edit the comment they selected.
 */
public class EditCommentActivity extends Activity {

			
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		String commentId = getIntent().getStringExtra("CommentId");
		final CommentController commentController = new CommentController(commentId, this);
			
		setContentView(R.layout.activity_edit_comment);
		
		EditText inputComment = (EditText) findViewById(R.id.edit_text);

		inputComment.setText(commentController.getText());
		
		final EditText latitude = (EditText) findViewById(R.id.latitude_editBox);
		final EditText longitude = (EditText) findViewById(R.id.longitude_editBox);
		
		double commentLat = commentController.getComment().getLocation().getLatitude();
		double commentLon = commentController.getComment().getLocation().getLongitude();
		final String strLat = String.valueOf(commentLat);
		final String strLon = String.valueOf(commentLon);
		
		latitude.setText(strLat);
		longitude.setText(strLon);


		Button post = (Button) findViewById(R.id.edit_post);
		
		post.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//for editing text
				EditText inputComment = (EditText) findViewById(R.id.edit_text);
				String newText = inputComment.getText().toString();
				
				//for editing locations
				double lat = 0, lon = 0;
				lat = Double.valueOf(latitude.getText().toString());
				lon = Double.valueOf(longitude.getText().toString());
				
				commentController.edit(newText, lat, lon);
	
				
				finish();
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.create_comment, menu);
		return true;
	}
}

@@ -1737,16 +1737,27 @@
 on = 0;%0A
+%09%09%09%09try %7B%0A%09
 %09%09%09%09lat 
@@ -1801,24 +1801,25 @@
 oString());%0A
+%09
 %09%09%09%09lon = Do
@@ -1860,24 +1860,215 @@
 oString());%0A
+%09%09%09%09%7D catch  (NumberFormatException ex)%7B%0A%09%09%09%09%09lat =  commentController.getComment().getLocation().getLatitude();%0A%09%09%09%09%09lon = commentController.getComment().getLocation().getLongitude();%0A%09%09%09%09%7D%0A
 %09%09%09%09%0A%09%09%09%09com

edit location handles bad user input now