diff --git a/app/src/main/java/com/example/citrusclient/viewmodels/SettingsViewModel.java b/app/src/main/java/com/example/citrusclient/viewmodels/SettingsViewModel.java index d58ef10..a696254 100644 --- a/app/src/main/java/com/example/citrusclient/viewmodels/SettingsViewModel.java +++ b/app/src/main/java/com/example/citrusclient/viewmodels/SettingsViewModel.java @@ -1,10 +1,7 @@ package com.example.citrusclient.viewmodels; -import com.example.citrusclient.Citrus; import com.example.citrusclient.rest.AccountsRest; -import java.net.HttpCookie; - import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import retrofit2.Call; @@ -17,6 +14,13 @@ private final Retrofit retrofit; private final AccountsRest accountsRest; private final MutableLiveData accountColorLiveData; + //通信レスポンスの画面表示用のライブデーター + //PW変更時の通信レスポンス結果格納用 + private final MutableLiveData error_changePw_LiveData; + //アカウント削除時の通信レスポンス結果格納用 + private final MutableLiveData error_deleteAccount_LiveData; + //アカウントID変更はやるのか不明なので一旦保留 + public SettingsViewModel(){ @@ -26,8 +30,12 @@ .build(); this.accountsRest = retrofit.create(AccountsRest.class); this.accountColorLiveData = new MutableLiveData<>(); + this.error_changePw_LiveData = new MutableLiveData<>(); + this.error_deleteAccount_LiveData = new MutableLiveData<>(); } public MutableLiveData getAccountColorLiveData(){return accountColorLiveData;} + public MutableLiveData getResponse_changePw(){return error_changePw_LiveData;} + public MutableLiveDatagetResponse_deleteAccount(){return error_deleteAccount_LiveData;} public void loadAccountColor(String accountId){ Call call= accountsRest.getAccountColor(accountId); @@ -60,15 +68,19 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("success"); + error_changePw_LiveData.setValue(204); + //成功処理 } else { System.out.println("fail"); + error_changePw_LiveData.setValue(404); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("NetWorkError"+t); + error_changePw_LiveData.setValue(404); } }); } @@ -82,9 +94,11 @@ if(response.isSuccessful()){ System.out.println("success"); //成功処理 + error_deleteAccount_LiveData.setValue(204); }else{ System.out.println("fail"); //もしコンソール表記をするならこの下に処理を記載 + error_deleteAccount_LiveData.setValue(404); } } @@ -92,6 +106,7 @@ public void onFailure(Call call, Throwable t) { System.out.println("NetWorkError"+t); //もしコンソール表記をするならこの下に処理を記載 + error_deleteAccount_LiveData.setValue(404); } }); } @@ -120,8 +135,8 @@ //通信Ver4 //アカウント名変更 - public void changeAccount(String accountId, String accountColor, String token){ - Call call =accountsRest.changeColor(accountId, accountColor, token); + public void changeAccount(String accountId, String new_account_id, String old_password, String token){ + Call call =accountsRest.changeAccount(accountId, new_account_id, old_password, token); call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { @@ -139,4 +154,5 @@ }); } + }