Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.nextcloud.client.account.UserAccountManagerImpl
import com.owncloud.android.MainApp
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.lib.common.utils.Log_OC
import javax.inject.Inject

class FileUploadBroadcastReceiver : BroadcastReceiver() {
Expand All @@ -21,12 +24,12 @@ class FileUploadBroadcastReceiver : BroadcastReceiver() {
lateinit var uploadsStorageManager: UploadsStorageManager

companion object {
// region cancel or remove actions
private const val TAG = "FileUploadBroadcastReceiver"

const val UPLOAD_ID = "UPLOAD_ID"
const val ACCOUNT_NAME = "ACCOUNT_NAME"
const val REMOTE_PATH = "REMOTE_PATH"
const val REMOVE = "REMOVE"
// endregion
}

@Suppress("ReturnCount")
Expand Down Expand Up @@ -57,9 +60,12 @@ class FileUploadBroadcastReceiver : BroadcastReceiver() {

val remove = intent.getBooleanExtra(REMOVE, false)

Log_OC.d(TAG, "upload: $remotePath removed: $remove")

FileUploadWorker.cancelUpload(remotePath, accountName)

if (remove) {
removeFileIfAlreadyUploaded(context, remotePath)
uploadsStorageManager.removeUpload(uploadId)
} else {
FileUploadHelper.instance().updateUploadStatus(
Expand All @@ -73,4 +79,13 @@ class FileUploadBroadcastReceiver : BroadcastReceiver() {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(uploadId.toInt())
}

@Suppress("DEPRECATION")
private fun removeFileIfAlreadyUploaded(context: Context, remotePath: String) {
val userAccountManager = UserAccountManagerImpl.fromContext(context)
val user = userAccountManager.user
val storageManager = FileDataStorageManager(user, context.contentResolver)
val ocFile = storageManager.getFileByPath(remotePath) ?: return
storageManager.removeFile(ocFile, true, false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.ForegroundServiceHelper
import com.nextcloud.utils.extensions.getPercent
import com.nextcloud.utils.extensions.toFile
import com.nextcloud.utils.extensions.updateStatus
import com.owncloud.android.R
import com.owncloud.android.datamodel.ForegroundServiceType
import com.owncloud.android.datamodel.SyncedFolder
Expand Down Expand Up @@ -374,14 +373,6 @@ class FileUploadWorker(
fileUploadEventBroadcaster.sendUploadStarted(operation, context)
} catch (e: Exception) {
Log_OC.e(TAG, "Error uploading", e)
uploadsStorageManager.run {
uploadDao.getUploadById(upload.uploadId, user.accountName)?.let { entity ->
updateStatus(
entity,
UploadsStorageManager.UploadStatus.UPLOAD_FAILED
)
}
}
result = RemoteOperationResult(e)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import com.owncloud.android.R
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.operations.UploadFileOperation

sealed class UploadBroadcastAction {
Expand Down Expand Up @@ -48,7 +49,10 @@ sealed class UploadBroadcastAction {
setPackage(context.packageName)
}

val requestCode = if (remove) operation.ocUploadId.toInt() + 1000 else operation.ocUploadId.toInt()
val uploadId = operation.ocUploadId.toInt()
val requestCode = if (remove) uploadId + 1000 else uploadId

Log_OC.i("UploadBroadcastAction", "broadcast action code: $requestCode")

return PendingIntent.getBroadcast(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -88,7 +88,7 @@ public LocalFileListAdapter(boolean localFolderPickerMode,
mContext = context;
mLocalFolderPicker = localFolderPickerMode;
this.localFileListFragmentInterface = localFileListFragmentInterface;
checkedFiles = new HashSet<>();
checkedFiles = new LinkedHashSet<>();
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserve user's file selection for upload

this.viewThemeUtils = viewThemeUtils;
this.isWithinEncryptedFolder = isWithinEncryptedFolder;
setHasStableIds(true);
Expand Down
Loading