diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt index 309211df9f..ba3197b919 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt @@ -15,18 +15,18 @@ import com.owncloud.android.utils.FileStorageUtils fun RemoteOperationResult<*>?.getConflictedRemoteIdsWithOfflineOperations( offlineOperations: List -): Pair, ArrayList>? { +): HashMap? { val newFiles = toOCFile() ?: return null - val (remoteIds, offlineOperationsPaths) = newFiles + val conflictedMap = newFiles .flatMap { file -> offlineOperations .filter { it.filename == file.fileName } .map { file.remoteId to it.path } } - .unzip() + .toMap(HashMap()) - return ArrayList(remoteIds) to ArrayList(offlineOperationsPaths) + return conflictedMap.ifEmpty { null } } @Suppress("Deprecation") diff --git a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java index 6b5aa60a07..46c6734b9a 100644 --- a/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/RefreshFolderOperation.java @@ -264,8 +264,8 @@ public class RefreshFolderOperation extends RemoteOperation { var offlineOperations = mStorageManager.offlineOperationDao.getAll(); var conflictData = RemoteOperationResultExtensionsKt.getConflictedRemoteIdsWithOfflineOperations(result, offlineOperations); - if (conflictData != null && !conflictData.getFirst().isEmpty() && !conflictData.getSecond().isEmpty()) { - sendFolderSyncConflictEventBroadcast(conflictData.getFirst(), conflictData.getSecond()); + if (conflictData != null && !conflictData.isEmpty()) { + sendFolderSyncConflictEventBroadcast(conflictData); } if (!mSyncFullAccount && mRemoteFolderChanged) { @@ -287,10 +287,9 @@ public class RefreshFolderOperation extends RemoteOperation { return result; } - private void sendFolderSyncConflictEventBroadcast(ArrayList newFiles, ArrayList offlineOperationPaths) { + private void sendFolderSyncConflictEventBroadcast(HashMap conflictData) { Intent intent = new Intent(FileDisplayActivity.FOLDER_SYNC_CONFLICT); - intent.putStringArrayListExtra(FileDisplayActivity.FOLDER_SYNC_CONFLICT_NEW_FILES, newFiles); - intent.putStringArrayListExtra(FileDisplayActivity.FOLDER_SYNC_CONFLICT_OFFLINE_OPERATION_PATHS, offlineOperationPaths); + intent.putExtra(FileDisplayActivity.FOLDER_SYNC_CONFLICT_ARG_REMOTE_IDS_TO_OPERATION_PATHS, conflictData); LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 883803003d..bc52cd2c24 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -173,8 +173,7 @@ public class FileDisplayActivity extends FileActivity public static final int SINGLE_USER_SIZE = 1; public static final String OPEN_FILE = "NC_OPEN_FILE"; public static final String FOLDER_SYNC_CONFLICT = "FOLDER_SYNC_CONFLICT"; - public static final String FOLDER_SYNC_CONFLICT_NEW_FILES = "FOLDER_SYNC_CONFLICT_NEW_FILES"; - public static final String FOLDER_SYNC_CONFLICT_OFFLINE_OPERATION_PATHS = "FOLDER_SYNC_CONFLICT_OFFLINE_OPERATION_PATHS"; + public static final String FOLDER_SYNC_CONFLICT_ARG_REMOTE_IDS_TO_OPERATION_PATHS = "FOLDER_SYNC_CONFLICT_ARG_REMOTE_IDS_TO_OPERATION_PATHS"; private FilesBinding binding; diff --git a/app/src/main/java/com/owncloud/android/ui/activity/fileDisplayActivity/OfflineFolderConflictManager.kt b/app/src/main/java/com/owncloud/android/ui/activity/fileDisplayActivity/OfflineFolderConflictManager.kt index e6677fe3e7..d9ffffa62e 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/fileDisplayActivity/OfflineFolderConflictManager.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/fileDisplayActivity/OfflineFolderConflictManager.kt @@ -13,6 +13,7 @@ import android.content.Intent import android.content.IntentFilter import androidx.localbroadcastmanager.content.LocalBroadcastManager import com.nextcloud.client.jobs.offlineOperations.OfflineOperationsNotificationManager +import com.nextcloud.utils.extensions.getSerializableArgument import com.owncloud.android.ui.activity.FileDisplayActivity class OfflineFolderConflictManager(private val activity: FileDisplayActivity) { @@ -27,23 +28,25 @@ class OfflineFolderConflictManager(private val activity: FileDisplayActivity) { private val folderSyncConflictEventReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { intent.run { - val remoteIds = getStringArrayListExtra(FileDisplayActivity.FOLDER_SYNC_CONFLICT_NEW_FILES) - val offlineOperationsPaths = - getStringArrayListExtra(FileDisplayActivity.FOLDER_SYNC_CONFLICT_OFFLINE_OPERATION_PATHS) + @Suppress("UNCHECKED_CAST") + val map = getSerializableArgument( + FileDisplayActivity.FOLDER_SYNC_CONFLICT_ARG_REMOTE_IDS_TO_OPERATION_PATHS, + HashMap::class.java + ) as? HashMap - if (!remoteIds.isNullOrEmpty() && !offlineOperationsPaths.isNullOrEmpty()) { - showFolderSyncConflictNotifications(remoteIds, offlineOperationsPaths) + if (!map.isNullOrEmpty()) { + showFolderSyncConflictNotifications(map) } } } } - private fun showFolderSyncConflictNotifications(remoteIds: List, offlineOperationsPaths: List) { - remoteIds.mapNotNull { activity.storageManager.getFileByRemoteId(it) } - .forEach { file -> - offlineOperationsPaths.forEach { path -> - notificationManager.showConflictResolveNotification(file, path) - } + private fun showFolderSyncConflictNotifications(remoteIdsToOperationPaths: HashMap) { + remoteIdsToOperationPaths.forEach { (remoteId, path) -> + val file = activity.storageManager.getFileByRemoteId(remoteId) + file?.let { + notificationManager.showConflictResolveNotification(file, path) } + } } }