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

adds prompt for missing info related to Eco-Score (solves issue 3624) #3644

Merged
merged 6 commits into from
Jan 16, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
/**boolean to determine if nutrient prompt should be shown*/
private var showNutrientPrompt = false

/**boolean to determine if eco score prompt should be shown*/
private var showEcoScorePrompt = false

/**boolean to determine if labels prompt should be shown*/
private var showLabelsPrompt = false

/**boolean to determine if origins prompt should be shown*/
private var showOriginsPrompt = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -252,7 +260,7 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
binding.labelsIcon.visibility = View.VISIBLE

// Checks the product states_tags to determine which prompt to be shown
refreshNutriScorePrompt()
refreshStatesTagsPrompt()
presenter.loadAllergens(null)
presenter.loadCategories()
presenter.loadLabels()
Expand Down Expand Up @@ -453,19 +461,29 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
binding.ecoscoreIcon.setImageResource(product.getEcoscoreResource())
}

private fun refreshNutriScorePrompt() {
private fun refreshStatesTagsPrompt() {
//checks the product states_tags to determine which prompt to be shown
val statesTags = product.statesTags
showCategoryPrompt = statesTags.contains("en:categories-to-be-completed") && !hasCategoryInsightQuestion
showNutrientPrompt = statesTags.contains("en:nutrition-facts-to-be-completed") && product.noNutritionData != "on"
showEcoScorePrompt = statesTags.contains("en:categories-completed") && (product.ecoscore.isNullOrEmpty() || product.ecoscore.equals("unknown", true))
showLabelsPrompt = statesTags.contains("en:labels-to-be-completed")
showOriginsPrompt = statesTags.contains("en:origins-to-be-completed")

Log.d(LOG_TAG, "Show category prompt: $showCategoryPrompt")
Log.d(LOG_TAG, "Show nutrient prompt: $showNutrientPrompt")
Log.d(LOG_TAG, "Show Eco Score prompt: $showEcoScorePrompt")
Log.d(LOG_TAG, "Show labels prompt: $showLabelsPrompt")
Log.d(LOG_TAG, "Show origins prompt: $showOriginsPrompt")

if(showEcoScorePrompt){
binding.tipBoxEcoScore.loadToolTip()
}

binding.addNutriscorePrompt.visibility = View.VISIBLE
when {
showNutrientPrompt && showCategoryPrompt -> {
// Both true
// showNutrientPrompt and showCategoryPrompt true
binding.addNutriscorePrompt.text = getString(R.string.add_nutrient_category_prompt_text)
}
showNutrientPrompt -> {
Expand All @@ -478,6 +496,23 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
}
else -> binding.addNutriscorePrompt.visibility = View.GONE
}

binding.addLabelOriginPrompt.visibility = View.VISIBLE
when {
showLabelsPrompt && showOriginsPrompt -> {
// showLabelsPrompt and showOriginsPrompt true
binding.addLabelOriginPrompt.text = getString(R.string.add_labels_origins_prompt_text)
}
showLabelsPrompt -> {
// showLabelsPrompt true
binding.addLabelOriginPrompt.text = getString(R.string.add_labels_prompt_text)
}
showOriginsPrompt -> {
// showOriginsPrompt true
binding.addLabelOriginPrompt.text = getString(R.string.add_origins_prompt_text)
}
else -> binding.addLabelOriginPrompt.visibility = View.GONE
}
}

override fun showAdditives(additives: List<AdditiveName>) {
Expand Down Expand Up @@ -550,7 +585,7 @@ class SummaryProductFragment : BaseFragment(), ISummaryProductPresenter.View {
}

if (isFlavors(OFF)) {
refreshNutriScorePrompt()
refreshStatesTagsPrompt()
refreshScoresLayout()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package openfoodfacts.github.scrachx.openfood.features.shared.views

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.util.AttributeSet
import android.view.*
import android.view.animation.Animation
import android.view.animation.Transformation
import android.widget.LinearLayout
import android.widget.Toast
import androidx.core.content.edit
import androidx.core.content.res.ResourcesCompat
import androidx.core.content.res.getStringOrThrow
Expand All @@ -19,7 +23,7 @@ class TipBox(context: Context, attrs: AttributeSet?) : LinearLayout(context, att

private val prefs: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(getContext()) }

private val binding = TipBoxBinding.inflate(LayoutInflater.from(context), this, false)
private val binding = TipBoxBinding.inflate(LayoutInflater.from(context), this, true)
VaiTon marked this conversation as resolved.
Show resolved Hide resolved
private val shouldAnimate: Boolean
private val identifier: String

Expand All @@ -40,11 +44,22 @@ class TipBox(context: Context, attrs: AttributeSet?) : LinearLayout(context, att
ResourcesCompat.getColor(resources, R.color.brand_light_blue, context.theme))
attributes.recycle()

binding.tipMessage.setTextColor(toolTipTextColor)
binding.tipMessage.text = context.getString(R.string.tip_message, message)

binding.arrow.setColorFilter(toolTipBackgroundColor)
setArrowAlignment(arrowAlignment, marginStart, marginEnd)
// if identifier != "showEcoScorePrompt" , set values to button Tip Box
// else. set value to icon tip box
if(identifier!= "showEcoScorePrompt"){
binding.tipBoxIcon.visibility= View.GONE
binding.tipMessageButton.setTextColor(toolTipTextColor)
binding.tipMessageButton.text = context.getString(R.string.tip_message, message)
binding.tipBoxContainer.setBackgroundColor(toolTipBackgroundColor)

binding.arrow.setColorFilter(toolTipBackgroundColor)
setArrowAlignment(arrowAlignment, marginStart, marginEnd)
} else{
binding.tipBoxButton.visibility = View.GONE
binding.tipMessageIcon.setTextColor(toolTipTextColor)
binding.tipMessageIcon.text = message
binding.tipBoxIcon.setBackgroundColor(toolTipBackgroundColor)
}

visibility = GONE

Expand All @@ -53,14 +68,32 @@ class TipBox(context: Context, attrs: AttributeSet?) : LinearLayout(context, att
prefs.edit { putBoolean(identifier, false) }
}

binding.tipBoxContainer.setBackgroundColor(toolTipBackgroundColor)
binding.closeBoxIcon.setOnClickListener {
hide()
prefs.edit { putBoolean(identifier, false) }
}

binding.mail.setOnClickListener {
val contactIntent = Intent(Intent.ACTION_SENDTO)
contactIntent.data = Uri.parse("mailto:contact@openfoodfacts.org")
contactIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
try {
context.startActivity(contactIntent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(getContext(), R.string.email_not_found, Toast.LENGTH_SHORT).show()
}
}


if (canDisplayImmediately) loadToolTip()
}


fun setTipMessage(message: CharSequence?) {
binding.tipMessage.text = message
if (identifier != "showEcoScorePrompt")
VaiTon marked this conversation as resolved.
Show resolved Hide resolved
binding.tipMessageButton.text = context.getString(R.string.tip_message, message)
else
binding.tipMessageIcon.text = message
}

fun setArrowAlignment(arrowAlignment: Int, marginStart: Int, marginEnd: Int) {
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/res/layout/fragment_summary_product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="@dimen/spacing_normal"
android:layout_marginTop="8dp"
android:visibility="gone"
app:drawableLeftCompat="@drawable/ic_add_box_blue_18dp"
app:drawableStartCompat="@drawable/ic_add_box_blue_18dp"
Expand All @@ -353,6 +352,34 @@
tools:text="@string/add_nutrition_facts_for_nutriscore"
tools:visibility="visible" />

<openfoodfacts.github.scrachx.openfood.features.shared.views.TipBox
android:id="@+id/tipBoxEcoScore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:identifier="showEcoScorePrompt"
app:backgroundColor="@color/md_light_green_500"
app:textColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/add_nutriscore_prompt"
app:message="@string/couldnot_compute_ecoscore_prompt_text"
app:shouldDisplayImmediately="false" />

<TextView
android:id="@+id/add_label_origin_prompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_normal"
android:visibility="gone"
android:gravity="center"
android:textSize="@dimen/font_normal"
android:padding="@dimen/padding_too_short"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tipBoxEcoScore"
tools:text="@string/add_origins_prompt_text"
tools:visibility="visible"/>

</androidx.constraintlayout.widget.ConstraintLayout>

<RelativeLayout
Expand Down
124 changes: 97 additions & 27 deletions app/src/main/res/layout/tip_box.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,112 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:id="@+id/tipBoxContainer"
<RelativeLayout
android:id="@+id/tip_box_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/brand_light_blue"
android:gravity="center"
android:background="@color/green_300"
android:orientation="horizontal"
android:padding="12dp">
android:paddingTop="@dimen/spacing_tiny"
android:paddingBottom="@dimen/spacing_tiny"
tools:visibility="visible">

<TextView
android:id="@+id/tipMessage"
android:layout_width="0dp"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_normal"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:textColor="@color/md_black_1000"
tools:text="Test test test test!" />

<TextView
android:id="@+id/gotItBtn"
style="@style/ButtonRounded"
android:layout_toRightOf="@id/close_box_icon"
android:layout_toStartOf="@id/close_box_icon"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:orientation="vertical">

<TextView
android:id="@+id/tipMessage_Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/spacing_small"
android:paddingTop="@dimen/spacing_small"
android:paddingRight="@dimen/spacing_small"
android:textColor="@android:color/white"
tools:text="@string/couldnot_compute_ecoscore_prompt_text" />

<TextView
android:id="@+id/mail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/spacing_tiny"
android:paddingStart="@dimen/spacing_small"
android:paddingLeft="@dimen/spacing_small"
android:paddingEnd="@dimen/spacing_tiny"
android:paddingRight="@dimen/spacing_tiny"
android:paddingBottom="@dimen/spacing_small"
android:text="@string/off_mail"
android:textAlignment="center"
android:textColor="@color/md_blue_A700" />

</LinearLayout>

<ImageView
android:id="@+id/close_box_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/got_it" />
</LinearLayout>
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="false"
android:contentDescription="@string/close_button"
android:padding="@dimen/spacing_normal"
app:srcCompat="@drawable/ic_clear_white_24dp" />

<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
</RelativeLayout>

<LinearLayout
android:id="@+id/tip_box_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_tip_box_down_arrow"
app:tint="@color/brand_light_blue"
tools:ignore="ContentDescription" />
android:orientation="vertical">

<LinearLayout
android:id="@+id/tipBoxContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/brand_light_blue"
android:gravity="center"
android:orientation="horizontal"
android:padding="12dp">

<TextView
android:id="@+id/tipMessage_Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_normal"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:textColor="@color/md_black_1000"
tools:text="Test test test test!" />

<TextView
android:id="@+id/gotItBtn"
style="@style/ButtonRounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/got_it" />
</LinearLayout>

<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:srcCompat="@drawable/ic_tip_box_down_arrow"
app:tint="@color/brand_light_blue"
tools:ignore="ContentDescription" />

</LinearLayout>

</LinearLayout>



</layout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@
<string name="start">GOT IT</string>
<string name="contact">Contact</string>
<string name="contact_summary">Contact the team</string>
<string name="off_mail" translatable="false">mailto:contact@openfoodfacts.org</string>
<string name="off_mail" translatable="false">mailto:<u>contact@openfoodfacts.org</u></string>
VaiTon marked this conversation as resolved.
Show resolved Hide resolved
<string name="email_not_found">No email applications found</string>

<string name="airplane_mode_active_dialog_title">Airplane mode enabled</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
<string name="start">GOT IT</string>
<string name="contact">Contact</string>
<string name="contact_summary">Contact the team</string>
<string name="off_mail" translatable="false">mailto:contact@openfoodfacts.org</string>
<string name="off_mail" translatable="false">mailto:<u>contact@openfoodfacts.org</u></string>
VaiTon marked this conversation as resolved.
Show resolved Hide resolved
<string name="email_not_found">No email applications found</string>

<string name="airplane_mode_active_dialog_title">Airplane mode enabled</string>
Expand Down Expand Up @@ -973,6 +973,10 @@
<string name="add_nutrient_prompt_text">Add nutrition facts to compute the Nutri-Score</string>
<string name="add_category_prompt_text">Add a category to compute the Nutri-Score</string>
<string name="add_nutrient_category_prompt_text">Add nutrition facts and a category to compute the Nutri-Score</string>
<string name="couldnot_compute_ecoscore_prompt_text">We could not compute an Eco-Score for this product. It might be that the category is not specific enough or that we don\'t have supporting data for this category. If you believe this is an error, you can mail us by clicking below.</string>
<string name="add_labels_origins_prompt_text">The Eco-Score takes into account environmental labels and origins of the ingredients. Please take them into photo or edit the product so that they can be taken into account</string>
<string name="add_labels_prompt_text">The Eco-Score takes into account environmental labels. Please take them into photo or edit the product so that they can be taken into account</string>
<string name="add_origins_prompt_text">The Eco-Score takes into account the origins of the ingredients. Please take them into photo (ingredient list and/or any geographic claim) or edit the product so that they can be taken into account</string>
<string name="category_game_btn">Help categorize products to compute the Nutri-Score</string>
<string name="version_string">Open Food Facts Android app</string>
<string name="version">Version</string>
Expand Down