Commit 56d5642a authored by jordan.dalby's avatar jordan.dalby

Added payment page

parent 53be020d
...@@ -34,6 +34,7 @@ dependencies { ...@@ -34,6 +34,7 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0' implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MuseumApp"> android:theme="@style/Theme.MuseumApp">
<activity android:name=".BookSouvenir"></activity> <activity android:name=".BookPayment"></activity>
<activity android:name=".BookSouvenir" />
<activity android:name=".BookCafe" /> <activity android:name=".BookCafe" />
<activity android:name=".BookMuseum" /> <activity android:name=".BookMuseum" />
<activity android:name=".MuseumPage" /> <activity android:name=".MuseumPage" />
......
...@@ -2,15 +2,135 @@ package com.yorksj.museumapp; ...@@ -2,15 +2,135 @@ package com.yorksj.museumapp;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import com.yorksj.museumapp.book.BookPacket;
import com.yorksj.museumapp.book.CafeItem;
import com.yorksj.museumapp.home.HomeButton;
public class BookCafe extends AppCompatActivity public class BookCafe extends AppCompatActivity
{ {
private BookPacket bookPacket;
private HomeButton homeButton;
private TextView subtotal;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_cafe); setContentView(R.layout.activity_book_cafe);
getBookPacket();
initialiseHomeButton();
initialiseMenuItems();
initialiseSubtotal();
initialiseContinueButton();
}
private void getBookPacket()
{
Intent intent = getIntent();
Bundle extras = intent.getExtras();
bookPacket = (BookPacket) extras.get("packet");
}
private void initialiseHomeButton()
{
homeButton = new HomeButton(this, BookCafe.this, BookMuseum.class);
homeButton.getIntent().putExtra("packet", bookPacket.museumPacket);
}
private void initialiseSubtotal()
{
subtotal = findViewById(R.id.subtotalAmountCafe);
updateSubtotal();
}
private void initialiseMenuItems()
{
initialiseMenuItem(CafeItem.TEA, R.id.teaAdd, R.id.teaMinus, R.id.teaQuantity);
initialiseMenuItem(CafeItem.WATER, R.id.waterAdd, R.id.waterMinus, R.id.waterQuantity);
initialiseMenuItem(CafeItem.COFFEE, R.id.coffeeAdd, R.id.coffeeMinus, R.id.coffeeQuantity);
initialiseMenuItem(CafeItem.FLATBREAD, R.id.flatbreadAdd, R.id.flatbreadMinus, R.id.flatbreadQuantity);
initialiseMenuItem(CafeItem.SANDWICH, R.id.sandwichAdd, R.id.sandwichMinus, R.id.sandwichQuantity);
initialiseMenuItem(CafeItem.SWEET_ROLL, R.id.sweetrollAdd, R.id.sweetrollMinus, R.id.sweetrollQuantity);
initialiseMenuItem(CafeItem.SALAD, R.id.saladAdd, R.id.saladMinus, R.id.saladQuantity);
}
private void initialiseMenuItem(CafeItem item, int add, int minus, int quantity)
{
ImageButton addButton = findViewById(add);
ImageButton minusButton = findViewById(minus);
TextView quantityText = findViewById(quantity);
addButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
bookPacket.cafe.addItem(item);
quantityText.setText(String.valueOf(bookPacket.cafe.getAmount(item)));
updateSubtotal();
}
});
minusButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
bookPacket.cafe.takeItem(item);
quantityText.setText(String.valueOf(bookPacket.cafe.getAmount(item)));
updateSubtotal();
}
});
}
public void updateSubtotal()
{
String s = "\t\tCafe Total \t\t\t\t£" + bookPacket.cafe.getTotal() + ".00" +
"\n+\tEntrance Fee \t\t£" + bookPacket.museumPacket.entranceFee + ".00" +
"\n=\tTotal \t\t\t\t\t\t\t\t\t£" + (bookPacket.cafe.getTotal() + bookPacket.museumPacket.entranceFee) + ".00";
subtotal.setText(s);
}
private void initialiseContinueButton()
{
Button button = findViewById(R.id.cafeContinue);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(BookCafe.this, BookSouvenir.class);
intent.putExtra("packet", bookPacket);
startActivity(intent);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (!homeButton.onClick(item))
{
super.onOptionsItemSelected(item);
return false;
}
return true;
} }
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import android.widget.ArrayAdapter; ...@@ -10,6 +10,7 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CalendarView; import android.widget.CalendarView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import com.yorksj.museumapp.book.BookPacket; import com.yorksj.museumapp.book.BookPacket;
import com.yorksj.museumapp.book.Time; import com.yorksj.museumapp.book.Time;
...@@ -43,8 +44,16 @@ public class BookMuseum extends AppCompatActivity ...@@ -43,8 +44,16 @@ public class BookMuseum extends AppCompatActivity
homeButton = new HomeButton(this, BookMuseum.this, MuseumPage.class); homeButton = new HomeButton(this, BookMuseum.this, MuseumPage.class);
homeButton.getIntent().putExtra("packet", activeMuseum); homeButton.getIntent().putExtra("packet", activeMuseum);
setName();
setUpCalendar(); setUpCalendar();
setUpDropdown(); setUpDropdown();
initialiseOnClick();
}
private void setName()
{
TextView name = findViewById(R.id.museumBookName);
name.setText(activeMuseum.name);
} }
private void setUpCalendar() private void setUpCalendar()
...@@ -87,22 +96,17 @@ public class BookMuseum extends AppCompatActivity ...@@ -87,22 +96,17 @@ public class BookMuseum extends AppCompatActivity
@Override @Override
public void onClick(View v) public void onClick(View v)
{ {
BookMuseum.this.onClick(); long date = calendarView.getDate();
} Time time = Time.NINE_TO_ELEVEN.getTimeFromString(spinnerTime.getSelectedItem().toString());
});
}
private void onClick()
{
long date = calendarView.getDate();
Time time = Time.NINE_TO_ELEVEN.getTimeFromString(spinnerTime.getSelectedItem().toString());
BookPacket packet = new BookPacket(activeMuseum, date, time); BookPacket packet = new BookPacket(activeMuseum, date, time);
Intent intent = new Intent(BookMuseum.this, BookCafe.class); Intent intent = new Intent(BookMuseum.this, BookCafe.class);
intent.putExtra("packet", packet); intent.putExtra("packet", packet);
startActivity(intent); startActivity(intent);
}
});
} }
private void getActiveMuseum() private void getActiveMuseum()
......
package com.yorksj.museumapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;
import com.yorksj.museumapp.book.BookPacket;
import com.yorksj.museumapp.book.CafeItem;
import com.yorksj.museumapp.book.SouvenirItem;
import com.yorksj.museumapp.home.HomeButton;
import java.util.ArrayList;
import java.util.List;
public class BookPayment extends AppCompatActivity
{
private BookPacket bookPacket;
private HomeButton homeButton;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_payment);
getBookPacket();
initialiseHomeButton();
setMuseumName();
updateOverview();
}
private void initialiseHomeButton()
{
homeButton = new HomeButton(this, BookPayment.this, BookMuseum.class);
homeButton.getIntent().putExtra("packet", bookPacket.museumPacket);
}
private void getBookPacket()
{
Intent intent = getIntent();
Bundle extras = intent.getExtras();
bookPacket = (BookPacket) extras.get("packet");
}
private void setMuseumName()
{
TextView name = findViewById(R.id.paymentMuseumName);
name.setText(bookPacket.museumPacket.name);
}
private void updateOverview()
{
TextView overview = findViewById(R.id.paymentOverview);
String format = "%32s%10s%16s\n";
int pad = 17;
StringBuilder stringList = new StringBuilder();
stringList.append(pad("Item", pad) + pad("Amount", pad) + pad("Total Cost", pad) + "\n");
for (CafeItem item : bookPacket.cafe.quantities.keySet())
{
int amt = bookPacket.cafe.getAmount(item);
if (amt == 0)
continue;
stringList.append(pad(item.displayName, pad) + pad(String.valueOf(amt), pad) + pad("£" + (item.cost * amt) + ".00", pad) + "\n");
}
stringList.append("\n");
for (SouvenirItem item : bookPacket.souvenir.quantities.keySet())
{
int amt = bookPacket.souvenir.getAmount(item);
if (amt == 0)
continue;
stringList.append(pad(item.displayName, pad) + pad(String.valueOf(amt), pad) + pad("£" + (item.cost * amt) + ".00", pad) + "\n");
}
stringList.append("\n\n");
stringList.append(pad("", pad) + "Entrance fee " + pad("£" + bookPacket.museumPacket.entranceFee + ".00\n", pad));
stringList.append(pad("", pad) + "Total " + pad("£" + bookPacket.getTotalCost() + ".00", pad));
overview.setText(stringList.toString());
}
private String pad(String s, int padAmount)
{
int amtToPad = padAmount - s.length();
StringBuilder builder = new StringBuilder();
builder.append(s);
for (int i = 0; i < amtToPad; i++)
{
builder.append("\t");
}
return builder.toString();
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (!homeButton.onClick(item))
{
super.onOptionsItemSelected(item);
return false;
}
return true;
}
}
\ No newline at end of file
...@@ -2,15 +2,136 @@ package com.yorksj.museumapp; ...@@ -2,15 +2,136 @@ package com.yorksj.museumapp;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import com.yorksj.museumapp.book.BookPacket;
import com.yorksj.museumapp.book.SouvenirItem;
import com.yorksj.museumapp.home.HomeButton;
public class BookSouvenir extends AppCompatActivity public class BookSouvenir extends AppCompatActivity
{ {
private BookPacket bookPacket;
private HomeButton homeButton;
private TextView subtotal;
@Override @Override
protected void onCreate(Bundle savedInstanceState) protected void onCreate(Bundle savedInstanceState)
{ {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book_souvenir); setContentView(R.layout.activity_book_souvenir);
getBookPacket();
initialiseHomeButton();
initialiseMenuItems();
initialiseSubtotal();
initialiseContinueButton();
}
private void initialiseHomeButton()
{
homeButton = new HomeButton(this, BookSouvenir.this, BookMuseum.class);
homeButton.getIntent().putExtra("packet", bookPacket.museumPacket);
}
private void initialiseSubtotal()
{
subtotal = findViewById(R.id.subtotalAmountSouvenir);
updateSubtotal();
}
private void getBookPacket()
{
Intent intent = getIntent();
Bundle extras = intent.getExtras();
bookPacket = (BookPacket) extras.get("packet");
}
private void initialiseMenuItems()
{
initialiseMenuItem(SouvenirItem.SHIRT, R.id.shirtAdd, R.id.shirtMinus, R.id.shirtQuantity);
initialiseMenuItem(SouvenirItem.HAT, R.id.hatAdd, R.id.hatMinus, R.id.hatQuantity);
initialiseMenuItem(SouvenirItem.SNOW_GLOBE, R.id.snowglobeAdd, R.id.snowglobeMinus, R.id.snowglobeQuantity);
initialiseMenuItem(SouvenirItem.KEY_CHAIN, R.id.keychainAdd, R.id.keychainMinus, R.id.keychainQuantity);
initialiseMenuItem(SouvenirItem.BOTTLE, R.id.bottleAdd, R.id.bottleMinus, R.id.bottleQuantity);
initialiseMenuItem(SouvenirItem.MUG, R.id.mugAdd, R.id.mugMinus, R.id.mugQuantity);
initialiseMenuItem(SouvenirItem.COASTER, R.id.coasterAdd, R.id.coasterMinus, R.id.coasterQuantity);
}
private void initialiseMenuItem(SouvenirItem item, int add, int minus, int quantity)
{
ImageButton addButton = findViewById(add);
ImageButton minusButton = findViewById(minus);
TextView quantityText = findViewById(quantity);
addButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
bookPacket.souvenir.addItem(item);
quantityText.setText(String.valueOf(bookPacket.souvenir.getAmount(item)));
updateSubtotal();
}
});
minusButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
bookPacket.souvenir.takeItem(item);
quantityText.setText(String.valueOf(bookPacket.souvenir.getAmount(item)));
updateSubtotal();
}
});
}
public void updateSubtotal()
{
String s = "\t\tCafe Total \t\t\t\t£" + bookPacket.cafe.getTotal() + ".00" +
"\n+\tSouvenir Total \t£" + bookPacket.souvenir.getTotal() + ".00" +
"\n+\tEntrance Fee \t\t£" + bookPacket.museumPacket.entranceFee + ".00" +
"\n=\tTotal \t\t\t\t\t\t\t\t\t£" + (bookPacket.souvenir.getTotal() + bookPacket.museumPacket.entranceFee) + ".00";
subtotal.setText(s);
}
private void initialiseContinueButton()
{
Button button = findViewById(R.id.souvenirContinue);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(BookSouvenir.this, BookPayment.class);
intent.putExtra("packet", bookPacket);
startActivity(intent);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if (!homeButton.onClick(item))
{
super.onOptionsItemSelected(item);
return false;
}
return true;
} }
} }
\ No newline at end of file
...@@ -12,11 +12,22 @@ public class BookPacket implements Serializable ...@@ -12,11 +12,22 @@ public class BookPacket implements Serializable
public long date; public long date;
public Time time; public Time time;
public CafePacket cafe;
public SouvenirPacket souvenir;
public BookPacket(MuseumPacket _museumPacket, long _date, Time _time) public BookPacket(MuseumPacket _museumPacket, long _date, Time _time)
{ {
museumPacket = _museumPacket; museumPacket = _museumPacket;
date = _date; date = _date;
time = _time; time = _time;
resetPurchases();
}
public void resetPurchases()
{
cafe = new CafePacket(CafeItem.values());
souvenir = new SouvenirPacket(SouvenirItem.values());
} }
public String getDateFormatted() public String getDateFormatted()
...@@ -25,4 +36,9 @@ public class BookPacket implements Serializable ...@@ -25,4 +36,9 @@ public class BookPacket implements Serializable
return format.format(date); return format.format(date);
} }
public int getTotalCost()
{
return museumPacket.entranceFee + cafe.getTotal() + souvenir.getTotal();
}
} }
package com.yorksj.museumapp.book;
import java.io.Serializable;
public enum CafeItem implements Serializable
{
TEA("Tea", 1),
WATER("Water", 1),
COFFEE("Coffee", 2),
FLATBREAD("Flatbread", 2),
SANDWICH("Sandwich", 2),
SWEET_ROLL("Sweet Roll", 2),
SALAD("Salad", 2);
public String displayName;
public int cost;
CafeItem(String _displayName, int _cost)
{
displayName = _displayName;
cost = _cost;
}
}
package com.yorksj.museumapp.book;
import java.io.Serializable;
public class CafePacket extends Shopping<CafeItem> implements Serializable
{
public CafePacket(CafeItem[] values)
{
super(values, 100);
}
public int getTotal()
{
int total = 0;
for (CafeItem item : super.quantities.keySet())
{
total += item.cost * super.quantities.get(item);
}
return total;
}
}
package com.yorksj.museumapp.book;
import java.io.Serializable;
import java.util.HashMap;
public abstract class Shopping<T> implements Serializable
{
public HashMap<T, Integer> quantities = new HashMap<>();
private int maxStack;
public Shopping(T[] values, int _maxStack)
{
for (T val : values)
{
quantities.put(val, 0); // initialise HashMap
}
maxStack = _maxStack;
}
public boolean addItem(T item)
{
if (!contains(item))
return false;
if (quantities.get(item) >= maxStack)
return false;
quantities.put(item, quantities.get(item) + 1); // increase the amount in the HashMap by 1
return true;
}
public boolean takeItem(T item)
{
if (!contains(item))
return false;
int i = quantities.get(item);
if (i <= 0)
return false;
quantities.put(item, quantities.get(item) - 1);
return true;
}
public int getAmount(T item)
{
if (!contains(item))
return 0;
return quantities.get(item);
}
public boolean contains(T item)
{
return quantities.containsKey(item);
}
}
package com.yorksj.museumapp.book;
import java.io.Serializable;
public enum SouvenirItem implements Serializable
{
SHIRT("Shirt", 10),
HAT("Hat", 5),
SNOW_GLOBE("Snow Globe", 5),
KEY_CHAIN("Key Chain", 5),
BOTTLE("Bottle", 5),
MUG("Mug", 5),
COASTER("Coaster", 2);
public String displayName;
public int cost;
SouvenirItem(String _displayName, int _cost)
{
displayName = _displayName;
cost = _cost;
}
}
package com.yorksj.museumapp.book;
import java.io.Serializable;
public class SouvenirPacket extends Shopping<SouvenirItem> implements Serializable
{
public SouvenirPacket(SouvenirItem[] values)
{
super(values, 100);
}
public int getTotal()
{
int total = 0;
for (SouvenirItem item : super.quantities.keySet())
{
total += item.cost * super.quantities.get(item);
}
return total;
}
}
package com.yorksj.museumapp.book; package com.yorksj.museumapp.book;
public enum Time import java.io.Serializable;
public enum Time implements Serializable
{ {
NINE_TO_ELEVEN("9am-11am"), NINE_TO_ELEVEN("9am-11am"),
ELEVEN_TO_ONE("11am-1pm"), ELEVEN_TO_ONE("11am-1pm"),
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
tools:context=".BookMuseum"> tools:context=".BookMuseum">
<TextView <TextView
android:id="@+id/textView" android:id="@+id/museumBookName"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_marginStart="4dp" android:layout_marginStart="4dp"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
android:text="Select a date and time" android:text="Select a date and time"
android:textAlignment="center" android:textAlignment="center"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" /> app:layout_constraintTop_toBottomOf="@+id/museumBookName" />
<CalendarView <CalendarView
android:id="@+id/dateSelect" android:id="@+id/dateSelect"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BookPayment">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="Confirm Purchase"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ScrollView
android:id="@+id/paymentScrollView"
android:layout_width="414dp"
android:layout_height="573dp"
android:layout_marginTop="80dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="@+id/paymentLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/paymentOverview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:text="test\ntest\ngood"
android:textAlignment="textStart" />
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/paymentMuseumName"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:layout_marginTop="16dp"
android:text="MuseumName"
android:textAlignment="center"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/paymentMuseumName2"
android:layout_width="fill_parent"
android:layout_height="26dp"
android:text="Please review your purchase overview"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/paymentMuseumName" />
<TextView
android:id="@+id/totalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="28dp"
android:layout_marginBottom="32dp"
android:text="Total"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/totalPaymentAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="68dp"
android:layout_marginBottom="32dp"
android:text="££££££"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment