Assignment 1 Code Documentation
Assignment 1 Code Documentation
MainAc vity:
MainAc vity.onCreate():
Ini alizes the DBOpenHelper and sets up the ac vity's UI. It manages the state
of todoItems, todoListName, and selectedItemId. It includes the func onality to
display an AlertDialog for adding and edi ng to-do lists. It also loads exis ng to-do
items from the database.
TodoItemGridView():
A composable func on that displays a single to-do item in a grid view. It shows
the item’s name along with edit and delete bu ons. Clicking the edit bu on opens an
edit dialog, while the delete bu on removes the item from the list. Addi onally, there
is a bu on to navigate to a second ac vity for viewing or managing tasks associated
with the to-do item.
SecondAc vity:
SecondAc vity.onCreate():
Ini alizes the DBOpenHelper and retrieves the todoId passed from the
previous ac vity. Sets up the UI for displaying and managing tasks associated with the
selected to-do item. It includes func onality to display a list of tasks, mark them as
completed, and edit or delete tasks. It also provides func onality for adding new tasks
with a due date and edi ng exis ng tasks.
DBOpenHelper:
DBOpenHelper Class
A helper class that extends SQLiteOpenHelper to manage the SQLite database
for the to-do list applica on. It is responsible for crea ng, upgrading, and managing
the todo_items and tasks tables, as well as providing methods for database opera ons
such as adding, upda ng, and dele ng to-do items and tasks.
DATABASE_NAME: "todo.db"
The name of the SQLite database used by the app.
TABLE_NAME: "todo_items"
The name of the table that stores the to-do list items.
COLUMN_ID: "id"
The column name for the primary key in the todo_items table.
COLUMN_NAME: "name"
The column name for the to-do item name in the todo_items table.
TASKS_TABLE_NAME: "tasks"
The name of the table that stores the tasks associated with each to-do item.
COLUMN_TODO_ID: "todo_id"
The column name for the foreign key linking tasks to a specific to-do item.
COLUMN_TASK_NAME: "task_name"
The column name for the name of a task in the tasks table.
COLUMN_TASK_ID: "task_id"
The column name for the primary key in the tasks table.
COLUMN_DUE_DATE: "due_date"
The column name for the task's due date.
COLUMN_COMPLETED: "completed"
The column name indica ng whether a task is completed (1 for completed, 0
for not completed).
onCreate(db: SQLiteDatabase?)
Called when the database is created for the first me. It creates two tables:
(i) todo_items: Stores the main to-do list items, each having a unique ID
and a name.
(ii) tasks: Stores tasks related to each to-do item, including the task name,
due date, comple on status, and a foreign key referencing the to-do
item.
getAllTodoItems(): Cursor
Retrieves all the to-do items from the todo_items table.
Returns: A Cursor object containing all rows in the todo_items table.