Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4663bbb
feat: cache content of different tabs
alperozturk96 Nov 20, 2025
ad5cedf
perf: implement diff util for adapter
alperozturk96 Nov 20, 2025
52977e1
offload jobs from adapter
alperozturk96 Nov 21, 2025
f4a0d1e
offload jobs from adapter
alperozturk96 Nov 21, 2025
4aa9cbc
extract diff util to new class
alperozturk96 Nov 21, 2025
5676fff
offload swapDirectory io jobs from main thread.
alperozturk96 Nov 21, 2025
0e7f94e
remove diff util
alperozturk96 Nov 21, 2025
048534d
fix lint
alperozturk96 Nov 21, 2025
4292260
fix lint
alperozturk96 Nov 21, 2025
e7c4de9
fix lint
alperozturk96 Nov 21, 2025
d084737
fix lint
alperozturk96 Nov 21, 2025
4616b81
only update if new data passed
alperozturk96 Nov 21, 2025
14a47b8
only update if new data passed
alperozturk96 Nov 21, 2025
c9d5ffd
fix state management
alperozturk96 Nov 21, 2025
7b0a6f9
faster filtering
alperozturk96 Nov 21, 2025
800e3d0
do not set empty list state outside of the empty list recycler view
alperozturk96 Nov 24, 2025
54d0f03
do not set empty list state outside of the empty list recycler view
alperozturk96 Nov 24, 2025
fbaac1d
add OCFileListAdapterHelperTest
alperozturk96 Nov 25, 2025
d961c78
add more OCFileListAdapterHelperTest
alperozturk96 Nov 26, 2025
94887ee
add more OCFileListAdapterHelperTest
alperozturk96 Nov 26, 2025
bd75d61
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
051a426
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
7942a48
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
c4a3c31
speed up parseAndSaveShares
alperozturk96 Nov 27, 2025
faf11d0
fix
alperozturk96 Nov 27, 2025
c1fd43c
fix
alperozturk96 Nov 27, 2025
e784cdf
detect new shares
alperozturk96 Nov 28, 2025
f70e3e8
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
a5d579a
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
96abd98
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.ui.adapter.OCShareToOCFileConverter
import com.owncloud.android.utils.EspressoIdlingResource
import com.owncloud.android.utils.ScreenshotTest
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -165,14 +167,14 @@ internal class SharedListFragmentIT : AbstractIT() {

fragment.isLoading = false
fragment.mEmptyListContainer?.visibility = View.GONE
fragment.adapter.setData(
shares,
SearchType.SHARED_FILTER,
storageManager,
null,
true
)

val newList = runBlocking {
OCShareToOCFileConverter.parseAndSaveShares(shares, storageManager, user.accountName)
}
fragment.adapter.run {
prepareForSearchData(storageManager, SearchType.SHARED_FILTER)
updateAdapter(newList, null)
}
EspressoIdlingResource.decrement()

val screenShotName = createName(testClassName + "_" + "showSharedFiles", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.nextcloud.client.database.dao.FileDao
import com.nextcloud.client.database.dao.FileSystemDao
import com.nextcloud.client.database.dao.OfflineOperationDao
import com.nextcloud.client.database.dao.RecommendedFileDao
import com.nextcloud.client.database.dao.ShareDao
import com.nextcloud.client.database.dao.SyncedFolderDao
import com.nextcloud.client.database.dao.UploadDao
import com.nextcloud.client.database.entity.ArbitraryDataEntity
Expand Down Expand Up @@ -106,6 +107,7 @@ abstract class NextcloudDatabase : RoomDatabase() {
abstract fun fileSystemDao(): FileSystemDao
abstract fun syncedFolderDao(): SyncedFolderDao
abstract fun assistantDao(): AssistantDao
abstract fun shareDao(): ShareDao

companion object {
const val FIRST_ROOM_DB_VERSION = 65
Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/com/nextcloud/client/database/dao/FileDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ interface FileDao {
@Query("SELECT * FROM filelist WHERE remote_id = :remoteId AND file_owner = :fileOwner LIMIT 1")
fun getFileByRemoteId(remoteId: String, fileOwner: String): FileEntity?

@Query("SELECT * FROM filelist WHERE remote_id = :remoteId LIMIT 1")
suspend fun getFileByRemoteId(remoteId: String): FileEntity?

@Query("SELECT * FROM filelist WHERE parent = :parentId ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}")
fun getFolderContent(parentId: Long): List<FileEntity>

@Query("SELECT * FROM filelist WHERE parent = :parentId ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}")
suspend fun getFolderContentSuspended(parentId: Long): List<FileEntity>

@Query(
"SELECT * FROM filelist WHERE modified >= :startDate" +
" AND modified < :endDate" +
Expand Down Expand Up @@ -111,4 +117,33 @@ interface FileDao {
"""
)
fun searchFilesInFolder(parentId: Long, fileOwner: String, query: String): List<FileEntity>

@Query(
"""
SELECT *
FROM filelist
WHERE file_owner = :accountName
AND (
share_by_link = 1
OR shared_via_users = 1
OR permissions LIKE '%S%'
)
ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}
"""
)
suspend fun getSharedFiles(accountName: String): List<FileEntity>

@Query(
"""
SELECT *
FROM filelist
WHERE file_owner = :fileOwner
AND favorite = 1
ORDER BY ${ProviderTableMeta.FILE_DEFAULT_SORT_ORDER}
"""
)
suspend fun getFavoriteFiles(fileOwner: String): List<FileEntity>

@Query("SELECT remote_id FROM filelist WHERE file_owner = :accountName AND remote_id IS NOT NULL")
fun getAllRemoteIds(accountName: String): List<String>
}
24 changes: 24 additions & 0 deletions app/src/main/java/com/nextcloud/client/database/dao/ShareDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2025 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

package com.nextcloud.client.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.nextcloud.client.database.entity.ShareEntity

@Dao
interface ShareDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(shares: List<ShareEntity>)

@Query("DELETE FROM ocshares WHERE owner_share = :accountName")
suspend fun clearSharesForAccount(accountName: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ package com.nextcloud.utils.extensions

import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.shares.OCShare
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

suspend fun FileDataStorageManager.saveShares(shares: List<OCShare>, accountName: String) {
withContext(Dispatchers.IO) {
val entities = shares.map { share ->
share.toEntity(accountName)
}

shareDao.insertAll(entities)
}
}

fun FileDataStorageManager.searchFilesByName(file: OCFile, accountName: String, query: String): List<OCFile> =
fileDao.searchFilesInFolder(file.fileId, accountName, query).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,34 @@ import com.owncloud.android.MainApp
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.utils.FileStorageUtils

fun List<OCFile>.filterFilenames(): List<OCFile> = distinctBy { it.fileName }
@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

fun List<OCFile>.filterTempFilter(): List<OCFile> = filterNot { it.isTempFile() }
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 List<OCFile>.filterHiddenFiles(): List<OCFile> = filterNot { it.isHidden }.distinct()

fun List<OCFile>.filterByMimeType(mimeType: String): List<OCFile> =
filter { it.isFolder || it.mimeType.startsWith(mimeType) }

fun List<OCFile>.limitToPersonalFiles(userId: String): List<OCFile> = filter { file ->
file.ownerId?.let { ownerId ->
ownerId == userId && !file.isSharedWithMe && !file.mounted()
} == true
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,35 @@

package com.nextcloud.utils.extensions

import com.nextcloud.client.database.entity.ShareEntity
import com.owncloud.android.lib.resources.shares.OCShare

fun OCShare.hasFileRequestPermission(): Boolean = (isFolder && shareType?.isPublicOrMail() == true)

fun List<OCShare>.mergeDistinctByToken(other: List<OCShare>): List<OCShare> = (this + other).distinctBy { it.token }

fun OCShare.toEntity(accountName: String): ShareEntity = ShareEntity(
id = remoteId.toInt(), // so that db is not keep updating same files
idRemoteShared = remoteId.toInt(),
path = path,
itemSource = itemSource.toInt(),
fileSource = fileSource.toInt(),
shareType = shareType?.value,
shareWith = shareWith,
permissions = permissions,
sharedDate = sharedDate.toInt(),
expirationDate = expirationDate.toInt(),
token = token,
shareWithDisplayName = sharedWithDisplayName,
isDirectory = if (isFolder) 1 else 0,
userId = userId,
accountOwner = accountName,
isPasswordProtected = if (isPasswordProtected) 1 else 0,
note = note,
hideDownload = if (isHideFileDownload) 1 else 0,
shareLink = shareLink,
shareLabel = label,
attributes = attributes,
downloadLimitLimit = fileDownloadLimit?.limit,
downloadLimitCount = fileDownloadLimit?.count
)
Loading
Loading