Skip to content

Commit

Permalink
Fix app crashing when viewing BP history (#5078)
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth authored Sep 12, 2024
1 parent 509a319 commit a454d92
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
- Bump AndroidX Paging to v3.3.1
- Bump Lottie to v6.5.0

### Fixes

- Fix app crashing when viewing BP history

## 2024-06-27-9140

### Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import androidx.paging.PagingData
import androidx.recyclerview.widget.LinearLayoutManager
import com.spotify.mobius.functions.Consumer
Expand Down Expand Up @@ -110,7 +111,10 @@ class BloodPressureHistoryScreen : BaseScreen<
override fun createUpdate() = BloodPressureHistoryScreenUpdate()

override fun createEffectHandler(viewEffectsConsumer: Consumer<BloodPressureHistoryViewEffect>) = effectHandler
.create(viewEffectsConsumer = viewEffectsConsumer)
.create(
viewEffectsConsumer = viewEffectsConsumer,
pagingCacheScope = { lifecycleScope }
)
.build()

override fun uiRenderer() = BloodPressureHistoryScreenUiRenderer(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import io.reactivex.ObservableTransformer
import io.reactivex.Scheduler
import kotlinx.coroutines.CoroutineScope
import org.simple.clinic.bp.BloodPressureHistoryListItemPagingSource
import org.simple.clinic.bp.BloodPressureRepository
import org.simple.clinic.patient.PatientRepository
import org.simple.clinic.summary.PatientSummaryConfig
import org.simple.clinic.util.PagerFactory
import org.simple.clinic.util.filterAndUnwrapJust
import org.simple.clinic.util.extractIfPresent
import org.simple.clinic.util.scheduler.SchedulersProvider

class BloodPressureHistoryScreenEffectHandler @AssistedInject constructor(
Expand All @@ -23,12 +24,14 @@ class BloodPressureHistoryScreenEffectHandler @AssistedInject constructor(
private val pagingSourceFactory: BloodPressureHistoryListItemPagingSource.Factory,
private val patientSummaryConfig: PatientSummaryConfig,
@Assisted private val viewEffectsConsumer: Consumer<BloodPressureHistoryViewEffect>,
@Assisted private val pagingCacheScope: () -> CoroutineScope
) {

@AssistedFactory
interface Factory {
fun create(
viewEffectsConsumer: Consumer<BloodPressureHistoryViewEffect>,
pagingCacheScope: () -> CoroutineScope
): BloodPressureHistoryScreenEffectHandler
}

Expand All @@ -55,6 +58,7 @@ class BloodPressureHistoryScreenEffectHandler @AssistedInject constructor(
source = pagingSource,
)
},
cacheScope = pagingCacheScope.invoke(),
)
}
.map(::BloodPressuresHistoryLoaded)
Expand All @@ -72,7 +76,7 @@ class BloodPressureHistoryScreenEffectHandler @AssistedInject constructor(
.take(1)
.subscribeOn(scheduler)
}
.filterAndUnwrapJust()
.extractIfPresent()
.map(::PatientLoaded)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.simple.clinic.bp.history

import androidx.paging.PagingData
import io.reactivex.Observable
import kotlinx.coroutines.test.TestScope
import org.junit.After
import org.junit.Test
import org.mockito.kotlin.any
Expand Down Expand Up @@ -36,6 +37,7 @@ class BloodPressureHistoryScreenEffectHandlerTest {
private val uiActions = mock<BloodPressureHistoryScreenUiActions>()
private val viewEffectHandler = BloodPressureHistoryViewEffectHandler(uiActions)
private val pagerFactory = mock<PagerFactory>()
private val pagingCacheScope = TestScope()
private val effectHandler = BloodPressureHistoryScreenEffectHandler(
bloodPressureRepository,
patientRepository,
Expand All @@ -46,7 +48,8 @@ class BloodPressureHistoryScreenEffectHandlerTest {
bpEditableDuration = Duration.ofMinutes(10),
numberOfMeasurementsForTeleconsultation = 0,
),
viewEffectHandler::handle
viewEffectsConsumer = viewEffectHandler::handle,
pagingCacheScope = { pagingCacheScope }
).build()
private val testCase = EffectHandlerTestCase(effectHandler)

Expand Down Expand Up @@ -148,7 +151,7 @@ class BloodPressureHistoryScreenEffectHandlerTest {
pageSize = eq(25),
enablePlaceholders = eq(false),
initialKey = eq(null),
cacheScope = eq(null),
cacheScope = eq(pagingCacheScope),
)) doReturn Observable.just(bloodPressures)

// when
Expand Down

0 comments on commit a454d92

Please sign in to comment.