Search in sources :

Example 1 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource 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 AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class MainActivity method urlintent.

public void urlintent() {
    Uri d = getIntent().getData();
    if (d.getHost().equals("opacapp.de")) {
        String[] split = d.getPath().split(":");
        String bib;
        try {
            bib = URLDecoder.decode(split[1], "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new AssertionError("UTF-8 is unknown");
        }
        if (app.getLibrary() == null || !app.getLibrary().getIdent().equals(bib)) {
            AccountDataSource adata = new AccountDataSource(this);
            List<Account> accounts = adata.getAllAccounts(bib);
            if (accounts.size() > 0) {
                app.setAccount(accounts.get(0).getId());
            } else {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://de.opacapp.net/" + d.getPath()));
                startActivity(i);
                return;
            }
        }
        String medianr = split[2];
        if (medianr.length() > 1) {
            Intent intent = new Intent(MainActivity.this, SearchResultDetailActivity.class);
            intent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, medianr);
            startActivity(intent);
        } else {
            String title;
            try {
                title = URLDecoder.decode(split[3], "UTF-8");
            } catch (UnsupportedEncodingException e) {
                throw new AssertionError("UTF-8 is unknown");
            }
            Bundle query = new Bundle();
            // TODO: This won't work with most modern APIs
            query.putString("title", title);
            Intent intent = new Intent(MainActivity.this, SearchResultListActivity.class);
            intent.putExtra("query", query);
            startActivity(intent);
        }
        finish();
    }
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) Bundle(android.os.Bundle) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri)

Example 3 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class OpacActivity method selectaccount.

public void selectaccount() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // Get the layout inflater
    LayoutInflater inflater = getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_simple_list, null);
    ListView lv = (ListView) view.findViewById(R.id.lvBibs);
    AccountDataSource data = new AccountDataSource(this);
    final List<Account> accounts = data.getAllAccounts();
    AccountListAdapter adapter = new AccountListAdapter(this, accounts);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            app.setAccount(accounts.get(position).getId());
            adialog.dismiss();
            ((AccountSelectedListener) fragment).accountSelected(accounts.get(position));
        }
    });
    builder.setTitle(R.string.account_select).setView(view).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            adialog.cancel();
        }
    }).setNeutralButton(R.string.accounts_edit, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
            Intent intent = new Intent(OpacActivity.this, AccountListActivity.class);
            startActivity(intent);
        }
    });
    adialog = builder.create();
    adialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.geeksfactory.opacclient.objects.Account) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AccountSwitcherNavigationView(de.geeksfactory.opacclient.ui.AccountSwitcherNavigationView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint) ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater)

Example 4 with AccountDataSource

use of de.geeksfactory.opacclient.storage.AccountDataSource in project opacclient by opacapp.

the class SearchResultDetailFragment method reservationPerform.

public void reservationPerform() {
    MultiStepResultHelper<DetailedItem> msrhReservation = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_res);
    msrhReservation.setCallback(new Callback<DetailedItem>() {

        @Override
        public void onSuccess(MultiStepResult result) {
            AccountDataSource adata = new AccountDataSource(getActivity());
            adata.invalidateCachedAccountData(app.getAccount());
            if (result.getMessage() != null) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage(result.getMessage()).setCancelable(false).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setPositiveButton(R.string.account, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(getActivity(), app.getMainActivity());
                        intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
                        getActivity().startActivity(intent);
                        getActivity().finish();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            } else {
                Intent intent = new Intent(getActivity(), app.getMainActivity());
                intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
                getActivity().startActivity(intent);
                getActivity().finish();
            }
        }

        @Override
        public void onError(MultiStepResult result) {
            dialog_wrong_credentials(result.getMessage(), false);
        }

        @Override
        public void onUnhandledResult(MultiStepResult result) {
        }

        @Override
        public void onUserCancel() {
        }

        @Override
        public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
            return new ResTask(helper, useraction, selection, item);
        }
    });
    msrhReservation.start();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) DialogInterface(android.content.DialogInterface) MultiStepResult(de.geeksfactory.opacclient.apis.OpacApi.MultiStepResult) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) StepTask(de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask) OnClickListener(android.view.View.OnClickListener) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem)

Example 5 with AccountDataSource

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

Aggregations

AccountDataSource (de.geeksfactory.opacclient.storage.AccountDataSource)23 Intent (android.content.Intent)10 OpacClient (de.geeksfactory.opacclient.OpacClient)8 OnClickListener (android.view.View.OnClickListener)7 Account (de.geeksfactory.opacclient.objects.Account)7 View (android.view.View)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 TextView (android.widget.TextView)6 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 AlertDialog (android.support.v7.app.AlertDialog)5 RecyclerView (android.support.v7.widget.RecyclerView)4 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)4 SharedPreferences (android.content.SharedPreferences)3 LayoutInflater (android.view.LayoutInflater)3 AdapterView (android.widget.AdapterView)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 PendingIntent (android.app.PendingIntent)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2