Formated the code + added header

This commit is contained in:
Kilian Périsset 2020-02-14 13:00:49 +01:00 committed by tobiasKaminsky
parent c821f192d6
commit c59f9c0b91
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
2 changed files with 33 additions and 12 deletions

View file

@ -1,5 +1,26 @@
package com.owncloud.android.ui.activity; 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 com.owncloud.android.datamodel.OCFile;
import org.junit.Assert; import org.junit.Assert;
@ -19,7 +40,7 @@ public class FolderPickerActivityTest {
new ActivityTestRule<>(FolderPickerActivity.class); new ActivityTestRule<>(FolderPickerActivity.class);
@Test @Test
public void getFile_NoDifferenceTest() { public void getActivityFile() {
// Arrange // Arrange
FolderPickerActivity targetActivity = activityRule.getActivity(); FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/test/file.test"); OCFile origin = new OCFile("/test/file.test");
@ -34,7 +55,7 @@ public class FolderPickerActivityTest {
} }
@Test @Test
public void getParentFolder_isNotRootFolderTest() { public void getParentFolder_isNotRootFolder() {
// Arrange // Arrange
FolderPickerActivity targetActivity = activityRule.getActivity(); FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/test/"); OCFile origin = new OCFile("/test/");
@ -52,7 +73,7 @@ public class FolderPickerActivityTest {
} }
@Test @Test
public void getParentFolder_isRootFolderTest() { public void getParentFolder_isRootFolder() {
// Arrange // Arrange
FolderPickerActivity targetActivity = activityRule.getActivity(); FolderPickerActivity targetActivity = activityRule.getActivity();
OCFile origin = new OCFile("/"); OCFile origin = new OCFile("/");

View file

@ -43,6 +43,7 @@ import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferences;
import com.google.android.material.button.MaterialButton; import com.google.android.material.button.MaterialButton;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -59,6 +60,8 @@ import com.owncloud.android.utils.DataHolderUtil;
import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.ThemeUtils; import com.owncloud.android.utils.ThemeUtils;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
@ -299,8 +302,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
boolean retval = true; boolean retval = true;
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_create_dir: { case R.id.action_create_dir: {
OCFile currentFolder = getCurrentFolder(); CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(getCurrentFolder());
CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(currentFolder);
dialog.show(getSupportFragmentManager(), CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT); dialog.show(getSupportFragmentManager(), CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
break; break;
} }
@ -333,20 +335,18 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
protected OCFile getCurrentFolder() { protected OCFile getCurrentFolder() {
OCFile currentFile = getFile(); OCFile currentFile = getFile();
OCFile finalFolder = null; 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 the file is null, take the root folder to avoid any error in functions depending on this one
if (currentFile != null) { if (currentFile != null) {
if (currentFile.isFolder()) { if (currentFile.isFolder()) {
finalFolder = currentFile; finalFolder = currentFile;
} else if(currentFile.getRemotePath() != null) { } else if (currentFile.getRemotePath() != null) {
String parentPath = currentFile long parentId = currentFile.getParentId();
.getRemotePath() finalFolder = storageManager.getFileById(parentId);
.substring(0, currentFile.getRemotePath()
.lastIndexOf(currentFile.getFileName()));
finalFolder = getStorageManager().getFileByPath(parentPath);
} }
} else { } else {
finalFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH); finalFolder = storageManager.getFileByPath(OCFile.ROOT_PATH);
} }
return finalFolder; return finalFolder;
} }