Skip to content

Instantly share code, notes, and snippets.

View lucassales2's full-sized avatar

Lucas Sales lucassales2

View GitHub Profile
@lucassales2
lucassales2 / SharedPreferenceLiveData.kt
Last active August 4, 2020 13:44 — forked from rharter/SharedPreferenceLiveData.kt
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.content.SharedPreferences
import androidx.lifecycle.LiveData
abstract class SharedPreferenceLiveData<T>(
val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T
) : LiveData<T>() {
private val preferenceChangeListener =