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;
}
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;
}
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;
}
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);
}
}
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;
}
}
Aggregations