Commit ab08d7f6 authored by a-j.towse's avatar a-j.towse

semi working ticket selector

parent 713ef004
...@@ -15,6 +15,7 @@ import android.widget.EditText; ...@@ -15,6 +15,7 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.NumberPicker; import android.widget.NumberPicker;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
...@@ -23,6 +24,11 @@ import java.util.List; ...@@ -23,6 +24,11 @@ import java.util.List;
public class performanceInfoPage extends AppCompatActivity { public class performanceInfoPage extends AppCompatActivity {
int ticketTypeCount = 0;
String selectedPerformance;
ArrayList currentPerformance = null;
ArrayList ticketTypeList = new ArrayList<>();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -30,10 +36,9 @@ public class performanceInfoPage extends AppCompatActivity { ...@@ -30,10 +36,9 @@ public class performanceInfoPage extends AppCompatActivity {
setContentView(R.layout.performance_infopage); setContentView(R.layout.performance_infopage);
Intent intent = getIntent(); Intent intent = getIntent();
String selectedPerformance = intent.getStringExtra("selectedPlay"); selectedPerformance = intent.getStringExtra("selectedPlay");
setInfo(selectedPerformance); setInfo(selectedPerformance);
} }
public void backBtn (View view) { public void backBtn (View view) {
...@@ -51,7 +56,6 @@ public class performanceInfoPage extends AppCompatActivity { ...@@ -51,7 +56,6 @@ public class performanceInfoPage extends AppCompatActivity {
DBConnector connector = new DBConnector(this, null); DBConnector connector = new DBConnector(this, null);
ArrayList performanceInfoList = connector.getPerformanceInfo(); ArrayList performanceInfoList = connector.getPerformanceInfo();
ArrayList currentPerformance = null;
for (int i = 0; i < performanceInfoList.size(); i++) { for (int i = 0; i < performanceInfoList.size(); i++) {
ArrayList tempList = (ArrayList) performanceInfoList.get(i); ArrayList tempList = (ArrayList) performanceInfoList.get(i);
...@@ -66,14 +70,16 @@ public class performanceInfoPage extends AppCompatActivity { ...@@ -66,14 +70,16 @@ public class performanceInfoPage extends AppCompatActivity {
venueTextView.setText((currentPerformance.get(3).toString()+ ": "+ venueTextView.setText((currentPerformance.get(3).toString()+ ": "+
currentPerformance.get(2).toString())); currentPerformance.get(2).toString()));
int ticketTypeCount = 0; ticketTypeCount =0;
//count the number of tickets types left //count the number of tickets types left
for (int x=7;x<currentPerformance.size();x++) { for (int x=7;x<currentPerformance.size();x++) {
if (currentPerformance.get(x) != null) { if (currentPerformance.get(x) != null) {
ticketTypeCount+=1; ticketTypeCount+=1;
String unSplitItem = currentPerformance.get(x).toString(); String unSplitItem = currentPerformance.get(x).toString();
System.out.println(currentPerformance.get(x));
String[] splitItems = unSplitItem.split(",",0); String[] splitItems = unSplitItem.split(",",0);
//String num = unSplitItem.substring(0,unSplitItem.indexOf(",")); //String num = unSplitItem.substring(0,unSplitItem.indexOf(","));
//String price = unSplitItem.substring(1,unSplitItem.indexOf(",")); //String price = unSplitItem.substring(1,unSplitItem.indexOf(","));
//String name = unSplitItem.substring(2,unSplitItem.indexOf(",")); //String name = unSplitItem.substring(2,unSplitItem.indexOf(","));
...@@ -85,7 +91,6 @@ public class performanceInfoPage extends AppCompatActivity { ...@@ -85,7 +91,6 @@ public class performanceInfoPage extends AppCompatActivity {
text.setPadding(0,0,0,15); text.setPadding(0,0,0,15);
linearLayout.addView(text); linearLayout.addView(text);
final LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.bookTicketsLayout2); final LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.bookTicketsLayout2);
final TextView text2 = new TextView(this); final TextView text2 = new TextView(this);
text2.setText("Available: "+splitItems[0]); text2.setText("Available: "+splitItems[0]);
...@@ -99,9 +104,60 @@ public class performanceInfoPage extends AppCompatActivity { ...@@ -99,9 +104,60 @@ public class performanceInfoPage extends AppCompatActivity {
numSelect.setMinimumWidth(40); numSelect.setMinimumWidth(40);
numSelect.setRawInputType(TYPE_CLASS_NUMBER); numSelect.setRawInputType(TYPE_CLASS_NUMBER);
numSelect.setMaxLines(1); numSelect.setMaxLines(1);
numSelect.setText("0");
numSelect.setGravity(Gravity.CENTER); numSelect.setGravity(Gravity.CENTER);
numSelect.setTag(("TixSelect,"+splitItems[2]));
linearLayout3.addView(numSelect); linearLayout3.addView(numSelect);
}
}
}
public ArrayList getTicketInfo(ArrayList currentPerformance) {
ArrayList workingTicketInfo = new ArrayList<>();
for (int x=7;x<currentPerformance.size();x++) {
if (currentPerformance.get(x) != null) {
String unSplitItem = currentPerformance.get(x).toString();
workingTicketInfo.add(unSplitItem);
}
} }
return workingTicketInfo;
}
public void getBookingInfo (View view) {
ArrayList workingTicketInfo = getTicketInfo(currentPerformance);
LinearLayout linearLayout3 = (LinearLayout) findViewById(R.id.bookTicketsLayout3);
for (int i=0;i<workingTicketInfo.size();i++) {
String currentTicket = workingTicketInfo.get(i).toString();
String[] splitItems = currentTicket.split(",",0);
String tickID = "TixSelect,"+splitItems[2];
EditText editText = (EditText) linearLayout3.findViewWithTag(tickID);
String ticketNumSelect = editText.getText().toString();
int ticketNumInt = Integer.parseInt(ticketNumSelect);
if (ticketNumInt > Integer.parseInt(splitItems[0])) {
Toast.makeText(this, "Number of selected tickets not available",
Toast.LENGTH_SHORT).show();
}
else
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++) {
}
} }
} }
......
...@@ -30,12 +30,23 @@ ...@@ -30,12 +30,23 @@
android:id="@+id/backBtn" android:id="@+id/backBtn"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:onClick="backBtn" android:onClick="backBtn"
android:text="Back" android:text="Back"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="16dp" />
<Button
android:id="@+id/bookNowBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="getBookingInfo"
android:text="Book Now"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@+id/bookTicketsLayout2" />
<LinearLayout <LinearLayout
android:id="@+id/linearLayout2" android:id="@+id/linearLayout2"
...@@ -95,8 +106,8 @@ ...@@ -95,8 +106,8 @@
android:id="@+id/textView6" android:id="@+id/textView6"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Book Tickets:"
android:paddingBottom="20dp" android:paddingBottom="20dp"
android:text="Book Tickets:"
android:textSize="20sp" /> android:textSize="20sp" />
</LinearLayout> </LinearLayout>
......
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