Skip to content

Commit

Permalink
Update: 01.04.2022 (Guthaben / Cancel onClick + Preferences)
Browse files Browse the repository at this point in the history
  • Loading branch information
derkrasseleo committed Apr 1, 2022
1 parent 263f63f commit b14a149
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
1 change: 1 addition & 0 deletions CoffeeMachine/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions CoffeeMachine/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CoffeeMachine/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.CoffeeMachine">
<activity
android:name=".MainActivity"
android:name=".gui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ public enum Coffee {
{
"Mokka", "Kleiner Brauner", "Franziskaner", "Melange", "Fiaker"
};
private final static int[] preisInCent =
{
150,180,200,180,250
};

public String getText()
{
return text[ordinal()];
}
public int getPreisInCent()
{
return preisInCent[ordinal()];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package at.htlkaindorf.android.bhmba17.coffeemachine.data;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.prefs.Preferences;

public class Credits
{
Expand All @@ -23,11 +26,17 @@ public int resetCredits()

public void save(Context context)
{

final SharedPreferences preferences =
context.getSharedPreferences("credits.prefs", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
editor.putInt("creditsInCents", creditsInCents);
editor.apply();
}

public void load(Context context)
{

final SharedPreferences preferences =
context.getSharedPreferences("credits.prefs", Context.MODE_PRIVATE);
creditsInCents = preferences.getInt("creditsInCents", 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void createRadioButtons()
for(Coffee coffee: Coffee.values())
{
final RadioButton radioButton = new RadioButton(this);
radioButton.setText(coffee.getText());
radioButton.setText(coffee.getText() + "(" + coffee.getPreisInCent() + " ¢)");
radioGroup.addView(radioButton);

if(coffee.ordinal()==0)
Expand Down Expand Up @@ -51,4 +51,17 @@ public void onCoin(View view)
credits.addCreditsInCents(coin);
updateCredits();
}
public void onCancel(View view)
{
// TODO: Geldrückgabe
credits.resetCredits();
updateCredits();
}

@Override
protected void onStop() {
credits.save(this);
super.onStop();

}
}
35 changes: 25 additions & 10 deletions CoffeeMachine/app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="5"
android:text=""
android:textSize="18sp" />

Expand All @@ -67,6 +69,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="10"
android:text="10¢"
android:textSize="18sp" />
</TableRow>
Expand All @@ -80,6 +84,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="20"
android:text="20¢"
android:textSize="18sp" />

Expand All @@ -88,6 +94,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="50"
android:text="50¢"
android:textSize="18sp" />
</TableRow>
Expand All @@ -101,6 +109,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="100"
android:text="1€"
android:textSize="18sp" />

Expand All @@ -109,6 +119,8 @@
style="@style/Widget.AppCompat.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onCoin"
android:tag="200"
android:text="2€"
android:textSize="18sp" />
</TableRow>
Expand All @@ -133,24 +145,27 @@
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/btCancel"
android:id="@+id/btCoffeeToGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginBottom="32dp"
android:text="Cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
android:layout_marginTop="24dp"
android:text="@string/coffeToGo"
app:layout_constraintEnd_toStartOf="@+id/btCoffeeToGo"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvGuthaben" />

<Button
android:id="@+id/btCoffeeToGo"
android:id="@+id/btCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:text="Coffee to go"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
android:onClick="onCancel"
android:text="@android:string/cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv0000" />

<SeekBar
android:id="@+id/zuckerSeekBar"
Expand Down
1 change: 1 addition & 0 deletions CoffeeMachine/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<string name="insertCoin" translatable="true">Muenze einwerfen</string>
<string name="sugar">Zucker</string>
<string name="credits">Guthaben</string>
<string name="coffeToGo" translatable="false">Coffee to go</string>
</resources>

0 comments on commit b14a149

Please sign in to comment.