Skip to content

Commit

Permalink
Add CALCULATE_DISTANCE_RULE_EXECUTOR LocationLogOption to app config (#…
Browse files Browse the repository at this point in the history
…3276)

- Add check for LocationLogOptions entry to AppMainActivity's setupLocationServices

Co-authored-by: Lentumunai Mark <[email protected]>
  • Loading branch information
qiarie and Lentumunai-Mark authored May 28, 2024
1 parent 1fbb783 commit 1d82052
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ enum class SyncStrategy {

enum class LocationLogOptions {
QUESTIONNAIRE,
CALCULATE_DISTANCE_RULE_EXECUTOR,
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.hl7.fhir.r4.model.IdType
import org.hl7.fhir.r4.model.QuestionnaireResponse
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.app.LocationLogOptions
import org.smartregister.fhircore.engine.configuration.app.SyncStrategy
import org.smartregister.fhircore.engine.configuration.workflow.ActionTrigger
import org.smartregister.fhircore.engine.datastore.ProtoDataStore
Expand Down Expand Up @@ -218,18 +219,24 @@ open class AppMainActivity : BaseMultiLanguageActivity(), QuestionnaireHandler,
}

private fun setupLocationServices() {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
if (
appMainViewModel.applicationConfiguration.logGpsLocation.contains(
LocationLogOptions.CALCULATE_DISTANCE_RULE_EXECUTOR,
)
) {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)

if (!LocationUtils.isLocationEnabled(this)) {
openLocationServicesSettings()
}
if (!LocationUtils.isLocationEnabled(this)) {
openLocationServicesSettings()
}

if (!hasLocationPermissions()) {
launchLocationPermissionsDialog()
}
if (!hasLocationPermissions()) {
launchLocationPermissionsDialog()
}

if (LocationUtils.isLocationEnabled(this) && hasLocationPermissions()) {
fetchLocation()
if (LocationUtils.isLocationEnabled(this) && hasLocationPermissions()) {
fetchLocation()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.task.FhirCarePlanGenerator
import org.smartregister.fhircore.engine.util.SharedPreferenceKey
import org.smartregister.fhircore.engine.util.extension.second
import org.smartregister.fhircore.quest.app.fakes.Faker
import org.smartregister.fhircore.quest.event.AppEvent
import org.smartregister.fhircore.quest.event.EventBus
Expand Down Expand Up @@ -85,8 +84,8 @@ class AppMainActivityTest : ActivityRobolectricTest() {
fun testActivityIsStartedCorrectly() {
Assert.assertNotNull(appMainActivity)
val fragments = appMainActivity.supportFragmentManager.fragments
Assert.assertEquals(2, fragments.size)
Assert.assertTrue(fragments.second() is NavHostFragment)
Assert.assertEquals(1, fragments.size)
Assert.assertTrue(fragments.first() is NavHostFragment)
}

override fun getActivity(): Activity {
Expand Down

0 comments on commit 1d82052

Please sign in to comment.