From 603f4f8731227ca722c18def8dab658e291b206f Mon Sep 17 00:00:00 2001 From: Stevdza-San Date: Thu, 28 Jul 2022 13:06:50 +0200 Subject: [PATCH] Removed Deprecated Code --- .../java/com/example/todoapp/fragments/add/AddFragment.kt | 5 ++++- .../java/com/example/todoapp/fragments/list/ListFragment.kt | 4 +++- .../com/example/todoapp/fragments/update/UpdateFragment.kt | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt b/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt index 647797c..afe793c 100644 --- a/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt +++ b/app/src/main/java/com/example/todoapp/fragments/add/AddFragment.kt @@ -7,6 +7,7 @@ import androidx.core.view.MenuHost import androidx.core.view.MenuProvider import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle import androidx.navigation.fragment.findNavController import com.example.todoapp.R import com.example.todoapp.data.models.ToDoData @@ -46,10 +47,12 @@ class AddFragment : Fragment() { override fun onMenuItemSelected(menuItem: MenuItem): Boolean { if (menuItem.itemId == R.id.menu_add) { insertDataToDb() + } else if (menuItem.itemId == android.R.id.home) { + requireActivity().onBackPressed() } return true } - }) + }, viewLifecycleOwner, Lifecycle.State.RESUMED) } private fun insertDataToDb() { diff --git a/app/src/main/java/com/example/todoapp/fragments/list/ListFragment.kt b/app/src/main/java/com/example/todoapp/fragments/list/ListFragment.kt index 9bf3d58..c5ee2ad 100644 --- a/app/src/main/java/com/example/todoapp/fragments/list/ListFragment.kt +++ b/app/src/main/java/com/example/todoapp/fragments/list/ListFragment.kt @@ -10,6 +10,7 @@ import androidx.core.view.MenuHost import androidx.core.view.MenuProvider import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.StaggeredGridLayoutManager @@ -82,10 +83,11 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener { mToDoViewModel.sortByLowPriority.observe(viewLifecycleOwner) { adapter.setData(it) } + android.R.id.home -> requireActivity().onBackPressed() } return true } - }) + }, viewLifecycleOwner, Lifecycle.State.RESUMED) } diff --git a/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt b/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt index 05c5525..f7f9fc2 100644 --- a/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt +++ b/app/src/main/java/com/example/todoapp/fragments/update/UpdateFragment.kt @@ -8,6 +8,7 @@ import androidx.core.view.MenuHost import androidx.core.view.MenuProvider import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels +import androidx.lifecycle.Lifecycle import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.example.todoapp.R @@ -52,10 +53,11 @@ class UpdateFragment : Fragment() { when (menuItem.itemId) { R.id.menu_save -> updateItem() R.id.menu_delete -> confirmItemRemoval() + android.R.id.home -> requireActivity().onBackPressed() } return true } - }) + }, viewLifecycleOwner, Lifecycle.State.RESUMED) } private fun updateItem() {