Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
THEATERT MOBILE APP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bryan.quispe
THEATERT MOBILE APP
Commits
c6de924c
Commit
c6de924c
authored
Jun 05, 2023
by
bryan.quispe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parent
079cac85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
208 additions
and
101 deletions
+208
-101
AndroidManifest.xml
MyApplication/app/src/main/AndroidManifest.xml
+1
-1
Database.java
...app/src/main/java/com/example/myapplication/Database.java
+136
-93
HomeActivity.java
...src/main/java/com/example/myapplication/HomeActivity.java
+71
-7
No files found.
MyApplication/app/src/main/AndroidManifest.xml
View file @
c6de924c
...
...
@@ -12,7 +12,7 @@
android:theme=
"@style/Theme.MyApplication"
tools:targetApi=
"31"
>
<activity
android:name=
".
Login
Activity"
android:name=
".
Home
Activity"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
...
...
MyApplication/app/src/main/java/com/example/myapplication/Database.java
View file @
c6de924c
package
com
.
example
.
myapplication
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.database.Cursor
;
...
...
@@ -11,61 +13,86 @@ import java.util.List;
public
class
Database
extends
SQLiteOpenHelper
{
// Users table
private
static
final
String
TABLE_USERS
=
"Users"
;
private
static
final
String
COLUMN_UID
=
"uid"
;
private
static
final
String
COLUMN_NAME
=
"name"
;
private
static
final
String
COLUMN_USERNAME
=
"username"
;
private
static
final
String
COLUMN_PASSWORD
=
"password"
;
// Booking table
private
static
final
String
TABLE_BOOKING
=
"Booking"
;
private
static
final
String
COLUMN_EVENT_ID
=
"eventID"
;
private
static
final
String
COLUMN_TITLE
=
"title"
;
private
static
final
String
COLUMN_GENRE
=
"genre"
;
private
static
final
String
COLUMN_TICKET_COUNT
=
"ticketCount"
;
// Database constants
private
static
final
String
DB_NAME
=
"MyApp.db"
;
private
static
final
int
DB_VERSION
=
2
;
private
Context
context
;
public
Database
(
Context
context
)
{
super
(
context
,
DB_NAME
,
null
,
DB_VERSION
);
this
.
context
=
context
;
}
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
{
createUsersTable
(
db
);
createBookingTable
(
db
);
}
private
void
createUsersTable
(
SQLiteDatabase
db
)
{
String
createUsersTable
=
"CREATE TABLE Users ("
+
"uid INTEGER PRIMARY KEY AUTOINCREMENT, "
+
"name TEXT, "
+
"username TEXT, "
+
"password TEXT)"
;
// Create Users table
String
createUsersTable
=
"CREATE TABLE "
+
TABLE_USERS
+
"("
+
COLUMN_UID
+
" INTEGER PRIMARY KEY AUTOINCREMENT, "
+
COLUMN_NAME
+
" TEXT, "
+
COLUMN_USERNAME
+
" TEXT, "
+
COLUMN_PASSWORD
+
" TEXT)"
;
db
.
execSQL
(
createUsersTable
);
}
private
void
createBookingTable
(
SQLiteDatabase
db
)
{
String
createBookingTable
=
"CREATE TABLE
Booking
("
+
"eventID
TEXT, "
+
"title
TEXT, "
+
"genre
TEXT, "
+
"ticketCount
INTEGER, "
+
"PRIMARY KEY (
eventID
))"
;
// Create Booking table
String
createBookingTable
=
"CREATE TABLE
"
+
TABLE_BOOKING
+
"
("
+
COLUMN_EVENT_ID
+
"
TEXT, "
+
COLUMN_TITLE
+
"
TEXT, "
+
COLUMN_GENRE
+
"
TEXT, "
+
COLUMN_TICKET_COUNT
+
"
INTEGER, "
+
"PRIMARY KEY (
"
+
COLUMN_EVENT_ID
+
"
))"
;
db
.
execSQL
(
createBookingTable
);
}
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS Booking"
);
createBookingTable
(
db
);
// Drop the existing Booking table
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
TABLE_BOOKING
);
// Create a new Booking table with the updated schema
String
createBookingTable
=
"CREATE TABLE "
+
TABLE_BOOKING
+
"("
+
COLUMN_EVENT_ID
+
" TEXT, "
+
COLUMN_TITLE
+
" TEXT, "
+
COLUMN_GENRE
+
" TEXT, "
+
COLUMN_TICKET_COUNT
+
" INTEGER, "
+
"PRIMARY KEY ("
+
COLUMN_EVENT_ID
+
"))"
;
db
.
execSQL
(
createBookingTable
);
}
public
boolean
addNewUser
(
String
name
,
String
username
,
String
password
)
{
SQLiteDatabase
db
=
getWritableDatabase
();
// User methods
public
void
addNewUser
(
String
name
,
String
username
,
String
password
)
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
ContentValues
values
=
new
ContentValues
();
values
.
put
(
"name"
,
name
);
values
.
put
(
"username"
,
username
);
values
.
put
(
"password"
,
password
);
db
.
insert
(
"Users"
,
null
,
values
);
values
.
put
(
COLUMN_NAME
,
name
);
values
.
put
(
COLUMN_USERNAME
,
username
);
values
.
put
(
COLUMN_PASSWORD
,
password
);
db
.
insert
(
TABLE_USERS
,
null
,
values
);
db
.
close
();
return
false
;
}
public
boolean
checkLogin
(
String
username
,
String
password
)
{
SQLiteDatabase
db
=
getReadableDatabase
();
String
[]
columns
=
{
"username"
};
String
selection
=
"username = ? AND password = ?"
;
String
[]
selectionArgs
=
{
username
,
password
};
Cursor
cursor
=
db
.
query
(
"Users"
,
columns
,
selection
,
selectionArgs
,
null
,
null
,
null
);
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
query
=
"SELECT * FROM "
+
TABLE_USERS
+
" WHERE "
+
COLUMN_USERNAME
+
" = ? AND "
+
COLUMN_PASSWORD
+
" = ?"
;
Cursor
cursor
=
db
.
rawQuery
(
query
,
new
String
[]{
username
,
password
});
boolean
result
=
cursor
.
getCount
()
>
0
;
cursor
.
close
();
db
.
close
();
...
...
@@ -73,87 +100,103 @@ public class Database extends SQLiteOpenHelper {
}
public
boolean
checkUsernameExists
(
String
username
)
{
SQLiteDatabase
db
=
getReadableDatabase
();
String
[]
columns
=
{
"username"
};
String
selection
=
"username = ?"
;
String
[]
selectionArgs
=
{
username
};
Cursor
cursor
=
db
.
query
(
"Users"
,
columns
,
selection
,
selectionArgs
,
null
,
null
,
null
);
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
query
=
"SELECT * FROM "
+
TABLE_USERS
+
" WHERE "
+
COLUMN_USERNAME
+
" = ?"
;
Cursor
cursor
=
db
.
rawQuery
(
query
,
new
String
[]{
username
});
boolean
exists
=
cursor
.
getCount
()
>
0
;
cursor
.
close
();
db
.
close
();
return
exists
;
}
public
void
addBooking
(
String
eventID
,
String
title
,
String
genre
,
int
ticketCount
)
{
SQLiteDatabase
db
=
getWritableDatabase
();
// Booking methods
public
void
addBooking
(
String
eventID
,
String
genre
,
String
title
,
int
ticketCount
)
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
ContentValues
values
=
new
ContentValues
();
values
.
put
(
"eventID"
,
eventID
);
values
.
put
(
"title"
,
title
);
values
.
put
(
"genre"
,
genre
);
values
.
put
(
"ticketCount"
,
ticketCount
);
long
rowsAffected
=
db
.
replace
(
"Booking"
,
null
,
values
);
if
(
rowsAffected
==
-
1
)
{
db
.
insert
(
"Booking"
,
null
,
values
);
}
db
.
close
();
}
values
.
put
(
COLUMN_EVENT_ID
,
eventID
);
values
.
put
(
COLUMN_TITLE
,
title
);
values
.
put
(
COLUMN_GENRE
,
genre
);
values
.
put
(
COLUMN_TICKET_COUNT
,
ticketCount
);
public
List
<
String
>
searchBooking
()
{
SQLiteDatabase
db
=
getReadableDatabase
();
String
[]
columns
=
{
"eventID"
,
"title"
,
"genre"
};
Cursor
cursor
=
db
.
query
(
"Booking"
,
columns
,
null
,
null
,
null
,
null
,
null
);
List
<
String
>
bookingsList
=
new
ArrayList
<>();
int
rowsAffected
=
db
.
update
(
TABLE_BOOKING
,
values
,
COLUMN_EVENT_ID
+
" = ?"
,
new
String
[]{
eventID
});
while
(
cursor
.
moveToNext
()
)
{
String
eventID
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"eventID"
));
String
title
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"title"
)
);
String
genre
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"genre"
));
if
(
rowsAffected
==
0
)
{
// No existing row found with the provided eventID
db
.
insert
(
TABLE_BOOKING
,
null
,
values
);
}
String
booking
=
"Event ID: "
+
eventID
+
"\n"
+
"Title: "
+
title
+
"\n"
+
"Genre: "
+
genre
+
"\n\n"
;
db
.
close
();
}
bookingsList
.
add
(
booking
);
public
String
searchBooking
(
String
eventID
)
{
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
query
=
"SELECT * FROM "
+
TABLE_BOOKING
+
" WHERE "
+
COLUMN_EVENT_ID
+
" = ?"
;
Cursor
cursor
=
db
.
rawQuery
(
query
,
new
String
[]{
eventID
});
String
result
=
null
;
if
(
cursor
.
moveToFirst
())
{
result
=
"Event ID: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_EVENT_ID
))
+
"\n"
+
"Title: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_TITLE
))
+
"\n"
+
"Genre: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_GENRE
));
}
cursor
.
close
();
db
.
close
();
return
result
;
}
public
ArrayList
<
String
>
getAllBookings
()
{
ArrayList
<
String
>
bookingsList
=
new
ArrayList
<>();
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
query
=
"SELECT * FROM "
+
TABLE_BOOKING
;
Cursor
cursor
=
db
.
rawQuery
(
query
,
null
);
if
(
cursor
.
moveToFirst
())
{
do
{
String
bookingInfo
=
"Event ID: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_EVENT_ID
))
+
"\n"
+
"Title: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_TITLE
))
+
"\n"
+
"Genre: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_GENRE
));
bookingsList
.
add
(
bookingInfo
);
}
while
(
cursor
.
moveToNext
());
}
cursor
.
close
();
db
.
close
();
return
bookingsList
;
}
public
void
deleteBooking
(
String
eventID
)
{
SQLiteDatabase
db
=
getWritableDatabase
();
String
whereClause
=
"eventID = ?"
;
String
[]
whereArgs
=
{
eventID
};
db
.
delete
(
"Booking"
,
whereClause
,
whereArgs
);
public
List
<
String
>
getTicketsForEvent
(
String
eventID
)
{
List
<
String
>
ticketsList
=
new
ArrayList
<>();
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
query
=
"SELECT * FROM "
+
TABLE_BOOKING
+
" WHERE "
+
COLUMN_EVENT_ID
+
" = ?"
;
Cursor
cursor
=
db
.
rawQuery
(
query
,
new
String
[]{
eventID
});
if
(
cursor
.
moveToFirst
())
{
do
{
String
ticketInfo
=
"Event ID: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_EVENT_ID
))
+
"\n"
+
"Title: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_TITLE
))
+
"\n"
+
"Genre: "
+
cursor
.
getString
(
cursor
.
getColumnIndex
(
COLUMN_GENRE
))
+
"\n"
+
"Ticket Count: "
+
cursor
.
getInt
(
cursor
.
getColumnIndex
(
COLUMN_TICKET_COUNT
));
ticketsList
.
add
(
ticketInfo
);
}
while
(
cursor
.
moveToNext
());
}
cursor
.
close
();
db
.
close
();
return
ticketsList
;
}
public
String
getTicketsForEvent
(
String
eventID
)
{
SQLiteDatabase
db
=
getReadableDatabase
();
String
[]
columns
=
{
"eventID"
,
"title"
,
"genre"
,
"ticketCount"
};
String
selection
=
"eventID = ?"
;
String
[]
selectionArgs
=
{
eventID
};
Cursor
cursor
=
db
.
query
(
"Booking"
,
columns
,
selection
,
selectionArgs
,
null
,
null
,
null
);
public
void
updateBooking
(
String
eventID
,
String
newTitle
,
String
newGenre
)
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
ContentValues
values
=
new
ContentValues
();
values
.
put
(
COLUMN_TITLE
,
newTitle
);
values
.
put
(
COLUMN_GENRE
,
newGenre
);
db
.
update
(
TABLE_BOOKING
,
values
,
COLUMN_EVENT_ID
+
" = ?"
,
new
String
[]{
eventID
});
db
.
close
();
}
if
(
cursor
.
moveToFirst
())
{
String
title
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"title"
));
String
genre
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
"genre"
));
int
ticketCount
=
cursor
.
getInt
(
cursor
.
getColumnIndex
(
"ticketCount"
));
String
tickets
=
"Event ID: "
+
eventID
+
"\n"
+
"Title: "
+
title
+
"\n"
+
"Genre: "
+
genre
+
"\n"
+
"Ticket Count: "
+
ticketCount
;
cursor
.
close
();
db
.
close
();
return
tickets
;
}
else
{
cursor
.
close
();
db
.
close
();
return
null
;
}
public
void
deleteBooking
(
String
eventID
)
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
db
.
delete
(
TABLE_BOOKING
,
COLUMN_EVENT_ID
+
" = ?"
,
new
String
[]{
eventID
});
db
.
close
();
}
}
}
MyApplication/app/src/main/java/com/example/myapplication/HomeActivity.java
View file @
c6de924c
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
(
tickets
List
.
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment