mirror of https://github.com/nextcloud/android
Fix di, add tag
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
fd20c1117e
commit
eb2dc25700
|
@ -41,6 +41,8 @@ import com.nextcloud.client.core.ClockImpl;
|
|||
import com.nextcloud.client.core.ThreadPoolAsyncRunner;
|
||||
import com.nextcloud.client.database.dao.ArbitraryDataDao;
|
||||
import com.nextcloud.client.device.DeviceInfo;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.files.downloader.FileTransferHelper;
|
||||
import com.nextcloud.client.logger.FileLogHandler;
|
||||
import com.nextcloud.client.logger.Logger;
|
||||
import com.nextcloud.client.logger.LoggerImpl;
|
||||
|
@ -50,6 +52,7 @@ import com.nextcloud.client.migrations.MigrationsDb;
|
|||
import com.nextcloud.client.migrations.MigrationsManager;
|
||||
import com.nextcloud.client.migrations.MigrationsManagerImpl;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.notifications.AppNotificationManager;
|
||||
import com.nextcloud.client.notifications.AppNotificationManagerImpl;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
|
@ -246,6 +249,12 @@ class AppModule {
|
|||
viewThemeUtilsProvider.get());
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
FileTransferHelper fileTransferHelper(ClientFactory clientFactory, FileDataStorageManager fileDataStorageManager, AsyncRunner runner, PowerManagementService powerManagementService, ConnectivityService connectivityService, UploadsStorageManager uploadsStorageManager) {
|
||||
return new FileTransferHelper(clientFactory, fileDataStorageManager, runner, powerManagementService, connectivityService, uploadsStorageManager);
|
||||
}
|
||||
|
||||
@Provides
|
||||
LocalBroadcastManager localBroadcastManager(Context context) {
|
||||
return LocalBroadcastManager.getInstance(context);
|
||||
|
|
|
@ -495,7 +495,4 @@ abstract class ComponentsModule {
|
|||
|
||||
@ContributesAndroidInjector
|
||||
abstract TestJob testJob();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract FileTransferHelper fileTransferHelper();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ class FileTransferHelper @Inject constructor(
|
|||
private val connectivityService: ConnectivityService,
|
||||
private val uploadsStorageManager: UploadsStorageManager
|
||||
) {
|
||||
|
||||
private val downloader: MutableMap<String, TransferManagerImpl> = mutableMapOf()
|
||||
|
||||
fun getTransferManager(context: Context, user: User): FileTransferWorker.Manager {
|
||||
|
|
|
@ -24,37 +24,18 @@ import android.content.Context
|
|||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.google.gson.Gson
|
||||
import com.nextcloud.client.core.AsyncRunner
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.logger.Logger
|
||||
import com.nextcloud.client.network.ClientFactory
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.nextcloud.client.notifications.AppNotificationManager
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
class FileTransferWorker(
|
||||
private val notificationsManager: AppNotificationManager,
|
||||
clientFactory: ClientFactory,
|
||||
runner: AsyncRunner,
|
||||
private val logger: Logger,
|
||||
uploadsStorageManager: UploadsStorageManager,
|
||||
connectivityService: ConnectivityService,
|
||||
powerManagementService: PowerManagementService,
|
||||
fileDataStorageManager: FileDataStorageManager,
|
||||
private val helper: FileTransferHelper,
|
||||
private val context: Context,
|
||||
params: WorkerParameters
|
||||
) : Worker(context, params) {
|
||||
|
||||
private val helper = FileTransferHelper(
|
||||
clientFactory,
|
||||
fileDataStorageManager,
|
||||
runner,
|
||||
powerManagementService,
|
||||
connectivityService,
|
||||
uploadsStorageManager
|
||||
)
|
||||
private val gson = Gson()
|
||||
|
||||
companion object {
|
||||
|
@ -74,8 +55,7 @@ class FileTransferWorker(
|
|||
val transferManager = helper.getTransferManager(downloader, context, request.user, this::onTransferUpdate)
|
||||
transferManager.enqueue(request)
|
||||
|
||||
logger.d(TAG, "Enqueued new transfer: ${request.uuid} ${request.file.remotePath}")
|
||||
|
||||
logger.d(TAG, "FileTransferWorker successfully completed: ${request.uuid} ${request.file.remotePath}")
|
||||
Result.success()
|
||||
} catch (t: Throwable) {
|
||||
logger.d(TAG, "Error caught at FileTransferWorker: ${t.localizedMessage}")
|
||||
|
@ -83,6 +63,11 @@ class FileTransferWorker(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onStopped() {
|
||||
logger.d(TAG, "FileTransferWorker stopped")
|
||||
super.onStopped()
|
||||
}
|
||||
|
||||
class Manager(downloader: TransferManagerImpl) : TransferManager by downloader
|
||||
|
||||
val isRunning: Boolean get() = downloader.any { it.value.isRunning }
|
||||
|
|
|
@ -29,21 +29,18 @@ import androidx.work.ListenableWorker
|
|||
import androidx.work.WorkerFactory
|
||||
import androidx.work.WorkerParameters
|
||||
import com.nextcloud.client.account.UserAccountManager
|
||||
import com.nextcloud.client.core.AsyncRunner
|
||||
import com.nextcloud.client.core.Clock
|
||||
import com.nextcloud.client.device.DeviceInfo
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.documentscan.GeneratePDFUseCase
|
||||
import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
|
||||
import com.nextcloud.client.files.downloader.FileTransferHelper
|
||||
import com.nextcloud.client.files.downloader.FileTransferWorker
|
||||
import com.nextcloud.client.integrations.deck.DeckApi
|
||||
import com.nextcloud.client.logger.Logger
|
||||
import com.nextcloud.client.network.ClientFactory
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
import com.nextcloud.client.notifications.AppNotificationManager
|
||||
import com.nextcloud.client.preferences.AppPreferences
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager
|
||||
import com.owncloud.android.datamodel.SyncedFolderProvider
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
|
@ -59,16 +56,13 @@ import javax.inject.Provider
|
|||
@Suppress("LongParameterList", "TooManyFunctions") // satisfied by DI
|
||||
class BackgroundJobFactory @Inject constructor(
|
||||
private val appNotificationManager: AppNotificationManager,
|
||||
private val clientFactory: ClientFactory,
|
||||
private val fileDataStorageManager: FileDataStorageManager,
|
||||
private val runner: AsyncRunner,
|
||||
private val transferHelper: FileTransferHelper,
|
||||
private val logger: Logger,
|
||||
private val preferences: AppPreferences,
|
||||
private val contentResolver: ContentResolver,
|
||||
private val clock: Clock,
|
||||
private val powerManagementService: PowerManagementService,
|
||||
private val backgroundJobManager: Provider<BackgroundJobManager>,
|
||||
private val deviceInfo: DeviceInfo,
|
||||
private val accountManager: UserAccountManager,
|
||||
private val resources: Resources,
|
||||
private val arbitraryDataProvider: ArbitraryDataProvider,
|
||||
|
@ -254,13 +248,8 @@ class BackgroundJobFactory @Inject constructor(
|
|||
private fun createFileTransferWorker(context: Context, params: WorkerParameters): FileTransferWorker {
|
||||
return FileTransferWorker(
|
||||
appNotificationManager,
|
||||
clientFactory,
|
||||
runner,
|
||||
logger,
|
||||
uploadsStorageManager,
|
||||
connectivityService,
|
||||
powerManagementService,
|
||||
fileDataStorageManager,
|
||||
transferHelper,
|
||||
context,
|
||||
params
|
||||
)
|
||||
|
|
|
@ -525,11 +525,14 @@ internal class BackgroundJobManagerImpl(
|
|||
FileTransferWorker.EXTRA_REQUEST to gson.toJson(request)
|
||||
)
|
||||
|
||||
val tag = JOB_FILES_TRANSFER + request.uuid
|
||||
|
||||
val requestData = oneTimeRequestBuilder(FileTransferWorker::class, JOB_FILES_TRANSFER)
|
||||
.addTag(tag)
|
||||
.setInputData(data)
|
||||
.build()
|
||||
|
||||
workManager.enqueueUniqueWork(JOB_FILES_TRANSFER + request.uuid, ExistingWorkPolicy.REPLACE, requestData)
|
||||
workManager.enqueueUniqueWork(tag, ExistingWorkPolicy.REPLACE, requestData)
|
||||
}
|
||||
|
||||
override fun startPdfGenerateAndUploadWork(
|
||||
|
|
Loading…
Reference in New Issue