OSDN Git Service

Search: Fix race condition with results display
authorStephen Bird <sbird@cyngn.com>
Mon, 24 Aug 2015 23:19:05 +0000 (16:19 -0700)
committerStephen Bird <sbird@cyngn.com>
Wed, 26 Aug 2015 21:22:58 +0000 (14:22 -0700)
Since results are now run through an asynctask before they are added
this created a race condition which lead to the screen sometimes
showing 'no results found' when results are actually available

Ticket: QRDL-995
Change-Id: I5b7ddb44c16603fac7ceca3f955038cc3d646de8

src/com/cyanogenmod/filemanager/activities/SearchActivity.java

index e87c63c..1ced5f9 100755 (executable)
@@ -249,14 +249,10 @@ public class SearchActivity extends Activity
                     try {
                         mExecutable = null;
                         mAdapter.stopStreaming();
-                        int resultsSize = mAdapter.resultsSize();
                         mStreamingSearchProgress.setVisibility(View.INVISIBLE);
                         if (mMimeTypeCategories != null && mMimeTypeCategories.size() > 1) {
                             mMimeTypeSpinner.setVisibility(View.VISIBLE);
                         }
-                        mSearchListView.setVisibility(resultsSize > 0 ? View.VISIBLE : View.GONE);
-                        mEmptyListMsg.setVisibility(resultsSize > 0 ? View.GONE : View.VISIBLE);
-
                     } catch (Throwable ex) {
                         Log.e(TAG, "onAsyncEnd method fails", ex); //$NON-NLS-1$
                     }
@@ -271,7 +267,6 @@ public class SearchActivity extends Activity
         @SuppressWarnings("unchecked")
         public void onConcurrentPartialResult(final Object partialResults) {
             //Saved in the global result list, for save at the end
-            FileSystemObject result = null;
             if (partialResults instanceof FileSystemObject) {
                 FileSystemObject fso = (FileSystemObject) partialResults;
                 if (mMimeTypeCategories == null || mMimeTypeCategories.contains(MimeTypeHelper
@@ -289,24 +284,6 @@ public class SearchActivity extends Activity
                     }
                 }
             }
-
-            //Notify progress
-            mSearchListView.post(new Runnable() {
-                @Override
-                public void run() {
-                    int progress = mAdapter.resultsSize();
-                    String foundItems =
-                            getResources().
-                                    getQuantityString(
-                                            R.plurals.search_found_items, progress,
-                                            Integer.valueOf(progress) );
-                    mSearchFoundItems.setText(
-                            getString(
-                                    R.string.search_found_items_in_directory,
-                                    foundItems,
-                                    mSearchDirectory));
-                }
-            });
         }
 
         /**
@@ -837,7 +814,7 @@ public class SearchActivity extends Activity
                     DialogHelper.showToast(
                             SearchActivity.this,
                             R.string.search_error_msg, Toast.LENGTH_SHORT);
-                    SearchActivity.this.mSearchListView.setVisibility(View.GONE);
+                    toggleResults(false, true);
                 }
             }
         });
@@ -880,14 +857,21 @@ public class SearchActivity extends Activity
         }
 
         @Override
-        protected void onPostExecute(Boolean sucess) {
+        protected void onPostExecute(Boolean success) {
             SearchActivity activity = mActivity.get();
             if (activity == null) {
                 return;
             }
-            if (sucess) {
+            if (success) {
                 // add to adapter
                 activity.mAdapter.addNewItem(mHolder);
+                int progress = activity.mAdapter.resultsSize();
+                activity.toggleResults(progress > 0, false);
+                String foundItems = activity.getResources().getQuantityString(
+                        R.plurals.search_found_items, progress, progress);
+                activity.mSearchFoundItems.setText(activity.getString(
+                        R.string.search_found_items_in_directory,
+                        foundItems, activity.mSearchDirectory));
             }
         }
     }