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