All snippets tagged with kotlin

Page 2 of 2
 

Soft keyboard event listener

Room type converters

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

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

Double trigger livedata transformation

Simple date formatting cheatsheet

Absent live data

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

Kotlin extension functions for Strings