Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2205: Bind new field in HTML card in the Environnment tab #2208

Merged
merged 6 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public class Product implements Serializable {
private String warning;
@JsonProperty("customer_service")
private String customerService;
@JsonProperty("environment_infocard")
private String environmentInfocard;


private Map<String, Object> additionalProperties = new HashMap<>();
Expand Down Expand Up @@ -559,6 +561,7 @@ public String getNoNutritionData() {
return noNutritionData;
}

public String getEnvironmentInfocard() {return environmentInfocard;}
/**
* @return Other information
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface OpenFoodAPIService {

String PRODUCT_API_COMMENT = "Official Android app";

@GET("api/v0/product/{barcode}.json?fields=image_small_url,vitamins_tags,minerals_tags,amino_acids_tags,other_nutritional_substances_tags,image_front_url,image_ingredients_url,image_nutrition_url,url,code,traces_tags,ingredients_that_may_be_from_palm_oil_tags,additives_tags,allergens_hierarchy,manufacturing_places,nutriments,ingredients_from_palm_oil_tags,brands_tags,traces,categories_tags,ingredients_text,product_name,generic_name,ingredients_from_or_that_may_be_from_palm_oil_n,serving_size,allergens_tags,allergens,origins,stores,nutrition_grade_fr,nutrient_levels,countries,countries_tags,brands,packaging,labels_tags,labels_hierarchy,cities_tags,quantity,ingredients_from_palm_oil_n,image_url,link,emb_codes_tags,states_tags,creator,created_t,last_modified_t,last_modified_by,editors_tags,nova_groups,lang,purchase_places,nutrition_data_per,no_nutrition_data,other,other_information,conservation_conditions,recycling_instructions_to_discard,recycling_instructions_to_recycle,warning,customer_service")
@GET("api/v0/product/{barcode}.json?fields=image_small_url,vitamins_tags,minerals_tags,amino_acids_tags,other_nutritional_substances_tags,image_front_url,image_ingredients_url,image_nutrition_url,url,code,traces_tags,ingredients_that_may_be_from_palm_oil_tags,additives_tags,allergens_hierarchy,manufacturing_places,nutriments,ingredients_from_palm_oil_tags,brands_tags,traces,categories_tags,ingredients_text,product_name,generic_name,ingredients_from_or_that_may_be_from_palm_oil_n,serving_size,allergens_tags,allergens,origins,stores,nutrition_grade_fr,nutrient_levels,countries,countries_tags,brands,packaging,labels_tags,labels_hierarchy,cities_tags,quantity,ingredients_from_palm_oil_n,image_url,link,emb_codes_tags,states_tags,creator,created_t,last_modified_t,last_modified_by,editors_tags,nova_groups,lang,purchase_places,nutrition_data_per,no_nutrition_data,other,other_information,conservation_conditions,recycling_instructions_to_discard,recycling_instructions_to_recycle,warning,customer_service,environment_infocard")
Call<State> getFullProductByBarcode(@Path("barcode") String barcode,
@Header("User-Agent") String header);

Expand All @@ -45,7 +45,7 @@ Single<State> getExistingProductDetails(@Path("barcode") String barcode,
@Query("fields") String fields,
@Header("User-Agent") String header);

@GET("api/v0/product/{barcode}.json?fields=image_small_url,vitamins_tags,minerals_tags,amino_acids_tags,other_nutritional_substances_tags,image_front_url,image_ingredients_url,image_nutrition_url,url,code,traces_tags,ingredients_that_may_be_from_palm_oil_tags,additives_tags,allergens_hierarchy,manufacturing_places,nutriments,ingredients_from_palm_oil_tags,brands_tags,traces,categories_tags,ingredients_text,product_name,generic_name,ingredients_from_or_that_may_be_from_palm_oil_n,serving_size,allergens_tags,allergens,origins,stores,nutrition_grade_fr,nutrient_levels,countries,countries_tags,brands,packaging,labels_tags,labels_hierarchy,cities_tags,quantity,ingredients_from_palm_oil_n,image_url,link,emb_codes_tags,states_tags,creator,created_t,last_modified_t,last_modified_by,editors_tags,nova_groups,lang,purchase_places,nutrition_data_per,no_nutrition_data,other_information,conservation_conditions,recycling_instructions_to_discard,recycling_instructions_to_recycle,warning,customer_service")
@GET("api/v0/product/{barcode}.json?fields=image_small_url,vitamins_tags,minerals_tags,amino_acids_tags,other_nutritional_substances_tags,image_front_url,image_ingredients_url,image_nutrition_url,url,code,traces_tags,ingredients_that_may_be_from_palm_oil_tags,additives_tags,allergens_hierarchy,manufacturing_places,nutriments,ingredients_from_palm_oil_tags,brands_tags,traces,categories_tags,ingredients_text,product_name,generic_name,ingredients_from_or_that_may_be_from_palm_oil_n,serving_size,allergens_tags,allergens,origins,stores,nutrition_grade_fr,nutrient_levels,countries,countries_tags,brands,packaging,labels_tags,labels_hierarchy,cities_tags,quantity,ingredients_from_palm_oil_n,image_url,link,emb_codes_tags,states_tags,creator,created_t,last_modified_t,last_modified_by,editors_tags,nova_groups,lang,purchase_places,nutrition_data_per,no_nutrition_data,other_information,conservation_conditions,recycling_instructions_to_discard,recycling_instructions_to_recycle,warning,customer_service,environment_infocard")
Single<State> getFullProductByBarcodeSingle(@Path("barcode") String barcode,
@Header("User-Agent") String header);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -273,10 +274,12 @@ private void setupViewPager( ViewPager viewPager )
if( BuildConfig.FLAVOR.equals( "off" ) )
{
adapterResult.addFragment( new NutritionProductFragment(), menuTitles[2] );
if( mState.getProduct().getNutriments() != null && mState.getProduct().getNutriments().contains(Nutriments.CARBON_FOOTPRINT) )
{
adapterResult.addFragment( new EnvironmentProductFragment(), menuTitles[4] );
}
if( (mState.getProduct().getNutriments() != null &&
mState.getProduct().getNutriments().contains(Nutriments.CARBON_FOOTPRINT)) ||
(mState.getProduct().getEnvironmentInfocard() != null && !mState.getProduct().getEnvironmentInfocard().isEmpty()))
{
adapterResult.addFragment(new EnvironmentProductFragment(), "Environment");
}
subhanjansaha marked this conversation as resolved.
Show resolved Hide resolved
if( PreferenceManager.getDefaultSharedPreferences( this ).getBoolean( "photoMode", false ) )
{
adapterResult.addFragment( new ProductPhotosFragment(), newMenuTitles[0] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import openfoodfacts.github.scrachx.openfood.views.customtabs.CustomTabsHelper;
import openfoodfacts.github.scrachx.openfood.views.customtabs.WebViewFallback;
import openfoodfacts.github.scrachx.openfood.views.listeners.OnRefreshListener;
import openfoodfacts.github.scrachx.openfood.views.product.environment.EnvironmentProductFragment;
import openfoodfacts.github.scrachx.openfood.views.product.ingredients.IngredientsProductFragment;
import openfoodfacts.github.scrachx.openfood.views.product.nutrition.NutritionProductFragment;
import openfoodfacts.github.scrachx.openfood.views.product.summary.SummaryProductFragment;
Expand Down Expand Up @@ -122,6 +123,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
toolbar.setVisibility(View.GONE);
mButtonScan.setVisibility(View.GONE);

mState = (State) getArguments().getSerializable("state");

setupViewPager(viewPager);

viewPager.setNestedScrollingEnabled(true);
Expand All @@ -130,7 +133,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

api = new OpenFoodAPIClient(getActivity());

mState = (State) getArguments().getSerializable("state");
if (!Utils.isHardwareCameraInstalled(getContext())) {
mButtonScan.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -265,6 +267,12 @@ private void setupViewPager(ViewPager viewPager) {
}
if (BuildConfig.FLAVOR.equals("off")) {
adapterResult.addFragment(new NutritionProductFragment(), menuTitles[2]);
if( (mState.getProduct().getNutriments() != null &&
mState.getProduct().getNutriments().contains(Nutriments.CARBON_FOOTPRINT)) ||
(mState.getProduct().getEnvironmentInfocard() != null && !mState.getProduct().getEnvironmentInfocard().isEmpty()))
{
adapterResult.addFragment(new EnvironmentProductFragment(), "Environment");
}
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("photoMode", false)) {
adapterResult.addFragment(new ProductPhotosFragment(), "Product Photos");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package openfoodfacts.github.scrachx.openfood.views.product.environment;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -15,13 +17,18 @@
import openfoodfacts.github.scrachx.openfood.models.Nutriments;
import openfoodfacts.github.scrachx.openfood.models.Product;
import openfoodfacts.github.scrachx.openfood.models.State;
import openfoodfacts.github.scrachx.openfood.views.product.ProductFragment;

import static openfoodfacts.github.scrachx.openfood.utils.Utils.bold;

public class EnvironmentProductFragment extends BaseFragment {

@BindView(R.id.textCarbonFootprint)
TextView carbonFootprint;
@BindView(R.id.environment_info_text)
TextView environmentInfoText;

private State mState;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand All @@ -32,22 +39,36 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Intent intent = getActivity().getIntent();
refreshView((State) intent.getExtras().getSerializable("state"));
}

@Override
public void refreshView(State state) {
super.refreshView(state);
if(intent!=null && intent.getExtras()!=null && intent.getExtras().getSerializable("state")!=null)
mState = (State) intent.getExtras().getSerializable("state");
else
mState = ProductFragment.mState;

final Product product = state.getProduct();
final Product product = mState.getProduct();
Nutriments nutriments = product.getNutriments();

if(nutriments != null) {
if(nutriments != null && nutriments.contains(Nutriments.CARBON_FOOTPRINT)) {
Nutriments.Nutriment carbonFootprintNutriment = nutriments.get(Nutriments.CARBON_FOOTPRINT);
carbonFootprint.setText(bold(getString(R.string.textCarbonFootprint)));
carbonFootprint.append(carbonFootprintNutriment.getFor100g());
carbonFootprint.append(carbonFootprintNutriment.getUnit());
}

if (product.getEnvironmentInfocard() != null && !product.getEnvironmentInfocard().isEmpty()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
environmentInfoText.append(Html.fromHtml(product.getEnvironmentInfocard(), Html.FROM_HTML_MODE_COMPACT));
} else {
environmentInfoText.append(Html.fromHtml(product.getEnvironmentInfocard()));
}
}

refreshView(mState);
}

@Override
public void refreshView(State state) {
super.refreshView(state);

}

}
13 changes: 13 additions & 0 deletions app/src/main/res/layout/fragment_environment_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
android:textIsSelectable="true"
android:textSize="@dimen/font_normal" />

<TextView
android:id="@+id/environment_info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_tiny"
android:layout_marginLeft="@dimen/spacing_normal"
android:layout_marginRight="@dimen/spacing_normal"
android:layout_marginTop="@dimen/spacing_tiny"
android:background="@drawable/textview_full"
android:padding="@dimen/spacing_small"
android:textIsSelectable="true"
android:textSize="@dimen/font_normal" />

</android.support.v7.widget.CardView>

</LinearLayout>
Expand Down