mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add password generator education
This commit is contained in:
@@ -37,11 +37,13 @@ import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.*
|
||||
import com.kunzisoft.keepass.activities.dialogs.FileTooBigDialogFragment.Companion.MAX_WARNING_BINARY_FILE
|
||||
import com.kunzisoft.keepass.activities.fragments.EntryEditFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.EntrySelectionHelper
|
||||
import com.kunzisoft.keepass.activities.helpers.ExternalFileHelper
|
||||
import com.kunzisoft.keepass.activities.lock.LockingActivity
|
||||
@@ -569,9 +571,12 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
fun performedNextEducation(entryEditActivityEducation: EntryEditActivityEducation) {
|
||||
/*
|
||||
TODO Fragment
|
||||
if (entryEditFragment?.generatePasswordEducationPerformed(entryEditActivityEducation) != true) {
|
||||
|
||||
val generatePasswordEductionPerformed = (supportFragmentManager.findFragmentById(R.id.entry_edit_content)
|
||||
as? EntryEditFragment?)?.getGeneratePasswordEductionPerformed(entryEditActivityEducation) {
|
||||
performedNextEducation(entryEditActivityEducation)
|
||||
} ?: false
|
||||
if (!generatePasswordEductionPerformed) {
|
||||
val addNewFieldView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_field)
|
||||
val addNewFieldEducationPerformed = mDatabase?.allowEntryCustomFields() == true
|
||||
&& addNewFieldView != null
|
||||
@@ -611,7 +616,6 @@ class EntryEditActivity : LockingActivity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
|
||||
@@ -139,7 +139,7 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
}
|
||||
|
||||
mEntryEditViewModel.onPasswordSelected.observe(viewLifecycleOwner) { passwordField ->
|
||||
templateView.setPasswordValue(passwordField)
|
||||
templateView.setPasswordField(passwordField)
|
||||
}
|
||||
|
||||
mEntryEditViewModel.onDateSelected.observe(viewLifecycleOwner) { viewModelDate ->
|
||||
@@ -263,34 +263,6 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
return entryInfo
|
||||
}
|
||||
|
||||
fun generatePasswordEducationPerformed(entryEditActivityEducation: EntryEditActivityEducation): Boolean {
|
||||
/* TODO
|
||||
val generatePasswordView = templateContainerView
|
||||
.findViewWithTag<EntryEditFieldView?>(FIELD_PASSWORD_TAG)
|
||||
?.getActionImageView()
|
||||
return if (generatePasswordView != null) {
|
||||
entryEditActivityEducation.checkAndPerformedGeneratePasswordEducation(
|
||||
generatePasswordView,
|
||||
{
|
||||
GeneratePasswordDialogFragment
|
||||
.getInstance(Field(LABEL_PASSWORD, ProtectedString(true, mEntryInfo.password)))
|
||||
.show(parentFragmentManager, "PasswordGeneratorFragment")
|
||||
},
|
||||
{
|
||||
try {
|
||||
(activity as? EntryEditActivity?)
|
||||
?.performedNextEducation(entryEditActivityEducation)
|
||||
} catch (ignore: Exception) {
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
*/
|
||||
return false
|
||||
}
|
||||
|
||||
/* -------------
|
||||
* Attachments
|
||||
* -------------
|
||||
@@ -358,6 +330,21 @@ class EntryEditFragment: DatabaseFragment() {
|
||||
outState.putParcelableArrayList(ATTACHMENTS_TAG, ArrayList(getAttachments()))
|
||||
}
|
||||
|
||||
fun getGeneratePasswordEductionPerformed(entryEditActivityEducation: EntryEditActivityEducation,
|
||||
actionNextEducation: () -> Unit): Boolean {
|
||||
val generatePasswordView = templateView.getActionImageView()
|
||||
return generatePasswordView != null
|
||||
&& entryEditActivityEducation.checkAndPerformedGeneratePasswordEducation(
|
||||
generatePasswordView,
|
||||
{
|
||||
mEntryEditViewModel.requestPasswordSelection(templateView.getPasswordField())
|
||||
},
|
||||
{
|
||||
actionNextEducation.invoke()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = EntryEditFragment::class.java.name
|
||||
|
||||
|
||||
@@ -273,6 +273,10 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
}
|
||||
}
|
||||
|
||||
fun getActionImageView(): View? {
|
||||
return findViewWithTag<EntryEditFieldView?>(FIELD_PASSWORD_TAG)?.getActionImageView()
|
||||
}
|
||||
|
||||
fun setFontInVisibility(fontInVisibility: Boolean) {
|
||||
this.mFontInVisibility = fontInVisibility
|
||||
}
|
||||
@@ -286,13 +290,18 @@ class TemplateView @JvmOverloads constructor(context: Context,
|
||||
populateIconMethod?.invoke(entryIconView, iconImage)
|
||||
}
|
||||
|
||||
fun setPasswordValue(passwordField: Field) {
|
||||
fun setPasswordField(passwordField: Field) {
|
||||
val passwordView = getFieldViewById(passwordField.name.hashCode())
|
||||
if (passwordView is EntryEditFieldView?) {
|
||||
passwordView?.value = passwordField.protectedValue.stringValue
|
||||
}
|
||||
}
|
||||
|
||||
fun getPasswordField(): Field {
|
||||
val passwordView: EntryEditFieldView? = templateContainerView.findViewWithTag(FIELD_PASSWORD_TAG)
|
||||
return Field(TemplateField.LABEL_PASSWORD, ProtectedString(true, passwordView?.value ?: ""))
|
||||
}
|
||||
|
||||
fun setCurrentDateTimeValue(date: Date) {
|
||||
// Save the date
|
||||
setCurrentDateTimeSelection { instant ->
|
||||
|
||||
Reference in New Issue
Block a user