From a53d661d73b7b975a7515f33cd9298cfb1be333d Mon Sep 17 00:00:00 2001 From: alperozturk Date: Fri, 26 Apr 2024 13:07:54 +0200 Subject: [PATCH] Inform user for uploading same file again Signed-off-by: alperozturk --- .../nextcloud/client/jobs/upload/FileUploadWorker.kt | 3 +++ .../nextcloud/utils/extensions/ContextExtensions.kt | 11 +++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 15 insertions(+) diff --git a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt index 368f672273..f0913b8fdf 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt @@ -21,6 +21,8 @@ import com.nextcloud.client.network.ConnectivityService import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.model.WorkerState import com.nextcloud.model.WorkerStateLiveData +import com.nextcloud.utils.extensions.showToast +import com.owncloud.android.R import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.ThumbnailsCacheManager import com.owncloud.android.datamodel.UploadsStorageManager @@ -263,6 +265,7 @@ class FileUploadWorker( uploadFileOperation.user, File(uploadFileOperation.storagePath), uploadFileOperation.remotePath, context ) ) { + context.showToast(R.string.file_upload_worker_same_file_already_exists) return } diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index c032a63fce..dd4e4abc4e 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -13,6 +13,9 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.Build +import android.os.Handler +import android.os.Looper +import android.widget.Toast import com.owncloud.android.datamodel.ReceiverFlag @SuppressLint("UnspecifiedRegisterReceiverFlag") @@ -23,3 +26,11 @@ fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: Inte registerReceiver(receiver, filter) } } + +fun Context.showToast(message: String) { + Handler(Looper.getMainLooper()).post { + Toast.makeText(this, message, Toast.LENGTH_LONG).show() + } +} + +fun Context.showToast(messageId: Int) = showToast(getString(messageId)) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5d0045cfd9..80ed1b46b7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -127,6 +127,7 @@ Keep file in source folder Delete file from source folder seconds ago + Same file already exists, no conflict detected LIVE No files here No folders here