package net.ichigotake.yancha.login;

import net.ichigotake.yancha.R;
import net.ichigotake.yancha.chat.ChatFragment;
import net.ichigotake.yancha.net.YanchaAuth;
import net.ichigotake.yancha.ui.FragmentTransit;
import net.ichigotake.yancha.ui.ViewContainer;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class LoginContainer implements ViewContainer {

	final private Fragment fragment;
	
	final private YanchaAuth auth;
	
	public LoginContainer(Fragment fragment) {
		this.fragment = fragment;
		this.auth = new YanchaAuth(fragment.getActivity());
	}
	
	@Override
	public void initializeView(View view) {
		view.findViewById(R.id.loginAuthSimpleSend).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				EditText nicknameTextView = (EditText) fragment.getActivity().findViewById(R.id.loginAuthSimpleNickname);
				String nickname = nicknameTextView.getText().toString();
				
				//TODO OCs̕
				auth.simpleLogin(nickname);

				new FragmentTransit(fragment).toNext(ChatFragment.newInstance());

			}
		});
		
		EditText loginSimple = (EditText) view.findViewById(R.id.loginAuthSimpleNickname);
		loginSimple.setOnEditorActionListener(new OnEditorActionListener() {	
			
			@Override
			public boolean onEditorAction(TextView v, int actionId,
					KeyEvent event) {
				EditText nicknameTextView = (EditText) fragment.getActivity().findViewById(R.id.loginAuthSimpleNickname);
				String nickname = nicknameTextView.getText().toString();
				
				//TODO OCs̕
				auth.simpleLogin(nickname);

				new FragmentTransit(fragment).toNext(ChatFragment.newInstance());

				return false;
			}
		});

		view.findViewById(R.id.loginAuthTwitter).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				new FragmentTransit(fragment).toNext(ChatFragment.newInstance());
			}
		});

	}

}

@@ -107,24 +107,64 @@
 atFragment;%0A
+import net.ichigotake.yancha.data.User;%0A
 import net.i
@@ -196,16 +196,16 @@
 haAuth;%0A
-
 import n
@@ -676,16 +676,44 @@
 auth;%0A%09%0A
+%09final private User user;%0A%09%0A
 %09public 
@@ -830,16 +830,64 @@
 ity());%0A
+%09%09this.user = new User(fragment.getActivity());%0A
 %09%7D%0A%09%0A%09@O
@@ -1387,16 +1387,16 @@
 %09%7D);%0A%09%09%0A
-
 %09%09EditTe
@@ -1472,16 +1472,59 @@
 kname);%0A
+%09%09loginSimple.setText(user.getNickname());%0A
 %09%09loginS

set default nickname