Search in sources :

Example 1 with Starred

use of de.geeksfactory.opacclient.objects.Starred in project opacclient by opacapp.

the class StarDataSource method getItem.

public Starred getItem(String bib, String id) {
    String[] selA = { bib, id };
    Cursor cursor = context.getContentResolver().query(((OpacClient) context.getApplication()).getStarProviderStarUri(), StarDatabase.COLUMNS, StarDatabase.STAR_WHERE_NR_LIB, selA, null);
    Starred item = null;
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        item = cursorToItem(cursor);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return item;
}
Also used : Cursor(android.database.Cursor) Starred(de.geeksfactory.opacclient.objects.Starred)

Example 2 with Starred

use of de.geeksfactory.opacclient.objects.Starred in project opacclient by opacapp.

the class StarDataSource method getItemByTitle.

public Starred getItemByTitle(String bib, String title) {
    String[] selA = { bib, title };
    Cursor cursor = context.getContentResolver().query(((OpacClient) context.getApplication()).getStarProviderStarUri(), StarDatabase.COLUMNS, StarDatabase.STAR_WHERE_TITLE_LIB, selA, null);
    Starred item = null;
    cursor.moveToFirst();
    if (!cursor.isAfterLast()) {
        item = cursorToItem(cursor);
        cursor.moveToNext();
    }
    // Make sure to close the cursor
    cursor.close();
    return item;
}
Also used : Cursor(android.database.Cursor) Starred(de.geeksfactory.opacclient.objects.Starred)

Example 3 with Starred

use of de.geeksfactory.opacclient.objects.Starred in project opacclient by opacapp.

the class StarDataSource method cursorToItem.

public static Starred cursorToItem(Cursor cursor) {
    Starred item = new Starred();
    item.setId(cursor.getInt(0));
    item.setMNr(cursor.getString(1));
    item.setTitle(cursor.getString(3));
    try {
        item.setMediaType(cursor.getString(4) != null ? SearchResult.MediaType.valueOf(cursor.getString(4)) : null);
    } catch (IllegalArgumentException e) {
    // Do not crash on invalid media types stored in the database
    }
    return item;
}
Also used : Starred(de.geeksfactory.opacclient.objects.Starred)

Example 4 with Starred

use of de.geeksfactory.opacclient.objects.Starred in project opacclient by opacapp.

the class StarredFragment method share.

protected void share() {
    Intent intent = new Intent(android.content.Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.addFlags(CompatibilityUtils.getNewDocumentIntentFlag());
    StringBuilder text = new StringBuilder();
    StarDataSource data = new StarDataSource(getActivity());
    List<Starred> items = data.getAllItems(app.getLibrary().getIdent());
    for (Starred item : items) {
        text.append(item.getTitle());
        text.append("\n");
        String shareUrl;
        try {
            shareUrl = app.getApi().getShareUrl(item.getMNr(), item.getTitle());
        } catch (OpacClient.LibraryRemovedException e) {
            return;
        }
        if (shareUrl != null) {
            text.append(shareUrl);
            text.append("\n");
        }
        text.append("\n");
    }
    intent.putExtra(Intent.EXTRA_TEXT, text.toString().trim());
    startActivity(Intent.createChooser(intent, getResources().getString(R.string.share)));
}
Also used : OpacClient(de.geeksfactory.opacclient.OpacClient) Intent(android.content.Intent) Starred(de.geeksfactory.opacclient.objects.Starred) StarDataSource(de.geeksfactory.opacclient.storage.StarDataSource)

Example 5 with Starred

use of de.geeksfactory.opacclient.objects.Starred 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)

Aggregations

Starred (de.geeksfactory.opacclient.objects.Starred)8 Cursor (android.database.Cursor)4 StarDataSource (de.geeksfactory.opacclient.storage.StarDataSource)2 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 OpacClient (de.geeksfactory.opacclient.OpacClient)1 SearchField (de.geeksfactory.opacclient.searchfields.SearchField)1 SearchQuery (de.geeksfactory.opacclient.searchfields.SearchQuery)1 JsonSearchFieldDataSource (de.geeksfactory.opacclient.storage.JsonSearchFieldDataSource)1 List (java.util.List)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1