Skip to content

Instantly share code, notes, and snippets.

View mehdisamavat's full-sized avatar
🎯
Focusing

Mehdi mehdisamavat

🎯
Focusing
View GitHub Profile
@mehdisamavat
mehdisamavat / SnappyRecyclerView.java
Created June 21, 2023 23:04 — forked from nesquena/SnappyRecyclerView.java
Snap-to-Center RecyclerView Extension
// From: http://stackoverflow.com/a/37816976
public class SnappyRecyclerView extends RecyclerView {
// Use it with a horizontal LinearLayoutManager
// Based on http://stackoverflow.com/a/29171652/4034572
public SnappyRecyclerView(Context context) {
super(context);
}
@mehdisamavat
mehdisamavat / PreferenceExtensions.kt
Created February 1, 2023 17:17 — forked from ologe/PreferenceExtensions.kt
Android shared preference observer using kotlin coroutines (1.3.0)
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> {
val flow = MutableStateFlow(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
flow.value = getItem(key, default)!!
}
}
registerOnSharedPreferenceChangeListener(listener)