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..64b850d 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,14 @@ 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変更 + private final MutableLiveData error_changeAccount_LiveData; + public SettingsViewModel(){ @@ -26,8 +31,14 @@ .build(); this.accountsRest = retrofit.create(AccountsRest.class); this.accountColorLiveData = new MutableLiveData<>(); + this.error_changePw_LiveData = new MutableLiveData<>(); + this.error_deleteAccount_LiveData = new MutableLiveData<>(); + this.error_changeAccount_LiveData = new MutableLiveData<>(); } public MutableLiveData getAccountColorLiveData(){return accountColorLiveData;} + public MutableLiveData getError_changePw_LiveData(){return error_changePw_LiveData;} + public MutableLiveData getError_deleteAccount_LiveData(){return error_deleteAccount_LiveData;} + public MutableLiveData getError_changeAccount_LiveData(){return error_changeAccount_LiveData;} public void loadAccountColor(String accountId){ Call call= accountsRest.getAccountColor(accountId); @@ -60,15 +71,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 +97,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 +109,7 @@ public void onFailure(Call call, Throwable t) { System.out.println("NetWorkError"+t); //もしコンソール表記をするならこの下に処理を記載 + error_deleteAccount_LiveData.setValue(404); } }); } @@ -120,23 +138,27 @@ //通信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) { if(response.isSuccessful()){ System.out.println("success"); + error_changeAccount_LiveData.setValue(204); }else{ System.out.println("fail"); + error_changeAccount_LiveData.setValue(404); } } @Override public void onFailure(Call call, Throwable t) { System.out.println("NetWorkError"+t); + error_changeAccount_LiveData.setValue(404); } }); } + }