package com.example.mirnabouchra.cloudolympics;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.view.View;

import com.firebase.client.Firebase;

/**
 * Created by mirnabouchra on 11/17/14.
 */
public class JoinActivity extends Activity {

    private static final String LOG_TAG = JoinActivity.class.getSimpleName();
    private EditText code;
    private Firebase firebaseRef;

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

        code = (EditText) findViewById(R.id.code);
        code.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                Log.d(LOG_TAG, editable.toString());
            }
        });

        firebaseRef = new Firebase("https://cloud-olympics.firebaseio.com/");
    }


    @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 void startGame(View view) {
        Intent intent = new Intent(this, TappingGameActivity.class);
        intent.putExtra("code", code.getText().toString());
        firebaseRef.child("message").setValue("Do you have data? You'll love Firebase.");
        startActivity(intent);
    }

}

@@ -2332,48 +2332,53 @@
 ue(%22
-Do you have data? You'll love Firebase.%22
+Connect to room %22 + code.getText().toString()
 );%0A 

Send the code to firebase on Join click