Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d105cc1
feat: cache content of different tabs
alperozturk96 Nov 20, 2025
144d639
perf: implement diff util for adapter
alperozturk96 Nov 20, 2025
2d6bf25
offload jobs from adapter
alperozturk96 Nov 21, 2025
c375e21
offload jobs from adapter
alperozturk96 Nov 21, 2025
68dd404
extract diff util to new class
alperozturk96 Nov 21, 2025
8b9cb5f
offload swapDirectory io jobs from main thread.
alperozturk96 Nov 21, 2025
90f5a1e
remove diff util
alperozturk96 Nov 21, 2025
1e87a96
fix lint
alperozturk96 Nov 21, 2025
949251a
fix lint
alperozturk96 Nov 21, 2025
e13343b
fix lint
alperozturk96 Nov 21, 2025
a5ce31a
fix lint
alperozturk96 Nov 21, 2025
cab8728
only update if new data passed
alperozturk96 Nov 21, 2025
fdf77da
only update if new data passed
alperozturk96 Nov 21, 2025
54a0749
fix state management
alperozturk96 Nov 21, 2025
1107c08
faster filtering
alperozturk96 Nov 21, 2025
ac25f9b
do not set empty list state outside of the empty list recycler view
alperozturk96 Nov 24, 2025
1f92478
do not set empty list state outside of the empty list recycler view
alperozturk96 Nov 24, 2025
77f3151
add OCFileListAdapterHelperTest
alperozturk96 Nov 25, 2025
75e5955
add more OCFileListAdapterHelperTest
alperozturk96 Nov 26, 2025
6283862
add more OCFileListAdapterHelperTest
alperozturk96 Nov 26, 2025
48351df
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
7b3e948
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
80b1a9c
speed up parseAndSaveShares
alperozturk96 Nov 26, 2025
5dfd9a0
speed up parseAndSaveShares
alperozturk96 Nov 27, 2025
e5094f4
fix
alperozturk96 Nov 27, 2025
dc86f03
fix
alperozturk96 Nov 27, 2025
905ef22
detect new shares
alperozturk96 Nov 28, 2025
9098840
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
6ae533c
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
493d660
fix caching mechanism use file dao
alperozturk96 Nov 28, 2025
35255cd
fix: ocfile constructor from share
alperozturk96 Dec 1, 2025
c387abc
fix git conflict
alperozturk96 Dec 2, 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 <[email protected]>
* 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,27 +11,38 @@ 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
}

fun OCFile.mediaSize(defaultThumbnailSize: Float): Pair<Int, Int> {
val width = (imageDimension?.width?.toInt() ?: defaultThumbnailSize.toInt())
val height = (imageDimension?.height?.toInt() ?: defaultThumbnailSize.toInt())
Expand Down
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