package com.example.jorgepalacios.threewayhandshake;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class TerminateActivity extends AppCompatActivity {

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


        Button bTerminate = (Button) findViewById(R.id.bTerminate);
        Button nConnection = (Button) findViewById(R.id.nConnection);

        final TextView termR = (TextView) findViewById(R.id.termRequest);
        final TextView receiveTerm = (TextView) findViewById(R.id.termAck);
        final TextView sendFin = (TextView) findViewById(R.id.sendTerm);
        final TextView receiveAck = (TextView) findViewById(R.id.ackTerm);
        final TextView receiveFin = (TextView) findViewById(R.id.recFin);
        final TextView connectionFin = (TextView) findViewById(R.id.connFin);

        final ImageView rightG = (ImageView) findViewById(R.id.reqImage);
        final ImageView leftR = (ImageView) findViewById(R.id.ackImg);
        final ImageView leftF = (ImageView) findViewById(R.id.finImg);
        final ImageView rightF = (ImageView) findViewById(R.id.ackFinImg);


        final HostA request = (HostA) getIntent().getSerializableExtra("HostA");
        final HostB responds = (HostB) getIntent().getSerializableExtra("HostB");

        bTerminate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final char tRequest = 'y';
                termR.setText(request.termReq());
                termR.setVisibility(View.VISIBLE);
                rightG.setVisibility(View.VISIBLE);

                receiveTerm.setText(responds.ackTerm());
                receiveTerm.setVisibility(View.VISIBLE);
                leftR.setVisibility(View.VISIBLE);

                receiveAck.setText(request.recAck());
                receiveAck.setVisibility(View.VISIBLE);
                leftF.setVisibility(View.VISIBLE);

                sendFin.setText(responds.sendTerm());
                sendFin.setVisibility(View.VISIBLE);
                receiveFin.setText(request.recFin());
                receiveFin.setVisibility(View.VISIBLE);
                rightF.setVisibility(View.VISIBLE);
                connectionFin.setText(responds.terminateCon(Character.toString(tRequest)));
                connectionFin.setVisibility(View.VISIBLE);

            }
        });

    }
}
