Skip to content

Commit

Permalink
Rename argument name
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 5, 2024
1 parent 83c18cd commit 5d23af3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FileDownloadIntents(private val context: Context) {
linkedToRemotePath: String
): Intent {
return Intent(FileDownloadWorker.getDownloadAddedMessage()).apply {
putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
putExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
setPackage(context.packageName)
Expand All @@ -53,7 +53,7 @@ class FileDownloadIntents(private val context: Context) {
): Intent {
return Intent(FileDownloadWorker.getDownloadFinishMessage()).apply {
putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, download.user.accountName)
putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.behaviour)
putExtra(SendShareDialog.ACTIVITY_NAME, download.activityName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.files.services.IndexedForest
import com.owncloud.android.lib.common.OwnCloudAccount
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
import com.owncloud.android.lib.common.operations.RemoteOperationResult
Expand Down Expand Up @@ -71,21 +70,20 @@ class FileDownloadWorker(
private var currentDownload: DownloadFileOperation? = null

const val FILES_SEPARATOR = ","
const val FOLDER_PATH = "FOLDER_PATH"
const val USER_NAME = "USER"
const val FILE_PATH = "FILE_PATH"
const val FILES_PATH = "FILES_PATH"
const val FOLDER_REMOTE_PATH = "FOLDER_REMOTE_PATH"
const val FILE_REMOTE_PATH = "FILE_REMOTE_PATH"
const val FILES_REMOTE_PATH = "FILES_REMOTE_PATH"
const val ACCOUNT_NAME = "ACCOUNT_NAME"
const val BEHAVIOUR = "BEHAVIOUR"
const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE"
const val ACTIVITY_NAME = "ACTIVITY_NAME"
const val PACKAGE_NAME = "PACKAGE_NAME"
const val CONFLICT_UPLOAD_ID = "CONFLICT_UPLOAD_ID"
const val EXTRA_USER = "USER"
const val EXTRA_FILE = "FILE"
const val EXTRA_DOWNLOAD_RESULT = "RESULT"
const val EXTRA_REMOTE_PATH = "REMOTE_PATH"
const val EXTRA_LINKED_TO_PATH = "LINKED_TO"
const val ACCOUNT_NAME = "ACCOUNT_NAME"

const val EXTRA_DOWNLOAD_RESULT = "EXTRA_DOWNLOAD_RESULT"
const val EXTRA_REMOTE_PATH = "EXTRA_REMOTE_PATH"
const val EXTRA_LINKED_TO_PATH = "EXTRA_LINKED_TO_PATH"
const val EXTRA_ACCOUNT_NAME = "EXTRA_ACCOUNT_NAME"

fun isDownloading(user: User, file: OCFile): Boolean {
return currentDownload?.file?.fileId == file.fileId &&
Expand All @@ -102,16 +100,20 @@ class FileDownloadWorker(
}

private val pendingDownloads = IndexedForest<DownloadFileOperation>()

private var conflictUploadId: Long? = null
private var lastPercent = 0

private val intents = FileDownloadIntents(context)
private val notificationManager = DownloadNotificationManager(context, viewThemeUtils)
private var downloadProgressListener = FileDownloadProgressListener()

private var user: User? = null
private var currentUser = Optional.empty<User>()
private var storageManager: FileDataStorageManager? = null

private var currentUserFileStorageManager: FileDataStorageManager? = null
private var fileDataStorageManager: FileDataStorageManager? = null
private var downloadClient: OwnCloudClient? = null
private var user: User? = null

private var folder: OCFile? = null
private var isAnyOperationFailed = true

Expand Down Expand Up @@ -223,22 +225,22 @@ class FileDownloadWorker(
}

private fun setUser() {
val accountName = inputData.keyValueMap[USER_NAME] as String
val accountName = inputData.keyValueMap[ACCOUNT_NAME] as String
user = accountManager.getUser(accountName).get()
fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
}

private fun setFolder() {
val folderPath = inputData.keyValueMap[FOLDER_PATH] as? String?
val folderPath = inputData.keyValueMap[FOLDER_REMOTE_PATH] as? String?
if (folderPath != null) {
folder = storageManager?.getFileByEncryptedRemotePath(folderPath)
folder = currentUserFileStorageManager?.getFileByEncryptedRemotePath(folderPath)
}
}

private fun getFiles(): List<OCFile> {
val result = arrayListOf<OCFile>()

val filesPath = inputData.keyValueMap[FILES_PATH] as String?
val filesPath = inputData.keyValueMap[FILES_REMOTE_PATH] as String?
val filesPathList = filesPath?.split(FILES_SEPARATOR)

if (filesPathList != null) {
Expand All @@ -248,7 +250,7 @@ class FileDownloadWorker(
}
}
} else {
val remotePath = inputData.keyValueMap[FILE_PATH] as String
val remotePath = inputData.keyValueMap[FILE_REMOTE_PATH] as String
fileDataStorageManager?.getFileByEncryptedRemotePath(remotePath)?.let { file ->
result.add(file)
}
Expand Down Expand Up @@ -296,13 +298,13 @@ class FileDownloadWorker(
var downloadResult: RemoteOperationResult<*>? = null
try {
val ocAccount = getOCAccountForDownload()
downloadClient =
val downloadClient =
OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)

downloadResult = currentDownload?.execute(downloadClient)
if (downloadResult?.isSuccess == true && currentDownload?.downloadType === DownloadType.DOWNLOAD) {
getCurrentFile()?.let {
FileDownloadHelper.instance().saveFile(it, currentDownload, storageManager)
FileDownloadHelper.instance().saveFile(it, currentDownload, currentUserFileStorageManager)
}
}
} catch (e: Exception) {
Expand All @@ -328,16 +330,16 @@ class FileDownloadWorker(
val currentDownloadUser = accountManager.getUser(currentDownloadAccount?.name)
if (currentUser != currentDownloadUser) {
currentUser = currentDownloadUser
storageManager = FileDataStorageManager(currentUser.get(), context.contentResolver)
currentUserFileStorageManager = FileDataStorageManager(currentUser.get(), context.contentResolver)
}
return currentDownloadUser.get().toOwnCloudAccount()
}

private fun getCurrentFile(): OCFile? {
var file: OCFile? = currentDownload?.file?.fileId?.let { storageManager?.getFileById(it) }
var file: OCFile? = currentDownload?.file?.fileId?.let { currentUserFileStorageManager?.getFileById(it) }

if (file == null) {
file = storageManager?.getFileByDecryptedRemotePath(currentDownload?.file?.remotePath)
file = currentUserFileStorageManager?.getFileByDecryptedRemotePath(currentDownload?.file?.remotePath)
}

if (file == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ internal class BackgroundJobManagerImpl(

override fun startFolderDownloadJob(folder: OCFile, user: User, filesPath: List<String>) {
val data = workDataOf(
FileDownloadWorker.USER_NAME to user.accountName,
FileDownloadWorker.FOLDER_PATH to folder.remotePath,
FileDownloadWorker.FILES_PATH to filesPath.joinToString(FileDownloadWorker.FILES_SEPARATOR),
FileDownloadWorker.ACCOUNT_NAME to user.accountName,
FileDownloadWorker.FOLDER_REMOTE_PATH to folder.remotePath,
FileDownloadWorker.FILES_REMOTE_PATH to filesPath.joinToString(FileDownloadWorker.FILES_SEPARATOR),
FileDownloadWorker.DOWNLOAD_TYPE to DownloadType.DOWNLOAD.toString()
)

Expand All @@ -552,8 +552,8 @@ internal class BackgroundJobManagerImpl(
val tag = startFileDownloadJobTag(user, file)

val data = workDataOf(
FileDownloadWorker.USER_NAME to user.accountName,
FileDownloadWorker.FILE_PATH to file.remotePath,
FileDownloadWorker.ACCOUNT_NAME to user.accountName,
FileDownloadWorker.FILE_REMOTE_PATH to file.remotePath,
FileDownloadWorker.BEHAVIOUR to behaviour,
FileDownloadWorker.DOWNLOAD_TYPE to downloadType.toString(),
FileDownloadWorker.ACTIVITY_NAME to activityName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void cancel(Account account, OCFile file){
*/
private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
Intent added = new Intent(FileDownloadWorker.Companion.getDownloadAddedMessage());
added.putExtra(FileDownloadWorker.ACCOUNT_NAME, account.name);
added.putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, account.name);
added.putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
added.setPackage(mService.getPackageName());
LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(added);
Expand All @@ -183,7 +183,7 @@ private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
private void sendBroadcastFinishedSyncFolder(Account account, String remotePath,
boolean success) {
Intent finished = new Intent(FileDownloadWorker.Companion.getDownloadFinishMessage());
finished.putExtra(FileDownloadWorker.ACCOUNT_NAME, account.name);
finished.putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, account.name);
finished.putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
finished.putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, success);
finished.setPackage(mService.getPackageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ private boolean isAscendant(String linkedToRemotePath) {
}

private boolean isSameAccount(Intent intent) {
String accountName = intent.getStringExtra(FileDownloadWorker.ACCOUNT_NAME);
String accountName = intent.getStringExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME);
return accountName != null && getAccount() != null && accountName.equals(getAccount().name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void onReceive(Context context, Intent intent) {
}

private void previewNewImage(Intent intent) {
String accountName = intent.getStringExtra(FileDownloadWorker.ACCOUNT_NAME);
String accountName = intent.getStringExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME);
String downloadedRemotePath = intent.getStringExtra(FileDownloadWorker.EXTRA_REMOTE_PATH);
String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
if (getAccount().name.equals(accountName) && downloadedRemotePath != null) {
Expand Down

0 comments on commit 5d23af3

Please sign in to comment.