app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/AddProductNutritionFactsFragment.java
/**
     * Pre fill the fields of the product which are already present on the server.
     */
Pre fill the fields of the product which are already present on the server.
Pre fill the fields of the product which are already present on the server .
private void preFillProductValues() {
        if (product.getImageNutritionUrl() != null && !product.getImageNutritionUrl().isEmpty()) {
            imageProgress.setVisibility(View.VISIBLE);
            imagePath = product.getImageNutritionUrl();
            loadNutritionsImage(imagePath);
        }
        if (product.getNoNutritionData() != null && product.getNoNutritionData().equalsIgnoreCase("on")) {
            noNutritionData.setChecked(true);
            nutritionFactsLayout.setVisibility(View.GONE);
        }
        if (product.getNutritionDataPer() != null && !product.getNutritionDataPer().isEmpty()) {
            updateSelectedDataSize(product.getNutritionDataPer());
        }
        if (product.getServingSize() != null && !product.getServingSize().isEmpty()) {
            String servingSize = product.getServingSize();
            updateServingSizeFrom(servingSize);
        }
        Nutriments nutriments = product.getNutriments();
        if (nutriments != null) {
            final ArrayList<CustomValidatingEditTextView> editViews = Utils.getViewsByType((ViewGroup) getView(), CustomValidatingEditTextView.class);
            for (CustomValidatingEditTextView view : editViews) {
                final String nutrientShortName = view.getEntryName();
                if (nutrientShortName.equals(serving_size.getEntryName())) {
                    continue;
                }
                String value = getValueFromShortName(nutriments, nutrientShortName);
                if (value != null) {
                    view.setText(value);
                    if (view.getAttachedSpinner() != null) {
                        view.getAttachedSpinner().setSelection(getSelectedUnitFromShortName(nutriments, nutrientShortName));
                    }
                }
            }
            for (int i = 0; i < AddProductNutritionFactsData.PARAMS_OTHER_NUTRIENTS.size(); i++) {
                String nutrientShortName = AddProductNutritionFactsData.getShortName(AddProductNutritionFactsData.PARAMS_OTHER_NUTRIENTS.get(i));
                if (nutriments.getValue(nutrientShortName) != null) {
                    String value = getValueFromShortName(nutriments, nutrientShortName);
                    int unitSelectedIndex = getSelectedUnitFromShortName(nutriments, nutrientShortName);
                    index.add(i);
                    String[] nutrients = getResources().getStringArray(R.array.nutrients_array);
                    addNutrientRow(i, nutrients[i], true, value, unitSelectedIndex);
                }
            }
        }
    }
private void preFillProductValues ( ) { if ( product . getImageNutritionUrl ( ) != null && ! product . getImageNutritionUrl ( ) . isEmpty ( ) ) { imageProgress . setVisibility ( View . VISIBLE ) ; imagePath = product . getImageNutritionUrl ( ) ; loadNutritionsImage ( imagePath ) ; } if ( product . getNoNutritionData ( ) != null && product . getNoNutritionData ( ) . equalsIgnoreCase ( "on" ) ) { noNutritionData . setChecked ( true ) ; nutritionFactsLayout . setVisibility ( View . GONE ) ; } if ( product . getNutritionDataPer ( ) != null && ! product . getNutritionDataPer ( ) . isEmpty ( ) ) { updateSelectedDataSize ( product . getNutritionDataPer ( ) ) ; } if ( product . getServingSize ( ) != null && ! product . getServingSize ( ) . isEmpty ( ) ) { String servingSize = product . getServingSize ( ) ; updateServingSizeFrom ( servingSize ) ; } Nutriments nutriments = product . getNutriments ( ) ; if ( nutriments != null ) { final ArrayList < CustomValidatingEditTextView > editViews = Utils . getViewsByType ( ( ViewGroup ) getView ( ) , CustomValidatingEditTextView . class ) ; for ( CustomValidatingEditTextView view : editViews ) { final String nutrientShortName = view . getEntryName ( ) ; if ( nutrientShortName . equals ( serving_size . getEntryName ( ) ) ) { continue ; } String value = getValueFromShortName ( nutriments , nutrientShortName ) ; if ( value != null ) { view . setText ( value ) ; if ( view . getAttachedSpinner ( ) != null ) { view . getAttachedSpinner ( ) . setSelection ( getSelectedUnitFromShortName ( nutriments , nutrientShortName ) ) ; } } } for ( int i = 0 ; i < AddProductNutritionFactsData . PARAMS_OTHER_NUTRIENTS . size ( ) ; i ++ ) { String nutrientShortName = AddProductNutritionFactsData . getShortName ( AddProductNutritionFactsData . PARAMS_OTHER_NUTRIENTS . get ( i ) ) ; if ( nutriments . getValue ( nutrientShortName ) != null ) { String value = getValueFromShortName ( nutriments , nutrientShortName ) ; int unitSelectedIndex = getSelectedUnitFromShortName ( nutriments , nutrientShortName ) ; index . add ( i ) ; String [ ] nutrients = getResources ( ) . getStringArray ( R . array . nutrients_array ) ; addNutrientRow ( i , nutrients [ i ] , true , value , unitSelectedIndex ) ; } } } }
Pre fill the fields of the product which are already present on the server.
Pre fill the fields of the product which are already present on the server .
// Splits the serving size into value and unit. Example: "15g" into "15" and "g" //set the values of all the other nutrients if defined and create new row in the tableLayout.