diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/LoginActivity.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/LoginActivity.java index b2cb452..ccd73a2 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/LoginActivity.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/LoginActivity.java @@ -5,16 +5,12 @@ import org.smartregister.eusm.R; import org.smartregister.eusm.application.EusmApplication; import org.smartregister.eusm.presenter.LoginPresenter; -import org.smartregister.eusm.util.AppUtils; import org.smartregister.eusm.util.TestDataUtils; -import org.smartregister.service.UserService; import org.smartregister.task.SaveTeamLocationsTask; import org.smartregister.util.Utils; import org.smartregister.view.activity.BaseLoginActivity; import org.smartregister.view.contract.BaseLoginContract; -import java.util.Set; - public class LoginActivity extends BaseLoginActivity implements BaseLoginContract.View { @Override @@ -36,11 +32,7 @@ public void goToHome(boolean remote) { TestDataUtils testDataUtils = new TestDataUtils(); testDataUtils.populateTestData(); - Set districtsIds = AppUtils.getDistrictsFromLocationHierarchy(); - UserService userService = EusmApplication.getInstance().context().userService(); - Set locations = userService.fetchJurisdictionIds(); - locations.addAll(districtsIds); - userService.saveJurisdictionIds(locations); + EusmApplication.getInstance().updateJurisdictions(); EusmApplication.getInstance().getContext().anmLocationController().evict(); diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/application/EusmApplication.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/application/EusmApplication.java index 034095b..a041419 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/application/EusmApplication.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/application/EusmApplication.java @@ -52,6 +52,7 @@ import org.smartregister.repository.Repository; import org.smartregister.repository.TaskNotesRepository; import org.smartregister.repository.TaskRepository; +import org.smartregister.service.UserService; import org.smartregister.stock.StockLibrary; import org.smartregister.stock.repository.dao.StockDaoImpl; import org.smartregister.sync.ClientProcessorForJava; @@ -65,6 +66,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Set; import id.zelory.compressor.Compressor; import io.fabric.sdk.android.Fabric; @@ -435,4 +437,17 @@ public AppLocationRepository getAppLocationRepository() { } return appLocationRepository; } + + /** + * Add districts to the list of jurisdictions + */ + public void updateJurisdictions() { + getAppExecutors().diskIO().execute(() -> { + Set districtsIds = AppUtils.getDistrictsFromLocationHierarchy(); + UserService userService = EusmApplication.getInstance().context().userService(); + Set locations = userService.fetchJurisdictionIds(); + locations.addAll(districtsIds); + userService.saveJurisdictionIds(locations); + }); + } }