Fix attachments after orientation change

This commit is contained in:
J-Jamet
2021-08-11 12:35:32 +02:00
parent eefdeb0bb7
commit 9cbe0664f6
2 changed files with 11 additions and 11 deletions

View File

@@ -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?) {

View File

@@ -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) {