Detect when the keyboard is visible and when not.
Read more…All snippets tagged with kotlin
Page 2 of 2Soft keyboard event listener
Room type converters
Common type converters for the Room library.
Read more…Open settings activity
Start the App Settings Activity so that the user can change settings related to the application, such as permissions.
Read more…Monitor permission status
Use LiveData to determine the status of any permission (in the sample code below: the location permission). If the user grants the permission at any point, then we will get notified.
Read more…Lock an app using the phone's default lock screen
The snippets below can lock access to the app whenever the user leaves the app and comes back, with an optional timeout.
Read more…Getting the user's location
All the methods below need the location permission:
Read more…Pagination
A very complete recipe that implements a RecyclerView that pulls in paginated data, using Retrofit, LiveData. It includes example models, adapter, viewholders, and a viewholder for displaying the network state in case of an error.
Read more…Encrypted shared prefs
A class that is using the “normal” shared preferences for any device with an sdk < M and the EncryptedSharedPreferences
for M and above.
Double trigger livedata transformation
A replacement for the mediator LiveData for triggering LiveData transformations.
Read more…Simple date formatting cheatsheet
It’s date formatting string time! This is the table you need for all simple date formatting in Java/Kotlin.
Read more…Absent live data
A LiveData class that has null
value.
Okhttp 401 handler
Handle session expirations and 401 error codes. The following code will be activated if the API responds with a 401 (no authentication). If there’s a token that should be renewed, we first renew the token and if this is successful we try the original request again.
Read more…Pagination
A very complete recipe that implements a RecyclerView that pulls in paginated data, using Retrofit, LiveData. It includes example models, adapter, viewholders, and a viewholder for displaying the network state in case of an error.
Read more…Centralized error handling
Global error handling for REST requests.
Read more…Kotlin extension functions for Strings
A collection of Kotlin extension methods that simplify many common tasks related to strings.
Read more…