Skip to content

Commit

Permalink
Move packages
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 26, 2023
1 parent eac877b commit 041e836
Show file tree
Hide file tree
Showing 49 changed files with 249 additions and 198 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 Expand Up @@ -101,7 +107,7 @@ class TransferManagerTest {

private fun createMockTask(): DownloadTask {
val task = mockk<DownloadTask>()
every { task.download(any(), any(), any()) } answers {
every { task.download(any()) } answers {
taskProgress.forEach {
arg<OnProgressCallback<Int>>(1).invoke(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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.FilesDownloadWorker
import com.nextcloud.client.files.downloader.FileDownloadWorker
import com.nextcloud.test.TestActivity
import com.nextcloud.utils.EditorUtils
import com.owncloud.android.AbstractIT
Expand Down Expand Up @@ -62,7 +62,7 @@ class FileMenuFilterIT : AbstractIT() {
private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder

@MockK
private lateinit var mockFileDownloaderBinder: FilesDownloadWorker.FileDownloaderBinder
private lateinit var mockFileDownloaderBinder: FileDownloadWorker.FileDownloaderBinder

@MockK
private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder
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,7 +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.FilesDownloadWorker
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 Down Expand Up @@ -130,7 +130,7 @@ class TestActivity :
return null
}

override fun getFileDownloaderBinder(): FilesDownloadWorker.FileDownloaderBinder? {
override fun getFileDownloaderBinder(): FileDownloadWorker.FileDownloaderBinder? {
return null
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
android:name=".services.OperationsService"
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
4 changes: 2 additions & 2 deletions app/src/main/java/com/nextcloud/client/di/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +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.FilesDownloadHelper;
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 @@ -72,7 +72,7 @@ public interface AppComponent {

void inject(FilesUploadHelper filesUploadHelper);

void inject(FilesDownloadHelper filesDownloadHelper);
void inject(FileDownloadHelper fileDownloadHelper);

void inject(ProgressIndicator progressIndicator);

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 Down Expand Up @@ -134,8 +134,6 @@
import com.owncloud.android.ui.trashbin.TrashbinActivity;
import com.owncloud.android.utils.FilesUploadHelper;

import java.io.File;

import dagger.Module;
import dagger.android.ContributesAndroidInjector;

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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package com.nextcloud.client.files.downloader

import android.content.ContentResolver
import android.content.Context
import com.nextcloud.client.core.IsCancelled
import com.nextcloud.client.files.DownloadRequest
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.OwnCloudClient
Expand All @@ -37,9 +37,9 @@ import java.io.File
* This design can be regarded as intermediary refactoring step.
*/
class DownloadTask(
val context: Context,
val contentResolver: ContentResolver,
val clientProvider: () -> OwnCloudClient
private val context: Context,
private val contentResolver: ContentResolver,
private val clientProvider: () -> OwnCloudClient
) {

data class Result(val file: OCFile, val success: Boolean)
Expand All @@ -62,39 +62,46 @@ class DownloadTask(
}
}

fun download(request: DownloadRequest, progress: (Int) -> Unit, isCancelled: IsCancelled): Result {
fun download(request: DownloadRequest): Result {
val op = DownloadFileOperation(request.user, request.file, context)
val client = clientProvider.invoke()
val result = op.execute(client)
if (result.isSuccess) {

return if (result.isSuccess) {
val storageManager = FileDataStorageManager(
request.user,
contentResolver
)
val file = saveDownloadedFile(op, storageManager)
return Result(file, true)
Result(file, true)
} else {
return Result(request.file, false)
Result(request.file, false)
}
}

private fun saveDownloadedFile(op: DownloadFileOperation, storageManager: FileDataStorageManager): OCFile {
val file = storageManager.getFileById(op.getFile().getFileId()) as OCFile
val syncDate = System.currentTimeMillis()
file.lastSyncDateForProperties = syncDate
file.lastSyncDateForData = syncDate
file.isUpdateThumbnailNeeded = true
file.modificationTimestamp = op.getModificationTimestamp()
file.modificationTimestampAtLastSyncForData = op.getModificationTimestamp()
file.etag = op.getEtag()
file.mimeType = op.getMimeType()
file.storagePath = op.getSavePath()
file.fileLength = File(op.getSavePath()).length()
file.remoteId = op.getFile().getRemoteId()
val file = storageManager.getFileById(op.file.fileId) as OCFile

file.apply {
val syncDate = System.currentTimeMillis()
lastSyncDateForProperties = syncDate
lastSyncDateForData = syncDate
isUpdateThumbnailNeeded = true
modificationTimestamp = op.modificationTimestamp
modificationTimestampAtLastSyncForData = op.modificationTimestamp
etag = op.etag
mimeType = op.mimeType
storagePath = op.savePath
fileLength = File(op.savePath).length()
remoteId = op.file.remoteId
}

storageManager.saveFile(file)
if (MimeTypeUtil.isMedia(op.getMimeType())) {

if (MimeTypeUtil.isMedia(op.mimeType)) {
FileDataStorageManager.triggerMediaScan(file.storagePath)
}

return file
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import com.owncloud.android.utils.MimeTypeUtil
import java.io.File
import javax.inject.Inject

class FilesDownloadHelper {
class FileDownloadHelper {

@Inject
lateinit var backgroundJobManager: BackgroundJobManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ import com.owncloud.android.ui.fragment.OCFileListFragment
import com.owncloud.android.ui.preview.PreviewImageActivity
import com.owncloud.android.ui.preview.PreviewImageFragment

class FilesDownloadIntents(private val context: Context) {
class FileDownloadIntents(private val context: Context) {

fun newDownloadIntent(
download: DownloadFileOperation,
linkedToRemotePath: String
): Intent {
return Intent(FilesDownloadWorker.getDownloadAddedMessage()).apply {
putExtra(FilesDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
putExtra(FilesDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
return Intent(FileDownloadWorker.getDownloadAddedMessage()).apply {
putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
putExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
setPackage(context.packageName)
}
}
Expand All @@ -51,15 +51,15 @@ class FilesDownloadIntents(private val context: Context) {
downloadResult: RemoteOperationResult<*>,
unlinkedFromRemotePath: String?
): Intent {
return Intent(FilesDownloadWorker.getDownloadFinishMessage()).apply {
putExtra(FilesDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
putExtra(FilesDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
return Intent(FileDownloadWorker.getDownloadFinishMessage()).apply {
putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.behaviour)
putExtra(SendShareDialog.ACTIVITY_NAME, download.activityName)
putExtra(SendShareDialog.PACKAGE_NAME, download.packageName)
if (unlinkedFromRemotePath != null) {
putExtra(FilesDownloadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
putExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
}
setPackage(context.packageName)
}
Expand Down
Loading

0 comments on commit 041e836

Please sign in to comment.