diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6906995..070f5b4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -39,4 +39,17 @@ dependencies { testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + val roomVersion = "2.6.1" + implementation("androidx.room:room-runtime:$roomVersion") + annotationProcessor("androidx.room:room-compiler:$roomVersion") + // optional - RxJava2 support for Room + implementation("androidx.room:room-rxjava2:$roomVersion") + // optional - RxJava3 support for Room + implementation("androidx.room:room-rxjava3:$roomVersion") + // optional - Guava support for Room, including Optional and ListenableFuture + implementation("androidx.room:room-guava:$roomVersion") + // optional - Test helpers + testImplementation("androidx.room:room-testing:$roomVersion") + // optional - Paging 3 Integration + implementation("androidx.room:room-paging:$roomVersion") } \ No newline at end of file diff --git a/app/src/main/java/com/example/taskmanager/Activity/CreateTaskActivity.java b/app/src/main/java/com/example/taskmanager/Activity/CreateTaskActivity.java index f563b06..89175aa 100644 --- a/app/src/main/java/com/example/taskmanager/Activity/CreateTaskActivity.java +++ b/app/src/main/java/com/example/taskmanager/Activity/CreateTaskActivity.java @@ -20,9 +20,12 @@ import android.widget.TimePicker; import android.widget.Toast; +import com.example.taskmanager.Database.RoomDB; import com.example.taskmanager.R; +import com.example.taskmanager.Utility.TaskModel; import java.time.LocalDate; +import java.util.List; public class CreateTaskActivity extends AppCompatActivity { String currentPriority = "Low"; @@ -53,6 +56,12 @@ public void onNothingSelected(AdapterView parentView) { // Do nothing } }); + + //for database testing purposes (note that anyways this wouldnt work as you can't directly call db method from the same UI thread) +// RoomDB instance = RoomDB.getInstance(getApplicationContext()); +// instance.taskDAO().insertTask(new TaskModel( 0, "test", "ayyyyy", "", "", "", true)); +// List allTasks = instance.taskDAO().getAllTasks(); +// Log.wtf("DB", allTasks.toString()); } public void selectDate(View v) { diff --git a/app/src/main/java/com/example/taskmanager/Database/RoomDB.java b/app/src/main/java/com/example/taskmanager/Database/RoomDB.java new file mode 100644 index 0000000..1d5eea5 --- /dev/null +++ b/app/src/main/java/com/example/taskmanager/Database/RoomDB.java @@ -0,0 +1,30 @@ +package com.example.taskmanager.Database; + +import android.content.Context; + +import androidx.room.Database; +import androidx.room.Room; +import androidx.room.RoomDatabase; + +import com.example.taskmanager.Utility.TaskModel; + +@Database(entities = {TaskModel.class}, version = 1) +public abstract class RoomDB extends RoomDatabase { + private static volatile RoomDB INSTANCE; + public abstract TaskDAO taskDAO (); + + public static RoomDB getInstance(Context context){ + if (INSTANCE == null){ + synchronized (RoomDB.class) { + if (INSTANCE == null){ + INSTANCE = Room.databaseBuilder(context.getApplicationContext(), RoomDB.class, "TASK_DB").build(); + } + } + } + return INSTANCE; + } + + public void insertTask(TaskModel task){ + + } +} diff --git a/app/src/main/java/com/example/taskmanager/Database/TaskDAO.java b/app/src/main/java/com/example/taskmanager/Database/TaskDAO.java new file mode 100644 index 0000000..03a04d5 --- /dev/null +++ b/app/src/main/java/com/example/taskmanager/Database/TaskDAO.java @@ -0,0 +1,35 @@ +package com.example.taskmanager.Database; + +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; + +import com.example.taskmanager.Utility.TaskModel; + +import java.util.List; + +@Dao +public interface TaskDAO { + @Insert + void insertTask(TaskModel task); + + @Delete + void deleteTask(TaskModel task); + + @Update + void updateTask(TaskModel task); + + @Query("SELECT * FROM task_table") + List getAllTasks(); + + @Query("SELECT * FROM task_table WHERE id LIKE :taskId") + TaskModel findTaskById(int taskId); + + @Query("SELECT * FROM task_table WHERE status LIKE 0") + List getAllOngoingTasks(); + + @Query("SELECT * FROM task_table WHERE status LIKE 1") + List getAllCompletedTasks(); +} diff --git a/app/src/main/java/com/example/taskmanager/Utility/TaskModel.java b/app/src/main/java/com/example/taskmanager/Utility/TaskModel.java index 87e30fb..92caa68 100644 --- a/app/src/main/java/com/example/taskmanager/Utility/TaskModel.java +++ b/app/src/main/java/com/example/taskmanager/Utility/TaskModel.java @@ -1,27 +1,42 @@ package com.example.taskmanager.Utility; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + import java.io.Serializable; +@Entity (tableName = "task_table") public class TaskModel implements Serializable { - private int id, status; + @PrimaryKey( autoGenerate = true) + private int id; + @ColumnInfo (name = "status") + private int status; + @ColumnInfo (name = "title") private String title; + @ColumnInfo (name = "desc") private String description; + @ColumnInfo (name = "priority") private String currentPriority; + @ColumnInfo (name = "date") private String currentDate; + @ColumnInfo (name = "time") private String currentTime; + @ColumnInfo (name = "editable") + private Boolean editable; public TaskModel() { } - public TaskModel(int id, int status, String title, String description, String currentPriority, String currentDate, String currentTime) { - this.id = id; + public TaskModel(int status, String title, String description, String currentPriority, String currentDate, String currentTime, Boolean editable) { this.status = status; this.title = title; this.description = description; this.currentPriority = currentPriority; this.currentDate = currentDate; this.currentTime = currentTime; + this.editable = editable; } @@ -81,4 +96,12 @@ public String getCurrentTime() { public void setCurrentTime(String currentTime) { this.currentTime = currentTime; } + + public Boolean getEditable() { + return editable; + } + + public void setEditable(Boolean editable) { + this.editable = editable; + } } diff --git a/app/src/main/java/com/example/taskmanager/ui/CompletedTaskFragment.java b/app/src/main/java/com/example/taskmanager/ui/CompletedTaskFragment.java index 8345978..51a908d 100644 --- a/app/src/main/java/com/example/taskmanager/ui/CompletedTaskFragment.java +++ b/app/src/main/java/com/example/taskmanager/ui/CompletedTaskFragment.java @@ -27,8 +27,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, TaskAdapter taskAdapter = new TaskAdapter(this); taskRecyclerView.setAdapter(taskAdapter); - TaskModel task = new TaskModel(0, 1, "Completed Task", "Dummy Task", "1", - "Deadline: 10-5-2024", "10pm"); + TaskModel task = new TaskModel(1, "Completed Task", "Dummy Task", "1", + "Deadline: 10-5-2024", "10pm", true); List tasksList = new ArrayList<>(); tasksList.add(task); diff --git a/app/src/main/java/com/example/taskmanager/ui/CurrentTasksFragment.java b/app/src/main/java/com/example/taskmanager/ui/CurrentTasksFragment.java index c3f14a7..5120a62 100644 --- a/app/src/main/java/com/example/taskmanager/ui/CurrentTasksFragment.java +++ b/app/src/main/java/com/example/taskmanager/ui/CurrentTasksFragment.java @@ -34,8 +34,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, taskAdapter = new TaskAdapter(this); taskRecyclerView.setAdapter(taskAdapter); - TaskModel task = new TaskModel(0, 0, "Test Task", "Dummy Task", "1", - "Deadline: 10-5-2024", "10pm"); + TaskModel task = new TaskModel(0, "Test Task", "Dummy Task", "1", + "Deadline: 10-5-2024", "10pm", true); tasksList = new ArrayList<>(); tasksList.add(task);