diff --git a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java index 8ac9b26..0a79ef0 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java @@ -29,6 +29,7 @@ final private MutableLiveData> openListMutableLiveData; final private MutableLiveData maxMutableLiveData; final private MutableLiveData turnNumberMutableLiveData; + final private MutableLiveData turnStateMutableLiveData; final private MutableLiveData> colorMutableLiveData; final private MutableLiveData> opensMutableLiveData; final private MutableLiveData> mapMutableLiveData; @@ -45,6 +46,7 @@ private List openListPreData = null; private Integer maxPreData = null; private Integer turnNumberPreData = null; + private Integer turnStatePreData = null; private List opensPreData = null; private Boolean[] QPreData = null; @@ -57,6 +59,7 @@ this.openListMutableLiveData = new MutableLiveData<>(); this.maxMutableLiveData = new MutableLiveData<>(); this.turnNumberMutableLiveData = new MutableLiveData<>(); + this.turnStateMutableLiveData = new MutableLiveData<>(); this.mapMutableLiveData = new MutableLiveData<>(); this.colorMutableLiveData = new MutableLiveData<>(); this.opensMutableLiveData = new MutableLiveData<>(); @@ -80,7 +83,6 @@ startColor(); startMap(); startImage(); - } //-------------------------------------------------------------- @@ -272,6 +274,7 @@ @Override public void update() { updateTurnNumber(); + updateTurnState(); updateTurns(); updateHint(); updateOpenList(); @@ -294,12 +297,14 @@ //初回代入 turnsMutableLiveData.setValue(response.body()); turnsPreData = response.body(); + System.out.println("現在のチームは" + turnsPreData + "です"); }else if(response.body().equals(turnsPreData)){ //値が一緒なら書き換えない }else{ //値が異なるときのみライブデータを上書き turnsMutableLiveData.setValue(response.body()); turnsPreData = response.body(); + System.out.println("現在のチームは" + turnsPreData + "です"); } } } @@ -447,12 +452,16 @@ //初回代入 turnNumberMutableLiveData.setValue(response.body()); turnNumberPreData = response.body(); + tno = response.body(); + System.out.println("TurnNumberは" + turnNumberPreData + "です"); }else if(response.body().equals(turnNumberPreData)){ //値が一緒なら書き換えない }else{ //値が異なるときのみライブデータを上書き turnNumberMutableLiveData.setValue(response.body()); turnNumberPreData = response.body(); + tno = response.body(); + System.out.println("TurnNumberは" + turnNumberPreData + "です"); } } } @@ -466,6 +475,38 @@ } + //TurnStateの更新 + public void updateTurnState() { + Call call = gameRest.getTurnstate(rid, tno); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + if(turnStatePreData == null){ + //初回代入 + turnStateMutableLiveData.setValue(response.body()); + turnStatePreData = response.body(); + }else if(response.body().equals(turnStatePreData)){ + //値が一緒なら書き換えない + }else{ + //値が異なるときのみライブデータを上書き + turnStateMutableLiveData.setValue(response.body()); + turnStatePreData = response.body(); + System.out.println("TurnStateは" + turnStatePreData + "です"); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("通信失敗:updateTurnState"); + System.out.println(t); + } + }); + } + + //現在開いているすべてのカードを取得([tffftffffftttff]みたいなリストを逐一更新する、マスが開くたびに更新) public void updateOpens() { Call> call = gameRest.getOpens(rid);