Skip to content

Commit

Permalink
Merge pull request #12308 from nextcloud/refactor/use-work-manager-fi…
Browse files Browse the repository at this point in the history
…le-download

Use Work Manager For File Download
  • Loading branch information
alperozturk96 committed Jan 12, 2024
2 parents 61493ee + 909c730 commit ed88a47
Show file tree
Hide file tree
Showing 68 changed files with 1,592 additions and 1,166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.nextcloud.client.files.downloader
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.rule.ServiceTestRule
import com.nextcloud.client.account.MockUser
import com.nextcloud.client.files.transfer.FileTransferService
import io.mockk.MockKAnnotations
import org.junit.Assert.assertTrue
import org.junit.Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
package com.nextcloud.client.files.downloader

import com.nextcloud.client.account.User
import com.nextcloud.client.files.DownloadRequest
import com.nextcloud.client.files.Registry
import com.nextcloud.client.files.Request
import com.nextcloud.client.files.transfer.Transfer
import com.nextcloud.client.files.transfer.TransferState
import com.owncloud.android.datamodel.OCFile
import io.mockk.CapturingSlot
import io.mockk.MockKAnnotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ package com.nextcloud.client.files.downloader
import android.content.ComponentName
import android.content.Context
import com.nextcloud.client.account.MockUser
import com.nextcloud.client.files.DownloadRequest
import com.nextcloud.client.files.transfer.FileTransferService
import com.nextcloud.client.files.transfer.Transfer
import com.nextcloud.client.files.transfer.TransferManager
import com.nextcloud.client.files.transfer.TransferManagerConnection
import com.nextcloud.client.files.transfer.TransferState
import com.owncloud.android.datamodel.OCFile
import io.mockk.MockKAnnotations
import io.mockk.every
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.nextcloud.client.account.User
import com.nextcloud.client.core.ManualAsyncRunner
import com.nextcloud.client.core.OnProgressCallback
import com.nextcloud.client.files.DownloadRequest
import com.nextcloud.client.files.Request
import com.nextcloud.client.files.transfer.Transfer
import com.nextcloud.client.files.transfer.TransferManagerImpl
import com.nextcloud.client.files.transfer.TransferState
import com.nextcloud.client.files.upload.UploadTask
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.OwnCloudClient
import io.mockk.MockKAnnotations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ package com.owncloud.android.files
import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.nextcloud.client.account.User
import com.nextcloud.client.files.downloader.FileDownloadWorker
import com.nextcloud.test.TestActivity
import com.nextcloud.utils.EditorUtils
import com.owncloud.android.AbstractIT
import com.owncloud.android.R
import com.owncloud.android.datamodel.ArbitraryDataProvider
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.files.services.FileDownloader
import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.lib.resources.files.model.FileLockType
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
Expand Down Expand Up @@ -62,7 +62,7 @@ class FileMenuFilterIT : AbstractIT() {
private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder

@MockK
private lateinit var mockFileDownloaderBinder: FileDownloader.FileDownloaderBinder
private lateinit var mockFileDownloadProgressListener: FileDownloadWorker.FileDownloadProgressListener

@MockK
private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder
Expand All @@ -77,8 +77,8 @@ class FileMenuFilterIT : AbstractIT() {
MockKAnnotations.init(this)
every { mockFileUploaderBinder.isUploading(any(), any()) } returns false
every { mockComponentsGetter.fileUploaderBinder } returns mockFileUploaderBinder
every { mockFileDownloaderBinder.isDownloading(any(), any()) } returns false
every { mockComponentsGetter.fileDownloaderBinder } returns mockFileDownloaderBinder
every { mockFileDownloadProgressListener.isDownloading(any(), any()) } returns false
every { mockComponentsGetter.fileDownloadProgressListener } returns mockFileDownloadProgressListener
every { mockOperationsServiceBinder.isSynchronizing(any(), any()) } returns false
every { mockComponentsGetter.operationsServiceBinder } returns mockOperationsServiceBinder
every { mockStorageManager.getFileById(any()) } returns OCFile("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

import android.content.Intent;
import android.view.View;

import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
Expand Down
4 changes: 2 additions & 2 deletions app/src/debug/java/com/nextcloud/test/TestActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.nextcloud.client.files.downloader.FileDownloadWorker
import com.nextcloud.client.network.Connectivity
import com.nextcloud.client.network.ConnectivityService
import com.nextcloud.utils.EditorUtils
Expand All @@ -33,7 +34,6 @@ import com.owncloud.android.databinding.TestLayoutBinding
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.files.services.FileDownloader
import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.lib.resources.status.OCCapability
import com.owncloud.android.lib.resources.status.OwnCloudVersion
Expand Down Expand Up @@ -130,7 +130,7 @@ class TestActivity :
return null
}

override fun getFileDownloaderBinder(): FileDownloader.FileDownloaderBinder? {
override fun getFileDownloadProgressListener(): FileDownloadWorker.FileDownloadProgressListener? {
return null
}

Expand Down
12 changes: 7 additions & 5 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@
android:exported="false"
android:configChanges="orientation|screenLayout|screenSize|keyboardHidden"
android:theme="@style/Theme.ownCloud.Media" />
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:directBootAware="false"
android:enabled="@bool/enable_system_foreground_service_default"
android:exported="false"
android:foregroundServiceType="dataSync" />
<service
android:name=".authentication.AccountAuthenticatorService"
android:exported="false">
Expand Down Expand Up @@ -394,11 +400,7 @@
android:name=".services.OperationsService"
android:exported="false" />
<service
android:name=".files.services.FileDownloader"
android:foregroundServiceType="dataSync"
android:exported="false" />
<service
android:name="com.nextcloud.client.files.downloader.FileTransferService"
android:name="com.nextcloud.client.files.transfer.FileTransferService"
android:foregroundServiceType="dataSync"
android:exported="false" />
<service
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/nextcloud/client/di/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.nextcloud.client.appinfo.AppInfoModule;
import com.nextcloud.client.database.DatabaseModule;
import com.nextcloud.client.device.DeviceModule;
import com.nextcloud.client.files.downloader.FileDownloadHelper;
import com.nextcloud.client.integrations.IntegrationsModule;
import com.nextcloud.client.jobs.JobsModule;
import com.nextcloud.client.network.NetworkModule;
Expand Down Expand Up @@ -71,6 +72,8 @@ public interface AppComponent {

void inject(FilesUploadHelper filesUploadHelper);

void inject(FileDownloadHelper fileDownloadHelper);

void inject(ProgressIndicator progressIndicator);

@Component.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.nextcloud.client.editimage.EditImageActivity;
import com.nextcloud.client.etm.EtmActivity;
import com.nextcloud.client.etm.pages.EtmBackgroundJobsFragment;
import com.nextcloud.client.files.downloader.FileTransferService;
import com.nextcloud.client.files.transfer.FileTransferService;
import com.nextcloud.client.jobs.BackgroundJobManagerImpl;
import com.nextcloud.client.jobs.NotificationWork;
import com.nextcloud.client.jobs.TestJob;
Expand All @@ -46,7 +46,6 @@
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.authentication.DeepLinkLoginActivity;
import com.owncloud.android.files.BootupBroadcastReceiver;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.providers.DiskLruImageCacheFileProvider;
import com.owncloud.android.providers.DocumentsStorageProvider;
Expand Down Expand Up @@ -324,9 +323,6 @@ abstract class ComponentsModule {
@ContributesAndroidInjector
abstract FileUploader fileUploader();

@ContributesAndroidInjector
abstract FileDownloader fileDownloader();

@ContributesAndroidInjector
abstract BootupBroadcastReceiver bootupBroadcastReceiver();

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/client/etm/EtmViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.nextcloud.client.etm.pages.EtmBackgroundJobsFragment
import com.nextcloud.client.etm.pages.EtmFileTransferFragment
import com.nextcloud.client.etm.pages.EtmMigrations
import com.nextcloud.client.etm.pages.EtmPreferencesFragment
import com.nextcloud.client.files.downloader.TransferManagerConnection
import com.nextcloud.client.files.transfer.TransferManagerConnection
import com.nextcloud.client.jobs.BackgroundJobManager
import com.nextcloud.client.jobs.JobInfo
import com.nextcloud.client.migrations.MigrationInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.nextcloud.client.etm.EtmBaseFragment
import com.nextcloud.client.files.downloader.DownloadRequest
import com.nextcloud.client.files.downloader.Transfer
import com.nextcloud.client.files.downloader.TransferManager
import com.nextcloud.client.files.downloader.UploadRequest
import com.nextcloud.client.files.DownloadRequest
import com.nextcloud.client.files.UploadRequest
import com.nextcloud.client.files.transfer.Transfer
import com.nextcloud.client.files.transfer.TransferManager
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.db.OCUpload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.files.downloader
package com.nextcloud.client.files

enum class Direction {
DOWNLOAD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2020 Chris Narkiewicz <[email protected]>
* @author Alper Ozturk
* Copyright (C) 2023 Alper Ozturk
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -15,10 +16,12 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.files.downloader
package com.nextcloud.client.files

import com.nextcloud.client.files.transfer.Transfer
import com.nextcloud.client.files.transfer.TransferState
import com.owncloud.android.datamodel.OCFile
import java.util.UUID
import kotlin.math.max
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Nextcloud Android client application
*
* @author Chris Narkiewicz
* Copyright (C) 2021 Chris Narkiewicz <[email protected]>
* @author Alper Ozturk
* Copyright (C) 2023 Alper Ozturk
* Copyright (C) 2023 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -15,13 +16,15 @@
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.client.files.downloader
package com.nextcloud.client.files

import android.os.Parcel
import android.os.Parcelable
import com.nextcloud.client.account.User
import com.nextcloud.client.files.upload.PostUploadAction
import com.nextcloud.client.files.upload.UploadTrigger
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
Expand Down
Loading

0 comments on commit ed88a47

Please sign in to comment.