Skip to content

Commit

Permalink
move juridictions update to background thread
Browse files Browse the repository at this point in the history
  • Loading branch information
bennsimon committed Jun 25, 2021
1 parent 25d3815 commit f600fde
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,11 +32,7 @@ public void goToHome(boolean remote) {
TestDataUtils testDataUtils = new TestDataUtils();
testDataUtils.populateTestData();

Set<String> districtsIds = AppUtils.getDistrictsFromLocationHierarchy();
UserService userService = EusmApplication.getInstance().context().userService();
Set<String> locations = userService.fetchJurisdictionIds();
locations.addAll(districtsIds);
userService.saveJurisdictionIds(locations);
EusmApplication.getInstance().updateJurisdictions();

EusmApplication.getInstance().getContext().anmLocationController().evict();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -435,4 +437,17 @@ public AppLocationRepository getAppLocationRepository() {
}
return appLocationRepository;
}

/**
* Add districts to the list of jurisdictions
*/
public void updateJurisdictions() {
getAppExecutors().diskIO().execute(() -> {
Set<String> districtsIds = AppUtils.getDistrictsFromLocationHierarchy();
UserService userService = EusmApplication.getInstance().context().userService();
Set<String> locations = userService.fetchJurisdictionIds();
locations.addAll(districtsIds);
userService.saveJurisdictionIds(locations);
});
}
}

0 comments on commit f600fde

Please sign in to comment.