Skip to content

Commit

Permalink
Convert to kt
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Nov 3, 2023
1 parent d7ea127 commit f499959
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ class MediaFoldersDetectionWork constructor(
)
val imageMediaFolderPaths: MutableList<String> = ArrayList()
val videoMediaFolderPaths: MutableList<String> = 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)
Expand Down
36 changes: 19 additions & 17 deletions app/src/main/java/com/owncloud/android/datamodel/MediaFolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <http://www.gnu.org/licenses/>.
* License along with this program. If not, see <http:></http:>//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<String> filePaths = new ArrayList<>();
/** list of file paths of the folder's content */
@JvmField
var filePaths: List<String> = 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
}
45 changes: 18 additions & 27 deletions app/src/main/java/com/owncloud/android/datamodel/MediaFolderType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,28 @@
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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<MediaFolderType> 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<MediaFolderType>(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!!]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,6 @@
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.datamodel

package com.owncloud.android.datamodel;

import java.util.List;

public class MediaFoldersModel {
private List<String> imageMediaFolders;
private List<String> videoMediaFolders;

public MediaFoldersModel(List<String> imageMediaFolders, List<String> videoMediaFolders) {
this.imageMediaFolders = imageMediaFolders;
this.videoMediaFolders = videoMediaFolders;
}

public List<String> getImageMediaFolders() {
return this.imageMediaFolders;
}

public List<String> getVideoMediaFolders() {
return this.videoMediaFolders;
}

public void setImageMediaFolders(List<String> imageMediaFolders) {
this.imageMediaFolders = imageMediaFolders;
}

public void setVideoMediaFolders(List<String> videoMediaFolders) {
this.videoMediaFolders = videoMediaFolders;
}
}
class MediaFoldersModel(var imageMediaFolders: List<String>, var videoMediaFolders: List<String>)
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit f499959

Please sign in to comment.