Search in sources :

Example 1 with Alarm

use of de.geeksfactory.opacclient.reminder.Alarm in project opacclient by opacapp.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sp = PreferenceManager.getDefaultSharedPreferences(this);
    String itemToSelect = null;
    if (getIntent() != null && getIntent().getAction() != null) {
        if (getIntent().getAction().equals("android.intent.action.VIEW")) {
            urlintent();
        } else if (getIntent().getAction().equals(ACTION_SEARCH) || getIntent().getAction().equals(ACTION_ACCOUNT)) {
            String lib = getIntent().getStringExtra("library");
            AccountDataSource adata = new AccountDataSource(this);
            List<Account> accounts = adata.getAllAccounts(lib);
            if (accounts.size() == 0) {
                // Check if library exists (an IOException should be thrown otherwise, correct?)
                try {
                    app.getLibrary(lib);
                } catch (IOException | JSONException e) {
                    return;
                }
                Account account = new Account();
                account.setLibrary(lib);
                account.setLabel(getString(R.string.default_account_name));
                account.setName("");
                account.setPassword("");
                long id = adata.addAccount(account);
                selectaccount(id);
            } else if (accounts.size() == 1) {
                selectaccount(accounts.get(0).getId());
            } else if (accounts.size() > 0) {
                if (getIntent().getAction().equals(ACTION_ACCOUNT)) {
                    List<Account> accountsWithPassword = new ArrayList<>();
                    for (Account account : accounts) {
                        if (account.getName() != null && account.getPassword() != null && !account.getName().isEmpty() && !account.getPassword().isEmpty()) {
                            accountsWithPassword.add(account);
                        }
                    }
                    if (accountsWithPassword.size() == 1) {
                        selectaccount(accountsWithPassword.get(0).getId());
                    } else {
                        showAccountSelectDialog(accounts);
                    }
                } else {
                    showAccountSelectDialog(accounts);
                }
            }
            if (getIntent().getAction().equals(ACTION_SEARCH)) {
                itemToSelect = "search";
            } else {
                itemToSelect = "account";
            }
        }
    }
    if (savedInstanceState == null) {
        if (getIntent().hasExtra(EXTRA_FRAGMENT)) {
            selectItem(getIntent().getStringExtra(EXTRA_FRAGMENT));
        } else if (getIntent().hasExtra(ReminderBroadcastReceiver.EXTRA_ALARM_ID)) {
            AccountDataSource adata = new AccountDataSource(this);
            long alid = getIntent().getLongExtra(ReminderBroadcastReceiver.EXTRA_ALARM_ID, -1);
            Alarm alarm = adata.getAlarm(alid);
            if (alarm == null) {
                throw new DataIntegrityException("Unknown alarm ID " + alid + " received.");
            }
            List<LentItem> items = adata.getLentItems(alarm.media);
            if (items.size() > 0) {
                long firstAccount = items.get(0).getAccount();
                boolean multipleAccounts = false;
                for (LentItem item : items) {
                    if (item.getAccount() != firstAccount) {
                        multipleAccounts = true;
                        break;
                    }
                }
                if (multipleAccounts) {
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            drawerLayout.openDrawer(drawer);
                        }
                    }, 500);
                } else {
                    selectaccount(firstAccount);
                    selectItem("account");
                }
            }
        } else if (itemToSelect != null) {
            selectItem(itemToSelect);
        } else if (sp.contains("startup_fragment")) {
            selectItem(sp.getString("startup_fragment", "search"));
        } else {
            selectItem(0);
        }
    }
    try {
        if (nfc_capable) {
            if (!getPackageManager().hasSystemFeature("android.hardware.nfc")) {
                nfc_capable = false;
            }
        }
        if (nfc_capable) {
            mAdapter = android.nfc.NfcAdapter.getDefaultAdapter(this);
            nfcIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
            IntentFilter ndef = new IntentFilter(android.nfc.NfcAdapter.ACTION_TECH_DISCOVERED);
            try {
                ndef.addDataType("*/*");
            } catch (MalformedMimeTypeException e) {
                throw new RuntimeException("fail", e);
            }
            intentFiltersArray = new IntentFilter[] { ndef };
            techListsArray = new String[][] { new String[] { android.nfc.tech.NfcV.class.getName() } };
        }
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    if (app.getLibrary() != null) {
        getSupportActionBar().setSubtitle(app.getLibrary().getDisplayName());
    }
    showUpdateInfoDialog();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setExitTransition(null);
    }
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) IntentFilter(android.content.IntentFilter) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) MalformedMimeTypeException(android.content.IntentFilter.MalformedMimeTypeException) DataIntegrityException(de.geeksfactory.opacclient.storage.DataIntegrityException) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Alarm(de.geeksfactory.opacclient.reminder.Alarm) ArrayList(java.util.ArrayList) List(java.util.List) LentItem(de.geeksfactory.opacclient.objects.LentItem) SuppressLint(android.annotation.SuppressLint)

Example 2 with Alarm

use of de.geeksfactory.opacclient.reminder.Alarm 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 3 with Alarm

use of de.geeksfactory.opacclient.reminder.Alarm in project opacclient by opacapp.

the class AccountDataSource method getAllAlarms.

public List<Alarm> getAllAlarms() {
    List<Alarm> alarms = new ArrayList<>();
    Cursor cursor = database.query(AccountDatabase.TABLENAME_ALARMS, AccountDatabase.COLUMNS_ALARMS, null, null, null, null, null);
    cursor.moveToFirst();
    while (!cursor.isAfterLast()) {
        Alarm alarm = cursorToAlarm(cursor);
        alarms.add(alarm);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return alarms;
}
Also used : Alarm(de.geeksfactory.opacclient.reminder.Alarm) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 4 with Alarm

use of de.geeksfactory.opacclient.reminder.Alarm in project opacclient by opacapp.

the class AccountDataSource method cursorToAlarm.

private Alarm cursorToAlarm(Cursor cursor) {
    Alarm alarm = new Alarm();
    alarm.id = cursor.getLong(0);
    alarm.deadline = new LocalDate(cursor.getString(1));
    alarm.media = splitLongs(cursor.getString(2), ",");
    alarm.notificationTime = new DateTime(cursor.getString(3));
    alarm.notified = cursor.getInt(4) == 1;
    alarm.finished = cursor.getInt(5) == 1;
    return alarm;
}
Also used : Alarm(de.geeksfactory.opacclient.reminder.Alarm) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

Example 5 with Alarm

use of de.geeksfactory.opacclient.reminder.Alarm in project opacclient by opacapp.

the class AccountDataSource method getAlarm.

public Alarm getAlarm(long id) {
    String[] selA = { "" + id };
    Cursor cursor = database.query(AccountDatabase.TABLENAME_ALARMS, AccountDatabase.COLUMNS_ALARMS, "id = ?", selA, null, null, null);
    Alarm item = null;
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        item = cursorToAlarm(cursor);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return item;
}
Also used : Alarm(de.geeksfactory.opacclient.reminder.Alarm) Cursor(android.database.Cursor)

Aggregations

Alarm (de.geeksfactory.opacclient.reminder.Alarm)6 Cursor (android.database.Cursor)3 AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)2 DataIntegrityException (de.geeksfactory.opacclient.storage.DataIntegrityException)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 MalformedMimeTypeException (android.content.IntentFilter.MalformedMimeTypeException)1 Handler (android.os.Handler)1 OpacClient (de.geeksfactory.opacclient.OpacClient)1 Account (de.geeksfactory.opacclient.objects.Account)1 LentItem (de.geeksfactory.opacclient.objects.LentItem)1 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1