Commit 5681a163 authored by a-j.towse's avatar a-j.towse

semi working cancel booking

parent ab08d7f6
......@@ -40,6 +40,14 @@
android:name=".performanceInfoPage"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".myBookingsActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
......
package com.example.no1theatrecompany;
import android.content.Context;
import android.content.Intent;
import android.telecom.Call;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.no1theatrecompany.IdleViewHolder;
import java.util.List;
public class BookingsPageAdapter extends RecyclerView.Adapter<IdleViewHolder2> {
private List<IdleData2> mData;
private LayoutInflater mInflater;
Context context;
BookingsPageAdapter(Context context, List<IdleData2> data) {
this.mInflater = LayoutInflater.from(context);
this.mData = data;
}
@Override
public IdleViewHolder2 onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.booking_item, parent, false);
return new IdleViewHolder2(view);
}
@Override
public void onBindViewHolder(@NonNull IdleViewHolder2 holder, int position) {
IdleData2 data = mData.get(position);
holder.setData(data);
holder.cancelBookingBtnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DBConnector connector = new DBConnector(context, null);
System.out.println(mData.get(position).name);
connector.cancelBooking(mData.get(position).name);
}
});
}
@Override
public int getItemCount() {
return mData.size();
}
}
\ No newline at end of file
......@@ -43,6 +43,12 @@ public class DBConnector extends SQLiteOpenHelper {
private static final String COLUMN_TIXRIVERBANK = "tixRiverBank";
private static final String COLUMN_TIXINCIRC = "tixInCirc";
private static final String COLUMN_TIXOUTCIRC = "tixOutCirc";
//DB columns for TABLE_USERS
private static final String TABLE_BOOKINGS = "bookings";
private static final String COLUMN_BOOKINGID = "bookingID";
private static final String COLUMN_PERFORMANCENAME = "performanceName";
private static final String COLUMN_TICKETINFO = "ticketInfo1";
//Constructor method - create DB
public DBConnector(Context context, SQLiteDatabase.CursorFactory factory) {
......@@ -85,6 +91,15 @@ public class DBConnector extends SQLiteOpenHelper {
//Execute query
db.execSQL(CREATE_table2);
//Build query that creates table
String CREATE_table3 = "CREATE TABLE "+TABLE_BOOKINGS +"("+
COLUMN_BOOKINGID+" INTEGER PRIMARY KEY, " +
COLUMN_PERFORMANCENAME + " TEXT, " +
COLUMN_TICKETINFO + " TEXT)" ;
//Execute query
db.execSQL(CREATE_table3);
ContentValues play1 = new ContentValues(); //Create new row object
play1.put(COLUMN_NAME, "The Merchant of Venice by William Shakespeare");
play1.put(COLUMN_DATE, "Sunday April 23 2023");
......@@ -258,7 +273,108 @@ public class DBConnector extends SQLiteOpenHelper {
return performanceInfoList;
}
public void updateDBTickets (ArrayList currentPerformance) {
ContentValues newValue = new ContentValues();
ContentValues newValue1 = new ContentValues();
ContentValues newValue2 = new ContentValues();
ContentValues newValue3 = new ContentValues();
ContentValues newValue4 = new ContentValues();
ContentValues newValue5 = new ContentValues();
ContentValues newValue6 = new ContentValues();
ContentValues newValue7 = new ContentValues();
ContentValues newValue8 = new ContentValues();
newValue.put(COLUMN_TIXSEAT, (String) currentPerformance.get(7));
newValue1.put(COLUMN_TIXSTAND, (String) currentPerformance.get(8));
newValue2.put(COLUMN_TIXSTAGE, (String) currentPerformance.get(9));
newValue3.put(COLUMN_TIXGRASS, (String) currentPerformance.get(10));
newValue4.put(COLUMN_TIXBOATA, (String) currentPerformance.get(11));
newValue5.put(COLUMN_TIXBOATB, (String) currentPerformance.get(12));
newValue6.put(COLUMN_TIXRIVERBANK, (String) currentPerformance.get(13));
newValue7.put(COLUMN_TIXINCIRC, (String) currentPerformance.get(14));
newValue8.put(COLUMN_TIXOUTCIRC, (String) currentPerformance.get(15));
String whereState = COLUMN_NAME + " = " + "\"" + currentPerformance.get(0) + "\"";
SQLiteDatabase db = this.getWritableDatabase();
db.update(TABLE_PERFORMANCES,newValue,whereState,null);
db.update(TABLE_PERFORMANCES,newValue1,whereState,null);
db.update(TABLE_PERFORMANCES,newValue2,whereState,null);
db.update(TABLE_PERFORMANCES,newValue3,whereState,null);
db.update(TABLE_PERFORMANCES,newValue4,whereState,null);
db.update(TABLE_PERFORMANCES,newValue5,whereState,null);
db.update(TABLE_PERFORMANCES,newValue6,whereState,null);
db.update(TABLE_PERFORMANCES,newValue7,whereState,null);
db.update(TABLE_PERFORMANCES,newValue8,whereState,null);
db.close();
}
public ArrayList getBookingInfo() {
ArrayList<ArrayList<String>> bookingInfoList = new ArrayList<>();
//Create query to select user from table
String query = "SELECT * FROM " + TABLE_BOOKINGS;
//Establish DB connection
SQLiteDatabase db = this.getWritableDatabase();
//Execute query
Cursor cursor = db.rawQuery(query, null);
String info;
cursor.moveToFirst();
for(int i=0;i< cursor.getCount();i++){
ArrayList<String> tempList = new ArrayList<>();
for (int column=0;column< cursor.getColumnCount();column++) {
info = cursor.getString(column);
tempList.add(info);
}
bookingInfoList.add(tempList);
cursor.moveToNext();
}
//Close DB
cursor.close();
db.close();
return bookingInfoList;
}
public void addBooking (String bookingID, String name, ArrayList tickInfo) {
ContentValues newValues = new ContentValues();
newValues.put(COLUMN_BOOKINGID, bookingID);
newValues.put(COLUMN_PERFORMANCENAME, name);
newValues.put(COLUMN_TICKETINFO, tickInfo.toString());
//Establish DB connection
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_BOOKINGS, null, newValues); //Store booking details
db.close();
}
public void cancelBooking (String playName) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_BOOKINGS, COLUMN_PERFORMANCENAME + "=" + playName, null);
db.close();
}
//Upgrade DB (to satisfy extends f SQLiteOpenHelper)
@Override
......
package com.example.no1theatrecompany;
public class IdleData2 {
String name;
String ticketInfo;
String bookingID;
IdleData2(String name,String ticketInfo,String bookingID)
{
this.name = name;
this.bookingID = bookingID;
this.ticketInfo = ticketInfo;
}
}
......@@ -13,7 +13,7 @@ public class IdleViewHolder extends RecyclerView.ViewHolder
IdleViewHolder(View v) {
super(v);
nameText = itemView.findViewById(R.id.performanceName);
nameText = itemView.findViewById(R.id.performanceBookName);
dateText =itemView.findViewById(R.id.performanceDate);
ticketsLeftText=itemView.findViewById(R.id.ticketsLeft);
}
......
package com.example.no1theatrecompany;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
public class IdleViewHolder2 extends RecyclerView.ViewHolder
{
TextView nameText;
TextView ticketInfoText;
TextView bookingIDText;
Button cancelBookingBtnButton;
IdleViewHolder2(View v) {
super(v);
nameText = itemView.findViewById(R.id.performanceBookName);
ticketInfoText=itemView.findViewById(R.id.ticketsBooked);
bookingIDText=itemView.findViewById(R.id.bookingReference);
cancelBookingBtnButton=itemView.findViewById(R.id.cancelBookingBtn);
}
void setData(IdleData2 data)
{
System.out.println(data.ticketInfo);
nameText.setText(data.name);
ticketInfoText.setText(data.ticketInfo);
bookingIDText.setText(data.bookingID);
}
}
\ No newline at end of file
......@@ -25,11 +25,11 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main);
//Get bundle from login page
Bundle loginBundle = getIntent().getExtras();
String currentUser = loginBundle.getString("currentUser");
//Bundle loginBundle = getIntent().getExtras();
//String currentUser = loginBundle.getString("currentUser");
TextView usernameTextView = (TextView) findViewById(R.id.usernameTextView);
usernameTextView.setText(currentUser);
//TextView usernameTextView = (TextView) findViewById(R.id.usernameTextView);
//usernameTextView.setText(currentUser);
performanceList = new ArrayList<>();
......@@ -74,6 +74,10 @@ public class MainActivity extends AppCompatActivity {
filterPerformances();
}
public void myBookingsBtn(View view) {
startActivity(new Intent(this,myBookingsActivity.class));
}
public void filterPerformances () {
boolean flashIsChecked = ((CheckBox) findViewById(R.id.flashCheckBox)).isChecked();
boolean stepsIsChecked = ((CheckBox) findViewById(R.id.stepsCheckBox)).isChecked();
......
package com.example.no1theatrecompany;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
public class myBookingsActivity extends AppCompatActivity {
BookingsPageAdapter adapter;
ArrayList<IdleData2> bookingList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mybookings_page);
bookingList = new ArrayList<>();
RecyclerView recyclerObj = findViewById(R.id.bookingsRecycler);
recyclerObj.setLayoutManager(new LinearLayoutManager(this));
adapter = new BookingsPageAdapter(this, bookingList);
recyclerObj.setAdapter(adapter);
//Connect to DB
DBConnector connector = new DBConnector(this, null);
ArrayList bookingInfoInfoList = connector.getBookingInfo();
//Display items of performanceInfoList
for (int i = 0;i<bookingInfoInfoList.size();i++) {
ArrayList tempList = (ArrayList) bookingInfoInfoList.get(i);
System.out.println(tempList.get(0));
System.out.println(tempList);
bookingList.add(bookingList.size(), new IdleData2(tempList.get(1).toString(),
tempList.get(2).toString(), tempList.get(0).toString()));
}
}
public void cancelBooking (View view) {
}
}
......@@ -21,6 +21,7 @@ import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class performanceInfoPage extends AppCompatActivity {
......@@ -132,7 +133,7 @@ public class performanceInfoPage extends AppCompatActivity {
ArrayList workingTicketInfo = getTicketInfo(currentPerformance);
LinearLayout linearLayout3 = (LinearLayout) findViewById(R.id.bookTicketsLayout3);
System.out.println(workingTicketInfo);
for (int i=0;i<workingTicketInfo.size();i++) {
String currentTicket = workingTicketInfo.get(i).toString();
......@@ -154,11 +155,31 @@ public class performanceInfoPage extends AppCompatActivity {
splitItems[0] = String.valueOf(Integer.parseInt(splitItems[0]) - ticketNumInt);
String unsplitSplit = splitItems[0]+","+splitItems[1]+","+splitItems[2];
for (int x=0;x>currentPerformance.size();x++) {
for (int x=0;x<currentPerformance.size();x++) {
if (currentPerformance.get(x) == (currentTicket)) {
currentPerformance.set(x,unsplitSplit);
//Connect to DB
DBConnector connector = new DBConnector(this, null);
connector.updateDBTickets(currentPerformance);
break;
}
}
}
DBConnector connector = new DBConnector(this, null);
String bookingID = createBookingID();
System.out.println(bookingID);
connector.addBooking(bookingID, currentPerformance.get(0).toString(),workingTicketInfo);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
public String createBookingID () {
int upper = 10000;
Random rand = new Random();
String bookingID = String.valueOf(rand.nextInt(upper));
return bookingID;
}
}
......@@ -15,16 +15,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/usernameTextView"
android:layout_width="108dp"
android:layout_height="23dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.947"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/logOutBtn"
android:layout_width="wrap_content"
......@@ -36,6 +26,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/myBookingsBtn"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:onClick="myBookingsBtn"
android:text="Bookings"
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="411dp"
......
<?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:id="@+id/linearLayoutPerf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5sp"
android:layout_marginTop="10sp"
android:layout_marginEnd="10sp"
android:layout_marginBottom="10sp"
android:background="@color/beigeWhite">
<TextView
android:id="@+id/performanceBookName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/ticketsBooked"
android:layout_width="wrap_content"
android:layout_height="22dp"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:text="TextView"
android:textSize="16sp"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/performanceBookName" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:text="Tickets Booked:"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/performanceBookName" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:text="Booking Reference: "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/bookingReference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:layout_weight="1"
android:text="TextView"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/cancelBookingBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:onClick="cancelBooking"
android:text="Cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?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"
android:background="@color/beigeWhite"
tools:context=".myBookingsActivity">
<Button
android:id="@+id/backBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Back"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="665dp"
android:layout_marginStart="1dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="1dp"
android:orientation="vertical"
android:background="@color/beige"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/backBtn1">
<TextView
android:id="@+id/textViewPerformances2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="serif"
android:text="My Bookings"
android:textAlignment="center"
android:textSize="24sp"
android:background="@color/beigeWhite"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bookingsRecycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -2,7 +2,7 @@
<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:id="@+id/linearLayout"
android:id="@+id/linearLayoutPerf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5sp"
......@@ -12,7 +12,7 @@
android:background="@color/beigeWhite">
<TextView
android:id="@+id/performanceName"
android:id="@+id/performanceBookName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
......@@ -35,7 +35,7 @@
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/performanceName" />
app:layout_constraintTop_toBottomOf="@+id/performanceBookName" />
<TextView
android:id="@+id/ticketsLeft"
......@@ -48,7 +48,7 @@
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/performanceName" />
app:layout_constraintTop_toBottomOf="@+id/performanceBookName" />
<TextView
android:id="@+id/textView2"
......@@ -61,7 +61,7 @@
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ticketsLeft"
app:layout_constraintTop_toBottomOf="@+id/performanceName" />
app:layout_constraintTop_toBottomOf="@+id/performanceBookName" />
</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