Undo function on Staggered Grid layout which caused app crash is now fixed.

This commit is contained in:
Stefan 2020-07-21 14:27:50 +02:00
parent d0280cc437
commit b3c748edf9
3 changed files with 9 additions and 4 deletions

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -72,21 +72,20 @@ class ListFragment : Fragment(), SearchView.OnQueryTextListener {
mToDoViewModel.deleteItem(deletedItem) mToDoViewModel.deleteItem(deletedItem)
adapter.notifyItemRemoved(viewHolder.adapterPosition) adapter.notifyItemRemoved(viewHolder.adapterPosition)
// Restore Deleted Item // Restore Deleted Item
restoreDeletedData(viewHolder.itemView, deletedItem, viewHolder.adapterPosition) restoreDeletedData(viewHolder.itemView, deletedItem)
} }
} }
val itemTouchHelper = ItemTouchHelper(swipeToDeleteCallback) val itemTouchHelper = ItemTouchHelper(swipeToDeleteCallback)
itemTouchHelper.attachToRecyclerView(recyclerView) itemTouchHelper.attachToRecyclerView(recyclerView)
} }
private fun restoreDeletedData(view: View, deletedItem: ToDoData, position: Int) { private fun restoreDeletedData(view: View, deletedItem: ToDoData) {
val snackBar = Snackbar.make( val snackBar = Snackbar.make(
view, "Deleted '${deletedItem.title}'", view, "Deleted '${deletedItem.title}'",
Snackbar.LENGTH_LONG Snackbar.LENGTH_LONG
) )
snackBar.setAction("Undo") { snackBar.setAction("Undo") {
mToDoViewModel.insertData(deletedItem) mToDoViewModel.insertData(deletedItem)
adapter.notifyItemChanged(position)
} }
snackBar.show() snackBar.show()
} }

View File

@ -11,7 +11,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { 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 "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"