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