Source:
<code>public void loadLocations(final String url) { loginView.showLocationLoadingAnimation(); <START> if (NetworkUtils.hasNetwork()) { <END> String locationEndPoint = url + ApplicationConstants.API.REST_ENDPOINT + "location"; RestApi restApi = RestServiceBuilder.createService(RestApi.class); Call<Results<Location>> call = restApi.getLocations(locationEndPoint, "Login Location", "full"); call.enqueue(new Callback<Results<Location>>() { @Override public void onResponse(Call<Results<Location>> call, Response<Results<Location>> response) { if (response.isSuccessful()) { RestServiceBuilder.changeBaseUrl(url.trim()); mOpenMRS.setServerUrl(url); mOpenMRS.setLocations(response.body().getResults()); loginView.initLoginForm(response.body().getResults(), url); loginView.startFormListService(); loginView.setLocationErrorOccurred(false); } else { loginView.showInvalidURLSnackbar("Failed to fetch server's locations"); loginView.setLocationErrorOccurred(true); } loginView.hideUrlLoadingAnimation(); } @Override public void onFailure(Call<Results<Location>> call, Throwable t) { loginView.hideUrlLoadingAnimation(); loginView.showInvalidURLSnackbar(t.getMessage()); loginView.setLocationErrorOccurred(true); } }); } else { List<Location> locations = mOpenMRS.getLocations(); if (locations != null) { loginView.initLoginForm(locations, url); loginView.setLocationErrorOccurred(false); } else { ToastUtil.error("Network not available."); loginView.setLocationErrorOccurred(true); } loginView.hideLoadingAnimation(); } }</code><technical_language>NetworkUtilis.isOnline() ? hasNetwork checks for internet connection sync button @rkorytkowski give some thoughts ? :)</technical_language>

Target:
public void loadLocations(final String url) { loginView.showLocationLoadingAnimation(); if (NetworkUtils.hasNetwork()) { String locationEndPoint = url + ApplicationConstants.API.REST_ENDPOINT + "location"; RestApi restApi = RestServiceBuilder.createService(RestApi.class); Call<Results<Location>> call = restApi.getLocations(locationEndPoint, "Login Location", "full"); call.enqueue(new Callback<Results<Location>>() { @Override public void onResponse(Call<Results<Location>> call, Response<Results<Location>> response) { if (response.isSuccessful()) { RestServiceBuilder.changeBaseUrl(url.trim()); mOpenMRS.setServerUrl(url); loginView.initLoginForm(response.body().getResults(), url); loginView.startFormListService(); loginView.setLocationErrorOccurred(false); } else { loginView.showInvalidURLSnackbar("Failed to fetch server's locations"); loginView.setLocationErrorOccurred(true); loginView.initLoginForm(new ArrayList<Location>(), url); } loginView.hideUrlLoadingAnimation(); } @Override public void onFailure(Call<Results<Location>> call, Throwable t) { loginView.hideUrlLoadingAnimation(); loginView.showInvalidURLSnackbar(t.getMessage()); loginView.setLocationErrorOccurred(true); } }); } else { List<Location> locations = LocationDAO.getLocations(); if (locations.size() > 0) { loginView.initLoginForm(locations, url); loginView.setLocationErrorOccurred(false); } else { loginView.showToast("Network not available.", ToastUtil.ToastType.ERROR); loginView.setLocationErrorOccurred(true); } loginView.hideLoadingAnimation(); } }