Skip to content

Commit

Permalink
Display data migration in settings (#3079)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Signed-off-by: Elly Kitoto <[email protected]>
Co-authored-by: Elly Kitoto <[email protected]>
  • Loading branch information
AbdulWahabMemon and ellykits authored Jul 22, 2024
1 parent c67c1dc commit 4fc1887
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 4 deletions.
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 @@ -8,6 +8,7 @@
<string name="sync_data">Synchronisation des données</string>
<string name="scan_bar_code">Scan du code-barres</string>
<string name="empty_client_list_message_title">Aucun résultat</string>
<string name="data_migration_version">Version de migration de données %1$s</string>
<string name="empty_client_list_message_details">Désolé, nous n\'avons pas trouvé de client avec le nom ou l\'identifiant donné.</string>
<string name="register_new_client">Enregistrer un nouveau client</string>
<string name="app_logo">Logo de l\'application</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 @@ -174,4 +174,5 @@
<string name="os_version">Versi OS</string>
<string name="device_date">Tanggal</string>
<string name="device">Perangkat</string>
<string name="data_migration_version">Versi migrasi data</string>
</resources>
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
@@ -1,5 +1,6 @@
<resources>
<string name="app_version">Toleo %1$d(%2$s)</string>
<string name="data_migration_version">Toleo la uhamiaji wa data %1$s</string>
<string name="last_sync">Usawazishaji wa mwisho %1$s</string>
<string name="language">Lugha</string>
<string name="empty_client_list_message_title">Hakuna Matokeo</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 @@ -14,6 +14,7 @@
<string name="app_logo">Application logo</string>
<string name="powered_by">Powered By</string>
<string name="app_version">App version %1$d(%2$s)</string>
<string name="data_migration_version">Data migration version %1$s</string>
<string name="last_sync">Last sync %1$s</string>
<string name="login_text">LOGIN</string>
<string name="login_call_fail_error_message">Failed to verify credentials from the server. Check your internet connection</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class UserSettingScreenTest {
isDebugVariant = isDebugVariant,
onEvent = {},
mainNavController = rememberNavController(),
dataMigrationVersion = "0",
lastSyncTime = "05:30 PM, Mar 3",
showProgressIndicatorFlow = MutableStateFlow(false),
enableManualSync = showManualSync,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,6 +120,7 @@ fun UserSettingScreen(
onEvent: (UserSettingsEvent) -> Unit,
mainNavController: NavController,
appVersionPair: Pair<Int, String>? = null,
dataMigrationVersion: String,
lastSyncTime: String?,
showProgressIndicatorFlow: MutableStateFlow<Boolean>,
enableManualSync: Boolean,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ 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
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
Expand Down Expand Up @@ -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() }
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<HiltTestApplication>()
private val resourceService: FhirResourceService = mockk()
Expand Down Expand Up @@ -100,6 +103,7 @@ class UserInsightScreenFragmentTest : RobolectricTest() {
accountAuthenticator = accountAuthenticator,
secureSharedPreference = secureSharedPreference,
sharedPreferencesHelper = sharedPreferencesHelper,
preferenceDataStore = preferenceDataStore,
configurationRegistry = configurationRegistry,
workManager = mockk(relaxed = true),
dispatcherProvider = testDispatcherProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -83,6 +85,7 @@ class UserSettingFragmentTest : RobolectricTest() {
accountAuthenticator = mockk()
secureSharedPreference = mockk()
sharedPreferencesHelper = mockk()
preferenceDataStore = mockk()
syncBroadcaster =
SyncBroadcaster(
configurationRegistry,
Expand All @@ -100,6 +103,7 @@ class UserSettingFragmentTest : RobolectricTest() {
accountAuthenticator = accountAuthenticator,
secureSharedPreference = secureSharedPreference,
sharedPreferencesHelper = sharedPreferencesHelper,
preferenceDataStore = preferenceDataStore,
configurationRegistry = configurationRegistry,
workManager = mockk(relaxed = true),
dispatcherProvider = dispatcherProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -126,6 +128,7 @@ class UserSettingViewModelTest : RobolectricTest() {
accountAuthenticator = accountAuthenticator,
secureSharedPreference = secureSharedPreference,
sharedPreferencesHelper = sharedPreferencesHelper,
preferenceDataStore = preferenceDataStore,
configurationRegistry = configurationRegistry,
workManager = workManager,
dispatcherProvider = dispatcherProvider,
Expand Down

0 comments on commit 4fc1887

Please sign in to comment.