Skip to content

Commit

Permalink
Fix alert allergens
Browse files Browse the repository at this point in the history
Update nutrition score images
Update dependencies
Add new apk  0.2.6
  • Loading branch information
itchix committed Oct 7, 2016
1 parent 1e25d1d commit 2b1b076
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
12 changes: 6 additions & 6 deletions app/build.gradle
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "openfoodfacts.github.scrachx.openfood"
minSdkVersion 16
targetSdkVersion 24
versionCode 23
versionName "0.2.5"
versionCode 24
versionName "0.2.6"
}

dexOptions {
Expand Down Expand Up @@ -57,11 +57,11 @@ apply plugin: 'com.neenbedankt.android-apt'

dependencies {

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:preference-v14:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:preference-v14:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:recyclerview-v7:24.2.1'

compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
Expand Down
Expand Up @@ -9,6 +9,7 @@
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -22,8 +23,11 @@
import org.apache.commons.collections.IteratorUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
Expand Down Expand Up @@ -75,29 +79,38 @@ public void onViewCreated(final View view, @Nullable Bundle savedInstanceState)
@OnClick(R.id.fab)
protected void onAddAllergens() {
final List<Allergen> all = IteratorUtils.toList(Allergen.findAll(Allergen.class));
List<String> allS = new ArrayList<>();
final LinkedHashMap<Integer,String> allS = new LinkedHashMap<>();
int index = 0;
for (Allergen a : all) {
if (Locale.getDefault().getLanguage().contains("fr")){
if(a.getIdAllergen().contains("fr:")) allS.add(a.getName().substring(a.getName().indexOf(":")+1));
if(a.getIdAllergen().contains("fr:")) allS.put(index, a.getName().substring(a.getName().indexOf(":")+1));
} else if (Locale.getDefault().getLanguage().contains("en")) {
if(a.getIdAllergen().contains("en:")) allS.add(a.getName().substring(a.getName().indexOf(":")+1));
if(a.getIdAllergen().contains("en:")) allS.put(index, a.getName().substring(a.getName().indexOf(":")+1));
}
index++;
}
if(allS.size() > 0) {
new MaterialDialog.Builder(mView.getContext())
.title(R.string.title_dialog_alert)
.items(allS)
.items(allS.values())
.itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
all.get(which).setEnable("true");
all.get(which).save();
boolean canAdd = true;
int index = -1;
String alergeneStringByPos = new ArrayList<String>(allS.values()).get(which);
for(Allergen a : mAllergens) {
if(a.getName().equals(all.get(which).getName())) canAdd = false;
}
if(canAdd) {
mAllergens.add(all.get(which));
for(Allergen a : all) {
if(a.getName().substring(a.getName().indexOf(":")+1).equalsIgnoreCase(alergeneStringByPos)) {
index = getKey(allS, alergeneStringByPos);
all.get(index).setEnable("true");
all.get(index).save();
}
}
if(canAdd && index != -1) {
mAllergens.add(all.get(index));
mAdapter.notifyItemInserted(mAllergens.size() - 1);
mRvAllergens.scrollToPosition(mAdapter.getItemCount() - 1);
}
Expand Down Expand Up @@ -152,4 +165,15 @@ public void onAllergensResponse(boolean value) {

}

public static Integer getKey(HashMap<Integer, String> map, String value) {
Integer key = null;
for(Map.Entry<Integer, String> entry : map.entrySet()) {
if((value == null && entry.getValue() == null) || (value != null && value.equals(entry.getValue()))) {
key = entry.getKey();
break;
}
}
return key;
}

}
Expand Up @@ -46,7 +46,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(final ViewHolder holder, final int position) {
final Allergen allergen = mAllergens.get(position);
TextView textView = holder.nameTextView;
textView.setText(allergen.getName());
textView.setText(allergen.getName().substring(allergen.getName().indexOf(":")+1));
Button button = holder.messageButton;
button.setText(R.string.delete_txt);
button.setOnClickListener(new View.OnClickListener() {
Expand Down
Binary file modified app/src/main/res/drawable-hdpi/nnc_a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/nnc_b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/nnc_c.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/nnc_d.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-hdpi/nnc_e.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b1b076

Please sign in to comment.