use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.
the class MainPreferenceFragment method refreshLastConfigUpdate.
private void refreshLastConfigUpdate(Preference updateLibraryConfig) {
DateTime lastUpdate = new PreferenceDataSource(context).getLastLibraryConfigUpdate();
if (lastUpdate != null) {
CharSequence lastUpdateStr = DateUtils.getRelativeTimeSpanString(context, lastUpdate.getMillis(), true);
updateLibraryConfig.setSummary(getString(R.string.library_config_last_update, lastUpdateStr));
} else {
updateLibraryConfig.setSummary(getString(R.string.library_config_last_update_never));
}
}
use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.
the class OpacClient method onCreate.
@Override
public void onCreate() {
super.onCreate();
sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!BuildConfig.DEBUG) {
try {
final ACRAConfiguration config = new ConfigurationBuilder(this).setResToastText(R.string.crash_toast_text).setResDialogText(R.string.crash_dialog_text).setResToastText(R.string.crash_toast_text).setResNotifTickerText(R.string.crash_notif_ticker_text).setResNotifTitle(R.string.crash_notif_title).setResNotifText(R.string.crash_notif_text).setResNotifIcon(android.R.drawable.stat_notify_error).setResDialogText(R.string.crash_dialog_text).build();
ACRA.init(this, config);
if (getLibrary() != null) {
ACRA.getErrorReporter().putCustomData("library", getLibrary().getIdent());
}
DateTime lastUpdate = new PreferenceDataSource(getApplicationContext()).getLastLibraryConfigUpdate();
ACRA.getErrorReporter().putCustomData("data_version", lastUpdate != null ? lastUpdate.toString() : "null");
} catch (ACRAConfigurationException e) {
e.printStackTrace();
}
}
DebugTools.init(this);
OpacClient.context = getApplicationContext();
try {
OpacClient.versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
// Schedule alarms
JobManager.create(this).addJobCreator(new SyncAccountJobCreator());
SyncAccountJob.scheduleJob(this);
}
use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.
the class LibraryConfigUpdateService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
WebService service = WebServiceManager.getInstance();
PreferenceDataSource prefs = new PreferenceDataSource(this);
File filesDir = new File(getFilesDir(), LIBRARIES_DIR);
filesDir.mkdirs();
try {
int count = ((OpacClient) getApplication()).getUpdateHandler().updateConfig(service, prefs, new FileOutput(filesDir), new JsonSearchFieldDataSource(this));
if (!BuildConfig.DEBUG) {
DateTime lastUpdate = prefs.getLastLibraryConfigUpdate();
ACRA.getErrorReporter().putCustomData("data_version", lastUpdate != null ? lastUpdate.toString() : "null");
}
if (BuildConfig.DEBUG) {
Log.d("LibraryConfigUpdate", "updated config for " + String.valueOf(count) + " libraries");
}
Intent broadcast = new Intent(ACTION_SUCCESS).putExtra(EXTRA_UPDATE_COUNT, count);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
((OpacClient) getApplication()).resetCache();
} catch (IOException e) {
Intent broadcast = new Intent(ACTION_FAILURE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
} catch (JSONException e) {
Intent broadcast = new Intent(ACTION_FAILURE);
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
ErrorReporter.handleException(e);
}
}
use of de.geeksfactory.opacclient.storage.PreferenceDataSource 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) {
}
}
use of de.geeksfactory.opacclient.storage.PreferenceDataSource in project opacclient by opacapp.
the class LibraryConfigUpdateService method clearConfigurationUpdates.
public static void clearConfigurationUpdates(Context context) {
File filesDir = new File(context.getFilesDir(), LIBRARIES_DIR);
filesDir.mkdirs();
File[] files = filesDir.listFiles();
for (File file : files) {
file.delete();
}
PreferenceDataSource prefs = new PreferenceDataSource(context);
prefs.clearLastLibraryConfigUpdate();
}
Aggregations