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

Added progress indicator on Insight Screen #3484

Open
wants to merge 8 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
1 change: 1 addition & 0 deletions android/engine/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<string name="syncing_retry">Reintentar sincronización</string>
<string name="syncing_in_progress">Sincronización en curso</string>
<string name="loading">Cargando</string>
<string name="loading_ellipsis">Cargando…</string>
<string name="error_logging_out">Mensaje de error al cerrar sesión: %1$s</string>
<string name="cannot_logout_user">No se puede cerrar sesión: ya se ha cerrado sesión o el dispositivo está desconectado.</string>
<string name="error_loading_config_http_error">No se pudo cargar la configuración. Inténtalo de nuevo más tarde</string>
Expand Down
1 change: 1 addition & 0 deletions android/engine/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<string name="syncing_retry">Réessayer la synchronisation</string>
<string name="syncing_in_progress">Synchronisation en cours</string>
<string name="loading">Chargement</string>
<string name="loading_ellipsis">Chargement…</string>
<string name="error_logging_out">Message d\'erreur de déconnexion %1$s</string>
<string name="cannot_logout_user">Impossible de se déconnecter : Déjà déconnecté ou l\'appareil est hors ligne.</string>
<string name="error_loading_config_http_error">Impossible de charger la configuration. Veuillez réessayer plus tard</string>
Expand Down
1 change: 1 addition & 0 deletions android/engine/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<string name="syncing_retry">Coba lagi sinkronisasi</string>
<string name="syncing_in_progress">Sinkronisasi sedang berlangsung</string>
<string name="loading">Memuat</string>
<string name="loading_ellipsis">Memuat…</string>
<string name="error_logging_out">Pesan kesalahan logout: %1$s</string>
<string name="cannot_logout_user">Tidak dapat logout: Sudah logout atau perangkat sedang offline.</string>
<string name="error_loading_config_http_error">Tidak dapat memuat konfigurasi. Silakan coba lagi nanti</string>
Expand Down
1 change: 1 addition & 0 deletions android/engine/src/main/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="syncing_retry">Jaribu kusawazisha tena</string>
<string name="syncing_in_progress">Kusawazisha inaendelea</string>
<string name="loading">Inapakia</string>
<string name="loading_ellipsis">Inapakia…</string>
<string name="error_loading_form">Hitilafu kounyesha fomu</string>
<string name="error_saving_form">Hitilafu imetokea, haiwezi kuhifadhi fomu</string>
<string name="replace_photo">Badilisha picha</string>
Expand Down
1 change: 1 addition & 0 deletions android/engine/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<string name="syncing_retry">Retry sync</string>
<string name="syncing_in_progress">Sync in progress</string>
<string name="loading">Loading</string>
<string name="loading_ellipsis">Loading…</string>
<string name="error_logging_out">Logout error message: %1$s</string>
<string name="cannot_logout_user">Unable to logout: Already logged out or device is offline.</string>
<string name="error_loading_config_http_error">Could not load configuration. Please try again later</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.smartregister.fhircore.quest.integration.ui.usersetting

import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand All @@ -30,6 +31,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.engine.util.extension.DEFAULT_FORMAT_SDF_DD_MM_YYYY
import org.smartregister.fhircore.quest.ui.usersetting.CIRCULAR_PROGRESS_INDICATOR
import org.smartregister.fhircore.quest.ui.usersetting.INSIGHT_UNSYNCED_DATA
import org.smartregister.fhircore.quest.ui.usersetting.UserSettingInsightScreen

Expand Down Expand Up @@ -100,8 +102,19 @@ class UserSettingInsightScreenTest {
composeRule.onNodeWithTag(INSIGHT_UNSYNCED_DATA).assertDoesNotExist()
}

@Test
fun testProgressIndicatorShowWhenFetchingTheData() {
val unsyncedResources = emptyList<Pair<String, Int>>()
initComposable(
unsyncedResourcesFlow = MutableStateFlow(unsyncedResources),
showProgressIndicator = true,
)
composeRule.onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists().assertIsDisplayed()
}

private fun initComposable(
unsyncedResourcesFlow: MutableSharedFlow<List<Pair<String, Int>>> = MutableSharedFlow(),
showProgressIndicator: Boolean = false,
) {
scenario.onActivity { activity ->
activity.setContent {
Expand All @@ -118,6 +131,7 @@ class UserSettingInsightScreenTest {
buildDate = "29 jan 2023",
unsyncedResourcesFlow = unsyncedResourcesFlow,
navController = rememberNavController(),
showProgressIndicator = showProgressIndicator,
onRefreshRequest = {},
dateFormat = DEFAULT_FORMAT_SDF_DD_MM_YYYY,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -56,6 +57,8 @@ class UserInsightScreenFragment : Fragment() {
buildDate = userSettingViewModel.getBuildDate(),
unsyncedResourcesFlow = userSettingViewModel.unsyncedResourcesMutableSharedFlow,
navController = findNavController(),
showProgressIndicator =
userSettingViewModel.showProgressIndicatorFlow.collectAsState().value,
onRefreshRequest = { userSettingViewModel.fetchUnsyncedResources() },
dateFormat = userSettingViewModel.getDateFormat(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
Expand Down Expand Up @@ -77,6 +78,7 @@ import org.smartregister.fhircore.engine.util.extension.formatDate

const val USER_INSIGHT_TOP_APP_BAR = "userInsightToAppBar"
const val INSIGHT_UNSYNCED_DATA = "insightUnsyncedData"
const val CIRCULAR_PROGRESS_INDICATOR = "progressIndicator"

@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
@Composable
Expand All @@ -94,6 +96,7 @@ fun UserSettingInsightScreen(
dividerColor: Color = DividerColor,
unsyncedResourcesFlow: MutableSharedFlow<List<Pair<String, Int>>>,
navController: NavController,
showProgressIndicator: Boolean = false,
onRefreshRequest: () -> Unit,
dateFormat: String = DEFAULT_FORMAT_SDF_DD_MM_YYYY,
) {
Expand Down Expand Up @@ -123,7 +126,32 @@ fun UserSettingInsightScreen(
horizontalAlignment = Alignment.Start,
contentPadding = PaddingValues(vertical = 24.dp, horizontal = 16.dp),
) {
if (unsyncedResources.isNotEmpty()) {
if (showProgressIndicator) {
item {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth(),
) {
Text(
text = stringResource(id = R.string.loading_ellipsis),
style = TextStyle(color = Color.Black, fontSize = 20.sp),
fontWeight = FontWeight.Bold,
)
Spacer(modifier = Modifier.width(8.dp))
CircularProgressIndicator(
modifier =
Modifier.testTag(CIRCULAR_PROGRESS_INDICATOR).size(24.dp).wrapContentWidth(),
strokeWidth = 1.6.dp,
)
}
}
item {
Spacer(modifier = Modifier.height(16.dp))
Divider(color = dividerColor)
Spacer(modifier = Modifier.height(24.dp))
}
} else if (unsyncedResources.isNotEmpty()) {
item {
Text(
text = stringResource(id = R.string.unsynced_resources),
Expand Down Expand Up @@ -368,6 +396,7 @@ fun UserSettingInsightScreenPreview() {
buildDate = "29 Jan 2023",
unsyncedResourcesFlow = MutableSharedFlow(),
navController = rememberNavController(),
showProgressIndicator = true,
onRefreshRequest = {},
dateFormat = DEFAULT_FORMAT_SDF_DD_MM_YYYY,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ import org.smartregister.fhircore.engine.ui.theme.LighterBlue
import org.smartregister.fhircore.engine.ui.theme.LoginDarkColor
import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated
import org.smartregister.fhircore.engine.util.extension.appVersion
import org.smartregister.fhircore.quest.ui.pin.CIRCULAR_PROGRESS_INDICATOR

const val RESET_DATABASE_DIALOG = "resetDatabaseDialog"
const val USER_SETTING_ROW_LOGOUT = "userSettingRowLogout"
Expand Down
Loading