<commit_before>package rtdc.android.presenter;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import rtdc.android.MyActivity;
import rtdc.android.R;
import rtdc.core.controller.AddUnitController;
import rtdc.core.json.JSONObject;
import rtdc.core.model.Unit;
import rtdc.core.view.AddUnitView;

public class CreateUnitActivity extends Activity implements AddUnitView{

    private AddUnitController controller;

    private EditText unitNameEdit, totalBedsEdit;

    private Unit currentUnit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_unit);

        unitNameEdit = (EditText) findViewById(R.id.unitNameEdit);
        totalBedsEdit = (EditText) findViewById(R.id.totalBedsEdit);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        Intent intent = getIntent();
        String unitJson = intent.getStringExtra("unit");
        if (unitJson != null) {
            currentUnit = new Unit(new JSONObject(unitJson));
            unitNameEdit.setText(currentUnit.getName());
            totalBedsEdit.setText(currentUnit.getTotalBeds());
        }

        controller = new AddUnitController(this);
    }


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

        return true;
    }

    @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.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_save_new_unit) {
            controller.addUnit();
            Intent intent = new Intent(this, MyActivity.class);
            startActivity(intent);
            return true;
        } else if (id == R.id.action_discard_unit) {
            if (currentUnit != null) {
                controller.deleteUnit(currentUnit);<commit_msg>Fixed crash when editing a unit (by casting an int to String)<commit_after>package rtdc.android.presenter;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import rtdc.android.MyActivity;
import rtdc.android.R;
import rtdc.core.controller.AddUnitController;
import rtdc.core.json.JSONObject;
import rtdc.core.model.Unit;
import rtdc.core.view.AddUnitView;

public class CreateUnitActivity extends Activity implements AddUnitView{

    private AddUnitController controller;

    private EditText unitNameEdit, totalBedsEdit;

    private Unit currentUnit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_unit);

        unitNameEdit = (EditText) findViewById(R.id.unitNameEdit);
        totalBedsEdit = (EditText) findViewById(R.id.totalBedsEdit);

        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        Intent intent = getIntent();
        String unitJson = intent.getStringExtra("unit");
        if (unitJson != null) {
            currentUnit = new Unit(new JSONObject(unitJson));
            unitNameEdit.setText(currentUnit.getName());
            totalBedsEdit.setText(Integer.toString(currentUnit.getTotalBeds()));
        }

        controller = new AddUnitController(this);
    }


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

        return true;
    }

    @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.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_save_new_unit) {
            controller.addUnit();
            Intent intent = new Intent(this, MyActivity.class);
            startActivity(intent);
            return true;
        } else if (id == R.id.action_discard_unit) {
            if (currentUnit != null) {
                controller.deleteUnit(currentUnit);
{'fraction_non_alphanumeric': 0.08837485172004746, 'fraction_numerical': 0.0, 'mean_word_length': 3.1096669374492283, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6648059', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1342, 'n_words': 342}