From f4999596683e619c9814fbf55165a6de2a8912e6 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 | 45 ++++++++----------- .../android/datamodel/MediaFoldersModel.kt | 31 +------------ .../datamodel/SyncedFolderProvider.java | 2 +- .../ui/adapter/SyncedFolderAdapter.java | 2 +- .../dialog/parcel/SyncedFolderParcelable.java | 2 +- 7 files changed, 51 insertions(+), 78 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 b647b5801062..47e653e57724 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 b2655e0b557f..5a7da2d20b15 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. */ + @JvmField + var absolutePath: String? = null - /** absolute path of the folder. */ - public String absolutePath; - - /** list of file paths of the folder's content */ - public List filePaths = new ArrayList<>(); + /** list of file paths of the folder's content */ + @JvmField + var filePaths: List = ArrayList() - /** total number of files in the media folder. */ - public long numberOfFiles; + /** total number of files in the media folder. */ + @JvmField + var numberOfFiles: Long = 0 - /** type of media folder. */ - public MediaFolderType type; + /** 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 efd3cf9774cc..c89ea65927d7 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); - - private Integer id; - - private static SparseArray reverseMap = new SparseArray<>(3); - - 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; +enum class MediaFolderType(@JvmField val id: Int) { + CUSTOM(0), IMAGE(1), VIDEO(2); + + companion object { + private val reverseMap = SparseArray(3) + + init { + reverseMap.put(CUSTOM.id, CUSTOM) + reverseMap.put(IMAGE.id, IMAGE) + reverseMap.put(VIDEO.id, VIDEO) + } + + @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 5b164012eb80..8af531021981 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 f36f27dfbb39..baa107efdc96 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 @@ private ContentValues createContentValuesFromSyncedFolder(SyncedFolder syncedFol 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 8a377a544d05..2f316929809b 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 @@ private boolean showFooter() { public int getSectionByLocalPathAndType(String localPath, int type) { for (int i = 0; i < filteredSyncFolderItems.size(); i++) { if (filteredSyncFolderItems.get(i).getLocalPath().equalsIgnoreCase(localPath) && - filteredSyncFolderItems.get(i).getType().getId().equals(type)) { + filteredSyncFolderItems.get(i).getType().id == type) { return i; } } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java b/app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java index 2972465c331c..c1a223d20e60 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java +++ b/app/src/main/java/com/owncloud/android/ui/dialog/parcel/SyncedFolderParcelable.java @@ -105,7 +105,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(existing ? 1 : 0); dest.writeInt(enabled ? 1 : 0); dest.writeInt(subfolderByDate ? 1 : 0); - dest.writeInt(type.getId()); + dest.writeInt(type.id); dest.writeString(account); dest.writeInt(uploadAction); dest.writeInt(nameCollisionPolicy.serialize());