Search in sources :

Example 1 with QueryParser

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();
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) Query(com.orgzly.android.query.Query) SearchFragment(com.orgzly.android.ui.fragments.SearchFragment) FilterFragment(com.orgzly.android.ui.fragments.FilterFragment) Fragment(android.support.v4.app.Fragment) AgendaFragment(com.orgzly.android.ui.fragments.AgendaFragment) NoteFragment(com.orgzly.android.ui.fragments.NoteFragment) BookFragment(com.orgzly.android.ui.fragments.BookFragment) BookPrefaceFragment(com.orgzly.android.ui.fragments.BookPrefaceFragment) BooksFragment(com.orgzly.android.ui.fragments.BooksFragment) FiltersFragment(com.orgzly.android.ui.fragments.FiltersFragment)

Example 2 with QueryParser

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);
    }
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) Query(com.orgzly.android.query.Query) AgendaCursor(com.orgzly.android.provider.AgendaCursor) Cursor(android.database.Cursor) AgendaCursor(com.orgzly.android.provider.AgendaCursor)

Example 3 with QueryParser

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);
}
Also used : InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) QueryParser(com.orgzly.android.query.QueryParser) InternalQueryParser(com.orgzly.android.query.user.InternalQueryParser) SqlQuery(com.orgzly.android.query.sql.SqlQuery) Query(com.orgzly.android.query.Query) SqlQuery(com.orgzly.android.query.sql.SqlQuery) SqliteQueryBuilder(com.orgzly.android.query.sql.SqliteQueryBuilder) ArrayList(java.util.ArrayList)

Aggregations

Query (com.orgzly.android.query.Query)3 QueryParser (com.orgzly.android.query.QueryParser)3 InternalQueryParser (com.orgzly.android.query.user.InternalQueryParser)3 Cursor (android.database.Cursor)1 Fragment (android.support.v4.app.Fragment)1 AgendaCursor (com.orgzly.android.provider.AgendaCursor)1 SqlQuery (com.orgzly.android.query.sql.SqlQuery)1 SqliteQueryBuilder (com.orgzly.android.query.sql.SqliteQueryBuilder)1 AgendaFragment (com.orgzly.android.ui.fragments.AgendaFragment)1 BookFragment (com.orgzly.android.ui.fragments.BookFragment)1 BookPrefaceFragment (com.orgzly.android.ui.fragments.BookPrefaceFragment)1 BooksFragment (com.orgzly.android.ui.fragments.BooksFragment)1 FilterFragment (com.orgzly.android.ui.fragments.FilterFragment)1 FiltersFragment (com.orgzly.android.ui.fragments.FiltersFragment)1 NoteFragment (com.orgzly.android.ui.fragments.NoteFragment)1 SearchFragment (com.orgzly.android.ui.fragments.SearchFragment)1 ArrayList (java.util.ArrayList)1