From b3c748edf9d8be66b0e8813b5df1bf247b111a53 Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 21 Jul 2020 14:27:50 +0200 Subject: [PATCH] Undo function on Staggered Grid layout which caused app crash is now fixed. --- .idea/vcs.xml | 6 ++++++ .../java/com/example/todoapp/fragments/list/ListFragment.kt | 5 ++--- build.gradle | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file 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 6212ae7..fbfbd23 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 @@ -72,21 +72,20 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener { mToDoViewModel.deleteItem(deletedItem) adapter.notifyItemRemoved(viewHolder.adapterPosition) // Restore Deleted Item - restoreDeletedData(viewHolder.itemView, deletedItem, viewHolder.adapterPosition) + restoreDeletedData(viewHolder.itemView, deletedItem) } } val itemTouchHelper = ItemTouchHelper(swipeToDeleteCallback) itemTouchHelper.attachToRecyclerView(recyclerView) } - private fun restoreDeletedData(view: View, deletedItem: ToDoData, position: Int) { + private fun restoreDeletedData(view: View, deletedItem: ToDoData) { val snackBar = Snackbar.make( view, "Deleted '${deletedItem.title}'", Snackbar.LENGTH_LONG ) snackBar.setAction("Undo") { mToDoViewModel.insertData(deletedItem) - adapter.notifyItemChanged(position) } snackBar.show() } diff --git a/build.gradle b/build.gradle index 2ee6591..5d3b372 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { jcenter() } dependencies { - classpath "com.android.tools.build:gradle:4.0.0" + classpath 'com.android.tools.build:gradle:4.0.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"