浏览代码

Merge pull request #13068 from nextcloud/uploadFilter

Upload filter
Alper Öztürk 9 月之前
父节点
当前提交
78e8294132

二进制
app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_search.png


+ 46 - 0
app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt

@@ -8,9 +8,16 @@
 package com.owncloud.android.ui.activity
 
 import android.content.Intent
+import androidx.annotation.UiThread
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.IdlingRegistry
+import androidx.test.espresso.assertion.ViewAssertions.matches
 import androidx.test.espresso.intent.rule.IntentsTestRule
+import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
+import androidx.test.espresso.matcher.ViewMatchers.isRoot
 import com.nextcloud.test.GrantStoragePermissionRule
 import com.owncloud.android.AbstractIT
+import com.owncloud.android.utils.EspressoIdlingResource
 import com.owncloud.android.utils.FileStorageUtils
 import com.owncloud.android.utils.ScreenshotTest
 import org.junit.After
@@ -20,6 +27,8 @@ import org.junit.Test
 import java.io.File
 
 class UploadFilesActivityIT : AbstractIT() {
+    private val testClassName = "com.owncloud.android.ui.activity.UploadFilesActivityIT"
+
     @get:Rule
     var activityRule = IntentsTestRule(UploadFilesActivity::class.java, true, false)
 
@@ -39,6 +48,16 @@ class UploadFilesActivityIT : AbstractIT() {
         directories.forEach { it.deleteRecursively() }
     }
 
+    @Before
+    fun registerIdlingResource() {
+        IdlingRegistry.getInstance().register(EspressoIdlingResource.countingIdlingResource)
+    }
+
+    @After
+    fun unregisterIdlingResource() {
+        IdlingRegistry.getInstance().unregister(EspressoIdlingResource.countingIdlingResource)
+    }
+
     @Test
     @ScreenshotTest
     fun noneSelected() {
@@ -88,6 +107,33 @@ class UploadFilesActivityIT : AbstractIT() {
         screenshot(sut)
     }
 
+    @Test
+    @UiThread
+    @ScreenshotTest
+    fun search() {
+        val sut: UploadFilesActivity = activityRule.launchActivity(null)
+
+        sut.runOnUiThread {
+            sut.fileListFragment.setFiles(
+                directories +
+                    listOf(
+                        File("1.txt"),
+                        File("2.pdf"),
+                        File("3.mp3")
+                    )
+            )
+
+            onIdleSync {
+                EspressoIdlingResource.increment()
+                sut.fileListFragment.performSearch("1.txt", arrayListOf(), false)
+                EspressoIdlingResource.decrement()
+                val screenShotName = createName(testClassName + "_" + "search", "")
+                onView(isRoot()).check(matches(isDisplayed()))
+                screenshotViaName(sut, screenShotName)
+            }
+        }
+    }
+
     fun fileSelected() {
         val sut: UploadFilesActivity = activityRule.launchActivity(null)
 

+ 1 - 0
app/src/main/java/com/nextcloud/client/etm/pages/EtmBackgroundJobsFragment.kt

@@ -80,6 +80,7 @@ class EtmBackgroundJobsFragment : EtmBaseFragment(), Injectable {
 
         private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:MM:ssZ", Locale.getDefault())
         var backgroundJobs: List<JobInfo> = emptyList()
+            @SuppressLint("NotifyDataSetChanged")
             set(value) {
                 field = value
                 notifyDataSetChanged()

+ 15 - 5
app/src/main/java/com/owncloud/android/ui/fragment/ExtendedListFragment.java

@@ -246,6 +246,10 @@ public class ExtendedListFragment extends Fragment implements
             performSearch(query, listOfHiddenFiles, false);
             return true;
         }
+        if (adapter instanceof LocalFileListAdapter) {
+            performSearch(query, new ArrayList<>(), false);
+            return true;
+        }
         return false;
     }
 
@@ -253,6 +257,7 @@ public class ExtendedListFragment extends Fragment implements
         handler.removeCallbacksAndMessages(null);
         RecyclerView.Adapter adapter = getRecyclerView().getAdapter();
         Activity activity = getActivity();
+
         if (activity != null) {
             if (activity instanceof FileDisplayActivity) {
                 if (isBackPressed && TextUtils.isEmpty(query)) {
@@ -274,8 +279,7 @@ public class ExtendedListFragment extends Fragment implements
                                     new SearchEvent(query, SearchRemoteOperation.SearchType.FILE_SEARCH)
                                                           );
                             }
-                        } else if (adapter instanceof LocalFileListAdapter) {
-                            LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
+                        } else if (adapter instanceof LocalFileListAdapter localFileListAdapter) {
                             localFileListAdapter.filter(query);
                         }
                     });
@@ -284,10 +288,12 @@ public class ExtendedListFragment extends Fragment implements
                         searchView.clearFocus();
                     }
                 }
-            } else if (activity instanceof UploadFilesActivity) {
+            } else if (activity instanceof UploadFilesActivity uploadFilesActivity) {
                 LocalFileListAdapter localFileListAdapter = (LocalFileListAdapter) adapter;
-                localFileListAdapter.filter(query);
-                ((UploadFilesActivity) activity).showToolbarSpinner();
+                if (localFileListAdapter != null) {
+                    localFileListAdapter.filter(query);
+                    uploadFilesActivity.getFileListFragment().setLoading(false);
+                }
             } else if (activity instanceof FolderPickerActivity) {
                 ((FolderPickerActivity) activity).search(query);
             }
@@ -630,6 +636,10 @@ public class ExtendedListFragment extends Fragment implements
                     setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
                                            R.string.file_list_empty_gallery,
                                            R.drawable.file_image);
+                } else if (searchType == SearchType.LOCAL_SEARCH) {
+                    setMessageForEmptyList(R.string.file_list_empty_headline_server_search,
+                                           R.string.file_list_empty_local_search,
+                                           R.drawable.ic_search_light_grey);
                 }
             }
         });

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java

@@ -374,7 +374,7 @@ public class LocalFileListFragment extends ExtendedListFragment implements
             new Handler().post(() -> {
                 mAdapter.notifyDataSetChanged();
                 if (mAdapter.getFilesCount() == 0) {
-                    setEmptyListMessage(SearchType.NO_SEARCH);
+                    setEmptyListMessage(SearchType.LOCAL_SEARCH);
                 }
             });
         }

+ 1 - 0
app/src/main/java/com/owncloud/android/ui/fragment/SearchType.kt

@@ -13,6 +13,7 @@ import kotlinx.parcelize.Parcelize
 @Parcelize
 enum class SearchType : Parcelable {
     NO_SEARCH,
+    LOCAL_SEARCH,
     REGULAR_FILTER,
     FILE_SEARCH,
     FAVORITE_SEARCH,

+ 1 - 2
app/src/main/res/values/strings.xml

@@ -1213,8 +1213,7 @@
     <string name="sub_folder_rule_day">Year/Month/Day</string>
     <string name="secure_share_not_set_up">Secure sharing is not set up for this user</string>
     <string name="share_not_allowed_when_file_drop">Resharing is not allowed during secure file drop</string>
-
-
+    <string name="file_list_empty_local_search">No file or folder matching your search</string>
     <string name="unified_search_fragment_calendar_event_not_found">Event not found, you can always sync to update. Redirecting to web…</string>
     <string name="unified_search_fragment_contact_not_found">Contact not found, you can always sync to update. Redirecting to web…</string>
     <string name="unified_search_fragment_permission_needed">Permissions are required to open search result otherwise it will redirected to web…</string>