Skip to content
Open
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
Expand Up @@ -59,8 +59,9 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper

protected String remotePath;
private RemoteFile createdRemoteFolder;
private User user;
private Context context;
private volatile boolean encrypt = false;
private final User user;
private final Context context;

/**
* Constructor
Expand All @@ -73,6 +74,14 @@ public CreateFolderOperation(String remotePath, User user, Context context, File
this.context = context;
}

public void setEncrypt(boolean value) {
encrypt = value;
}

public boolean shouldEncrypt() {
return encrypt;
}

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
String remoteParentPath = new File(getRemotePath()).getParent();
Expand Down Expand Up @@ -490,14 +499,18 @@ private String createRandomFileName(DecryptedFolderMetadataFileV1 metadata) {
return encryptedFileName;
}

private RemoteOperationResult normalCreate(OwnCloudClient client) {
RemoteOperationResult result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
private RemoteOperationResult<?> normalCreate(OwnCloudClient client) {
final var result = new CreateFolderRemoteOperation(remotePath, true).execute(client);

if (result.isSuccess()) {
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
final var remoteFolderOperationResult = new ReadFolderRemoteOperation(remotePath)
.execute(client);

createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
if (remoteFolderOperationResult.isSuccess() &&
remoteFolderOperationResult.getData().get(0) instanceof RemoteFile remoteFile) {
createdRemoteFolder = remoteFile;
}

saveFolderInDB();
} else {
Log_OC.e(TAG, remotePath + " hasn't been created");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class OperationsService extends Service {

private static final String TAG = OperationsService.class.getSimpleName();

public static final String EXTRA_ENCRYPTED = "ENCRYPTED";
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_POST_DIALOG_EVENT = "EXTRA_POST_DIALOG_EVENT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
Expand Down Expand Up @@ -708,10 +709,13 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {

case ACTION_CREATE_FOLDER:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
operation = new CreateFolderOperation(remotePath,
user,
getApplicationContext(),
fileDataStorageManager);
boolean encrypt = operationIntent.getBooleanExtra(EXTRA_ENCRYPTED, false);
final var createFolderOperation = new CreateFolderOperation(remotePath,
user,
getApplicationContext(),
fileDataStorageManager);
createFolderOperation.setEncrypt(encrypt);
operation = createFolderOperation;
break;

case ACTION_SYNC_FILE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,19 @@ class FileDisplayActivity :
private fun onCreateFolderOperationFinish(operation: CreateFolderOperation, result: RemoteOperationResult<*>) {
if (result.isSuccess) {
val fileListFragment = this.listOfFilesFragment
if (operation.shouldEncrypt()) {
val file = storageManager.getFileByDecryptedRemotePath(operation.remotePath)
if (file == null) {
Log_OC.e(
TAG,
"onCreateFolderOperationFinish(): file not saved after create folder operation, cannot encrypt"
)
return
}
fileOperationsHelper.toggleEncryption(file, true)
return
}

fileListFragment?.onItemClicked(storageManager.getFileByDecryptedRemotePath(operation.getRemotePath()))
} else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ open class FolderPickerActivity :
val itemId = item.itemId

if (itemId == R.id.action_create_dir) {
val dialog = CreateFolderDialogFragment.newInstance(currentFolder)
val dialog = CreateFolderDialogFragment.newInstance(currentFolder, false)
dialog.show(supportFragmentManager, CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT)
} else if (itemId == android.R.id.home) {
val currentDir = currentFolder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();

if (itemId == R.id.action_create_dir) {
CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile);
CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile, false);
dialog.show(getSupportFragmentManager(), CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
} else if (itemId == android.R.id.home) {
if (mParents.size() > SINGLE_PARENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected Integer doInBackground(Void... voids) {
}

static private class FileMigrationTask extends FileMigrationTaskBase {
private class MigrationException extends Exception {
private static class MigrationException extends Exception {
private static final long serialVersionUID = -4575848188034992066L;
private int mResId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,25 +289,22 @@ public void refreshCommentsCount(String fileId) {
new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
}

public void setEncryptionAttributeForItemID(String fileId, boolean encrypted) {
for (OCFile file : mFiles) {
if (file.getRemoteId().equals(fileId)) {
file.setEncrypted(encrypted);
file.setE2eCounter(0L);
mStorageManager.saveFile(file);
public void updateFileEncryptionById(String fileId, boolean encrypted) {
if (fileId == null) return;

break;
}
}

for (OCFile file : mFilesAll) {
if (file.getRemoteId().equals(fileId)) {
mFilesAll.stream()
.filter(f -> fileId.equals(f.getRemoteId()))
.findFirst()
.ifPresent(file -> {
file.setEncrypted(encrypted);
file.setE2eCounter(0L);
}
}
mStorageManager.saveFile(file);

new Handler(Looper.getMainLooper()).post(this::notifyDataSetChanged);
int position = getItemPosition(file);
if (position != -1) {
notifyItemChanged(position);
}
});
}

@Override
Expand Down Expand Up @@ -968,6 +965,28 @@ public List<OCFile> getFiles() {
return mFiles;
}

@Nullable
public OCFile getFileByRemoteId(@Nullable String fileId) {
return mFilesAll.stream()
.filter(f -> java.util.Objects.equals(fileId, f.getRemoteId()))
.findFirst()
.orElse(null);
}

public void insertFile(@Nullable OCFile file) {
if (file == null) return;

if (mFilesAll.contains(file)) return;

mFilesAll.add(file);
mFiles.add(file);

int position = getItemPosition(file);
if (position != -1) {
notifyItemInserted(position);
}
}

public void addVirtualFile(@NonNull OCFile file) {
if (mFiles.isEmpty() || !mFiles.contains(file)) {
mFiles.add(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class CreateFolderDialogFragment :

private var parentFolder: OCFile? = null
private var positiveButton: MaterialButton? = null
private var encrypted: Boolean = false

private lateinit var binding: EditBoxDialogBinding

Expand Down Expand Up @@ -112,6 +113,7 @@ class CreateFolderDialogFragment :
viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer)

val parentFolder = requireArguments().getParcelableArgument(ARG_PARENT_FOLDER, OCFile::class.java)
encrypted = requireArguments().getBoolean(ARG_ENCRYPTED, false)

val folderContent = fileDataStorageManager.getFolderContent(parentFolder, false)
val fileNames: MutableSet<String> = Sets.newHashSetWithExpectedSize(folderContent.size)
Expand Down Expand Up @@ -190,7 +192,7 @@ class CreateFolderDialogFragment :
val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR
connectivityService.isNetworkAndServerAvailable { result ->
if (result) {
typedActivity<ComponentsGetter>()?.fileOperationsHelper?.createFolder(path)
typedActivity<ComponentsGetter>()?.fileOperationsHelper?.createFolder(path, encrypted)
} else {
Log_OC.d(TAG, "Network not available, creating offline operation")
fileDataStorageManager.addCreateFolderOfflineOperation(
Expand All @@ -208,6 +210,8 @@ class CreateFolderDialogFragment :
companion object {
private const val TAG = "CreateFolderDialogFragment"
private const val ARG_PARENT_FOLDER = "PARENT_FOLDER"
private const val ARG_ENCRYPTED = "ENCRYPTED"

const val CREATE_FOLDER_FRAGMENT = "CREATE_FOLDER_FRAGMENT"

/**
Expand All @@ -217,8 +221,9 @@ class CreateFolderDialogFragment :
* @return Dialog ready to show.
*/
@JvmStatic
fun newInstance(parentFolder: OCFile?): CreateFolderDialogFragment {
fun newInstance(parentFolder: OCFile?, encrypted: Boolean): CreateFolderDialogFragment {
val bundle = Bundle().apply {
putBoolean(ARG_ENCRYPTED, encrypted)
putParcelable(ARG_PARENT_FOLDER, parentFolder)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2018 Andy Scherzinger <info@andy-scherzinger.de>
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/
package com.owncloud.android.ui.fragment

import com.owncloud.android.lib.common.Creator

interface OCFileListBottomSheetActions {
fun createFolder(encrypted: Boolean)

/**
* offers a file upload with the Android OS file picker to the current folder.
*/
fun uploadFromApp()

/**
* offers a file upload with the app file picker to the current folder.
*/
fun uploadFiles()

/**
* opens template selection for documents
*/
fun newDocument()

/**
* opens template selection for spreadsheets
*/
fun newSpreadsheet()

fun newPresentation()
fun directCameraUpload()
fun scanDocUpload()

/**
* Offers scanning a document in a supported external app and then upload to the current folder.
*/
fun scanDocUploadFromApp()

/**
* @return true, if a supported external app is available for [.scanDocUploadFromApp]
*/
val isScanDocUploadFromAppAvailable: Boolean

/**
* open template selection for creator @link Creator
*/
fun showTemplate(creator: Creator?, headline: String?)

fun createRichWorkspace()
}
Loading
Loading