Skip to content

Commit

Permalink
Only show the "not adjusted" message if the ingredient line contains …
Browse files Browse the repository at this point in the history
…any numbers at all #255
  • Loading branch information
flauschtrud committed Dec 13, 2024
1 parent 76ccb86 commit 50e19a2
Show file tree
Hide file tree
Showing 21 changed files with 16 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.app.Application;

import com.flauschcode.broccoli.recipe.ingredients.ScaledQuantityBuilder;

import javax.inject.Singleton;

import dagger.Module;
Expand All @@ -17,4 +19,10 @@ Compressor compressor(Application application) {
return new Compressor(application);
}

@Provides
@Singleton
ScaledQuantityBuilder scaledQuantityBuilder() {
return new ScaledQuantityBuilder();
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
package com.flauschcode.broccoli.recipe.ingredients;

import android.app.Application;

import com.flauschcode.broccoli.R;

import java.text.DecimalFormat;
import java.text.Normalizer;

import javax.inject.Inject;
import javax.inject.Singleton;

@Singleton
public class ScaledQuantityBuilder {

private final Application application;

@Inject
public ScaledQuantityBuilder(Application application) {
this.application = application;
}

private static final DecimalFormat decimalFormat = new DecimalFormat("0.##");

public String from(String quantity, float scaleFactor) {
Expand All @@ -40,7 +25,7 @@ public String from(String quantity, float scaleFactor) {

return scale(quantity, scaleFactor);
} catch (NumberFormatException e) {
return "(" + getNotScaledString() + ") " + quantity;
return quantity;
}
}

Expand Down Expand Up @@ -108,8 +93,4 @@ private String prettyPrint(float f) {
return f == i ? String.valueOf(i) : decimalFormat.format(f);
}

private String getNotScaledString() {
return application.getString(R.string.unscaled);
}

}
1 change: 0 additions & 1 deletion app/src/main/res/values-b+sr+Latn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Za</string>
<string name="recipe_amount">Količina u receptu</string>
<string name="scaling_factor">Koeficijent skaliranja</string>
<string name="unscaled">nije prilagođeno</string>
<string name="share_action">Podeli</string>
<string name="shared_with">Podeli sa %1$s</string>
<string name="recipe_could_not_be_imported_message">Žao nam je, ovo nije uspelo.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
<string name="no_ingredients_and_directions_message">Dieses Rezept hat noch keine Zutaten oder Anleitung.</string>
<string name="cook_action">Kochen</string>
<string name="adjust_ingredients">Zutaten anpassen</string>
<string name="unscaled">nicht angepasst</string>
<string name="share_action">Teilen</string>
<string name="shared_with">Geteilt mit %1$s</string>
<string name="recipe_could_not_be_imported_message">Das hat leider nicht funktioniert.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Recipe amount</string>
<string name="scaling_factor">Scaling factor</string>
<string name="unscaled">not adjusted</string>
<string name="share_action">Share</string>
<string name="shared_with">Shared with %1$s</string>
<string name="recipe_could_not_be_imported_message">Sorry, this did not work.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Cantidad de la receta</string>
<string name="scaling_factor">Factor de escala</string>
<string name="unscaled">no ajustado</string>
<string name="share_action">Compartir</string>
<string name="shared_with">Compartido con %1$s</string>
<string name="recipe_could_not_be_imported_message">Lo sentimos, esto no ha funcionado.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Quantité de la recette</string>
<string name="scaling_factor">Facteur d\'échelle</string>
<string name="unscaled">non ajusté</string>
<string name="share_action">Partager</string>
<string name="shared_with">Partagé avec %1$s</string>
<string name="recipe_could_not_be_imported_message">Désolé, cela n\'a pas fonctionné.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Recipe amount</string>
<string name="scaling_factor">Scaling factor</string>
<string name="unscaled">not adjusted</string>
<string name="share_action">Share</string>
<string name="shared_with">Shared with %1$s</string>
<string name="recipe_could_not_be_imported_message">Sorry, this did not work.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Avanzato</string>
<string name="recipe_amount">Quantità ricetta</string>
<string name="scaling_factor">Fattore di scala</string>
<string name="unscaled">non personalizzato</string>
<string name="share_action">Condividi</string>
<string name="shared_with">Condividi con %1$s</string>
<string name="recipe_could_not_be_imported_message">Siamo spiacenti, si è verificato un errore.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">פרו</string>
<string name="recipe_amount">כמות במתכון</string>
<string name="scaling_factor">מכפיל מידות</string>
<string name="unscaled">לא מותאם</string>
<string name="share_action">שתף</string>
<string name="shared_with">‏שתף באמצעות %1$s</string>
<string name="recipe_could_not_be_imported_message">מצטער, הפעולה לא הצליחה</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">プロ</string>
<string name="recipe_amount">レシピの量</string>
<string name="scaling_factor">倍率</string>
<string name="unscaled">調整していない</string>
<string name="share_action">共有</string>
<string name="shared_with">%1$sと共有</string>
<string name="recipe_could_not_be_imported_message">もし訳ありませんが、動作はが失敗しました。</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Oppskriftens mengde</string>
<string name="scaling_factor">Skaleringsfaktor</string>
<string name="unscaled">ikke justert</string>
<string name="share_action">Del</string>
<string name="shared_with">Delt med %1$s</string>
<string name="recipe_could_not_be_imported_message">Beklager, dette fungerte ikke.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Geavanceerd</string>
<string name="recipe_amount">Recipe amount</string>
<string name="scaling_factor">Schalingsfactor</string>
<string name="unscaled">ongewijzigd</string>
<string name="share_action">Delen</string>
<string name="shared_with">Gedeeld met %1$s</string>
<string name="recipe_could_not_be_imported_message">Sorry, dit is niet gelukt.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Recipe amount</string>
<string name="scaling_factor">Współczynnik skalowania</string>
<string name="unscaled">niedostosowane</string>
<string name="share_action">Udostępnij</string>
<string name="shared_with">Udostępniono przez %1$s</string>
<string name="recipe_could_not_be_imported_message">Przepraszamy, ale to nie zadziałało.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Profissional</string>
<string name="recipe_amount">Quantidade da receita</string>
<string name="scaling_factor">Proporção</string>
<string name="unscaled">não ajustado</string>
<string name="share_action">Compartilhar</string>
<string name="shared_with">Compartilhado com %1$s</string>
<string name="recipe_could_not_be_imported_message">Desculpe, isso não funcionou.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Сложный</string>
<string name="recipe_amount">Количество рецептов</string>
<string name="scaling_factor">Коэффициент масштабирования</string>
<string name="unscaled">не отрегулировано</string>
<string name="share_action">Поделиться</string>
<string name="shared_with">Поделились с помощью %1$s</string>
<string name="recipe_could_not_be_imported_message">К сожалению, это не работает.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Receptmängd</string>
<string name="scaling_factor">Skalningsfaktor</string>
<string name="unscaled">ej justerad</string>
<string name="share_action">Share</string>
<string name="shared_with">Shared with %1$s</string>
<string name="recipe_could_not_be_imported_message">Tyvärr fungerade inte detta.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">Profesyonel</string>
<string name="recipe_amount">Tarif miktarı</string>
<string name="scaling_factor">Ölçekleme faktörü</string>
<string name="unscaled">ölçeklenmemiş</string>
<string name="share_action">Paylaş</string>
<string name="shared_with">%1$s ile paylaşıldı</string>
<string name="recipe_could_not_be_imported_message">Üzgünüz, bu işlem başarısız oldu.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<string name="scaling_pro">高级</string>
<string name="recipe_amount">食谱分量</string>
<string name="scaling_factor">比例倍数</string>
<string name="unscaled">未调整</string>
<string name="share_action">分享</string>
<string name="shared_with">已与 %1$s 分享</string>
<string name="recipe_could_not_be_imported_message">抱歉,此操作不可用。</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<string name="scaling_pro">Pro</string>
<string name="recipe_amount">Recipe amount</string>
<string name="scaling_factor">Scaling factor</string>
<string name="unscaled">not adjusted</string>

<string name="share_action">Share</string>
<string name="shared_with">Shared with %1$s</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
package com.flauschcode.broccoli.recipe.ingredients;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

import android.app.Application;

import com.flauschcode.broccoli.R;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class ScaledQuantityBuilderTest {

@Mock
private Application application;

@InjectMocks
private ScaledQuantityBuilder scaledQuantityBuilder;
private final ScaledQuantityBuilder scaledQuantityBuilder = new ScaledQuantityBuilder();

@Test
public void scale_integer_quantity() {
Expand Down Expand Up @@ -61,23 +50,20 @@ public void scale_fraction_range_quantity() {

@Test
public void scale_non_scalable_quantity() {
when(application.getString(R.string.unscaled)).thenReturn("not scaled");
String scaled = scaledQuantityBuilder.from("je 1", 2f);
assertThat(scaled, is("(not scaled) je 1"));
assertThat(scaled, is("je 1"));
}

@Test
public void scale_missing_quantity() {
when(application.getString(R.string.unscaled)).thenReturn("not scaled");
String scaled = scaledQuantityBuilder.from("", 2f);
assertThat(scaled, is("(not scaled) "));
assertThat(scaled, is(""));
}

@Test
public void scale_incomplete_range() {
when(application.getString(R.string.unscaled)).thenReturn("not scaled");
String scaled = scaledQuantityBuilder.from("1-", 2f);
assertThat(scaled, is("(not scaled) 1-"));
assertThat(scaled, is("1-"));
}

}

0 comments on commit 50e19a2

Please sign in to comment.