Fix focus and orientation change

This commit is contained in:
J-Jamet committed 2021-06-15 13:41:32 +02:00
1 parent 37cbb18626
commit e9aa8609f1
3 files changed
+21 -3

No files matched your search

@@ -176,7 +176,7 @@ class EntryEditActivity : LockingActivity(),
mEntryTemplate = mEntry?.let {
mDatabase?.getTemplate(it)
} ?: Template.STANDARD
mEntryEditViewModel.assignTemplate(mEntryTemplate)
mEntryEditViewModel.loadTemplate(mEntryTemplate)
// Decode the entry
mEntry?.let {
@@ -1,5 +1,6 @@
package com.kunzisoft.keepass.view
import android.app.Activity
import android.content.Context
import android.os.Build
import android.os.Parcel
@@ -10,6 +11,7 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.annotation.IdRes
@@ -85,8 +87,16 @@ class TemplateView @JvmOverloads constructor(context: Context,
var populateIconMethod: ((ImageView, IconImage) -> Unit)? = null
fun setTemplate(template: Template?) {
mTemplate = template
buildTemplateAndPopulateInfo()
if (mTemplate != template) {
mTemplate = template
if (mEntryInfo != null) {
populateEntryInfoWithViews()
}
buildTemplateAndPopulateInfo()
clearFocus()
(context.getSystemService(Activity.INPUT_METHOD_SERVICE) as? InputMethodManager?)
?.hideSoftInputFromWindow(windowToken, 0)
}
}
fun buildTemplate() {
@@ -29,6 +29,7 @@ class EntryEditViewModel: ViewModel() {
val onEntryInfoSaved : LiveData<EntryInfoTempAttachments> get() = _onEntryInfoSaved
private val _onEntryInfoSaved = SingleLiveEvent<EntryInfoTempAttachments>()
private var mTemplateLoaded = false
val onTemplateChanged : LiveData<Template> get() = _onTemplateChanged
private val _onTemplateChanged = SingleLiveEvent<Template>()
@@ -123,6 +124,13 @@ class EntryEditViewModel: ViewModel() {
).execute()
}
fun loadTemplate(template: Template) {
if (!mTemplateLoaded) {
mTemplateLoaded = true
_onTemplateChanged.value = template
}
}
fun assignTemplate(template: Template) {
if (_onTemplateChanged.value != template)
_onTemplateChanged.value = template