From 172e9a76d9c93e83270e56e209bfeb264f21ac24 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 29 Dec 2023 14:15:43 +0100 Subject: [PATCH] Fix code analytics Signed-off-by: alperozturk --- .../files/downloader/FileDownloadHelper.kt | 124 ++++-------------- .../files/downloader/FileDownloadWorker.kt | 5 +- .../nextcloud/client/jobs/FilesExportWork.kt | 4 +- .../android/files/FileMenuFilter.java | 7 +- .../operations/SynchronizeFileOperation.java | 13 +- .../SynchronizeFolderOperation.java | 4 +- .../ui/activity/ConflictsResolveActivity.kt | 4 +- .../android/ui/activity/FileActivity.java | 3 +- .../ui/activity/FileDisplayActivity.java | 9 +- .../ui/activity/ManageAccountsActivity.java | 5 +- .../android/ui/adapter/OCFileListDelegate.kt | 26 ++-- .../ui/fragment/FileDetailFragment.java | 6 +- .../ui/helpers/FileOperationsHelper.java | 7 +- .../ui/preview/PreviewImageActivity.java | 6 +- .../ui/preview/PreviewMediaActivity.kt | 7 +- .../ui/preview/PreviewMediaFragment.java | 5 +- 16 files changed, 71 insertions(+), 164 deletions(-) diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt index e4d7ce201ebe..189b6263dba0 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt @@ -27,14 +27,13 @@ import com.owncloud.android.MainApp import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.UploadsStorageManager -import com.owncloud.android.lib.common.network.OnDatatransferProgressListener import com.owncloud.android.operations.DownloadFileOperation import com.owncloud.android.operations.DownloadType import com.owncloud.android.utils.MimeTypeUtil import java.io.File import javax.inject.Inject -class FileDownloadHelper : OnDatatransferProgressListener { +class FileDownloadHelper { @Inject lateinit var backgroundJobManager: BackgroundJobManager @@ -42,49 +41,20 @@ class FileDownloadHelper : OnDatatransferProgressListener { @Inject lateinit var uploadsStorageManager: UploadsStorageManager - private val boundListeners: MutableMap = HashMap() - private var currentDownload: DownloadFileOperation? = null + companion object { + private var instance: FileDownloadHelper? = null - init { - MainApp.getAppComponent().inject(this) - } - - fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) { - if (file == null || listener == null) { - return - } - - boundListeners[file.fileId] = listener - } - - fun removeDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) { - if (file == null || listener == null) { - return - } - - val fileId = file.fileId - if (boundListeners[fileId] === listener) { - boundListeners.remove(fileId) + fun instance(): FileDownloadHelper { + return if (instance == null) { + FileDownloadHelper() + } else { + instance!! + } } } - override fun onTransferProgress( - progressRate: Long, - totalTransferredSoFar: Long, - totalToTransfer: Long, - fileName: String - ) { - val listener = boundListeners[currentDownload?.file?.fileId] - listener?.onTransferProgress( - progressRate, - totalTransferredSoFar, - totalToTransfer, - fileName - ) - } - - fun setCurrentDownload(operation: DownloadFileOperation) { - currentDownload = operation + init { + MainApp.getAppComponent().inject(this) } fun isDownloading(user: User?, file: OCFile?): Boolean { @@ -145,75 +115,25 @@ class FileDownloadHelper : OnDatatransferProgressListener { storageManager?.saveConflict(file, null) } - fun downloadFile(user: User, ocFile: OCFile) { - backgroundJobManager.startFileDownloadJob( - user, - ocFile, - "", - DownloadType.DOWNLOAD, - "", - "", - null - ) - } - - fun downloadFile(user: User, ocFile: OCFile, behaviour: String) { - backgroundJobManager.startFileDownloadJob( - user, - ocFile, - behaviour, - DownloadType.DOWNLOAD, - "", - "", - null - ) - } - - fun downloadFile(user: User, ocFile: OCFile, behaviour: String, packageName: String, activityName: String) { - backgroundJobManager.startFileDownloadJob( - user, - ocFile, - behaviour, - DownloadType.DOWNLOAD, - packageName, - packageName, - null - ) - } - - fun downloadFile(user: User, ocFile: OCFile, downloadType: DownloadType) { - backgroundJobManager.startFileDownloadJob( - user, - ocFile, - "", - downloadType, - "", - "", - null - ) + fun downloadFileIfNotStartedBefore(user: User, file: OCFile) { + if (!isDownloading(user, file)) { + downloadFile(user, file, downloadType = DownloadType.DOWNLOAD) + } } - fun downloadFile(user: User, ocFile: OCFile, conflictUploadId: Long) { - backgroundJobManager.startFileDownloadJob( - user, - ocFile, - "", - DownloadType.DOWNLOAD, - "", - "", - conflictUploadId - ) + fun downloadFile(user: User, ocFile: OCFile) { + downloadFile(user, ocFile, downloadType = DownloadType.DOWNLOAD) } @Suppress("LongParameterList") fun downloadFile( user: User, ocFile: OCFile, - behaviour: String, - downloadType: DownloadType?, - activityName: String, - packageName: String, - conflictUploadId: Long? + behaviour: String = "", + downloadType: DownloadType? = DownloadType.DOWNLOAD, + activityName: String = "", + packageName: String = "", + conflictUploadId: Long? = null ) { backgroundJobManager.startFileDownloadJob( user, diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index c432f253e052..0dde3df25d41 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -97,7 +97,6 @@ class FileDownloadWorker( private val pendingDownloads = IndexedForest() private var downloadProgressListener = FileDownloadProgressListener() private var currentUser = Optional.empty() - private val helper = FileDownloadHelper() private var startedDownload = false private var storageManager: FileDataStorageManager? = null private var downloadClient: OwnCloudClient? = null @@ -230,7 +229,7 @@ class FileDownloadWorker( downloadResult = currentDownload?.execute(downloadClient) if (downloadResult?.isSuccess == true && currentDownload?.downloadType === DownloadType.DOWNLOAD) { getCurrentFile()?.let { - helper.saveFile(it, currentDownload, storageManager) + FileDownloadHelper.instance().saveFile(it, currentDownload, storageManager) } } } catch (e: Exception) { @@ -366,7 +365,7 @@ class FileDownloadWorker( private val boundListeners: MutableMap = HashMap() fun isDownloading(user: User?, file: OCFile?): Boolean { - return helper.isDownloading(user, file) + return FileDownloadHelper.instance().isDownloading(user, file) } fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) { diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt index c5f82cc89df2..05586ba96569 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt @@ -111,10 +111,10 @@ class FilesExportWork( } private fun downloadFile(ocFile: OCFile) { - FileDownloadHelper().downloadFile( + FileDownloadHelper.instance().downloadFile( user, ocFile, - DownloadType.EXPORT + downloadType = DownloadType.EXPORT ) } diff --git a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 6639a201c320..e209d21bc301 100644 --- a/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/app/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -380,9 +380,8 @@ private boolean anyFileSynchronizing() { if (componentsGetter != null && !files.isEmpty() && user != null) { OperationsServiceBinder opsBinder = componentsGetter.getOperationsServiceBinder(); FileUploaderBinder uploaderBinder = componentsGetter.getFileUploaderBinder(); - FileDownloadHelper fileDownloadHelper = new FileDownloadHelper(); synchronizing = anyFileSynchronizing(opsBinder) || // comparing local and remote - anyFileDownloading(fileDownloadHelper) || + anyFileDownloading() || anyFileUploading(uploaderBinder); } return synchronizing; @@ -398,9 +397,9 @@ private boolean anyFileSynchronizing(OperationsServiceBinder opsBinder) { return synchronizing; } - private boolean anyFileDownloading(FileDownloadHelper downloadHelper) { + private boolean anyFileDownloading() { for (OCFile file : files) { - if (downloadHelper.isDownloading(user, file)) { + if (FileDownloadHelper.Companion.instance().isDownloading(user, file)) { return true; } } diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java index 48b7aa9b701f..e993df4f66f4 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java @@ -309,30 +309,19 @@ private void requestForUpload(OCFile file) { mTransferWasRequested = true; } - - /** - * Requests for a download to the FileDownloader service - * - * @param file OCFile object representing the file to download - */ private void requestForDownload(OCFile file) { - FileDownloadHelper downloadHelper = new FileDownloadHelper(); - - downloadHelper.downloadFile( + FileDownloadHelper.Companion.instance().downloadFile( mUser, file); mTransferWasRequested = true; } - public boolean transferWasRequested() { return mTransferWasRequested; } - public OCFile getLocalFile() { return mLocalFile; } - } diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index 0cb9cff609e8..d6228d3d67bd 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -445,14 +445,12 @@ private void syncContents() throws OperationCancelledException { } private void startDirectDownloads() throws OperationCancelledException { - FileDownloadHelper downloadHelper = new FileDownloadHelper(); - for (OCFile file : mFilesForDirectDownload) { synchronized(mCancellationRequested) { if (mCancellationRequested.get()) { throw new OperationCancelledException(); } - downloadHelper.downloadFile(user, file); + FileDownloadHelper.Companion.instance().downloadFile(user, file); } } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt index 0a1f8d3bffbe..b85f3925c5e1 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt @@ -115,10 +115,10 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener Decision.KEEP_SERVER -> if (!shouldDeleteLocal()) { // Overwrite local file file?.let { - FileDownloadHelper().downloadFile( + FileDownloadHelper.instance().downloadFile( getUser().orElseThrow { RuntimeException() }, file, - conflictUploadId + conflictUploadId = conflictUploadId ) } } else { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java index fb0c623fabdc..fca1cbd96bc1 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java @@ -166,7 +166,6 @@ public abstract class FileActivity extends DrawerActivity private boolean mResumed; - protected FileDownloadHelper fileDownloadHelper = new FileDownloadHelper(); protected FileDownloadWorker.FileDownloadProgressListener fileDownloadProgressListener; protected FileUploaderBinder mUploaderBinder; private ServiceConnection mUploadServiceConnection; @@ -235,7 +234,7 @@ protected void onCreate(Bundle savedInstanceState) { Context.BIND_AUTO_CREATE); if (user != null) { - new FileDownloadHelper().downloadFile(user, mFile); + FileDownloadHelper.Companion.instance().downloadFile(user, mFile); } mUploadServiceConnection = newTransferenceServiceConnection(); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index a0e94413e315..543d2a982dbe 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -65,6 +65,7 @@ import com.nextcloud.client.di.Injectable; import com.nextcloud.client.editimage.EditImageActivity; import com.nextcloud.client.files.DeepLinkHandler; +import com.nextcloud.client.files.downloader.FileDownloadHelper; import com.nextcloud.client.files.downloader.FileDownloadWorker; import com.nextcloud.client.media.PlayerServiceConnection; import com.nextcloud.client.network.ClientFactory; @@ -1896,9 +1897,7 @@ public void onTransferStateChanged(OCFile file, boolean downloading, boolean upl private void requestForDownload() { User user = getUser().orElseThrow(RuntimeException::new); - if (!fileDownloadHelper.isDownloading(user, mWaitingToPreview)) { - fileDownloadHelper.downloadFile(user, mWaitingToPreview); - } + FileDownloadHelper.Companion.instance().downloadFileIfNotStartedBefore(user, mWaitingToPreview); } @Override @@ -1968,8 +1967,8 @@ public void run() { private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) { final User currentUser = getUser().orElseThrow(RuntimeException::new); - if (!fileDownloadHelper.isDownloading(currentUser, file)) { - fileDownloadHelper.downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null); + if (!FileDownloadHelper.Companion.instance().isDownloading(currentUser, file)) { + FileDownloadHelper.Companion.instance().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null); } } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java index a26c4f95c13e..29f102988a2a 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java @@ -41,6 +41,7 @@ import com.google.common.collect.Sets; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.client.files.downloader.FileDownloadHelper; import com.nextcloud.client.jobs.BackgroundJobManager; import com.nextcloud.client.onboarding.FirstRunActivity; import com.nextcloud.java.util.Optional; @@ -341,7 +342,7 @@ public void run(AccountManagerFuture future) { mUploaderBinder.cancel(accountName); } - fileDownloadHelper.cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload); + FileDownloadHelper.Companion.instance().cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload); } User currentUser = getUserAccountManager().getUser(); @@ -431,7 +432,7 @@ private void performAccountRemoval(User user) { mUploaderBinder.cancel(user); } - fileDownloadHelper.cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload); + FileDownloadHelper.Companion.instance().cancelAllDownloadsForAccount(workerAccountName, workerCurrentDownload); backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false); diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt index 5cd63ffe60c8..9b430135b56f 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt +++ b/app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt @@ -341,27 +341,31 @@ class OCFileListDelegate( private fun showLocalFileIndicator(file: OCFile, gridViewHolder: ListGridImageViewHolder) { val operationsServiceBinder = transferServiceGetter.operationsServiceBinder - val fileDownloadHelper = FileDownloadHelper() val fileUploaderBinder = transferServiceGetter.fileUploaderBinder - when { + + val icon: Int? = when { operationsServiceBinder?.isSynchronizing(user, file) == true || - fileDownloadHelper.isDownloading(user, file) || + FileDownloadHelper.instance().isDownloading(user, file) || fileUploaderBinder?.isUploading(user, file) == true -> { // synchronizing, downloading or uploading - gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing) - gridViewHolder.localFileIndicator.visibility = View.VISIBLE + R.drawable.ic_synchronizing } file.etagInConflict != null -> { - // conflict - gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synchronizing_error) - gridViewHolder.localFileIndicator.visibility = View.VISIBLE + R.drawable.ic_synchronizing_error } file.isDown -> { - // downloaded - gridViewHolder.localFileIndicator.setImageResource(R.drawable.ic_synced) - gridViewHolder.localFileIndicator.visibility = View.VISIBLE + R.drawable.ic_synced } + else -> { null } } + + gridViewHolder.localFileIndicator.run { + icon?.let { + setImageResource(icon) + visibility = View.VISIBLE + } + } + } private fun showShareIcon(gridViewHolder: ListGridImageViewHolder, file: OCFile) { diff --git a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java index 1801404df9f4..cecc01838c49 100644 --- a/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -534,10 +534,9 @@ public void updateFileDetails(boolean transferring, boolean refresh) { setFavoriteIconStatus(file.isFavorite()); // configure UI for depending upon local state of the file - FileDownloadHelper fileDownloadHelper = new FileDownloadHelper(); FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder(); if (transferring - || (fileDownloadHelper.isDownloading(user, file)) + || (FileDownloadHelper.Companion.instance().isDownloading(user, file)) || (uploaderBinder != null && uploaderBinder.isUploading(user, file))) { setButtonsForTransferring(); @@ -659,9 +658,8 @@ private void setButtonsForTransferring() { // show the progress bar for the transfer binding.progressBlock.setVisibility(View.VISIBLE); binding.progressText.setVisibility(View.VISIBLE); - FileDownloadHelper fileDownloadHelper = new FileDownloadHelper(); FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder(); - if (fileDownloadHelper.isDownloading(user, getFile())) { + if (FileDownloadHelper.Companion.instance().isDownloading(user, getFile())) { binding.progressText.setText(R.string.downloader_download_in_progress_ticker); } else { if (uploaderBinder != null && uploaderBinder.isUploading(user, getFile())) { diff --git a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index a072ddd7cd23..69ee619382b2 100755 --- a/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -996,11 +996,10 @@ public void cancelTransference(OCFile file) { } } - // for both files and folders - FileDownloadHelper fileDownloadHelper = new FileDownloadHelper(); - if (fileDownloadHelper.isDownloading(currentUser, file)) { - fileDownloadHelper.cancelPendingOrCurrentDownloads(currentUser, file); + if (FileDownloadHelper.Companion.instance().isDownloading(currentUser, file)) { + FileDownloadHelper.Companion.instance().cancelPendingOrCurrentDownloads(currentUser, file); } + FileUploaderBinder uploaderBinder = fileActivity.getFileUploaderBinder(); if (uploaderBinder != null && uploaderBinder.isUploading(currentUser, file)) { uploaderBinder.cancel(currentUser.toPlatformAccount(), file); diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java b/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java index 34a26831e63e..8915ed9c1b46 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -37,6 +37,7 @@ import com.nextcloud.client.account.User; import com.nextcloud.client.di.Injectable; import com.nextcloud.client.editimage.EditImageActivity; +import com.nextcloud.client.files.downloader.FileDownloadHelper; import com.nextcloud.client.files.downloader.FileDownloadWorker; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.java.util.Optional; @@ -54,6 +55,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.operations.DownloadType; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.ui.activity.FileActivity; @@ -419,8 +421,8 @@ public void requestForDownload(OCFile file) { public void requestForDownload(OCFile file, String downloadBehaviour) { final User user = getUser().orElseThrow(RuntimeException::new); - if (!fileDownloadHelper.isDownloading(user, file)) { - fileDownloadHelper.downloadFile(user, file, downloadBehaviour); + if (!FileDownloadHelper.Companion.instance().isDownloading(user, file)) { + FileDownloadHelper.Companion.instance().downloadFile(user, file, downloadBehaviour, DownloadType.DOWNLOAD, "", "", null); } } diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt index 8e6d15c2f9ef..23d7bd00b40f 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt @@ -62,6 +62,7 @@ import androidx.media3.ui.PlayerView import com.nextcloud.client.account.User import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.di.Injectable +import com.nextcloud.client.files.downloader.FileDownloadHelper import com.nextcloud.client.jobs.BackgroundJobManager import com.nextcloud.client.media.ExoplayerListener import com.nextcloud.client.media.NextcloudExoPlayer.createNextcloudExoplayer @@ -82,6 +83,7 @@ import com.owncloud.android.lib.common.operations.OnRemoteOperationListener import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC +import com.owncloud.android.operations.DownloadType import com.owncloud.android.operations.RemoveFileOperation import com.owncloud.android.operations.SynchronizeFileOperation import com.owncloud.android.ui.activity.FileActivity @@ -574,16 +576,17 @@ class PreviewMediaActivity : packageName: String? = null, activityName: String? = null ) { - if (fileDownloadHelper.isDownloading(user, file)) { + if (FileDownloadHelper.instance().isDownloading(user, file)) { return } user?.let { user -> file?.let { file -> - fileDownloadHelper.downloadFile( + FileDownloadHelper.instance().downloadFile( user, file, downloadBehavior ?: "", + DownloadType.DOWNLOAD, packageName ?: "", activityName ?: "" ) diff --git a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 28c3e4d4f314..a1ef3e805734 100644 --- a/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -131,7 +131,6 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene private boolean autoplay; private boolean isLivePhoto; - private final FileDownloadHelper downloadHelper = new FileDownloadHelper(); private boolean prepared; private PlayerServiceConnection mediaPlayerServiceConnection; @@ -479,9 +478,7 @@ public void onFileActionChosen(final int itemId) { getView(), backgroundJobManager); } else if (itemId == R.id.action_download_file) { - if (!downloadHelper.isDownloading(user, getFile())) { - downloadHelper.downloadFile(user, getFile()); - } + FileDownloadHelper.Companion.instance().downloadFileIfNotStartedBefore(user, getFile()); } }