From 4fc18878f0f35fb6789a966a9dca7afd49759603 Mon Sep 17 00:00:00 2001 From: AbdulWahabMemon Date: Mon, 22 Jul 2024 22:05:46 +0500 Subject: [PATCH] Display data migration in settings (#3079) * display data-migration-version in User Settings Page * resolve error after main build success * merge main * changes as per reviewer feedback * Fix failing tests Signed-off-by: Elly Kitoto --------- Signed-off-by: Elly Kitoto Co-authored-by: Elly Kitoto --- .../engine/src/main/res/values-fr/strings.xml | 1 + .../engine/src/main/res/values-in/strings.xml | 1 + .../engine/src/main/res/values-sw/strings.xml | 1 + .../engine/src/main/res/values/strings.xml | 1 + .../ui/usersetting/UserSettingScreenTest.kt | 1 + .../ui/usersetting/UserSettingFragment.kt | 1 + .../quest/ui/usersetting/UserSettingScreen.kt | 19 +++++++++++++++---- .../ui/usersetting/UserSettingViewModel.kt | 8 ++++++++ .../UserInsightScreenFragmentTest.kt | 4 ++++ .../ui/usersetting/UserSettingFragmentTest.kt | 4 ++++ .../usersetting/UserSettingViewModelTest.kt | 3 +++ 11 files changed, 40 insertions(+), 4 deletions(-) diff --git a/android/engine/src/main/res/values-fr/strings.xml b/android/engine/src/main/res/values-fr/strings.xml index 3e9a00e173..644dc23a3d 100644 --- a/android/engine/src/main/res/values-fr/strings.xml +++ b/android/engine/src/main/res/values-fr/strings.xml @@ -8,6 +8,7 @@ Synchronisation des données Scan du code-barres Aucun résultat + Version de migration de données %1$s Désolé, nous n\'avons pas trouvé de client avec le nom ou l\'identifiant donné. Enregistrer un nouveau client Logo de l\'application diff --git a/android/engine/src/main/res/values-in/strings.xml b/android/engine/src/main/res/values-in/strings.xml index f55d32390a..5f64139afc 100644 --- a/android/engine/src/main/res/values-in/strings.xml +++ b/android/engine/src/main/res/values-in/strings.xml @@ -174,4 +174,5 @@ Versi OS Tanggal Perangkat + Versi migrasi data diff --git a/android/engine/src/main/res/values-sw/strings.xml b/android/engine/src/main/res/values-sw/strings.xml index 9db5abf150..49f7c029c3 100644 --- a/android/engine/src/main/res/values-sw/strings.xml +++ b/android/engine/src/main/res/values-sw/strings.xml @@ -1,5 +1,6 @@ Toleo %1$d(%2$s) + Toleo la uhamiaji wa data %1$s Usawazishaji wa mwisho %1$s Lugha Hakuna Matokeo diff --git a/android/engine/src/main/res/values/strings.xml b/android/engine/src/main/res/values/strings.xml index 4571522bdf..b3c5187dac 100644 --- a/android/engine/src/main/res/values/strings.xml +++ b/android/engine/src/main/res/values/strings.xml @@ -14,6 +14,7 @@ Application logo Powered By App version %1$d(%2$s) + Data migration version %1$s Last sync %1$s LOGIN Failed to verify credentials from the server. Check your internet connection diff --git a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/usersetting/UserSettingScreenTest.kt b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/usersetting/UserSettingScreenTest.kt index 17b7933bd8..e4152e75ab 100644 --- a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/usersetting/UserSettingScreenTest.kt +++ b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/usersetting/UserSettingScreenTest.kt @@ -199,6 +199,7 @@ class UserSettingScreenTest { isDebugVariant = isDebugVariant, onEvent = {}, mainNavController = rememberNavController(), + dataMigrationVersion = "0", lastSyncTime = "05:30 PM, Mar 3", showProgressIndicatorFlow = MutableStateFlow(false), enableManualSync = showManualSync, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragment.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragment.kt index 4a2ff3c565..4d13f98023 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragment.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragment.kt @@ -107,6 +107,7 @@ class UserSettingFragment : Fragment(), OnSyncListener { mainNavController = findNavController(), lastSyncTime = userSettingViewModel.retrieveLastSyncTimestamp(), showProgressIndicatorFlow = userSettingViewModel.showProgressIndicatorFlow, + dataMigrationVersion = userSettingViewModel.retrieveDataMigrationVersion(), enableManualSync = userSettingViewModel.enableMenuOption(SettingsOptions.MANUAL_SYNC), allowSwitchingLanguages = userSettingViewModel.allowSwitchingLanguages(), diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingScreen.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingScreen.kt index f145fff38b..8941520b23 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingScreen.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingScreen.kt @@ -46,11 +46,11 @@ import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.material.TopAppBar import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material.icons.automirrored.rounded.Logout import androidx.compose.material.icons.rounded.ChevronRight import androidx.compose.material.icons.rounded.DeleteForever import androidx.compose.material.icons.rounded.Insights -import androidx.compose.material.icons.rounded.Logout import androidx.compose.material.icons.rounded.Map import androidx.compose.material.icons.rounded.Phone import androidx.compose.material.icons.rounded.Share @@ -120,6 +120,7 @@ fun UserSettingScreen( onEvent: (UserSettingsEvent) -> Unit, mainNavController: NavController, appVersionPair: Pair? = null, + dataMigrationVersion: String, lastSyncTime: String?, showProgressIndicatorFlow: MutableStateFlow, enableManualSync: Boolean, @@ -141,7 +142,7 @@ fun UserSettingScreen( title = { Text(text = stringResource(R.string.settings)) }, navigationIcon = { IconButton(onClick = { mainNavController.popBackStack() }) { - Icon(Icons.Filled.ArrowBack, null) + Icon(Icons.AutoMirrored.Filled.ArrowBack, null) } }, contentColor = Color.White, @@ -356,7 +357,7 @@ fun UserSettingScreen( } UserSettingRow( - icon = Icons.Rounded.Logout, + icon = Icons.AutoMirrored.Rounded.Logout, text = stringResource(id = R.string.logout), clickListener = { onEvent(UserSettingsEvent.Logout(context)) }, modifier = modifier.testTag(USER_SETTING_ROW_LOGOUT), @@ -394,6 +395,15 @@ fun UserSettingScreen( modifier = modifier.padding(top = 8.dp).align(Alignment.CenterHorizontally), ) + if (dataMigrationVersion.toInt() > 0) { + Text( + color = contentColor, + fontSize = 16.sp, + text = stringResource(id = R.string.data_migration_version, dataMigrationVersion), + modifier = modifier.padding(top = 2.dp).align(Alignment.CenterHorizontally), + ) + } + Text( color = contentColor, fontSize = 16.sp, @@ -505,6 +515,7 @@ fun UserSettingPreview() { onEvent = {}, mainNavController = rememberNavController(), appVersionPair = Pair(1, "1.0.1"), + dataMigrationVersion = "0", lastSyncTime = "05:30 PM, Mar 3", showProgressIndicatorFlow = MutableStateFlow(false), enableManualSync = true, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModel.kt index f6261fa023..30e41778fc 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModel.kt @@ -29,7 +29,9 @@ import javax.inject.Inject import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.smartregister.fhircore.engine.R import org.smartregister.fhircore.engine.configuration.ConfigType @@ -37,6 +39,7 @@ import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration import org.smartregister.fhircore.engine.configuration.app.SettingsOptions import org.smartregister.fhircore.engine.data.remote.model.response.UserInfo +import org.smartregister.fhircore.engine.datastore.PreferenceDataStore import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig import org.smartregister.fhircore.engine.sync.SyncBroadcaster import org.smartregister.fhircore.engine.util.DispatcherProvider @@ -70,6 +73,7 @@ constructor( val configurationRegistry: ConfigurationRegistry, val workManager: WorkManager, val dispatcherProvider: DispatcherProvider, + private val preferenceDataStore: PreferenceDataStore, ) : ViewModel() { val languages by lazy { configurationRegistry.fetchLanguages() } @@ -102,6 +106,10 @@ constructor( fun retrieveCareTeam() = sharedPreferencesHelper.read(SharedPreferenceKey.CARE_TEAM.name, null) + fun retrieveDataMigrationVersion(): String = runBlocking { + (preferenceDataStore.read(PreferenceDataStore.MIGRATION_VERSION).firstOrNull() ?: 0).toString() + } + fun retrieveLastSyncTimestamp(): String? = sharedPreferencesHelper.read(SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name, null) diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserInsightScreenFragmentTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserInsightScreenFragmentTest.kt index 50cc2df167..92e24359b6 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserInsightScreenFragmentTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserInsightScreenFragmentTest.kt @@ -38,6 +38,7 @@ import org.smartregister.fhircore.engine.R import org.smartregister.fhircore.engine.configuration.app.ConfigService import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceDataSource import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceService +import org.smartregister.fhircore.engine.datastore.PreferenceDataStore import org.smartregister.fhircore.engine.sync.SyncBroadcaster import org.smartregister.fhircore.engine.util.DispatcherProvider import org.smartregister.fhircore.engine.util.SecureSharedPreference @@ -58,6 +59,8 @@ class UserInsightScreenFragmentTest : RobolectricTest() { @Inject lateinit var testDispatcherProvider: DispatcherProvider @Inject lateinit var workManager: WorkManager + + @Inject lateinit var preferenceDataStore: PreferenceDataStore private val navController = TestNavHostController(ApplicationProvider.getApplicationContext()) private val context = ApplicationProvider.getApplicationContext() private val resourceService: FhirResourceService = mockk() @@ -100,6 +103,7 @@ class UserInsightScreenFragmentTest : RobolectricTest() { accountAuthenticator = accountAuthenticator, secureSharedPreference = secureSharedPreference, sharedPreferencesHelper = sharedPreferencesHelper, + preferenceDataStore = preferenceDataStore, configurationRegistry = configurationRegistry, workManager = mockk(relaxed = true), dispatcherProvider = testDispatcherProvider, diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragmentTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragmentTest.kt index 442eccc2cf..6b7b2f415c 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragmentTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingFragmentTest.kt @@ -38,6 +38,7 @@ import org.smartregister.fhircore.engine.R import org.smartregister.fhircore.engine.configuration.app.ConfigService import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceDataSource import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceService +import org.smartregister.fhircore.engine.datastore.PreferenceDataStore import org.smartregister.fhircore.engine.sync.SyncBroadcaster import org.smartregister.fhircore.engine.util.DispatcherProvider import org.smartregister.fhircore.engine.util.SecureSharedPreference @@ -69,6 +70,7 @@ class UserSettingFragmentTest : RobolectricTest() { private lateinit var userSettingViewModel: UserSettingViewModel private lateinit var accountAuthenticator: AccountAuthenticator private lateinit var secureSharedPreference: SecureSharedPreference + private lateinit var preferenceDataStore: PreferenceDataStore init { sharedPreferencesHelper = SharedPreferencesHelper(context = context, gson = mockk()) @@ -83,6 +85,7 @@ class UserSettingFragmentTest : RobolectricTest() { accountAuthenticator = mockk() secureSharedPreference = mockk() sharedPreferencesHelper = mockk() + preferenceDataStore = mockk() syncBroadcaster = SyncBroadcaster( configurationRegistry, @@ -100,6 +103,7 @@ class UserSettingFragmentTest : RobolectricTest() { accountAuthenticator = accountAuthenticator, secureSharedPreference = secureSharedPreference, sharedPreferencesHelper = sharedPreferencesHelper, + preferenceDataStore = preferenceDataStore, configurationRegistry = configurationRegistry, workManager = mockk(relaxed = true), dispatcherProvider = dispatcherProvider, diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModelTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModelTest.kt index 0ab62cf92d..6c106a4c5e 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModelTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/usersetting/UserSettingViewModelTest.kt @@ -51,6 +51,7 @@ import org.smartregister.fhircore.engine.configuration.app.ConfigService import org.smartregister.fhircore.engine.configuration.app.SettingsOptions import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceDataSource import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceService +import org.smartregister.fhircore.engine.datastore.PreferenceDataStore import org.smartregister.fhircore.engine.domain.model.Language import org.smartregister.fhircore.engine.sync.SyncBroadcaster import org.smartregister.fhircore.engine.util.DispatcherProvider @@ -78,6 +79,7 @@ class UserSettingViewModelTest : RobolectricTest() { @Inject lateinit var dispatcherProvider: DispatcherProvider + @Inject lateinit var preferenceDataStore: PreferenceDataStore lateinit var fhirEngine: FhirEngine private var sharedPreferencesHelper: SharedPreferencesHelper private var configService: ConfigService @@ -126,6 +128,7 @@ class UserSettingViewModelTest : RobolectricTest() { accountAuthenticator = accountAuthenticator, secureSharedPreference = secureSharedPreference, sharedPreferencesHelper = sharedPreferencesHelper, + preferenceDataStore = preferenceDataStore, configurationRegistry = configurationRegistry, workManager = workManager, dispatcherProvider = dispatcherProvider,