diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java index de17b6600..27a02b63a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.java @@ -23,22 +23,20 @@ package com.kunzisoft.keepass.activities; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.v4.content.ContextCompat; +import android.os.Handler; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; -import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.getkeepsafe.taptargetview.TapTarget; -import com.getkeepsafe.taptargetview.TapTargetSequence; +import com.getkeepsafe.taptargetview.TapTargetView; import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.database.Database; @@ -70,7 +68,7 @@ public class EntryActivity extends LockingHideActivity { private ImageView titleIconView; private TextView titleView; private EntryContentsView entryContentsView; - private View editView; + private Toolbar toolbar; protected PwEntry mEntry; private boolean mShowPassword; @@ -93,7 +91,7 @@ public class EntryActivity extends LockingHideActivity { setContentView(R.layout.entry_view); - Toolbar toolbar = findViewById(R.id.toolbar); + toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); assert getSupportActionBar() != null; getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp); @@ -206,51 +204,55 @@ public class EntryActivity extends LockingHideActivity { mEntry.endToManageFieldReferences(); } firstLaunchOfActivity = false; - - checkAndPerformedEducation(); } - private void checkAndPerformedEducation() { - if (!PreferencesUtil.isEducationEntryPerformed(this)) { + private void checkAndPerformedEducation(Menu menu) { - TapTarget copyTapTarget = TapTarget.forView(findViewById(R.id.entry_user_name_action_image), - getString(R.string.education_field_copy_title), - getString(R.string.education_field_copy_summary)); - // Construct the drawable if not visible - if (!entryContentsView.isUserNamePresent()) { - Drawable copyDrawable = ContextCompat.getDrawable(this, R.drawable.ic_content_copy_black_24dp); - copyTapTarget = copyTapTarget.icon(copyDrawable); + if (entryContentsView != null && entryContentsView.isUserNamePresent() + && !PreferencesUtil.isEducationCopyUsernamePerformed(this)) { + TapTargetView.showFor(this, + TapTarget.forView(findViewById(R.id.entry_user_name_action_image), + getString(R.string.education_field_copy_title), + getString(R.string.education_field_copy_summary)) + .tintTarget(false) + .cancelable(true), + new TapTargetView.Listener() { + @Override + public void onTargetClick(TapTargetView view) { + super.onTargetClick(view); + clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(), + getString(R.string.copy_field, getString(R.string.entry_user_name))); + } + }); + PreferencesUtil.saveEducationPreference(this, + R.string.education_copy_username_key); + + } else if (!PreferencesUtil.isEducationEntryEditPerformed(this)) { + + try { + TapTargetView.showFor(this, + TapTarget.forToolbarMenuItem(toolbar, R.id.menu_edit, + getString(R.string.education_entry_edit_title), + getString(R.string.education_entry_edit_summary)) + .tintTarget(true) + .cancelable(true), + new TapTargetView.Listener() { + @Override + public void onTargetClick(TapTargetView view) { + super.onTargetClick(view); + MenuItem editItem = menu.findItem(R.id.menu_edit); + onOptionsItemSelected(editItem); + } + }); + PreferencesUtil.saveEducationPreference(this, + R.string.education_entry_edit_key); + } catch (Exception e) { + // If icon not visible + Log.w(TAG, "Can't performed education for entry's edition"); } - - new TapTargetSequence(this) - .target(copyTapTarget) - // TODO .targets(TapTarget.forView(editView, - // getString(R.string.education_entry_edit_title), - // getString(R.string.education_entry_edit_summary)) - // .tintTarget(false) - //) - .listener(new TapTargetSequence.Listener() { - @Override - public void onSequenceFinish() { - saveEducationPreference(); - } - - @Override - public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {} - - @Override - public void onSequenceCanceled(TapTarget lastTarget) {} - }).continueOnCancel(true).start(); } } - private void saveEducationPreference() { - SharedPreferences sharedPreferences = PreferencesUtil.getEducationSharedPreferences(this); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putBoolean(getString(R.string.education_entry_key), true); - editor.apply(); - } - private void populateTitle(Drawable drawIcon, String text) { titleIconView.setImageDrawable(drawIcon); titleView.setText(text); @@ -372,6 +374,9 @@ public class EntryActivity extends LockingHideActivity { } } } + + // Show education views + new Handler().post(() -> checkAndPerformedEducation(menu)); return true; } diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java index 2a968c5c9..9224deae4 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryEditActivity.java @@ -21,7 +21,6 @@ package com.kunzisoft.keepass.activities; import android.app.Activity; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.support.v7.widget.Toolbar; @@ -38,7 +37,7 @@ import android.widget.ScrollView; import android.widget.Toast; import com.getkeepsafe.taptargetview.TapTarget; -import com.getkeepsafe.taptargetview.TapTargetSequence; +import com.getkeepsafe.taptargetview.TapTargetView; import com.kunzisoft.keepass.R; import com.kunzisoft.keepass.app.App; import com.kunzisoft.keepass.database.Database; @@ -63,8 +62,6 @@ import com.kunzisoft.keepass.utils.Types; import com.kunzisoft.keepass.utils.Util; import com.kunzisoft.keepass.view.EntryEditCustomField; -import java.util.ArrayList; -import java.util.List; import java.util.UUID; public class EntryEditActivity extends LockingHideActivity @@ -180,130 +177,160 @@ public class EntryEditActivity extends LockingHideActivity // Generate password button generatePasswordView = findViewById(R.id.generate_button); generatePasswordView.setOnClickListener(v -> { - GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment(); - generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment"); + openPasswordGenerator(); }); // Save button saveView = findViewById(R.id.entry_save); saveView.setOnClickListener(v -> { - if (!validateBeforeSaving()) { - return; - } - mCallbackNewEntry = populateNewEntry(); - - OnFinish onFinish = new AfterSave(); - EntryEditActivity act = EntryEditActivity.this; - RunnableOnFinish task; - if ( mIsNew ) { - task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish); - } else { - task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); - } - ProgressTask pt = new ProgressTask(act, task, R.string.saving_database); - pt.run(); + saveEntry(); }); if (mEntry.allowExtraFields()) { addNewFieldView = findViewById(R.id.add_new_field); addNewFieldView.setVisibility(View.VISIBLE); - addNewFieldView.setOnClickListener(v -> { - EntryEditCustomField ees = new EntryEditCustomField(EntryEditActivity.this); - ees.setData("", new ProtectedString(false, "")); - entryExtraFieldsContainer.addView(ees); - - // Scroll bottom - scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN)); - }); + addNewFieldView.setOnClickListener(v -> addNewCustomField()); } + + // Verify the education views + checkAndPerformedEducation(); } - @Override - protected void onResume() { - super.onResume(); + /** + * Open the password generator fragment + */ + private void openPasswordGenerator() { + GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment(); + generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment"); + } - checkAndPerformedEducation(); + /** + * Add a new view to fill in the information of the customized field + */ + private void addNewCustomField() { + EntryEditCustomField ees = new EntryEditCustomField(EntryEditActivity.this); + ees.setData("", new ProtectedString(false, "")); + entryExtraFieldsContainer.addView(ees); + + // Scroll bottom + scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN)); + } + + /** + * Saves the new entry or update an existing entry in the database + */ + private void saveEntry() { + if (!validateBeforeSaving()) { + return; + } + mCallbackNewEntry = populateNewEntry(); + + OnFinish onFinish = new AfterSave(); + EntryEditActivity act = EntryEditActivity.this; + RunnableOnFinish task; + if ( mIsNew ) { + task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish); + } else { + task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish); + } + ProgressTask pt = new ProgressTask(act, task, R.string.saving_database); + pt.run(); } private void checkAndPerformedEducation() { - // For the first time show the tuto - if (!PreferencesUtil.isEducationEntryEditPerformed(this)) { - List tapTargets = new ArrayList<>(); + // TODO Show icon - TapTarget generatePasswordTapTarget = TapTarget.forView(generatePasswordView, - getString(R.string.education_generate_password_title), - getString(R.string.education_generate_password_summary)) - .tintTarget(false); - tapTargets.add(generatePasswordTapTarget); + if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) { + TapTargetView.showFor(this, + TapTarget.forView(generatePasswordView, + getString(R.string.education_generate_password_title), + getString(R.string.education_generate_password_summary)) + .tintTarget(false) + .cancelable(true), + new TapTargetView.Listener() { + @Override + public void onTargetClick(TapTargetView view) { + super.onTargetClick(view); + openPasswordGenerator(); + } + }); + PreferencesUtil.saveEducationPreference(this, + R.string.education_password_generator_key); + } - if (mEntry.allowExtraFields()) { - TapTarget newCustomFieldTapTarget = TapTarget.forView(addNewFieldView, - getString(R.string.education_entry_new_field_title), - getString(R.string.education_entry_new_field_summary)) - .tintTarget(false); - tapTargets.add(newCustomFieldTapTarget); - } - - TapTarget saveTapTarget = TapTarget.forView(saveView, - getString(R.string.education_entry_save_title), - getString(R.string.education_entry_save_summary)) - .tintTarget(false); - tapTargets.add(saveTapTarget); - - new TapTargetSequence(this) - .targets(tapTargets).listener(new TapTargetSequence.Listener() { - @Override - public void onSequenceFinish() { - saveEducationPreference(); - } - - @Override - public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {} - - @Override - public void onSequenceCanceled(TapTarget lastTarget) {} - }).continueOnCancel(true).start(); + else if (mEntry.allowExtraFields() + && !mEntry.containsCustomFields() + && !PreferencesUtil.isEducationEntryNewFieldPerformed(this)) { + TapTargetView.showFor(this, + TapTarget.forView(addNewFieldView, + getString(R.string.education_entry_new_field_title), + getString(R.string.education_entry_new_field_summary)) + .tintTarget(false) + .cancelable(true), + new TapTargetView.Listener() { + @Override + public void onTargetClick(TapTargetView view) { + super.onTargetClick(view); + addNewCustomField(); + } + }); + PreferencesUtil.saveEducationPreference(this, + R.string.education_entry_new_field_key); } } - private void saveEducationPreference() { - SharedPreferences sharedPreferences = PreferencesUtil.getEducationSharedPreferences(this); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putBoolean(getString(R.string.education_entry_edit_key), true); - editor.apply(); - } - - protected boolean validateBeforeSaving() { - // Require title - String title = entryTitleView.getText().toString(); - if ( title.length() == 0 ) { - Toast.makeText(this, R.string.error_title_required, Toast.LENGTH_LONG).show(); - return false; - } - - // Validate password - String pass = entryPasswordView.getText().toString(); - String conf = entryConfirmationPasswordView.getText().toString(); - if ( ! pass.equals(conf) ) { - Toast.makeText(this, R.string.error_pass_match, Toast.LENGTH_LONG).show(); - return false; - } + private class ErrorValidation { + static final int unknownMessage = -1; - // Validate extra fields + boolean isValidate = false; + int messageId = unknownMessage; + + void showValidationErrorIfNeeded() { + if (!isValidate && messageId != unknownMessage) + Toast.makeText(EntryEditActivity.this, messageId, Toast.LENGTH_LONG).show(); + } + } + + protected ErrorValidation validate() { + ErrorValidation errorValidation = new ErrorValidation(); + + // Require title + String title = entryTitleView.getText().toString(); + if ( title.length() == 0 ) { + errorValidation.messageId = R.string.error_title_required; + return errorValidation; + } + + // Validate password + String pass = entryPasswordView.getText().toString(); + String conf = entryConfirmationPasswordView.getText().toString(); + if ( ! pass.equals(conf) ) { + errorValidation.messageId = R.string.error_pass_match; + return errorValidation; + } + + // Validate extra fields if (mEntry.allowExtraFields()) { for (int i = 0; i < entryExtraFieldsContainer.getChildCount(); i++) { EntryEditCustomField entryEditCustomField = (EntryEditCustomField) entryExtraFieldsContainer.getChildAt(i); String key = entryEditCustomField.getLabel(); if (key == null || key.length() == 0) { - Toast.makeText(this, R.string.error_string_key, Toast.LENGTH_LONG).show(); - return false; + errorValidation.messageId = R.string.error_string_key; + return errorValidation; } } } - return true; + errorValidation.isValidate = true; + return errorValidation; + } + + protected boolean validateBeforeSaving() { + ErrorValidation errorValidation = validate(); + errorValidation.showValidationErrorIfNeeded(); + return errorValidation.isValidate; } protected PwEntry populateNewEntry() { @@ -423,6 +450,8 @@ public class EntryEditActivity extends LockingHideActivity String generatedPassword = bundle.getString(GeneratePasswordDialogFragment.KEY_PASSWORD_ID); entryPasswordView.setText(generatedPassword); entryConfirmationPasswordView.setText(generatedPassword); + + checkAndPerformedEducation(); } @Override diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java index 88cf95b9c..c8c7b366d 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/activities/GroupActivity.java @@ -290,22 +290,27 @@ public class GroupActivity extends ListNodesActivity // Else show the search education } else if (!PreferencesUtil.isEducationSearchPerformed(this)) { - TapTargetView.showFor(this, - TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search, - getString(R.string.education_search_title), - getString(R.string.education_search_summary)) - .tintTarget(true) - .cancelable(true), - new TapTargetView.Listener() { - @Override - public void onTargetClick(TapTargetView view) { - super.onTargetClick(view); - MenuItem searchItem = menu.findItem(R.id.menu_search); - searchItem.expandActionView(); - } - }); - PreferencesUtil.saveEducationPreference(this, - R.string.education_search_key); + try { + TapTargetView.showFor(this, + TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search, + getString(R.string.education_search_title), + getString(R.string.education_search_summary)) + .tintTarget(true) + .cancelable(true), + new TapTargetView.Listener() { + @Override + public void onTargetClick(TapTargetView view) { + super.onTargetClick(view); + MenuItem searchItem = menu.findItem(R.id.menu_search); + searchItem.expandActionView(); + } + }); + PreferencesUtil.saveEducationPreference(this, + R.string.education_search_key); + } catch (Exception e) { + // If icon not visible + Log.w(TAG, "Can't performed education for search"); + } // Else show the sort education } else if (!PreferencesUtil.isEducationSortPerformed(this)) { @@ -328,7 +333,6 @@ public class GroupActivity extends ListNodesActivity PreferencesUtil.saveEducationPreference(this, R.string.education_sort_key); } catch (Exception e) { - // If icon not visible Log.w(TAG, "Can't performed education for sort"); } @@ -353,7 +357,6 @@ public class GroupActivity extends ListNodesActivity PreferencesUtil.saveEducationPreference(this, R.string.education_lock_key); } catch (Exception e) { - // If icon not visible Log.w(TAG, "Can't performed education for lock"); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java index d1917f55d..218928c19 100644 --- a/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java +++ b/app/src/main/java/com/kunzisoft/keepass/password/PasswordActivity.java @@ -327,7 +327,7 @@ public class PasswordActivity extends StylishActivity } private void checkAndPerformedEducation(Bundle savedInstanceState) { - if (!PreferencesUtil.isEducationPasswordPerformed(this)) { + if (!PreferencesUtil.isEducationUnlockPerformed(this)) { List targets = new ArrayList<>(); @@ -352,7 +352,7 @@ public class PasswordActivity extends StylishActivity .targets(targets).continueOnCancel(true).start(); } - PreferencesUtil.saveEducationPreference(PasswordActivity.this, R.string.education_password_key); + PreferencesUtil.saveEducationPreference(PasswordActivity.this, R.string.education_unlock_key); } } diff --git a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.java b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.java index c423d1e7f..ddbfa1e33 100644 --- a/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.java +++ b/app/src/main/java/com/kunzisoft/keepass/settings/PreferencesUtil.java @@ -146,20 +146,21 @@ public class PreferencesUtil { } /** - * Education Preferences + * All preference keys associated with education */ - public static int[] educationResourceKeys = new int[] { R.string.education_create_db_key, R.string.education_select_db_key, R.string.education_open_link_db_key, + R.string.education_unlock_key, R.string.education_search_key, R.string.education_new_node_key, R.string.education_sort_key, R.string.education_lock_key, - R.string.education_entry_key, - R.string.education_password_key, - R.string.education_entry_edit_key + R.string.education_copy_username_key, + R.string.education_entry_edit_key, + R.string.education_password_generator_key, + R.string.education_entry_new_field_key }; public static void saveEducationPreference(Context context, int... educationKeys) { @@ -189,6 +190,12 @@ public class PreferencesUtil { context.getResources().getBoolean(R.bool.education_open_link_db_default)); } + public static boolean isEducationUnlockPerformed(Context context) { + SharedPreferences prefs = getEducationSharedPreferences(context); + return prefs.getBoolean(context.getString(R.string.education_unlock_key), + context.getResources().getBoolean(R.bool.education_unlock_default)); + } + public static boolean isEducationSearchPerformed(Context context) { SharedPreferences prefs = getEducationSharedPreferences(context); return prefs.getBoolean(context.getString(R.string.education_search_key), @@ -213,21 +220,27 @@ public class PreferencesUtil { context.getResources().getBoolean(R.bool.education_lock_default)); } - public static boolean isEducationEntryPerformed(Context context) { + public static boolean isEducationCopyUsernamePerformed(Context context) { SharedPreferences prefs = getEducationSharedPreferences(context); - return prefs.getBoolean(context.getString(R.string.education_entry_key), - context.getResources().getBoolean(R.bool.education_entry_default)); - } - - public static boolean isEducationPasswordPerformed(Context context) { - SharedPreferences prefs = getEducationSharedPreferences(context); - return prefs.getBoolean(context.getString(R.string.education_password_key), - context.getResources().getBoolean(R.bool.education_password_default)); + return prefs.getBoolean(context.getString(R.string.education_copy_username_key), + context.getResources().getBoolean(R.bool.education_copy_username_key)); } public static boolean isEducationEntryEditPerformed(Context context) { SharedPreferences prefs = getEducationSharedPreferences(context); return prefs.getBoolean(context.getString(R.string.education_entry_edit_key), - context.getResources().getBoolean(R.bool.education_entry_default)); + context.getResources().getBoolean(R.bool.education_entry_edit_default)); + } + + public static boolean isEducationPasswordGeneratorPerformed(Context context) { + SharedPreferences prefs = getEducationSharedPreferences(context); + return prefs.getBoolean(context.getString(R.string.education_password_generator_key), + context.getResources().getBoolean(R.bool.education_password_generator_default)); + } + + public static boolean isEducationEntryNewFieldPerformed(Context context) { + SharedPreferences prefs = getEducationSharedPreferences(context); + return prefs.getBoolean(context.getString(R.string.education_entry_new_field_key), + context.getResources().getBoolean(R.bool.education_entry_new_field_default)); } } diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 23a755fee..74230fe85 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -272,8 +272,6 @@ Générez un mot de passe fort à associer avec votre entrée, définissez le facilement en fonction des critères du formulaire et n\'oubliez plus un mot de passe difficile mais sécurisé. Ajoutez des champs customisés Vous voulez enregistrer un champ non fourni de base, renseignez en simplement un nouveau que vous pouvez aussi protéger visuelement. - Sauvegardez votre entrée - Sauvegardez votre entrée ici une fois que tous les champs voulus sont remplis. Débloquez votre base de données Entrez un mot de passe et/ou un fichier de clé pour ouvrir la base de données.\n\nPensez à sauvegarder une copie de votre fichier en lieu sûr après chaque modification. Copiez un champ diff --git a/app/src/main/res/values/donottranslate.xml b/app/src/main/res/values/donottranslate.xml index 0a6ed054a..fbb57b1fb 100644 --- a/app/src/main/res/values/donottranslate.xml +++ b/app/src/main/res/values/donottranslate.xml @@ -76,13 +76,15 @@ education_create_db_key education_select_db_key education_open_link_db_key + education_unlock_key education_search_key education_new_node_key education_sort_key education_lock_key - education_entry_key - education_password_key + education_copy_username_key education_entry_edit_key + education_password_generator_key + education_entry_new_field_key true true @@ -103,13 +105,15 @@ false false false + false false false false false - false - false + false false + false + false 300000 60000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dbd2e0727..067b0d1fe 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -276,8 +276,6 @@ Generate a strong password to associate with your entry, easily define it according to the criteria of the form and don\'t forget a difficult but secure password. Add custom fields You want to register a basic non-supplied field, simply fill in a new one that you can also protect visually. - Save you entry - Save your entry here once all the desired fields are filled. Unlock your database Enter a password and/or a key file to unlock your database.\n\nRemember to save a copy of your file in a safe place after each modification. Copy a field