Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimized code in some places #838

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions app/src/main/java/io/plaidapp/ui/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -242,11 +241,10 @@ class HomeActivity : AppCompatActivity() {
private fun initViewModelObservers() {
viewModel.sources.observe(this@HomeActivity, Observer<SourcesUiModel> {
filtersAdapter.submitList(it.sourceUiModels)
if (it.highlightSources != null) {
val highlightUiModel = (it.highlightSources as Event<SourcesHighlightUiModel>)
.consume()
if (highlightUiModel != null) {
highlightPosition(highlightUiModel)
it.highlightSources?.let {
val highlightUiModel = it.consume()
highlightUiModel?.let {
highlightPosition(it)
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ class ShotsRepository constructor(private val remoteDataSource: SearchRemoteData
}

fun getShot(id: Long): Result<Shot> {
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<Shot>) {
shots.associateTo(shotCache) { it.id to it }
shots.associateByTo(shotCache) { it.id }
}

companion object {
Expand Down