mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix custom fields orientation change #337
This commit is contained in:
@@ -105,14 +105,12 @@ class EntryEditActivity : LockingHideActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the icon after an orientation change
|
// Create the new entry from the current one
|
||||||
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_NEW_ENTRY)) {
|
if (savedInstanceState == null
|
||||||
mNewEntry = savedInstanceState.getParcelable(KEY_NEW_ENTRY) as EntryVersioned
|
|| !savedInstanceState.containsKey(KEY_NEW_ENTRY)) {
|
||||||
} else {
|
|
||||||
mEntry?.let { entry ->
|
mEntry?.let { entry ->
|
||||||
// Create a copy to modify
|
// Create a copy to modify
|
||||||
mNewEntry = EntryVersioned(entry).also { newEntry ->
|
mNewEntry = EntryVersioned(entry).also { newEntry ->
|
||||||
|
|
||||||
// WARNING Remove the parent to keep memory with parcelable
|
// WARNING Remove the parent to keep memory with parcelable
|
||||||
newEntry.parent = null
|
newEntry.parent = null
|
||||||
}
|
}
|
||||||
@@ -123,7 +121,11 @@ class EntryEditActivity : LockingHideActivity(),
|
|||||||
// Parent is retrieve, it's a new entry to create
|
// Parent is retrieve, it's a new entry to create
|
||||||
intent.getParcelableExtra<PwNodeId<*>>(KEY_PARENT)?.let {
|
intent.getParcelableExtra<PwNodeId<*>>(KEY_PARENT)?.let {
|
||||||
mIsNew = true
|
mIsNew = true
|
||||||
mNewEntry = mDatabase?.createEntry()
|
// Create an empty new entry
|
||||||
|
if (savedInstanceState == null
|
||||||
|
|| !savedInstanceState.containsKey(KEY_NEW_ENTRY)) {
|
||||||
|
mNewEntry = mDatabase?.createEntry()
|
||||||
|
}
|
||||||
mParent = mDatabase?.getGroupById(it)
|
mParent = mDatabase?.getGroupById(it)
|
||||||
// Add the default icon
|
// Add the default icon
|
||||||
mDatabase?.drawFactory?.let { iconFactory ->
|
mDatabase?.drawFactory?.let { iconFactory ->
|
||||||
@@ -131,6 +133,12 @@ class EntryEditActivity : LockingHideActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve the new entry after an orientation change
|
||||||
|
if (savedInstanceState != null
|
||||||
|
&& savedInstanceState.containsKey(KEY_NEW_ENTRY)) {
|
||||||
|
mNewEntry = savedInstanceState.getParcelable(KEY_NEW_ENTRY)
|
||||||
|
}
|
||||||
|
|
||||||
// Close the activity if entry or parent can't be retrieve
|
// Close the activity if entry or parent can't be retrieve
|
||||||
if (mNewEntry == null || mParent == null) {
|
if (mNewEntry == null || mParent == null) {
|
||||||
finish()
|
finish()
|
||||||
@@ -342,7 +350,10 @@ class EntryEditActivity : LockingHideActivity(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
outState.putParcelable(KEY_NEW_ENTRY, mNewEntry)
|
mNewEntry?.let {
|
||||||
|
populateEntryWithViews(it)
|
||||||
|
outState.putParcelable(KEY_NEW_ENTRY, it)
|
||||||
|
}
|
||||||
|
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.kunzisoft.keepass.icons.IconDrawableFactory
|
|||||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||||
import com.kunzisoft.keepass.icons.assignDefaultDatabaseIcon
|
import com.kunzisoft.keepass.icons.assignDefaultDatabaseIcon
|
||||||
import com.kunzisoft.keepass.model.Field
|
import com.kunzisoft.keepass.model.Field
|
||||||
|
import java.util.HashMap
|
||||||
|
|
||||||
class EntryEditContentsView @JvmOverloads constructor(context: Context,
|
class EntryEditContentsView @JvmOverloads constructor(context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
@@ -167,11 +168,14 @@ class EntryEditContentsView @JvmOverloads constructor(context: Context,
|
|||||||
/**
|
/**
|
||||||
* Add a new view to fill in the information of the customized field
|
* Add a new view to fill in the information of the customized field
|
||||||
*/
|
*/
|
||||||
fun addNewCustomField(name: String = "", value:ProtectedString = ProtectedString(false, "")) {
|
fun addNewCustomField(name: String = "", value: ProtectedString = ProtectedString(false, "")) {
|
||||||
val entryEditCustomField = EntryEditCustomField(context)
|
val entryEditCustomField = EntryEditCustomField(context).apply {
|
||||||
entryEditCustomField.setData(name, value)
|
setData(name, value)
|
||||||
entryEditCustomField.setFontVisibility(fontInVisibility)
|
setFontVisibility(fontInVisibility)
|
||||||
entryExtraFieldsContainer.addView(entryEditCustomField)
|
}
|
||||||
|
entryExtraFieldsContainer.post {
|
||||||
|
entryExtraFieldsContainer.addView(entryEditCustomField)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user