use of de.geeksfactory.opacclient.searchfields.SearchField 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;
}
}
use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.
the class StarredFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
view = inflater.inflate(R.layout.fragment_starred, container, false);
app = (OpacClient) getActivity().getApplication();
adapter = new ItemListAdapter();
listView = (ListView) view.findViewById(R.id.lvStarred);
tvWelcome = (TextView) view.findViewById(R.id.tvWelcome);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Starred item = (Starred) view.findViewById(R.id.ivDelete).getTag();
if (item.getMNr() == null || item.getMNr().equals("null") || item.getMNr().equals("")) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
List<SearchQuery> query = new ArrayList<>();
List<SearchField> fields = new JsonSearchFieldDataSource(app).getSearchFields(app.getLibrary().getIdent());
if (fields != null) {
SearchField title_field = null, free_field = null;
for (SearchField field : fields) {
if (field.getMeaning() == Meaning.TITLE) {
title_field = field;
} else if (field.getMeaning() == Meaning.FREE) {
free_field = field;
} else if (field.getMeaning() == Meaning.HOME_BRANCH) {
query.add(new SearchQuery(field, sp.getString(OpacClient.PREF_HOME_BRANCH_PREFIX + app.getAccount().getId(), null)));
}
}
if (title_field != null) {
query.add(new SearchQuery(title_field, item.getTitle()));
} else if (free_field != null) {
query.add(new SearchQuery(free_field, item.getTitle()));
}
app.startSearch(getActivity(), query);
} else {
Toast.makeText(getActivity(), R.string.no_search_cache, Toast.LENGTH_LONG).show();
}
} else {
callback.showDetail(item.getMNr());
}
}
});
listView.setClickable(true);
listView.setTextFilterEnabled(true);
getActivity().getSupportLoaderManager().initLoader(0, null, this);
listView.setAdapter(adapter);
// Restore the previously serialized activated item position.
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
setActivateOnItemClick(((OpacActivity) getActivity()).isTablet());
return view;
}
use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.
the class LibraryApiTestCases method scrollTestHelper.
public void scrollTestHelper(String q) throws OpacErrorException, IOException, JSONException {
List<SearchQuery> query = new ArrayList<>();
SearchField field = findFreeSearchOrTitle(fields);
if (field == null) {
throw new // TODO: prevent this
OpacErrorException("There is no free or title search field");
}
query.add(new SearchQuery(field, q));
SearchRequestResult res = api.search(query);
assertTrue(res.getTotal_result_count() == -1 || res.getResults().size() <= res.getTotal_result_count());
assertTrue(res.getResults().size() > 0);
SearchResult third;
if (res.getResults().size() >= 3) {
third = res.getResults().get(2);
} else {
third = res.getResults().get(res.getResults().size() - 1);
}
DetailedItem detail;
if (third.getId() != null) {
detail = api.getResultById(third.getId(), "");
} else {
detail = api.getResult(third.getNr());
}
assertNotNull(detail);
confirmDetail(third, detail);
if (res.getResults().size() < res.getTotal_result_count()) {
api.searchGetPage(2);
SearchResult second = res.getResults().get(1);
DetailedItem detail2;
if (second.getId() != null) {
detail2 = api.getResultById(second.getId(), "");
} else {
detail2 = api.getResult(second.getNr());
}
confirmDetail(second, detail2);
}
}
use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.
the class Littera method addAdvancedSearchFields.
protected void addAdvancedSearchFields(List<SearchField> fields) throws IOException, JSONException {
final String html = httpGet(getApiUrl() + "&mode=a", getDefaultEncoding());
final Document doc = Jsoup.parse(html);
final Elements options = doc.select("select#adv_search_crit_0").first().select("option");
for (final Element option : options) {
final SearchField field;
if (SEARCH_FIELDS_FOR_DROPDOWN.contains(option.val())) {
field = new DropdownSearchField();
addDropdownValuesForField(((DropdownSearchField) field), option.val());
} else {
field = new TextSearchField();
((TextSearchField) field).setHint("");
}
field.setDisplayName(option.text());
field.setId(option.val());
field.setData(new JSONObject());
field.getData().put("meaning", field.getId());
fields.add(field);
}
}
use of de.geeksfactory.opacclient.searchfields.SearchField in project opacclient by opacapp.
the class SISIS method parseSearchFields.
public List<SearchField> parseSearchFields() throws IOException, JSONException {
if (!initialised) {
start();
}
String html = httpGet(opac_url + "/search.do?methodToCall=switchSearchPage&SearchType=2", ENCODING);
Document doc = Jsoup.parse(html);
List<SearchField> fields = new ArrayList<>();
Elements options = doc.select("select[name=searchCategories[0]] option");
for (Element option : options) {
TextSearchField field = new TextSearchField();
field.setDisplayName(option.text());
field.setId(option.attr("value"));
field.setHint("");
fields.add(field);
}
for (Element dropdown : doc.select("#tab-content select")) {
parseDropdown(dropdown, fields);
}
return fields;
}
Aggregations