mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
Merge pull request #13749 from nextcloud/feature/offline-file-rename-2
Feature - Offline File Rename
This commit is contained in:
commit
7286af80f0
7 changed files with 80 additions and 8 deletions
|
@ -40,8 +40,15 @@ class OfflineOperationTypeAdapter : JsonSerializer<OfflineOperationType>, JsonDe
|
|||
jsonObject.addProperty("mimeType", src.mimeType)
|
||||
}
|
||||
|
||||
is OfflineOperationType.RenameFile -> {
|
||||
jsonObject.addProperty("type", src.type)
|
||||
jsonObject.addProperty("ocFileId", src.ocFileId)
|
||||
jsonObject.addProperty("newName", src.newName)
|
||||
}
|
||||
|
||||
null -> Unit
|
||||
}
|
||||
|
||||
return jsonObject
|
||||
}
|
||||
|
||||
|
@ -65,6 +72,12 @@ class OfflineOperationTypeAdapter : JsonSerializer<OfflineOperationType>, JsonDe
|
|||
jsonObject.get("mimeType").asString
|
||||
)
|
||||
|
||||
OfflineOperationRawType.RenameFile.name -> OfflineOperationType.RenameFile(
|
||||
jsonObject.get("type").asString,
|
||||
jsonObject.get("ocFileId").asLong,
|
||||
jsonObject.get("newName").asString
|
||||
)
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
|||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.lib.resources.files.UploadFileRemoteOperation
|
||||
import com.owncloud.android.operations.CreateFolderOperation
|
||||
import com.owncloud.android.operations.RenameFileOperation
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.NonCancellable
|
||||
|
@ -98,6 +99,7 @@ class OfflineOperationsWorker(
|
|||
Result.success()
|
||||
} catch (e: Exception) {
|
||||
Log_OC.d(TAG, "OfflineOperationsWorker terminated: $e")
|
||||
notificationManager.dismissNotification()
|
||||
Result.failure()
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +148,21 @@ class OfflineOperationsWorker(
|
|||
createFileOperation.execute(client) to createFileOperation
|
||||
}
|
||||
|
||||
is OfflineOperationType.RenameFile -> {
|
||||
val renameFileOperation = withContext(NonCancellable) {
|
||||
val operationType = (operation.type as OfflineOperationType.RenameFile)
|
||||
fileDataStorageManager.getFileById(operationType.ocFileId)?.remotePath?.let { updatedRemotePath ->
|
||||
RenameFileOperation(
|
||||
updatedRemotePath,
|
||||
operationType.newName,
|
||||
fileDataStorageManager
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
renameFileOperation?.execute(client) to renameFileOperation
|
||||
}
|
||||
|
||||
else -> {
|
||||
Log_OC.d(TAG, "Unsupported operation type: ${operation.type}")
|
||||
null
|
||||
|
|
|
@ -11,15 +11,23 @@ sealed class OfflineOperationType {
|
|||
abstract val type: String
|
||||
|
||||
data class CreateFolder(override val type: String, var path: String) : OfflineOperationType()
|
||||
|
||||
data class CreateFile(
|
||||
override val type: String,
|
||||
val localPath: String,
|
||||
var remotePath: String,
|
||||
val mimeType: String
|
||||
) : OfflineOperationType()
|
||||
|
||||
data class RenameFile(
|
||||
override val type: String,
|
||||
var ocFileId: Long,
|
||||
val newName: String
|
||||
) : OfflineOperationType()
|
||||
}
|
||||
|
||||
enum class OfflineOperationRawType {
|
||||
CreateFolder,
|
||||
CreateFile
|
||||
CreateFile,
|
||||
RenameFile
|
||||
}
|
||||
|
|
|
@ -217,6 +217,35 @@ public class FileDataStorageManager {
|
|||
offlineOperationsRepository.deleteOperation(file);
|
||||
}
|
||||
|
||||
public void addRenameFileOfflineOperation(OCFile file, String newName) {
|
||||
OfflineOperationEntity entity = new OfflineOperationEntity();
|
||||
|
||||
entity.setFilename(newName);
|
||||
entity.setParentOCFileId(file.getParentId());
|
||||
|
||||
OfflineOperationType operationType = new OfflineOperationType.RenameFile(OfflineOperationRawType.RenameFile.name(), file.getFileId(), newName);
|
||||
entity.setType(operationType);
|
||||
entity.setPath(file.getDecryptedRemotePath());
|
||||
|
||||
long createdAt = System.currentTimeMillis();
|
||||
long modificationTimestamp = System.currentTimeMillis();
|
||||
|
||||
entity.setCreatedAt(createdAt);
|
||||
entity.setModifiedAt(modificationTimestamp / 1000);
|
||||
|
||||
offlineOperationDao.insert(entity);
|
||||
}
|
||||
|
||||
public String getFilenameConsideringOfflineOperation(OCFile file) {
|
||||
String filename = file.getDecryptedFileName();
|
||||
OfflineOperationEntity renameEntity = offlineOperationDao.getByPath(file.getDecryptedRemotePath());
|
||||
if (renameEntity != null && renameEntity.getType() instanceof OfflineOperationType.RenameFile renameFile) {
|
||||
filename = renameFile.getNewName();
|
||||
}
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void renameOfflineOperation(OCFile file, String newFolderName) {
|
||||
var entity = offlineOperationDao.getByPath(file.getDecryptedRemotePath());
|
||||
if (entity == null) {
|
||||
|
|
|
@ -142,7 +142,7 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
|
|||
String title;
|
||||
boolean isRoot = isRoot(chosenFile);
|
||||
|
||||
title = isRoot ? themeUtils.getDefaultDisplayNameForRootFolder(this) : chosenFile.getFileName();
|
||||
title = isRoot ? themeUtils.getDefaultDisplayNameForRootFolder(this) : fileDataStorageManager.getFilenameConsideringOfflineOperation(chosenFile);
|
||||
updateActionBarTitleAndHomeButtonByString(title);
|
||||
|
||||
if (mAppBar != null) {
|
||||
|
|
|
@ -518,7 +518,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
}
|
||||
|
||||
private void bindListGridItemViewHolder(ListGridItemViewHolder holder, OCFile file) {
|
||||
holder.getFileName().setText(file.getDecryptedFileName());
|
||||
holder.getFileName().setText(mStorageManager.getFilenameConsideringOfflineOperation(file));
|
||||
|
||||
boolean gridImage = MimeTypeUtil.isImage(file) || MimeTypeUtil.isVideo(file);
|
||||
if (gridView && gridImage) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.google.common.collect.Sets
|
|||
import com.nextcloud.client.account.CurrentAccountProvider
|
||||
import com.nextcloud.client.di.Injectable
|
||||
import com.nextcloud.utils.extensions.getParcelableArgument
|
||||
import com.nextcloud.utils.extensions.typedActivity
|
||||
import com.nextcloud.utils.fileNameValidator.FileNameValidator.checkFileName
|
||||
import com.nextcloud.utils.fileNameValidator.FileNameValidator.isFileHidden
|
||||
import com.owncloud.android.R
|
||||
|
@ -147,12 +148,16 @@ class RenameFileDialogFragment : DialogFragment(), DialogInterface.OnClickListen
|
|||
|
||||
if (mTargetFile?.isOfflineOperation == true) {
|
||||
fileDataStorageManager.renameOfflineOperation(mTargetFile, newFileName)
|
||||
if (requireActivity() is FileDisplayActivity) {
|
||||
val activity = requireActivity() as FileDisplayActivity
|
||||
activity.refreshCurrentDirectory()
|
||||
}
|
||||
typedActivity<FileDisplayActivity>()?.refreshCurrentDirectory()
|
||||
} else {
|
||||
(requireActivity() as ComponentsGetter).fileOperationsHelper.renameFile(mTargetFile, newFileName)
|
||||
typedActivity<FileDisplayActivity>()?.connectivityService?.isNetworkAndServerAvailable { result ->
|
||||
if (result) {
|
||||
typedActivity<ComponentsGetter>()?.fileOperationsHelper?.renameFile(mTargetFile, newFileName)
|
||||
} else {
|
||||
fileDataStorageManager.addRenameFileOfflineOperation(mTargetFile, newFileName)
|
||||
typedActivity<FileDisplayActivity>()?.refreshCurrentDirectory()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue