Skip to content

Commit 3ebefc8

Browse files
committed
Code refactoring and operation migrated to kotlin
Signed-off-by: Surinder Kumar <[email protected]>
1 parent 008ab57 commit 3ebefc8

File tree

12 files changed

+172
-149
lines changed

12 files changed

+172
-149
lines changed

app/src/main/java/com/nextcloud/ui/albumItemActions/AlbumItemAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum class AlbumItemAction(@IdRes val id: Int, @StringRes val title: Int, @Drawa
2323
@JvmField
2424
val SORTED_VALUES = listOf(
2525
RENAME_ALBUM,
26-
DELETE_ALBUM,
26+
DELETE_ALBUM
2727
)
2828
}
2929
}

app/src/main/java/com/owncloud/android/operations/albums/CopyFileToAlbumOperation.kt

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,32 @@
44
* SPDX-FileCopyrightText: 2025 TSI-mc <[email protected]>
55
* SPDX-License-Identifier: AGPL-3.0-or-later
66
*/
7+
package com.owncloud.android.operations.albums
78

8-
package com.owncloud.android.operations.albums;
9-
10-
import com.owncloud.android.datamodel.FileDataStorageManager;
11-
import com.owncloud.android.datamodel.OCFile;
12-
import com.owncloud.android.lib.common.OwnCloudClient;
13-
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
14-
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
15-
import com.owncloud.android.lib.resources.albums.CopyFileToAlbumRemoteOperation;
16-
import com.owncloud.android.operations.UploadFileOperation;
17-
import com.owncloud.android.operations.common.SyncOperation;
9+
import com.owncloud.android.datamodel.FileDataStorageManager
10+
import com.owncloud.android.datamodel.OCFile
11+
import com.owncloud.android.lib.common.OwnCloudClient
12+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
14+
import com.owncloud.android.lib.resources.albums.CopyFileToAlbumRemoteOperation
15+
import com.owncloud.android.operations.UploadFileOperation
16+
import com.owncloud.android.operations.common.SyncOperation
1817

1918
/**
20-
* Operation copying an {@link OCFile} to a different folder.
19+
* Constructor
2120
*
22-
* @author David A. Velasco
21+
* @param srcPath Remote path of the [OCFile] to move.
22+
* @param targetParentPath Path to the folder where the file will be copied into.
2323
*/
24-
public class CopyFileToAlbumOperation extends SyncOperation {
25-
26-
private final String srcPath;
27-
private String targetParentPath;
28-
29-
/**
30-
* Constructor
31-
*
32-
* @param srcPath Remote path of the {@link OCFile} to move.
33-
* @param targetParentPath Path to the folder where the file will be copied into.
34-
*/
35-
public CopyFileToAlbumOperation(String srcPath, String targetParentPath, FileDataStorageManager storageManager) {
36-
super(storageManager);
37-
38-
this.srcPath = srcPath;
39-
this.targetParentPath = targetParentPath;
40-
if (!this.targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
41-
this.targetParentPath += OCFile.PATH_SEPARATOR;
24+
class CopyFileToAlbumOperation(
25+
private val srcPath: String,
26+
private var targetParentPath: String,
27+
storageManager: FileDataStorageManager
28+
) :
29+
SyncOperation(storageManager) {
30+
init {
31+
if (!targetParentPath.endsWith(OCFile.PATH_SEPARATOR)) {
32+
this.targetParentPath += OCFile.PATH_SEPARATOR
4233
}
4334
}
4435

@@ -47,43 +38,45 @@ public class CopyFileToAlbumOperation extends SyncOperation {
4738
*
4839
* @param client Client object to communicate with the remote ownCloud server.
4940
*/
50-
@Override
51-
protected RemoteOperationResult run(OwnCloudClient client) {
52-
/// 1. check copy validity
53-
if (targetParentPath.startsWith(srcPath)) {
54-
return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
55-
}
56-
OCFile file = getStorageManager().getFileByPath(srcPath);
57-
if (file == null) {
58-
return new RemoteOperationResult(ResultCode.FILE_NOT_FOUND);
59-
}
41+
@Deprecated("Deprecated in Java")
42+
@Suppress("NestedBlockDepth")
43+
override fun run(client: OwnCloudClient): RemoteOperationResult<Any> {
44+
/** 1. check copy validity */
45+
val result: RemoteOperationResult<Any>
6046

61-
/// 2. remote copy
62-
String targetPath = targetParentPath + file.getFileName();
63-
if (file.isFolder()) {
64-
targetPath += OCFile.PATH_SEPARATOR;
65-
}
47+
if (targetParentPath.startsWith(srcPath)) {
48+
result = RemoteOperationResult<Any>(ResultCode.INVALID_COPY_INTO_DESCENDANT)
49+
} else {
50+
val file = storageManager.getFileByPath(srcPath)
51+
if (file == null) {
52+
result = RemoteOperationResult(ResultCode.FILE_NOT_FOUND)
53+
} else {
54+
/** 2. remote copy */
55+
var targetPath = "$targetParentPath${file.fileName}"
56+
if (file.isFolder) {
57+
targetPath += OCFile.PATH_SEPARATOR
58+
}
6659

67-
// auto rename, to allow copy
68-
if (targetPath.equals(srcPath)) {
69-
if (file.isFolder()) {
70-
targetPath = targetParentPath + file.getFileName();
71-
}
72-
targetPath = UploadFileOperation.getNewAvailableRemotePath(client, targetPath, null, false);
60+
// auto rename, to allow copy
61+
if (targetPath == srcPath) {
62+
if (file.isFolder) {
63+
targetPath = "$targetParentPath${file.fileName}"
64+
}
65+
targetPath = UploadFileOperation.getNewAvailableRemotePath(client, targetPath, null, false)
7366

74-
if (file.isFolder()) {
75-
targetPath += OCFile.PATH_SEPARATOR;
76-
}
77-
}
67+
if (file.isFolder) {
68+
targetPath += OCFile.PATH_SEPARATOR
69+
}
70+
}
7871

79-
RemoteOperationResult result = new CopyFileToAlbumRemoteOperation(srcPath, targetPath).execute(client);
72+
result = CopyFileToAlbumRemoteOperation(srcPath, targetPath).execute(client)
8073

81-
/// 3. local copy
82-
if (result.isSuccess()) {
83-
getStorageManager().copyLocalFile(file, targetPath);
74+
/** 3. local copy */
75+
if (result.isSuccess) {
76+
storageManager.copyLocalFile(file, targetPath)
77+
}
78+
}
8479
}
85-
// TODO handle ResultCode.PARTIAL_COPY_DONE in client Activity, for the moment
86-
87-
return result;
80+
return result
8881
}
8982
}

app/src/main/java/com/owncloud/android/ui/activity/AlbumsPickerActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ class AlbumsPickerActivity : FileActivity(), FileFragment.ContainerActivity, OnE
143143
* @param operation Creation operation performed.
144144
* @param result Result of the creation.
145145
*/
146-
private fun onCreateAlbumOperationFinish(operation: CreateNewAlbumRemoteOperation, result: RemoteOperationResult<*>) {
146+
@Suppress("MaxLineLength")
147+
private fun onCreateAlbumOperationFinish(
148+
operation: CreateNewAlbumRemoteOperation,
149+
result: RemoteOperationResult<*>
150+
) {
147151
if (result.isSuccess) {
148152
val fileListFragment = listOfFilesFragment
149153
fileListFragment?.refreshAlbums()

app/src/main/java/com/owncloud/android/ui/adapter/GalleryAdapter.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ class GalleryAdapter(
206206
}
207207

208208
@SuppressLint("NotifyDataSetChanged")
209-
fun showAlbumItems(
210-
albumItems: List<OCFile>,
211-
) {
209+
fun showAlbumItems(albumItems: List<OCFile>) {
212210
files = albumItems.toGalleryItems()
213211
Handler(Looper.getMainLooper()).post { notifyDataSetChanged() }
214212
}
@@ -313,7 +311,7 @@ class GalleryAdapter(
313311
}
314312

315313
fun setCheckedItem(files: Set<OCFile>?) {
316-
ocFileListDelegate.setCheckedItem(files)
314+
ocFileListDelegate.setCheckedItem(files)
317315
}
318316

319317
override fun getFilesCount(): Int {

app/src/main/java/com/owncloud/android/ui/adapter/albums/AlbumFragmentInterface.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ import com.owncloud.android.lib.resources.albums.PhotoAlbumEntry
1111

1212
interface AlbumFragmentInterface {
1313
fun onItemClick(album: PhotoAlbumEntry)
14-
}
14+
}

app/src/main/java/com/owncloud/android/ui/adapter/albums/AlbumGridItemViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ internal class AlbumGridItemViewHolder(private var binding: AlbumsGridItemBindin
2323
get() = binding.Filename
2424
override val albumInfo: TextView
2525
get() = binding.fileInfo
26-
}
26+
}

app/src/main/java/com/owncloud/android/ui/adapter/albums/AlbumItemViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ interface AlbumItemViewHolder {
1616
val shimmerThumbnail: LoaderImageView
1717
val albumName: TextView
1818
val albumInfo: TextView
19-
}
19+
}

app/src/main/java/com/owncloud/android/ui/adapter/albums/AlbumListItemViewHolder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ internal class AlbumListItemViewHolder(private var binding: AlbumsListItemBindin
2323
get() = binding.Filename
2424
override val albumInfo: TextView
2525
get() = binding.fileInfo
26-
}
26+
}

app/src/main/java/com/owncloud/android/ui/adapter/albums/AlbumsAdapter.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.owncloud.android.lib.resources.albums.PhotoAlbumEntry
2626
import com.owncloud.android.utils.DisplayUtils
2727
import com.owncloud.android.utils.theme.ViewThemeUtils
2828

29+
@Suppress("LongParameterList")
2930
class AlbumsAdapter(
3031
val context: Context,
3132
private val storageManager: FileDataStorageManager?,
@@ -60,7 +61,8 @@ class AlbumsAdapter(
6061
gridViewHolder.thumbnail.tag = file.lastPhoto
6162
gridViewHolder.albumInfo.text = String.format(
6263
context.resources.getString(R.string.album_items_text),
63-
file.nbItems, file.createdDate
64+
file.nbItems,
65+
file.createdDate
6466
)
6567

6668
if (file.lastPhoto > 0) {
@@ -106,4 +108,4 @@ class AlbumsAdapter(
106108
}
107109
notifyDataSetChanged()
108110
}
109-
}
111+
}

app/src/main/java/com/owncloud/android/ui/dialog/CreateAlbumDialogFragment.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class CreateAlbumDialogFragment : DialogFragment(), DialogInterface.OnClickListe
9797
val inflater = requireActivity().layoutInflater
9898
binding = EditBoxDialogBinding.inflate(inflater, null, false)
9999

100-
101100
binding.userInput.setText(albumName ?: "")
102101
viewThemeUtils.material.colorTextInputLayout(binding.userInputContainer)
103102
albumName?.let {
@@ -194,7 +193,7 @@ class CreateAlbumDialogFragment : DialogFragment(), DialogInterface.OnClickListe
194193
fun newInstance(albumName: String? = null): CreateAlbumDialogFragment {
195194
return CreateAlbumDialogFragment().apply {
196195
val argsBundle = bundleOf(
197-
ARG_ALBUM_NAME to albumName,
196+
ARG_ALBUM_NAME to albumName
198197
)
199198
arguments = argsBundle
200199
}

0 commit comments

Comments
 (0)