diff --git a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt index 38403a53a..b47335bc7 100644 --- a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt +++ b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt @@ -76,7 +76,6 @@ import io.plaidapp.core.util.AnimUtils import io.plaidapp.core.util.ColorUtils import io.plaidapp.core.util.ViewUtils import io.plaidapp.core.util.drawableToBitmap -import io.plaidapp.core.util.event.Event import io.plaidapp.core.util.intentTo import io.plaidapp.dagger.inject import io.plaidapp.ui.recyclerview.FilterTouchHelperCallback @@ -242,11 +241,10 @@ class HomeActivity : AppCompatActivity() { private fun initViewModelObservers() { viewModel.sources.observe(this@HomeActivity, Observer { filtersAdapter.submitList(it.sourceUiModels) - if (it.highlightSources != null) { - val highlightUiModel = (it.highlightSources as Event) - .consume() - if (highlightUiModel != null) { - highlightPosition(highlightUiModel) + it.highlightSources?.let { + val highlightUiModel = it.consume() + highlightUiModel?.let { + highlightPosition(it) } } }) diff --git a/core/src/main/java/io/plaidapp/core/dribbble/data/ShotsRepository.kt b/core/src/main/java/io/plaidapp/core/dribbble/data/ShotsRepository.kt index 1a8896e9e..01b49e456 100644 --- a/core/src/main/java/io/plaidapp/core/dribbble/data/ShotsRepository.kt +++ b/core/src/main/java/io/plaidapp/core/dribbble/data/ShotsRepository.kt @@ -36,16 +36,14 @@ class ShotsRepository constructor(private val remoteDataSource: SearchRemoteData } fun getShot(id: Long): Result { - val shot = shotCache[id] - return if (shot != null) { - Result.Success(shot) - } else { - Result.Error(IllegalStateException("Shot $id not cached")) + return when (val shot = shotCache[id]) { + null -> Result.Error(IllegalStateException("Shot $id not cached")) + else -> Result.Success(shot) } } private fun cache(shots: List) { - shots.associateTo(shotCache) { it.id to it } + shots.associateByTo(shotCache) { it.id } } companion object {