diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index 1adb1c2..40556a2 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -7,11 +7,11 @@ - + - + \ No newline at end of file diff --git a/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java index b670f3a..aec3547 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/AccountViewModel.java @@ -1,5 +1,6 @@ package com.example.nemophila.viewmodels; +import android.util.Log; import android.widget.TextView; import com.example.nemophila.R; @@ -12,6 +13,7 @@ import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -31,6 +33,7 @@ private final MutableLiveData pwLiveData; private final MutableLiveData> accountPostsLiveData; private final MutableLiveData pwErrorLiveData; + private final MutableLiveData accountLiveData; // コンストラクタ public AccountViewModel() { @@ -43,6 +46,7 @@ this.pwLiveData = new MutableLiveData<>(); this.accountPostsLiveData = new MutableLiveData<>(); this.pwErrorLiveData = new MutableLiveData<>(); + this.accountLiveData = new MutableLiveData<>(); } // ライブデータの取得(ゲッター) @@ -56,6 +60,9 @@ public MutableLiveData getPwErrorLiveData() { return pwErrorLiveData; } + public MutableLiveData getAccountLiveData() { + return accountLiveData; + } // 対象のアカウント情報の削除 public void deleteAccount(String uid, String token) { @@ -156,6 +163,47 @@ accountPostsLiveData.setValue(posts); } + //idからアカウント情報を取得するメソッド + private void fetchAccount(String id) { + Call call = accountsRest.getAccount(id); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + Account ac = new Account(response.body()); + accountLiveData.setValue(ac); + System.out.println("success"); + } else { + System.out.println("response error"); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("network error" + t); + } + }); + } + + //同期的にidからアカウント情報を取得するメソッド + public Account sample(String id) { + try { + Response response = accountsRest.getAccount(id).execute(); + + if (response.isSuccessful()) { + Account account = new Account(response.body()); + return account; + } else { + Log.d("message", "error" + response.code()); + } + + } catch (IOException e) { + Log.i("message", "error" + e.getMessage()); + } + return null; + } + // 対象のアカウントがした投稿の削除 public void deleteAccountPost(String sid, String uid, String pid, String token) { Call call = accountsRest.deletePost(sid, uid, pid, token);