Skip to content

Commit

Permalink
- Add warning popup on alert view
Browse files Browse the repository at this point in the history
- Fix alert allergens & traces detection
- Fix strings
  • Loading branch information
itchix committed Apr 24, 2016
1 parent 2cb24e0 commit 82c77b5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 39 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package openfoodfacts.github.scrachx.openfood.fragments;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
Expand All @@ -16,13 +18,15 @@

import openfoodfacts.github.scrachx.openfood.R;
import openfoodfacts.github.scrachx.openfood.models.Allergen;
import openfoodfacts.github.scrachx.openfood.views.MainActivity;
import openfoodfacts.github.scrachx.openfood.views.adapters.AllergensAdapter;

public class AlertUserFragment extends BaseFragment {

private List<Allergen> mAllergens;
private AllergensAdapter mAdapter;
private RecyclerView mRvAllergens;
private SharedPreferences mSettings;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand All @@ -33,6 +37,19 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

mSettings = getActivity().getSharedPreferences("prefs", 0);
boolean firstRunAlert = mSettings.getBoolean("firstRunAlert", true);
if (firstRunAlert) {
MaterialDialog dialog = new MaterialDialog.Builder(getContext())
.title(R.string.alert_dialog_warning_title)
.content(R.string.warning_alert_data)
.positiveText(R.string.ok_button)
.show();
SharedPreferences.Editor editor = mSettings.edit();
editor.putBoolean("firstRunAlert", false);
editor.apply();
}

mRvAllergens = (RecyclerView) view.findViewById(R.id.alergens_recycle);

mAllergens = Allergen.find(Allergen.class, "enable = ?", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,14 @@ protected void onCreate(Bundle savedInstanceState) {

List<String> all = (List<String>) state.getProduct().getAllergensHierarchy();
List<String> traces = (List<String>) state.getProduct().getTracesTags();
all.addAll(traces);
List<String> matchAll = new ArrayList<String>();
int i = 0; boolean isMatch = false;
for(String sA : all) {
if(mAllergens.size() > 0) {
if(sA.equals(mAllergens.get(i).getIdAllergen())) {
matchAll.add(mAllergens.get(i).getName());
isMatch = true;
for (int a = 0; a < mAllergens.size(); a++) {
for(int i = 0; i < all.size(); i++) {
if (all.get(i).trim().equals(mAllergens.get(a).getIdAllergen().trim())) {
matchAll.add(mAllergens.get(a).getName());
}
}
if(traces.size() > 0) {
Log.d("trace", traces.get(i));
Log.d("all", sA);
if(sA.contains(traces.get(i))) {
matchAll.add(mAllergens.get(i).getName());
isMatch = true;
}
}
if(isMatch) i++;
isMatch = false;
}

if(matchAll.size() > 0) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@
<string name="alert_drawer">Alerte allergènes</string>
<string name="warning_allergens">Contient des allergènes</string>
<string name="title_dialog_alert">Add alert</string>
<string name="warning_alert_data">Les données peuvent être non précis, attention à vérifier par vous même!</string>
</resources>
29 changes: 16 additions & 13 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@
<string name="action_find">検索</string>
<string name="text_barcode">バーコードを入れてください :</string>

<string name="drawer_open">スライダーメニューを開きました</string>
<string name="drawer_close">スライダーメニューを閉じました</string>

<!-- Nav Drawer Main Menu Items -->
<string-array name="nav_drawer_items_main">
<item>ホーム</item>
<item>バーコードで検索</item>
<item>名前で検索</item>
<item>スキャン</item>
<item>ユーザー</item>
<item>オフライン編集</item>
</string-array>

<!-- Nav Drawer Main Menu List Item Icons -->
<array name="nav_drawer_icons_main">
<item>@drawable/ic_home</item>
Expand Down Expand Up @@ -128,8 +115,10 @@
<string name="txtBarcodeNotValid">バーコードが正しくありません</string>
<string name="try_it_scan_now">今すぐスキャンしてみてください!</string>
<string name="share">共有</string>
<string name="scan_search">Scan</string>
<string name="msg_share">Open Food Facts でこの製品を参照してください:</string>
<string name="create_account">サインアップ</string>
<string name="warning_alert_data">Data may not be accurate, be careful, please check by yourself!!</string>

<style name="DefaultButtonText">
<item name="android:layout_width">fill_parent</item>
Expand All @@ -145,4 +134,18 @@
<item name="android:shadowRadius">1</item>
</style>

<string name="alert_drawer">Alert allergens</string>
<string name="delete_txt">Delete</string>
<string name="home_drawer">Home</string>
<string name="offline_edit_drawer">Offline edit</string>
<string name="search_by_barcode_drawer">Search by barcode</string>
<string name="search_by_name_drawer">Search by name</string>
<string name="search_drawer">Search</string>
<string name="sign_in_drawer">Sign-in</string>
<string name="title_dialog_alert">Add alert</string>
<string name="txt_anonymous">Anonymous</string>
<string name="txt_product_not_found">Products not found</string>
<string name="user_drawer">User</string>
<string name="warning_allergens">Contains allergens</string>

</resources>
21 changes: 11 additions & 10 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@
<string name="warning_allergens">Contains allergens</string>
<string name="title_dialog_alert">Add alert</string>

<string name="toggle_flash">Flash</string>
<string name="flash_on">Flash [ON]</string>
<string name="flash_off">Flash [OFF]</string>
<string name="auto_focus_on">Auto Focus [ON]</string>
<string name="auto_focus_off">Auto Focus [OFF]</string>
<string name="formats">Formats</string>
<string name="choose_formats">Choose Formats</string>
<string name="select_camera">Select a Camera</string>
<string name="ok_button">OK</string>
<string name="cancel_button">Cancel</string>
<string name="toggle_flash" translatable="false">Flash</string>
<string name="flash_on" translatable="false">Flash [ON]</string>
<string name="flash_off" translatable="false">Flash [OFF]</string>
<string name="auto_focus_on" translatable="false">Auto Focus [ON]</string>
<string name="auto_focus_off" translatable="false">Auto Focus [OFF]</string>
<string name="formats" translatable="false">Formats</string>
<string name="choose_formats" translatable="false">Choose Formats</string>
<string name="select_camera" translatable="false">Select a Camera</string>
<string name="ok_button" translatable="false">OK</string>
<string name="cancel_button" translatable="false">Cancel</string>
<string name="warning_alert_data">Data may not be accurate, be careful, please check by yourself!</string>

<style name="DefaultButtonText">
<item name="android:layout_width">fill_parent</item>
Expand Down

0 comments on commit 82c77b5

Please sign in to comment.