diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/UserLoginController.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/UserLoginController.java index 7c9cb3f..e0a1d9a 100644 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/UserLoginController.java +++ b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/controller/UserLoginController.java @@ -1,68 +1,76 @@ package org.ntlab.radishforandroidstudio.cactusClient.controller; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.widget.EditText; import net.arnx.jsonic.JSON; import net.arnx.jsonic.TypeReference; +import org.ntlab.radishforandroidstudio.R; import org.ntlab.radishforandroidstudio.cactusClient.Cactus; import org.ntlab.radishforandroidstudio.cactusClient.connections.LoginFragmentConnection; import org.ntlab.radishforandroidstudio.cactusClient.models.account.Account; import org.ntlab.radishforandroidstudio.cactusClient.models.account.URIAddressedAccount; +import org.ntlab.radishforandroidstudio.cactusClient.views.InstancesFragment; import org.ntlab.radishforandroidstudio.framework.network.CallBack; public class UserLoginController { - - private String userId; + private LoginFragmentConnection connection; + private Cactus userCactus; + private String userID; private String userPass; - private Cactus cactus; - private LoginFragmentConnection loginFragmentConnection; + private FragmentManager manager; - Account account; - private boolean isLogin=false; - - public UserLoginController(Cactus cactus, EditText userName, EditText passWord) { - loginFragmentConnection = new LoginFragmentConnection(); - this.userId = userName.getText().toString(); + public UserLoginController(Cactus cactus, EditText userName, EditText passWord, FragmentManager fragmentManager) { + connection = new LoginFragmentConnection(); + this.userID = userName.getText().toString(); this.userPass = passWord.getText().toString(); - this.cactus = cactus; - + this.userCactus = cactus; + this.manager = fragmentManager; } + public void addFormParam() { + connection.addFormParam("userID", userID); + connection.addFormParam("userPass", userPass); + connection.doPut(); - public boolean login() { -// loginFragmentConnection = new LoginFragmentConnection(); - loginFragmentConnection.setCallBack(new CallBack() { + } + + private void changeJson(String response) { + URIAddressedAccount lac = JSON.decode(response, new TypeReference() { + }); +// System.out.println(response); + Account user = lac.getAccount(); + if (user.isLogin()) { + System.out.println("成功"); + userCactus.setMyAccount(user); + userCactus.setAddressedAccount(lac); + FragmentTransaction transaction = manager.beginTransaction(); + transaction.replace(R.id.fragment_place, new InstancesFragment()); + transaction.commit(); + } else { + System.out.println("失敗"); + } + } + + public void loginResponse() { + connection.setCallBack(new CallBack() { @Override public void onResponse(String response) { - //通信した時の処理を書くのだよ - URIAddressedAccount uriAddressedAccount = JSON.decode(response, new TypeReference() { - }); - account = uriAddressedAccount.getAccount(); + changeJson(response); - if (account.isLogin()) { - cactus.setMyAccount(account);//Cactusにアカウントセット - cactus.setAddressedAccount(uriAddressedAccount);//Jsonから - System.out.println("ログインに成功しました。"); - isLogin = true; - } else { - System.out.println("ログインに失敗しました。"); - isLogin = false; - - } } }); - - return isLogin; } - - public void addUserFormParam(){ - loginFragmentConnection.addFormParam("userID", userId); - loginFragmentConnection.addFormParam("userPass", userPass); - loginFragmentConnection.doPut(); - - } - - } + + + + + + + + +