From 14371ecf9495e268454f19eef12fdc674e2b2a0f Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Tue, 1 Sep 2020 19:12:25 +0200 Subject: [PATCH] Educational hint for attachment --- .../keepass/activities/EntryEditActivity.kt | 30 +++++++++++----- .../kunzisoft/keepass/education/Education.kt | 14 +++++++- .../education/EntryEditActivityEducation.kt | 35 ++++++++++++++++++- app/src/main/res/values/donottranslate.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 5 files changed, 73 insertions(+), 10 deletions(-) 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 eb6d21d5f..6e521dee7 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.kt @@ -589,8 +589,8 @@ class EntryEditActivity : LockingActivity(), if (!generatePasswordEducationPerformed) { val addNewFieldView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_field) val addNewFieldEducationPerformed = mNewEntry != null - && mNewEntry!!.allowCustomFields() && mNewEntry!!.customFields.isEmpty() - && addNewFieldView != null && addNewFieldView.visibility == View.VISIBLE + && mNewEntry!!.allowCustomFields() && addNewFieldView != null + && addNewFieldView.visibility == View.VISIBLE && entryEditActivityEducation.checkAndPerformedEntryNewFieldEducation( addNewFieldView, { @@ -601,13 +601,27 @@ class EntryEditActivity : LockingActivity(), } ) if (!addNewFieldEducationPerformed) { - val setupOtpView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_otp) - setupOtpView != null && setupOtpView.visibility == View.VISIBLE - && entryEditActivityEducation.checkAndPerformedSetUpOTPEducation( - setupOtpView, + val attachmentView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_attachment) + val addAttachmentEducationPerformed = attachmentView != null && attachmentView.visibility == View.VISIBLE + && entryEditActivityEducation.checkAndPerformedAttachmentEducation( + attachmentView, { - setupOTP() - }) + mSelectFileHelper?.selectFileOnClickViewListener?.onClick(attachmentView) + }, + { + performedNextEducation(entryEditActivityEducation) + } + ) + if (!addAttachmentEducationPerformed) { + val setupOtpView: View? = entryEditAddToolBar?.findViewById(R.id.menu_add_otp) + setupOtpView != null && setupOtpView.visibility == View.VISIBLE + && entryEditActivityEducation.checkAndPerformedSetUpOTPEducation( + setupOtpView, + { + setupOTP() + } + ) + } } } } diff --git a/app/src/main/java/com/kunzisoft/keepass/education/Education.kt b/app/src/main/java/com/kunzisoft/keepass/education/Education.kt index 4de51a2c6..eb8b47ad1 100644 --- a/app/src/main/java/com/kunzisoft/keepass/education/Education.kt +++ b/app/src/main/java/com/kunzisoft/keepass/education/Education.kt @@ -95,9 +95,9 @@ open class Education(val activity: Activity) { R.string.education_entry_edit_key, R.string.education_password_generator_key, R.string.education_entry_new_field_key, + R.string.education_add_attachment_key, R.string.education_setup_OTP_key) - /** * Get preferences bundle for education */ @@ -272,6 +272,18 @@ open class Education(val activity: Activity) { context.resources.getBoolean(R.bool.education_entry_new_field_default)) } + /** + * Determines whether the explanatory view of the new attachment button in an entry has already been displayed. + * + * @param context The context to open the SharedPreferences + * @return boolean value of education_add_attachment_key key + */ + fun isEducationAddAttachmentPerformed(context: Context): Boolean { + val prefs = getEducationSharedPreferences(context) + return prefs.getBoolean(context.getString(R.string.education_add_attachment_key), + context.resources.getBoolean(R.bool.education_add_attachment_default)) + } + /** * Determines whether the explanatory view to setup OTP has already been displayed. * diff --git a/app/src/main/java/com/kunzisoft/keepass/education/EntryEditActivityEducation.kt b/app/src/main/java/com/kunzisoft/keepass/education/EntryEditActivityEducation.kt index b7d1f01ef..f9eb011b5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/education/EntryEditActivityEducation.kt +++ b/app/src/main/java/com/kunzisoft/keepass/education/EntryEditActivityEducation.kt @@ -29,6 +29,10 @@ import com.kunzisoft.keepass.R class EntryEditActivityEducation(activity: Activity) : Education(activity) { + /** + * Check and display learning views + * Displays the explanation for the password generator + */ fun checkAndPerformedGeneratePasswordEducation(educationView: View, onEducationViewClick: ((TapTargetView?) -> Unit)? = null, onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean { @@ -56,7 +60,7 @@ class EntryEditActivityEducation(activity: Activity) /** * Check and display learning views - * Displays the explanation for the icon selection, the password generator and for a new field + * Displays the explanation to create a new field */ fun checkAndPerformedEntryNewFieldEducation(educationView: View, onEducationViewClick: ((TapTargetView?) -> Unit)? = null, @@ -83,6 +87,35 @@ class EntryEditActivityEducation(activity: Activity) R.string.education_entry_new_field_key) } + /** + * Check and display learning views + * Displays the explanation for to upload attachment + */ + fun checkAndPerformedAttachmentEducation(educationView: View, + onEducationViewClick: ((TapTargetView?) -> Unit)? = null, + onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean { + return checkAndPerformedEducation(!isEducationAddAttachmentPerformed(activity), + TapTarget.forView(educationView, + activity.getString(R.string.education_add_attachment_title), + activity.getString(R.string.education_add_attachment_summary)) + .textColorInt(Color.WHITE) + .tintTarget(true) + .cancelable(true), + object : TapTargetView.Listener() { + override fun onTargetClick(view: TapTargetView) { + super.onTargetClick(view) + onEducationViewClick?.invoke(view) + } + + override fun onOuterCircleClick(view: TapTargetView?) { + super.onOuterCircleClick(view) + view?.dismiss(false) + onOuterViewClick?.invoke(view) + } + }, + R.string.education_add_attachment_key) + } + /** * Check and display learning views * Displays the explanation to setup OTP diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index e75382b0c..b7f2a0259 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -250,6 +250,8 @@ false education_entry_new_field_key false + education_add_attachment_key + false education_setup_OTP_key false education_screen_reclicked_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1285c09e3..ca5531c23 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -426,6 +426,8 @@ Generate a strong password to associate with your entry, easily define it according to the criteria of the form and don\'t forget secure password. Add custom fields Register an additional field, add a value and optionally protect it. + Add attachment + Upload an attachment to your entry to save important external data. Set up OTP Set up one-time password management (HOTP / TOTP) to generate a token requested for two-factor authentication (2FA). Unlock your database