Fix file name in notification

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-04-05 10:39:45 +02:00 committed by Alper Öztürk
parent c6c6460630
commit 6515602ee6
4 changed files with 32 additions and 29 deletions

View file

@ -165,16 +165,16 @@ class FileUploadWorker(
} }
if (user.isPresent) { if (user.isPresent) {
val operation = createUploadFileOperation(upload, user.get()) val uploadFileOperation = createUploadFileOperation(upload, user.get())
currentUploadFileOperation = operation currentUploadFileOperation = uploadFileOperation
val result = upload(operation, user.get()) val result = upload(uploadFileOperation, user.get())
currentUploadFileOperation = null currentUploadFileOperation = null
fileUploaderDelegate.sendBroadcastUploadFinished( fileUploaderDelegate.sendBroadcastUploadFinished(
operation, uploadFileOperation,
result, result,
operation.oldFile?.storagePath, uploadFileOperation.oldFile?.storagePath,
context, context,
localBroadcastManager localBroadcastManager
) )
@ -205,39 +205,39 @@ class FileUploadWorker(
} }
@Suppress("TooGenericExceptionCaught", "DEPRECATION") @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?> lateinit var result: RemoteOperationResult<Any?>
notificationManager.prepareForStart( notificationManager.prepareForStart(
operation, uploadFileOperation,
intents.startIntent(operation), intents.startIntent(uploadFileOperation),
intents.notificationStartIntent(operation) intents.notificationStartIntent(uploadFileOperation)
) )
try { try {
val storageManager = operation.storageManager val storageManager = uploadFileOperation.storageManager
val ocAccount = OwnCloudAccount(user.toPlatformAccount(), context) val ocAccount = OwnCloudAccount(user.toPlatformAccount(), context)
val uploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context) val uploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
result = operation.execute(uploadClient) result = uploadFileOperation.execute(uploadClient)
val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user) val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user)
val file = File(operation.originalStoragePath) val file = File(uploadFileOperation.originalStoragePath)
val remoteId: String? = operation.file.remoteId val remoteId: String? = uploadFileOperation.file.remoteId
task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId)) task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId))
} catch (e: Exception) { } catch (e: Exception) {
Log_OC.e(TAG, "Error uploading", e) Log_OC.e(TAG, "Error uploading", e)
result = RemoteOperationResult<Any?>(e) result = RemoteOperationResult<Any?>(e)
} finally { } finally {
cleanupUploadProcess(result, operation) cleanupUploadProcess(result, uploadFileOperation)
} }
return result return result
} }
private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, operation: UploadFileOperation) { private fun cleanupUploadProcess(result: RemoteOperationResult<Any?>, uploadFileOperation: UploadFileOperation) {
if (!isStopped || !result.isCancelled) { if (!isStopped || !result.isCancelled) {
uploadsStorageManager.updateDatabaseUploadResult(result, operation) uploadsStorageManager.updateDatabaseUploadResult(result, uploadFileOperation)
notifyUploadResult(operation, result) notifyUploadResult(uploadFileOperation, result)
notificationManager.dismissWorkerNotifications() notificationManager.dismissWorkerNotifications()
} }
} }
@ -315,10 +315,11 @@ class FileUploadWorker(
if (percent != lastPercent) { if (percent != lastPercent) {
notificationManager.run { notificationManager.run {
updateUploadProgress(fileAbsoluteName, percent, currentUploadFileOperation)
val accountName = currentUploadFileOperation?.user?.accountName val accountName = currentUploadFileOperation?.user?.accountName
val remotePath = currentUploadFileOperation?.remotePath val remotePath = currentUploadFileOperation?.remotePath
val filename = currentUploadFileOperation?.fileName ?: ""
updateUploadProgress(filename, percent, currentUploadFileOperation)
if (accountName != null && remotePath != null) { if (accountName != null && remotePath != null) {
val key: String = val key: String =
@ -329,7 +330,7 @@ class FileUploadWorker(
progressRate, progressRate,
totalTransferredSoFar, totalTransferredSoFar,
totalToTransfer, totalToTransfer,
fileAbsoluteName filename
) )
} }

View file

@ -16,7 +16,6 @@ import android.os.Build
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.common.operations.RemoteOperationResult 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.operations.UploadFileOperation
import com.owncloud.android.ui.notifications.NotificationUtils import com.owncloud.android.ui.notifications.NotificationUtils
import com.owncloud.android.utils.theme.ViewThemeUtils import com.owncloud.android.utils.theme.ViewThemeUtils
@ -44,14 +43,14 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
} }
@Suppress("MagicNumber") @Suppress("MagicNumber")
fun prepareForStart(upload: UploadFileOperation, pendingIntent: PendingIntent, startIntent: PendingIntent) { fun prepareForStart(uploadFileOperation: UploadFileOperation, pendingIntent: PendingIntent, startIntent: PendingIntent) {
notificationBuilder.run { notificationBuilder.run {
setContentTitle(context.getString(R.string.uploader_upload_in_progress_ticker)) setContentTitle(context.getString(R.string.uploader_upload_in_progress_ticker))
setContentText( setContentText(
String.format( String.format(
context.getString(R.string.uploader_upload_in_progress), context.getString(R.string.uploader_upload_in_progress),
0, 0,
upload.fileName uploadFileOperation.fileName
) )
) )
setTicker(context.getString(R.string.foreground_service_upload)) setTicker(context.getString(R.string.foreground_service_upload))
@ -68,7 +67,7 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
setContentIntent(startIntent) setContentIntent(startIntent)
} }
if (!upload.isInstantPicture && !upload.isInstantVideo) { if (!uploadFileOperation.isInstantPicture && !uploadFileOperation.isInstantVideo) {
showNotification() showNotification()
} }
} }
@ -138,11 +137,10 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
} }
@Suppress("MagicNumber") @Suppress("MagicNumber")
fun updateUploadProgress(filePath: String, percent: Int, currentOperation: UploadFileOperation?) { fun updateUploadProgress(filename: String, percent: Int, currentOperation: UploadFileOperation?) {
notificationBuilder.run { notificationBuilder.run {
setProgress(100, percent, false) 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) setContentText(text)
showNotification() showNotification()

View file

@ -272,7 +272,11 @@ public class UploadFileOperation extends SyncOperation {
} }
public String getFileName() { public String getFileName() {
return (mFile != null) ? mFile.getFileName() : null; if (mFile == null) {
return null;
}
return mFile.getFileName();
} }
public OCFile getFile() { public OCFile getFile() {

View file

@ -548,7 +548,7 @@ public final class EncryptionUtils {
} }
public static EncryptedFile encryptFile(Context context, File file, Cipher cipher) throws InvalidParameterSpecException, IOException { 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); encryptFileWithGivenCipher(file, tempEncryptedFile, cipher);
String authenticationTagString = getAuthenticationTag(cipher); String authenticationTagString = getAuthenticationTag(cipher);
return new EncryptedFile(tempEncryptedFile, authenticationTagString); return new EncryptedFile(tempEncryptedFile, authenticationTagString);