<commit_before>/*

Copyright 2015 Team3ScandalouStopwatch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

/* EditExpenseActivity.java Basic Info:
 *  Activity takes an expense from the ExpenseListActivity and allows 
 *  the user to edit information about the expense.
 */

package ca.ualberta.cs.scandaloutraveltracker;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class EditExpenseActivity extends Activity implements ViewInterface {

	private ClaimController claimController;
	private Claim currentClaim;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit_expense);
		
		//makes sure that the position of the claim and corresponding 
		//expense to be edited are actually passed to this activity
		Bundle extras = getIntent().getExtras();
		int claimId =-1;
		int expenseId =-1;
		Intent intent = getIntent();
	    claimId = (int) intent.getIntExtra(Constants.claimIdLabel, -1);
		expenseId = (int) extras.getLong("expenseId", -1);
		if (claimId == -1) {
			Toast.makeText(this, "The Claim Position needs to be added to the " +
					"EditExpenseActivity intent before startActivity(intent) is called",
					Toast.LENGTH_LONG).show();
			finish();
		}
		else if (expenseId == -1) {
			Toast.makeText(this, "The Expense Position needs to be added to the " +
					"EditExpenseActivity intent before startActivity(intent) is called",
					Toast.LENGTH_LONG).show();
			finish();
		}
		
		//TODO - Delete Toast Later
		Toast.makeText(this, "Expense Position " + expenseId,
				Toast.LENGTH_SHORT).show();
		
		//Set currentClaim to the claim that was selected via intent
		currentClaim = new Claim((int)claimId);
	    claimController = new ClaimController(currentClaim);
		
	    //initialize fields 
		EditText description = (EditText) findViewById(R.id.description);
		EditText date = (EditText) findViewById(R.id.date_expense);
		EditText cost = (EditText) findViewById(R.id.amount);
		Spinner category = (Spinner) findViewById(R.id.catspinner);
		Spinner currencyType = (Spinner) findViewById(R.id.currencyspinner);
		String categoryString = claimController.getExpense(expenseId).getCategory();
		String currencyString = claimController.getExpense(expenseId).getCurrencyType();
	
		//set fields to correct values
		description.setText(claimController.getExpense(expenseId)
				.getDescription());
		date.setText(claimController.getExpense(expenseId)
				.getDateString());
		cost.setText(""+claimController.getExpense(expenseId)
				.getCost());
		category.setSelection(getIndex(category, categoryString));
		currencyType.setSelection(getIndex(currencyType, currencyString));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.view_expense, menu);
		return true;
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	public void update() {
		// TODO Auto-generated method stub
		
	}
	
	//is called when edit button is clicked
	public void confirmEdit(View v) {
		Toast.makeText(this, "Editting done bro!",
				Toast.LENGTH_SHORT).show();
	}
	<commit_msg>Has error handling when editing expenses<commit_after>/*

Copyright 2015 Team3ScandalouStopwatch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

/* EditExpenseActivity.java Basic Info:
 *  Activity takes an expense from the ExpenseListActivity and allows 
 *  the user to edit information about the expense.
 */

package ca.ualberta.cs.scandaloutraveltracker;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class EditExpenseActivity extends Activity implements ViewInterface {

	private ClaimController claimController;
	private Claim currentClaim;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit_expense);
		
		//makes sure that the position of the claim and corresponding 
		//expense to be edited are actually passed to this activity
		Bundle extras = getIntent().getExtras();
		int claimId =-1;
		int expenseId =-1;
		Intent intent = getIntent();
	    claimId = (int) intent.getIntExtra(Constants.claimIdLabel, -1);
		expenseId = (int) extras.getLong("expenseId", -1);
		if (claimId == -1) {
			Toast.makeText(this, "The Claim Position needs to be added to the " +
					"EditExpenseActivity intent before startActivity(intent) is called",
					Toast.LENGTH_LONG).show();
			finish();
		}
		else if (expenseId == -1) {
			Toast.makeText(this, "The Expense Position needs to be added to the " +
					"EditExpenseActivity intent before startActivity(intent) is called",
					Toast.LENGTH_LONG).show();
			finish();
		}
		
		//TODO - Delete Toast Later
		Toast.makeText(this, "Expense Position " + expenseId,
				Toast.LENGTH_SHORT).show();
		
		//Set currentClaim to the claim that was selected via intent
		currentClaim = new Claim((int)claimId);
	    claimController = new ClaimController(currentClaim);
		
	    //initialize fields 
		EditText description = (EditText) findViewById(R.id.description);
		EditText date = (EditText) findViewById(R.id.date_expense);
		EditText cost = (EditText) findViewById(R.id.amount);
		Spinner category = (Spinner) findViewById(R.id.catspinner);
		Spinner currencyType = (Spinner) findViewById(R.id.currencyspinner);
		String categoryString = claimController.getExpense(expenseId).getCategory();
		String currencyString = claimController.getExpense(expenseId).getCurrencyType();
	
		//set fields to correct values
		description.setText(claimController.getExpense(expenseId)
				.getDescription());
		date.setText(claimController.getExpense(expenseId)
				.getDateString());
		cost.setText(""+claimController.getExpense(expenseId)
				.getCost());
		category.setSelection(getIndex(category, categoryString));
		currencyType.setSelection(getIndex(currencyType, currencyString));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.view_expense, menu);
		return true;
	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}
	
	public void update() {
		// TODO Auto-generated method stub
		
	}
	
	//is called when edit button is clicked
	public void confirmEdit(View v) {
		Bundle extras = getIntent().getExtras();
		int claimId =-1;
		int expenseId =-1;
		Intent intent = getIntent();
	    claimId = (int) intent.getIntExtra(Constants.claimIdLabel, -1);
		expenseId = (int) extras.getLong("expenseId", -1);
		
		//get the EditText fields
		EditText description = (EditText) findViewById(R.id.description);
		EditText date = (EditText) findViewById(R.id.date_expense);
		EditText cost = (EditText) findViewById(R.id.amount);
		Spinner category = (Spinner) findViewById(R.id.catspinner);
		Spinner currencyType = (Spinner) findViewById(R.id.currencyspinner);
		
		//parse the string input from user
		String descrString = description.getText().toString();
		String dateString = date.getText().toString();
		String costString = cost.getText().toString();
		String categoryString = category.getSelectedItem().toString();
		String currencyTypeString = currencyType.getSelectedItem().toString();
		
		//check multiple user input errors and get them to correct accordingly
		//description is required
		if (descrString.equals("")) {
			description.setError("Description is Required");
			description.requestFocus();
			return;
		}
		//date is required
		if (dateString.equals("")) {
			date.setError("Cost is Required");
			date.requestFocus();
			return;
		}
		//cost is required
		if (costString.equals("")) {
			cost.setError("Cost is Required");
			cost.requestFocus();
			return;
		}
		//category is required
		if (categoryString.equals("--Choose Category--")) {
			Toast.makeText(this, "Category Type is Required", Toast.LENGTH_SHORT).show();
			return;
		}
		//currency is required
		if (currencyTypeString.equals("--Choose Currency--")) {
			Toast.makeText(this, "Currency Type is Required", Toast.LENGTH_SHORT).show();
			return;
		}
	}
	
{'fraction_non_alphanumeric': 0.10294272756038393, 'fraction_numerical': 0.0035861196076363254, 'mean_word_length': 4.4369266055045875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3529480', 'n_tokens_mistral': 3039, 'n_tokens_neox': 2686, 'n_words': 818}