fix: view null exception

This commit is contained in:
J-Jamet 2024-12-08 17:07:46 +01:00
parent 113601d09a
commit aed49e19e8

View file

@ -18,8 +18,14 @@ import com.kunzisoft.keepass.database.element.DateInstant
import com.kunzisoft.keepass.database.element.Field import com.kunzisoft.keepass.database.element.Field
import com.kunzisoft.keepass.database.element.icon.IconImage import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.security.ProtectedString import com.kunzisoft.keepass.database.element.security.ProtectedString
import com.kunzisoft.keepass.database.element.template.* import com.kunzisoft.keepass.database.element.template.Template
import com.kunzisoft.keepass.database.element.template.TemplateAttribute
import com.kunzisoft.keepass.database.element.template.TemplateAttributeAction
import com.kunzisoft.keepass.database.element.template.TemplateAttributeOption
import com.kunzisoft.keepass.database.element.template.TemplateAttributeType
import com.kunzisoft.keepass.database.element.template.TemplateEngine
import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.addTemplateDecorator import com.kunzisoft.keepass.database.element.template.TemplateEngine.Companion.addTemplateDecorator
import com.kunzisoft.keepass.database.element.template.TemplateField
import com.kunzisoft.keepass.model.EntryInfo import com.kunzisoft.keepass.model.EntryInfo
import com.kunzisoft.keepass.otp.OtpElement import com.kunzisoft.keepass.otp.OtpElement
import com.kunzisoft.keepass.otp.OtpEntryFields import com.kunzisoft.keepass.otp.OtpEntryFields
@ -608,9 +614,8 @@ abstract class TemplateAbstractView<
getViewFieldByName(oldField.name)?.view?.let { viewToReplace -> getViewFieldByName(oldField.name)?.view?.let { viewToReplace ->
val oldValue = getCustomField(oldField.name).protectedValue.toString() val oldValue = getCustomField(oldField.name).protectedValue.toString()
val parentGroup = viewToReplace.parent as ViewGroup val parentGroup = viewToReplace.parent as? ViewGroup?
val indexInParent = parentGroup.indexOfChild(viewToReplace) parentGroup?.removeView(viewToReplace)
parentGroup.removeView(viewToReplace)
val newCustomFieldWithValue = if (keepOldValue) val newCustomFieldWithValue = if (keepOldValue)
Field(newField.name, Field(newField.name,
@ -624,7 +629,9 @@ abstract class TemplateAbstractView<
val newCustomView = buildViewForCustomField(newCustomFieldWithValue) val newCustomView = buildViewForCustomField(newCustomFieldWithValue)
newCustomView?.let { newCustomView?.let {
parentGroup.addView(newCustomView, indexInParent) parentGroup?.indexOfChild(viewToReplace)?.let { indexInParent ->
parentGroup.addView(newCustomView, indexInParent)
}
mViewFields.add( mViewFields.add(
oldPosition, oldPosition,
ViewField( ViewField(