diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt
index 8c4e3add4..8eeb418b2 100644
--- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt
@@ -38,6 +38,7 @@ import androidx.appcompat.app.AlertDialog
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible
import androidx.core.widget.NestedScrollView
+import androidx.lifecycle.lifecycleScope
import com.google.android.material.snackbar.Snackbar
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.activities.dialogs.*
@@ -218,30 +219,11 @@ class EntryEditActivity : LockingActivity(),
add(TemplateAttribute("Another password", TemplateAttributeType.INLINE, true, TemplateAttributeAction.PASSWORD_GENERATION))
})))
- templateSelectorSpinner = findViewById(R.id.entry_edit_template_selector)
- templateSelectorSpinner?.apply {
- adapter = TemplatesSelectorAdapter(this@EntryEditActivity, mDatabase, templates)
- onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
- override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
- val newTemplate = templates[position]
- entryEditFragment?.apply {
- if (getTemplate() != newTemplate) {
- assignTemplate(newTemplate)
- }
- }
- }
- override fun onNothingSelected(parent: AdapterView<*>?) {}
- }
- }
-
// Build fragment to manage entry modification
entryEditFragment = supportFragmentManager.findFragmentByTag(ENTRY_EDIT_FRAGMENT_TAG) as? EntryEditFragment?
if (entryEditFragment == null) {
entryEditFragment = EntryEditFragment.getInstance(tempEntryInfo)
}
- supportFragmentManager.beginTransaction()
- .replace(R.id.entry_edit_contents, entryEditFragment!!, ENTRY_EDIT_FRAGMENT_TAG)
- .commit()
entryEditFragment?.apply {
drawFactory = mDatabase?.iconDrawableFactory
onDateTimeClickListener = { dateInstant ->
@@ -269,6 +251,32 @@ class EntryEditActivity : LockingActivity(),
}
}
+ // To show Fragment asynchronously
+ lifecycleScope.launchWhenResumed {
+ entryEditFragment?.let { fragment ->
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.entry_edit_contents, fragment, ENTRY_EDIT_FRAGMENT_TAG)
+ .commit()
+ }
+ }
+
+ // Change template dynamically
+ templateSelectorSpinner = findViewById(R.id.entry_edit_template_selector)
+ templateSelectorSpinner?.apply {
+ adapter = TemplatesSelectorAdapter(this@EntryEditActivity, mDatabase, templates)
+ onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
+ override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
+ val newTemplate = templates[position]
+ entryEditFragment?.apply {
+ if (getTemplate() != newTemplate) {
+ assignTemplate(newTemplate)
+ }
+ }
+ }
+ override fun onNothingSelected(parent: AdapterView<*>?) {}
+ }
+ }
+
// Retrieve temp attachments in case of deletion
if (savedInstanceState?.containsKey(TEMP_ATTACHMENTS) == true) {
mTempAttachments = savedInstanceState.getParcelableArrayList(TEMP_ATTACHMENTS) ?: mTempAttachments
diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryEditFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryEditFragment.kt
index 04d5bea14..6e6c127dc 100644
--- a/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryEditFragment.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/activities/fragments/EntryEditFragment.kt
@@ -68,12 +68,13 @@ class EntryEditFragment : StylishFragment() {
private var mInflater: LayoutInflater? = null
+ private lateinit var rootView: View
private lateinit var entryIconView: ImageView
private lateinit var entryTitleView: EntryEditFieldView
private lateinit var templateContainerView: ViewGroup
private lateinit var customFieldsContainerView: SectionView
- private lateinit var attachmentsContainerView: View
+ private lateinit var attachmentsContainerView: ViewGroup
private lateinit var attachmentsListView: RecyclerView
private lateinit var attachmentsAdapter: EntryAttachmentsItemsAdapter
@@ -99,7 +100,7 @@ class EntryEditFragment : StylishFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
super.onCreateView(inflater, container, savedInstanceState)
- val rootView = inflater.cloneInContext(contextThemed)
+ rootView = inflater.cloneInContext(contextThemed)
.inflate(R.layout.fragment_entry_edit_contents, container, false)
mInflater = inflater
@@ -110,7 +111,6 @@ class EntryEditFragment : StylishFragment() {
entryIconView.setOnClickListener {
onIconClickListener?.invoke(mEntryInfo.icon)
}
-
entryTitleView = rootView.findViewById(R.id.entry_edit_title)
templateContainerView = rootView.findViewById(R.id.template_fields_container)
// To fix card view margin in KitKat-
@@ -145,7 +145,7 @@ class EntryEditFragment : StylishFragment() {
iconColor = taIconColor?.getColor(0, Color.WHITE) ?: Color.WHITE
taIconColor?.recycle()
- rootView?.resetAppTimeoutWhenViewFocusedOrChanged(requireContext())
+ rootView.resetAppTimeoutWhenViewFocusedOrChanged(requireContext())
// Retrieve the new entry after an orientation change
if (arguments?.containsKey(KEY_TEMP_ENTRY_INFO) == true)
@@ -167,6 +167,8 @@ class EntryEditFragment : StylishFragment() {
onRemoveAttachment?.invoke(attachment)
}
+ rootView.showByFading()
+
return rootView
}
@@ -219,6 +221,7 @@ class EntryEditFragment : StylishFragment() {
populateEntryWithViews()
this.mTemplate = template
populateViewsWithEntry()
+ rootView.showByFading()
}
private fun populateViewsWithEntry() {
diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt
index 6837a77d6..5b70aa49b 100644
--- a/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/adapters/TemplatesSelectorAdapter.kt
@@ -21,7 +21,7 @@ class TemplatesSelectorAdapter(context: Context,
private var mIconColor = Color.BLACK
init {
- val taIconColor = context.theme.obtainStyledAttributes(intArrayOf(R.attr.colorAccent))
+ val taIconColor = context.theme.obtainStyledAttributes(intArrayOf(R.attr.colorPrimary))
mIconColor = taIconColor.getColor(0, Color.BLACK)
taIconColor.recycle()
}
diff --git a/app/src/main/java/com/kunzisoft/keepass/view/SectionView.kt b/app/src/main/java/com/kunzisoft/keepass/view/SectionView.kt
index f39f7d3be..30b99d88b 100644
--- a/app/src/main/java/com/kunzisoft/keepass/view/SectionView.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/view/SectionView.kt
@@ -56,14 +56,7 @@ class SectionView @JvmOverloads constructor(context: Context,
override fun addView(child: View?) {
visibility = View.VISIBLE
- containerSectionView.apply {
- alpha = 0f
- addView(child)
- animate()
- .alpha(1f)
- .setDuration(200)
- .setListener(null)
- }
+ containerSectionView.addView(child)
}
fun removeViewById(@IdRes viewId: Int, onFinish: ((View) ->Unit)? = null) {
diff --git a/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt b/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt
index af8725ed2..8100d9136 100644
--- a/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt
+++ b/app/src/main/java/com/kunzisoft/keepass/view/ViewUtil.kt
@@ -158,6 +158,23 @@ fun View.expand(animate: Boolean = true,
}.start()
}
+fun View.hideByFading() {
+ alpha = 1f
+ animate()
+ .alpha(0f)
+ .setDuration(400)
+ .setListener(null)
+}
+
+fun View.showByFading() {
+ // Trick to keep the focus
+ alpha = 0.01f
+ animate()
+ .alpha(1f)
+ .setDuration(400)
+ .setListener(null)
+}
+
fun View.updateLockPaddingLeft() {
updatePadding(resources.getDimensionPixelSize(
if (PreferencesUtil.showLockDatabaseButton(context)) {
diff --git a/app/src/main/res/layout/fragment_entry_edit_contents.xml b/app/src/main/res/layout/fragment_entry_edit_contents.xml
index 06afb5901..e119f9484 100644
--- a/app/src/main/res/layout/fragment_entry_edit_contents.xml
+++ b/app/src/main/res/layout/fragment_entry_edit_contents.xml
@@ -26,7 +26,7 @@
android:layout_height="wrap_content">
diff --git a/app/src/main/res/layout/item_template.xml b/app/src/main/res/layout/item_template.xml
index 035d56a76..8ddd20c90 100644
--- a/app/src/main/res/layout/item_template.xml
+++ b/app/src/main/res/layout/item_template.xml
@@ -37,11 +37,12 @@
android:layout_marginLeft="12dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
+ android:src="@drawable/ic_new_field_white_24dp"
android:contentDescription="@string/content_description_entry_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:tint="?attr/colorAccent" />
+ app:tint="?attr/colorPrimary" />