Skip to content

Instantly share code, notes, and snippets.

@samiuelson
samiuelson / activity_main.xml
Created May 6, 2020 12:34
Add chat list widget with translucent gradient
...
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView ... />
<!-- Translucent gradient overlay background to make chat more visible -->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bg_chat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="@+id/messagesList" />
@samiuelson
samiuelson / MyUnitTest.kt
Created April 4, 2020 11:20
Coroutines setup with org.jetbrains.kotlinx:kotlinx-coroutines-test
class MyUnitTest {
@get:Rule
val coroutineRule = TestCoroutineRule()
@Test
fun `my test executed on TestCoroutineDispatcher`() = coroutineRule.runBlockingTest {
assertEquals(42, answer())
}
}
@samiuelson
samiuelson / LifecycleAwareLazy.kt
Created September 4, 2018 15:34
Property delegate useful for Android development. Allows to declare lazily evaluated properties dependant on Activity Context and avoid memory leaks.
class LifecycleAwareLazy<T>(lifecycle: Lifecycle, private val initializer: () -> T) :
Lazy<T>, GenericLifecycleObserver {
init {
lifecycle.addObserver(this)
}
private object UNINITIALIZED_VALUE
private var _value: Any? = UNINITIALIZED_VALUE