Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
setProperty("archivesBaseName", "kdrive-$versionName ($versionCode)")

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "CLIENT_ID", "\"9473D73C-C20F-4971-9E10-D957C563FA68\"")
buildConfigField("String", "CLIENT_ID", "\"6B9A260B-EE8C-46C9-8B4F-61B2169B31ED\"")

buildConfigField("String", "BUGTRACKER_DRIVE_BUCKET_ID", "\"app_drive\"")
buildConfigField("String", "BUGTRACKER_DRIVE_PROJECT_NAME", "\"drive\"")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2024 Infomaniak Network SA
* Copyright (C) 2024-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -299,11 +299,11 @@ class FileControllerTest : KDriveTest() {
FileController.saveRemoteFileToDb(remoteFile, userDrive, okHttpClient)

assertNotNull(
FileController.getFileById(remoteFile.id, userDrive),
FileController.getFileByUidOrId(remoteFile.id, userDrive),
"the saved remote file must be stored in realm",
)

val localParent = FileController.getFileById(folder.id, userDrive)
val localParent = FileController.getFileByUidOrId(folder.id, userDrive)
assertNotNull(localParent, "the ancestor folder must be fetched and stored in realm")

assertNotNull(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,28 @@ object FileController {
return customRealm?.let(block) ?: getRealmInstance(userDrive).use(block)
}

fun getFileById(fileId: Int, userDrive: UserDrive? = null): File? {
return getRealmInstance(userDrive).use { realm ->
fun getFileByUidOrId(fileId: Int, userDrive: UserDrive? = null): File? {
return userDrive?.let { getFileByUid(fileId, userDrive = it) } ?: getFileById(fileId)
}
Comment on lines +160 to +162

private fun getFileById(fileId: Int): File? {
return getRealmInstance().use { realm ->
realm.where(File::class.java).equalTo(File::id.name, fileId).findFirst()?.let {
realm.copyFromRealm(it, 1)
}
}
}

private fun getFileByUid(fileId: Int, userDrive: UserDrive): File? {
val uid = "${fileId}_${userDrive.driveId}"
return getRealmInstance(userDrive).use { realm ->
realm.where(File::class.java)
.equalTo(File::uid.name, uid)
.findFirst()
?.let { realm.copyFromRealm(it, 1) }
}
}

suspend fun hasFile(fileId: Int, userDrive: UserDrive? = null): Boolean = forRealm(userDrive) {
where(File::class.java)
.equalTo(File::id.name, fileId)
Expand Down Expand Up @@ -313,7 +327,7 @@ object FileController {
if (filesToDelete.isEmpty()) return

val file = filesToDelete.removeAt(0)
val children = getFileById(file.id, userDrive)?.children ?: emptyList()
val children = getFileByUidOrId(file.id, userDrive)?.children ?: emptyList()

filesToDelete.addAll(children)
file.deleteCaches(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class CloudStorageProvider : DocumentsProvider() {
val accessMode = ParcelFileDescriptor.parseMode(mode)
val fileId = getFileIdFromDocumentId(documentId)
val userDrive = createUserDrive(documentId)
val localFile = FileController.getFileById(fileId, userDrive)
val localFile = FileController.getFileByUidOrId(fileId, userDrive)

val updatedFile = runCatching {
getRemoteFile(localFile, fileId, userDrive.driveId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ sealed interface DeeplinkType : Parcelable {

val deeplinkTargetFile = getDrives(sharedWithMe = withSharedDrives).firstNotNullOfOrNull { userDrive ->
newUserId = userDrive.userId
FileController.getFileById(fileId, userDrive = userDrive)
FileController.getFileByUidOrId(fileId, userDrive = userDrive)
}

return deeplinkTargetFile?.let { file ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2024-2025 Infomaniak Network SA
* Copyright (C) 2024-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -35,7 +35,7 @@ class BulkDownloadWorker(context: Context, workerParams: WorkerParameters) : Bas
private val folderId: Int by lazy { inputData.getInt(FOLDER_ID, 0) }
private val files: List<File> by lazy {
FileController.getFolderOfflineFilesId(folderId = folderId, sortType = UiSettings(context).sortType)
.map { FileController.getFileById(it, userDrive)!! }
.map { FileController.getFileByUidOrId(it, userDrive)!! }
}

private val userDrive: UserDrive by lazy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2025 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,7 @@ import com.infomaniak.drive.utils.NotificationUtils.cancelNotification
class DownloadWorker(context: Context, workerParams: WorkerParameters) : BaseDownloadWorker(context, workerParams) {

private val fileId: Int by lazy { inputData.getInt(FILE_ID, 0) }
private val file: File? by lazy { FileController.getFileById(fileId) }
private val file: File? by lazy { FileController.getFileByUidOrId(fileId) }
private val fileName: String by lazy { inputData.getString(FILE_NAME) ?: "" }
private val userDrive: UserDrive by lazy {
UserDrive(
Expand All @@ -47,7 +47,7 @@ class DownloadWorker(context: Context, workerParams: WorkerParameters) : BaseDow
)
}

override fun downloadNotification(): DownloadNotification? {
override fun downloadNotification(): DownloadNotification {
return DownloadNotification(id = fileId, notification = downloadProgressNotification)
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,15 @@ class MainViewModel(

// Emit destination folder id
viewModelScope.launch(Dispatchers.IO) {
val file = FileController.getFileById(fileId, userDrive)
val file = FileController.getFileByUidOrId(fileId, userDrive)
?: FileController.getFileDetails(fileId, userDrive = userDrive)
?: return@launch
navigateFileListTo.postValue(FileListNavigationType.Folder(file))
}
}

fun loadCurrentFolder(folderId: Int, userDrive: UserDrive) = viewModelScope.launch(Dispatchers.IO) {
postCurrentFolder(FileController.getFileById(folderId, userDrive))
postCurrentFolder(FileController.getFileByUidOrId(folderId, userDrive))
}

fun createMultiSelectMediator(): MediatorLiveData<MultiSelectMediatorState> =
Expand Down Expand Up @@ -602,7 +602,7 @@ class MainViewModel(
private fun initCurrentFolderFromRealm() {
val savedFolderId: Int? = savedStateHandle[SAVED_STATE_FOLDER_ID_KEY]
if (currentFolder.value == null && savedFolderId != null) {
FileController.getFileById(savedFolderId)?.let {
FileController.getFileByUidOrId(savedFolderId)?.let {
_currentFolder.value = it
saveCurrentFolder()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class SaveExternalFilesActivity : BaseActivity() {
)
driveIdSharedWithMe = FileController.getSharedDrive(userDrive.userId, folderId)?.driveId

FileController.getFileById(folderId, userDrive) ?: FileController.getFileById(
FileController.getFileByUidOrId(folderId, userDrive) ?: FileController.getFileByUidOrId(
fileId = folderId,
userDrive = UserDrive(
userId = selectedUserId.value!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class FileInfoActionsBottomSheetDialog : EdgeToEdgeBottomSheetDialog(), FileInfo
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

currentFile = FileController.getFileById(navigationArgs.fileId, navigationArgs.userDrive) ?: run {
currentFile = FileController.getFileByUidOrId(navigationArgs.fileId, navigationArgs.userDrive) ?: run {
findNavController().popBackStack()
return
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2024 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,7 +43,7 @@ class NotSupportedExtensionBottomSheetDialog : InformationBottomSheetDialog() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?): Unit = with(binding) {
super.onViewCreated(view, savedInstanceState)

FileController.getFileById(navigationArgs.fileId, userDrive)?.let { currentFile ->
FileController.getFileByUidOrId(navigationArgs.fileId, userDrive)?.let { currentFile ->

title.text = getString(R.string.notSupportedExtensionTitle, currentFile.getFileExtension())
description.text = getString(R.string.notSupportedExtensionDescription, currentFile.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DeeplinkHandler(registryOwner: SavedStateRegistryOwner) : SavedStateRegist
activity.lifecycleScope.launch(context = Dispatchers.IO) {
DriveInfosController.getDrive(userId = userId, driveId = driveId, maintenance = false)
?.ensureRightUser()
?.run { FileController.getFileById(fileId = fileId, userDrive = UserDrive(userId = userId, driveId = id)) }
?.run { FileController.getFileByUidOrId(fileId = fileId, userDrive = UserDrive(userId = userId, driveId = id)) }
?.let { Dispatchers.Main { activity.openOnlyOfficeActivity(it) } }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2025 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,7 +47,7 @@ class ConvertToDropboxFragment : ManageDropboxFragment() {
shareLinkCardView.isGone = true
disableButton.isGone = true

val file = FileController.getFileById(navigationArgs.fileId) ?: return
val file = FileController.getFileByUidOrId(navigationArgs.fileId) ?: return

updateUi(file)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2025 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -92,7 +92,7 @@ open class ManageDropboxFragment : Fragment() {
disableButton.isEnabled = false
saveButton.isEnabled = false

FileController.getFileById(navigationArgs.fileId)?.let { file ->
FileController.getFileByUidOrId(navigationArgs.fileId)?.let { file ->
disableButton.isEnabled = true

if (isManageDropBox) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2024-2025 Infomaniak Network SA
* Copyright (C) 2024-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -40,7 +40,7 @@ class DownloadProgressViewModel : ViewModel() {
val localFile = SingleLiveEvent<File?>()

fun getLocalFile(fileId: Int, userDrive: UserDrive) {
localFile.value = FileController.getFileById(fileId, userDrive)
localFile.value = FileController.getFileByUidOrId(fileId, userDrive)
}

fun downloadFile(context: Context, file: File, userDrive: UserDrive) = viewModelScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ open class FileListFragment : MultiSelectFragment(
is DeeplinkFilePath.FilePreviewInFolder -> fileType.folderId
else -> navigationArgs.folderId
}
folderName = fileType?.let { FileController.getFileById(folderId, userDrive)?.name } ?: navigationArgs.folderName
folderName = fileType?.let { FileController.getFileByUidOrId(folderId, userDrive)?.name } ?: navigationArgs.folderName
}

override fun initMultiSelectLayout(): MultiSelectLayoutBinding? = binding.multiSelectLayout
Expand Down Expand Up @@ -384,7 +384,7 @@ open class FileListFragment : MultiSelectFragment(
lifecycleScope.launchWhenResumed {
with(requireActivity() as SelectFolderActivity) {
showSaveButton()
val currentFolderRights = FileController.getFileById(folderId, userDrive)?.rights ?: Rights()
val currentFolderRights = FileController.getFileByUidOrId(folderId, userDrive)?.rights ?: Rights()
val enable = folderId != selectFolderViewModel.disableSelectedFolderId
&& (currentFolderRights.canMoveInto || currentFolderRights.canCreateFile)
enableSaveButton(enable)
Expand Down Expand Up @@ -654,7 +654,7 @@ open class FileListFragment : MultiSelectFragment(
activitiesRefreshTimer.cancel()
isLoadingActivities = true
mainViewModel.currentFolder.value?.let { localCurrentFolder ->
FileController.getFileById(localCurrentFolder.id, userDrive)?.let { updatedFolder ->
FileController.getFileByUidOrId(localCurrentFolder.id, userDrive)?.let { updatedFolder ->
downloadFolderActivities(updatedFolder)
activitiesRefreshTimer.start()
} ?: run { activitiesRefreshTimer.start() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class FileListViewModel(application: Application) : AndroidViewModel(application
}

fun shouldDisplaySubtitle(folderId: Int, userDrive: UserDrive?): Boolean {
val folder = FileController.getFileById(folderId, userDrive) ?: return false
val folder = FileController.getFileByUidOrId(folderId, userDrive) ?: return false
return folder.getVisibilityType() == File.VisibilityType.IS_TEAM_SPACE
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class SelectFolderActivity : BaseActivity() {
val selectedFolderName = if (folderId == ROOT_ID) {
currentDrive?.name
} else {
FileController.getFileById(folderId, userDrive)?.name
FileController.getFileByUidOrId(folderId, userDrive)?.name
}
return selectedFolderName ?: "/"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2025 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -57,7 +57,7 @@ class SelectFolderFragment : FileListFragment() {
toolbar.menu.findItem(R.id.addFolderItem).apply {
setOnMenuItemClickListener {
val selectFolderActivity = requireActivity() as? SelectFolderActivity
if (FileController.getFileById(folderId, userDrive)?.rights?.canCreateDirectory == true) {
if (FileController.getFileByUidOrId(folderId, userDrive)?.rights?.canCreateDirectory == true) {
selectFolderActivity?.hideSaveButton()
trackNewElementEvent(MatomoName.CreateFolderOnTheFly)
safeNavigate(
Expand Down Expand Up @@ -96,7 +96,7 @@ class SelectFolderFragment : FileListFragment() {
lifecycleScope.launchWhenResumed {
with(requireActivity() as SelectFolderActivity) {
showSaveButton()
val currentFolderRights = FileController.getFileById(folderId, userDrive)?.rights ?: Rights()
val currentFolderRights = FileController.getFileByUidOrId(folderId, userDrive)?.rights ?: Rights()
val enable = folderId != selectFolderViewModel.disableSelectedFolderId
&& (currentFolderRights.canMoveInto || currentFolderRights.canCreateFile)
enableSaveButton(enable)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2024 Infomaniak Network SA
* Copyright (C) 2024-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -65,7 +65,7 @@ class SharedWithMeViewModel : ViewModel() {
FileController.createSharedWithMeFolderIfNeeded(userDrive)
}

val folderIsNotEmpty = FileController.getFileById(folderId, userDrive)?.children?.isNotEmpty() == true
val folderIsNotEmpty = FileController.getFileByUidOrId(folderId, userDrive)?.children?.isNotEmpty() == true
if (folderIsNotEmpty) notifyUiToLoadData()

if (!isNewSort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class UploadInProgressViewModel(application: Application) : AndroidViewModel(app
private val getFolderJob = Job()

fun getFolder(folderId: Int, userDrive: UserDrive) = liveData(getFolderJob + Dispatchers.IO) {
val localFolder = FileController.getFileById(folderId, userDrive)
val localFolder = FileController.getFileByUidOrId(folderId, userDrive)
var remoteFolder: File? = null

if (localFolder == null) {
Expand Down Expand Up @@ -156,7 +156,7 @@ class UploadInProgressViewModel(application: Application) : AndroidViewModel(app
}

private fun createFolderFile(fileId: Int, userDrive: UserDrive): File? {
val folder = FileController.getFileById(fileId, userDrive)
val folder = FileController.getFileByUidOrId(fileId, userDrive)
?: FileController.getFileDetails(fileId, userDrive)
?: return null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Infomaniak kDrive - Android
* Copyright (C) 2022-2024 Infomaniak Network SA
* Copyright (C) 2022-2026 Infomaniak Network SA
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -33,7 +33,7 @@ class CreateOrEditCategoryViewModel : ViewModel() {
val driveId: Int by lazy { selectedFiles.first().driveId }

fun init(filesId: IntArray?): LiveData<Boolean> = liveData(Dispatchers.IO) {
selectedFiles = filesId?.toList()?.mapNotNull { fileId -> FileController.getFileById(fileId) } ?: emptyList()
selectedFiles = filesId?.toList()?.mapNotNull { fileId -> FileController.getFileByUidOrId(fileId) } ?: emptyList()
emit(selectedFiles.isEmpty())
}

Expand Down
Loading
Loading