Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/androidTest/assets/videoFile.mp4
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.owncloud.android.lib.resources.files.SearchRemoteOperation.SearchType.GALLERY_SEARCH;
import static com.owncloud.android.lib.resources.files.SearchRemoteOperation.SearchType.PHOTO_SEARCH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand All @@ -60,7 +61,7 @@ abstract public class FileDataStorageManagerTest extends AbstractOnServerIT {
public void before() {
// make sure everything is removed
sut.deleteAllFiles();
sut.deleteVirtuals(VirtualFolderType.PHOTOS);
sut.deleteVirtuals(VirtualFolderType.GALLERY);

assertEquals(0, sut.getAllFiles().size());
}
Expand All @@ -70,7 +71,7 @@ public void after() {
super.after();

sut.deleteAllFiles();
sut.deleteVirtuals(VirtualFolderType.PHOTOS);
sut.deleteVirtuals(VirtualFolderType.GALLERY);
}

@Test
Expand Down Expand Up @@ -147,7 +148,7 @@ public void testFolderContent() throws IOException {
@Test
public void testPhotoSearch() throws IOException {
String remotePath = "/imageFile.png";
VirtualFolderType virtualType = VirtualFolderType.PHOTOS;
VirtualFolderType virtualType = VirtualFolderType.GALLERY;

assertEquals(0, sut.getFolderContent(sut.getFileByPath("/"), false).size());
assertEquals(1, sut.getAllFiles().size());
Expand Down Expand Up @@ -207,6 +208,82 @@ public void testPhotoSearch() throws IOException {
sut.getFolderContent(sut.getFileByPath("/"), false).get(0));
}

/**
* This test creates an image and a video, does a gallery search (now returned image and video is not yet in file
* hierarchy), then root folder is refreshed and it is verified that the same image file is used in database
*/
@Test
public void testGallerySearch() throws IOException {
String remotePath = "/imageFile.png";
VirtualFolderType virtualType = VirtualFolderType.GALLERY;

assertEquals(0, sut.getFolderContent(sut.getFileByPath("/"), false).size());
assertEquals(1, sut.getAllFiles().size());

File imageFile = getFile("imageFile.png");
assertTrue(new UploadFileRemoteOperation(imageFile.getAbsolutePath(),
remotePath,
"image/png",
String.valueOf(System.currentTimeMillis() / 1000))
.execute(client).isSuccess());

assertNull(sut.getFileByPath(remotePath));

File videoFile = getFile("videoFile.mp4");
assertTrue(new UploadFileRemoteOperation(videoFile.getAbsolutePath(),
remotePath,
"video/mpeg",
String.valueOf(System.currentTimeMillis() / 1000))
.execute(client).isSuccess());

assertNull(sut.getFileByPath(remotePath));

// search
SearchRemoteOperation searchRemoteOperation = new SearchRemoteOperation("",
GALLERY_SEARCH,
false);

RemoteOperationResult searchResult = searchRemoteOperation.execute(client);
TestCase.assertTrue(searchResult.isSuccess());
TestCase.assertEquals(1, searchResult.getData().size());

OCFile ocFile = FileStorageUtils.fillOCFile((RemoteFile) searchResult.getData().get(0));
sut.saveFile(ocFile);

List<ContentValues> contentValues = new ArrayList<>();
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_TYPE, virtualType.toString());
cv.put(ProviderMeta.ProviderTableMeta.VIRTUAL_OCFILE_ID, ocFile.getFileId());

contentValues.add(cv);

sut.saveVirtuals(contentValues);

assertEquals(remotePath, ocFile.getRemotePath());

assertEquals(0, sut.getFolderContent(sut.getFileByPath("/"), false).size());

assertEquals(2, sut.getVirtualFolderContent(virtualType, false).size());
assertEquals(3, sut.getAllFiles().size());

// update root
assertTrue(new RefreshFolderOperation(sut.getFileByPath("/"),
System.currentTimeMillis() / 1000,
false,
false,
sut,
account,
targetContext).execute(client).isSuccess());


assertEquals(1, sut.getFolderContent(sut.getFileByPath("/"), false).size());
assertEquals(2, sut.getVirtualFolderContent(virtualType, false).size());
assertEquals(3, sut.getAllFiles().size());

assertEquals(sut.getVirtualFolderContent(virtualType, false).get(0),
sut.getFolderContent(sut.getFileByPath("/"), false).get(0));
}

@Test
public void testSaveNewFile() {
assertTrue(new CreateFolderRemoteOperation("/1/1/", true).execute(client).isSuccess());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nextcloud/client/di/ComponentsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
import com.owncloud.android.ui.fragment.FileDetailActivitiesFragment;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileDetailSharingFragment;
import com.owncloud.android.ui.fragment.GalleryFragment;
import com.owncloud.android.ui.fragment.LocalFileListFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
import com.owncloud.android.ui.fragment.contactsbackup.ContactsBackupFragment;
import com.owncloud.android.ui.preview.PreviewImageActivity;
Expand Down Expand Up @@ -181,7 +181,7 @@ abstract class ComponentsModule {
abstract PreviewTextStringFragment previewTextStringFragment();

@ContributesAndroidInjector
abstract PhotoFragment photoFragment();
abstract GalleryFragment photoFragment();

@ContributesAndroidInjector
abstract MultipleAccountsDialog multipleAccountsDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
* Type for virtual folders
*/
public enum VirtualFolderType {
FAVORITE, PHOTOS, NONE
FAVORITE, GALLERY, NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
import com.owncloud.android.ui.events.ChangeMenuEvent;
import com.owncloud.android.ui.events.DummyDrawerEvent;
import com.owncloud.android.ui.events.SearchEvent;
import com.owncloud.android.ui.fragment.GalleryFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.preview.PreviewTextStringFragment;
import com.owncloud.android.ui.trashbin.TrashbinActivity;
import com.owncloud.android.utils.DisplayUtils;
Expand Down Expand Up @@ -331,7 +331,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.nav_all_files:
if (this instanceof FileDisplayActivity &&
!(((FileDisplayActivity) this).getLeftFragment() instanceof PhotoFragment) &&
!(((FileDisplayActivity) this).getLeftFragment() instanceof GalleryFragment) &&
!(((FileDisplayActivity) this).getLeftFragment() instanceof PreviewTextStringFragment)) {
showFiles(false);
((FileDisplayActivity) this).browseToRoot();
Expand All @@ -348,7 +348,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH),
menuItem.getItemId());
break;
case R.id.nav_photos:
case R.id.nav_gallery:
startPhotoSearch(menuItem);
break;
case R.id.nav_on_device:
Expand Down Expand Up @@ -454,7 +454,7 @@ private void startPhotoSearch(MenuItem menuItem) {

private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) {
if (this instanceof FileDisplayActivity) {
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof PhotoFragment) {
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof GalleryFragment) {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.GalleryFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.fragment.TaskRetainerFragment;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.ui.helpers.UriUploader;
Expand Down Expand Up @@ -498,7 +498,7 @@ protected void onNewIntent(Intent intent) {
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH.equals(searchEvent.searchType)) {
Log_OC.d(this, "Switch to photo search fragment");

PhotoFragment photoFragment = new PhotoFragment(true);
GalleryFragment photoFragment = new GalleryFragment(true);
Bundle bundle = new Bundle();
bundle.putParcelable(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
photoFragment.setArguments(bundle);
Expand Down Expand Up @@ -1182,8 +1182,8 @@ protected void onResume() {
setDrawerMenuItemChecked(menuItemId);
}

if (ocFileListFragment instanceof PhotoFragment) {
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_photos));
if (ocFileListFragment instanceof GalleryFragment) {
updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_item_gallery));
}

Log_OC.v(TAG, "onResume() end");
Expand Down Expand Up @@ -2329,7 +2329,7 @@ public void onMessageEvent(final SearchEvent event) {
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH == event.searchType) {
Log_OC.d(this, "Switch to photo search fragment");

fragment = new PhotoFragment(true);
fragment = new GalleryFragment(true);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
transaction.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ public void setData(List<Object> objects,
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case PHOTO_SEARCH:
type = VirtualFolderType.PHOTOS;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
break;
default:
type = VirtualFolderType.NONE;
Expand All @@ -1003,10 +1003,8 @@ public void setData(List<Object> objects,
}
}

if (searchType != ExtendedListFragment.SearchType.PHOTO_SEARCH &&
searchType != ExtendedListFragment.SearchType.PHOTOS_SEARCH_FILTER &&
searchType != ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH &&
searchType != ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH_FILTER) {
if (searchType != ExtendedListFragment.SearchType.GALLERY_SEARCH &&
searchType != ExtendedListFragment.SearchType.RECENTLY_MODIFIED_SEARCH) {
FileSortOrder sortOrder = preferences.getSortOrderByFolder(folder);
mFiles = sortOrder.sortCloudFiles(mFiles);
} else {
Expand Down Expand Up @@ -1066,15 +1064,15 @@ private void parseShares(List<Object> objects) {

private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType searchType) {
VirtualFolderType type;
boolean onlyImages = false;
boolean onlyMedia = false;

switch (searchType) {
case FAVORITE_SEARCH:
type = VirtualFolderType.FAVORITE;
break;
case PHOTO_SEARCH:
type = VirtualFolderType.PHOTOS;
onlyImages = true;
case GALLERY_SEARCH:
type = VirtualFolderType.GALLERY;
onlyMedia = true;

int lastPosition = objects.size() - 1;

Expand All @@ -1098,7 +1096,7 @@ private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType
FileStorageUtils.searchForLocalFileInDefaultPath(ocFile, user.toPlatformAccount());

try {
if (ExtendedListFragment.SearchType.PHOTO_SEARCH == searchType) {
if (ExtendedListFragment.SearchType.GALLERY_SEARCH == searchType) {
mStorageManager.saveFile(ocFile);
} else {

Expand All @@ -1118,7 +1116,7 @@ private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType
}
}

if (!onlyImages || MimeTypeUtil.isImage(ocFile)) {
if (!onlyMedia || MimeTypeUtil.isImage(ocFile) || MimeTypeUtil.isVideo(ocFile)) {
mFiles.add(ocFile);
}

Expand All @@ -1139,7 +1137,7 @@ private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType
public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {
mFiles = storageManager.getVirtualFolderContent(type, onlyImages);

if (VirtualFolderType.PHOTOS == type) {
if (VirtualFolderType.GALLERY == type) {
mFiles = FileStorageUtils.sortOcFolderDescDateModifiedWithoutFavoritesFirst(mFiles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
import com.owncloud.android.ui.adapter.OCFileListAdapter;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.fragment.GalleryFragment;

import java.lang.ref.WeakReference;

public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult> {
public class GallerySearchTask extends AsyncTask<Void, Void, RemoteOperationResult> {

private int columnCount;
private User user;
private WeakReference<PhotoFragment> photoFragmentWeakReference;
private WeakReference<GalleryFragment> photoFragmentWeakReference;
private SearchRemoteOperation searchRemoteOperation;
private FileDataStorageManager storageManager;
private int limit;

public PhotoSearchTask(int columnsCount,
PhotoFragment photoFragment,
User user,
SearchRemoteOperation searchRemoteOperation,
FileDataStorageManager storageManager) {
public GallerySearchTask(int columnsCount,
GalleryFragment photoFragment,
User user,
SearchRemoteOperation searchRemoteOperation,
FileDataStorageManager storageManager) {
this.columnCount = columnsCount;
this.user = user;
this.photoFragmentWeakReference = new WeakReference<>(photoFragment);
Expand All @@ -62,7 +62,7 @@ protected void onPreExecute() {
if (photoFragmentWeakReference.get() == null) {
return;
}
PhotoFragment photoFragment = photoFragmentWeakReference.get();
GalleryFragment photoFragment = photoFragmentWeakReference.get();
photoFragment.setPhotoSearchQueryRunning(true);
}

Expand All @@ -71,7 +71,7 @@ protected RemoteOperationResult doInBackground(Void... voids) {
if (photoFragmentWeakReference.get() == null) {
return new RemoteOperationResult(new Exception("Photo fragment is null"));
}
PhotoFragment photoFragment = photoFragmentWeakReference.get();
GalleryFragment photoFragment = photoFragmentWeakReference.get();
OCFileListAdapter adapter = photoFragment.getAdapter();

if (isCancelled()) {
Expand All @@ -98,7 +98,7 @@ protected RemoteOperationResult doInBackground(Void... voids) {
@Override
protected void onPostExecute(RemoteOperationResult result) {
if (photoFragmentWeakReference.get() != null) {
PhotoFragment photoFragment = photoFragmentWeakReference.get();
GalleryFragment photoFragment = photoFragmentWeakReference.get();

if (result.isSuccess() && result.getData() != null && !isCancelled()) {
if (result.getData() == null || result.getData().size() == 0) {
Expand All @@ -112,7 +112,7 @@ protected void onPostExecute(RemoteOperationResult result) {
}

adapter.setData(result.getData(),
ExtendedListFragment.SearchType.PHOTO_SEARCH,
ExtendedListFragment.SearchType.GALLERY_SEARCH,
storageManager,
null,
false);
Expand All @@ -124,7 +124,7 @@ protected void onPostExecute(RemoteOperationResult result) {
photoFragment.setLoading(false);

if (!result.isSuccess() && !isCancelled()) {
photoFragment.setEmptyListMessage(ExtendedListFragment.SearchType.PHOTO_SEARCH);
photoFragment.setEmptyListMessage(ExtendedListFragment.SearchType.GALLERY_SEARCH);
}

photoFragment.setPhotoSearchQueryRunning(false);
Expand Down
Loading