package com.github.pongdang.parcelable;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SubActivity extends Activity implements OnClickListener {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sub);
		
		//Main에서 받기
		receiveFromMain();
		
		((Button) findViewById(R.id.btn_sub)).setOnClickListener(this);
	}

	private void receiveFromMain() {
		ArrayList<MyParcels> sub_recvList = getIntent().getParcelableArrayListExtra("MAIN");
		
		((TextView) findViewById(R.id.text_sub_receive1)).setText(sub_recvList.get(0).str1);
		((TextView) findViewById(R.id.text_sub_receive2)).setText(sub_recvList.get(0).str2);
	}
	
	@Override
	public void onClick(View v) {
		MyParcels parcel = new MyParcels();
		parcel.str1 = ((EditText) findViewById(R.id.edit_sub_send1)).getText().toString();
		parcel.str2 = ((EditText) findViewById(R.id.edit_sub_send2)).getText().toString();
		
		ArrayList<MyParcels> sub_sendList = new ArrayList<MyParcels>();
		sub_sendList.add(parcel);
		
		Intent intent = new Intent(this, MainActivity.class);
		intent.putParcelableArrayListExtra("SUB", sub_sendList);
		setResult(RESULT_OK, intent);
		
		finish();
	}
}
