forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOCFileExtensions.kt
More file actions
86 lines (68 loc) · 2.55 KB
/
OCFileExtensions.kt
File metadata and controls
86 lines (68 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.utils.extensions
import com.owncloud.android.MainApp
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.OCFileDepth
import com.owncloud.android.datamodel.OCFileDepth.DeepLevel
import com.owncloud.android.datamodel.OCFileDepth.FirstLevel
import com.owncloud.android.datamodel.OCFileDepth.Root
import com.owncloud.android.utils.FileStorageUtils
@Suppress("ReturnCount")
fun List<OCFile>.hasSameContentAs(other: List<OCFile>): Boolean {
if (this.size != other.size) return false
if (this === other) return true
for (i in this.indices) {
val a = this[i]
val b = other[i]
if (a != b) return false
if (a.fileId != b.fileId) return false
if (a.etag != b.etag) return false
if (a.modificationTimestamp != b.modificationTimestamp) return false
if (a.fileLength != b.fileLength) return false
if (a.isFavorite != b.isFavorite) return false
if (a.fileName != b.fileName) return false
}
return true
}
fun List<OCFile>.filterFilenames(): List<OCFile> = distinctBy { it.fileName }
fun OCFile.isTempFile(): Boolean {
val context = MainApp.getAppContext()
val appTempPath = FileStorageUtils.getAppTempDirectoryPath(context)
return storagePath?.startsWith(appTempPath) == true
}
fun OCFile.mediaSize(defaultThumbnailSize: Float): Pair<Int, Int> {
val width = (imageDimension?.width?.toInt() ?: defaultThumbnailSize.toInt())
val height = (imageDimension?.height?.toInt() ?: defaultThumbnailSize.toInt())
return width to height
}
fun OCFile?.isPNG(): Boolean {
if (this == null) {
return false
}
return "image/png".equals(mimeType, ignoreCase = true)
}
@Suppress("ReturnCount")
fun OCFile?.getDepth(): OCFileDepth? {
if (this == null) {
return null
}
// Check if it's the root directory
if (this.isRootDirectory) {
return Root
}
// If parent is root ("/"), this is a direct child of root
val parentPath = this.parentRemotePath ?: return null
if (parentPath == OCFile.ROOT_PATH) {
return FirstLevel
}
// Otherwise, it's a subdirectory of a subdirectory
return DeepLevel
}
// NMC method to filter only folders with/without e2ee folders
fun List<OCFile>.filterByFolder(hideEncryptedFolder: Boolean = false): List<OCFile> =
filter { it.isFolder && (!hideEncryptedFolder || !it.isEncrypted) }