Search in sources :

Example 21 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField 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 22 with DropdownSearchField

use of de.geeksfactory.opacclient.searchfields.DropdownSearchField 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 23 with DropdownSearchField

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

Example 24 with DropdownSearchField

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

the class WinBiap method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException {
    // extract branches and categories
    String html = httpGet(opac_url + "/search.aspx", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    Elements mediaGroupOptions = doc.select("[id$=ListBoxMediagroups_ListBoxMultiselection] option");
    Elements branchOptions = doc.select("[id$=MultiSelectionBranch_ListBoxMultiselection] option");
    final DropdownSearchField mediaGroups = new DropdownSearchField(KEY_SEARCH_QUERY_CATEGORY, "Mediengruppe", false, null);
    mediaGroups.setMeaning(Meaning.CATEGORY);
    final DropdownSearchField branches = new DropdownSearchField(KEY_SEARCH_QUERY_BRANCH, "Zweigstelle", false, null);
    branches.setMeaning(Meaning.BRANCH);
    mediaGroups.addDropdownValue("", "Alle");
    branches.addDropdownValue("", "Alle");
    for (Element option : mediaGroupOptions) {
        mediaGroups.addDropdownValue(option.attr("value"), option.text());
    }
    for (Element option : branchOptions) {
        branches.addDropdownValue(option.attr("value"), option.text());
    }
    List<SearchField> searchFields = new ArrayList<>();
    SearchField field = new TextSearchField(KEY_SEARCH_QUERY_FREE, "", false, false, "Beliebig", true, false);
    field.setMeaning(Meaning.FREE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_AUTHOR, "Autor", false, false, "Nachname, Vorname", false, false);
    field.setMeaning(Meaning.AUTHOR);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_TITLE, "Titel", false, false, "Stichwort", false, false);
    field.setMeaning(Meaning.TITLE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_KEYWORDA, "Schlagwort", true, false, "", false, false);
    field.setMeaning(Meaning.KEYWORD);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_AUDIENCE, "Interessenkreis", true, false, "", false, false);
    field.setMeaning(Meaning.AUDIENCE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_SYSTEM, "Systematik", true, false, "", false, false);
    field.setMeaning(Meaning.SYSTEM);
    searchFields.add(field);
    field = new BarcodeSearchField(KEY_SEARCH_QUERY_ISBN, "Strichcode", false, false, "ISBN");
    field.setMeaning(Meaning.ISBN);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_PUBLISHER, "Verlag", false, false, "", false, false);
    field.setMeaning(Meaning.PUBLISHER);
    searchFields.add(field);
    field = new BarcodeSearchField(KEY_SEARCH_QUERY_BARCODE, "Strichcode", false, true, "Mediennummer");
    field.setMeaning(Meaning.BARCODE);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_START, "Jahr", false, false, "von", false, true);
    field.setMeaning(Meaning.YEAR);
    searchFields.add(field);
    field = new TextSearchField(KEY_SEARCH_QUERY_YEAR_RANGE_END, "Jahr", false, true, "bis", false, true);
    field.setMeaning(Meaning.YEAR);
    searchFields.add(field);
    searchFields.add(branches);
    searchFields.add(mediaGroups);
    return searchFields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) Element(org.jsoup.nodes.Element) FormElement(org.jsoup.nodes.FormElement) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 25 with DropdownSearchField

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

the class Zones method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException {
    if (!initialised)
        start();
    List<SearchField> fields = new ArrayList<>();
    String html = httpGet(opac_url + "/APS_ZONES?fn=AdvancedSearch&Style=Portal3&SubStyle=&Lang=GER" + "&ResponseEncoding=utf-8", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    // find text fields
    Elements txt_opts = doc.select("#formSelectTerm_1 option");
    for (Element opt : txt_opts) {
        TextSearchField field = new TextSearchField();
        field.setId(opt.attr("value"));
        field.setHint("");
        field.setDisplayName(opt.text());
        fields.add(field);
    }
    // find filters
    String filtersQuery = version18 ? ".inSearchLimits .floatingBox" : ".TabRechAv .limitBlock";
    Elements filters = doc.select(filtersQuery);
    int i = 0;
    for (Element filter : filters) {
        DropdownSearchField dropdown = new DropdownSearchField();
        dropdown.addDropdownValue("", "Alle");
        // All dropdowns use "q.limits.limit" as URL param, but they must not have the same ID
        dropdown.setId("dropdown_" + i);
        if (version18) {
            dropdown.setDisplayName(filter.select("tr").get(0).text().trim());
            Elements opts = filter.select("tr").get(1).select("table td:has(input)");
            for (Element opt : opts) {
                dropdown.addDropdownValue(opt.select("input").attr("value"), opt.text().trim());
            }
        } else {
            dropdown.setDisplayName(filter.parent().previousElementSibling().text().trim());
            Elements opts = filter.select(".limitChoice label");
            for (Element opt : opts) {
                dropdown.addDropdownValue(opt.attr("for"), opt.text().trim());
            }
        }
        fields.add(dropdown);
        i++;
    }
    return fields;
}
Also used : TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Aggregations

DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)32 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)27 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)21 Element (org.jsoup.nodes.Element)21 ArrayList (java.util.ArrayList)17 Document (org.jsoup.nodes.Document)17 Elements (org.jsoup.select.Elements)16 BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)13 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 JSONObject (org.json.JSONObject)10 ViewGroup (android.view.ViewGroup)6 Spinner (android.widget.Spinner)6 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)6 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)6 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 NotReachableException (de.geeksfactory.opacclient.networking.NotReachableException)3 NameValuePair (org.apache.http.NameValuePair)3