非同期実行するように

This commit is contained in:
rca 2024-07-08 00:19:34 +09:00
parent bdb57f5412
commit 9f3f34ed72
2 changed files with 44 additions and 34 deletions

View File

@ -61,26 +61,30 @@ public class LoginActivity extends AppCompatActivity {
String email = emailEditText.getText().toString(); // TODO: メールアドレスのバリデーション String email = emailEditText.getText().toString(); // TODO: メールアドレスのバリデーション
String password = passwordEditText.getText().toString(); String password = passwordEditText.getText().toString();
Call<ParentAuthResponse> call = kidShiftApiService.parentLogin(new ParentAuthRequest(email, password)); CompletableFuture.runAsync(() -> {
try { Call<ParentAuthResponse> call = kidShiftApiService.parentLogin(new ParentAuthRequest(email, password));
Response<ParentAuthResponse> response = call.execute(); try {
if (response.isSuccessful()) { Response<ParentAuthResponse> response = call.execute();
ParentAuthResponse parentAuthResponse = response.body(); if (response.isSuccessful()) {
if (parentAuthResponse == null || parentAuthResponse.getAccessToken() == null) { ParentAuthResponse parentAuthResponse = response.body();
if (parentAuthResponse == null || parentAuthResponse.getAccessToken() == null) {
// エラー処理
logger.error("ParentAuthResponseがnullまたはAccessTokenがnullです");
return;
}
userSettings.getAppCommonSetting().setLoggedIn(true);
userSettings.getAppCommonSetting().setAccessToken(parentAuthResponse.getAccessToken());
} else {
logger.error("リクエストに失敗しました");
// エラー処理 // エラー処理
logger.error("ParentAuthResponseがnullまたはAccessTokenがnullです");
return;
} }
userSettings.getAppCommonSetting().setLoggedIn(true); } catch (Exception e) {
userSettings.getAppCommonSetting().setAccessToken(parentAuthResponse.getAccessToken()); logger.error("リクエストに失敗しました: " + e.getMessage());
} else { e.printStackTrace();
logger.error("リクエストに失敗しました");
// エラー処理
} }
} catch (Exception e) { }).thenRun(() -> {
logger.error("リクエストに失敗しました: " + e.getMessage()); startActivity(new Intent(this, MainActivity.class));
e.printStackTrace(); });
}
}); });
findViewById(R.id.intentRegisterButton).setOnClickListener(v -> { findViewById(R.id.intentRegisterButton).setOnClickListener(v -> {

View File

@ -10,6 +10,8 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsCompat;
import java.util.concurrent.CompletableFuture;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
@ -58,26 +60,30 @@ public class RegisterActivity extends AppCompatActivity {
String email = emailEditText.getText().toString(); String email = emailEditText.getText().toString();
String password = passwordEditText.getText().toString(); String password = passwordEditText.getText().toString();
Call<ParentAuthResponse> call = kidShiftApiService.parentRegister(new ParentAuthRequest(email, password)); CompletableFuture.runAsync(() -> {
try { Call<ParentAuthResponse> call = kidShiftApiService.parentRegister(new ParentAuthRequest(email, password));
Response<ParentAuthResponse> response = call.execute(); try {
if (response.isSuccessful()) { Response<ParentAuthResponse> response = call.execute();
ParentAuthResponse parentAuthResponse = response.body(); if (response.isSuccessful()) {
if (parentAuthResponse == null || parentAuthResponse.getAccessToken() == null) { ParentAuthResponse parentAuthResponse = response.body();
if (parentAuthResponse == null || parentAuthResponse.getAccessToken() == null) {
// エラー処理
logger.error("ParentAuthResponseがnullまたはAccessTokenがnullです");
return;
}
userSettings.getAppCommonSetting().setLoggedIn(true);
userSettings.getAppCommonSetting().setAccessToken(parentAuthResponse.getAccessToken());
} else {
logger.error("リクエストに失敗しました");
// エラー処理 // エラー処理
logger.error("ParentAuthResponseがnullまたはAccessTokenがnullです");
return;
} }
userSettings.getAppCommonSetting().setLoggedIn(true); } catch (Exception e) {
userSettings.getAppCommonSetting().setAccessToken(parentAuthResponse.getAccessToken()); logger.error("リクエストに失敗しました: " + e.getMessage());
} else { e.printStackTrace();
logger.error("リクエストに失敗しました");
// エラー処理
} }
} catch (Exception e) { }).thenRun(() -> {
logger.error("リクエストに失敗しました: " + e.getMessage()); startActivity(new Intent(this, MainActivity.class));
e.printStackTrace(); });
}
}); });
findViewById(R.id.intentLoginButton).setOnClickListener(v -> { findViewById(R.id.intentLoginButton).setOnClickListener(v -> {