| |
---|
| | final private MutableLiveData<Integer> stateMutableLiveData=new MutableLiveData<>(); |
---|
| | final private MutableLiveData<Integer> dnoMutableLiveData=new MutableLiveData<>(); |
---|
| | final private MutableLiveData<String> drawingMutableLiveData = new MutableLiveData<>(); |
---|
| | final private MutableLiveData<List<String>> keywordsMutableLiveData = new MutableLiveData<>(); |
---|
| | final private MutableLiveData<Integer> timerMutableLiveData = new MutableLiveData<>(); |
---|
| | |
---|
| | final private Retrofit retrofit; |
---|
| | private Integer drawingStatePreData; |
---|
| | private Integer dnoPreData = null; |
---|
| | private Integer timerPreData; |
---|
| | |
---|
| | private String drawingPreData; |
---|
| | private List<String> keywords; |
---|
| | |
---|
| |
---|
| | }); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | public void updateTimer(String rid) { |
---|
| | |
---|
| | final DrawingRest drawingRest = retrofit.create(DrawingRest.class); |
---|
| | Call<Integer> call = drawingRest.getTime(rid); |
---|
| | |
---|
| | call.enqueue(new Callback<Integer>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<Integer> call, Response<Integer> response) { |
---|
| | if (response.isSuccessful()){ |
---|
| | |
---|
| | if(response.body().equals(timerPreData)){ |
---|
| | //値が一緒なら書き換えない |
---|
| | }else{ |
---|
| | //値が異なるときのみライブデータを上書き |
---|
| | timerMutableLiveData.setValue(response.body()); |
---|
| | timerPreData = response.body(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | public void onFailure(Call<Integer> call, Throwable t) { |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | |
---|
| | // public LiveData<List<Member>> getMembers(String rid){ |
---|
| | // RoomViewModel members = new RoomViewModel(); |
---|
| | // return members.getMembersLiveData(); |
---|
| | // } |
---|
| |
---|
| | } |
---|
| | public LiveData<Integer> getState(){ |
---|
| | return this.stateMutableLiveData; |
---|
| | } |
---|
| | public LiveData<Integer> getTimer(){return this.timerMutableLiveData;} |
---|
| | |
---|
| | public void start(int interval, Iris iris) { |
---|
| | super.start(interval, iris); |
---|
| | String rid = iris.getRid(); |
---|
| |
---|
| | String rid = iris.getRid(); |
---|
| | String nickName = iris.getNickname(); |
---|
| | updateState(rid); |
---|
| | updateDno(rid, nickName); |
---|
| | updateTimer(rid); |
---|
| | } |
---|
| | |
---|
| | public void putDrawing(Bitmap image) { |
---|
| | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
---|
| |
---|
| | String encoded = encoder.encodeToString(byteArray); |
---|
| | |
---|
| | final DrawingRest drawingRest = retrofit.create(DrawingRest.class); |
---|
| | Integer dno = dnoMutableLiveData.getValue(); |
---|
| | |
---|
| | Call<String> call = drawingRest.putDrawing(iris.getRid(), dno, encoded ); |
---|
| | call.enqueue(new Callback<String>() { |
---|
| | @Override |
---|
| | public void onResponse(Call<String> call, Response<String> response) { |
---|
| | if (response.isSuccessful()){ |
---|
| | System.out.println("success"); |
---|
| | // System.out.println(encoded); |
---|
| | } |
---|
| | } |
---|
| | @Override |
---|
| | public void onFailure(Call<String> call, Throwable t) { |
---|
| |
---|
| | |
DrawingStateViewModelにタイマー関連の機能を書きました。
ok
efc5619
intomaster
fromOkazaki0927
on 27 Oct 2022