app/src/main/java/openfoodfacts/github/scrachx/openfood/fragments/AddProductNutritionFactsFragment.java
/**
     * Pre fill the fields if the product is already present in SavedProductOffline db.
     */
Pre fill the fields if the product is already present in SavedProductOffline db.
Pre fill the fields if the product is already present in SavedProductOffline db .
private void preFillValuesFromOffline() {
        HashMap<String, String> productDetails = mOfflineSavedProduct.getProductDetailsMap();
        if (productDetails != null) {
            if (productDetails.get("image_nutrition_facts") != null) {
                imagePath = productDetails.get("image_nutrition_facts");
                final String path = "file://" + imagePath;
                imageProgress.setVisibility(View.VISIBLE);
                loadNutritionsImage(path);
            }
            if (productDetails.get(PARAM_NO_NUTRITION_DATA) != null) {
                noNutritionData.setChecked(true);
                nutritionFactsLayout.setVisibility(View.GONE);
            }
            if (productDetails.get(PARAM_NUTRITION_DATA_PER) != null) {
                String s = productDetails.get(PARAM_NUTRITION_DATA_PER);
                updateSelectedDataSize(s);
            }
            if (productDetails.get(PARAM_SERVING_SIZE) != null) {
                String servingSize = productDetails.get(PARAM_SERVING_SIZE);
                updateServingSizeFrom(servingSize);
            }
            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;
                }
                final String nutrientCompleteName = AddProductNutritionFactsData.getCompleteEntryName(view);
                String value = productDetails.get(nutrientCompleteName);
                if (value != null) {
                    view.setText(value);
                    if (view.getAttachedSpinner() != null) {
                        view.getAttachedSpinner()
                            .setSelection(getSelectedUnit(nutrientShortName, productDetails.get(nutrientCompleteName + AddProductNutritionFactsData.SUFFIX_UNIT)));
                    }
                }
            }
            for (int i = 0; i < AddProductNutritionFactsData.PARAMS_OTHER_NUTRIENTS.size(); i++) {
                String completeNutrientName = AddProductNutritionFactsData.PARAMS_OTHER_NUTRIENTS.get(i);
                if (productDetails.get(completeNutrientName) != null) {
                    int position = 0;
                    String value = productDetails.get(completeNutrientName);
                    if (productDetails.get(completeNutrientName + AddProductNutritionFactsData.SUFFIX_UNIT) != null) {
                        position = getPositionInAllUnitArray(productDetails.get(completeNutrientName + AddProductNutritionFactsData.SUFFIX_UNIT));
                    }
                    index.add(i);
                    String[] nutrients = getResources().getStringArray(R.array.nutrients_array);
                    addNutrientRow(i, nutrients[i], true, value, position);
                }
            }
        }
    }
private void preFillValuesFromOffline ( ) { HashMap < String , String > productDetails = mOfflineSavedProduct . getProductDetailsMap ( ) ; if ( productDetails != null ) { if ( productDetails . get ( "image_nutrition_facts" ) != null ) { imagePath = productDetails . get ( "image_nutrition_facts" ) ; final String path = "file://" + imagePath ; imageProgress . setVisibility ( View . VISIBLE ) ; loadNutritionsImage ( path ) ; } if ( productDetails . get ( PARAM_NO_NUTRITION_DATA ) != null ) { noNutritionData . setChecked ( true ) ; nutritionFactsLayout . setVisibility ( View . GONE ) ; } if ( productDetails . get ( PARAM_NUTRITION_DATA_PER ) != null ) { String s = productDetails . get ( PARAM_NUTRITION_DATA_PER ) ; updateSelectedDataSize ( s ) ; } if ( productDetails . get ( PARAM_SERVING_SIZE ) != null ) { String servingSize = productDetails . get ( PARAM_SERVING_SIZE ) ; updateServingSizeFrom ( servingSize ) ; } 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 ; } final String nutrientCompleteName = AddProductNutritionFactsData . getCompleteEntryName ( view ) ; String value = productDetails . get ( nutrientCompleteName ) ; if ( value != null ) { view . setText ( value ) ; if ( view . getAttachedSpinner ( ) != null ) { view . getAttachedSpinner ( ) . setSelection ( getSelectedUnit ( nutrientShortName , productDetails . get ( nutrientCompleteName + AddProductNutritionFactsData . SUFFIX_UNIT ) ) ) ; } } } for ( int i = 0 ; i < AddProductNutritionFactsData . PARAMS_OTHER_NUTRIENTS . size ( ) ; i ++ ) { String completeNutrientName = AddProductNutritionFactsData . PARAMS_OTHER_NUTRIENTS . get ( i ) ; if ( productDetails . get ( completeNutrientName ) != null ) { int position = 0 ; String value = productDetails . get ( completeNutrientName ) ; if ( productDetails . get ( completeNutrientName + AddProductNutritionFactsData . SUFFIX_UNIT ) != null ) { position = getPositionInAllUnitArray ( productDetails . get ( completeNutrientName + AddProductNutritionFactsData . SUFFIX_UNIT ) ) ; } index . add ( i ) ; String [ ] nutrients = getResources ( ) . getStringArray ( R . array . nutrients_array ) ; addNutrientRow ( i , nutrients [ i ] , true , value , position ) ; } } } }
Pre fill the fields if the product is already present in SavedProductOffline db.
Pre fill the fields if the product is already present in SavedProductOffline db .
// 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.