Newer
Older
CosmosClient / app / src / main / java / com / example / cosmosclient / views / SignupActivity.java
package com.example.cosmosclient.views;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.cosmosclient.R;


import java.util.regex.Pattern;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

public class SignupActivity extends AppCompatActivity {
    public static final String UserInfomation="com.example.cosmosclient.views";

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

        //retrofitの処理
        final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/")
                .addConverterFactory(JacksonConverterFactory.create())
                .build();
        //interfaceから実装を取得
        final Signup signup = retrofit.create(Signup.class);


        //各種idを取得
        Button LoginButton = findViewById(R.id.LoginButton);
        Button MakeAccountButton = findViewById(R.id.MakeAccountButton);
        final EditText NameText = findViewById(R.id.NameText);
        final EditText PasswordText = findViewById(R.id.PasswordText);
        final EditText ConfirmPasswordText = findViewById(R.id.ConfirmPasswordText);



        //Make Accountボタンの処理
        MakeAccountButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){

                //パスワードと確認パスワードが一致していない際の処理
                if(!PasswordText.equals(ConfirmPasswordText)){
                    Toast.makeText(SignupActivity.this,"入力されたパスワードが一致しません。",Toast.LENGTH_SHORT);
                    return;
                }

                //API呼び出しのための値入力
                Call<User> call = signup.listUser(NameText.getText().toString(),
                        PasswordText.getText().toString(),null);

                call.enqueue(new Callback<User>() {
                    //成功時
                    @Override
                    public void onResponse(Call<User> call, Response<User> response) {
                        if (response.isSuccessful()) {
                            User result = response.body();
                            Intent intent = new Intent(getApplication(), GroupList.class);
                            //intent.putExtra("UserInfomation",result);
                            startActivity(intent);
                            finish();

                        }
                    }

                    //失敗時
                    @Override
                    public void onFailure(Call<User> call, Throwable t) {
                        //t.printStackTrace();
                        Toast.makeText(SignupActivity.this,
                                "アカウント作成失敗",Toast.LENGTH_SHORT);
                    }

                });

            }
        });

        //サインイン画面への遷移処理
        LoginButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent = new Intent(getApplication(),SigninActivity.class);
                startActivity(intent);
                finish();
            }
        });

    }
}