From 8dee07dafb8305bff76730298cc0dc1bc6f14c40 Mon Sep 17 00:00:00 2001 From: Scot Scriven Date: Thu, 29 Sep 2016 21:27:07 +0200 Subject: [PATCH] Fix #104 & #132 --- .../fragments/SummaryProductFragment.java | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/SummaryProductFragment.java b/app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/SummaryProductFragment.java index 99dc903b599b..b9df544d9bae 100644 --- a/app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/SummaryProductFragment.java +++ b/app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/SummaryProductFragment.java @@ -3,42 +3,36 @@ import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.v4.app.FragmentManager; import android.support.v4.view.animation.LinearOutSlowInInterpolator; import android.text.Html; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import com.hkm.slider.Animations.DescriptionAnimation; import com.hkm.slider.Indicators.PagerIndicator; import com.hkm.slider.SliderLayout; import com.hkm.slider.SliderTypes.AdjustableSlide; import com.hkm.slider.SliderTypes.BaseSliderView; -import com.hkm.slider.SliderTypes.DefaultSliderView; - import java.util.ArrayList; - -import butterknife.Bind; +import butterknife.BindView; import openfoodfacts.github.scrachx.openfood.R; import openfoodfacts.github.scrachx.openfood.models.State; public class SummaryProductFragment extends BaseFragment { - @Bind(R.id.textNameProduct) TextView nameProduct; - @Bind(R.id.textBarcodeProduct) TextView barCodeProduct; - @Bind(R.id.textQuantityProduct) TextView quantityProduct; - @Bind(R.id.textPackagingProduct) TextView packagingProduct; - @Bind(R.id.textBrandProduct) TextView brandProduct; - @Bind(R.id.textManufacturingProduct) TextView manufacturingProduct; - @Bind(R.id.textCityProduct) TextView cityProduct; - @Bind(R.id.textStoreProduct) TextView storeProduct; - @Bind(R.id.textCountryProduct) TextView countryProduct; - @Bind(R.id.textCategoryProduct) TextView categoryProduct; - @Bind(R.id.slider) SliderLayout sliderImages; - @Bind(R.id.custom_indicator) PagerIndicator pagerIndicator; + @BindView(R.id.textNameProduct) TextView nameProduct; + @BindView(R.id.textBarcodeProduct) TextView barCodeProduct; + @BindView(R.id.textQuantityProduct) TextView quantityProduct; + @BindView(R.id.textPackagingProduct) TextView packagingProduct; + @BindView(R.id.textBrandProduct) TextView brandProduct; + @BindView(R.id.textManufacturingProduct) TextView manufacturingProduct; + @BindView(R.id.textCityProduct) TextView cityProduct; + @BindView(R.id.textStoreProduct) TextView storeProduct; + @BindView(R.id.textCountryProduct) TextView countryProduct; + @BindView(R.id.textCategoryProduct) TextView categoryProduct; + @BindView(R.id.slider) SliderLayout sliderImages; + @BindView(R.id.custom_indicator) PagerIndicator pagerIndicator; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -76,54 +70,54 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { sliderImages.setDuration(5500); sliderImages.startAutoCycle(); - if(!state.getProduct().getProductName().trim().isEmpty()) { + if(state.getProduct().getProductName() != null && !state.getProduct().getProductName().trim().isEmpty()) { nameProduct.setText(state.getProduct().getProductName()); } else { nameProduct.setVisibility(View.GONE); } - if(!state.getProduct().getCode().trim().isEmpty()) { + if(state.getProduct().getCode() != null && !state.getProduct().getCode().trim().isEmpty()) { barCodeProduct.setText(Html.fromHtml("" + getString(R.string.txtBarcode) + "" + ' ' + state.getProduct().getCode())); } else { barCodeProduct.setVisibility(View.GONE); } - if(!state.getProduct().getQuantity().trim().isEmpty()) { + if(state.getProduct().getQuantity() != null && !state.getProduct().getQuantity().trim().isEmpty()) { quantityProduct.setText(Html.fromHtml("" + getString(R.string.txtQuantity) + "" + ' ' + state.getProduct().getQuantity())); } else { quantityProduct.setVisibility(View.GONE); } - if(!state.getProduct().getPackaging().trim().isEmpty()) { + if(state.getProduct().getPackaging() != null && !state.getProduct().getPackaging().trim().isEmpty()) { packagingProduct.setText(Html.fromHtml("" + getString(R.string.txtPackaging) + "" + ' ' + state.getProduct().getPackaging())); } else { packagingProduct.setVisibility(View.GONE); } - if(!state.getProduct().getBrands().trim().isEmpty()) { + if(state.getProduct().getBrands() != null && !state.getProduct().getBrands().trim().isEmpty()) { brandProduct.setText(Html.fromHtml("" + getString(R.string.txtBrands) + "" + ' ' + state.getProduct().getBrands())); } else { brandProduct.setVisibility(View.GONE); } - if(!state.getProduct().getManufacturingPlaces().trim().isEmpty()) { + if(state.getProduct().getManufacturingPlaces() != null && !state.getProduct().getManufacturingPlaces().trim().isEmpty()) { manufacturingProduct.setText(Html.fromHtml("" + getString(R.string.txtManufacturing) + "" + ' ' + state.getProduct().getManufacturingPlaces())); } else { manufacturingProduct.setVisibility(View.GONE); } String categ; - if (!state.getProduct().getCategories().trim().isEmpty()) { - categoryProduct.setVisibility(View.GONE); - } else { + if (state.getProduct().getCategories() != null && !state.getProduct().getCategories().trim().isEmpty()) { categ = state.getProduct().getCategories().replace(",", ", "); categoryProduct.setText(Html.fromHtml("" + getString(R.string.txtCategories) + "" + ' ' + categ)); + } else { + categoryProduct.setVisibility(View.GONE); } - if(!state.getProduct().getCitiesTags().toString().trim().equals("[]")) { + if(state.getProduct().getCitiesTags() != null && !state.getProduct().getCitiesTags().toString().trim().equals("[]")) { cityProduct.setText(Html.fromHtml("" + getString(R.string.txtCity) + "" + ' ' + state.getProduct().getCitiesTags().toString().replace("[", "").replace("]", ""))); } else { cityProduct.setVisibility(View.GONE); } - if(!state.getProduct().getStores().trim().isEmpty()) { + if(state.getProduct().getStores() != null && !state.getProduct().getStores().trim().isEmpty()) { storeProduct.setText(Html.fromHtml("" + getString(R.string.txtStores) + "" + ' ' + state.getProduct().getStores())); } else { storeProduct.setVisibility(View.GONE); } - if(!state.getProduct().getCountries().trim().isEmpty()) { + if(state.getProduct().getCountries() != null && !state.getProduct().getCountries().trim().isEmpty()) { countryProduct.setText(Html.fromHtml("" + getString(R.string.txtCountries) + "" + ' ' + state.getProduct().getCountries())); } else { countryProduct.setVisibility(View.GONE);