package de.svenkaestle.prapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddDrugsActivity extends AppCompatActivity {
    EditText medicationAmount;
    Button minus;
    Button plus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_drugs);
        medicationAmount = (EditText) findViewById(R.id.medicationNumberEditView);
        medicationAmount.setText("0");

        minus = (Button) findViewById(R.id.decreaseMedicationNumberButton);
        plus = (Button) findViewById(R.id.increaseMedicationNumberButton);


        minus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String medicationAmountOldValue = medicationAmount.getText().toString();
                Integer newValue = Integer.valueOf(medicationAmountOldValue)-1;
                if(newValue <= 0){
                    newValue = 0;
                }
                String medicationAmountNewValue = newValue.toString();
                medicationAmount.setText(medicationAmountNewValue);
            }
        });

        plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String medicationAmountOldValue = medicationAmount.getText().toString();
                Integer newValue = Integer.valueOf(medicationAmountOldValue)+1;
                String medicationAmountNewValue = newValue.toString();
                medicationAmount.setText(medicationAmountNewValue);
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.top_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_links:
                startActivity(new Intent(getApplicationContext(), LinksActivity.class));
                return true;
            case R.id.menu_disclaimer:
                startActivity(new Intent(getApplicationContext(), DisclaimerActivity.class));
                return true;
            case R.id.menu_contact:
                startActivity(new Intent(getApplicationContext(), ContactActivity.class));
                return true;
            default:
                finish();
                return true;
        }
    }
}

@@ -379,30 +379,166 @@
 ton 
-minus;%0A    Button plus
+decreaseMedicationAmount;%0A    Button increaseMedicationAmount;%0A%0A    String medicationAmountOldValue;%0A    String medicationAmountNewValue;%0A    Integer newValue
 ;%0A%0A 
@@ -835,21 +835,40 @@
         
-minus
+decreaseMedicationAmount
  = (Butt
@@ -930,20 +930,40 @@
         
-plus
+increaseMedicationAmount
  = (Butt
@@ -1018,25 +1018,24 @@
 tton);%0A%0A
-%0A
         
 minus.se
@@ -1030,13 +1030,32 @@
     
-minus
+decreaseMedicationAmount
 .set
@@ -1171,39 +1171,32 @@
                 
-String 
 medicationAmount
@@ -1257,32 +1257,24 @@
             
-Integer 
 newValue = I
@@ -1317,9 +1317,11 @@
 lue)
--
+ - 
 1;%0A 
@@ -1337,16 +1337,17 @@
       if
+ 
 (newValu
@@ -1353,16 +1353,17 @@
 ue %3C= 0)
+ 
 %7B%0A      
@@ -1416,39 +1416,32 @@
                 
-String 
 medicationAmount
@@ -1579,12 +1579,32 @@
     
-plus
+increaseMedicationAmount
 .set
@@ -1720,39 +1720,32 @@
                 
-String 
 medicationAmount
@@ -1806,32 +1806,24 @@
             
-Integer 
 newValue = I
@@ -1866,9 +1866,11 @@
 lue)
-+
+ + 
 1;%0A 
@@ -1880,31 +1880,24 @@
             
-String 
 medicationAm

clean code