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 205eb27..c4be43e 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java @@ -376,27 +376,29 @@ call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - if (response.isSuccessful()){ - if(hintPreData == null){ - try { - hintMutableLiveData.setValue(response.body().string()); + if (response.isSuccessful()) { + if (response.body() != null) { + if (hintPreData == null) { + try { + hintMutableLiveData.setValue(response.body().string()); - hintPreData = hintMutableLiveData.getValue(); - System.out.println("今回のヒントは" + hintPreData + "です(初回)"+hintMutableLiveData.getValue()); - } catch (IOException e) { - e.printStackTrace(); - } - }else if(hintMutableLiveData.getValue().equals(hintPreData)){ - //値が一緒なら書き換えない - }else{ - try { - hintMutableLiveData.setValue(response.body().string()); - hintPreData = hintMutableLiveData.getValue(); - } catch (IOException e) { - e.printStackTrace(); - } + hintPreData = hintMutableLiveData.getValue(); + System.out.println("今回のヒントは" + hintPreData + "です(初回)" + hintMutableLiveData.getValue()); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (hintMutableLiveData.getValue().equals(hintPreData)) { + //値が一緒なら書き換えない + } else { + try { + hintMutableLiveData.setValue(response.body().string()); + hintPreData = hintMutableLiveData.getValue(); + } catch (IOException e) { + e.printStackTrace(); + } - System.out.println("今回のヒントは" + hintPreData + "です"); + System.out.println("今回のヒントは" + hintPreData + "です"); + } } } } @@ -447,16 +449,18 @@ @Override public void onResponse(Call call, Response response) { if (response.isSuccessful()){ - if(maxPreData == null){ - //初回代入 - maxMutableLiveData.setValue(response.body()); - maxPreData = response.body(); - }else if(response.body().equals(maxPreData)){ - //値が一緒なら書き換えない - }else{ - //値が異なるときのみライブデータを上書き - maxMutableLiveData.setValue(response.body()); - maxPreData = response.body(); + if (response.body() != null) { + if (maxPreData == null) { + //初回代入 + maxMutableLiveData.setValue(response.body()); + maxPreData = response.body(); + } else if (response.body().equals(maxPreData)) { + //値が一緒なら書き換えない + } else { + //値が異なるときのみライブデータを上書き + maxMutableLiveData.setValue(response.body()); + maxPreData = response.body(); + } } } } @@ -476,16 +480,16 @@ call.enqueue(new Callback() { @Override public void onResponse(Call call, Response response) { - if (response.isSuccessful()){ - if(turnNumberPreData == null){ + if (response.isSuccessful()) { + if (turnNumberPreData == null) { //初回代入 turnNumberMutableLiveData.setValue(response.body()); turnNumberPreData = response.body(); tno = response.body(); System.out.println("TurnNumberは" + turnNumberPreData + "です"); - }else if(response.body().equals(turnNumberPreData)){ + } else if (response.body().equals(turnNumberPreData)) { //値が一緒なら書き換えない - }else{ + } else { //値が異なるときのみライブデータを上書き turnNumberMutableLiveData.setValue(response.body()); turnNumberPreData = response.body();