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

Initial commit

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