Skip to content

Commit 965ca75

Browse files
alperozturk96backportbot[bot]
authored andcommitted
fix: search task root sub dir content fetch
Signed-off-by: alperozturk <[email protected]>
1 parent 1bc71f8 commit 965ca75

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

app/src/main/java/com/owncloud/android/ui/fragment/OCFileListSearchTask.kt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package com.owncloud.android.ui.fragment
1111
import android.annotation.SuppressLint
1212
import android.app.Activity
1313
import android.content.ContentValues
14+
import android.content.Context
1415
import androidx.lifecycle.lifecycleScope
1516
import com.nextcloud.client.account.User
1617
import com.nextcloud.client.preferences.AppPreferences
@@ -40,8 +41,9 @@ import kotlinx.coroutines.launch
4041
import kotlinx.coroutines.withContext
4142
import kotlinx.coroutines.withTimeoutOrNull
4243
import java.lang.ref.WeakReference
44+
import java.util.concurrent.TimeUnit
4345

44-
@Suppress("LongParameterList", "ReturnCount", "TooGenericExceptionCaught")
46+
@Suppress("LongParameterList", "ReturnCount", "TooGenericExceptionCaught", "DEPRECATION", "MagicNumber")
4547
@SuppressLint("NotifyDataSetChanged")
4648
class OCFileListSearchTask(
4749
containerActivity: FileFragment.ContainerActivity,
@@ -64,7 +66,6 @@ class OCFileListSearchTask(
6466

6567
private var job: Job? = null
6668

67-
@Suppress("TooGenericExceptionCaught", "DEPRECATION", "ReturnCount")
6869
fun execute() {
6970
Log_OC.d(TAG, "search task running, query: ${event.searchType}")
7071
val fragment = fragmentReference.get() ?: return
@@ -105,6 +106,14 @@ class OCFileListSearchTask(
105106
fragment.adapter.files
106107
}
107108

109+
val subDirectories = newList
110+
.filter { it.isFolder }
111+
.sortedBy { it.fileId }
112+
113+
subDirectories.forEach { dir ->
114+
fetchRootSubDirContent(dir, fileDataStorageManager, fragment.context)
115+
}
116+
108117
val sortedNewList = sortSearchData(newList, searchType, null, setNewSortOrder = {
109118
fragment.adapter.setSortOrder(it)
110119
})
@@ -126,6 +135,39 @@ class OCFileListSearchTask(
126135

127136
fun isFinished(): Boolean = job?.isCompleted == true
128137

138+
private suspend fun fetchRootSubDirContent(
139+
folder: OCFile,
140+
storageManager: FileDataStorageManager?,
141+
context: Context?
142+
) = withContext(Dispatchers.IO) {
143+
if (context == null || storageManager == null) {
144+
Log_OC.e(TAG, "sub directory content cannot be fetched, context or storage manager is null")
145+
return@withContext
146+
}
147+
148+
val currentSyncTime = System.currentTimeMillis()
149+
val shouldIgnoreETag = (currentSyncTime - folder.lastSyncDateForProperties) > TimeUnit.MINUTES.toMillis(5)
150+
151+
Log_OC.d(TAG, "fetching content for: " + folder.remotePath + " ignore eTag: " + shouldIgnoreETag)
152+
153+
val operation =
154+
RefreshFolderOperation(
155+
folder,
156+
currentSyncTime,
157+
shouldIgnoreETag,
158+
shouldIgnoreETag,
159+
storageManager,
160+
currentUser,
161+
context
162+
)
163+
val result = operation.execute(currentUser, context)
164+
if (result.isSuccess) {
165+
Log_OC.d(TAG, "sub directory content is fetched")
166+
} else {
167+
Log_OC.e(TAG, "sub directory content cannot be fetched")
168+
}
169+
}
170+
129171
private suspend fun loadCachedDbFiles(searchType: SearchRemoteOperation.SearchType): List<OCFile> {
130172
val storage = fileDataStorageManager ?: return emptyList()
131173
return if (searchType == SearchRemoteOperation.SearchType.SHARED_FILTER) {
@@ -137,7 +179,6 @@ class OCFileListSearchTask(
137179
}.mapNotNull { storage.createFileInstance(it) }
138180
}
139181

140-
@Suppress("DEPRECATION")
141182
private suspend fun fetchRemoteResults(): RemoteOperationResult<List<Any>>? {
142183
val fragment = fragmentReference.get() ?: return null
143184
val context = fragment.context ?: return null

0 commit comments

Comments
 (0)