Search in sources :

Example 1 with OpacClient

use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.

the class SnoozeDatePickerActivity method onTimeSet.

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
    dt = dt.withHourOfDay(hourOfDay).withMinuteOfHour(minute);
    long alarmId = getIntent().getLongExtra(ReminderBroadcastReceiver.EXTRA_ALARM_ID, -1);
    AccountDataSource adata = new AccountDataSource(this);
    Alarm alarm = adata.getAlarm(alarmId);
    if (alarm == null) {
        throw new DataIntegrityException("Trying to snooze unknown alarm ID " + alarmId);
    }
    alarm.notified = false;
    alarm.notificationTime = dt;
    adata.updateAlarm(alarm);
    // dismiss notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel((int) alarm.id);
    // reschedule alarms
    new ReminderHelper((OpacClient) getApplication()).scheduleAlarms();
    finish();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) OpacClient(de.geeksfactory.opacclient.OpacClient) NotificationManager(android.app.NotificationManager) DataIntegrityException(de.geeksfactory.opacclient.storage.DataIntegrityException) Alarm(de.geeksfactory.opacclient.reminder.Alarm)

Example 2 with OpacClient

use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.

the class AccountEditActivity method save.

private void save() {
    AccountDataSource data = new AccountDataSource(AccountEditActivity.this);
    data.update(account);
    if (((OpacClient) getApplication()).getAccount().getId() == account.getId()) {
        ((OpacClient) getApplication()).resetCache();
    }
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient)

Example 3 with OpacClient

use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.

the class ReminderBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    this.context = context;
    this.intent = intent;
    this.prefs = PreferenceManager.getDefaultSharedPreferences(context);
    adata = new AccountDataSource(context);
    alarm = adata.getAlarm(intent.getLongExtra(EXTRA_ALARM_ID, -1));
    if (alarm == null) {
        return;
    }
    switch(intent.getAction()) {
        case ACTION_SHOW_NOTIFICATION:
            showNotification();
            break;
        case ACTION_NOTIFICATION_DELETED:
            notificationDeleted();
            break;
        case ACTION_NOTIFICATION_SNOOZE:
            notificationSnooze();
            break;
        case ACTION_NOTIFICATION_CLICK:
            notificationClick();
            break;
        case ACTION_NOTIFICATION_DONT_REMIND_AGAIN:
            notificationDontRemindAgain();
            break;
    }
    // reschedule alarms
    new ReminderHelper((OpacClient) context.getApplicationContext()).scheduleAlarms();
}
Also used : AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OpacClient(de.geeksfactory.opacclient.OpacClient)

Example 4 with OpacClient

use of de.geeksfactory.opacclient.OpacClient in project opacclient by opacapp.

the class CoverDownloadTask method getImage.

protected byte[] getImage() throws IOException {
    try {
        OpacApi api = ((OpacClient) context.getApplicationContext()).getApi();
        if (api instanceof ApacheBaseApi) {
            return getImageApacheClient(((ApacheBaseApi) api).http_client);
        } else if (api instanceof OkHttpBaseApi) {
            return getImageOkHttpClient(((OkHttpBaseApi) api).http_client);
        }
    } catch (OpacClient.LibraryRemovedException e) {
    }
    HttpClient httpClient;
    httpClient = new AndroidHttpClientFactory().getNewApacheHttpClient(false, true, false, false);
    return getImageApacheClient(httpClient);
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) OkHttpBaseApi(de.geeksfactory.opacclient.apis.OkHttpBaseApi) AndroidHttpClient(android.net.http.AndroidHttpClient) OkHttpClient(okhttp3.OkHttpClient) HttpClient(org.apache.http.client.HttpClient) OpacApi(de.geeksfactory.opacclient.apis.OpacApi) ApacheBaseApi(de.geeksfactory.opacclient.apis.ApacheBaseApi)

Example 5 with OpacClient

use of de.geeksfactory.opacclient.OpacClient 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)

Aggregations

OpacClient (de.geeksfactory.opacclient.OpacClient)10 AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)5 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)3 IOException (java.io.IOException)3 JSONException (org.json.JSONException)3 Account (de.geeksfactory.opacclient.objects.Account)2 Library (de.geeksfactory.opacclient.objects.Library)2 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)2 NotificationManager (android.app.NotificationManager)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 AndroidHttpClient (android.net.http.AndroidHttpClient)1 NonNull (android.support.annotation.NonNull)1 MenuItem (android.view.MenuItem)1 ApacheBaseApi (de.geeksfactory.opacclient.apis.ApacheBaseApi)1 EbookServiceApi (de.geeksfactory.opacclient.apis.EbookServiceApi)1 OkHttpBaseApi (de.geeksfactory.opacclient.apis.OkHttpBaseApi)1 AccountData (de.geeksfactory.opacclient.objects.AccountData)1 LentItem (de.geeksfactory.opacclient.objects.LentItem)1 ReservedItem (de.geeksfactory.opacclient.objects.ReservedItem)1