mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-29 21:33:07 -08:00
Fix uploading attachment with same name
This commit is contained in:
1 parent
0f6c8601d2
commit
8267e13d22
3 files changed
+28
-5
No files matched your search
@@ -310,7 +310,6 @@ class EntryEditActivity : LockingActivity(),
|
||||
override fun onAttachmentAction(fileUri: Uri, entryAttachmentState: EntryAttachmentState) {
|
||||
when (entryAttachmentState.downloadState) {
|
||||
AttachmentState.START -> {
|
||||
mTempAttachments.add(entryAttachmentState.attachment)
|
||||
entryEditContentsView?.apply {
|
||||
// When only one attachment is allowed
|
||||
if (!mAllowMultipleAttachments) {
|
||||
@@ -381,7 +380,9 @@ class EntryEditActivity : LockingActivity(),
|
||||
|
||||
mDatabase?.binaryPool?.let { binaryPool ->
|
||||
assignAttachments(newEntry.getAttachments(binaryPool).toSet(), StreamDirection.UPLOAD) { attachment ->
|
||||
// Remove entry by clicking trash button
|
||||
newEntry.removeAttachment(attachment)
|
||||
mAttachmentFileBinderManager?.removeBinaryAttachment(attachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -475,8 +476,15 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
override fun onValidateReplaceFile(attachmentToUploadUri: Uri?, attachment: Attachment?) {
|
||||
startUploadAttachment(attachmentToUploadUri, attachment)
|
||||
}
|
||||
|
||||
private fun startUploadAttachment(attachmentToUploadUri: Uri?, attachment: Attachment?) {
|
||||
if (attachmentToUploadUri != null && attachment != null) {
|
||||
// Start uploading in service
|
||||
mAttachmentFileBinderManager?.startUploadAttachment(attachmentToUploadUri, attachment)
|
||||
// Add in temp list
|
||||
mTempAttachments.add(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,7 +498,7 @@ class EntryEditActivity : LockingActivity(),
|
||||
ReplaceFileDialogFragment.build(attachmentToUploadUri, entryAttachment)
|
||||
.show(supportFragmentManager, "replacementFileFragment")
|
||||
} else {
|
||||
mAttachmentFileBinderManager?.startUploadAttachment(attachmentToUploadUri, entryAttachment)
|
||||
startUploadAttachment(attachmentToUploadUri, entryAttachment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-3
@@ -107,6 +107,13 @@ class AttachmentFileNotificationService: LockNotificationService() {
|
||||
intent,
|
||||
StreamDirection.DOWNLOAD)
|
||||
}
|
||||
ACTION_ATTACHMENT_REMOVE -> {
|
||||
intent.getParcelableExtra<Attachment>(ATTACHMENT_KEY)?.let { entryAttachment ->
|
||||
attachmentNotificationList.firstOrNull { it.entryAttachmentState.attachment == entryAttachment }?.let { elementToRemove ->
|
||||
attachmentNotificationList.remove(elementToRemove)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
if (downloadFileUri != null) {
|
||||
attachmentNotificationList.firstOrNull { it.uri == downloadFileUri }?.let { elementToRemove ->
|
||||
@@ -265,13 +272,13 @@ class AttachmentFileNotificationService: LockNotificationService() {
|
||||
?.notificationId ?: notificationId) + 1
|
||||
val entryAttachmentState = EntryAttachmentState(entryAttachment, streamDirection)
|
||||
val attachmentNotification = AttachmentNotification(downloadFileUri, nextNotificationId, entryAttachmentState)
|
||||
|
||||
// Add action to the list on start
|
||||
attachmentNotificationList.add(attachmentNotification)
|
||||
|
||||
mainScope.launch {
|
||||
AttachmentFileAction(attachmentNotification,
|
||||
contentResolver).apply {
|
||||
listener = attachmentFileActionListener
|
||||
}.executeAction()
|
||||
contentResolver).executeAction()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -426,6 +433,7 @@ class AttachmentFileNotificationService: LockNotificationService() {
|
||||
|
||||
const val ACTION_ATTACHMENT_FILE_START_UPLOAD = "ACTION_ATTACHMENT_FILE_START_UPLOAD"
|
||||
const val ACTION_ATTACHMENT_FILE_START_DOWNLOAD = "ACTION_ATTACHMENT_FILE_START_DOWNLOAD"
|
||||
const val ACTION_ATTACHMENT_REMOVE = "ACTION_ATTACHMENT_REMOVE"
|
||||
|
||||
const val FILE_URI_KEY = "FILE_URI_KEY"
|
||||
const val ATTACHMENT_KEY = "ATTACHMENT_KEY"
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService.Companion.ACTION_ATTACHMENT_FILE_START_DOWNLOAD
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService.Companion.ACTION_ATTACHMENT_FILE_START_UPLOAD
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService.Companion.ACTION_ATTACHMENT_REMOVE
|
||||
|
||||
class AttachmentFileBinderManager(private val activity: FragmentActivity) {
|
||||
|
||||
@@ -126,4 +127,10 @@ class AttachmentFileBinderManager(private val activity: FragmentActivity) {
|
||||
putParcelable(AttachmentFileNotificationService.ATTACHMENT_KEY, attachment)
|
||||
}, ACTION_ATTACHMENT_FILE_START_DOWNLOAD)
|
||||
}
|
||||
|
||||
fun removeBinaryAttachment(attachment: Attachment) {
|
||||
start(Bundle().apply {
|
||||
putParcelable(AttachmentFileNotificationService.ATTACHMENT_KEY, attachment)
|
||||
}, ACTION_ATTACHMENT_REMOVE)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user