Skip to content
Permalink
Browse files

Use .switchMap Kotlin extension for Transformations

  • Loading branch information...
ianhanniballake committed May 10, 2019
1 parent 83f133e commit 5f30277b837eb4ae33e6bad958d65ba57395ad77
@@ -18,11 +18,11 @@ package com.google.android.apps.muzei.util

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.switchMap

fun <T> LiveData<T?>.filterNotNull() : LiveData<T> {
val mutableLiveData = MutableLiveData<T>()
return Transformations.switchMap(this) { value ->
return switchMap { value ->
if (value != null) {
mutableLiveData.value = value
}
@@ -25,7 +25,7 @@ import android.os.Handler
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.switchMap
import androidx.lifecycle.viewModelScope
import com.google.android.apps.muzei.room.Artwork
import com.google.android.apps.muzei.util.ContentProviderClientCompat
@@ -103,8 +103,7 @@ class BrowseProviderViewModel(
contentUriLiveData.value = contentUri
}

val artLiveData: LiveData<List<Artwork>> = Transformations
.switchMap(contentUriLiveData) { contentUri ->
ProviderArtworkLiveData(application, viewModelScope, contentUri)
}
val artLiveData: LiveData<List<Artwork>> = contentUriLiveData.switchMap { contentUri ->
ProviderArtworkLiveData(application, viewModelScope, contentUri)
}
}

0 comments on commit 5f30277

Please sign in to comment.
You can’t perform that action at this time.