0% found this document useful (0 votes)
4 views

Assignment 1 Code Documentation

Uploaded by

waghray101177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 1 Code Documentation

Uploaded by

waghray101177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Code Documenta on

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.

 Task (data class):


Represents a task within a to-do list, containing proper es such as id, name,
dueDate, and completed.

 Task Management (UI and Logic):


Displays a list of tasks related to a par cular to-do item. Each task can be
checked for comple on, edited, deleted, or marked as completed. The tasks are
displayed with a name, due date (if any), and op ons for interac on (edit, delete, mark
completed).
If the user decides to add a new task, an AlertDialog appears to enter the
task's name and op onally select a due date.
If the user wants to modify a task, a similar dialog appears pre-populated with
the task’s details.
 Add Task Dialog:
A dialog that allows the user to input a new task's name and op onally select
a due date. Once confirmed, the task is added to the database and the list of tasks is
updated.

 Modify Task Dialog:


A dialog that allows the user to modify the details of an exis ng task. The user
can edit the task's name and due date. Upon confirma on, the task is updated in the
database.

 DB Opera ons (via dbHelper):


Opera ons such as fetching tasks for a par cular to-do item, inser ng a new
task, upda ng a task’s details, and dele ng a task are handled through dbHelper, which
interacts with the database.

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.

 onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int)


Called when the database needs to be upgraded (e.g., schema changes). If the
database version is upgraded to version 4 or higher, it adds the completed column to
the tasks table.

 insertTodoItem(name: String): Long


Inserts a new to-do item into the todo_items table.
Parameters: name (The name of the to-do item).
Returns: The row ID of the newly inserted 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.

 deleteTodoItem(id: Int): Int


Deletes a to-do item from the todo_items table by its ID.
Parameters: id (The ID of the to-do item to delete).
Returns: The number of rows affected (should be 1 if successful).
 updateTodoItem(id: Int, newName: String): Int
Updates the name of a to-do item in the todo_items table.
Parameters: id (The ID of the to-do item to update), newName (The new name
of the to-do item).
Returns: The number of rows affected (should be 1 if successful).

 insertTask(todoId: Int, taskName: String, dueDate: String?, completed: Boolean):


Long
Inserts a new task for a specific to-do item into the tasks table.
Parameters: todoId (The ID of the to-do item to associate the task with),
taskName (The name of the task), dueDate (The due date for the task,
op onal), completed (A boolean indica ng whether the task is completed).
Returns: The row ID of the newly inserted task.

 getTasksForTodo(todoId: Int): Cursor


Retrieves all tasks associated with a specific to-do item.
Parameters: todoId (The ID of the to-do item).
Returns: A Cursor object containing all tasks for the specified to-do item.

 deleteTask(taskId: Int): Int

Deletes a task from the tasks table by its ID.


Parameters: taskId (The ID of the task to delete).
Returns: The number of rows affected (should be 1 if successful).

 updateTaskComple on(taskId: Int, completed: Boolean): Int

Updates the comple on status of a task.


Parameters: taskId (The ID of the task to update), completed (The new
comple on status of the task).
Returns: The number of rows affected (should be 1 if successful).

 updateTask(taskId: Int, newName: String, newDueDate: String?): Int


Updates the details of a task (name and/or due date).
Parameters: taskId (The ID of the task to update), newName (The new name
of the task), newDueDate (The new due date of the task, op onal).
Returns: The number of rows affected (should be 1 if successful).

 isTodoItemNameUnique(name: String): Boolean


Checks if a to-do item name is unique (i.e., not already used in the database).
Parameters: name (The name of the to-do item to check).
Returns: true if the name is unique, false otherwise.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy