Search in sources :

Example 16 with SearchField

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;
    }
}
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 17 with SearchField

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;
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) JsonSearchFieldDataSource(de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) List(java.util.List) ArrayList(java.util.ArrayList) Starred(de.geeksfactory.opacclient.objects.Starred)

Example 18 with SearchField

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);
    }
}
Also used : SearchQuery(de.geeksfactory.opacclient.searchfields.SearchQuery) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) SearchField(de.geeksfactory.opacclient.searchfields.SearchField) SearchRequestResult(de.geeksfactory.opacclient.objects.SearchRequestResult) ArrayList(java.util.ArrayList) OpacErrorException(de.geeksfactory.opacclient.apis.OpacApi.OpacErrorException) SearchResult(de.geeksfactory.opacclient.objects.SearchResult) DetailedItem(de.geeksfactory.opacclient.objects.DetailedItem)

Example 19 with SearchField

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);
    }
}
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) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField)

Example 20 with SearchField

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;
}
Also used : SearchField(de.geeksfactory.opacclient.searchfields.SearchField) TextSearchField(de.geeksfactory.opacclient.searchfields.TextSearchField) DropdownSearchField(de.geeksfactory.opacclient.searchfields.DropdownSearchField) 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)

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