Application Design Patterns

How to delete a record from Firestore on a RecyclerView left or right swipe?

Alex Mamo
Firebase Developers
3 min readNov 5, 2020

--

When you want to delete a record from Cloud Firestore, you want to do it fast. So there are a few gestures that can help us achieve that. We can swipe, we can long-press on an item, or even use multiple item selections.

In this article, I will show you how can we delete a record, on a RecyclerView item left/right swipe.

I will use the latest technologies that are recommended by the Android team. I will use the MVVM Architecture Pattern with LiveData and ViewModel. For the asynchronous calls to Firestore, I will also use Kotlin Coroutines, for dependency injection I will use Hilt for Android, and for binding the UI components in the layouts I will use data binding. The database on which we are working has the following structure:

Because the result of a Firestore database call will always return either the data or an Exception, we’ll use a generic data class that looks like this:

data class DataOrException<T, E : Exception?>(
var data: T? = null,
var e: E? = null
)

--

--