mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix orientation for attachments and entry info as template property
This commit is contained in:
@@ -115,6 +115,11 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
adapter = attachmentsAdapter
|
||||
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
val attachments: List<Attachment> =
|
||||
savedInstanceState.getParcelableArrayList(ATTACHMENTS_TAG) ?: listOf()
|
||||
setAttachments(attachments)
|
||||
}
|
||||
|
||||
mEntryEditViewModel.onTemplateChanged.observe(viewLifecycleOwner) { template ->
|
||||
templateView.setTemplate(template)
|
||||
@@ -122,10 +127,7 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
|
||||
mEntryEditViewModel.entryInfoLoaded.observe(viewLifecycleOwner) { entryInfo ->
|
||||
templateView.setEntryInfo(entryInfo)
|
||||
assignAttachments(entryInfo.attachments, StreamDirection.UPLOAD) { attachment ->
|
||||
removeAttachment(EntryAttachmentState(attachment, StreamDirection.DOWNLOAD))
|
||||
mEntryEditViewModel.deleteAttachment(attachment)
|
||||
}
|
||||
setAttachments(entryInfo.attachments)
|
||||
}
|
||||
|
||||
mEntryEditViewModel.requestEntryInfoUpdate.observe(viewLifecycleOwner) {
|
||||
@@ -249,11 +251,6 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
drawFactory = mDatabase?.iconDrawableFactory
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
mEntryEditViewModel.updateEntryInfo(retrieveEntryInfo())
|
||||
}
|
||||
|
||||
override fun onDetach() {
|
||||
super.onDetach()
|
||||
|
||||
@@ -303,13 +300,15 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
return attachmentsAdapter?.itemsList?.map { it.attachment } ?: listOf()
|
||||
}
|
||||
|
||||
private fun assignAttachments(attachments: List<Attachment>,
|
||||
streamDirection: StreamDirection,
|
||||
onDeleteItem: (attachment: Attachment) -> Unit) {
|
||||
private fun setAttachments(attachments: List<Attachment>) {
|
||||
attachmentsContainerView.visibility = if (attachments.isEmpty()) View.GONE else View.VISIBLE
|
||||
attachmentsAdapter?.assignItems(attachments.map { EntryAttachmentState(it, streamDirection) })
|
||||
attachmentsAdapter?.assignItems(attachments.map {
|
||||
EntryAttachmentState(it, StreamDirection.UPLOAD)
|
||||
})
|
||||
attachmentsAdapter?.onDeleteButtonClickListener = { item ->
|
||||
onDeleteItem.invoke(item.attachment)
|
||||
val attachment = item.attachment
|
||||
removeAttachment(EntryAttachmentState(attachment, StreamDirection.DOWNLOAD))
|
||||
mEntryEditViewModel.deleteAttachment(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,8 +353,15 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
}, 250)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putParcelableArrayList(ATTACHMENTS_TAG, ArrayList(getAttachments()))
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = EntryEditFragment::class.java.name
|
||||
|
||||
private const val ATTACHMENTS_TAG = "ATTACHMENTS_TAG"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -601,6 +601,7 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
return
|
||||
} else {
|
||||
mTemplate = state.template
|
||||
mEntryInfo = state.entryInfo
|
||||
mTempDateTimeViewId = state.tempDateTimeViewId
|
||||
buildTemplateAndPopulateInfo()
|
||||
super.onRestoreInstanceState(state.superState)
|
||||
@@ -612,6 +613,7 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
val saveState = SavedState(superSave)
|
||||
populateEntryInfoWithViews()
|
||||
saveState.template = this.mTemplate
|
||||
saveState.entryInfo = this.mEntryInfo
|
||||
saveState.tempDateTimeViewId = this.mTempDateTimeViewId
|
||||
return saveState
|
||||
}
|
||||
@@ -621,6 +623,7 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
|
||||
internal class SavedState : BaseSavedState {
|
||||
var template: Template? = null
|
||||
var entryInfo: EntryInfo? = null
|
||||
var tempDateTimeViewId: Int? = null
|
||||
|
||||
constructor(superState: Parcelable?) : super(superState)
|
||||
@@ -628,6 +631,8 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
private constructor(parcel: Parcel) : super(parcel) {
|
||||
template = parcel.readParcelable(Template::class.java.classLoader)
|
||||
?: template
|
||||
entryInfo = parcel.readParcelable(EntryInfo::class.java.classLoader)
|
||||
?: entryInfo
|
||||
val dateTimeViewId = parcel.readInt()
|
||||
if (dateTimeViewId != -1)
|
||||
tempDateTimeViewId = dateTimeViewId
|
||||
@@ -636,6 +641,7 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
override fun writeToParcel(out: Parcel, flags: Int) {
|
||||
super.writeToParcel(out, flags)
|
||||
out.writeParcelable(template, flags)
|
||||
out.writeParcelable(entryInfo, flags)
|
||||
out.writeInt(tempDateTimeViewId ?: -1)
|
||||
}
|
||||
|
||||
|
||||
@@ -86,12 +86,6 @@ class EntryEditViewModel: ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateEntryInfo(entryInfo: EntryInfo) {
|
||||
internalUpdateEntryInfo(entryInfo) {
|
||||
_entryInfoLoaded.value = it
|
||||
}
|
||||
}
|
||||
|
||||
fun saveEntryInfo(entryInfo: EntryInfo) {
|
||||
internalUpdateEntryInfo(entryInfo) {
|
||||
_onEntryInfoSaved.value = EntryInfoTempAttachments(it, mTempAttachments)
|
||||
@@ -99,7 +93,7 @@ class EntryEditViewModel: ViewModel() {
|
||||
}
|
||||
|
||||
private fun internalUpdateEntryInfo(entryInfo: EntryInfo,
|
||||
actionOnFinish: (entryInfo: EntryInfo) -> Unit) {
|
||||
actionOnFinish: ((entryInfo: EntryInfo) -> Unit)? = null) {
|
||||
IOActionTask(
|
||||
{
|
||||
// Do not save entry in upload progression
|
||||
@@ -124,7 +118,7 @@ class EntryEditViewModel: ViewModel() {
|
||||
},
|
||||
{
|
||||
if (it != null)
|
||||
actionOnFinish.invoke(it)
|
||||
actionOnFinish?.invoke(it)
|
||||
}
|
||||
).execute()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user