Skip to content

Commit b32ed65

Browse files
authored
Merge pull request #2038 from opensrp/fix-menu-count-anr
Fix menu count anr
2 parents 0fb7a99 + d97874b commit b32ed65

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/SideMenuOption.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.smartregister.fhircore.engine.appfeature.model.HealthModule
2424
* @property healthModule Optional healthModule property
2525
* @property iconResource Android drawable resource used as icon for menu option
2626
* @property titleResource Android translatable string resource used as the menu option title
27-
* @property count The current count for the menu item. Default is 0
27+
* @property count Gets the current count for the menu item. Default is 0
2828
* @property showCount Show clients count against the menu option queries for resources other than
2929
* Patient
3030
*/
@@ -34,6 +34,6 @@ data class SideMenuOption(
3434
val healthModule: HealthModule = HealthModule.DEFAULT,
3535
val iconResource: Int,
3636
val titleResource: Int,
37-
val count: Long = 0,
37+
val count: suspend () -> Long = suspend { 0 },
3838
val showCount: Boolean = true,
3939
)

android/quest/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ dependencies {
181181
implementation('org.smartregister:p2p-lib:0.3.0-SNAPSHOT')
182182
implementation deps.accompanist.swiperefresh
183183

184+
implementation 'com.github.anrwatchdog:anrwatchdog:1.4.0'
185+
184186
//Hilt - Dependency Injection
185187
implementation "com.google.dagger:hilt-android:$hiltVersion"
186188
kapt "com.google.dagger:hilt-compiler:$hiltVersion"

android/quest/src/main/java/org/smartregister/fhircore/quest/QuestApplication.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
2525
import androidx.lifecycle.LifecycleOwner
2626
import androidx.lifecycle.ProcessLifecycleOwner
2727
import androidx.work.Configuration
28+
import com.github.anrwatchdog.ANRWatchDog
2829
import com.google.android.fhir.datacapture.DataCaptureConfig
2930
import dagger.hilt.android.HiltAndroidApp
3031
import javax.inject.Inject
@@ -67,6 +68,10 @@ class QuestApplication :
6768

6869
override fun onCreate() {
6970
super<Application>.onCreate()
71+
72+
// Detect input timeout ANRs
73+
ANRWatchDog().start()
74+
7075
if (BuildConfig.DEBUG) {
7176
Timber.plant(Timber.DebugTree())
7277
}

android/quest/src/main/java/org/smartregister/fhircore/quest/navigation/SideMenuOptionFactory.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package org.smartregister.fhircore.quest.navigation
1818

1919
import javax.inject.Inject
2020
import javax.inject.Singleton
21-
import kotlinx.coroutines.runBlocking
2221
import org.smartregister.fhircore.engine.appfeature.AppFeature
2322
import org.smartregister.fhircore.engine.appfeature.AppFeatureManager
2423
import org.smartregister.fhircore.engine.appfeature.model.HealthModule
@@ -41,7 +40,7 @@ constructor(
4140
titleResource = R.string.all_clients,
4241
showCount = true,
4342
count =
44-
runBlocking {
43+
suspend {
4544
patientRegisterRepository.countRegisterData(
4645
appFeatureName = AppFeature.PatientManagement.name,
4746
healthModule = HealthModule.DEFAULT
@@ -81,7 +80,7 @@ constructor(
8180
},
8281
showCount = true,
8382
count =
84-
runBlocking {
83+
suspend {
8584
patientRegisterRepository.countRegisterData(
8685
appFeatureName = it.feature,
8786
healthModule = it.healthModule!!

android/quest/src/main/java/org/smartregister/fhircore/quest/ui/main/components/AppDrawer.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import androidx.compose.material.DropdownMenuItem
3838
import androidx.compose.material.Icon
3939
import androidx.compose.material.Text
4040
import androidx.compose.runtime.Composable
41+
import androidx.compose.runtime.LaunchedEffect
4142
import androidx.compose.runtime.getValue
4243
import androidx.compose.runtime.mutableStateOf
4344
import androidx.compose.runtime.remember
@@ -54,6 +55,7 @@ import androidx.compose.ui.unit.dp
5455
import androidx.compose.ui.unit.sp
5556
import androidx.navigation.NavHostController
5657
import androidx.navigation.compose.rememberNavController
58+
import kotlinx.coroutines.launch
5759
import org.smartregister.fhircore.engine.domain.model.Language
5860
import org.smartregister.fhircore.engine.domain.model.SideMenuOption
5961
import org.smartregister.fhircore.engine.ui.theme.AppTitleColor
@@ -113,10 +115,14 @@ fun AppDrawer(
113115
items(sideMenuOptions, { "${it.appFeatureName}|${it.healthModule.name}" }) { sideMenuOption
114116
->
115117
val title = stringResource(sideMenuOption.titleResource)
118+
119+
val (countValue, setCountValue) = remember { mutableStateOf(0L) }
120+
LaunchedEffect(key1 = sideMenuOption.count) { setCountValue(sideMenuOption.count()) }
121+
116122
SideMenuItem(
117123
iconResource = sideMenuOption.iconResource,
118124
title = title,
119-
endText = sideMenuOption.count.toString(),
125+
endText = countValue.toString(),
120126
showEndText = sideMenuOption.showCount,
121127
onSideMenuClick = {
122128
openDrawer(false)
@@ -270,14 +276,14 @@ fun AppDrawerPreview() {
270276
appFeatureName = "AllFamilies",
271277
iconResource = R.drawable.ic_user,
272278
titleResource = R.string.clients,
273-
count = 4,
279+
count = suspend { 4 },
274280
showCount = true,
275281
),
276282
SideMenuOption(
277283
appFeatureName = "ChildClients",
278284
iconResource = R.drawable.ic_user,
279285
titleResource = R.string.clients,
280-
count = 16,
286+
count = suspend { 16 },
281287
showCount = true
282288
),
283289
SideMenuOption(
@@ -312,14 +318,14 @@ fun AppDrawerPreviewSyncDisabled() {
312318
appFeatureName = "AllFamilies",
313319
iconResource = R.drawable.ic_user,
314320
titleResource = R.string.clients,
315-
count = 4,
321+
count = suspend { 4 },
316322
showCount = true,
317323
),
318324
SideMenuOption(
319325
appFeatureName = "ChildClients",
320326
iconResource = R.drawable.ic_user,
321327
titleResource = R.string.clients,
322-
count = 16,
328+
count = suspend { 16 },
323329
showCount = true
324330
),
325331
SideMenuOption(

0 commit comments

Comments
 (0)