Search in sources :

Example 1 with WebService

use of de.geeksfactory.opacclient.webservice.WebService in project opacclient by opacapp.

the class SyncAccountJob method updateLibraryConfig.

private void updateLibraryConfig() {
    PreferenceDataSource prefs = new PreferenceDataSource(getContext());
    if (prefs.getLastLibraryConfigUpdate() != null && prefs.getLastLibraryConfigUpdate().isAfter(DateTime.now().minus(Hours.ONE))) {
        Log.d(TAG, "Do not run updateLibraryConfig as last run was less than an hour ago.");
        return;
    }
    WebService service = WebServiceManager.getInstance();
    File filesDir = new File(getContext().getFilesDir(), LibraryConfigUpdateService.LIBRARIES_DIR);
    filesDir.mkdirs();
    try {
        int count = getApp().getUpdateHandler().updateConfig(service, prefs, new LibraryConfigUpdateService.FileOutput(filesDir), new JsonSearchFieldDataSource(getContext()));
        Log.d(TAG, "updated config for " + String.valueOf(count) + " libraries");
        getApp().resetCache();
        if (!BuildConfig.DEBUG) {
            ACRA.getErrorReporter().putCustomData("data_version", prefs.getLastLibraryConfigUpdate().toString());
        }
    } catch (IOException | JSONException ignore) {
    }
}
Also used : WebService(de.geeksfactory.opacclient.webservice.WebService) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) JSONException(org.json.JSONException) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) IOException(java.io.IOException) File(java.io.File) LibraryConfigUpdateService(de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)

Aggregations

JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)1 PreferenceDataSource (de.geeksfactory.opacclient.storage.PreferenceDataSource)1 LibraryConfigUpdateService (de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)1 WebService (de.geeksfactory.opacclient.webservice.WebService)1 File (java.io.File)1 IOException (java.io.IOException)1 JSONException (org.json.JSONException)1