mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Fix file name in notification
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
c6c6460630
commit
6515602ee6
4 changed files with 32 additions and 29 deletions
|
@ -165,16 +165,16 @@ class FileUploadWorker(
|
|||
}
|
||||
|
||||
if (user.isPresent) {
|
||||
val operation = createUploadFileOperation(upload, user.get())
|
||||
val uploadFileOperation = createUploadFileOperation(upload, user.get())
|
||||
|
||||
currentUploadFileOperation = operation
|
||||
val result = upload(operation, user.get())
|
||||
currentUploadFileOperation = uploadFileOperation
|
||||
val result = upload(uploadFileOperation, user.get())
|
||||
currentUploadFileOperation = null
|
||||
|
||||
fileUploaderDelegate.sendBroadcastUploadFinished(
|
||||
operation,
|
||||
uploadFileOperation,
|
||||
result,
|
||||
operation.oldFile?.storagePath,
|
||||
uploadFileOperation.oldFile?.storagePath,
|
||||
context,
|
||||
localBroadcastManager
|
||||
)
|
||||
|
@ -205,39 +205,39 @@ class FileUploadWorker(
|
|||
}
|
||||
|
||||
@Suppress("TooGenericExceptionCaught", "DEPRECATION")
|
||||
private fun upload(operation: UploadFileOperation, user: User): RemoteOperationResult<Any?> {
|
||||
private fun upload(uploadFileOperation: UploadFileOperation, user: User): RemoteOperationResult<Any?> {
|
||||
lateinit var result: RemoteOperationResult<Any?>
|
||||
|
||||
notificationManager.prepareForStart(
|
||||
operation,
|
||||
intents.startIntent(operation),
|
||||
intents.notificationStartIntent(operation)
|
||||
uploadFileOperation,
|
||||
intents.startIntent(uploadFileOperation),
|
||||
intents.notificationStartIntent(uploadFileOperation)
|
||||
)
|
||||
|
||||
try {
|
||||
val storageManager = operation.storageManager
|
||||
val storageManager = uploadFileOperation.storageManager
|
||||
val ocAccount = OwnCloudAccount(user.toPlatformAccount(), context)
|
||||
val uploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
|
||||
result = operation.execute(uploadClient)
|
||||
result = uploadFileOperation.execute(uploadClient)
|
||||
|
||||
val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user)
|
||||
val file = File(operation.originalStoragePath)
|
||||
val remoteId: String? = operation.file.remoteId
|
||||
val file = File(uploadFileOperation.originalStoragePath)
|
||||
val remoteId: String? = uploadFileOperation.file.remoteId
|
||||
task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId))
|
||||
} catch (e: Exception) {
|
||||
Log_OC.e(TAG, "Error uploading", e)
|
||||
result = RemoteOperationResult<Any?>(e)
|
||||
} finally {
|
||||
cleanupUploadProcess(result, operation)
|
||||
cleanupUploadProcess(result, uploadFileOperation)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, operation: UploadFileOperation) {
|
||||
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, uploadFileOperation: UploadFileOperation) {
|
||||
if (!isStopped || !result.isCancelled) {
|
||||
uploadsStorageManager.updateDatabaseUploadResult(result, operation)
|
||||
notifyUploadResult(operation, result)
|
||||
uploadsStorageManager.updateDatabaseUploadResult(result, uploadFileOperation)
|
||||
notifyUploadResult(uploadFileOperation, result)
|
||||
notificationManager.dismissWorkerNotifications()
|
||||
}
|
||||
}
|
||||
|
@ -315,10 +315,11 @@ class FileUploadWorker(
|
|||
|
||||
if (percent != lastPercent) {
|
||||
notificationManager.run {
|
||||
updateUploadProgress(fileAbsoluteName, percent, currentUploadFileOperation)
|
||||
|
||||
val accountName = currentUploadFileOperation?.user?.accountName
|
||||
val remotePath = currentUploadFileOperation?.remotePath
|
||||
val filename = currentUploadFileOperation?.fileName ?: ""
|
||||
|
||||
updateUploadProgress(filename, percent, currentUploadFileOperation)
|
||||
|
||||
if (accountName != null && remotePath != null) {
|
||||
val key: String =
|
||||
|
@ -329,7 +330,7 @@ class FileUploadWorker(
|
|||
progressRate,
|
||||
totalTransferredSoFar,
|
||||
totalToTransfer,
|
||||
fileAbsoluteName
|
||||
filename
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import android.os.Build
|
|||
import androidx.core.app.NotificationCompat
|
||||
import com.owncloud.android.R
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult
|
||||
import com.owncloud.android.lib.resources.files.FileUtils
|
||||
import com.owncloud.android.operations.UploadFileOperation
|
||||
import com.owncloud.android.ui.notifications.NotificationUtils
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
|
@ -44,14 +43,14 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
|
|||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
fun prepareForStart(upload: UploadFileOperation, pendingIntent: PendingIntent, startIntent: PendingIntent) {
|
||||
fun prepareForStart(uploadFileOperation: UploadFileOperation, pendingIntent: PendingIntent, startIntent: PendingIntent) {
|
||||
notificationBuilder.run {
|
||||
setContentTitle(context.getString(R.string.uploader_upload_in_progress_ticker))
|
||||
setContentText(
|
||||
String.format(
|
||||
context.getString(R.string.uploader_upload_in_progress),
|
||||
0,
|
||||
upload.fileName
|
||||
uploadFileOperation.fileName
|
||||
)
|
||||
)
|
||||
setTicker(context.getString(R.string.foreground_service_upload))
|
||||
|
@ -68,7 +67,7 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
|
|||
setContentIntent(startIntent)
|
||||
}
|
||||
|
||||
if (!upload.isInstantPicture && !upload.isInstantVideo) {
|
||||
if (!uploadFileOperation.isInstantPicture && !uploadFileOperation.isInstantVideo) {
|
||||
showNotification()
|
||||
}
|
||||
}
|
||||
|
@ -138,11 +137,10 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
|
|||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
fun updateUploadProgress(filePath: String, percent: Int, currentOperation: UploadFileOperation?) {
|
||||
fun updateUploadProgress(filename: String, percent: Int, currentOperation: UploadFileOperation?) {
|
||||
notificationBuilder.run {
|
||||
setProgress(100, percent, false)
|
||||
val fileName = filePath.substring(filePath.lastIndexOf(FileUtils.PATH_SEPARATOR) + 1)
|
||||
val text = String.format(context.getString(R.string.uploader_upload_in_progress), percent, fileName)
|
||||
val text = String.format(context.getString(R.string.uploader_upload_in_progress), percent, filename)
|
||||
setContentText(text)
|
||||
|
||||
showNotification()
|
||||
|
|
|
@ -272,7 +272,11 @@ public class UploadFileOperation extends SyncOperation {
|
|||
}
|
||||
|
||||
public String getFileName() {
|
||||
return (mFile != null) ? mFile.getFileName() : null;
|
||||
if (mFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return mFile.getFileName();
|
||||
}
|
||||
|
||||
public OCFile getFile() {
|
||||
|
|
|
@ -548,7 +548,7 @@ public final class EncryptionUtils {
|
|||
}
|
||||
|
||||
public static EncryptedFile encryptFile(Context context, File file, Cipher cipher) throws InvalidParameterSpecException, IOException {
|
||||
File tempEncryptedFile = File.createTempFile(file.getName(), "", context.getCacheDir());
|
||||
File tempEncryptedFile = File.createTempFile(file.getName(), ".", context.getCacheDir());
|
||||
encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
|
||||
String authenticationTagString = getAuthenticationTag(cipher);
|
||||
return new EncryptedFile(tempEncryptedFile, authenticationTagString);
|
||||
|
|
Loading…
Reference in a new issue