Skip to content

Commit 41fc243

Browse files
committed
check nested files
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent 983635c commit 41fc243

File tree

6 files changed

+64
-2
lines changed

6 files changed

+64
-2
lines changed

app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,22 @@ interface FileDao {
146146

147147
@Query("SELECT remote_id FROM filelist WHERE file_owner = :accountName AND remote_id IS NOT NULL")
148148
fun getAllRemoteIds(accountName: String): List<String>
149+
150+
@Query("SELECT parent FROM filelist WHERE _id = :fileId LIMIT 1")
151+
suspend fun getParentId(fileId: Long): Long?
152+
153+
@Query("SELECT favorite FROM filelist WHERE _id = :fileId LIMIT 1")
154+
suspend fun isFavoriteFolder(fileId: Long): Int?
155+
156+
@Query(
157+
"""
158+
SELECT
159+
(share_by_link = 1) OR
160+
(shared_via_users = 1) OR
161+
(permissions LIKE '%S%')
162+
FROM filelist
163+
WHERE _id = :fileId LIMIT 1
164+
"""
165+
)
166+
suspend fun isSharedFolder(fileId: Long): Boolean?
149167
}

app/src/main/java/com/owncloud/android/datamodel/OCFileListAdapterDataProviderImpl.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package com.owncloud.android.datamodel
1010
import com.nextcloud.client.database.entity.FileEntity
1111
import com.owncloud.android.ui.adapter.helper.OCFileListAdapterDataProvider
1212

13+
@Suppress("ReturnCount")
1314
class OCFileListAdapterDataProviderImpl(private val storageManager: FileDataStorageManager) :
1415
OCFileListAdapterDataProvider {
1516
override fun convertToOCFiles(id: Long): List<OCFile> =
@@ -19,4 +20,30 @@ class OCFileListAdapterDataProviderImpl(private val storageManager: FileDataStor
1920
storageManager.fileDao.getFolderContentSuspended(id)
2021

2122
override fun createFileInstance(entity: FileEntity): OCFile = storageManager.createFileInstance(entity)
23+
24+
override suspend fun hasFavoriteParent(fileId: Long): Boolean {
25+
var currentId: Long? = fileId
26+
27+
while (currentId != null) {
28+
val parentId = storageManager.fileDao.getParentId(currentId) ?: return false
29+
val isFavorite = storageManager.fileDao.isFavoriteFolder(parentId) == 1
30+
if (isFavorite) return true
31+
currentId = parentId
32+
}
33+
34+
return false
35+
}
36+
37+
override suspend fun hasSharedParent(fileId: Long): Boolean {
38+
var currentId: Long? = fileId
39+
40+
while (currentId != null) {
41+
val parentId = storageManager.fileDao.getParentId(currentId) ?: return false
42+
val isShared = storageManager.fileDao.isSharedFolder(parentId) == true
43+
if (isShared) return true
44+
currentId = parentId
45+
}
46+
47+
return false
48+
}
2249
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ interface OCFileListAdapterDataProvider {
1414
fun convertToOCFiles(id: Long): List<OCFile>
1515
suspend fun getFolderContent(id: Long): List<FileEntity>
1616
fun createFileInstance(entity: FileEntity): OCFile
17+
suspend fun hasFavoriteParent(fileId: Long): Boolean
18+
suspend fun hasSharedParent(fileId: Long): Boolean
1719
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ class OCFileListAdapterHelper {
9090
}
9191
}
9292

93-
if (isSharedView && !directory.isShared && !file.isShared) {
93+
val hasSharedParent = dataProvider.hasSharedParent(file.fileId)
94+
if (isSharedView && !hasSharedParent && !file.isShared) {
9495
continue
9596
}
9697

97-
if (isFavoritesView && !directory.isFavorite && !file.isFavorite) {
98+
val hasFavoriteParent = dataProvider.hasFavoriteParent(file.fileId)
99+
if (isFavoritesView && !hasFavoriteParent && !file.isFavorite) {
98100
continue
99101
}
100102

app/src/test/java/com/owncloud/android/ui/adapter/MockOCFileListAdapterDataProvider.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class MockOCFileListAdapterDataProvider : OCFileListAdapterDataProvider {
1717

1818
private var offlineOCFile: OCFile? = null
1919
private var files = listOf<OCFile>()
20+
var hasFavoriteParent = false
21+
var hasSharedParent = false
2022

2123
private fun getEntities(): List<FileEntity> = files.map { file ->
2224
FileEntity(
@@ -94,4 +96,8 @@ class MockOCFileListAdapterDataProvider : OCFileListAdapterDataProvider {
9496
}
9597

9698
override fun createFileInstance(entity: FileEntity): OCFile = files.first { it.fileId == entity.id }
99+
100+
override suspend fun hasFavoriteParent(fileId: Long): Boolean = hasFavoriteParent
101+
102+
override suspend fun hasSharedParent(fileId: Long): Boolean = hasSharedParent
97103
}

app/src/test/java/com/owncloud/android/ui/adapter/OCFileListAdapterHelperTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class OCFileListAdapterHelperTest {
7979
this.localId = localId
8080
etag = "etag_$id"
8181
storagePath = localPath
82+
sharees = emptyList()
8283
}
8384

8485
fun prepare(files: List<OCFile>, offline: OCFile? = null) {
@@ -149,6 +150,9 @@ class OCFileListAdapterHelperTest {
149150
}
150151
val file6 = env.file(sub2, "image6.jpg", 16, MimeType.JPEG)
151152

153+
dataProvider.hasFavoriteParent = true
154+
dataProvider.hasSharedParent = false
155+
152156
env.prepare(listOf(root, sub1, sub2, file1, file2, file3, file4, file5, file6))
153157
stubPreferences(sort = FileSortOrder.SORT_A_TO_Z, favFirst = true)
154158
val (list, sort) = env.run(sub1)
@@ -178,6 +182,9 @@ class OCFileListAdapterHelperTest {
178182
}
179183
val file6 = env.file(sub2, "image6.jpg", 16, MimeType.JPEG)
180184

185+
dataProvider.hasFavoriteParent = false
186+
dataProvider.hasSharedParent = true
187+
181188
env.prepare(listOf(root, sub1, sub2, file1, file2, file3, file4, file5, file6))
182189
stubPreferences(sort = FileSortOrder.SORT_A_TO_Z, favFirst = true)
183190
val (list, sort) = env.run(sub1)

0 commit comments

Comments
 (0)