diff --git a/owncloudApp/src/main/AndroidManifest.xml b/owncloudApp/src/main/AndroidManifest.xml index 0abeee83540..8f15da93d0b 100644 --- a/owncloudApp/src/main/AndroidManifest.xml +++ b/owncloudApp/src/main/AndroidManifest.xml @@ -138,9 +138,6 @@ android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter_files" /> - > { - return listOf() - // FIXME: 13/10/2020 : New_arch: Av.Offline -// val result = ArrayList>() -// var cursorOnKeptInSync: Cursor? = null -// try { -// cursorOnKeptInSync = performQuery( -// uri = CONTENT_URI, -// projection = null, -// selection = "$FILE_KEEP_IN_SYNC = ? OR $FILE_KEEP_IN_SYNC = ?", -// selectionArgs = arrayOf(AVAILABLE_OFFLINE.value.toString(), AVAILABLE_OFFLINE_PARENT.value.toString()), -// sortOrder = null, -// performWithContentProviderClient = false -// ) -// -// if (cursorOnKeptInSync != null && cursorOnKeptInSync.moveToFirst()) { -// var file: OCFile? -// var accountName: String -// do { -// file = createFileInstance(cursorOnKeptInSync) -// accountName = -// cursorOnKeptInSync.getStringFromColumnOrEmpty(FILE_ACCOUNT_OWNER) -// if (!file!!.isFolder && AccountUtils.exists(accountName, mContext)) { -// result.add(Pair(file, accountName)) -// } -// } while (cursorOnKeptInSync.moveToNext()) -// } else { -// Timber.d("No available offline files found") -// } -// -// } catch (e: Exception) { -// Timber.e(e, "Exception retrieving all the available offline files") -// -// } finally { -// cursorOnKeptInSync?.close() -// } -// -// return result - } - fun sharedByLinkFilesFromCurrentAccount(): List? = runBlocking(CoroutinesDispatcherProvider().io) { val getFilesSharedByLinkUseCase: GetFilesSharedByLinkUseCase by inject() @@ -506,37 +454,6 @@ class FileDataStorageManager : KoinComponent { result ?: listOf() } - /** - * Checks if it is favorite or it is inside a favorite folder - * - * @param file [OCFile] which ancestors will be searched. - * @return true/false - */ - // FIXME: 13/10/2020 : New_arch: Av.Offline - private fun isAnyAncestorAvailableOfflineFolder(file: OCFile) = false //getAvailableOfflineAncestorOf(file) != null - - /** - * Returns ancestor folder with available offline status AVAILABLE_OFFLINE. - * - * @param file [OCFile] which ancestors will be searched. - * @return Ancestor folder with available offline status AVAILABLE_OFFLINE, or null if - * does not exist. - */ - // FIXME: 13/10/2020 : New_arch: Av.Offline - private fun getAvailableOfflineAncestorOf(file: OCFile): OCFile? { - return null -// var avOffAncestor: OCFile? = null -// val parent = getFileById(file.parentId) -// if (parent != null && parent.isFolder) { // file is null for the parent of the root folder -// if (parent.availableOfflineStatus == AVAILABLE_OFFLINE) { -// avOffAncestor = parent -// } else if (parent.fileName != ROOT_PATH) { -// avOffAncestor = getAvailableOfflineAncestorOf(parent) -// } -// } -// return avOffAncestor - } - // FIXME: 13/10/2020 : New_arch: Migration private fun createFileInstance(c: Cursor?): OCFile? = null//c?.let { // OCFile(it.getStringFromColumnOrThrow(FILE_PATH)).apply { @@ -840,13 +757,6 @@ class FileDataStorageManager : KoinComponent { ) } - // FIXME: 13/10/2020 : New_arch: Av.Offline - private fun selectionForAllDescendantsOf(file: OCFile): Pair> { - val selection = "$FILE_ACCOUNT_OWNER=? AND $FILE_PATH LIKE ? " - val selectionArgs = arrayOf(account.name, "${file.remotePath}_%") // one or more characters after remote path - return Pair(selection, selectionArgs) - } - private fun performQuery( uri: Uri, projection: Array?, diff --git a/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineHandler.java b/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineHandler.java deleted file mode 100644 index 331877eb874..00000000000 --- a/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineHandler.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * ownCloud Android client application - * - * @author David González Verdugo - * Copyright (C) 2020 ownCloud GmbH. - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.files.services; - -import android.app.job.JobInfo; -import android.app.job.JobScheduler; -import android.content.ComponentName; -import android.content.Context; -import android.os.PersistableBundle; - -import com.owncloud.android.utils.Extras; -import timber.log.Timber; - -/** - * Schedule the periodic job responsible for synchronizing available offline files, a.k.a. kept-in-sync files, that - * have been updated locally, with the remote server - */ -public class AvailableOfflineHandler { - - private static final long MILLISECONDS_INTERVAL_AVAILABLE_OFFLINE = 900000; - - // It needs to be always the same so that the previous job is removed and replaced with a new one with the recent - // configuration - private static final int JOB_ID_AVAILABLE_OFFLINE = 2; - - private JobScheduler mJobScheduler; - - public AvailableOfflineHandler(Context context) { - mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); - } - - /** - * Schedule a periodic job to check whether recently updated available offline files need to be synchronized - */ - public void scheduleAvailableOfflineJob(Context context) { - ComponentName serviceComponent = new ComponentName(context, AvailableOfflineSyncJobService.class); - JobInfo.Builder builder; - - builder = new JobInfo.Builder(JOB_ID_AVAILABLE_OFFLINE, serviceComponent); - - builder.setPersisted(true); - - // Execute job every 15 minutes - builder.setPeriodic(MILLISECONDS_INTERVAL_AVAILABLE_OFFLINE); - - // Extra data - PersistableBundle extras = new PersistableBundle(); - - extras.putInt(Extras.EXTRA_AVAILABLE_OFFLINE_SYNC_JOB_ID, JOB_ID_AVAILABLE_OFFLINE); - - builder.setExtras(extras); - - Timber.d("Scheduling an AvailableOfflineSyncJobService"); - - mJobScheduler.schedule(builder.build()); - } -} diff --git a/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineSyncJobService.java b/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineSyncJobService.java deleted file mode 100644 index ca349aa5ffb..00000000000 --- a/owncloudApp/src/main/java/com/owncloud/android/files/services/AvailableOfflineSyncJobService.java +++ /dev/null @@ -1,186 +0,0 @@ -/** - * ownCloud Android client application - * - * @author David González Verdugo - * Copyright (C) 2020 ownCloud GmbH. - *

- * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2, - * as published by the Free Software Foundation. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.owncloud.android.files.services; - -import android.app.job.JobParameters; -import android.app.job.JobScheduler; -import android.app.job.JobService; -import android.content.Context; -import android.os.AsyncTask; - -import androidx.core.util.Pair; -import com.owncloud.android.domain.files.model.OCFile; -import timber.log.Timber; - -import java.util.List; - -/** - * Job to watch for local changes in available offline files (formerly known as kept-in-sync files) and try to - * synchronize them with the OC server. - * This job should be executed every 15 minutes since a file is set as available offline for the first time and stopped - * when there's no available offline files - */ -public class AvailableOfflineSyncJobService extends JobService { - - @Override - public boolean onStartJob(JobParameters jobParameters) { - Timber.d("Starting job to sync available offline files"); - - new AvailableOfflineJobTask(this).execute(jobParameters); - - return true; // True because we have a thread still running in background - } - - private static class AvailableOfflineJobTask extends AsyncTask { - - private final JobService mAvailableOfflineJobService; - - public AvailableOfflineJobTask(JobService mAvailableOfflineJobService) { - this.mAvailableOfflineJobService = mAvailableOfflineJobService; - } - - @Override - protected JobParameters doInBackground(JobParameters... jobParams) { -// FIXME: 13/10/2020 : New_arch: Av.Offline -// Account account; -// -// if (mAvailableOfflineJobService != null) { -// account = AccountUtils.getCurrentOwnCloudAccount(mAvailableOfflineJobService.getApplicationContext()); -// } else { -// Timber.w("AvailableOfflineJobService is null"); -// return jobParams[0]; -// } -// -// if (account == null) { -// Timber.w("Account is null, do not sync av. offline files."); -// return jobParams[0]; -// } -// -// if (mAvailableOfflineJobService.getContentResolver() == null) { -// Timber.w("Content resolver is null, do not sync av. offline files."); -// return jobParams[0]; -// } -// -// FileDataStorageManager fileDataStorageManager = new FileDataStorageManager( -// mAvailableOfflineJobService, account, mAvailableOfflineJobService.getContentResolver() -// ); -// -// List> availableOfflineFilesFromEveryAccount = fileDataStorageManager. -// getAvailableOfflineFilesFromEveryAccount(); -// -// // Cancel periodic job if there's no available offline files to watch for local changes -// if (availableOfflineFilesFromEveryAccount.isEmpty()) { -// Timber.w("No available files for any account."); -// cancelPeriodicJob(jobParams[0].getJobId()); -// return jobParams[0]; -// } else { -// syncAvailableOfflineFiles(availableOfflineFilesFromEveryAccount); -// } - - return jobParams[0]; - } - - private void syncAvailableOfflineFiles(List> availableOfflineFilesForAccount) { - // FIXME: 13/10/2020 : New_arch: Av.Offline -// for (Pair fileForAccount : availableOfflineFilesForAccount) { -// -// String localPath = fileForAccount.first.getStoragePath(); -// -// if (localPath == null) { -// localPath = FileStorageUtils.getDefaultSavePathFor( -// fileForAccount.second, // Account name -// fileForAccount.first // OCFile -// ); -// } -// -// File localFile = new File(localPath); -// -// if (localFile.lastModified() <= fileForAccount.first.getLastSyncDateForData() && -// MainApp.Companion.getEnabledLogging()) { -// Timber.i("File " + fileForAccount.first.getRemotePath() + " already synchronized " + -// "in account " + fileForAccount.second + ", ignoring"); -// continue; -// } -// -// startSyncOperation(fileForAccount.first, fileForAccount.second); -// } - } - - /** - * Triggers an operation to synchronize the contents of a recently modified available offline file with - * its remote counterpart in the associated ownCloud account. - * - * @param availableOfflineFile file to synchronize - * @param accountName account to synchronize the available offline file with - */ - private void startSyncOperation(OCFile availableOfflineFile, String accountName) { - // FIXME: 13/10/2020 : New_arch: Av.Offline - Timber.i("Requested synchronization for file %1s in account %2s", - availableOfflineFile.getRemotePath(), accountName); -// -// Account account = AccountUtils.getOwnCloudAccountByName(mAvailableOfflineJobService, accountName); -// if (account == null) { -// Timber.w("Account '" + accountName + "' not found in account manager. Aborting Sync operation..."); -// return; -// } -// -// FileDataStorageManager storageManager = -// new FileDataStorageManager(mAvailableOfflineJobService, account, mAvailableOfflineJobService.getContentResolver()); -// -// SynchronizeFileOperation synchronizeFileOperation = -// new SynchronizeFileOperation(availableOfflineFile, null, account, false, -// mAvailableOfflineJobService, true); -// -// RemoteOperationResult result = synchronizeFileOperation.execute(storageManager, mAvailableOfflineJobService); -// -// if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) { -// notifyConflict(availableOfflineFile, account, mAvailableOfflineJobService); -// } - } - - /** - * Cancel the periodic job - * - * @param jobId id of the job to cancel - */ - private void cancelPeriodicJob(int jobId) { - JobScheduler jobScheduler = (JobScheduler) mAvailableOfflineJobService.getSystemService( - Context.JOB_SCHEDULER_SERVICE); - - jobScheduler.cancel(jobId); - - Timber.d("No available offline files to check, cancelling the periodic job"); - } - - @Override - protected void onPostExecute(JobParameters jobParameters) { - mAvailableOfflineJobService.jobFinished(jobParameters, false); - } - } - - @Override - /* - * Called by the system if the job is cancelled before being finished - */ - public boolean onStopJob(JobParameters jobParameters) { - Timber.d("Job was cancelled before finishing."); - return true; - } -} diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/SetFilesAsAvailableOfflineUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/SetFilesAsAvailableOfflineUseCase.kt index c4cc2dfd08e..dacd8b1d2ae 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/SetFilesAsAvailableOfflineUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/SetFilesAsAvailableOfflineUseCase.kt @@ -29,6 +29,7 @@ class SetFilesAsAvailableOfflineUseCase( override fun run(params: Params) { params.filesToSetAsAvailableOffline.forEach { fileToSetAsAvailableOffline -> // Its possible to multiselect several files including already available offline files. + // If it is already available offline, we will ignore it. if (!fileToSetAsAvailableOffline.isAvailableOffline) { availableOfflineRepository.setFileAsAvailableOffline(fileToSetAsAvailableOffline) } diff --git a/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/UnsetFilesAsAvailableOfflineUseCase.kt b/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/UnsetFilesAsAvailableOfflineUseCase.kt index 91cb0774dfc..4d425580574 100644 --- a/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/UnsetFilesAsAvailableOfflineUseCase.kt +++ b/owncloudDomain/src/main/java/com/owncloud/android/domain/availableoffline/usecases/UnsetFilesAsAvailableOfflineUseCase.kt @@ -29,6 +29,7 @@ class UnsetFilesAsAvailableOfflineUseCase( override fun run(params: Params) { params.filesToUnsetAsAvailableOffline.forEach { fileToUnsetAsAvailableOffline -> // Its possible to multiselect several files including not available offline files. + // If it is not available offline, we will ignore it. if (fileToUnsetAsAvailableOffline.isAvailableOffline) { availableOfflineRepository.unsetFileAsAvailableOffline(fileToUnsetAsAvailableOffline) }