Эх сурвалжийг харах

Fix file name in notification

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 жил өмнө
parent
commit
6515602ee6

+ 21 - 20
app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

@@ -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
-                val result = upload(operation, user.get())
+                currentUploadFileOperation = uploadFileOperation
+                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,
-            intents.startIntent(operation),
-            intents.notificationStartIntent(operation)
+            uploadFileOperation,
+            intents.startIntent(uploadFileOperation),
+            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 remoteId: String? = operation.file.remoteId
+            val file = File(uploadFileOperation.originalStoragePath)
+            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)
-            notifyUploadResult(operation, result)
+            uploadsStorageManager.updateDatabaseUploadResult(result, uploadFileOperation)
+            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
                     )
                     )
                 }
                 }
 
 

+ 5 - 7
app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt

@@ -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()

+ 5 - 1
app/src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -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() {

+ 1 - 1
app/src/main/java/com/owncloud/android/utils/EncryptionUtils.java

@@ -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);