Search in sources :

Example 1 with SearchFieldDataSource

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

the class MainActivity method onNewIntent.

@SuppressLint("NewApi")
@Override
public void onNewIntent(Intent intent) {
    if (nfc_capable && sp.getBoolean("nfc_search", false)) {
        android.nfc.Tag tag = intent.getParcelableExtra(android.nfc.NfcAdapter.EXTRA_TAG);
        String scanResult = readPageToString(tag);
        if (scanResult != null) {
            if (scanResult.length() > 5) {
                SearchFieldDataSource source = new JsonSearchFieldDataSource(this);
                if (source.hasSearchFields(app.getLibrary().getIdent())) {
                    List<SearchField> fields = source.getSearchFields(app.getLibrary().getIdent());
                    for (SearchField field : fields) {
                        if (field.getMeaning() == SearchField.Meaning.BARCODE) {
                            List<SearchQuery> queries = new ArrayList<>();
                            queries.add(new SearchQuery(field, scanResult));
                            app.startSearch(this, queries);
                            return;
                        }
                    }
                }
                Intent detailIntent = new Intent(this, SearchResultDetailActivity.class);
                detailIntent.putExtra(SearchResultDetailFragment.ARG_ITEM_ID, scanResult);
                startActivity(detailIntent);
            }
        }
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) ArrayList(java.util.ArrayList) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint)

Example 2 with SearchFieldDataSource

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

the class SearchFragment method saveFields.

public void saveFields(List<SearchField> fields) {
    SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
    dataSource.saveSearchFields(app.getLibrary().getIdent(), fields);
}
Also used : SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)

Example 3 with SearchFieldDataSource

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

the class SearchFragment method accountSelected.

@Override
public void accountSelected(Account account) {
    errorView.removeAllViews();
    progress(false);
    if (!app.getLibrary().isActive()) {
        showConnectivityError(getString(R.string.library_removed_error), false);
        return;
    }
    SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
    int versionCode = 0;
    try {
        versionCode = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
    }
    String language = getActivity().getResources().getConfiguration().locale.getLanguage();
    if (dataSource.hasSearchFields(app.getLibrary().getIdent()) && dataSource.getLastSearchFieldUpdateVersion(app.getLibrary().getIdent()) == versionCode && language.equals(dataSource.getSearchFieldLanguage(app.getLibrary().getIdent()))) {
        if (task != null && !task.isCancelled()) {
            task.cancel(true);
        }
        Map<String, String> saved = saveQuery();
        fields = dataSource.getSearchFields(app.getLibrary().getIdent());
        buildSearchForm(savedState != null ? OpacClient.bundleToMap(savedState) : saved);
        savedState = null;
    } else {
        executeNewLoadSearchFieldsTask();
    }
    setAdvanced(false);
}
Also used : SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)

Example 4 with SearchFieldDataSource

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

the class MainPreferenceFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    this.context = getActivity();
    addPreferencesFromResource(R.xml.settings);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH || !context.getPackageManager().hasSystemFeature("android.hardware.nfc")) {
        if (findPreference("nfc_search") != null) {
            findPreference("nfc_search").setEnabled(false);
        }
    }
    Preference assistant = findPreference("accounts");
    assistant.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference arg0) {
            ((OpacClient) context.getApplication()).openAccountList(context);
            return false;
        }
    });
    if (!ebooksSupported()) {
        ((PreferenceCategory) findPreference("cat_web_opac")).removePreference(findPreference("email"));
    }
    CheckBoxPreference notification = (CheckBoxPreference) findPreference("notification_service");
    if (notification != null) {
        notification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                boolean enabled = (Boolean) newValue;
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(enabled);
                return true;
            }
        });
    }
    ListPreference warning = (ListPreference) findPreference("notification_warning");
    if (warning != null) {
        warning.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
                // int oldWarning = Integer.parseInt(prefs.getString("notification_warning",
                // "3"));
                int newWarning = Integer.parseInt((String) newValue);
                new ReminderHelper((OpacClient) getActivity().getApplication()).updateAlarms(newWarning);
                return true;
            }
        });
    }
    Preference meta_run_check = findPreference("meta_run_check");
    if (meta_run_check != null) {
        meta_run_check.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    Preference meta = findPreference("meta_clear");
    if (meta != null) {
        meta.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference arg0) {
                AccountDataSource adata = new AccountDataSource(context);
                adata.invalidateCachedData();
                new ReminderHelper((OpacClient) context.getApplication()).updateAlarms(-1);
                SearchFieldDataSource sfdata = new JsonSearchFieldDataSource(context);
                sfdata.clearAll();
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
                sp.edit().remove("reservation_fee_warning_ignore").apply();
                SyncAccountJob.runImmediately();
                return false;
            }
        });
    }
    final Preference updateLibraryConfig = findPreference("update_library_config");
    if (updateLibraryConfig != null) {
        updateLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                IntentFilter successFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_SUCCESS);
                IntentFilter failureFilter = new IntentFilter(LibraryConfigUpdateService.ACTION_FAILURE);
                BroadcastReceiver receiver = new LibraryConfigServiceReceiver(updateLibraryConfig);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, successFilter);
                LocalBroadcastManager.getInstance(context).registerReceiver(receiver, failureFilter);
                Intent i = new Intent(context, LibraryConfigUpdateService.class);
                context.startService(i);
                DialogFragment newFragment = ProgressDialogFragment.getInstance(R.string.updating_library_config);
                showDialog(newFragment);
                updateLibraryConfig.setEnabled(false);
                return false;
            }
        });
        refreshLastConfigUpdate(updateLibraryConfig);
    }
    final Preference resetLibraryConfig = findPreference("reset_library_config");
    if (resetLibraryConfig != null) {
        PreferenceDataSource prefs = new PreferenceDataSource(getActivity());
        resetLibraryConfig.setEnabled(prefs.hasBundledConfiguration());
        resetLibraryConfig.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                LibraryConfigUpdateService.clearConfigurationUpdates(getContext());
                if (getView() != null) {
                    Snackbar.make(getView(), R.string.library_config_reset, Snackbar.LENGTH_SHORT).show();
                    refreshLastConfigUpdate(updateLibraryConfig);
                }
                return false;
            }
        });
    }
}
Also used : IntentFilter(android.content.IntentFilter) AccountDataSource(de.geeksfactory.opacclient.storage.AccountDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) DialogFragment(android.support.v4.app.DialogFragment) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) BroadcastReceiver(android.content.BroadcastReceiver) ReminderHelper(de.geeksfactory.opacclient.reminder.ReminderHelper) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) PreferenceDataSource(de.geeksfactory.opacclient.storage.PreferenceDataSource) LibraryConfigUpdateService(de.geeksfactory.opacclient.webservice.LibraryConfigUpdateService)

Example 5 with SearchFieldDataSource

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

the class SearchFragment method saveQuery.

public Map<String, String> saveQuery() {
    if (app.getLibrary() == null) {
        return null;
    }
    saveHomeBranch();
    Map<String, String> query = new HashMap<>();
    if (fields == null) {
        SearchFieldDataSource dataSource = new JsonSearchFieldDataSource(app);
        int versionCode = 0;
        try {
            versionCode = app.getPackageManager().getPackageInfo(app.getPackageName(), 0).versionCode;
        } catch (NameNotFoundException e) {
            // should not happen
            e.printStackTrace();
        }
        if (dataSource.hasSearchFields(app.getLibrary().getIdent()) && dataSource.getLastSearchFieldUpdateVersion(app.getLibrary().getIdent()) == versionCode) {
            if (task != null && !task.isCancelled()) {
                task.cancel(true);
            }
            fields = dataSource.getSearchFields(app.getLibrary().getIdent());
            if (fields == null) {
                return null;
            }
        } else {
            return null;
        }
    }
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        if (field instanceof TextSearchField && ((TextSearchField) field).isFreeSearch()) {
            query.put(field.getId(), etSimpleSearch.getEditableText().toString());
            continue;
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (v == null) {
            continue;
        }
        if (field instanceof TextSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            query.put(field.getId(), text.getEditableText().toString());
        } else if (field instanceof BarcodeSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            query.put(field.getId(), text.getEditableText().toString());
        } else if (field instanceof DropdownSearchField) {
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            if (spinner.getSelectedItemPosition() > 0) {
                query.put(field.getId(), ((DropdownSearchField) field).getDropdownValues().get(spinner.getSelectedItemPosition()).getKey());
            }
        } else if (field instanceof CheckboxSearchField) {
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            query.put(field.getId(), String.valueOf(checkbox.isChecked()));
        }
    }
    return query;
}
Also used : EditText(android.widget.EditText) HashMap(java.util.HashMap) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchFieldDataSource(de.geeksfactory.opacclient.storage.SearchFieldDataSource) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) CheckBox(android.widget.CheckBox)

Aggregations

JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)5 SearchFieldDataSource (de.geeksfactory.opacclient.storage.SearchFieldDataSource)5 Intent (android.content.Intent)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)2 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)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 ViewGroup (android.view.ViewGroup)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 Spinner (android.widget.Spinner)1 ReminderHelper (de.geeksfactory.opacclient.reminder.ReminderHelper)1