Search in sources :

Example 1 with PreferenceDataSource

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));
    }
}
Also used : PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) DateTime(org.joda.time.DateTime)

Example 2 with PreferenceDataSource

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);
}
Also used : ConfigurationBuilder(org.acra.config.ConfigurationBuilder) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) ACRAConfiguration(org.acra.config.ACRAConfiguration) ACRAConfigurationException(org.acra.config.ACRAConfigurationException) DateTime(org.joda.time.DateTime) SyncAccountJobCreator(de.geeksfactory.opacclient.reminder.SyncAccountJobCreator)

Example 3 with PreferenceDataSource

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);
    }
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) JSONException(org.json.JSONException) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) IOException(java.io.IOException) File(java.io.File) DateTime(org.joda.time.DateTime)

Example 4 with PreferenceDataSource

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) {
    }
}
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)

Example 5 with PreferenceDataSource

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();
}
Also used : PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) File(java.io.File)

Aggregations

PreferenceDataSource (de.geeksfactory.opacclient.storage.PreferenceDataSource)8 File (java.io.File)4 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)3 DateTime (org.joda.time.DateTime)3 Intent (android.content.Intent)2 LibraryConfigUpdateService (de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)2 IOException (java.io.IOException)2 JSONException (org.json.JSONException)2 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 ConnectivityManager (android.net.ConnectivityManager)1 DialogFragment (android.support.v4.app.DialogFragment)1 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)1 ListPreference (android.support.v7.preference.ListPreference)1 Preference (android.support.v7.preference.Preference)1 PreferenceCategory (android.support.v7.preference.PreferenceCategory)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1