Search in sources :

Example 21 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class SRU method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws OpacErrorException, NotReachableException {
    List<SearchField> searchFields = new ArrayList<>();
    Set<String> fieldsCompat = searchQueries.keySet();
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_FREE)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_FREE, "", false, false, "Freie Suche", true, false);
        field.setMeaning(Meaning.FREE);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_TITLE)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_TITLE, "Titel", false, false, "Stichwort", false, false);
        field.setMeaning(Meaning.TITLE);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_AUTHOR)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_AUTHOR, "Verfasser", false, false, "Nachname, Vorname", false, false);
        field.setMeaning(Meaning.AUTHOR);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_PUBLISHER)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_PUBLISHER, "Verlag", false, false, "", false, false);
        field.setMeaning(Meaning.PUBLISHER);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_DIGITAL)) {
        SearchField field = new CheckboxSearchField(KEY_SEARCH_QUERY_DIGITAL, "nur digitale Medien", false);
        field.setMeaning(Meaning.DIGITAL);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_AVAILABLE)) {
        SearchField field = new CheckboxSearchField(KEY_SEARCH_QUERY_AVAILABLE, "nur verfügbare Medien", false);
        field.setMeaning(Meaning.AVAILABLE);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_ISBN)) {
        SearchField field = new BarcodeSearchField(KEY_SEARCH_QUERY_ISBN, "Strichcode", false, false, "ISBN");
        field.setMeaning(Meaning.ISBN);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_BARCODE)) {
        SearchField field = new BarcodeSearchField(KEY_SEARCH_QUERY_BARCODE, "Strichcode", false, true, "Buchungsnr.");
        field.setMeaning(Meaning.BARCODE);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_YEAR)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_YEAR, "Jahr", false, false, "", false, true);
        field.setMeaning(Meaning.YEAR);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_YEAR_RANGE_START)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_START, "Jahr", false, false, "von", false, true);
        field.setMeaning(Meaning.YEAR);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_YEAR_RANGE_END)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_END, "Jahr", false, true, "bis", false, true);
        field.setMeaning(Meaning.YEAR);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_PUBLISHER)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_PUBLISHER, "Verlag", false, false, "", false, false);
        field.setMeaning(Meaning.PUBLISHER);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_KEYWORDA)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_KEYWORDA, "Schlagwort", true, false, "", false, false);
        field.setMeaning(Meaning.KEYWORD);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_KEYWORDB)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_KEYWORDB, "Schlagwort", true, true, "", false, false);
        field.setMeaning(Meaning.KEYWORD);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_SYSTEM)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_SYSTEM, "Systematik", true, false, "", false, false);
        field.setMeaning(Meaning.SYSTEM);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_AUDIENCE)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_AUDIENCE, "Interessenkreis", true, false, "", false, false);
        field.setMeaning(Meaning.AUDIENCE);
        searchFields.add(field);
    }
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_LOCATION)) {
        SearchField field = new TextSearchField(KEY_SEARCH_QUERY_LOCATION, "Ort", false, false, "", false, false);
        field.setMeaning(Meaning.LOCATION);
        searchFields.add(field);
    }
    // noinspection StatementWithEmptyBody
    if (fieldsCompat.contains(KEY_SEARCH_QUERY_ORDER)) {
    // TODO: Implement this (was this even usable before?)
    }
    return searchFields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ArrayList(java.util.ArrayList) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField)

Example 22 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class TestApi method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
    List<SearchField> fields = new ArrayList<>();
    fields.add(new TextSearchField("free", "Freie Suche", false, false, "Freie Suche", true, false));
    return fields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) ArrayList(java.util.ArrayList) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField)

Example 23 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class SearchFragment method clear.

public void clear() {
    if (fields == null)
        return;
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        if (field instanceof TextSearchField && ((TextSearchField) field).isFreeSearch()) {
            etSimpleSearch.setText("");
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (v == null) {
            continue;
        }
        if (field instanceof TextSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            text.setText("");
        } else if (field instanceof BarcodeSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            text.setText("");
        } else if (field instanceof DropdownSearchField) {
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            spinner.setSelection(0);
        } else if (field instanceof CheckboxSearchField) {
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            checkbox.setChecked(false);
        }
    }
}
Also used : EditText(android.widget.EditText) 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) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) CheckBox(android.widget.CheckBox) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 24 with SearchField

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

Example 25 with SearchField

use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.

the class WebOpacNet method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
    List<SearchField> fields = new ArrayList<>();
    // Text fields
    String html = httpGet(opac_url + "/de/mobile/default.aspx", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    Elements options = doc.select("#drpOptSearchT option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setData(new JSONObject("{\"filter\":false}"));
        field.setHint("");
        fields.add(field);
    }
    // Dropdowns
    String text = httpGet(opac_url + "/de/mobile/GetRestrictions.ashx", getDefaultEncoding());
    JSONArray filters = new JSONObject(text).getJSONArray("restrcontainers");
    for (int i = 0; i < filters.length(); i++) {
        JSONObject filter = filters.getJSONObject(i);
        if (filter.getString("querytyp").equals("EJ")) {
            // Querying by year also works for other years than the ones
            // listed
            // -> Make it a text field instead of a dropdown
            TextSearchField field = new TextSearchField();
            field.setDisplayName(filter.getString("kopf"));
            field.setId(filter.getString("querytyp"));
            field.setData(new JSONObject("{\"filter\":true}"));
            field.setHint("");
            fields.add(field);
        } else {
            DropdownSearchField field = new DropdownSearchField();
            field.setId(filter.getString("querytyp"));
            field.setDisplayName(filter.getString("kopf"));
            JSONArray restrictions = filter.getJSONArray("restrictions");
            field.addDropdownValue("", "Alle");
            for (int j = 0; j < restrictions.length(); j++) {
                JSONObject restriction = restrictions.getJSONObject(j);
                field.addDropdownValue(restriction.getString("id"), restriction.getString("bez"));
            }
            field.setData(new JSONObject("{\"filter\":true}"));
            fields.add(field);
        }
    }
    return fields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Aggregations

SearchField (de.geeksfactory.opacclient.searchfields.SearchField)32 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)26 ArrayList (java.util.ArrayList)23 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)22 Document (org.jsoup.nodes.Document)16 Element (org.jsoup.nodes.Element)16 Elements (org.jsoup.select.Elements)15 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)12 JSONObject (org.json.JSONObject)11 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 ViewGroup (android.view.ViewGroup)6 Spinner (android.widget.Spinner)6 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)6 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 IOException (java.io.IOException)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3