Skip to content

Commit

Permalink
fix: product name TextView was not updated on failed request status c…
Browse files Browse the repository at this point in the history
  • Loading branch information
VaiTon authored Sep 8, 2020
1 parent 9fb1bac commit 98549dd
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -649,28 +649,38 @@ private void setProductLanguage(String lang) {
disp.add(client.getProductByBarcodeSingle(product.getCode(), fields, Utils.getUserAgent(Utils.HEADER_USER_AGENT_SEARCH))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnSubscribe(disposable -> binding.name.setText(getString(R.string.txtLoading)))
.doOnSubscribe(disposable -> {
binding.name.setText(getString(R.string.txtLoading));
binding.name.setActivated(false);
})
.subscribe(productState -> {
if (productState.getStatus() != 1) {
Log.e(AddProductOverviewFragment.class.getSimpleName(),
String.format("Retrieved product with code %s, but status was not successful.", productState.getCode()));
binding.name.setText(StringUtils.EMPTY);
binding.name.setActivated(true);
return;
}
if (productState.getProduct().getProductName(lang) != null) {
if (languageCode.equals(lang)) {
binding.name.setText(productState.getProduct().getProductName(lang));
binding.name.setActivated(true);
if (activity instanceof AddProductActivity) {
((AddProductActivity) activity).setIngredients("set", productState.getProduct().getIngredientsText(lang));
((AddProductActivity) activity).updateLanguage();
}
}
} else {
binding.name.setText(null);
binding.name.setText(StringUtils.EMPTY);
binding.name.setActivated(true);
if (activity instanceof AddProductActivity) {
((AddProductActivity) activity).setIngredients("set", null);
}
}
}, e -> {
Log.w("addProductOverview", "Error retrieving product state from server api.", e);
binding.name.setText(null);
Log.e(AddProductOverviewFragment.class.getSimpleName(), "Error retrieving product state from server api.", e);
binding.name.setText(StringUtils.EMPTY);
binding.name.setActivated(true);
}));
}
}
Expand Down

0 comments on commit 98549dd

Please sign in to comment.