package com.example.stockprophit;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.support.v4.app.NavUtils;

public class SocialSearch extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_socialsearch); //create page with activity_socialsearch template
		// Show the Up button in the action bar.
		getActionBar().setDisplayHomeAsUpEnabled(true);
		
		// Get a reference to the AutoCompleteTextView in the layout
    	AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.edt_search);
    	// Get the string array
    	String[] tickers = getResources().getStringArray(R.array.UserNames);
    	ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tickers);
    	textView.setAdapter(adapter); // use adapter to set text view
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_social, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void goSocialHome(View view) //go to social page
	{
		Intent intent = new Intent(this, SocialActivity.class);
		startActivity(intent);
	}
	
	public void goSocialSearch(View view) //search for user
	{  
		Intent intent = new Intent(this, FriendProfile_Activity.class); 
	    EditText editText = (EditText)findViewById(R.id.edt_search); //take what was in edit text and store it
	    String message = editText.getText().toString(); //set it to a string
	    startActivity(intent); //go to profile page
	    
	    //user shared preference to pass the name from here to the profile
	    SharedPreferences settings = getSharedPreferences("prefs", 1);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString("name", message);
		editor.commit();
	 }
}
