use of com.orgzly.android.query.QueryParser in project orgzly-android by orgzly.
the class DisplayManager method displayQuery.
public static void displayQuery(FragmentManager fragmentManager, @NonNull String queryString) {
// If the same query is already displayed, don't do anything.
String displayedQuery = getDisplayedQuery(fragmentManager);
if (displayedQuery != null && displayedQuery.equals(queryString)) {
return;
}
// Parse query
QueryParser queryParser = new InternalQueryParser();
Query query = queryParser.parse(queryString);
Fragment fragment;
String tag;
// Display agenda or query fragment
if (query.getOptions().getAgendaDays() > 0) {
fragment = AgendaFragment.getInstance(queryString);
tag = AgendaFragment.FRAGMENT_TAG;
} else {
fragment = SearchFragment.getInstance(queryString);
tag = SearchFragment.FRAGMENT_TAG;
}
// Add fragment.
fragmentManager.beginTransaction().setCustomAnimations(R.anim.fragment_enter, R.anim.fragment_exit, R.anim.fragment_enter, R.anim.fragment_exit).addToBackStack(null).replace(R.id.single_pane_container, fragment, tag).commit();
}
use of com.orgzly.android.query.QueryParser in project orgzly-android by orgzly.
the class ListWidgetViewsFactory method onDataSetChanged.
@Override
public void onDataSetChanged() {
if (mCursor != null) {
mCursor.close();
}
// Parse query
QueryParser queryParser = new InternalQueryParser();
Query query = queryParser.parse(queryString);
isPartitioned = query.getOptions().getAgendaDays() > 0;
// from http://stackoverflow.com/a/20645908
final long token = Binder.clearCallingIdentity();
try {
if (isPartitioned) {
Cursor cursor = NotesClient.getCursorForQuery(mContext, queryString);
AgendaCursor.AgendaMergedCursor agendaCursor = AgendaCursor.INSTANCE.create(mContext, cursor, queryString);
mCursor = agendaCursor.getCursor();
originalNoteIDs = agendaCursor.getOriginalNoteIDs();
} else {
mCursor = NotesClient.getCursorForQuery(mContext, queryString);
}
} finally {
Binder.restoreCallingIdentity(token);
}
}
use of com.orgzly.android.query.QueryParser in project orgzly-android by orgzly.
the class Provider method runUserQuery.
private Cursor runUserQuery(SQLiteDatabase db, String queryString, String sortOrder) {
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, queryString, sortOrder);
QueryParser parser = new InternalQueryParser();
Query query = parser.parse(queryString);
SqliteQueryBuilder queryBuilder = new SqliteQueryBuilder(getContext());
SqlQuery sqlQuery = queryBuilder.build(query);
// If order hasn't been passed, try getting it from the query.
if (sortOrder == null) {
sortOrder = sqlQuery.getOrderBy();
}
List<String> selections = new ArrayList<>();
// if (!TextUtils.isEmpty(sqlQuery.getSelection())) {
if (query.getCondition() != null) {
selections.add(sqlQuery.getSelection());
}
if (query.getOptions().getAgendaDays() > 0) {
selections.add(DatabaseUtils.WHERE_NOTES_WITH_TIMES);
}
if (!selections.isEmpty() || !query.getSortOrders().isEmpty()) {
selections.add(DatabaseUtils.WHERE_EXISTING_NOTES);
}
String selection = selections.isEmpty() ? "0" : TextUtils.join(" AND ", selections);
String[] selectionArgs = sqlQuery.getSelectionArgs().toArray(new String[sqlQuery.getSelectionArgs().size()]);
if (BuildConfig.LOG_DEBUG)
LogUtils.d(TAG, query, query.getCondition(), sqlQuery.getOrderBy(), selection, selectionArgs, sortOrder);
return db.query(DbNoteView.VIEW_NAME, null, selection, selectionArgs, null, null, sortOrder);
}
Aggregations