<commit_before>package es.unizar.eina.allpc;

import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Switch;

public class PCedit extends AppCompatActivity {

    private EditText mIdText;
    private EditText mModeloText;
    private EditText mMarcaText;
    private Spinner mRamText;
    private EditText mProcesadorText;
    private EditText mSOText;
    private Spinner mHDDText;
    private Spinner mPantallaText;
    private EditText mGraficaText;
    private EditText mConexionesText;

    private EditText mBodyText;
    private Long mRowId;

    private DbAdapter mDbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //p3
        mDbHelper = new DbAdapter(this);
        mDbHelper.open();




        setContentView(R.layout.activity_pcedit);
        setTitle(R.string.app_name);

        mIdText = (EditText) findViewById(R.id.id);
        mModeloText = (EditText) findViewById(R.id.modelo);
        mMarcaText = (EditText) findViewById(R.id.marca);
        mRamText = (Spinner) findViewById(R.id.ram);
        mProcesadorText = (EditText) findViewById(R.id.procesador);
        mSOText = (EditText) findViewById(R.id.so);
        mHDDText = (Spinner) findViewById(R.id.hdd);
        mPantallaText = (Spinner) findViewById(R.id.pantalla);
        mGraficaText = (EditText) findViewById(R.id.grafica);
        mConexionesText = (EditText) findViewById(R.id.conexiones);

        Button confirmButton = (Button) findViewById(R.id.confirm);

        mRowId = (savedInstanceState == null) ? null :
                (Long) savedInstanceState.getSerializable(DbAdapter.KEY_PC_ROWID);
        if (mRowId == null) {
            Bundle extras = getIntent().getExtras();
            mRowId = (extras != null) ? extras.getLong(DbAdapter.KEY_PC_ROWID)
                    : null;
        }

        //RELLENAR EL SPINNER RAM---------------------------------------------------
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter.add("1GB");
        adapter.add("2GB");
        adapter.add("4GB");
        adapter.add("8GB");
        adapter.add("16GB");

        mRamText = (Spinner) findViewById(R.id.ram);
        mRamText.setAdapter(adapter);
        //-----------------------------------------------

        //RELLENAR EL SPINNER HDD--------------------------------------------------------
        ArrayAdapter<CharSequence> adapter2 = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter2.add("128GB");
        adapter2.add("256GB");
        adapter2.add("512GB");
        adapter2.add("1TB");
        adapter2.add("2TB");

        mHDDText = (Spinner) findViewById(R.id.hdd);
        mHDDText.setAdapter(adapter2);
        //-----------------------------------------------

        //RELLENAR EL SPINNER PANTALLA---------------------------------------------------------
        ArrayAdapter<CharSequence> adapter3 = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter3.add("10 pulgadas");
        adapter3.add("12 pulgadas");
        adapter3.add("15.7 pulgadas");
        adapter3.add("17 pulgadas");

        mPantallaText = (Spinner) findViewById(R.id.pantalla);
        mPantallaText.setAdapter(adapter3);
        //-----------------------------------------------

        populateFields();
        confirmButton.setOnClickListener(new View.OnClickListener() {

                                             public void onClick(View view) {
                                                 Intent mIntent = new Intent();
                                                 setResult(RESULT_OK, mIntent);
                                                 finish();
                                             }

                                         }
        );
    }


    private void populateFields() {
        if (mRowId != null) {
            //Cursor pc = mDbHelper.fetchPC(mRowId);
            ConexionBD bd = new ConexionBD();
            Cursor pc = bd.getPC(mRowId);
            startManagingCursor(pc);
            /*mIdText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_ROWID)));
            mModeloText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_MODELO)));
            mMarcaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_MARCA)));
            mRamText.setSelection(spinnerPositionRAM(
                    pc.getString(pc.getColumnIndex(DbAdapter.KEY_PC_RAM))));
            mProcesadorText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_PROCESADOR)));
            mSOText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_SO)));
            mHDDText.setSelection(1);
            mPantallaText.setSelection(1);
            mGraficaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_GRAFICA)));
            mConexionesText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_CONEXIONES)));*/
            System.out.println("------------------------------");
            pc.moveToFirst();
            /*String[] a = pc.getColumnNames();
            System.out.println(a[0] + " " + a[1]);
            System.out.println(pc.getColumnIndex(a[0]));
            System.out.println(pc.getString(pc.getColumnIndex(a[2])));
            System.out.println("------------------------------");*/
            mIdText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("_id")));
            mModeloText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("modelo")));
            mMarcaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("marca")));
            mRamText.setSelection(spinnerPositionRAM(
                    pc.getString(pc.getColumnIndex("ram"))));
            mProcesadorText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("procesador")));
            mSOText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("so")));
            mHDDText.setSelection(1);
            mPantallaText.setSelection(1);
            mGraficaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("grafica")));
            mConexionesText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("conexiones")));
        }
    }

    private int spinnerPositionRAM (String valor){
        switch (valor){
            case "1":
                return 0;
            case "2":
                return 1;
            case "4":
                return 2;
            case "8":
                return 3;
            case "16":
                return 4;
        }
        return 1;
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(DbAdapter.KEY_PC_ROWID, mRowId);
    }
    @Override
    protected void onPause() {
        super.onPause();
        saveState();
        Intent mIntent = new Intent();
        setResult(RESULT_OK, mIntent);
    }
    @Override
    protected void onResume() {
        super.onResume();
        populateFields();
    }<commit_msg>EditPC recoge todos los datos bien<commit_after>package es.unizar.eina.allpc;

import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Switch;

public class PCedit extends AppCompatActivity {

    private EditText mIdText;
    private EditText mModeloText;
    private EditText mMarcaText;
    private Spinner mRamText;
    private EditText mProcesadorText;
    private EditText mSOText;
    private Spinner mHDDText;
    private Spinner mPantallaText;
    private EditText mGraficaText;
    private EditText mConexionesText;

    private EditText mBodyText;
    private Long mRowId;

    private DbAdapter mDbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //p3
        mDbHelper = new DbAdapter(this);
        mDbHelper.open();




        setContentView(R.layout.activity_pcedit);
        setTitle(R.string.app_name);

        mIdText = (EditText) findViewById(R.id.id);
        mModeloText = (EditText) findViewById(R.id.modelo);
        mMarcaText = (EditText) findViewById(R.id.marca);
        mRamText = (Spinner) findViewById(R.id.ram);
        mProcesadorText = (EditText) findViewById(R.id.procesador);
        mSOText = (EditText) findViewById(R.id.so);
        mHDDText = (Spinner) findViewById(R.id.hdd);
        mPantallaText = (Spinner) findViewById(R.id.pantalla);
        mGraficaText = (EditText) findViewById(R.id.grafica);
        mConexionesText = (EditText) findViewById(R.id.conexiones);

        Button confirmButton = (Button) findViewById(R.id.confirm);

        mRowId = (savedInstanceState == null) ? null :
                (Long) savedInstanceState.getSerializable(DbAdapter.KEY_PC_ROWID);
        if (mRowId == null) {
            Bundle extras = getIntent().getExtras();
            mRowId = (extras != null) ? extras.getLong(DbAdapter.KEY_PC_ROWID)
                    : null;
        }

        //RELLENAR EL SPINNER RAM---------------------------------------------------
        ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter.add("1GB");
        adapter.add("2GB");
        adapter.add("4GB");
        adapter.add("8GB");
        adapter.add("16GB");

        mRamText = (Spinner) findViewById(R.id.ram);
        mRamText.setAdapter(adapter);
        //-----------------------------------------------

        //RELLENAR EL SPINNER HDD--------------------------------------------------------
        ArrayAdapter<CharSequence> adapter2 = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter2.add("128GB");
        adapter2.add("256GB");
        adapter2.add("512GB");
        adapter2.add("1TB");
        adapter2.add("2TB");

        mHDDText = (Spinner) findViewById(R.id.hdd);
        mHDDText.setAdapter(adapter2);
        //-----------------------------------------------

        //RELLENAR EL SPINNER PANTALLA---------------------------------------------------------
        ArrayAdapter<CharSequence> adapter3 = new ArrayAdapter<CharSequence>(
                this, android.R.layout.simple_spinner_item);
        adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        adapter3.add("10 pulgadas");
        adapter3.add("12 pulgadas");
        adapter3.add("15.7 pulgadas");
        adapter3.add("17 pulgadas");

        mPantallaText = (Spinner) findViewById(R.id.pantalla);
        mPantallaText.setAdapter(adapter3);
        //-----------------------------------------------

        populateFields();
        confirmButton.setOnClickListener(new View.OnClickListener() {

                                             public void onClick(View view) {
                                                 Intent mIntent = new Intent();
                                                 setResult(RESULT_OK, mIntent);
                                                 finish();
                                             }

                                         }
        );
    }


    private void populateFields() {
        if (mRowId != null) {
            //Cursor pc = mDbHelper.fetchPC(mRowId);
            ConexionBD bd = new ConexionBD();
            Cursor pc = bd.getPC(mRowId);
            startManagingCursor(pc);
            /*mIdText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_ROWID)));
            mModeloText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_MODELO)));
            mMarcaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_MARCA)));
            mRamText.setSelection(spinnerPositionRAM(
                    pc.getString(pc.getColumnIndex(DbAdapter.KEY_PC_RAM))));
            mProcesadorText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_PROCESADOR)));
            mSOText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_SO)));
            mHDDText.setSelection(1);
            mPantallaText.setSelection(1);
            mGraficaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_GRAFICA)));
            mConexionesText.setText(pc.getString(
                    pc.getColumnIndexOrThrow(DbAdapter.KEY_PC_CONEXIONES)));*/
            System.out.println("------------------------------");
            pc.moveToFirst();
            /*String[] a = pc.getColumnNames();
            System.out.println(a[0] + " " + a[1]);
            System.out.println(pc.getColumnIndex(a[0]));
            System.out.println(pc.getString(pc.getColumnIndex(a[2])));
            System.out.println("------------------------------");*/
            mIdText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("_id")));
            mModeloText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("modelo")));
            mMarcaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("marca")));
            mRamText.setSelection(spinnerPositionRAM(
                    pc.getString(pc.getColumnIndex("ram"))));
            mProcesadorText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("procesador")));
            mSOText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("so")));
            mHDDText.setSelection(spinnerPositionHDD(
                    pc.getString(pc.getColumnIndex("almacenamiento"))));
            mPantallaText.setSelection(spinnerPositionPantalla(
                    pc.getString(pc.getColumnIndex("pantalla"))));
            mGraficaText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("grafica")));
            mConexionesText.setText(pc.getString(
                    pc.getColumnIndexOrThrow("conexiones")));
        }
    }

    private int spinnerPositionRAM (String valor){
        switch (valor){
            case "1":
                return 0;
            case "2":
                return 1;
            case "4":
                return 2;
            case "8":
                return 3;
            case "16":
                return 4;
        }
        return 1;
    }

    private int spinnerPositionHDD (String valor){
        System.out.println("VALOOOOOR HDD---------------- " + valor);
        switch (valor){
            case "128":
                return 0;
            case "256":
                return 1;
            case "512":
                return 2;
            case "1024":
                return 3;
            case "2048":
                return 4;
        }
        return 1;
    }

    private int spinnerPositionPantalla (String valor){
        System.out.println("VALOOOOOR PANTALLA---------------- " + valor);
        switch (valor){
            case "10":
                return 0;
            case "12":
                return 1;
            case "15.7":
                return 2;
            case "17":
                return 3;
        }
        return 1;
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        saveState();
        outState.putSerializable(DbAdapter.KEY_PC_ROWID, mRowId);
    }
    @Override
    protected void onPause() {
        super.onPause();
        saveState();
        Intent mIntent = new Intent();
        setResult(RESULT_OK, mIntent);
    }
    @Override
    protected void onResume() {
        super.onResume();
        populateFields();
    }
{'fraction_non_alphanumeric': 0.14471687098657326, 'fraction_numerical': 0.00939871570344425, 'mean_word_length': 1.737018693081962, 'pattern_counts': {'":': 19, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '982671', 'n_tokens_mistral': 4827, 'n_tokens_neox': 4590, 'n_words': 727}