Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New arch] Available offline fixes #3764

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class FileDetailsFragment : FileFragment() {
is UIResult.Error -> {
showErrorInSnackbar(R.string.sync_fail_ticker, uiResult.error)
fileDetailsViewModel.updateActionInDetailsView(NONE)
requireActivity().invalidateOptionsMenu()
}
is UIResult.Loading -> {}
is UIResult.Success -> when (uiResult.data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package com.owncloud.android.presentation.ui.files.operations

import com.owncloud.android.domain.files.model.OCFile

sealed class FileOperation {
data class CopyOperation(val listOfFilesToCopy: List<OCFile>, val targetFolder: OCFile) : FileOperation()
data class CreateFolder(val folderName: String, val parentFile: OCFile) : FileOperation()
data class MoveOperation(val listOfFilesToMove: List<OCFile>, val targetFolder: OCFile) : FileOperation()
data class RemoveOperation(val listOfFilesToRemove: List<OCFile>, val removeOnlyLocalCopy: Boolean) : FileOperation()
data class RenameOperation(val ocFileToRename: OCFile, val newName: String) : FileOperation()
data class SynchronizeFileOperation(val fileToSync: OCFile, val accountName: String) : FileOperation()
data class SetFilesAsAvailableOffline(val filesToUpdate: List<OCFile>) : FileOperation()
data class UnsetFilesAsAvailableOffline(val filesToUpdate: List<OCFile>) : FileOperation()
sealed interface FileOperation {
data class CopyOperation(val listOfFilesToCopy: List<OCFile>, val targetFolder: OCFile) : FileOperation
data class CreateFolder(val folderName: String, val parentFile: OCFile) : FileOperation
data class MoveOperation(val listOfFilesToMove: List<OCFile>, val targetFolder: OCFile) : FileOperation
data class RemoveOperation(val listOfFilesToRemove: List<OCFile>, val removeOnlyLocalCopy: Boolean) : FileOperation
data class RenameOperation(val ocFileToRename: OCFile, val newName: String) : FileOperation
data class SynchronizeFileOperation(val fileToSync: OCFile, val accountName: String) : FileOperation
data class SetFilesAsAvailableOffline(val filesToUpdate: List<OCFile>) : FileOperation
data class UnsetFilesAsAvailableOffline(val filesToUpdate: List<OCFile>) : FileOperation
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.owncloud.android.presentation.ui.settings.fragments.SettingsMoreFragm
import com.owncloud.android.presentation.ui.settings.fragments.SettingsPictureUploadsFragment
import com.owncloud.android.presentation.ui.settings.fragments.SettingsSecurityFragment
import com.owncloud.android.presentation.ui.settings.fragments.SettingsVideoUploadsFragment
import com.owncloud.android.providers.WorkManagerProvider
import com.owncloud.android.ui.activity.FileDisplayActivity

class SettingsActivity : AppCompatActivity() {
Expand All @@ -62,12 +61,6 @@ class SettingsActivity : AppCompatActivity() {
redirectToSubsection(intent)
}

override fun onDestroy() {
val workerProvider = WorkManagerProvider(context = this)
workerProvider.enqueueAvailableOfflinePeriodicWorker()
super.onDestroy()
}

private fun updateToolbarTitle() {
val titleId = when (supportFragmentManager.fragments.lastOrNull()) {
is SettingsSecurityFragment -> R.string.prefs_subsection_security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import com.owncloud.android.presentation.ui.files.operations.FileOperation
import com.owncloud.android.presentation.ui.files.operations.FileOperationsViewModel
import com.owncloud.android.presentation.ui.security.bayPassUnlockOnce
import com.owncloud.android.presentation.viewmodels.transfers.TransfersViewModel
import com.owncloud.android.providers.WorkManagerProvider
import com.owncloud.android.syncadapter.FileSyncAdapter
import com.owncloud.android.ui.fragment.FileFragment
import com.owncloud.android.ui.fragment.TaskRetainerFragment
Expand Down Expand Up @@ -242,6 +243,8 @@ class FileDisplayActivity : FileActivity(),
super.onPostCreate(savedInstanceState)

if (savedInstanceState == null && mAccountWasSet) {
val workerProvider = WorkManagerProvider(context = this)
workerProvider.enqueueAvailableOfflinePeriodicWorker()
initAndShowListOfFiles()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface LocalFileDataSource {
fun getFilesAvailableOfflineFromAccount(owner: String): List<OCFile>
fun getFilesAvailableOfflineFromEveryAccount(): List<OCFile>
fun moveFile(sourceFile: OCFile, targetFolder: OCFile, finalRemotePath: String, finalStoragePath: String)
fun saveFilesInFolder(listOfFiles: List<OCFile>, folder: OCFile)
fun saveFilesInFolderAndReturnThem(listOfFiles: List<OCFile>, folder: OCFile): List<OCFile>
fun saveFile(file: OCFile)
fun removeFile(fileId: Long)
fun removeFilesForAccount(accountName: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ class OCLocalFileDataSource(
finalStoragePath = sourceFile.storagePath?.let { finalStoragePath }
)

override fun saveFilesInFolder(listOfFiles: List<OCFile>, folder: OCFile) {
override fun saveFilesInFolderAndReturnThem(listOfFiles: List<OCFile>, folder: OCFile): List<OCFile> {
// TODO: If it is root, add 0 as parent Id
fileDao.insertFilesInFolder(
val folderContent = fileDao.insertFilesInFolderAndReturnThem(
folder = folder.toEntity(),
folderContent = listOfFiles.map { it.toEntity() }
)
return folderContent.map { it.toModel() }
}

override fun saveFile(file: OCFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ abstract class FileDao {

/**
* Make sure that the ids are set properly. We don't take care of conflicts and that stuff here.
*
* return folder content
*/
@Transaction
open fun insertFilesInFolder(
open fun insertFilesInFolderAndReturnThem(
folder: OCFileEntity,
folderContent: List<OCFileEntity>,
) {
): List<OCFileEntity> {
val folderId = insert(folder)

folderContent.forEach { fileToInsert ->
Expand All @@ -130,6 +132,7 @@ abstract class FileDao {
availableOfflineStatus = getNewAvailableOfflineStatus(folder.availableOfflineStatus, fileToInsert.availableOfflineStatus)
})
}
return getFolderContent(folderId)
}

@Transaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OCFileRepository(
createFullPath = false,
isChunksFolder = false
).also {
localFileDataSource.saveFilesInFolder(
localFileDataSource.saveFilesInFolderAndReturnThem(
folder = parentFolder,
listOfFiles = listOf(
OCFile(
Expand Down Expand Up @@ -270,11 +270,10 @@ class OCFileRepository(
}
}

localFileDataSource.saveFilesInFolder(
return localFileDataSource.saveFilesInFolderAndReturnThem(
folder = remoteFolder,
listOfFiles = folderContentUpdated
)
return folderContentUpdated
}

override fun removeFile(listOfFilesToRemove: List<OCFile>, removeOnlyLocalCopy: Boolean) {
Expand Down