From c59f9c0b913b5da2a5b5c1a9960c3542b63a13fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kilian=20Pe=CC=81risset?= Date: Fri, 14 Feb 2020 13:00:49 +0100 Subject: [PATCH] Formated the code + added header --- .../ui/activity/FolderPickerActivityTest.java | 27 ++++++++++++++++--- .../ui/activity/FolderPickerActivity.java | 18 ++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/androidTest/java/com/owncloud/android/ui/activity/FolderPickerActivityTest.java b/src/androidTest/java/com/owncloud/android/ui/activity/FolderPickerActivityTest.java index 62d0e5c114..28052d07dd 100644 --- a/src/androidTest/java/com/owncloud/android/ui/activity/FolderPickerActivityTest.java +++ b/src/androidTest/java/com/owncloud/android/ui/activity/FolderPickerActivityTest.java @@ -1,5 +1,26 @@ 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 . + */ + import com.owncloud.android.datamodel.OCFile; import org.junit.Assert; @@ -19,7 +40,7 @@ public class FolderPickerActivityTest { new ActivityTestRule<>(FolderPickerActivity.class); @Test - public void getFile_NoDifferenceTest() { + public void getActivityFile() { // Arrange FolderPickerActivity targetActivity = activityRule.getActivity(); OCFile origin = new OCFile("/test/file.test"); @@ -34,7 +55,7 @@ public class FolderPickerActivityTest { } @Test - public void getParentFolder_isNotRootFolderTest() { + public void getParentFolder_isNotRootFolder() { // Arrange FolderPickerActivity targetActivity = activityRule.getActivity(); OCFile origin = new OCFile("/test/"); @@ -52,7 +73,7 @@ public class FolderPickerActivityTest { } @Test - public void getParentFolder_isRootFolderTest() { + public void getParentFolder_isRootFolder() { // Arrange FolderPickerActivity targetActivity = activityRule.getActivity(); OCFile origin = new OCFile("/"); diff --git a/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java index d37030b242..66d0021d43 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -43,6 +43,7 @@ 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; @@ -59,6 +60,8 @@ import com.owncloud.android.utils.DataHolderUtil; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.ThemeUtils; + +import java.io.File; import java.util.ArrayList; import javax.inject.Inject; import androidx.appcompat.app.ActionBar; @@ -299,8 +302,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C boolean retval = true; switch (item.getItemId()) { case R.id.action_create_dir: { - OCFile currentFolder = getCurrentFolder(); - CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(currentFolder); + CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(getCurrentFolder()); dialog.show(getSupportFragmentManager(), CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT); break; } @@ -333,20 +335,18 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C protected OCFile getCurrentFolder() { 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 = currentFile - .getRemotePath() - .substring(0, currentFile.getRemotePath() - .lastIndexOf(currentFile.getFileName())); - finalFolder = getStorageManager().getFileByPath(parentPath); + } else if (currentFile.getRemotePath() != null) { + long parentId = currentFile.getParentId(); + finalFolder = storageManager.getFileById(parentId); } } else { - finalFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH); + finalFolder = storageManager.getFileByPath(OCFile.ROOT_PATH); } return finalFolder; }