mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix attachments after orientation change
This commit is contained in:
@@ -35,7 +35,6 @@ import com.kunzisoft.keepass.activities.dialogs.SetOTPDialogFragment
|
||||
import com.kunzisoft.keepass.adapters.EntryAttachmentsItemsAdapter
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.icons.IconDrawableFactory
|
||||
import com.kunzisoft.keepass.model.AttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryAttachmentState
|
||||
import com.kunzisoft.keepass.model.EntryInfo
|
||||
@@ -87,6 +86,13 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
attachmentsContainerView = view.findViewById(R.id.entry_attachments_container)
|
||||
attachmentsListView = view.findViewById(R.id.entry_attachments_list)
|
||||
|
||||
attachmentsAdapter = EntryAttachmentsItemsAdapter(requireContext())
|
||||
attachmentsListView.apply {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
adapter = attachmentsAdapter
|
||||
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||
}
|
||||
|
||||
templateView.apply {
|
||||
setOnIconClickListener {
|
||||
mEntryEditViewModel.requestIconSelection(templateView.getIcon())
|
||||
@@ -217,10 +223,12 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
mEntryEditViewModel.binaryPreviewLoaded(attachment, position)
|
||||
}
|
||||
}
|
||||
mEntryEditViewModel.onAttachmentAction(null)
|
||||
}
|
||||
AttachmentState.CANCELED,
|
||||
AttachmentState.ERROR -> {
|
||||
removeAttachment(entryAttachmentState)
|
||||
mEntryEditViewModel.onAttachmentAction(null)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
@@ -235,7 +243,6 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
|
||||
mAllowMultipleAttachments = database?.allowMultipleAttachments == true
|
||||
|
||||
attachmentsAdapter = EntryAttachmentsItemsAdapter(requireContext())
|
||||
attachmentsAdapter?.database = database
|
||||
attachmentsAdapter?.onListSizeChangedListener = { previousSize, newSize ->
|
||||
if (previousSize > 0 && newSize == 0) {
|
||||
@@ -244,11 +251,6 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
attachmentsContainerView.expand(true)
|
||||
}
|
||||
}
|
||||
attachmentsListView.apply {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
adapter = attachmentsAdapter
|
||||
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun assignEntryInfo(entryInfo: EntryInfo?) {
|
||||
|
||||
@@ -188,8 +188,6 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
registerInfo?.let { regInfo ->
|
||||
tempEntryInfo.saveRegisterInfo(mDatabase, regInfo)
|
||||
}
|
||||
|
||||
internalUpdateEntryInfo(tempEntryInfo)
|
||||
return tempEntryInfo
|
||||
}
|
||||
}
|
||||
@@ -215,7 +213,7 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
fun saveEntryInfo(entryInfo: EntryInfo) {
|
||||
IOActionTask(
|
||||
{
|
||||
internalUpdateEntryInfo(entryInfo)
|
||||
removeTempAttachmentsNotCompleted(entryInfo)
|
||||
mEntry?.let { oldEntry ->
|
||||
// Create a clone
|
||||
var newEntry = Entry(oldEntry)
|
||||
@@ -252,7 +250,7 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
).execute()
|
||||
}
|
||||
|
||||
private fun internalUpdateEntryInfo(entryInfo: EntryInfo) {
|
||||
private fun removeTempAttachmentsNotCompleted(entryInfo: EntryInfo) {
|
||||
// Do not save entry in upload progression
|
||||
mTempAttachments.forEach { attachmentState ->
|
||||
if (attachmentState.streamDirection == StreamDirection.UPLOAD) {
|
||||
|
||||
Reference in New Issue
Block a user