From e9fc9cbc2abe0ecd2441a6aa9baac7802430bd8d Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 15 Sep 2021 12:21:44 +0200 Subject: [PATCH] Capture cast exception --- .../keepass/view/TemplateAbstractView.kt | 63 ++++++++++--------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TemplateAbstractView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TemplateAbstractView.kt index 57ae43f0a..ce970154d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TemplateAbstractView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TemplateAbstractView.kt @@ -275,22 +275,26 @@ abstract class TemplateAbstractView< templateAttribute: TemplateAttribute, entryInfoValue: String, showEmptyFields: Boolean) { - var fieldView: TEntryFieldView? = findViewWithTag(fieldTag) - if (!showEmptyFields && entryInfoValue.isEmpty()) { - fieldView?.isFieldVisible = false - } else if (fieldView == null && entryInfoValue.isNotEmpty()) { - // Add new not referenced view if standard field not in template - fieldView = buildViewForNotReferencedField( - Field(templateAttribute.label, - ProtectedString(templateAttribute.protected, "")), - templateAttribute - ) as? TEntryFieldView? - fieldView?.let { - addNotReferencedView(it as View) + try { + var fieldView: TEntryFieldView? = findViewWithTag(fieldTag) + if (!showEmptyFields && entryInfoValue.isEmpty()) { + fieldView?.isFieldVisible = false + } else if (fieldView == null && entryInfoValue.isNotEmpty()) { + // Add new not referenced view if standard field not in template + fieldView = buildViewForNotReferencedField( + Field(templateAttribute.label, + ProtectedString(templateAttribute.protected, "")), + templateAttribute + ) as? TEntryFieldView? + fieldView?.let { + addNotReferencedView(it as View) + } } + fieldView?.value = entryInfoValue + fieldView?.applyFontVisibility(mFontInVisibility) + } catch(e: Exception) { + Log.e(TAG, "Unable to populate entry field view", e) } - fieldView?.value = entryInfoValue - fieldView?.applyFontVisibility(mFontInVisibility) } @Suppress("UNCHECKED_CAST") @@ -299,22 +303,25 @@ abstract class TemplateAbstractView< expires: Boolean, expiryTime: DateInstant, showEmptyFields: Boolean) { - - var fieldView: TDateTimeView? = findViewWithTag(fieldTag) - if (!showEmptyFields && !expires) { - fieldView?.isFieldVisible = false - } else if (fieldView == null && expires) { - fieldView = buildViewForNotReferencedField( - Field(templateAttribute.label, - ProtectedString(templateAttribute.protected, "")), - templateAttribute - ) as? TDateTimeView? - fieldView?.let { - addNotReferencedView(it as View) + try { + var fieldView: TDateTimeView? = findViewWithTag(fieldTag) + if (!showEmptyFields && !expires) { + fieldView?.isFieldVisible = false + } else if (fieldView == null && expires) { + fieldView = buildViewForNotReferencedField( + Field(templateAttribute.label, + ProtectedString(templateAttribute.protected, "")), + templateAttribute + ) as? TDateTimeView? + fieldView?.let { + addNotReferencedView(it as View) + } } + fieldView?.activation = expires + fieldView?.dateTime = expiryTime + } catch(e: Exception) { + Log.e(TAG, "Unable to populate date time view", e) } - fieldView?.activation = expires - fieldView?.dateTime = expiryTime } /**