package com.example.nemophila; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.TextView; import com.example.nemophila.entities.Account; import com.example.nemophila.resources.AccountsRest; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class LoginActivity extends AppCompatActivity { private Retrofit retrofit; private AccountsRest AccountsRest; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); //通信の初期化 this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/nemophila/") .addConverterFactory(JacksonConverterFactory.create()) .build(); this.AccountsRest = retrofit.create(AccountsRest.class); findViewById(R.id.LoginButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText edituid = (EditText) findViewById(R.id.editTextUserID); String uid = edituid.getText().toString(); EditText editpw = (EditText) findViewById(R.id.editTextTextNewPassword); String pw = editpw.getText().toString(); // 通信 Call<Account> call = AccountsRest.getAccounts(uid,pw); call.enqueue (new Callback<Account>() { @Override public void onResponse(Call<Account> call, Response<Account> response) { if (response.isSuccessful()) { System.out.println("通信成功:changeBelongsAndMaster"); Intent intent = new Intent(LoginActivity.this,MainActivity.class); startActivity(intent); } else { System.out.println("通信可能:changeBelongsAndMaster: " + response.code()); if (response.code() == 500){ ((TextView) findViewById(R.id.textView)).setText("Invalid UserID or Password"); }else if (response.code() == 404){ ((TextView) findViewById(R.id.textView)).setText("Login failed. Please enter the correct credentials."); } } } @Override public void onFailure(Call<Account> call, Throwable t) { System.out.println("通信失敗:changeBelongsAndMaster"); } }); } }); findViewById(R.id.SignUp).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(LoginActivity.this,SignUpActivity.class); startActivity(intent); } }); findViewById(R.id.ForgotPW).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Intent intent = new Intent(LoginActivity.this, ChangePwActivity.class); // startActivity(intent); } }); } }