diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_localFolderPickerMode.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_localFolderPickerMode.png new file mode 100644 index 0000000000..b66bacedc9 Binary files /dev/null and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_localFolderPickerMode.png differ diff --git a/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_noneSelected.png b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_noneSelected.png new file mode 100644 index 0000000000..2dbf5b3fb3 Binary files /dev/null and b/app/screenshots/gplay/debug/com.owncloud.android.ui.activity.UploadFilesActivityIT_noneSelected.png differ diff --git a/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt index 703d0f1597..245852530f 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt @@ -21,20 +21,83 @@ */ package com.owncloud.android.ui.activity +import android.content.Intent import androidx.test.espresso.intent.rule.IntentsTestRule +import com.nextcloud.client.GrantStoragePermissionRule import com.owncloud.android.AbstractIT +import com.owncloud.android.utils.FileStorageUtils +import com.owncloud.android.utils.ScreenshotTest +import org.junit.After +import org.junit.Before import org.junit.Rule import org.junit.Test +import java.io.File class UploadFilesActivityIT : AbstractIT() { @get:Rule var activityRule = IntentsTestRule(UploadFilesActivity::class.java, true, false) + @get:Rule + var permissionRule = GrantStoragePermissionRule.grant() + + private val directories = listOf("A", "B", "C", "D") + .map { File("${FileStorageUtils.getTemporalPath(account.name)}${File.separator}$it") } + + @Before + fun setUp() { + directories.forEach { it.mkdirs() } + } + + @After + fun tearDown() { + directories.forEach { it.deleteRecursively() } + } + @Test - // @ScreenshotTest // TODO re-enable and make sure that folder content on emulator is the same on all devices + @ScreenshotTest fun noneSelected() { val sut: UploadFilesActivity = activityRule.launchActivity(null) + sut.runOnUiThread { + sut.fileListFragment.setFiles( + directories + + listOf( + File("1.txt"), + File("2.pdf"), + File("3.mp3") + ) + ) + } + + waitForIdleSync() + + screenshot(sut) + } + + @Test + @ScreenshotTest + fun localFolderPickerMode() { + val sut: UploadFilesActivity = activityRule.launchActivity( + Intent().apply { + putExtra( + UploadFilesActivity.KEY_LOCAL_FOLDER_PICKER_MODE, + true + ) + putExtra( + UploadFilesActivity.REQUEST_CODE_KEY, + FileDisplayActivity.REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM + ) + } + ) + + sut.runOnUiThread { + sut.fileListFragment.setFiles( + directories + ) + } + + waitForIdleSync() + screenshot(sut) } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java index 50766642d1..92cff9401c 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/UploadFilesActivity.java @@ -70,6 +70,7 @@ import java.util.List; import javax.inject.Inject; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; import androidx.core.view.MenuItemCompat; @@ -117,6 +118,12 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList private Spinner mBehaviourSpinner; private MaterialButton uploadButton; + + @VisibleForTesting + public LocalFileListFragment getFileListFragment() { + return mFileListFragment; + } + /** * Helper to launch the UploadFilesActivity for which you would like a result when it finished. Your * onActivityResult() method will be called with the given requestCode. @@ -189,7 +196,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList uploadButton = findViewById(R.id.upload_files_btn_upload); ThemeButtonUtils.colorPrimaryButton(uploadButton, this); uploadButton.setOnClickListener(this); - uploadButton.setEnabled(false); + uploadButton.setEnabled(mLocalFolderPickerMode); int localBehaviour = preferences.getUploaderBehaviour(); @@ -458,7 +465,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList private void updateUploadButtonActive() { final boolean anySelected = mFileListFragment.getCheckedFilesCount() > 0; - uploadButton.setEnabled(anySelected); + uploadButton.setEnabled(anySelected || mLocalFolderPickerMode); } private void setSelectAllMenuItem(MenuItem selectAll, boolean checked) { @@ -600,7 +607,7 @@ public class UploadFilesActivity extends DrawerActivity implements LocalFileList */ @Override public void onFileClick(File file) { - uploadButton.setEnabled(mFileListFragment.getCheckedFilesCount() > 0); + updateUploadButtonActive(); boolean selectAll = mFileListFragment.getCheckedFilesCount() == mFileListFragment.getFilesCount(); setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), selectAll); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index caf81ac076..e04b2b6ed7 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -54,6 +54,7 @@ import java.util.Set; import java.util.concurrent.Executors; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.RecyclerView; /** @@ -159,31 +160,34 @@ public class LocalFileListAdapter extends RecyclerView.Adapter localFileListFragmentInterface + .onItemCheckboxClicked(finalFile)); } gridViewHolder.thumbnail.setTag(file.hashCode()); setThumbnail(file, gridViewHolder.thumbnail, mContext); - gridViewHolder.checkbox.setVisibility(View.VISIBLE); - - File finalFile = file; gridViewHolder.itemLayout.setOnClickListener(v -> localFileListFragmentInterface - .onItemClicked(finalFile)); - gridViewHolder.checkbox.setOnClickListener(v -> localFileListFragmentInterface - .onItemCheckboxClicked(finalFile)); - + .onItemClicked(finalFile)); if (holder instanceof LocalFileListItemViewHolder) { LocalFileListItemViewHolder itemViewHolder = (LocalFileListItemViewHolder) holder; @@ -521,4 +525,14 @@ public class LocalFileListAdapter extends RecyclerView.Adapter newFiles) { + mFiles = newFiles; + mFilesAll = new ArrayList<>(); + mFilesAll.addAll(mFiles); + + notifyDataSetChanged(); + localFileListFragmentInterface.setLoading(false); + } } diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java index c8c70111f1..18cd6fa7e0 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/LocalFileListFragment.java @@ -41,10 +41,12 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileSortOrder; import java.io.File; +import java.util.List; import javax.inject.Inject; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -377,13 +379,18 @@ public class LocalFileListFragment extends ExtendedListFragment implements // ugly hack because setEmptyListLoadingMessage also uses a handler and there's a race condition otherwise new Handler().post(() -> { mAdapter.notifyDataSetChanged(); - if(mAdapter.getFilesCount() == 0){ + if (mAdapter.getFilesCount() == 0) { setEmptyListMessage(SearchType.NO_SEARCH); } }); } } + @VisibleForTesting + public void setFiles(List newFiles) { + mAdapter.setFiles(newFiles); + } + /** * Interface to implement by any Activity that includes some instance of LocalFileListFragment */ diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 53a274896e..d8560d5c66 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -626 \ No newline at end of file +627 diff --git a/scripts/analysis/lint-results.txt b/scripts/analysis/lint-results.txt index 2d857a44dc..7a5728da39 100644 --- a/scripts/analysis/lint-results.txt +++ b/scripts/analysis/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 92 warnings + Lint Report: 93 warnings