Fix education hints #1192

This commit is contained in:
J-Jamet
2022-02-18 10:31:24 +01:00
parent fa09e2d21d
commit 10598ef5e5
10 changed files with 103 additions and 83 deletions

View File

@@ -5,6 +5,7 @@ KeePassDX(3.3.0)
* Search with regular expression #175 * Search with regular expression #175
* Merge from file and save as copy #1221 #1204 #840 * Merge from file and save as copy #1221 #1204 #840
* Fix custom data #1236 * Fix custom data #1236
* Fix education hints #1192
* New UI and fix styles * New UI and fix styles
* Add "Simple" and "Reply" themes * Add "Simple" and "Reply" themes

View File

@@ -91,6 +91,8 @@ class EntryActivity : DatabaseLockActivity() {
private val mEntryViewModel: EntryViewModel by viewModels() private val mEntryViewModel: EntryViewModel by viewModels()
private val mEntryActivityEducation = EntryActivityEducation(this)
private var mMainEntryId: NodeId<UUID>? = null private var mMainEntryId: NodeId<UUID>? = null
private var mHistoryPosition: Int = -1 private var mHistoryPosition: Int = -1
private var mEntryIsHistory: Boolean = false private var mEntryIsHistory: Boolean = false
@@ -379,11 +381,7 @@ class EntryActivity : DatabaseLockActivity() {
// Show education views // Show education views
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
performedNextEducation( performedNextEducation(menu)
EntryActivityEducation(
this
), menu
)
} }
} }
return true return true
@@ -409,31 +407,30 @@ class EntryActivity : DatabaseLockActivity() {
return super.onPrepareOptionsMenu(menu) return super.onPrepareOptionsMenu(menu)
} }
private fun performedNextEducation(entryActivityEducation: EntryActivityEducation, private fun performedNextEducation(menu: Menu) {
menu: Menu) {
val entryFragment = supportFragmentManager.findFragmentByTag(ENTRY_FRAGMENT_TAG) val entryFragment = supportFragmentManager.findFragmentByTag(ENTRY_FRAGMENT_TAG)
as? EntryFragment? as? EntryFragment?
val entryFieldCopyView: View? = entryFragment?.firstEntryFieldCopyView() val entryFieldCopyView: View? = entryFragment?.firstEntryFieldCopyView()
val entryCopyEducationPerformed = entryFieldCopyView != null val entryCopyEducationPerformed = entryFieldCopyView != null
&& entryActivityEducation.checkAndPerformedEntryCopyEducation( && mEntryActivityEducation.checkAndPerformedEntryCopyEducation(
entryFieldCopyView, entryFieldCopyView,
{ {
entryFragment.launchEntryCopyEducationAction() entryFragment.launchEntryCopyEducationAction()
}, },
{ {
performedNextEducation(entryActivityEducation, menu) performedNextEducation(menu)
}) })
if (!entryCopyEducationPerformed) { if (!entryCopyEducationPerformed) {
val menuEditView = toolbar?.findViewById<View>(R.id.menu_edit) val menuEditView = toolbar?.findViewById<View>(R.id.menu_edit)
// entryEditEducationPerformed // entryEditEducationPerformed
menuEditView != null && entryActivityEducation.checkAndPerformedEntryEditEducation( menuEditView != null && mEntryActivityEducation.checkAndPerformedEntryEditEducation(
menuEditView, menuEditView,
{ {
onOptionsItemSelected(menu.findItem(R.id.menu_edit)) onOptionsItemSelected(menu.findItem(R.id.menu_edit))
}, },
{ {
performedNextEducation(entryActivityEducation, menu) performedNextEducation(menu)
} }
) )
} }

View File

@@ -113,7 +113,7 @@ class EntryEditActivity : DatabaseLockActivity(),
private var mExternalFileHelper: ExternalFileHelper? = null private var mExternalFileHelper: ExternalFileHelper? = null
private var mAttachmentFileBinderManager: AttachmentFileBinderManager? = null private var mAttachmentFileBinderManager: AttachmentFileBinderManager? = null
// Education // Education
private var entryEditActivityEducation: EntryEditActivityEducation? = null private var mEntryEditActivityEducation = EntryEditActivityEducation(this)
private var mIconSelectionActivityResultLauncher = IconPickerActivity.registerIconSelectionForResult(this) { icon -> private var mIconSelectionActivityResultLauncher = IconPickerActivity.registerIconSelectionForResult(this) { icon ->
mEntryEditViewModel.selectIcon(icon) mEntryEditViewModel.selectIcon(icon)
@@ -183,8 +183,6 @@ class EntryEditActivity : DatabaseLockActivity(),
} }
mAttachmentFileBinderManager = AttachmentFileBinderManager(this) mAttachmentFileBinderManager = AttachmentFileBinderManager(this)
// Verify the education views
entryEditActivityEducation = EntryEditActivityEducation(this)
// Lock button // Lock button
lockView?.setOnClickListener { lockAndExit() } lockView?.setOnClickListener { lockAndExit() }
@@ -538,10 +536,8 @@ class EntryEditActivity : DatabaseLockActivity(),
super.onCreateOptionsMenu(menu) super.onCreateOptionsMenu(menu)
if (mEntryLoaded) { if (mEntryLoaded) {
menuInflater.inflate(R.menu.entry_edit, menu) menuInflater.inflate(R.menu.entry_edit, menu)
entryEditActivityEducation?.let { Handler(Looper.getMainLooper()).post {
Handler(Looper.getMainLooper()).post { performedNextEducation()
performedNextEducation(it)
}
} }
} }
return true return true
@@ -568,19 +564,19 @@ class EntryEditActivity : DatabaseLockActivity(),
return super.onPrepareOptionsMenu(menu) return super.onPrepareOptionsMenu(menu)
} }
private fun performedNextEducation(entryEditActivityEducation: EntryEditActivityEducation) { private fun performedNextEducation() {
val entryEditFragment = supportFragmentManager.findFragmentById(R.id.entry_edit_content) val entryEditFragment = supportFragmentManager.findFragmentById(R.id.entry_edit_content)
as? EntryEditFragment? as? EntryEditFragment?
val generatePasswordView = entryEditFragment?.getActionImageView() val generatePasswordView = entryEditFragment?.getActionImageView()
val generatePasswordEductionPerformed = generatePasswordView != null val generatePasswordEductionPerformed = generatePasswordView != null
&& entryEditActivityEducation.checkAndPerformedGeneratePasswordEducation( && mEntryEditActivityEducation.checkAndPerformedGeneratePasswordEducation(
generatePasswordView, generatePasswordView,
{ {
entryEditFragment.launchGeneratePasswordEductionAction() entryEditFragment.launchGeneratePasswordEductionAction()
}, },
{ {
performedNextEducation(entryEditActivityEducation) performedNextEducation()
} }
) )
@@ -589,33 +585,33 @@ class EntryEditActivity : DatabaseLockActivity(),
val addNewFieldEducationPerformed = mAllowCustomFields val addNewFieldEducationPerformed = mAllowCustomFields
&& addNewFieldView != null && addNewFieldView != null
&& addNewFieldView.isVisible && addNewFieldView.isVisible
&& entryEditActivityEducation.checkAndPerformedEntryNewFieldEducation( && mEntryEditActivityEducation.checkAndPerformedEntryNewFieldEducation(
addNewFieldView, addNewFieldView,
{ {
addNewCustomField() addNewCustomField()
}, },
{ {
performedNextEducation(entryEditActivityEducation) performedNextEducation()
} }
) )
if (!addNewFieldEducationPerformed) { if (!addNewFieldEducationPerformed) {
val attachmentView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_attachment) val attachmentView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_attachment)
val addAttachmentEducationPerformed = attachmentView != null val addAttachmentEducationPerformed = attachmentView != null
&& attachmentView.isVisible && attachmentView.isVisible
&& entryEditActivityEducation.checkAndPerformedAttachmentEducation( && mEntryEditActivityEducation.checkAndPerformedAttachmentEducation(
attachmentView, attachmentView,
{ {
addNewAttachment() addNewAttachment()
}, },
{ {
performedNextEducation(entryEditActivityEducation) performedNextEducation()
} }
) )
if (!addAttachmentEducationPerformed) { if (!addAttachmentEducationPerformed) {
val setupOtpView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_otp) val setupOtpView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_otp)
setupOtpView != null setupOtpView != null
&& setupOtpView.isVisible && setupOtpView.isVisible
&& entryEditActivityEducation.checkAndPerformedSetUpOTPEducation( && mEntryEditActivityEducation.checkAndPerformedSetUpOTPEducation(
setupOtpView, setupOtpView,
{ {
setupOtp() setupOtp()
@@ -662,8 +658,8 @@ class EntryEditActivity : DatabaseLockActivity(),
override fun acceptPassword(passwordField: Field) { override fun acceptPassword(passwordField: Field) {
mEntryEditViewModel.selectPassword(passwordField) mEntryEditViewModel.selectPassword(passwordField)
entryEditActivityEducation?.let { Handler(Looper.getMainLooper()).post {
Handler(Looper.getMainLooper()).post { performedNextEducation(it) } performedNextEducation()
} }
} }

View File

@@ -78,6 +78,8 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
private val databaseFilesViewModel: DatabaseFilesViewModel by viewModels() private val databaseFilesViewModel: DatabaseFilesViewModel by viewModels()
private val mFileDatabaseSelectActivityEducation = FileDatabaseSelectActivityEducation(this)
// Adapter to manage database history list // Adapter to manage database history list
private var mAdapterDatabaseHistory: FileDatabaseHistoryAdapter? = null private var mAdapterDatabaseHistory: FileDatabaseHistoryAdapter? = null
@@ -132,7 +134,7 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
Log.e(TAG, error) Log.e(TAG, error)
} }
} }
openDatabaseButtonView = findViewById(R.id.open_keyfile_button) openDatabaseButtonView = findViewById(R.id.open_database_button)
openDatabaseButtonView?.setOpenDocumentClickListener(mExternalFileHelper) openDatabaseButtonView?.setOpenDocumentClickListener(mExternalFileHelper)
// History list // History list
@@ -392,39 +394,40 @@ class FileDatabaseSelectActivity : DatabaseModeActivity(),
MenuUtil.defaultMenuInflater(menuInflater, menu) MenuUtil.defaultMenuInflater(menuInflater, menu)
} }
Handler(Looper.getMainLooper()).post { performedNextEducation(FileDatabaseSelectActivityEducation(this)) } Handler(Looper.getMainLooper()).post {
performedNextEducation()
}
return true return true
} }
private fun performedNextEducation(fileDatabaseSelectActivityEducation: FileDatabaseSelectActivityEducation) { private fun performedNextEducation() {
// If no recent files // If no recent files
val createDatabaseEducationPerformed = val createDatabaseEducationPerformed =
createDatabaseButtonView != null createDatabaseButtonView != null
&& createDatabaseButtonView!!.visibility == View.VISIBLE && createDatabaseButtonView!!.visibility == View.VISIBLE
&& mAdapterDatabaseHistory != null && mFileDatabaseSelectActivityEducation.checkAndPerformedCreateDatabaseEducation(
&& mAdapterDatabaseHistory!!.itemCount == 0
&& fileDatabaseSelectActivityEducation.checkAndPerformedCreateDatabaseEducation(
createDatabaseButtonView!!, createDatabaseButtonView!!,
{ {
createNewFile() createNewFile()
}, },
{ {
// But if the user cancel, it can also select a database // But if the user cancel, it can also select a database
performedNextEducation(fileDatabaseSelectActivityEducation) performedNextEducation()
}) })
if (!createDatabaseEducationPerformed) { if (!createDatabaseEducationPerformed) {
// selectDatabaseEducationPerformed // selectDatabaseEducationPerformed
openDatabaseButtonView != null openDatabaseButtonView != null
&& fileDatabaseSelectActivityEducation.checkAndPerformedSelectDatabaseEducation( && mFileDatabaseSelectActivityEducation.checkAndPerformedSelectDatabaseEducation(
openDatabaseButtonView!!, openDatabaseButtonView!!,
{ tapTargetView -> { tapTargetView ->
tapTargetView?.let { tapTargetView?.let {
mExternalFileHelper?.openDocument() mExternalFileHelper?.openDocument()
} }
}, },
{} {
)
})
} }
} }

View File

@@ -118,6 +118,8 @@ class GroupActivity : DatabaseLockActivity(),
private val mGroupViewModel: GroupViewModel by viewModels() private val mGroupViewModel: GroupViewModel by viewModels()
private val mGroupEditViewModel: GroupEditViewModel by viewModels() private val mGroupEditViewModel: GroupEditViewModel by viewModels()
private val mGroupActivityEducation = GroupActivityEducation(this)
private var mBreadcrumbAdapter: BreadcrumbAdapter? = null private var mBreadcrumbAdapter: BreadcrumbAdapter? = null
private var mSearchMenuItem: MenuItem? = null private var mSearchMenuItem: MenuItem? = null
@@ -1205,70 +1207,64 @@ class GroupActivity : DatabaseLockActivity(),
// Launch education screen // Launch education screen
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
performedNextEducation( performedNextEducation(menu)
GroupActivityEducation(this),
menu
)
} }
return true return true
} }
private fun performedNextEducation( private fun performedNextEducation(menu: Menu) {
groupActivityEducation: GroupActivityEducation,
menu: Menu
) {
// If no node, show education to add new one // If no node, show education to add new one
val addNodeButtonEducationPerformed = actionNodeMode == null val addNodeButtonEducationPerformed = actionNodeMode == null
&& addNodeButtonView?.addButtonView != null && addNodeButtonView?.addButtonView != null
&& addNodeButtonView!!.isEnable && addNodeButtonView!!.isEnable
&& groupActivityEducation.checkAndPerformedAddNodeButtonEducation( && mGroupActivityEducation.checkAndPerformedAddNodeButtonEducation(
addNodeButtonView?.addButtonView!!, addNodeButtonView?.addButtonView!!,
{ {
addNodeButtonView?.openButtonIfClose() addNodeButtonView?.openButtonIfClose()
}, },
{ {
performedNextEducation(groupActivityEducation, menu) performedNextEducation(menu)
} }
) )
if (!addNodeButtonEducationPerformed) { if (!addNodeButtonEducationPerformed) {
val searchMenuEducationPerformed = toolbar != null val searchMenuEducationPerformed = toolbar != null
&& toolbar!!.findViewById<View>(R.id.menu_search) != null && toolbar!!.findViewById<View>(R.id.menu_search) != null
&& groupActivityEducation.checkAndPerformedSearchMenuEducation( && mGroupActivityEducation.checkAndPerformedSearchMenuEducation(
toolbar!!.findViewById(R.id.menu_search), toolbar!!.findViewById(R.id.menu_search),
{ {
menu.findItem(R.id.menu_search).expandActionView() menu.findItem(R.id.menu_search).expandActionView()
}, },
{ {
performedNextEducation(groupActivityEducation, menu) performedNextEducation(menu)
}) })
if (!searchMenuEducationPerformed) { if (!searchMenuEducationPerformed) {
val sortMenuEducationPerformed = toolbar != null val sortMenuEducationPerformed = toolbar != null
&& toolbar!!.findViewById<View>(R.id.menu_sort) != null && toolbar!!.findViewById<View>(R.id.menu_sort) != null
&& groupActivityEducation.checkAndPerformedSortMenuEducation( && mGroupActivityEducation.checkAndPerformedSortMenuEducation(
toolbar!!.findViewById(R.id.menu_sort), toolbar!!.findViewById(R.id.menu_sort),
{ {
onOptionsItemSelected(menu.findItem(R.id.menu_sort)) onOptionsItemSelected(menu.findItem(R.id.menu_sort))
}, },
{ {
performedNextEducation(groupActivityEducation, menu) performedNextEducation(menu)
}) })
if (!sortMenuEducationPerformed) { if (!sortMenuEducationPerformed) {
// lockMenuEducationPerformed // lockMenuEducationPerformed
val lockButtonView = findViewById<View>(R.id.lock_button) val lockButtonView = findViewById<View>(R.id.lock_button)
lockButtonView != null lockButtonView != null
&& groupActivityEducation.checkAndPerformedLockMenuEducation( && mGroupActivityEducation.checkAndPerformedLockMenuEducation(
lockButtonView, lockButtonView,
{ {
lockAndExit() lockAndExit()
}, },
{ {
performedNextEducation(groupActivityEducation, menu) performedNextEducation(menu)
}) })
} }
} }

View File

@@ -88,6 +88,8 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
private val mDatabaseFileViewModel: DatabaseFileViewModel by viewModels() private val mDatabaseFileViewModel: DatabaseFileViewModel by viewModels()
private val mAdvancedUnlockViewModel: AdvancedUnlockViewModel by viewModels() private val mAdvancedUnlockViewModel: AdvancedUnlockViewModel by viewModels()
private val mPasswordActivityEducation = PasswordActivityEducation(this)
private var mDefaultDatabase: Boolean = false private var mDefaultDatabase: Boolean = false
private var mDatabaseFileUri: Uri? = null private var mDatabaseFileUri: Uri? = null
@@ -553,26 +555,27 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
if (!performedEductionInProgress) { if (!performedEductionInProgress) {
performedEductionInProgress = true performedEductionInProgress = true
// Show education views // Show education views
Handler(Looper.getMainLooper()).post { performedNextEducation(PasswordActivityEducation(this), menu) } Handler(Looper.getMainLooper()).post {
performedNextEducation(menu)
}
} }
} }
private fun performedNextEducation(passwordActivityEducation: PasswordActivityEducation, private fun performedNextEducation(menu: Menu) {
menu: Menu) {
val educationToolbar = toolbar val educationToolbar = toolbar
val unlockEducationPerformed = educationToolbar != null val unlockEducationPerformed = educationToolbar != null
&& passwordActivityEducation.checkAndPerformedUnlockEducation( && mPasswordActivityEducation.checkAndPerformedUnlockEducation(
educationToolbar, educationToolbar,
{ {
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}, },
{ {
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}) })
if (!unlockEducationPerformed) { if (!unlockEducationPerformed) {
val readOnlyEducationPerformed = val readOnlyEducationPerformed =
educationToolbar?.findViewById<View>(R.id.menu_open_file_read_mode_key) != null educationToolbar?.findViewById<View>(R.id.menu_open_file_read_mode_key) != null
&& passwordActivityEducation.checkAndPerformedReadOnlyEducation( && mPasswordActivityEducation.checkAndPerformedReadOnlyEducation(
educationToolbar.findViewById(R.id.menu_open_file_read_mode_key), educationToolbar.findViewById(R.id.menu_open_file_read_mode_key),
{ {
try { try {
@@ -580,19 +583,19 @@ class MainCredentialActivity : DatabaseModeActivity(), AdvancedUnlockFragment.Bu
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Unable to find read mode menu") Log.e(TAG, "Unable to find read mode menu")
} }
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}, },
{ {
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}) })
advancedUnlockFragment?.performEducation(passwordActivityEducation, advancedUnlockFragment?.performEducation(mPasswordActivityEducation,
readOnlyEducationPerformed, readOnlyEducationPerformed,
{ {
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}, },
{ {
performedNextEducation(passwordActivityEducation, menu) performedNextEducation(menu)
}) })
} }
} }

View File

@@ -31,6 +31,7 @@ import com.kunzisoft.keepass.R
open class Education(val activity: Activity) { open class Education(val activity: Activity) {
private var mOneEducationHintOpen = false
/** /**
* Utility method to save preference after an education action * Utility method to save preference after an education action
*/ */
@@ -39,15 +40,36 @@ open class Education(val activity: Activity) {
listener: TapTargetView.Listener, listener: TapTargetView.Listener,
saveEducationStringId: Int): Boolean { saveEducationStringId: Int): Boolean {
var doEducation = false var doEducation = false
if (isEducationScreensEnabled()) { if (isEducationScreensEnabled()
if (!isEducationAlreadyPerformed) { && !mOneEducationHintOpen
try { && !isEducationAlreadyPerformed) {
TapTargetView.showFor(activity, tapTarget, listener) try {
saveEducationPreference(activity, saveEducationStringId) TapTargetView.showFor(activity, tapTarget, object : TapTargetView.Listener() {
doEducation = true override fun onTargetClick(view: TapTargetView) {
} catch (e: Exception) { mOneEducationHintOpen = false
Log.w(Education::class.java.name, "Can't performed education " + e.message) saveEducationPreference(activity, saveEducationStringId)
} super.onTargetClick(view)
listener.onTargetClick(view)
}
override fun onOuterCircleClick(view: TapTargetView?) {
mOneEducationHintOpen = false
saveEducationPreference(activity, saveEducationStringId)
super.onOuterCircleClick(view)
listener.onOuterCircleClick(view)
view?.dismiss(false)
}
override fun onTargetCancel(view: TapTargetView?) {
mOneEducationHintOpen = false
saveEducationPreference(activity, saveEducationStringId)
super.onTargetCancel(view)
}
})
mOneEducationHintOpen = true
doEducation = true
} catch (e: Exception) {
Log.w(Education::class.java.name, "Can't performed education " + e.message)
} }
} }
return doEducation return doEducation

View File

@@ -158,11 +158,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_gravity="top" android:layout_gravity="top"
app:layout_constraintBottom_toTopOf="@+id/open_keyfile_button" app:layout_constraintBottom_toTopOf="@+id/open_database_button"
android:background="?attr/colorPrimaryDark"/> android:background="?attr/colorPrimaryDark"/>
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/open_keyfile_button" android:id="@+id/open_database_button"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/select_database_file" android:text="@string/select_database_file"

View File

@@ -4,5 +4,6 @@
* Search with regular expression #175 * Search with regular expression #175
* Merge from file and save as copy #1221 #1204 #840 * Merge from file and save as copy #1221 #1204 #840
* Fix custom data #1236 * Fix custom data #1236
* Fix education hints #1192
* New UI and fix styles * New UI and fix styles
* Add "Simple" and "Reply" themes * Add "Simple" and "Reply" themes

View File

@@ -4,5 +4,6 @@
* Recherche avec expression régulière #175 * Recherche avec expression régulière #175
* Fusion depuis un fichier et sauvegarde de copie #1221 #1204 #840 * Fusion depuis un fichier et sauvegarde de copie #1221 #1204 #840
* Correction des données customisées #1236 * Correction des données customisées #1236
* Correction de écrans d'éducation #1192
* Nouvelle interface utilisateur et correction des styles * Nouvelle interface utilisateur et correction des styles
* Ajout des thèmes "Simple" et "Réponse" * Ajout des thèmes "Simple" et "Réponse"