From 1c2f58a4f86f849c0a4a5526faf6e6fa12c79f80 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 3 Nov 2023 15:19:33 +0100 Subject: [PATCH] Convert to kt Signed-off-by: alperozturk --- .../client/jobs/MediaFoldersDetectionWork.kt | 11 +++++- .../owncloud/android/datamodel/MediaFolder.kt | 36 +++++++++-------- .../android/datamodel/MediaFolderType.kt | 39 +++++++------------ .../android/datamodel/MediaFoldersModel.kt | 31 +-------------- .../datamodel/SyncedFolderProvider.java | 2 +- .../ui/adapter/SyncedFolderAdapter.java | 2 +- .../dialog/parcel/SyncedFolderParcelable.java | 2 +- 7 files changed, 48 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt b/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt index b647b58010..47e653e577 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/MediaFoldersDetectionWork.kt @@ -105,12 +105,19 @@ class MediaFoldersDetectionWork constructor( ) val imageMediaFolderPaths: MutableList = ArrayList() val videoMediaFolderPaths: MutableList = ArrayList() + for (imageMediaFolder in imageMediaFolders) { - imageMediaFolderPaths.add(imageMediaFolder.absolutePath) + imageMediaFolder.absolutePath?.let { + imageMediaFolderPaths.add(it) + } } + for (videoMediaFolder in videoMediaFolders) { - imageMediaFolderPaths.add(videoMediaFolder.absolutePath) + videoMediaFolder.absolutePath?.let { + imageMediaFolderPaths.add(it) + } } + val arbitraryDataString = arbitraryDataProvider.getValue(ACCOUNT_NAME_GLOBAL, KEY_MEDIA_FOLDERS) if (!TextUtils.isEmpty(arbitraryDataString)) { mediaFoldersModel = gson.fromJson(arbitraryDataString, MediaFoldersModel::class.java) diff --git a/app/src/main/java/com/owncloud/android/datamodel/MediaFolder.kt b/app/src/main/java/com/owncloud/android/datamodel/MediaFolder.kt index b2655e0b55..5a7da2d20b 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/MediaFolder.kt +++ b/app/src/main/java/com/owncloud/android/datamodel/MediaFolder.kt @@ -16,29 +16,31 @@ * 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 . + * License along with this program. If not, see //www.gnu.org/licenses/>. */ -package com.owncloud.android.datamodel; - -import java.util.ArrayList; -import java.util.List; +package com.owncloud.android.datamodel /** * Business object representing a media folder with all information that are gathered via media queries. */ -public class MediaFolder { - /** name of the folder. */ - public String folderName; +class MediaFolder { + /** name of the folder. */ + @JvmField + var folderName: String? = null - /** absolute path of the folder. */ - public String absolutePath; - - /** list of file paths of the folder's content */ - public List filePaths = new ArrayList<>(); + /** absolute path of the folder. */ + @JvmField + var absolutePath: String? = null - /** total number of files in the media folder. */ - public long numberOfFiles; + /** list of file paths of the folder's content */ + @JvmField + var filePaths: List = ArrayList() - /** type of media folder. */ - public MediaFolderType type; + /** total number of files in the media folder. */ + @JvmField + var numberOfFiles: Long = 0 + + /** type of media folder. */ + @JvmField + var type: MediaFolderType? = null } diff --git a/app/src/main/java/com/owncloud/android/datamodel/MediaFolderType.kt b/app/src/main/java/com/owncloud/android/datamodel/MediaFolderType.kt index efd3cf9774..c89ea65927 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/MediaFolderType.kt +++ b/app/src/main/java/com/owncloud/android/datamodel/MediaFolderType.kt @@ -17,37 +17,28 @@ * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . */ -package com.owncloud.android.datamodel; +package com.owncloud.android.datamodel -import android.util.SparseArray; +import android.util.SparseArray /** * Types of media folder. */ -public enum MediaFolderType { - CUSTOM(0), - IMAGE(1), - VIDEO(2); +enum class MediaFolderType(@JvmField val id: Int) { + CUSTOM(0), IMAGE(1), VIDEO(2); - private Integer id; + companion object { + private val reverseMap = SparseArray(3) - private static SparseArray reverseMap = new SparseArray<>(3); + init { + reverseMap.put(CUSTOM.id, CUSTOM) + reverseMap.put(IMAGE.id, IMAGE) + reverseMap.put(VIDEO.id, VIDEO) + } - static { - reverseMap.put(CUSTOM.getId(), CUSTOM); - reverseMap.put(IMAGE.getId(), IMAGE); - reverseMap.put(VIDEO.getId(), VIDEO); - } - - MediaFolderType(Integer id) { - this.id = id; - } - - public static MediaFolderType getById(Integer id) { - return reverseMap.get(id); - } - - public Integer getId() { - return this.id; + @JvmStatic + fun getById(id: Int?): MediaFolderType { + return reverseMap[id!!] + } } } diff --git a/app/src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.kt b/app/src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.kt index 5b164012eb..8af5310219 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.kt +++ b/app/src/main/java/com/owncloud/android/datamodel/MediaFoldersModel.kt @@ -19,33 +19,6 @@ * You should have received a copy of the GNU Affero General Public * License along with this program. If not, see . */ +package com.owncloud.android.datamodel -package com.owncloud.android.datamodel; - -import java.util.List; - -public class MediaFoldersModel { - private List imageMediaFolders; - private List videoMediaFolders; - - public MediaFoldersModel(List imageMediaFolders, List videoMediaFolders) { - this.imageMediaFolders = imageMediaFolders; - this.videoMediaFolders = videoMediaFolders; - } - - public List getImageMediaFolders() { - return this.imageMediaFolders; - } - - public List getVideoMediaFolders() { - return this.videoMediaFolders; - } - - public void setImageMediaFolders(List imageMediaFolders) { - this.imageMediaFolders = imageMediaFolders; - } - - public void setVideoMediaFolders(List videoMediaFolders) { - this.videoMediaFolders = videoMediaFolders; - } -} +class MediaFoldersModel(var imageMediaFolders: List, var videoMediaFolders: List) diff --git a/app/src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java b/app/src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java index f36f27dfbb..baa107efdc 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java +++ b/app/src/main/java/com/owncloud/android/datamodel/SyncedFolderProvider.java @@ -415,7 +415,7 @@ public class SyncedFolderProvider extends Observable { cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_UPLOAD_ACTION, syncedFolder.getUploadAction()); cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_NAME_COLLISION_POLICY, syncedFolder.getNameCollisionPolicyInt()); - cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().getId()); + cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_TYPE, syncedFolder.getType().id); cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_HIDDEN, syncedFolder.isHidden()); cv.put(ProviderMeta.ProviderTableMeta.SYNCED_FOLDER_SUBFOLDER_RULE, syncedFolder.getSubfolderRule().ordinal()); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/SyncedFolderAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/SyncedFolderAdapter.java index 8a377a544d..2f31692980 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/SyncedFolderAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/SyncedFolderAdapter.java @@ -248,7 +248,7 @@ public class SyncedFolderAdapter extends SectionedRecyclerViewAdapter