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 56f480b..7073c10 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java @@ -1,8 +1,11 @@ package org.ntlab.irisclient.viewmodels; +import org.ntlab.irisclient.Iris; import org.ntlab.irisclient.entities.GameJson; import org.ntlab.irisclient.entities.TurnJson; import org.ntlab.irisclient.resources.GameRest; +import org.ntlab.irisclient.resources.RoomsRest; + import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; @@ -22,8 +25,8 @@ private Integer tno; private Integer cno; private String team; - private String hint; - private Integer max; + + private List openList; final private MutableLiveData turnsMutableLiveData; @@ -33,6 +36,7 @@ final private MutableLiveData> mapMutableLiveData; final private MutableLiveData imageMutableLiveData; final private GameJson game = new GameJson(); + final private GameRest gameRest; final private Retrofit retrofit; //更新比較用フィールド @@ -55,6 +59,8 @@ .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") .addConverterFactory(JacksonConverterFactory.create()) .build(); + + this.gameRest = retrofit.create(GameRest.class); } //---------------------------------------------------- @@ -63,12 +69,6 @@ this.rid = rid; } - public void putHint(String hint, int max) { - this.hint = hint; - this.max = max; - updateTurn(); - } - public void setOpenList(Integer cno) { this.cno = cno; } @@ -76,9 +76,9 @@ //-------------------------------------------------------------- // getter - public LiveData getTurnsLiveData() { - return this.turnsMutableLiveData; - } +// public LiveData getTurnsLiveData() { +// return this.turnsMutableLiveData; +// } public LiveData getTurnLiveData() { return this.turnMutableLiveData; } @@ -99,6 +99,47 @@ } + //--------------------------------------------- + // マスターのヒントを送信するメソッド + 最大回答数も送信 + public void putHint(String hint, Integer max) { + + Call call = gameRest.putHint(rid, tno, hint, max); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + System.out.println("通信成功:changeBelongsAndMaster"); + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("通信失敗:changeBelongsAndMaster"); + System.out.println(t); + } + }); + } + +// public void putTeam(String team){ +// final Iris iris = retrofit.create(Iris.class); +// Call call = iris.setTeam(team); +// +// call.enqueue(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()){ +// System.out.println("通信成功:changeBelongsAndMaster"); +// } +// } +// @Override +// public void onFailure(Call call, Throwable t) { +// System.out.println("通信失敗:changeBelongsAndMaster"); +// System.out.println(t); +// } +// }); +// } + + //----------------------------------------------------------------------------- // updates public void init() { @@ -109,46 +150,45 @@ @Override public void update() { - updateTurns(rid); - //updateTurn(rid); + //updateTurns(rid); + updateTurn(rid); updateOpens(rid); } - //r,bの取得(今どちらのチームかの判別) - public void updateTurns(String rid) { - final GameRest gameRest = retrofit.create(GameRest.class); - Call call = gameRest.getTeam(rid); +// //r,bの取得(今どちらのチームかの判別) +// public void updateTurns(String rid) { +// final GameRest gameRest = retrofit.create(GameRest.class); +// Call call = gameRest.getTeam(rid); +// +// call.enqueue(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()){ +// if(turnsPreData == null){ +// //初回代入 +// turnsMutableLiveData.setValue(response.body()); +// turnsPreData = response.body(); +// }else if(response.body().equals(turnsPreData)){ +// //値が一緒なら書き換えない +// }else{ +// //値が異なるときのみライブデータを上書き +// turnsMutableLiveData.setValue(response.body()); +// turnsPreData = response.body(); +// } +// } +// } +// +// @Override +// public void onFailure(Call call, Throwable t) { +// System.out.println("通信失敗:changeBelongsAndMaster"); +// System.out.println(t); +// } +// }); +// } - call.enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - if (response.isSuccessful()){ - if(turnsPreData == null){ - //初回代入 - turnsMutableLiveData.setValue(response.body()); - turnsPreData = response.body(); - }else if(response.body().equals(turnsPreData)){ - //値が一緒なら書き換えない - }else{ - //値が異なるときのみライブデータを上書き - turnsMutableLiveData.setValue(response.body()); - turnsPreData = response.body(); - } - } - } - - @Override - public void onFailure(Call call, Throwable t) { - System.out.println("通信失敗:changeBelongsAndMaster"); - System.out.println(t); - } - }); - } - - //hint,openList,maxの更新 - public void updateTurn() { - final GameRest gameRest = retrofit.create(GameRest.class); - Call call = gameRest.putHint(rid, tno, hint, max); + //hint,openList,maxの取得 + public void updateTurn(String rid) { + Call call = gameRest.getTurns(rid, tno); call.enqueue(new Callback() { @Override