diff --git a/app/src/main/java/org/ntlab/irisclient/viewmodels/DrawingStateViewModel.java b/app/src/main/java/org/ntlab/irisclient/viewmodels/DrawingStateViewModel.java index 1e374ad..1fd4811 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/DrawingStateViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/DrawingStateViewModel.java @@ -1,6 +1,7 @@ package org.ntlab.irisclient.viewmodels; import org.ntlab.irisclient.models.DrawingState; +import org.ntlab.irisclient.resources.DrawingRest; import org.ntlab.irisclient.resources.RoomsRest; import androidx.lifecycle.LiveData; @@ -17,14 +18,15 @@ public class DrawingStateViewModel extends ViewModel { - final private MutableLiveData drawingStateMutableLiveData; + final private MutableLiveData stateMutableLiveData=new MutableLiveData<>(); + final private MutableLiveData dnoMutableLiveData=new MutableLiveData<>(); final private Retrofit retrofit; - private DrawingState drawingStatePreData; + private Integer drawingStatePreData; + private Integer dnoPreData; //フィールド - public DrawingStateViewModel(MutableLiveData drawingStateMutableLiveData) { - this.drawingStateMutableLiveData = new MutableLiveData<>(); + public DrawingStateViewModel(MutableLiveData drawingStateMutableLiveData) { this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") .addConverterFactory(JacksonConverterFactory.create()) @@ -32,44 +34,70 @@ } //ゲッター - public LiveData getDrawingStateLiveData(){ - return this.drawingStateMutableLiveData; + public LiveData getDrawingStateLiveData(){ + return this.stateMutableLiveData; } -// public void updateDrawingState(String rid) { + public void updateState(String rid) { + + final RoomsRest roomsRest = retrofit.create(RoomsRest.class); + final DrawingRest drawingRest = retrofit.create(DrawingRest.class); + Call call = roomsRest.getState(rid); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + + if(response.body().equals(drawingStatePreData)){ + //値が一緒なら書き換えない + }else{ + //値が異なるときのみライブデータを上書き + stateMutableLiveData.setValue(response.body()); + drawingStatePreData = response.body(); + } + } + } + + @Override + public void onFailure(Call call, Throwable t) { + } + }); + } +// public void updateDno(String rid) { // // final RoomsRest roomsRest = retrofit.create(RoomsRest.class); -// Call call = roomsRest.getState(rid); +// final DrawingRest drawingRest = retrofit.create(DrawingRest.class); +// Call call = drawingRest.getDno(rid,nickname); // -// -// call.enqueue(new Callback() { +// call.enqueue(new Callback() { // @Override -// public void onResponse(Call call, Response response) { +// public void onResponse(Call call, Response response) { // if (response.isSuccessful()){ // // if(response.body().equals(drawingStatePreData)){ // //値が一緒なら書き換えない // }else{ // //値が異なるときのみライブデータを上書き -// drawingStateMutableLiveData.setValue(response.body()); -// drawingStatePreData = response.body(); +// dnoMutableLiveData.setValue(response.body()); +// dnoPreData = response.body(); // } // } // } - +// // @Override -// public void onFailure(Call call, Throwable t) { +// public void onFailure(Call call, Throwable t) { // } // }); -// } +// } public List getKeywords(String rid){ return null; } -public int getDno(){ - return 0; +public LiveData getDno(){ + return this.dnoMutableLiveData; } -public int getCno(){ - return 0; +public LiveData getCno(){ + return this.stateMutableLiveData; } }