Use hashmap rather than pair of arraylist string

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-20 11:26:42 +02:00
parent 3401386920
commit d5747ab028
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
4 changed files with 23 additions and 22 deletions

View file

@ -15,18 +15,18 @@ import com.owncloud.android.utils.FileStorageUtils
fun RemoteOperationResult<*>?.getConflictedRemoteIdsWithOfflineOperations(
offlineOperations: List<OfflineOperationEntity>
): Pair<ArrayList<String>, ArrayList<String?>>? {
): HashMap<String, String?>? {
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")

View file

@ -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<String> newFiles, ArrayList<String> offlineOperationPaths) {
private void sendFolderSyncConflictEventBroadcast(HashMap<String, String> 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);
}

View file

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

View file

@ -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<String, String>
if (!remoteIds.isNullOrEmpty() && !offlineOperationsPaths.isNullOrEmpty()) {
showFolderSyncConflictNotifications(remoteIds, offlineOperationsPaths)
if (!map.isNullOrEmpty()) {
showFolderSyncConflictNotifications(map)
}
}
}
}
private fun showFolderSyncConflictNotifications(remoteIds: List<String>, offlineOperationsPaths: List<String>) {
remoteIds.mapNotNull { activity.storageManager.getFileByRemoteId(it) }
.forEach { file ->
offlineOperationsPaths.forEach { path ->
notificationManager.showConflictResolveNotification(file, path)
}
private fun showFolderSyncConflictNotifications(remoteIdsToOperationPaths: HashMap<String, String>) {
remoteIdsToOperationPaths.forEach { (remoteId, path) ->
val file = activity.storageManager.getFileByRemoteId(remoteId)
file?.let {
notificationManager.showConflictResolveNotification(file, path)
}
}
}
}