Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 048d1a48 authored by Karl Rosaen's avatar Karl Rosaen
Browse files

Show progress spinner while waiting for results in in app search.

parent 9d19fdb2
Loading
Loading
Loading
Loading
+32 −1
Original line number Original line Diff line number Diff line
@@ -83,6 +83,9 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
    // holds the position that, when displayed, should result in notifying the cursor
    // holds the position that, when displayed, should result in notifying the cursor
    int mDisplayNotifyPos = NONE;
    int mDisplayNotifyPos = NONE;


    private final Runnable mStartSpinnerRunnable;
    private final Runnable mStopSpinnerRunnable;

    public SuggestionsAdapter(Context context, SearchDialog searchDialog, SearchableInfo searchable,
    public SuggestionsAdapter(Context context, SearchDialog searchDialog, SearchableInfo searchable,
            WeakHashMap<String, Drawable> outsideDrawablesCache, boolean globalSearchMode) {
            WeakHashMap<String, Drawable> outsideDrawablesCache, boolean globalSearchMode) {
        super(context,
        super(context,
@@ -103,6 +106,18 @@ class SuggestionsAdapter extends ResourceCursorAdapter {


        mOutsideDrawablesCache = outsideDrawablesCache;
        mOutsideDrawablesCache = outsideDrawablesCache;
        mGlobalSearchMode = globalSearchMode;
        mGlobalSearchMode = globalSearchMode;

        mStartSpinnerRunnable = new Runnable() {
                public void run() {
                    mSearchDialog.setWorking(true);
                }
            };

        mStopSpinnerRunnable = new Runnable() {
            public void run() {
                mSearchDialog.setWorking(false);
            }
        };
    }
    }


    /**
    /**
@@ -123,11 +138,27 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        if (DBG) Log.d(LOG_TAG, "runQueryOnBackgroundThread(" + constraint + ")");
        if (DBG) Log.d(LOG_TAG, "runQueryOnBackgroundThread(" + constraint + ")");
        String query = (constraint == null) ? "" : constraint.toString();
        String query = (constraint == null) ? "" : constraint.toString();
        if (!mGlobalSearchMode) {
            /**
             * for in app search we show the progress spinner until the cursor is returned with
             * the results.  for global search we manage the progress bar using
             * {@link DialogCursorProtocol#POST_REFRESH_RECEIVE_ISPENDING}.
             */
            mSearchDialog.getWindow().getDecorView().post(mStartSpinnerRunnable);
        }
        try {
        try {
            return SearchManager.getSuggestions(mContext, mSearchable, query);
            final Cursor cursor = SearchManager.getSuggestions(mContext, mSearchable, query);
            // trigger fill window so the spinner stays up until the results are copied over and
            // closer to being ready
            if (!mGlobalSearchMode) cursor.getCount();
            return cursor;
        } catch (RuntimeException e) {
        } catch (RuntimeException e) {
            Log.w(LOG_TAG, "Search suggestions query threw an exception.", e);
            Log.w(LOG_TAG, "Search suggestions query threw an exception.", e);
            return null;
            return null;
        } finally {
            if (!mGlobalSearchMode) {
                mSearchDialog.getWindow().getDecorView().post(mStopSpinnerRunnable);
            }
        }
        }
    }
    }