Skip to content

Commit

Permalink
You can now remove your custom mixtures; added goaßmaß
Browse files Browse the repository at this point in the history
  • Loading branch information
dieechtenilente committed Jul 13, 2017
1 parent 6524ef4 commit 92ec483
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 28 deletions.
29 changes: 28 additions & 1 deletion app/src/main/java/de/klaushackner/breathalyzer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, l
final int pos = position;

AlertDialog.Builder builder = new AlertDialog.Builder(ma);
builder.setTitle(R.string.remove_drink_question);
builder.setTitle(R.string.dialog_drink_question);
builder.setPositiveButton(R.string.remove_drink, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
try {
Expand Down Expand Up @@ -419,6 +419,33 @@ public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
}
});

mixtureList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
final int pos = position;
final Dialog d = dialog;

AlertDialog.Builder builder = new AlertDialog.Builder(ma);
builder.setTitle(R.string.remove_custom_mixture);
builder.setPositiveButton(R.string.remove_mixture, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Mixture m = mixtureArray[pos];
Mixture.removeCustomMixture(c, m);
d.dismiss();

}
});

builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});

builder.create().show();
return true;
}
});

dialog.show();
}

Expand Down
64 changes: 43 additions & 21 deletions app/src/main/java/de/klaushackner/breathalyzer/model/Mixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,32 @@ public static boolean isValidMixture(String name, double amount, double percenta

public static Mixture[] getMixtureArray(Context c, User u) {
try {
JSONArray mixtures = new JSONArray();
JSONArray customMixtures = getCustomMixtures(c);

if (mixtures.length() < 8) {
//Add new mixtures here!
mixtures = new JSONArray("[]");
mixtures.put(new Mixture("Bier", 500, 0.05, "beer").toString());
mixtures.put(new Mixture("Bier", 1000, 0.05, "morebeer").toString());
mixtures.put(new Mixture("Pils", 330, 0.048, "pils").toString());
mixtures.put(new Mixture("Pils", 500, 0.048, "pils").toString());
mixtures.put(new Mixture("Wein", 200, 0.10, "wine").toString());
mixtures.put(new Mixture("Wodka", 20, 0.40, "vodka").toString());
mixtures.put(new Mixture("Whisky", 20, 0.40, "whisky").toString());
mixtures.put(new Mixture("Sekt", 200, 0.12, "sparklingwine").toString());

for (int i = 0; i < customMixtures.length(); i++) {
mixtures.put(customMixtures.get(i).toString());
}
//Add new mixtures here!
JSONArray mixtures = new JSONArray("[]");
mixtures.put(new Mixture("Bier", 500, 0.05, "beer").toString());
mixtures.put(new Mixture("Bier", 1000, 0.05, "morebeer").toString());
mixtures.put(new Mixture("Goaß", 270, 0.06296296296, "goass").toString());
mixtures.put(new Mixture("Goaßmaß", 540, 0.06296296296, "goass").toString());
mixtures.put(new Mixture("Pils", 330, 0.048, "pils").toString());
mixtures.put(new Mixture("Pils", 500, 0.048, "pils").toString());
mixtures.put(new Mixture("Wein", 200, 0.10, "wine").toString());
mixtures.put(new Mixture("Wodka", 20, 0.40, "vodka").toString());
mixtures.put(new Mixture("Whisky", 20, 0.40, "whisky").toString());
mixtures.put(new Mixture("Sekt", 200, 0.12, "sparklingwine").toString());

for (int i = 0; i < customMixtures.length(); i++) {
mixtures.put(customMixtures.get(i).toString());
}

if (u.getName().compareTo("Franzi") == 0) {
mixtures.put(new Mixture("Eigenes\nGetränk", 0, 0, "custom_franzi").toString());
} else {
mixtures.put(new Mixture("Eigenes\nGetränk", 0, 0, "custom").toString());
}
if (u.getName().compareTo("Franzi") == 0) {
mixtures.put(new Mixture("Eigenes\nGetränk", 0, 0, "custom_franzi").toString());
} else {
mixtures.put(new Mixture("Eigenes\nGetränk", 0, 0, "custom").toString());
}


final Mixture[] mixtureArray = new Mixture[mixtures.length()];

for (int i = 0; i < mixtures.length(); i++) {
Expand Down Expand Up @@ -157,5 +157,27 @@ public static void addCustomMixture(Context c, Mixture m) {
e.printStackTrace();
}
}


public static void removeCustomMixture(Context c, Mixture m) {
try {
SharedPreferences sharedPref = c.getSharedPreferences("data", 0);
SharedPreferences.Editor editor = sharedPref.edit();

JSONArray mixtures = new JSONArray(sharedPref.getString("customMixtures", "[]"));

for (int i = 0; i < mixtures.length(); i++) {
if (mixtures.get(i).toString().compareTo(m.toString()) == 0) {
mixtures.remove(i);
break; //break prevents removing every mixture matching to the given mixture (helpful if you add the same mixture two times and want to remove it)
}
}

editor.putString("customMixtures", mixtures.toString());
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
}

Binary file added app/src/main/res/drawable/goass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.11"
app:srcCompat="@drawable/logo" />
app:srcCompat="@mipmap/logo" />

<TextView
android:id="@+id/about_text"
Expand Down
File renamed without changes
9 changes: 4 additions & 5 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<string name="app_name">Alkomat 3000</string>
<string name="press_back_again_to_leave">Nochmal drücken, um zu Verlassen</string>
<string name="about_text">© 2017 Klaus Hackner\n\nAlkomat 3000 for Android\n\nSource: https://github.com/dieechtenilente/alcoholtestapp\n\nEmoji artwork provided by EmojiOne.\nhttp://emojione.com/</string>

<string name="wronginput">Fehler! Bitte überprüfe Deine Eingaben</string>
<string name="no_information">k. A.</string>
<string name="only_one_user_there">Es ist nur ein Benutzer vorhanden. Dieser wurde jetzt ausgewählt</string>
Expand Down Expand Up @@ -35,12 +34,12 @@
<string name="remove_current_user">Aktuellen Benutzer löschen</string>
<string name="time_left">verbl.</string>
<string name="time_ago">verstr.</string>

<string name="notification_alert">Obacht</string>
<string name="notification_text_current_bac">Du hast aktuell %1$s ‰ Alkohol in deinem Blut!</string>

<string name="remove_drink_question">Soll das Getränk wirklich entfernt werden?</string>
<string name="dialog_drink_question">Was soll mit dem Getränk geschehen?</string>
<string name="remove_drink">Getränk\nentfernen</string>
<string name="cancel">Abbruch</string>
<string name="add_as_mixture">Getränk\nspeichern</string>
<string name="add_as_mixture">Rezeptur\nspeichern</string>
<string name="remove_custom_mixture">Rezeptur entfernen?</string>
<string name="remove_mixture">Rezeptur\nentfernen</string>
</resources>

0 comments on commit 92ec483

Please sign in to comment.