Search in sources :

Example 1 with CheckboxSearchField

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

the class Open method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, OpacErrorException, JSONException {
    String url = opac_url + "/" + data.getJSONObject("urls").getString("advanced_search") + NO_MOBILE;
    Document doc = Jsoup.parse(httpGet(url, getDefaultEncoding()));
    if (doc.select("[id$=LblErrorMsg]").size() > 0 && doc.select("[id$=ContentPane] input").size() == 0) {
        throw new OpacErrorException(doc.select("[id$=LblErrorMsg]").text());
    }
    Element module = doc.select(".ModOPENExtendedSearchModuleC").first();
    List<SearchField> fields = new ArrayList<>();
    JSONObject selectable = new JSONObject();
    selectable.put("selectable", true);
    JSONObject notSelectable = new JSONObject();
    notSelectable.put("selectable", false);
    // Selectable search criteria
    Elements options = module.select("select[id$=FirstSearchField] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setId(option.val());
        field.setDisplayName(option.text());
        field.setData(selectable);
        fields.add(field);
    }
    // More criteria
    Element moreHeader = null;
    if (module.select("table").size() == 1) {
        moreHeader = module.select("span[id$=LblMoreCriterias]").parents().select("tr").first();
    } else {
        // Newer OPEN, e.g. Erlangen
        moreHeader = module.select("span[id$=LblMoreCriterias]").first();
    }
    if (moreHeader != null) {
        Elements siblings = moreHeader.siblingElements();
        int startIndex = moreHeader.elementSiblingIndex();
        for (int i = startIndex; i < siblings.size(); i++) {
            Element tr = siblings.get(i);
            if (tr.select("input, select").size() == 0)
                continue;
            if (tr.select("input[type=text]").size() == 1) {
                Element input = tr.select("input[type=text]").first();
                TextSearchField field = new TextSearchField();
                field.setId(input.attr("name"));
                field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field.setData(notSelectable);
                if (tr.text().contains("nur Ziffern"))
                    field.setNumber(true);
                fields.add(field);
            } else if (tr.select("input[type=text]").size() == 2) {
                Element input1 = tr.select("input[type=text]").get(0);
                Element input2 = tr.select("input[type=text]").get(1);
                TextSearchField field1 = new TextSearchField();
                field1.setId(input1.attr("name"));
                field1.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field1.setData(notSelectable);
                if (tr.text().contains("nur Ziffern"))
                    field1.setNumber(true);
                fields.add(field1);
                TextSearchField field2 = new TextSearchField();
                field2.setId(input2.attr("name"));
                field2.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                field2.setData(notSelectable);
                field2.setHalfWidth(true);
                if (tr.text().contains("nur Ziffern"))
                    field2.setNumber(true);
                fields.add(field2);
            } else if (tr.select("select").size() == 1) {
                Element select = tr.select("select").first();
                DropdownSearchField dropdown = new DropdownSearchField();
                dropdown.setId(select.attr("name"));
                dropdown.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                List<DropdownSearchField.Option> values = new ArrayList<>();
                for (Element option : select.select("option")) {
                    DropdownSearchField.Option opt = new DropdownSearchField.Option(option.val(), option.text());
                    values.add(opt);
                }
                dropdown.setDropdownValues(values);
                fields.add(dropdown);
            } else if (tr.select("input[type=checkbox]").size() == 1) {
                Element checkbox = tr.select("input[type=checkbox]").first();
                CheckboxSearchField field = new CheckboxSearchField();
                field.setId(checkbox.attr("name"));
                field.setDisplayName(tr.select("span[id*=Lbl]").first().text());
                fields.add(field);
            }
        }
    }
    return fields;
}
Also used : 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) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField)

Example 2 with CheckboxSearchField

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

the class Pica method parseSearchFields.

@Override
public List<SearchField> parseSearchFields() throws IOException, JSONException {
    if (!initialised) {
        start();
    }
    String html = httpGet(opac_url + "/LNG=" + getLang() + "/DB=" + db + "/ADVANCED_SEARCHFILTER", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    List<SearchField> fields = new ArrayList<>();
    Elements options = doc.select("select[name=IKT0] option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setHint("");
        field.setData(new JSONObject("{\"ADI\": false}"));
        Pattern pattern = Pattern.compile("(?: --- )?(\\[X?[A-Za-z]{2,3}:?\\]|\\(X?[A-Za-z]{2,3}:?\\))");
        Matcher matcher = pattern.matcher(field.getDisplayName());
        if (matcher.find()) {
            field.getData().put("meaning", matcher.group(1).replace(":", "").toUpperCase());
            field.setDisplayName(matcher.replaceFirst("").trim());
        }
        fields.add(field);
    }
    Elements sort = doc.select("select[name=SRT]");
    if (sort.size() > 0) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName(sort.first().parent().parent().select(".longval").first().text());
        field.setId("SRT");
        for (Element option : sort.select("option")) {
            field.addDropdownValue(option.attr("value"), option.text());
        }
        fields.add(field);
    }
    for (Element input : doc.select("input[type=text][name^=ADI]")) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(input.parent().parent().select(".longkey").text());
        field.setId(input.attr("name"));
        field.setHint(input.parent().select("span").text());
        field.setData(new JSONObject("{\"ADI\": true}"));
        fields.add(field);
    }
    for (Element dropdown : doc.select("select[name^=ADI]")) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName(dropdown.parent().parent().select(".longkey").text());
        field.setId(dropdown.attr("name"));
        for (Element option : dropdown.select("option")) {
            field.addDropdownValue(option.attr("value"), option.text());
        }
        fields.add(field);
    }
    Elements fuzzy = doc.select("input[name=FUZZY]");
    if (fuzzy.size() > 0) {
        CheckboxSearchField field = new CheckboxSearchField();
        field.setDisplayName(fuzzy.first().parent().parent().select(".longkey").first().text());
        field.setId("FUZZY");
        fields.add(field);
    }
    Elements mediatypes = doc.select("input[name=ADI_MAT]");
    if (mediatypes.size() > 0) {
        DropdownSearchField field = new DropdownSearchField();
        field.setDisplayName("Materialart");
        field.setId("ADI_MAT");
        field.addDropdownValue("", "Alle");
        for (Element mt : mediatypes) {
            field.addDropdownValue(mt.attr("value"), mt.parent().nextElementSibling().text().replace("\u00a0", ""));
        }
        fields.add(field);
    }
    return fields;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) 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) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) JSONObject(org.json.JSONObject) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField)

Example 3 with CheckboxSearchField

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

the class SearchFragment method saveSearchQuery.

public List<SearchQuery> saveSearchQuery() {
    saveHomeBranch();
    List<SearchQuery> query = new ArrayList<>();
    if (fields == null || view == null) {
        return null;
    }
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (field instanceof TextSearchField) {
            EditText text;
            if (((TextSearchField) field).isFreeSearch()) {
                text = etSimpleSearch;
            } else {
                if (v == null)
                    continue;
                text = (EditText) v.findViewById(R.id.edittext);
            }
            query.add(new SearchQuery(field, text.getEditableText().toString().trim()));
        } else if (field instanceof BarcodeSearchField) {
            if (v == null)
                continue;
            EditText text = (EditText) v.findViewById(R.id.edittext);
            query.add(new SearchQuery(field, text.getEditableText().toString().trim()));
        } else if (field instanceof DropdownSearchField) {
            if (v == null)
                continue;
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            if (spinner.getSelectedItemPosition() != -1) {
                String key = ((DropdownSearchField) field).getDropdownValues().get(spinner.getSelectedItemPosition()).getKey();
                if (!key.equals("")) {
                    query.add(new SearchQuery(field, key));
                }
            }
        } else if (field instanceof CheckboxSearchField) {
            if (v == null)
                continue;
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            query.add(new SearchQuery(field, String.valueOf(checkbox.isChecked())));
        }
    }
    return query;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) EditText(android.widget.EditText) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) 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) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) CheckBox(android.widget.CheckBox)

Example 4 with CheckboxSearchField

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

the class SearchFragment method buildSearchForm.

protected void buildSearchForm(Map<String, String> restoreQuery) {
    String skey = "annoyed_" + app.getLibrary().getIdent();
    if (app.getLibrary().getReplacedBy() != null && !"".equals(app.getLibrary().getReplacedBy()) && sp.getInt(skey, 0) < 5 && app.promotePlusApps()) {
        rlReplaced.setVisibility(View.VISIBLE);
        ivReplacedStore.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy().replace("https://play.google.com/store/apps/details?id=", "market://details?id=")));
                    startActivity(i);
                } catch (ActivityNotFoundException e) {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(app.getLibrary().getReplacedBy()));
                    startActivity(i);
                }
            }
        });
        sp.edit().putInt(skey, sp.getInt(skey, 0) + 1).apply();
    } else {
        rlReplaced.setVisibility(View.GONE);
    }
    llFormFields.removeAllViews();
    llAdvancedFields.removeAllViews();
    llExpand.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            setAdvanced(!advanced);
        }
    });
    rlSimpleSearch.setVisibility(View.GONE);
    tvSearchAdvHeader.setVisibility(View.GONE);
    int i = 0;
    if (fields == null) {
        return;
    }
    for (final SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        ViewGroup v = null;
        if (field instanceof TextSearchField) {
            TextSearchField textSearchField = (TextSearchField) field;
            if (textSearchField.isFreeSearch()) {
                rlSimpleSearch.setVisibility(View.VISIBLE);
                tvSearchAdvHeader.setVisibility(View.VISIBLE);
                etSimpleSearch.setHint(textSearchField.getHint());
            } else {
                v = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.searchfield_text, llFormFields, false);
                TextView title = (TextView) v.findViewById(R.id.title);
                title.setText(textSearchField.getDisplayName());
                EditText edittext = (EditText) v.findViewById(R.id.edittext);
                edittext.setHint(textSearchField.getHint());
                if (((TextSearchField) field).isNumber()) {
                    edittext.setInputType(InputType.TYPE_CLASS_NUMBER);
                }
                if (((TextSearchField) field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField) fields.get(i - 1)).isFreeSearch())) {
                    ViewGroup before = (ViewGroup) view.findViewWithTag(fields.get(i - 1).getId());
                    llFormFields.removeView(before);
                    llAdvancedFields.removeView(before);
                    v.setTag(field.getId());
                    View together = makeHalfWidth(before, v);
                    v = null;
                    if (field.isAdvanced()) {
                        llAdvancedFields.addView(together);
                    } else {
                        llFormFields.addView(together);
                    }
                }
            }
        } else if (field instanceof BarcodeSearchField) {
            BarcodeSearchField bcSearchField = (BarcodeSearchField) field;
            v = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.searchfield_barcode, llFormFields, false);
            TextView title = (TextView) v.findViewById(R.id.title);
            title.setText(bcSearchField.getDisplayName());
            EditText edittext = (EditText) v.findViewById(R.id.edittext);
            edittext.setHint(bcSearchField.getHint());
            ImageView ivBarcode = (ImageView) v.findViewById(R.id.ivBarcode);
            ivBarcode.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    barcodeScanningField = field.getId();
                    callback.scanBarcode();
                }
            });
            if (((BarcodeSearchField) field).isHalfWidth() && i >= 1 && !(fields.get(i - 1) instanceof TextSearchField && ((TextSearchField) fields.get(i - 1)).isFreeSearch())) {
                ViewGroup before = (ViewGroup) view.findViewWithTag(fields.get(i - 1).getId());
                llFormFields.removeView(before);
                llAdvancedFields.removeView(before);
                v = makeHalfWidth(before, v);
            }
        } else if (field instanceof DropdownSearchField) {
            DropdownSearchField ddSearchField = (DropdownSearchField) field;
            if (ddSearchField.getDropdownValues() == null) {
                continue;
            }
            v = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.searchfield_dropdown, llFormFields, false);
            TextView title = (TextView) v.findViewById(R.id.title);
            title.setText(ddSearchField.getDisplayName());
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            spinner.setAdapter(((OpacActivity) getActivity()).new MetaAdapter<DropdownSearchField.Option>(getActivity(), ddSearchField.getDropdownValues(), R.layout.simple_spinner_item));
            // Load saved home branch
            if (field.getMeaning() == Meaning.HOME_BRANCH) {
                String selection;
                if (sp.contains(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId())) {
                    selection = sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(), "");
                } else {
                    try {
                        selection = app.getLibrary().getData().getString("homebranch");
                    } catch (JSONException e) {
                        selection = "";
                    }
                }
                if (!selection.equals("")) {
                    int j = 0;
                    for (DropdownSearchField.Option row : ddSearchField.getDropdownValues()) {
                        if (row.getKey().equals(selection)) {
                            spinner.setSelection(j);
                        }
                        j++;
                    }
                }
            }
        } else if (field instanceof CheckboxSearchField) {
            CheckboxSearchField cbSearchField = (CheckboxSearchField) field;
            v = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.searchfield_checkbox, llFormFields, false);
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            checkbox.setText(cbSearchField.getDisplayName());
        }
        if (v != null) {
            v.setTag(field.getId());
            if (field.isAdvanced()) {
                llAdvancedFields.addView(v);
            } else {
                llFormFields.addView(v);
            }
        }
        i++;
    }
    llExpand.setVisibility(llAdvancedFields.getChildCount() == 0 ? View.GONE : View.VISIBLE);
    if (restoreQuery != null) {
        loadQuery(restoreQuery);
    }
}
Also used : EditText(android.widget.EditText) BarcodeSearchField(de.geeksfactory.opacclient.searchfields.BarcodeSearchField) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) JSONException(org.json.JSONException) Intent(android.content.Intent) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) 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) CheckboxSearchField(de.geeksfactory.opacclient.searchfields.CheckboxSearchField) ActivityNotFoundException(android.content.ActivityNotFoundException) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 5 with CheckboxSearchField

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

the class SearchFragment method loadQuery.

public void loadQuery(Bundle query) {
    if (query == null) {
        return;
    }
    for (SearchField field : fields) {
        if (!field.isVisible()) {
            continue;
        }
        ViewGroup v = (ViewGroup) view.findViewWithTag(field.getId());
        if (v == null) {
            continue;
        }
        if (field instanceof TextSearchField) {
            EditText text;
            if (((TextSearchField) field).isFreeSearch()) {
                text = etSimpleSearch;
            } else {
                text = (EditText) v.findViewById(R.id.edittext);
            }
            text.setText(query.getString(field.getId()));
        } else if (field instanceof BarcodeSearchField) {
            EditText text = (EditText) v.findViewById(R.id.edittext);
            text.setText(query.getString(field.getId()));
        } else if (field instanceof DropdownSearchField) {
            Spinner spinner = (Spinner) v.findViewById(R.id.spinner);
            int i = 0;
            if (((DropdownSearchField) field).getDropdownValues() == null) {
                continue;
            }
            for (DropdownSearchField.Option map : ((DropdownSearchField) field).getDropdownValues()) {
                if (map.getKey().equals(query.getString(field.getId()))) {
                    spinner.setSelection(i);
                    break;
                }
                i++;
            }
        } else if (field instanceof CheckboxSearchField) {
            CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkbox);
            checkbox.setChecked(Boolean.valueOf(query.getString(field.getId())));
        }
    }
    if (barcodeScanningField != null && scanResult != null) {
        ViewGroup v = (ViewGroup) view.findViewWithTag(barcodeScanningField);
        EditText text = (EditText) v.findViewById(R.id.edittext);
        text.setText(scanResult.getContents());
        barcodeScanningField = null;
        scanResult = null;
    }
}
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)

Aggregations

BarcodeSearchField (de.geeksfactory.opacclient.searchfields.BarcodeSearchField)10 CheckboxSearchField (de.geeksfactory.opacclient.searchfields.CheckboxSearchField)10 TextSearchField (de.geeksfactory.opacclient.searchfields.TextSearchField)10 DropdownSearchField (de.geeksfactory.opacclient.searchfields.DropdownSearchField)9 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)9 ViewGroup (android.view.ViewGroup)5 CheckBox (android.widget.CheckBox)5 EditText (android.widget.EditText)5 Spinner (android.widget.Spinner)5 ArrayList (java.util.ArrayList)4 Document (org.jsoup.nodes.Document)3 Element (org.jsoup.nodes.Element)3 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)2 JSONObject (org.json.JSONObject)2 FormElement (org.jsoup.nodes.FormElement)2 Elements (org.jsoup.select.Elements)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 View (android.view.View)1