Add KEEP_BOTH_FOLDER click

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-08-21 10:10:18 +02:00
parent 2f4ee1f392
commit 986d0848fc
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF
4 changed files with 50 additions and 16 deletions

View file

@ -10,6 +10,7 @@ package com.nextcloud.client.jobs.offlineOperations
import android.app.PendingIntent
import android.content.Context
import androidx.core.app.NotificationCompat
import com.nextcloud.client.database.entity.OfflineOperationEntity
import com.nextcloud.client.jobs.notification.WorkerNotificationManager
import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile
@ -76,13 +77,19 @@ class OfflineOperationsNotificationManager(private val context: Context, viewThe
}
}
fun showConflictResolveNotification(file: OCFile, path: String) {
val notificationId = file.fileId.toInt()
fun showConflictResolveNotification(file: OCFile, entity: OfflineOperationEntity?) {
val path = entity?.path
val id = entity?.id
if (path == null || id == null) {
return
}
val intent = ConflictsResolveActivity.createIntent(file, path, context)
val pendingIntent = PendingIntent.getActivity(
context,
notificationId,
id,
intent,
PendingIntent.FLAG_IMMUTABLE
)
@ -104,9 +111,11 @@ class OfflineOperationsNotificationManager(private val context: Context, viewThe
.setContentIntent(pendingIntent)
.addAction(action)
notificationManager.notify(
notificationId,
notificationBuilder.build()
)
notificationManager.notify(id, notificationBuilder.build())
}
fun dismissNotification(id: Int?) {
if (id == null) return
notificationManager.cancel(id)
}
}

View file

@ -68,6 +68,7 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -233,6 +234,29 @@ public class FileDataStorageManager {
addCreateFolderOfflineOperation(newPath, newFolderName, file.getParentId());
}
@SuppressLint("SimpleDateFormat")
public void keepOfflineOperationAndServerFile(OfflineOperationEntity entity) {
Long parentOCFileId = entity.getParentOCFileId();
if (parentOCFileId == null) return;
OCFile parentFolder = getFileById(parentOCFileId);
if (parentFolder == null) return;
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy - HH:mm");
String currentDateTime = sdf.format(new Date());
String newFolderName = entity.getFilename() + " - " + currentDateTime;
String newPath = parentFolder.getDecryptedRemotePath() + newFolderName + OCFile.PATH_SEPARATOR;
entity.setPath(newPath);
entity.setFilename(newFolderName);
offlineOperationDao.update(entity);
OCFile file = new OCFile(entity.getPath());
file.setMimeType(MimeType.DIRECTORY);
saveFileWithParent(file, MainApp.getAppContext());
}
private @Nullable
OCFile getFileByPath(String type, String path) {
final boolean shouldUseEncryptedPath = ProviderTableMeta.FILE_PATH.equals(type);

View file

@ -17,6 +17,7 @@ import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.lifecycleScope
import com.nextcloud.client.account.User
import com.nextcloud.client.jobs.download.FileDownloadHelper
import com.nextcloud.client.jobs.offlineOperations.OfflineOperationsNotificationManager
import com.nextcloud.client.jobs.upload.FileUploadHelper
import com.nextcloud.client.jobs.upload.FileUploadWorker
import com.nextcloud.client.jobs.upload.UploadNotificationManager
@ -24,7 +25,6 @@ import com.nextcloud.model.HTTPStatusCodes
import com.nextcloud.utils.extensions.getParcelableArgument
import com.nextcloud.utils.extensions.logFileSize
import com.owncloud.android.R
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.datamodel.UploadsStorageManager
import com.owncloud.android.db.OCUpload
@ -47,14 +47,12 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
@Inject
lateinit var uploadsStorageManager: UploadsStorageManager
@Inject
lateinit var fileStorageManager: FileDataStorageManager
private var conflictUploadId: Long = 0
private var offlineOperationPath: String? = null
private var existingFile: OCFile? = null
private var newFile: OCFile? = null
private var localBehaviour = FileUploadWorker.LOCAL_BEHAVIOUR_FORGET
private lateinit var offlineOperationNotificationManager: OfflineOperationsNotificationManager
@JvmField
var listener: OnConflictDecisionMadeListener? = null
@ -72,6 +70,7 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
// new file was modified locally in file system
newFile = file
setupOnConflictDecisionMadeListener(upload)
offlineOperationNotificationManager = OfflineOperationsNotificationManager(this, viewThemeUtils)
}
private fun getArguments(savedInstanceState: Bundle?) {
@ -130,7 +129,9 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
}
Decision.KEEP_BOTH_FOLDER -> {
fileDataStorageManager.keepOfflineOperationAndServerFile(entity)
backgroundJobManager.startOfflineOperations()
offlineOperationNotificationManager.dismissNotification(offlineOperation.id)
}
else -> Unit
@ -140,7 +141,6 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
}
}
private fun keepLocal(file: OCFile?, upload: OCUpload?, user: User) {
upload?.let {
FileUploadHelper.instance().removeFileUpload(it.remotePath, it.accountName)
@ -233,7 +233,7 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
}
if (existingFile == null) {
val remotePath = fileStorageManager.retrieveRemotePathConsideringEncryption(newFile) ?: return
val remotePath = fileDataStorageManager.retrieveRemotePathConsideringEncryption(newFile) ?: return
val operation = ReadFileRemoteOperation(remotePath)
@Suppress("TooGenericExceptionCaught")
@ -254,7 +254,7 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
}
}
} else {
val remotePath = fileStorageManager.retrieveRemotePathConsideringEncryption(existingFile) ?: return
val remotePath = fileDataStorageManager.retrieveRemotePathConsideringEncryption(existingFile) ?: return
startDialog(remotePath)
}
}

View file

@ -45,7 +45,8 @@ class OfflineFolderConflictManager(private val activity: FileDisplayActivity) {
remoteIdsToOperationPaths.forEach { (remoteId, path) ->
val file = activity.storageManager.getFileByRemoteId(remoteId)
file?.let {
notificationManager.showConflictResolveNotification(file, path)
val entity = activity.storageManager.offlineOperationDao.getByPath(path)
notificationManager.showConflictResolveNotification(file, entity)
}
}
}