Skip to content

Commit

Permalink
Merge pull request #13068 from nextcloud/uploadFilter
Browse files Browse the repository at this point in the history
Upload filter
  • Loading branch information
alperozturk96 authored Aug 15, 2024
2 parents 9eef9dd + f0e3572 commit 78e8294
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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() {
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,18 @@ public boolean onQueryTextSubmit(String query) {
performSearch(query, listOfHiddenFiles, false);
return true;
}
if (adapter instanceof LocalFileListAdapter) {
performSearch(query, new ArrayList<>(), false);
return true;
}
return false;
}

public void performSearch(final String query, final ArrayList<String> listOfHiddenFiles, boolean isBackPressed) {
handler.removeCallbacksAndMessages(null);
RecyclerView.Adapter adapter = getRecyclerView().getAdapter();
Activity activity = getActivity();

if (activity != null) {
if (activity instanceof FileDisplayActivity) {
if (isBackPressed && TextUtils.isEmpty(query)) {
Expand All @@ -274,8 +279,7 @@ public void performSearch(final String query, final ArrayList<String> listOfHidd
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);
}
});
Expand All @@ -284,10 +288,12 @@ public void performSearch(final String query, final ArrayList<String> listOfHidd
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);
}
Expand Down Expand Up @@ -630,6 +636,10 @@ public void run() {
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);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void setLoading(boolean enabled) {
new Handler().post(() -> {
mAdapter.notifyDataSetChanged();
if (mAdapter.getFilesCount() == 0) {
setEmptyListMessage(SearchType.NO_SEARCH);
setEmptyListMessage(SearchType.LOCAL_SEARCH);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import kotlinx.parcelize.Parcelize
@Parcelize
enum class SearchType : Parcelable {
NO_SEARCH,
LOCAL_SEARCH,
REGULAR_FILTER,
FILE_SEARCH,
FAVORITE_SEARCH,
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 78e8294

Please sign in to comment.