diff --git a/app/src/main/java/org/ntlab/irisclient/resources/GameRest.java b/app/src/main/java/org/ntlab/irisclient/resources/GameRest.java index 78cb88d..dd1d4a8 100644 --- a/app/src/main/java/org/ntlab/irisclient/resources/GameRest.java +++ b/app/src/main/java/org/ntlab/irisclient/resources/GameRest.java @@ -42,7 +42,7 @@ //----------------------------------------------- // カードの色を取得するメソッド @GET("/{rid}/game/color") - Call> getColor( + Call> getColorList( @Path("rid") String rid ); 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 fc27d90..1138b61 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java @@ -1,7 +1,7 @@ package org.ntlab.irisclient.viewmodels; +import org.ntlab.irisclient.entities.GameJson; import org.ntlab.irisclient.entities.TurnJson; -import org.ntlab.irisclient.models.Game; import org.ntlab.irisclient.resources.GameRest; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; @@ -19,7 +19,8 @@ //フィールド private String rid; - private int tno; + private Integer tno; + private Integer cno; private String team; private String hint; private Integer max; @@ -28,13 +29,16 @@ final private MutableLiveData turnsMutableLiveData; final private MutableLiveData turnMutableLiveData; final private MutableLiveData> colorMutableLiveData; + final private MutableLiveData> opensMutableLiveData; final private MutableLiveData> mapMutableLiveData; - final private Game game = new Game(); + final private MutableLiveData imageMutableLiveData; + final private GameJson game = new GameJson(); final private Retrofit retrofit; //更新比較用フィールド private String turnsPreData = null; private TurnJson turnPreData = null; + private List opensPreData = null; //------------------------------------------------------------------ //コンストラクタ @@ -42,7 +46,9 @@ this.turnsMutableLiveData = new MutableLiveData<>(); this.turnMutableLiveData = new MutableLiveData<>(); this.colorMutableLiveData = new MutableLiveData<>(); + this.opensMutableLiveData = new MutableLiveData<>(); this.mapMutableLiveData = new MutableLiveData<>(); + this.imageMutableLiveData = new MutableLiveData<>(); this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") .addConverterFactory(JacksonConverterFactory.create()) @@ -54,6 +60,9 @@ public void setRid(String rid) { this.rid = rid; } +// public void setCno(Integer cno) { +// this.cno = cno; +// } public void putHint(String hint, int max) { this.hint = hint; @@ -72,26 +81,33 @@ public LiveData> getColorLiveData() { return this.colorMutableLiveData; } + public LiveData> getOpenLiveData() { + return this.opensMutableLiveData; + } public LiveData> getMapLiveData() { return this.mapMutableLiveData; } - public void getGame() { - return; + public LiveData getImageLiveData() { + return this.imageMutableLiveData; } -// public Integer getTurnNumber(){ -// return tno; -// } + public GameJson getGame() { + return game; + } + //----------------------------------------------------------------------------- // updates public void init() { updateColor(rid); updateMap(rid); + updateImage(rid); } + @Override public void update() { updateTurns(rid); updateTurn(rid); + updateOpens(rid); } //r,bの取得(今どちらのチームかの判別) @@ -157,9 +173,9 @@ } //カードのカラー(r,b,g,d)の取得 - public void updateColor(String rid) { + private void updateColor(String rid) { final GameRest gameRest = retrofit.create(GameRest.class); - Call> call = gameRest.getColor(rid); + Call> call = gameRest.getColorList(rid); call.enqueue(new Callback>() { @Override @@ -177,8 +193,39 @@ }); } + //現在開いているすべてのカードを取得 + public void updateOpens(String rid) { + final GameRest gameRest = retrofit.create(GameRest.class); + Call> call = gameRest.getOpens(rid); + + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + if (response.isSuccessful()){ + if(opensPreData == null){ + //初回代入 + opensMutableLiveData.setValue(response.body()); + opensPreData = response.body(); + }if(response.body().equals(turnPreData)){ + //値が一緒なら書き換えない + }else{ + //値が異なるときのみライブデータを上書き + opensMutableLiveData.setValue(response.body()); + opensPreData = response.body(); + } + } + } + + @Override + public void onFailure(Call> call, Throwable t) { + System.out.println("通信失敗:changeBelongsAndMaster"); + System.out.println(t); + } + }); + } + //カードの並び順の取得 - public void updateMap(String rid) { + private void updateMap(String rid) { final GameRest gameRest = retrofit.create(GameRest.class); Call> call = gameRest.getMap(rid); @@ -198,4 +245,25 @@ }); } + //カード(画像)の取得 + private void updateImage(String rid) { + final GameRest gameRest = retrofit.create(GameRest.class); + Call call = gameRest.getGame(rid); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + imageMutableLiveData.setValue(response.body()); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("通信失敗:changeBelongsAndMaster"); + System.out.println(t); + } + }); + } + }