From 88dca4aa5ecdb428e7e8d8b048a45fae40766c16 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:09:13 +0000
Subject: [PATCH 01/13] readme update
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index 33148ab..58c01bb 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,10 @@
Todo - a task management application built for Android
+## Details
+
+Todo is a basic task manager/todo list built for Android. It is built using Kotlin, MVVM / Clean Architecture, Fragments, Dagger & Hilt, with Firebase for the backend (Authentication & Firestore).
+
## References
[Android Architecture Documentation](https://developer.android.com/topic/architecture)
From 39918b4df37f70ea29027f7000b22c2160eac244 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:11:44 +0000
Subject: [PATCH 02/13] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 58c01bb..4ab1367 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ Todo - a task management application built for Android
## Details
-Todo is a basic task manager/todo list built for Android. It is built using Kotlin, MVVM / Clean Architecture, Fragments, Dagger & Hilt, with Firebase for the backend (Authentication & Firestore).
+Todo is a basic task manager/todo list built for Android. It is built using Kotlin, MVVM / Clean Architecture, Fragments, Dagger & Hilt, with Firebase for the backend (Authentication & Firestore). The interface is built with Material 3 and uses the system preference to determine light/dark mode.
## References
From 28c03aa1322bf0da102ff1e2bbd4af914c8943fd Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sat, 26 Nov 2022 23:18:14 +0000
Subject: [PATCH 03/13] fix forgot password location when keyboard is open
---
app/src/main/res/layout/fragment_login.xml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/app/src/main/res/layout/fragment_login.xml b/app/src/main/res/layout/fragment_login.xml
index 0568bde..cc69e90 100644
--- a/app/src/main/res/layout/fragment_login.xml
+++ b/app/src/main/res/layout/fragment_login.xml
@@ -79,8 +79,7 @@
android:text="@string/forgot_password"
android:paddingTop="4dp"
android:paddingBottom="4dp"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/login"
- app:layout_constraintTop_toTopOf="@id/login"
+ app:layout_constraintTop_toBottomOf="@id/login"
app:layout_constraintVertical_bias="0.11" />
\ No newline at end of file
From 45de58012a63de912a7bcab5ca7a3ac5190a6574 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 11:29:02 +0000
Subject: [PATCH 04/13] add priority to task
---
.../dev/jord/todo/ui/home/AddTaskFragment.kt | 17 ++++++++-----
app/src/main/res/layout/dropdown_item.xml | 8 ++++++
app/src/main/res/layout/fragment_add_task.xml | 25 ++++++++++++++++++-
app/src/main/res/values/strings.xml | 14 +++++------
4 files changed, 49 insertions(+), 15 deletions(-)
create mode 100644 app/src/main/res/layout/dropdown_item.xml
diff --git a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
index f7c780b..8b56219 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
@@ -5,6 +5,7 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.ArrayAdapter
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
@@ -37,13 +38,17 @@ class AddTaskFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentAddTaskBinding.bind(view)
+
+ val priorityArray = resources.getStringArray(R.array.priority)
+ val arrayAdapter = activity?.let { ArrayAdapter(it, R.layout.dropdown_item, priorityArray) }
+ binding.priorityDropdown.setAdapter(arrayAdapter)
+
binding.addTaskButton.setOnClickListener {
- viewModel.addTask(
- Task(
- title = binding.taskName.text.toString(),
- description = binding.taskDescription.text.toString()
- )
- )
+ val title = binding.taskName.text.toString()
+ val description = binding.taskDescription.text.toString()
+ val priority = binding.priorityDropdown.text.toString()
+ val task = Task(title = title, description = description, priority = priority)
+ viewModel.addTask(task)
snackbar("Task added successfully!")
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.container, HomeFragment())
diff --git a/app/src/main/res/layout/dropdown_item.xml b/app/src/main/res/layout/dropdown_item.xml
new file mode 100644
index 0000000..37f941a
--- /dev/null
+++ b/app/src/main/res/layout/dropdown_item.xml
@@ -0,0 +1,8 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_add_task.xml b/app/src/main/res/layout/fragment_add_task.xml
index 48c6600..ea8b573 100644
--- a/app/src/main/res/layout/fragment_add_task.xml
+++ b/app/src/main/res/layout/fragment_add_task.xml
@@ -43,6 +43,29 @@
android:layout_height="wrap_content" />
+
+
+
+ />
+
+
+
+ app:layout_constraintTop_toBottomOf="@+id/priorityMenu" />
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d48430e..44e7d05 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -20,14 +20,12 @@
Join Todo
Next
Previous
-
- Hello blank fragment
New Task
LoginActivity
-
- First Fragment
- Second Fragment
-
- Hello first fragment
- Hello second fragment. Arg: %1$s
+ Hello Blank Fragment
+
+ - Low
+ - Medium
+ - High
+
\ No newline at end of file
From 6c265a0920e59a8219ba24d9974be2e6dcf8361a Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 13:09:52 +0000
Subject: [PATCH 05/13] priority color
---
.../java/dev/jord/todo/ui/home/TaskAdapter.kt | 20 ++++++++++++++-----
app/src/main/res/layout/task_list_item.xml | 12 +++--------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt b/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
index bcd2842..2c2c47b 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
@@ -1,8 +1,12 @@
package dev.jord.todo.ui.home
+import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
+import androidx.appcompat.content.res.AppCompatResources
import androidx.recyclerview.widget.RecyclerView
+import com.google.android.material.color.MaterialColors
+import dev.jord.todo.R
import dev.jord.todo.data.model.Task
import dev.jord.todo.databinding.TaskListItemBinding
@@ -36,12 +40,18 @@ class TaskAdapter(
fun bind(task: Task) {
binding.taskTitle.text = task.title
binding.taskDescription.text = task.description
- if(task.completed) {
- binding.taskStatus.text = "Done"
- } else {
- binding.taskStatus.text = "To do"
- }
binding.taskPriority.text = task.priority
+ when (task.priority) {
+ "Low" -> {
+ binding.taskPriority.setTextColor(Color.parseColor("#4ea832"))
+ }
+ "Medium" -> {
+ binding.taskPriority.setTextColor(Color.parseColor("#de891b"))
+ }
+ "High" -> {
+ binding.taskPriority.setTextColor(Color.parseColor("#de1b1b"))
+ }
+ }
binding.taskDueDate.text = task.dueDate
binding.taskLocation.text = task.location
binding.doneButton.setOnClickListener {
diff --git a/app/src/main/res/layout/task_list_item.xml b/app/src/main/res/layout/task_list_item.xml
index 4e2ff23..69d5ba2 100644
--- a/app/src/main/res/layout/task_list_item.xml
+++ b/app/src/main/res/layout/task_list_item.xml
@@ -51,19 +51,11 @@
android:layout_height="wrap_content"
android:orientation="horizontal">
-
-
Date: Sun, 27 Nov 2022 13:26:45 +0000
Subject: [PATCH 06/13] due date on task
---
.../dev/jord/todo/ui/home/AddTaskFragment.kt | 15 +++++++++++-
app/src/main/res/layout/fragment_add_task.xml | 23 ++++++++++++++++++-
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
index 8b56219..042cede 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
@@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.viewModels
+import com.google.android.material.datepicker.MaterialDatePicker
import dagger.hilt.android.AndroidEntryPoint
import dev.jord.todo.R
import dev.jord.todo.data.model.Task
@@ -43,11 +44,23 @@ class AddTaskFragment : Fragment() {
val arrayAdapter = activity?.let { ArrayAdapter(it, R.layout.dropdown_item, priorityArray) }
binding.priorityDropdown.setAdapter(arrayAdapter)
+ val datePicker =
+ MaterialDatePicker.Builder.datePicker()
+ .setTitleText("Select date")
+ .build()
+ binding.dueDateDropdown.setOnClickListener {
+ datePicker.show(childFragmentManager, "DATE_PICKER")
+ }
+ datePicker.addOnPositiveButtonClickListener {
+ binding.dueDateDropdown.setText(datePicker.headerText)
+ }
+
binding.addTaskButton.setOnClickListener {
val title = binding.taskName.text.toString()
val description = binding.taskDescription.text.toString()
val priority = binding.priorityDropdown.text.toString()
- val task = Task(title = title, description = description, priority = priority)
+ val date = binding.dueDateDropdown.text.toString()
+ val task = Task(title = title, description = description, priority = priority, dueDate = date)
viewModel.addTask(task)
snackbar("Task added successfully!")
activity?.supportFragmentManager?.beginTransaction()
diff --git a/app/src/main/res/layout/fragment_add_task.xml b/app/src/main/res/layout/fragment_add_task.xml
index ea8b573..49d1f44 100644
--- a/app/src/main/res/layout/fragment_add_task.xml
+++ b/app/src/main/res/layout/fragment_add_task.xml
@@ -63,7 +63,28 @@
android:inputType="none"
tools:text="Low" />
/>
+
+
+
+
+ />
+ app:layout_constraintTop_toBottomOf="@+id/dueDateMenu" />
\ No newline at end of file
From 99d880d86fdcedfe3135e85fe17ef5bb726b240a Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 13:36:00 +0000
Subject: [PATCH 07/13] remove default text & add location menu (non
functional)
---
app/src/main/res/layout/fragment_add_task.xml | 29 +++++++++++++++----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/app/src/main/res/layout/fragment_add_task.xml b/app/src/main/res/layout/fragment_add_task.xml
index 49d1f44..b2d40c6 100644
--- a/app/src/main/res/layout/fragment_add_task.xml
+++ b/app/src/main/res/layout/fragment_add_task.xml
@@ -60,8 +60,7 @@
android:id="@+id/priorityDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:inputType="none"
- tools:text="Low" />
+ android:inputType="none" />
/>
@@ -82,8 +81,28 @@
android:id="@+id/dueDateDropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:inputType="none"
- tools:text="Today" />
+ android:inputType="none" />
+ />
+
+
+
+
+
/>
@@ -97,6 +116,6 @@
android:text="Add Task"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/dueDateMenu" />
+ app:layout_constraintTop_toBottomOf="@+id/locationMenu" />
\ No newline at end of file
From 810b4f38ac66ac26c486124f413966abe03df180 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 14:34:07 +0000
Subject: [PATCH 08/13] add location (text input)
---
app/src/main/AndroidManifest.xml | 4 ++--
app/src/main/java/dev/jord/todo/MainActivity.kt | 13 -------------
.../java/dev/jord/todo/ui/home/AddTaskFragment.kt | 5 ++---
app/src/main/res/layout/fragment_add_task.xml | 8 +++-----
4 files changed, 7 insertions(+), 23 deletions(-)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 32a8004..5a34199 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -18,13 +18,13 @@
tools:targetApi="31">
diff --git a/app/src/main/java/dev/jord/todo/MainActivity.kt b/app/src/main/java/dev/jord/todo/MainActivity.kt
index 6a213b2..312ee3d 100644
--- a/app/src/main/java/dev/jord/todo/MainActivity.kt
+++ b/app/src/main/java/dev/jord/todo/MainActivity.kt
@@ -3,29 +3,16 @@ package dev.jord.todo
import android.content.Intent
import android.os.Bundle
import android.view.Menu
-import android.view.View
-import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat
import androidx.fragment.app.Fragment
-import androidx.fragment.app.viewModels
-import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
-import androidx.navigation.ui.navigateUp
-import androidx.navigation.ui.setupActionBarWithNavController
import com.google.firebase.auth.ktx.auth
import com.google.firebase.ktx.Firebase
import dagger.hilt.android.AndroidEntryPoint
import dev.jord.todo.databinding.ActivityMainBinding
import dev.jord.todo.ui.account.AccountFragment
-import dev.jord.todo.ui.auth.AuthViewModel
-import dev.jord.todo.ui.auth.LoginFragment
-import dev.jord.todo.ui.auth.WelcomeFragment
import dev.jord.todo.ui.home.HomeFragment
-import dev.jord.todo.util.UiState
-import dev.jord.todo.util.hide
-import dev.jord.todo.util.show
-import dev.jord.todo.util.snackbar
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
diff --git a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
index 042cede..2b42956 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
@@ -13,8 +13,6 @@ import dagger.hilt.android.AndroidEntryPoint
import dev.jord.todo.R
import dev.jord.todo.data.model.Task
import dev.jord.todo.databinding.FragmentAddTaskBinding
-import dev.jord.todo.databinding.FragmentForgotPasswordBinding
-import dev.jord.todo.ui.auth.AuthViewModel
import dev.jord.todo.util.snackbar
@AndroidEntryPoint
@@ -60,7 +58,8 @@ class AddTaskFragment : Fragment() {
val description = binding.taskDescription.text.toString()
val priority = binding.priorityDropdown.text.toString()
val date = binding.dueDateDropdown.text.toString()
- val task = Task(title = title, description = description, priority = priority, dueDate = date)
+ val location = binding.locationTextField.text.toString()
+ val task = Task(title = title, description = description, priority = priority, dueDate = date, location = location)
viewModel.addTask(task)
snackbar("Task added successfully!")
activity?.supportFragmentManager?.beginTransaction()
diff --git a/app/src/main/res/layout/fragment_add_task.xml b/app/src/main/res/layout/fragment_add_task.xml
index b2d40c6..da700bf 100644
--- a/app/src/main/res/layout/fragment_add_task.xml
+++ b/app/src/main/res/layout/fragment_add_task.xml
@@ -87,7 +87,6 @@
-
+ android:layout_height="wrap_content" />
/>
From d772377e993d2d631d528528292af8288118924f Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 14:34:51 +0000
Subject: [PATCH 09/13] change soft input mode
---
app/src/main/AndroidManifest.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5a34199..6a24a23 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -18,7 +18,7 @@
tools:targetApi="31">
From d0bd8cddcda41693f21cb44c5131834f34e0f647 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 15:35:23 +0000
Subject: [PATCH 10/13] add edit task fragment
---
.../dev/jord/todo/ui/home/EditTaskFragment.kt | 33 +++++
.../dev/jord/todo/ui/home/HomeFragment.kt | 9 +-
.../java/dev/jord/todo/ui/home/TaskAdapter.kt | 4 +
.../main/res/layout/fragment_edit_task.xml | 119 ++++++++++++++++++
4 files changed, 164 insertions(+), 1 deletion(-)
create mode 100644 app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
create mode 100644 app/src/main/res/layout/fragment_edit_task.xml
diff --git a/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
new file mode 100644
index 0000000..97b2335
--- /dev/null
+++ b/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
@@ -0,0 +1,33 @@
+package dev.jord.todo.ui.home
+
+import android.os.Bundle
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import dev.jord.todo.R
+
+class EditTaskFragment : Fragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ // Inflate the layout for this fragment
+ return inflater.inflate(R.layout.fragment_edit_task, container, false)
+
+ }
+
+ companion object {
+ @JvmStatic
+ fun newInstance(param1: String, param2: String) =
+ EditTaskFragment().apply {
+ arguments = Bundle().apply {
+ }
+ }
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
index 342bef4..c58af69 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
@@ -27,7 +27,8 @@ class HomeFragment : Fragment() {
val adapter by lazy {
TaskAdapter(
donePressed = { task -> donePressed(task) },
- deletePressed = { task -> deletePressed(task) }
+ deletePressed = { task -> deletePressed(task) },
+ editPressed = { task -> editPressed(task) }
)
}
private var taskList = mutableListOf()
@@ -135,4 +136,10 @@ class HomeFragment : Fragment() {
?.replace(R.id.container, HomeFragment())
?.commit();
}
+
+ private fun editPressed(task: Task) {
+ activity?.supportFragmentManager?.beginTransaction()
+ ?.replace(R.id.container, EditTaskFragment())
+ ?.commit();
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt b/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
index 2c2c47b..b40474e 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/TaskAdapter.kt
@@ -12,6 +12,7 @@ import dev.jord.todo.databinding.TaskListItemBinding
class TaskAdapter(
val donePressed: ((Task) -> Unit)? = null,
+ val editPressed: ((Task) -> Unit)? = null,
val deletePressed: ((Task) -> Unit)? = null
): RecyclerView.Adapter() {
@@ -57,6 +58,9 @@ class TaskAdapter(
binding.doneButton.setOnClickListener {
donePressed?.invoke(task)
}
+ binding.editButton.setOnClickListener {
+ editPressed?.invoke(task)
+ }
binding.deleteButton.setOnClickListener {
deletePressed?.invoke(task)
}
diff --git a/app/src/main/res/layout/fragment_edit_task.xml b/app/src/main/res/layout/fragment_edit_task.xml
new file mode 100644
index 0000000..b461b04
--- /dev/null
+++ b/app/src/main/res/layout/fragment_edit_task.xml
@@ -0,0 +1,119 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ />
+
+
+
+
+
+ />
+
+
+
+
+
+ />
+
+
+
+
+
\ No newline at end of file
From c75fc4a4e37cc1f85a74f98378f00086fd39ea57 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Sun, 27 Nov 2022 21:15:33 +0000
Subject: [PATCH 11/13] type changes
---
.../todo/data/repository/TaskRepository.kt | 2 +-
.../TaskRepositoryImplementation.kt | 4 +-
.../dev/jord/todo/ui/home/EditTaskFragment.kt | 39 +++++++++++++------
3 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/dev/jord/todo/data/repository/TaskRepository.kt b/app/src/main/java/dev/jord/todo/data/repository/TaskRepository.kt
index 9bfe878..ebf1b27 100644
--- a/app/src/main/java/dev/jord/todo/data/repository/TaskRepository.kt
+++ b/app/src/main/java/dev/jord/todo/data/repository/TaskRepository.kt
@@ -8,7 +8,7 @@ interface TaskRepository {
fun addTask(task: Task, result: (UiState>) -> Unit)
fun updateTask(task: Task, result: (UiState>) -> Unit)
fun deleteTask(task: Task, result: (UiState>) -> Unit)
- fun getTask(id: String, result: (UiState) -> Unit)
+ fun getTask(id: String, result: (UiState>) -> Unit)
fun getTasks(user: User?, result: (UiState>) -> Unit)
fun storeTasks(tasks: List, result: (UiState) -> Unit)
}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jord/todo/data/repository/TaskRepositoryImplementation.kt b/app/src/main/java/dev/jord/todo/data/repository/TaskRepositoryImplementation.kt
index 97f9339..47d00e1 100644
--- a/app/src/main/java/dev/jord/todo/data/repository/TaskRepositoryImplementation.kt
+++ b/app/src/main/java/dev/jord/todo/data/repository/TaskRepositoryImplementation.kt
@@ -70,7 +70,7 @@ class TaskRepositoryImplementation @Inject constructor(
}
}
- override fun getTask(id: String, result: (UiState) -> Unit) {
+ override fun getTask(id: String, result: (UiState>) -> Unit) {
database.collection(FireStoreCollection.TASKS)
.document(auth.currentUser?.uid ?: "")
.collection(FireStoreCollection.TASKS)
@@ -79,7 +79,7 @@ class TaskRepositoryImplementation @Inject constructor(
.addOnSuccessListener {
val task = it.toObject(Task::class.java)
if(task != null) {
- result.invoke(UiState.Success(task.id))
+ result.invoke(UiState.Success(Pair(task, "Task deleted successfully!")))
} else {
result.invoke(UiState.Failure("Task not found!"))
}
diff --git a/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
index 97b2335..f73f0e6 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
@@ -5,29 +5,46 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.fragment.app.setFragmentResultListener
+import androidx.fragment.app.viewModels
+import dagger.hilt.android.AndroidEntryPoint
import dev.jord.todo.R
+import dev.jord.todo.data.model.Task
+import dev.jord.todo.databinding.FragmentEditTaskBinding
+import dev.jord.todo.databinding.FragmentHomeBinding
+import dev.jord.todo.util.UiState
+import dev.jord.todo.util.snackbar
+@AndroidEntryPoint
class EditTaskFragment : Fragment() {
+ private lateinit var binding: FragmentEditTaskBinding
+ private val viewModel: TaskViewModel by viewModels()
+
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
- // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_edit_task, container, false)
-
- }
-
- companion object {
- @JvmStatic
- fun newInstance(param1: String, param2: String) =
- EditTaskFragment().apply {
- arguments = Bundle().apply {
- }
- }
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
+ binding = FragmentEditTaskBinding.bind(view)
+ }
+
+ private fun observer() {
+ viewModel.getTask.observe(viewLifecycleOwner) { state ->
+ when (state) {
+ is UiState.Success -> {
+ snackbar(state.data.toString())
+ }
+ is UiState.Failure -> {
+ }
+ is UiState.Loading -> {
+ }
+ else -> {}
+ }
}
+ }
}
\ No newline at end of file
From 593a13f25f19e17b4ac0234807eb32fe512a5c68 Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Mon, 28 Nov 2022 18:49:54 +0000
Subject: [PATCH 12/13] fix data type
---
app/src/main/java/dev/jord/todo/ui/home/TaskViewModel.kt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/dev/jord/todo/ui/home/TaskViewModel.kt b/app/src/main/java/dev/jord/todo/ui/home/TaskViewModel.kt
index a83f40d..8ec2fe8 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/TaskViewModel.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/TaskViewModel.kt
@@ -31,8 +31,8 @@ class TaskViewModel @Inject constructor(
private val _storeTasks = MutableLiveData>()
val storeTasks: LiveData>
get() = _storeTasks
- private val _getTask = MutableLiveData>()
- val getTask: LiveData>
+ private val _getTask = MutableLiveData>>()
+ val getTask: LiveData>>
get() = _getTask
private val _getTasks = MutableLiveData>>()
val getTasks: MutableLiveData>>
From dc44568438a5f9554290c24e3c5072e02a9d597f Mon Sep 17 00:00:00 2001
From: Jordan Harrison <76656637+jordharr@users.noreply.github.com>
Date: Mon, 28 Nov 2022 19:29:26 +0000
Subject: [PATCH 13/13] edit task feature with bottom sheet
---
.../dev/jord/todo/ui/home/AddTaskFragment.kt | 33 ++++-
.../dev/jord/todo/ui/home/EditTaskFragment.kt | 50 --------
.../dev/jord/todo/ui/home/HomeFragment.kt | 12 +-
app/src/main/res/layout/fragment_add_task.xml | 2 +-
.../main/res/layout/fragment_edit_task.xml | 119 ------------------
5 files changed, 40 insertions(+), 176 deletions(-)
delete mode 100644 app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
delete mode 100644 app/src/main/res/layout/fragment_edit_task.xml
diff --git a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
index 2b42956..b61c2b4 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/AddTaskFragment.kt
@@ -8,19 +8,23 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.viewModels
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.datepicker.MaterialDatePicker
import dagger.hilt.android.AndroidEntryPoint
import dev.jord.todo.R
import dev.jord.todo.data.model.Task
import dev.jord.todo.databinding.FragmentAddTaskBinding
+import dev.jord.todo.ui.auth.AuthViewModel
import dev.jord.todo.util.snackbar
@AndroidEntryPoint
-class AddTaskFragment : Fragment() {
+class AddTaskFragment(private val task: Task? = null) : BottomSheetDialogFragment() {
val TAG: String = "AddTaskFragment"
lateinit var binding: FragmentAddTaskBinding
+ var closeFunction: ((Boolean) -> Unit)? = null
val viewModel: TaskViewModel by viewModels()
+ val authViewModel: AuthViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -38,6 +42,14 @@ class AddTaskFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
binding = FragmentAddTaskBinding.bind(view)
+ task?.let {
+ binding.taskName.setText(it.title)
+ binding.taskDescription.setText(it.description)
+ binding.dueDateDropdown.setText(it.dueDate)
+ binding.priorityDropdown.setText(it.priority)
+ binding.locationTextField.setText(it.location)
+ }
+
val priorityArray = resources.getStringArray(R.array.priority)
val arrayAdapter = activity?.let { ArrayAdapter(it, R.layout.dropdown_item, priorityArray) }
binding.priorityDropdown.setAdapter(arrayAdapter)
@@ -60,8 +72,11 @@ class AddTaskFragment : Fragment() {
val date = binding.dueDateDropdown.text.toString()
val location = binding.locationTextField.text.toString()
val task = Task(title = title, description = description, priority = priority, dueDate = date, location = location)
- viewModel.addTask(task)
- snackbar("Task added successfully!")
+ if (validation()) {
+ viewModel.addTask(task)
+ }else {
+ viewModel.updateTask(task)
+ }
activity?.supportFragmentManager?.beginTransaction()
?.replace(R.id.container, HomeFragment())
?.commit();
@@ -71,4 +86,16 @@ class AddTaskFragment : Fragment() {
override fun onDestroyView() {
super.onDestroyView()
}
+
+ private fun validation(): Boolean {
+ var isValid = true
+ if (binding.taskName.text.toString().isEmpty()) {
+ isValid = false
+ }
+ return isValid
+ }
+
+ fun setDismissListener(function: ((Boolean) -> Unit)?) {
+ closeFunction = function
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
deleted file mode 100644
index f73f0e6..0000000
--- a/app/src/main/java/dev/jord/todo/ui/home/EditTaskFragment.kt
+++ /dev/null
@@ -1,50 +0,0 @@
-package dev.jord.todo.ui.home
-
-import android.os.Bundle
-import androidx.fragment.app.Fragment
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.fragment.app.setFragmentResultListener
-import androidx.fragment.app.viewModels
-import dagger.hilt.android.AndroidEntryPoint
-import dev.jord.todo.R
-import dev.jord.todo.data.model.Task
-import dev.jord.todo.databinding.FragmentEditTaskBinding
-import dev.jord.todo.databinding.FragmentHomeBinding
-import dev.jord.todo.util.UiState
-import dev.jord.todo.util.snackbar
-
-@AndroidEntryPoint
-class EditTaskFragment : Fragment() {
-
- private lateinit var binding: FragmentEditTaskBinding
- private val viewModel: TaskViewModel by viewModels()
-
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- return inflater.inflate(R.layout.fragment_edit_task, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- binding = FragmentEditTaskBinding.bind(view)
- }
-
- private fun observer() {
- viewModel.getTask.observe(viewLifecycleOwner) { state ->
- when (state) {
- is UiState.Success -> {
- snackbar(state.data.toString())
- }
- is UiState.Failure -> {
- }
- is UiState.Loading -> {
- }
- else -> {}
- }
- }
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt b/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
index c58af69..2bd41a8 100644
--- a/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
+++ b/app/src/main/java/dev/jord/todo/ui/home/HomeFragment.kt
@@ -138,8 +138,14 @@ class HomeFragment : Fragment() {
}
private fun editPressed(task: Task) {
- activity?.supportFragmentManager?.beginTransaction()
- ?.replace(R.id.container, EditTaskFragment())
- ?.commit();
+ val addTaskFragmentSheet = AddTaskFragment(task)
+ addTaskFragmentSheet.setDismissListener {
+ if (it) {
+ authViewModel.getSession {
+ viewModel.getTasks(it)
+ }
+ }
+ }
+ addTaskFragmentSheet.show(childFragmentManager,"create_task")
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_add_task.xml b/app/src/main/res/layout/fragment_add_task.xml
index da700bf..9a5936c 100644
--- a/app/src/main/res/layout/fragment_add_task.xml
+++ b/app/src/main/res/layout/fragment_add_task.xml
@@ -111,7 +111,7 @@
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
- android:text="Add Task"
+ android:text="Save Task"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/locationMenu" />
diff --git a/app/src/main/res/layout/fragment_edit_task.xml b/app/src/main/res/layout/fragment_edit_task.xml
deleted file mode 100644
index b461b04..0000000
--- a/app/src/main/res/layout/fragment_edit_task.xml
+++ /dev/null
@@ -1,119 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- />
-
-
-
-
-
- />
-
-
-
-
-
- />
-
-
-
-
-
\ No newline at end of file