mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 00:02:27 -08:00
fix: Better isTemplate and EntryLoaded implementation
This commit is contained in:
2 files changed
+17
-21
No files matched your search
@@ -129,8 +129,6 @@ class EntryEditActivity : DatabaseLockActivity(),
|
||||
private var loadingView: ProgressBar? = null
|
||||
|
||||
private val mEntryEditViewModel: EntryEditViewModel by viewModels()
|
||||
private var mIsTemplate: Boolean = false
|
||||
private var mEntryLoaded: Boolean = false
|
||||
private var mTemplatesSelectorAdapter: TemplatesSelectorAdapter? = null
|
||||
|
||||
private val mColorPickerViewModel: ColorPickerViewModel by viewModels()
|
||||
@@ -251,7 +249,6 @@ class EntryEditActivity : DatabaseLockActivity(),
|
||||
mEntryEditViewModel.templatesEntry.observe(this) { templatesEntry ->
|
||||
if (templatesEntry != null) {
|
||||
// Change template dynamically
|
||||
this.mIsTemplate = templatesEntry.isTemplate
|
||||
templatesEntry.templates.let { templates ->
|
||||
templateSelectorSpinner?.apply {
|
||||
// Build template selector
|
||||
@@ -283,9 +280,7 @@ class EntryEditActivity : DatabaseLockActivity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loadingView?.hideByFading()
|
||||
mEntryLoaded = true
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
@@ -683,7 +678,7 @@ class EntryEditActivity : DatabaseLockActivity(),
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
super.onCreateOptionsMenu(menu)
|
||||
if (mEntryLoaded) {
|
||||
if (mEntryEditViewModel.entryLoaded) {
|
||||
menuInflater.inflate(R.menu.entry_edit, menu)
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
performedNextEducation()
|
||||
@@ -698,12 +693,11 @@ class EntryEditActivity : DatabaseLockActivity(),
|
||||
isVisible = isEnabled
|
||||
}
|
||||
menu?.findItem(R.id.menu_add_attachment)?.apply {
|
||||
isEnabled = !mIsTemplate
|
||||
isEnabled = !mEntryEditViewModel.isTemplate
|
||||
isVisible = isEnabled
|
||||
}
|
||||
menu?.findItem(R.id.menu_add_otp)?.apply {
|
||||
isEnabled = mAllowOTP
|
||||
&& !mIsTemplate
|
||||
isEnabled = mAllowOTP && !mEntryEditViewModel.isTemplate
|
||||
isVisible = isEnabled
|
||||
}
|
||||
return super.onPrepareOptionsMenu(menu)
|
||||
|
||||
@@ -33,7 +33,8 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
private var mRegisterInfo: RegisterInfo? = null
|
||||
private var mParent: Group? = null
|
||||
private var mEntry: Entry? = null
|
||||
private var mIsTemplate: Boolean = false
|
||||
var isTemplate: Boolean = false
|
||||
private set
|
||||
private val mTempAttachments = mutableListOf<EntryAttachmentState>()
|
||||
|
||||
// To show dialog only one time
|
||||
@@ -84,6 +85,9 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
private val mEntryEditState = MutableStateFlow<EntryEditState>(EntryEditState.Loading)
|
||||
val entryEditState: StateFlow<EntryEditState> = mEntryEditState
|
||||
|
||||
val entryLoaded: Boolean
|
||||
get() = templatesEntry.value != null
|
||||
|
||||
fun loadTemplateEntry(database: ContextualDatabase?) {
|
||||
loadTemplateEntry(database, mEntryId, mParentId, mRegisterInfo)
|
||||
}
|
||||
@@ -112,11 +116,11 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
entry.parent = database.rootGroup
|
||||
}
|
||||
// Define if current entry is a template (in direct template group)
|
||||
mIsTemplate = database.entryIsTemplate(mEntry)
|
||||
isTemplate = database.entryIsTemplate(mEntry)
|
||||
decodeTemplateEntry(
|
||||
database,
|
||||
entry,
|
||||
mIsTemplate,
|
||||
isTemplate,
|
||||
registerInfo
|
||||
)
|
||||
}
|
||||
@@ -155,11 +159,11 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
// Useful to recognize child state (ie: entry is a template)
|
||||
parent = parentGroup
|
||||
}
|
||||
mIsTemplate = database.entryIsTemplate(mEntry)
|
||||
isTemplate = database.entryIsTemplate(mEntry)
|
||||
decodeTemplateEntry(
|
||||
database,
|
||||
mEntry,
|
||||
mIsTemplate,
|
||||
isTemplate,
|
||||
registerInfo
|
||||
)
|
||||
}
|
||||
@@ -198,12 +202,11 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
}
|
||||
}
|
||||
return TemplatesEntry(
|
||||
onTemplateChanged.value,
|
||||
isTemplate,
|
||||
templates,
|
||||
entryTemplate,
|
||||
entryInfo,
|
||||
overwrittenData
|
||||
template = onTemplateChanged.value,
|
||||
templates = templates,
|
||||
defaultTemplate = entryTemplate,
|
||||
entryInfo = entryInfo,
|
||||
overwrittenData = overwrittenData
|
||||
)
|
||||
}
|
||||
|
||||
@@ -364,7 +367,6 @@ class EntryEditViewModel: NodeEditViewModel() {
|
||||
|
||||
data class TemplatesEntry(
|
||||
val template: Template?,
|
||||
val isTemplate: Boolean,
|
||||
val templates: List<Template>,
|
||||
val defaultTemplate: Template,
|
||||
val entryInfo: EntryInfo?,
|
||||
|
||||
Reference in new issue
Block a user