mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-21 01:21:34 -08:00
Encapsulate consume attachment action
This commit is contained in:
1 parent
acb3657d95
commit
42515bfb2d
6 files changed
+15
-13
No files matched your search
@@ -317,11 +317,9 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
AttachmentState.COMPLETE -> {
|
||||
entryEditContentsView?.putAttachment(entryAttachmentState)
|
||||
mAttachmentFileBinderManager?.removeAttachmentAction(entryAttachmentState)
|
||||
}
|
||||
AttachmentState.ERROR -> {
|
||||
mDatabase?.removeAttachmentIfNotUsed(entryAttachmentState.attachment)
|
||||
mAttachmentFileBinderManager?.removeAttachmentAction(entryAttachmentState)
|
||||
entryEditContentsView?.removeAttachment(entryAttachmentState)
|
||||
}
|
||||
else -> {}
|
||||
|
||||
@@ -30,13 +30,10 @@ open class SaveDatabaseRunnable(protected var context: Context,
|
||||
: ActionRunnable() {
|
||||
|
||||
var mAfterSaveDatabase: ((Result) -> Unit)? = null
|
||||
protected var mAllowRemoveUnlinkedAttachments = true
|
||||
|
||||
override fun onStartRun() {}
|
||||
|
||||
override fun onActionRun() {
|
||||
if (mAllowRemoveUnlinkedAttachments)
|
||||
database.removeUnlinkedAttachment()
|
||||
if (saveDatabase && result.isSuccess) {
|
||||
try {
|
||||
database.saveData(context.contentResolver)
|
||||
|
||||
-5
@@ -31,11 +31,6 @@ class UpdateCompressionBinariesDatabaseRunnable (
|
||||
saveDatabase: Boolean)
|
||||
: SaveDatabaseRunnable(context, database, saveDatabase) {
|
||||
|
||||
init {
|
||||
// To prevent attachment corruption during compression
|
||||
mAllowRemoveUnlinkedAttachments = false
|
||||
}
|
||||
|
||||
override fun onStartRun() {
|
||||
// Set new compression
|
||||
if (database.allowDataCompression) {
|
||||
|
||||
@@ -558,6 +558,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
removeUnlinkedAttachment(attachment.binaryAttachment)
|
||||
}
|
||||
|
||||
// TODO buf unlink right element
|
||||
fun removeUnlinkedAttachment(vararg binaries: BinaryAttachment) {
|
||||
// Build binaries to remove with all binaries known
|
||||
val binariesToRemove = ArrayList<BinaryAttachment>()
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ import java.util.zip.GZIPOutputStream
|
||||
class AttachmentFileNotificationService: LockNotificationService() {
|
||||
|
||||
override val notificationId: Int = 10000
|
||||
private val attachmentNotificationList = CopyOnWriteArrayList<AttachmentNotification>()
|
||||
private val attachmentNotificationList = ArrayList<AttachmentNotification>()
|
||||
|
||||
private var mActionTaskBinder = ActionTaskBinder()
|
||||
private var mActionTaskListeners = LinkedList<ActionTaskListener>()
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService
|
||||
import com.kunzisoft.keepass.notifications.AttachmentFileNotificationService.Companion.ACTION_ATTACHMENT_FILE_START_DOWNLOAD
|
||||
@@ -46,7 +47,17 @@ class AttachmentFileBinderManager(private val activity: FragmentActivity) {
|
||||
|
||||
private val mActionTaskListener = object: AttachmentFileNotificationService.ActionTaskListener {
|
||||
override fun onAttachmentAction(fileUri: Uri, entryAttachmentState: EntryAttachmentState) {
|
||||
onActionTaskListener?.onAttachmentAction(fileUri, entryAttachmentState)
|
||||
onActionTaskListener?.let {
|
||||
it.onAttachmentAction(fileUri, entryAttachmentState)
|
||||
when (entryAttachmentState.downloadState) {
|
||||
AttachmentState.COMPLETE,
|
||||
AttachmentState.ERROR -> {
|
||||
// Finish the action when capture by activity
|
||||
consummeAttachmentAction(entryAttachmentState)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +99,7 @@ class AttachmentFileBinderManager(private val activity: FragmentActivity) {
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun removeAttachmentAction(attachment: EntryAttachmentState) {
|
||||
fun consummeAttachmentAction(attachment: EntryAttachmentState) {
|
||||
mBinder?.getService()?.removeAttachmentAction(attachment)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user