Commit c6de924c authored by bryan.quispe's avatar bryan.quispe

Initial commit

parent 079cac85
......@@ -12,7 +12,7 @@
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".LoginActivity"
android:name=".HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
......
package com.example.myapplication;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
......@@ -19,7 +20,9 @@ public class HomeActivity extends AppCompatActivity {
private Database dbConnector;
private List<String> bookingsList; // List to store all bookings
private int ticketCount;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -35,6 +38,7 @@ public class HomeActivity extends AppCompatActivity {
Button addButton = findViewById(R.id.addButton);
Button searchButton = findViewById(R.id.searchButton);
Button showAllButton = findViewById(R.id.showAllButton);
Button updateButton = findViewById(R.id.updateButton);
Button deleteButton = findViewById(R.id.deleteButton);
// Initialize the bookings list
......@@ -44,13 +48,13 @@ public class HomeActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
String eventID = eventIDEditText.getText().toString();
String title = titleEditText.getText().toString();
String genre = genreEditText.getText().toString();
String title = genreEditText.getText().toString(); // Swap genreEditText and titleEditText
String genre = titleEditText.getText().toString(); // Swap titleEditText and genreEditText
if (eventID.isEmpty() || title.isEmpty() || genre.isEmpty()) {
Toast.makeText(HomeActivity.this, "Please fill in all fields", Toast.LENGTH_SHORT).show();
} else {
dbConnector.addBooking(eventID, title, genre, 0);
dbConnector.addBooking(eventID, title, genre, getTicketCount());
Toast.makeText(HomeActivity.this, "Booking added successfully", Toast.LENGTH_SHORT).show();
// Clear the input fields after adding the booking
......@@ -76,7 +80,7 @@ public class HomeActivity extends AppCompatActivity {
showAllButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bookingsList = dbConnector.searchBooking();
bookingsList = dbConnector.getAllBookings();
if (bookingsList.isEmpty()) {
resultTextView.setText("No bookings available");
} else {
......@@ -89,6 +93,22 @@ public class HomeActivity extends AppCompatActivity {
}
});
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String eventID = eventIDEditText.getText().toString();
String newTitle = titleEditText.getText().toString();
String newGenre = genreEditText.getText().toString();
dbConnector.updateBooking(eventID, newTitle, newGenre);
Toast.makeText(HomeActivity.this, "Booking updated successfully", Toast.LENGTH_SHORT).show();
// Clear the input fields after updating the booking
eventIDEditText.setText("");
titleEditText.setText("");
genreEditText.setText("");
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -100,14 +120,49 @@ public class HomeActivity extends AppCompatActivity {
eventIDEditText.setText("");
}
});
EditText filterEditText = findViewById(R.id.filterEditText);
Button filterButton = findViewById(R.id.filterButton);
filterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String keyword = filterEditText.getText().toString();
filterBookings(keyword);
}
});
}
// Additional method to handle filter/search functionality
private void filterBookings(String keyword) {
List<String> filteredList = new ArrayList<>();
for (String booking : bookingsList) {
// Check if the booking genre contains the keyword
if (booking.toLowerCase().contains(keyword.toLowerCase())) {
filteredList.add(booking);
}
}
if (filteredList.isEmpty()) {
resultTextView.setText("No matching bookings found");
} else {
StringBuilder sb = new StringBuilder();
for (String booking : filteredList) {
sb.append(booking).append("\n\n");
}
resultTextView.setText(sb.toString());
}
}
private void displayTicketsForEvent(String eventID) {
String tickets = dbConnector.getTicketsForEvent(eventID);
if (tickets == null) {
List<String> ticketsList = dbConnector.getTicketsForEvent(eventID);
if (ticketsList.isEmpty()) {
resultTextView.setText("No tickets available for this event");
} else {
resultTextView.setText(tickets);
StringBuilder sb = new StringBuilder();
for (String ticket : ticketsList) {
sb.append(ticket).append("\n\n");
}
resultTextView.setText(sb.toString());
}
}
......@@ -116,4 +171,13 @@ public class HomeActivity extends AppCompatActivity {
super.onDestroy();
dbConnector.close();
}
public void setTicketCount(int ticketCount) {
this.ticketCount = ticketCount;
}
public int getTicketCount() {
return ticketCount;
}
}
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