package com.blocksolid.income;

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

import java.text.DecimalFormat;

public class MainActivity extends AppCompatActivity {

    TextView grossAnnualIncomeValueText;
    TextView personalAllowanceValueText;
    TextView totalTaxDeductionsValueText;
    TextView nationalInsuranceValueText;
    TextView totalDeductionsValueText;
    TextView netAnnualIncomeValueText;

    TaxCalculator taxCalculator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        taxCalculator = new TaxCalculator();
        grossAnnualIncomeValueText = (TextView)findViewById(R.id.main_txt_gross_value);
        personalAllowanceValueText = (TextView)findViewById(R.id.main_txt_allowance_value);
        totalTaxDeductionsValueText = (TextView)findViewById(R.id.main_txt_tax_deductions_value);
        nationalInsuranceValueText = (TextView)findViewById(R.id.main_txt_national_insurance_value);
        totalDeductionsValueText = (TextView)findViewById(R.id.main_txt_total_deductions_value);
        netAnnualIncomeValueText = (TextView)findViewById(R.id.main_txt_net_income_value);
    }

    public void displayAnnualDeductions(View view) {
        // Display breakdown of all deductions
        EditText editText = (EditText) findViewById(R.id.main_edit_salary);
        if ((editText.getText()).length() > 0) {
            Integer enteredValue = Integer.valueOf(editText.getText().toString())*100;
            taxCalculator.setGrossIncome(enteredValue);
            setAnnualTextValues();
        }
        else {
            clearTextValues();
        }
    }

    public void displayMonthlyDeductions(View view) {
        // Display breakdown of all deductions monthly
        // TODO refactor this and the above method
        EditText editText = (EditText) findViewById(R.id.main_edit_salary);
        if ((editText.getText()).length() > 0) {
            Integer enteredValue = Integer.valueOf(editText.getText().toString())*100;
            taxCalculator.setGrossIncome(enteredValue);
            setMonthlyTextValues();
        }
        else {
            clearTextValues();
        }
    }

    public void setAnnualTextValues() {
        grossAnnualIncomeValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualGrossIncome()));
        personalAllowanceValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualPersonalAllowance()));
        totalTaxDeductionsValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualTotalTaxDeductions()));
        nationalInsuranceValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualNiContributions()));
        totalDeductionsValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualTotalDeductions()));
        netAnnualIncomeValueText.setText(displayAsPoundsAndPence(taxCalculator.getAnnualNetIncome()));
    }

    public void setMonthlyTextValues() {
        grossAnnualIncomeValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyGrossIncome()));
        personalAllowanceValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyPersonalAllowance()));
        totalTaxDeductionsValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyTotalTaxDeductions()));
        nationalInsuranceValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyNiContributions()));
        totalDeductionsValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyTotalDeductions()));
        netAnnualIncomeValueText.setText(displayAsPoundsAndPence(taxCalculator.getMonthlyNetIncome()));
    }

    public void clearTextValues() {
        grossAnnualIncomeValueText.setText("");
        personalAllowanceValueText.setText("");
        totalTaxDeductionsValueText.setText("");
        nationalInsuranceValueText.setText("");
        totalDeductionsValueText.setText("");
        netAnnualIncomeValueText.setText("");
    }

    @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_main, 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_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public static String displayAsPoundsAndPence(int value) {
        DecimalFormat currency = new DecimalFormat("£#,###,##0.00");
        Double valueDouble = value/100.0;
        return currency.format(valueDouble);
    }
}

@@ -349,30 +349,24 @@
 xtView gross
-Annual
 IncomeValueT
@@ -545,30 +545,24 @@
 TextView net
-Annual
 IncomeValueT
@@ -567,16 +567,75 @@
 eText;%0A%0A
+    TextView grossIncomeText;%0A    TextView netIncomeText;%0A%0A
     TaxC
@@ -873,38 +873,32 @@
 );%0A        gross
-Annual
 IncomeValueText 
@@ -1341,38 +1341,32 @@
 ue);%0A        net
-Annual
 IncomeValueText 
@@ -1418,24 +1418,170 @@
 come_value);
+%0A%0A        grossIncomeText = (TextView)findViewById(R.id.main_txt_gross);%0A        netIncomeText = (TextView)findViewById(R.id.main_txt_net_income);
 %0A    %7D%0A%0A    
@@ -2634,38 +2634,32 @@
  %7B%0A        gross
-Annual
 IncomeValueText.
@@ -3181,38 +3181,32 @@
 )));%0A        net
-Annual
 IncomeValueText.
@@ -3266,32 +3266,143 @@
 alNetIncome()));
+%0A%0A        grossIncomeText.setText(%22Gross annual income:%22);%0A        netIncomeText.setText(%22Net annual income:%22);
 %0A    %7D%0A%0A    publ
@@ -3439,38 +3439,32 @@
  %7B%0A        gross
-Annual
 IncomeValueText.
@@ -3991,38 +3991,32 @@
 )));%0A        net
-Annual
 IncomeValueText.
@@ -4081,24 +4081,137 @@
 tIncome()));
+%0A%0A        grossIncomeText.setText(%22Gross monthly income:%22);%0A        netIncomeText.setText(%22Net monthly income:%22);
 %0A    %7D%0A%0A    
@@ -4255,22 +4255,16 @@
    gross
-Annual
 IncomeVa
@@ -4486,22 +4486,16 @@
      net
-Annual
 IncomeVa

Change text strings displayed when showing monthly values