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
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.owncloud.android.ui.activity;

/*
* Nextcloud Android client application
*
* @author Kilian Périsset
* Copyright (C) 2019 Kilian Périsset (Infomaniak Network SA)
* Copyright (C) 2019 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import com.owncloud.android.datamodel.OCFile;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class FolderPickerActivityIT {
@Rule
public ActivityTestRule<FolderPickerActivity> activityRule =
new ActivityTestRule<>(FolderPickerActivity.class);

@Test
public void getActivityFile() {
// Arrange
FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/test/file.test");
origin.setRemotePath("/remotePath/test");

// Act
targetActivity.setFile(origin);
OCFile target = targetActivity.getFile();

// Assert
Assert.assertEquals(origin, target);
}

@Test
public void getParentFolder_isNotRootFolder() {
// Arrange
FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/test/");
origin.setFileId(1);
origin.setRemotePath("/test/");
origin.setStoragePath("/test/");
origin.setFolder();

// Act
targetActivity.setFile(origin);
OCFile target = targetActivity.getCurrentFolder();

// Assert
Assert.assertEquals(origin, target);
}

@Test
public void getParentFolder_isRootFolder() {
// Arrange
FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/");
origin.setFileId(1);
origin.setRemotePath("/");
origin.setStoragePath("/");
origin.setFolder();

// Act
targetActivity.setFile(origin);
OCFile target = targetActivity.getCurrentFolder();

// Assert
Assert.assertEquals(origin, target);
}

@Test
public void nullFile() {
// Arrange
FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile rootFolder = targetActivity.getStorageManager().getFileByPath(OCFile.ROOT_PATH);

// Act
targetActivity.setFile(null);
OCFile target = targetActivity.getCurrentFolder();

// Assert
Assert.assertEquals(rootFolder, target);
}

@Test
public void getParentFolder() {
// Arrange
FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/test/file.test");
origin.setRemotePath("/test/file.test");

OCFile target = new OCFile("/test/");

// Act
targetActivity.setFile(origin);

// Assert
Assert.assertEquals(origin, target);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
import android.view.View;
import android.view.View.OnClickListener;

import com.google.android.material.button.MaterialButton;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferences;
import com.google.android.material.button.MaterialButton;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
Expand All @@ -60,6 +61,7 @@
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.ThemeUtils;

import java.io.File;
import java.util.ArrayList;

import javax.inject.Inject;
Expand Down Expand Up @@ -195,8 +197,7 @@ protected void createFragments() {
}

/**
* Show a text message on screen view for notifying user if content is
* loading or folder is empty
* Show a text message on screen view for notifying user if content is loading or folder is empty
*/
private void setBackgroundText() {
OCFileListFragment listFragment = getListOfFilesFragment();
Expand Down Expand Up @@ -249,8 +250,13 @@ public void startSyncFolderOperation(OCFile folder, boolean ignoreETag) {
mSyncInProgress = true;

// perform folder synchronization
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false,
ignoreETag, getStorageManager(), getAccount(), getApplicationContext());
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(folder,
currentSyncTime,
false,
ignoreETag,
getStorageManager(),
getAccount(),
getApplicationContext());

refreshFolderOperation.execute(getAccount(), this, null, null);
setIndeterminate(true);
Expand Down Expand Up @@ -333,16 +339,22 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

protected OCFile getCurrentFolder() {
OCFile file = getFile();
if (file != null) {
if (file.isFolder()) {
return file;
} else if (getStorageManager() != null) {
String parentPath = file.getRemotePath().substring(0, file.getRemotePath().lastIndexOf(file.getFileName()));
return getStorageManager().getFileByPath(parentPath);
OCFile currentFile = getFile();
OCFile finalFolder = null;
FileDataStorageManager storageManager = getStorageManager();

// If the file is null, take the root folder to avoid any error in functions depending on this one
if (currentFile != null) {
if (currentFile.isFolder()) {
finalFolder = currentFile;
} else if (currentFile.getRemotePath() != null) {
String parentPath = new File(currentFile.getRemotePath()).getParent();
finalFolder = storageManager.getFileByPath(parentPath);
}
} else {
finalFolder = storageManager.getFileByPath(OCFile.ROOT_PATH);
}
return null;
return finalFolder;
}

public void refreshListOfFilesFragment(boolean fromSearch) {
Expand Down Expand Up @@ -443,8 +455,7 @@ public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationRe


/**
* Updates the view associated to the activity after the finish of an operation trying
* to create a new folder.
* Updates the view associated to the activity after the finish of an operation trying to create a new folder.
*
* @param operation Creation operation performed.
* @param result Result of the creation.
Expand Down Expand Up @@ -495,8 +506,9 @@ public void onReceive(Context context, Intent intent) {

if (currentDir == null) {
// current folder was removed from the server
DisplayUtils.showSnackMessage(getActivity(), R.string.sync_current_folder_was_removed,
getCurrentFolder().getFileName());
DisplayUtils.showSnackMessage(getActivity(),
R.string.sync_current_folder_was_removed,
getCurrentFolder().getFileName());
browseToRoot();
} else {
if (currentFile == null && !getFile().isFolder()) {
Expand Down