Refactor Education

This commit is contained in:
J-Jamet committed 2019-07-07 15:23:47 +02:00
1 parent 77c397e0d1
commit e8b341c69f
14 files changed
+968 -731

No files matched your search

@@ -37,8 +37,7 @@ import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.lock.LockingHideActivity;
import com.kunzisoft.keepass.app.App;
@@ -46,6 +45,7 @@ import com.kunzisoft.keepass.database.element.Database;
import com.kunzisoft.keepass.database.element.EntryVersioned;
import com.kunzisoft.keepass.database.element.PwNodeId;
import com.kunzisoft.keepass.database.element.security.ProtectedString;
import com.kunzisoft.keepass.education.EntryActivityEducation;
import com.kunzisoft.keepass.notifications.NotificationCopyingService;
import com.kunzisoft.keepass.notifications.NotificationField;
import com.kunzisoft.keepass.settings.PreferencesUtil;
@@ -240,79 +240,6 @@ public class EntryActivity extends LockingHideActivity {
firstLaunchOfActivity = false;
}
/**
* Check and display learning views
* Displays the explanation for copying a field and editing an entry
*/
private void checkAndPerformedEducation(Menu menu) {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
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))
.textColorInt(Color.WHITE)
.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)));
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
// Launch autofill settings
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
}
});
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))
.textColorInt(Color.WHITE)
.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);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
// Open Keepass doc to create field references
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(getString(R.string.field_references_url)));
startActivity(browserIntent);
}
});
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");
}
}
}
}
protected void fillData() {
Database database = App.Companion.getCurrentDatabase();
database.startManageEntry(mEntry);
@@ -460,11 +387,45 @@ public class EntryActivity extends LockingHideActivity {
}
// Show education views
new Handler().post(() -> checkAndPerformedEducation(menu));
new Handler().post(() -> performedNextEducation(new EntryActivityEducation(this), menu));
return true;
}
private void performedNextEducation(EntryActivityEducation entryActivityEducation,
Menu menu) {
if (entryContentsView != null
&& entryContentsView.isUserNamePresent()
&& entryActivityEducation.checkAndPerformedEntryCopyEducation(
findViewById(R.id.entry_user_name_action_image),
tapTargetView -> {
clipboardHelper.timeoutCopyToClipboard(mEntry.getUsername(),
getString(R.string.copy_field,
getString(R.string.entry_user_name)));
return null;
},
tapTargetView -> {
// Launch autofill settings
startActivity(new Intent(EntryActivity.this, SettingsAutofillActivity.class));
return null;
})
);
else if (toolbar.findViewById(R.id.menu_edit) != null
&& entryActivityEducation.checkAndPerformedEntryEditEducation(
toolbar.findViewById(R.id.menu_edit),
tapTargetView -> {
onOptionsItemSelected(menu.findItem(R.id.menu_edit));
return null;
},
tapTargetView -> {
// Open Keepass doc to create field references
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(getString(R.string.field_references_url))));
return null;
})
);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ( item.getItemId() ) {
@@ -24,12 +24,20 @@ import android.content.Intent;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.*;
import android.widget.*;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.lock.LockingHideActivity;
import com.kunzisoft.keepass.app.App;
@@ -37,16 +45,24 @@ import com.kunzisoft.keepass.database.action.node.ActionNodeValues;
import com.kunzisoft.keepass.database.action.node.AddEntryRunnable;
import com.kunzisoft.keepass.database.action.node.AfterActionNodeFinishRunnable;
import com.kunzisoft.keepass.database.action.node.UpdateEntryRunnable;
import com.kunzisoft.keepass.database.element.*;
import com.kunzisoft.keepass.database.element.Database;
import com.kunzisoft.keepass.database.element.EntryVersioned;
import com.kunzisoft.keepass.database.element.GroupVersioned;
import com.kunzisoft.keepass.database.element.PwDate;
import com.kunzisoft.keepass.database.element.PwIcon;
import com.kunzisoft.keepass.database.element.PwIconStandard;
import com.kunzisoft.keepass.database.element.PwNodeId;
import com.kunzisoft.keepass.database.element.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.GeneratePasswordDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.education.EntryEditActivityEducation;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.ActionRunnable;
import com.kunzisoft.keepass.timeout.TimeoutHelper;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.Util;
import com.kunzisoft.keepass.view.EntryEditCustomField;
import org.jetbrains.annotations.NotNull;
import static com.kunzisoft.keepass.dialogs.IconPickerDialogFragment.KEY_ICON_STANDARD;
@@ -90,6 +106,9 @@ public class EntryEditActivity extends LockingHideActivity
private View saveView;
private int iconColor;
// Education
private EntryEditActivityEducation entryEditActivityEducation;
/**
* Launch EntryEditActivity to update an existing entry
*
@@ -218,8 +237,33 @@ public class EntryEditActivity extends LockingHideActivity
}
// Verify the education views
checkAndPerformedEducation();
}
entryEditActivityEducation = new EntryEditActivityEducation(this);
new Handler().post(() -> performedNextEducation(entryEditActivityEducation));
}
private void performedNextEducation(EntryEditActivityEducation entryEditActivityEducation) {
if (entryEditActivityEducation.checkAndPerformedGeneratePasswordEducation(
generatePasswordView,
tapTargetView -> {
openPasswordGenerator();
return null;
},
tapTargetView -> {
performedNextEducation(entryEditActivityEducation);
return null;
}
));
else if (mEntry.allowExtraFields()
&& !mEntry.containsCustomFields()
&& entryEditActivityEducation.checkAndPerformedEntryNewFieldEducation(
addNewFieldView,
tapTargetView -> {
addNewCustomField();
return null;
},
tapTargetView -> null)
);
}
/**
* Open the password generator fragment
@@ -283,65 +327,7 @@ public class EntryEditActivity extends LockingHideActivity
new Thread(task).start();
}
/**
* Check and display learning views
* Displays the explanation for the icon selection, the password generator and for a new field
*/
private void checkAndPerformedEducation() {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
// TODO Show icon
if (!PreferencesUtil.isEducationPasswordGeneratorPerformed(this)) {
TapTargetView.showFor(this,
TapTarget.forView(generatePasswordView,
getString(R.string.education_generate_password_title),
getString(R.string.education_generate_password_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
openPasswordGenerator();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_password_generator_key);
} 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))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
addNewCustomField();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_entry_new_field_key);
}
}
}
/**
* Utility class to retrieve a validation or an error with a message
@@ -549,7 +535,7 @@ public class EntryEditActivity extends LockingHideActivity
entryPasswordView.setText(generatedPassword);
entryConfirmationPasswordView.setText(generatedPassword);
checkAndPerformedEducation();
new Handler().post(() -> performedNextEducation(entryEditActivityEducation));
}
@Override
@@ -51,8 +51,6 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.lock.LockingActivity;
import com.kunzisoft.keepass.adapters.NodeAdapter;
@@ -71,7 +69,12 @@ import com.kunzisoft.keepass.database.action.node.DeleteGroupRunnable;
import com.kunzisoft.keepass.database.action.node.MoveEntryRunnable;
import com.kunzisoft.keepass.database.action.node.MoveGroupRunnable;
import com.kunzisoft.keepass.database.action.node.UpdateGroupRunnable;
import com.kunzisoft.keepass.database.element.*;
import com.kunzisoft.keepass.database.element.Database;
import com.kunzisoft.keepass.database.element.EntryVersioned;
import com.kunzisoft.keepass.database.element.GroupVersioned;
import com.kunzisoft.keepass.database.element.NodeVersioned;
import com.kunzisoft.keepass.database.element.PwIcon;
import com.kunzisoft.keepass.database.element.PwNodeId;
import com.kunzisoft.keepass.database.element.security.ProtectedString;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
@@ -79,6 +82,7 @@ import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.education.GroupActivityEducation;
import com.kunzisoft.keepass.magikeyboard.KeyboardEntryNotificationService;
import com.kunzisoft.keepass.magikeyboard.KeyboardHelper;
import com.kunzisoft.keepass.magikeyboard.MagikIME;
@@ -712,141 +716,6 @@ public class GroupActivity extends LockingActivity
searchSuggestionAdapter.reInit(this);
}
/**
* Check and display learning views
* Displays the explanation for a add, search, sort a new node and lock the database
*/
private void checkAndPerformedEducation(Menu menu) {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
// If no node, show education to add new one
if (listNodesFragment != null
&& listNodesFragment.isEmpty()) {
if (!PreferencesUtil.isEducationNewNodePerformed(this)
&& addNodeButtonView.isEnable()) {
TapTargetView.showFor(this,
TapTarget.forView(findViewById(R.id.add_button),
getString(R.string.education_new_node_title),
getString(R.string.education_new_node_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
addNodeButtonView.openButtonIfClose();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_new_node_key);
}
}
// Else show the search education
else if (!PreferencesUtil.isEducationSearchPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_search,
getString(R.string.education_search_title),
getString(R.string.education_search_summary))
.textColorInt(Color.WHITE)
.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();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
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)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_sort,
getString(R.string.education_sort_title),
getString(R.string.education_sort_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem sortItem = menu.findItem(R.id.menu_sort);
onOptionsItemSelected(sortItem);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_sort_key);
} catch (Exception e) {
Log.w(TAG, "Can't performed education for sort");
}
}
// Else show the lock education
else if (!PreferencesUtil.isEducationLockPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_lock,
getString(R.string.education_lock_title),
getString(R.string.education_lock_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem lockItem = menu.findItem(R.id.menu_lock);
onOptionsItemSelected(lockItem);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_lock_key);
} catch (Exception e) {
Log.w(TAG, "Can't performed education for lock");
}
}
}
}
@Override
protected void onStop() {
super.onStop();
@@ -898,11 +767,63 @@ public class GroupActivity extends LockingActivity
super.onCreateOptionsMenu(menu);
// Launch education screen
new Handler().post(() -> checkAndPerformedEducation(menu));
new Handler().post(() -> performedNextEducation(new GroupActivityEducation(this), menu));
return true;
}
private void performedNextEducation(GroupActivityEducation groupActivityEducation,
Menu menu) {
// If no node, show education to add new one
if (listNodesFragment != null
&& listNodesFragment.isEmpty()
&& addNodeButtonView.isEnable()
&& groupActivityEducation.checkAndPerformedAddNodeButtonEducation(
addNodeButtonView,
tapTargetView -> {
addNodeButtonView.openButtonIfClose();
return null;
},
tapTargetView -> {
performedNextEducation(groupActivityEducation, menu);
return null;
}
));
else if (toolbar.findViewById(R.id.menu_search) != null
&& groupActivityEducation.checkAndPerformedSearchMenuEducation(
toolbar.findViewById(R.id.menu_search),
tapTargetView -> {
menu.findItem(R.id.menu_search).expandActionView();
return null;
},
tapTargetView -> {
performedNextEducation(groupActivityEducation, menu);
return null;
}));
else if (toolbar.findViewById(R.id.menu_sort) != null
&& groupActivityEducation.checkAndPerformedSortMenuEducation(
toolbar.findViewById(R.id.menu_sort),
tapTargetView -> {
onOptionsItemSelected(menu.findItem(R.id.menu_sort));
return null;
},
tapTargetView -> {
performedNextEducation(groupActivityEducation, menu);
return null;
}));
else if (toolbar.findViewById(R.id.menu_lock) != null
&& groupActivityEducation.checkAndPerformedLockMenuEducation(
toolbar.findViewById(R.id.menu_lock),
tapTargetView -> {
onOptionsItemSelected(menu.findItem(R.id.menu_lock));
return null;
},
tapTargetView -> {
performedNextEducation(groupActivityEducation, menu);
return null;
}));
}
@Override
public void startActivity(Intent intent) {
@@ -0,0 +1,281 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.util.Log
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
open class Education(val activity: Activity) {
/**
* Utility method to save preference after an education action
*/
protected fun checkAndPerformedEducation(isEducationAlreadyPerformed: Boolean,
tapTarget: TapTarget,
listener: TapTargetView.Listener,
saveEducationStringId: Int): Boolean {
var doEducation = false
if (isEducationScreensEnabled()) {
if (isEducationAlreadyPerformed) {
try {
TapTargetView.showFor(activity, tapTarget, listener)
saveEducationPreference(activity, saveEducationStringId)
doEducation = true
} catch (e: Exception) {
Log.w(Education::class.java.name, "Can't performed education " + e.message)
}
}
}
return doEducation
}
/**
* Define if educations screens are enabled
*/
fun isEducationScreensEnabled(): Boolean {
return isEducationScreensEnabled(activity)
}
/**
* Register education preferences as true in EDUCATION_PREFERENCE SharedPreferences
*
* @param context The context to retrieve the key string in XML
* @param educationKeys Keys to save as boolean 'true'
*/
fun saveEducationPreference(context: Context, vararg educationKeys: Int) {
val sharedPreferences = getEducationSharedPreferences(context)
val editor = sharedPreferences.edit()
for (key in educationKeys) {
editor.putBoolean(context.getString(key), true)
}
editor.apply()
}
companion object {
private const val EDUCATION_PREFERENCE = "kdbxeducation"
/**
* All preference keys associated with education
*/
val educationResourcesKeys = intArrayOf(
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_read_only_key,
R.string.education_fingerprint_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_copy_username_key,
R.string.education_entry_edit_key,
R.string.education_password_generator_key,
R.string.education_entry_new_field_key)
/**
* Get preferences bundle for education
*/
fun getEducationSharedPreferences(ctx: Context): SharedPreferences {
return ctx.getSharedPreferences(
EDUCATION_PREFERENCE,
Context.MODE_PRIVATE)
}
/**
* Define if educations screens are enabled
*/
fun isEducationScreensEnabled(context: Context): Boolean {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
return sharedPreferences.getBoolean(context.getString(R.string.enable_education_screens_key),
context.resources.getBoolean(R.bool.enable_education_screens_default))
}
/**
* Determines whether the explanatory view of the database creation has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_create_db_key key
*/
fun isEducationCreateDatabasePerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_create_db_key),
context.resources.getBoolean(R.bool.education_create_db_default))
}
/**
* Determines whether the explanatory view of the database selection has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_select_db_key key
*/
fun isEducationSelectDatabasePerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_select_db_key),
context.resources.getBoolean(R.bool.education_select_db_default))
}
/**
* Determines whether the explanatory view of the database selection has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_select_db_key key
*/
fun isEducationOpenLinkDatabasePerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_open_link_db_key),
context.resources.getBoolean(R.bool.education_open_link_db_default))
}
/**
* Determines whether the explanatory view of the database unlock has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_unlock_key key
*/
fun isEducationUnlockPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_unlock_key),
context.resources.getBoolean(R.bool.education_unlock_default))
}
/**
* Determines whether the explanatory view of the database read-only has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_read_only_key key
*/
fun isEducationReadOnlyPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_read_only_key),
context.resources.getBoolean(R.bool.education_read_only_default))
}
/**
* Determines whether the explanatory view of the fingerprint unlock has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_fingerprint_key key
*/
fun isEducationFingerprintPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_fingerprint_key),
context.resources.getBoolean(R.bool.education_fingerprint_default))
}
/**
* Determines whether the explanatory view of search has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_search_key key
*/
fun isEducationSearchPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_search_key),
context.resources.getBoolean(R.bool.education_search_default))
}
/**
* Determines whether the explanatory view of add new node has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_new_node_key key
*/
fun isEducationNewNodePerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_new_node_key),
context.resources.getBoolean(R.bool.education_new_node_default))
}
/**
* Determines whether the explanatory view of the sort has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_sort_key key
*/
fun isEducationSortPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_sort_key),
context.resources.getBoolean(R.bool.education_sort_default))
}
/**
* Determines whether the explanatory view of the database lock has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_lock_key key
*/
fun isEducationLockPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_lock_key),
context.resources.getBoolean(R.bool.education_lock_default))
}
/**
* Determines whether the explanatory view of the username copy has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_copy_username_key key
*/
fun isEducationCopyUsernamePerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_copy_username_key),
context.resources.getBoolean(R.bool.education_copy_username_key))
}
/**
* Determines whether the explanatory view of the entry edition has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_entry_edit_key key
*/
fun isEducationEntryEditPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_entry_edit_key),
context.resources.getBoolean(R.bool.education_entry_edit_default))
}
/**
* Determines whether the explanatory view of the password generator has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_password_generator_key key
*/
fun isEducationPasswordGeneratorPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_password_generator_key),
context.resources.getBoolean(R.bool.education_password_generator_default))
}
/**
* Determines whether the explanatory view of the new fields button in an entry has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_entry_new_field_key key
*/
fun isEducationEntryNewFieldPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_entry_new_field_key),
context.resources.getBoolean(R.bool.education_entry_new_field_default))
}
/**
* Defines if the reset education preference has been reclicked
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_screen_reclicked_key key
*/
fun isEducationScreenReclickedPerformed(context: Context): Boolean {
val prefs = getEducationSharedPreferences(context)
return prefs.getBoolean(context.getString(R.string.education_screen_reclicked_key),
context.resources.getBoolean(R.bool.education_screen_reclicked_default))
}
}
}
@@ -0,0 +1,69 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.graphics.Color
import android.view.View
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
class EntryActivityEducation(activity: Activity)
: Education(activity) {
fun checkAndPerformedEntryCopyEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(
!isEducationCopyUsernamePerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_field_copy_title),
activity.getString(R.string.education_field_copy_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_copy_username_key)
}
/**
* Check and display learning views
* Displays the explanation for copying a field and editing an entry
*/
fun checkAndPerformedEntryEditEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(
!isEducationEntryEditPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_entry_edit_title),
activity.getString(R.string.education_entry_edit_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_entry_edit_key)
}
}
@@ -0,0 +1,66 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.graphics.Color
import android.view.View
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
class EntryEditActivityEducation(activity: Activity)
: Education(activity) {
fun checkAndPerformedGeneratePasswordEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationPasswordGeneratorPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_generate_password_title),
activity.getString(R.string.education_generate_password_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_password_generator_key)
}
/**
* Check and display learning views
* Displays the explanation for the icon selection, the password generator and for a new field
*/
fun checkAndPerformedEntryNewFieldEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationEntryNewFieldPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_entry_new_field_title),
activity.getString(R.string.education_entry_new_field_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_entry_new_field_key)
}
}
@@ -0,0 +1,102 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.graphics.Color
import android.support.v4.content.ContextCompat
import android.view.View
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
class FileDatabaseSelectActivityEducation(activity: Activity)
: Education(activity) {
/**
* Check and display learning views
* Displays the explanation for a database creation then a database selection
*/
fun checkAndPerformedCreateDatabaseEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
// Try to open the creation base education
return checkAndPerformedEducation(!isEducationCreateDatabasePerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_create_database_title),
activity.getString(R.string.education_create_database_summary))
.icon(ContextCompat.getDrawable(activity, R.drawable.ic_database_plus_white_24dp))
.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_create_db_key)
}
/**
* Check and display learning views
* Displays the explanation for a database selection
*/
fun checkAndPerformedSelectDatabaseEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationSelectDatabasePerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_select_database_title),
activity.getString(R.string.education_select_database_summary))
.icon(ContextCompat.getDrawable(activity, R.drawable.ic_folder_white_24dp))
.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_select_db_key)
}
fun checkAndPerformedOpenLinkDatabaseEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationOpenLinkDatabasePerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_open_link_database_title),
activity.getString(R.string.education_open_link_database_summary))
.icon(ContextCompat.getDrawable(activity, R.drawable.ic_link_white_24dp))
.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_open_link_db_key)
}
}
@@ -0,0 +1,112 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.graphics.Color
import android.view.View
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
class GroupActivityEducation(activity: Activity)
: Education(activity) {
fun checkAndPerformedAddNodeButtonEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationNewNodePerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_new_node_title),
activity.getString(R.string.education_new_node_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_new_node_key)
}
fun checkAndPerformedSearchMenuEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationSearchPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_search_title),
activity.getString(R.string.education_search_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_search_key)
}
fun checkAndPerformedSortMenuEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationSortPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_sort_title),
activity.getString(R.string.education_sort_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_sort_key)
}
fun checkAndPerformedLockMenuEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationLockPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_lock_title),
activity.getString(R.string.education_lock_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_lock_key)
}
}
@@ -0,0 +1,90 @@
package com.kunzisoft.keepass.education
import android.app.Activity
import android.graphics.Color
import android.support.v4.content.ContextCompat
import android.view.View
import com.getkeepsafe.taptargetview.TapTarget
import com.getkeepsafe.taptargetview.TapTargetView
import com.kunzisoft.keepass.R
class PasswordActivityEducation(activity: Activity)
: Education(activity) {
fun checkAndPerformedFingerprintUnlockEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationUnlockPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_unlock_title),
activity.getString(R.string.education_unlock_summary))
.dimColor(R.color.green)
.icon(ContextCompat.getDrawable(activity, R.mipmap.ic_launcher_round))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_unlock_key)
}
fun checkAndPerformedReadOnlyEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationReadOnlyPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_read_only_title),
activity.getString(R.string.education_read_only_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_read_only_key)
}
fun checkAndPerformedFingerprintEducation(educationView: View,
onEducationViewClick: ((TapTargetView?) -> Unit)? = null,
onOuterViewClick: ((TapTargetView?) -> Unit)? = null): Boolean {
return checkAndPerformedEducation(!isEducationFingerprintPerformed(activity),
TapTarget.forView(educationView,
activity.getString(R.string.education_fingerprint_title),
activity.getString(R.string.education_fingerprint_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.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_fingerprint_key)
}
}
@@ -24,15 +24,14 @@ import android.app.Activity;
import android.app.assist.AssistStructure;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -45,23 +44,22 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.EntrySelectionHelper;
import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.autofill.AutofillHelper;
import com.kunzisoft.keepass.database.action.AssignPasswordInDatabaseRunnable;
import com.kunzisoft.keepass.database.action.CreateDatabaseRunnable;
import com.kunzisoft.keepass.fileselect.database.FileDatabaseHistory;
import com.kunzisoft.keepass.tasks.ActionRunnable;
import com.kunzisoft.keepass.database.action.ProgressDialogRunnable;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
import com.kunzisoft.keepass.education.FileDatabaseSelectActivityEducation;
import com.kunzisoft.keepass.fileselect.database.FileDatabaseHistory;
import com.kunzisoft.keepass.magikeyboard.KeyboardHelper;
import com.kunzisoft.keepass.password.PasswordActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.stylish.StylishActivity;
import com.kunzisoft.keepass.tasks.ActionRunnable;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil;
@@ -233,8 +231,40 @@ public class FileDatabaseSelectActivity extends StylishActivity implements
}
}
// For the first time show education
checkAndPerformedEducation();
new Handler().post(() -> performedNextEducation(new FileDatabaseSelectActivityEducation(this)));
}
private void performedNextEducation(FileDatabaseSelectActivityEducation fileDatabaseSelectActivityEducation) {
// If no recent files
if (!fileDatabaseHistory.hasRecentFiles()
&& fileDatabaseSelectActivityEducation.checkAndPerformedCreateDatabaseEducation(
createButtonView,
tapTargetView -> {
FileDatabaseSelectActivityPermissionsDispatcher
.openCreateFileDialogFragmentWithPermissionCheck(FileDatabaseSelectActivity.this);
return null;
},
tapTargetView -> {
// But if the user cancel, it can also select a database
performedNextEducation(fileDatabaseSelectActivityEducation);
return null;
})
);
else if (fileDatabaseSelectActivityEducation.checkAndPerformedSelectDatabaseEducation(
browseButtonView,
tapTargetView -> {
keyFileHelper.getOpenFileOnClickViewListener().onClick(tapTargetView);
return null;
},
tapTargetView -> {
fileDatabaseSelectActivityEducation.checkAndPerformedOpenLinkDatabaseEducation(
fileSelectExpandableButton,
tapTargetView1 -> null,
tapTargetView12 -> null
);
return null;
}
));
}
private void fileNoFoundAction(FileNotFoundException e) {
@@ -314,113 +344,6 @@ public class FileDatabaseSelectActivity extends StylishActivity implements
mAdapter.notifyDataSetChanged();
}
/**
* Check and display learning views
* Displays the explanation for a database creation then a database selection
*/
private void checkAndPerformedEducation() {
// If no recent files
if ( !fileDatabaseHistory.hasRecentFiles() ) {
// Try to open the creation base education
if (!PreferencesUtil.isEducationCreateDatabasePerformed(this) ) {
TapTargetView.showFor(this,
TapTarget.forView(createButtonView,
getString(R.string.education_create_database_title),
getString(R.string.education_create_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_database_plus_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
FileDatabaseSelectActivityPermissionsDispatcher
.openCreateFileDialogFragmentWithPermissionCheck(FileDatabaseSelectActivity.this);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
// But if the user cancel, it can also select a database
checkAndPerformedEducationForSelection();
}
});
PreferencesUtil.saveEducationPreference(FileDatabaseSelectActivity.this,
R.string.education_create_db_key);
}
}
else
checkAndPerformedEducationForSelection();
}
/**
* Check and display learning views
* Displays the explanation for a database selection
*/
private void checkAndPerformedEducationForSelection() {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
if (!PreferencesUtil.isEducationSelectDatabasePerformed(this)
&& browseButtonView != null) {
TapTargetView.showFor(FileDatabaseSelectActivity.this,
TapTarget.forView(browseButtonView,
getString(R.string.education_select_database_title),
getString(R.string.education_select_database_summary))
.icon(ContextCompat.getDrawable(this, R.drawable.ic_folder_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
keyFileHelper.getOpenFileOnClickViewListener().onClick(view);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
if (!PreferencesUtil.isEducationOpenLinkDatabasePerformed(FileDatabaseSelectActivity.this)) {
TapTargetView.showFor(FileDatabaseSelectActivity.this,
TapTarget.forView(fileSelectExpandableButton,
getString(R.string.education_open_link_database_title),
getString(R.string.education_open_link_database_summary))
.icon(ContextCompat.getDrawable(FileDatabaseSelectActivity.this, R.drawable.ic_link_white_24dp))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
// Do nothing here
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
PreferencesUtil.saveEducationPreference(FileDatabaseSelectActivity.this,
R.string.education_open_link_db_key);
}
}
});
PreferencesUtil.saveEducationPreference(FileDatabaseSelectActivity.this,
R.string.education_select_db_key);
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@@ -25,7 +25,6 @@ import android.app.assist.AssistStructure;
import android.app.backup.BackupManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.hardware.fingerprint.FingerprintManager;
import android.net.Uri;
import android.os.Build;
@@ -34,7 +33,6 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
@@ -44,9 +42,13 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.*;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.EntrySelectionHelper;
import com.kunzisoft.keepass.activities.GroupActivity;
@@ -59,6 +61,7 @@ import com.kunzisoft.keepass.database.action.LoadDatabaseRunnable;
import com.kunzisoft.keepass.database.action.ProgressDialogRunnable;
import com.kunzisoft.keepass.database.element.Database;
import com.kunzisoft.keepass.dialogs.PasswordEncodingDialogHelper;
import com.kunzisoft.keepass.education.PasswordActivityEducation;
import com.kunzisoft.keepass.fileselect.KeyFileHelper;
import com.kunzisoft.keepass.fingerprint.FingerPrintAnimatedVector;
import com.kunzisoft.keepass.fingerprint.FingerPrintExplanationDialog;
@@ -70,13 +73,20 @@ import com.kunzisoft.keepass.tasks.ActionRunnable;
import com.kunzisoft.keepass.utils.EmptyUtils;
import com.kunzisoft.keepass.utils.MenuUtil;
import com.kunzisoft.keepass.utils.UriUtil;
import org.jetbrains.annotations.Nullable;
import permissions.dispatcher.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.OnNeverAskAgain;
import permissions.dispatcher.OnPermissionDenied;
import permissions.dispatcher.OnShowRationale;
import permissions.dispatcher.PermissionRequest;
import permissions.dispatcher.RuntimePermissions;
@RuntimePermissions
public class PasswordActivity extends StylishActivity
implements FingerPrintHelper.FingerPrintCallback, UriIntentInitTaskCallback {
@@ -325,113 +335,6 @@ public class PasswordActivity extends StylishActivity
super.onSaveInstanceState(outState);
}
/**
* Check and display learning views
* Displays the explanation for a database opening with fingerprints if available
*/
private void checkAndPerformedEducation(Menu menu) {
if (PreferencesUtil.isEducationScreensEnabled(this)) {
if (!PreferencesUtil.isEducationUnlockPerformed(this)) {
TapTargetView.showFor(this,
TapTarget.forView(findViewById(R.id.password_input_container),
getString(R.string.education_unlock_title),
getString(R.string.education_unlock_summary))
.dimColor(R.color.green)
.icon(ContextCompat.getDrawable(getApplicationContext(), R.mipmap.ic_launcher_round))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
performedReadOnlyEducation(menu);
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
performedReadOnlyEducation(menu);
}
});
// TODO make a period for donation
PreferencesUtil.saveEducationPreference(PasswordActivity.this,
R.string.education_unlock_key);
}
}
}
/**
* Check and display learning views
* Displays read-only if available
*/
private void performedReadOnlyEducation(Menu menu) {
if (!PreferencesUtil.isEducationReadOnlyPerformed(this)) {
try {
TapTargetView.showFor(this,
TapTarget.forToolbarMenuItem(toolbar, R.id.menu_open_file_read_mode_key,
getString(R.string.education_read_only_title),
getString(R.string.education_read_only_summary))
.textColorInt(Color.WHITE)
.tintTarget(true)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view);
MenuItem editItem = menu.findItem(R.id.menu_open_file_read_mode_key);
onOptionsItemSelected(editItem);
checkAndPerformedEducationForFingerprint();
}
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
checkAndPerformedEducationForFingerprint();
}
});
PreferencesUtil.saveEducationPreference(this,
R.string.education_read_only_key);
} catch (Exception e) {
// If icon not visible
Log.w(TAG, "Can't performed education for entry's edition");
}
}
}
/**
* Check and display learning views
* Displays fingerprints if available
*/
private void checkAndPerformedEducationForFingerprint() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if ( PreferencesUtil.isFingerprintEnable(getApplicationContext())
&& FingerPrintHelper.isFingerprintSupported(getSystemService(FingerprintManager.class))) {
TapTargetView.showFor(this,
TapTarget.forView(fingerprintImageView,
getString(R.string.education_fingerprint_title),
getString(R.string.education_fingerprint_summary))
.textColorInt(Color.WHITE)
.tintTarget(false)
.cancelable(true),
new TapTargetView.Listener() {
@Override
public void onOuterCircleClick(TapTargetView view) {
super.onOuterCircleClick(view);
view.dismiss(false);
}
});
}
}
}
@Override
public void onPostInitTask(Uri dbUri, Uri keyFileUri, Integer errorStringId) {
mDbUri = dbUri;
@@ -957,11 +860,46 @@ public class PasswordActivity extends StylishActivity
super.onCreateOptionsMenu(menu);
// Show education views
new Handler().post(() -> checkAndPerformedEducation(menu));
new Handler().post(() -> performedNextEducation(new PasswordActivityEducation(this), menu));
return true;
}
private void performedNextEducation(PasswordActivityEducation passwordActivityEducation,
Menu menu) {
if (passwordActivityEducation.checkAndPerformedFingerprintUnlockEducation(
toolbar,
tapTargetView -> {
performedNextEducation(passwordActivityEducation, menu);
return null;
},
tapTargetView -> {
performedNextEducation(passwordActivityEducation, menu);
return null;
})
);
else if (toolbar.findViewById(R.id.menu_open_file_read_mode_key) != null
&& passwordActivityEducation.checkAndPerformedReadOnlyEducation(
toolbar.findViewById(R.id.menu_open_file_read_mode_key),
tapTargetView -> {
onOptionsItemSelected(menu.findItem(R.id.menu_open_file_read_mode_key));
performedNextEducation(passwordActivityEducation, menu);
return null;
},
tapTargetView -> {
performedNextEducation(passwordActivityEducation, menu);
return null;
})
);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& PreferencesUtil.isFingerprintEnable(getApplicationContext())
&& FingerPrintHelper.isFingerprintSupported(getSystemService(FingerprintManager.class))
&& passwordActivityEducation.checkAndPerformedFingerprintEducation(fingerprintImageView,
tapTargetView -> null,
tapTargetView -> null)
);
}
private void changeOpenFileReadIcon(MenuItem togglePassword) {
if ( readOnly ) {
togglePassword.setTitle(R.string.menu_file_selection_read_only);
@@ -49,6 +49,7 @@ import com.kunzisoft.keepass.database.element.Database;
import com.kunzisoft.keepass.dialogs.ProFeatureDialogFragment;
import com.kunzisoft.keepass.dialogs.UnavailableFeatureDialogFragment;
import com.kunzisoft.keepass.dialogs.UnderDevelopmentFeatureDialogFragment;
import com.kunzisoft.keepass.education.Education;
import com.kunzisoft.keepass.fileselect.database.FileDatabaseHistory;
import com.kunzisoft.keepass.fingerprint.FingerPrintHelper;
import com.kunzisoft.keepass.icons.IconPackChooser;
@@ -392,7 +393,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
Preference stylePreference = findPreference(getString(R.string.setting_style_key));
stylePreference.setOnPreferenceChangeListener((preference, newValue) -> {
String styleIdString = (String) newValue;
if (!(!BuildConfig.CLOSED_STORE && PreferencesUtil.isEducationScreenReclickedPerformed(getContext())))
if (!(!BuildConfig.CLOSED_STORE && Education.Companion.isEducationScreenReclickedPerformed(getContext())))
for (String themeIdDisabled : BuildConfig.STYLES_DISABLED) {
if (themeIdDisabled.equals(styleIdString)) {
ProFeatureDialogFragment dialogFragment = new ProFeatureDialogFragment();
@@ -411,7 +412,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
Preference iconPackPreference = findPreference(getString(R.string.setting_icon_pack_choose_key));
iconPackPreference.setOnPreferenceChangeListener((preference, newValue) -> {
String iconPackId = (String) newValue;
if (!(!BuildConfig.CLOSED_STORE && PreferencesUtil.isEducationScreenReclickedPerformed(getContext())))
if (!(!BuildConfig.CLOSED_STORE && Education.Companion.isEducationScreenReclickedPerformed(getContext())))
for (String iconPackIdDisabled : BuildConfig.ICON_PACKS_DISABLED) {
if (iconPackIdDisabled.equals(iconPackId)) {
ProFeatureDialogFragment dialogFragment = new ProFeatureDialogFragment();
@@ -429,9 +430,9 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
resetEducationScreens.setOnPreferenceClickListener(preference -> {
// To allow only one toast
if (count == 0) {
SharedPreferences sharedPreferences = PreferencesUtil.getEducationSharedPreferences(getContext());
SharedPreferences sharedPreferences = Education.Companion.getEducationSharedPreferences(getContext());
SharedPreferences.Editor editor = sharedPreferences.edit();
for (int resourceId : PreferencesUtil.educationResourceKeys) {
for (int resourceId : Education.Companion.getEducationResourcesKeys()) {
editor.putBoolean(getString(resourceId), false);
}
editor.apply();
@@ -487,7 +488,7 @@ public class NestedSettingsFragment extends PreferenceFragmentCompat
super.onStop();
if(count==10) {
if (getActivity()!=null)
PreferencesUtil.getEducationSharedPreferences(getActivity()).edit()
Education.Companion.getEducationSharedPreferences(getActivity()).edit()
.putBoolean(getString(R.string.education_screen_reclicked_key), true).apply();
}
}
@@ -33,7 +33,6 @@ import java.util.Set;
public class PreferencesUtil {
private static final String NO_BACKUP_PREFERENCE_FILE_NAME = "nobackup";
private static final String EDUCATION_PREFERENCE = "kdbxeducation";
public static SharedPreferences getNoBackupSharedPreferences(Context ctx) {
return ctx.getSharedPreferences(
@@ -41,12 +40,6 @@ public class PreferencesUtil {
Context.MODE_PRIVATE);
}
public static SharedPreferences getEducationSharedPreferences(Context ctx) {
return ctx.getSharedPreferences(
PreferencesUtil.EDUCATION_PREFERENCE,
Context.MODE_PRIVATE);
}
public static void deleteAllValuesFromNoBackupPreferences(Context ctx) {
SharedPreferences prefsNoBackup = getNoBackupSharedPreferences(ctx);
SharedPreferences.Editor sharedPreferencesEditor = prefsNoBackup.edit();
@@ -220,212 +213,4 @@ public class PreferencesUtil {
return prefs.getBoolean(context.getString(R.string.keyboard_key_sound_key),
context.getResources().getBoolean(R.bool.keyboard_key_sound_default));
}
/**
* 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_read_only_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_copy_username_key,
R.string.education_entry_edit_key,
R.string.education_password_generator_key,
R.string.education_entry_new_field_key
};
public static boolean isEducationScreensEnabled(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
return sharedPreferences.getBoolean(context.getString(R.string.enable_education_screens_key),
context.getResources().getBoolean(R.bool.enable_education_screens_default));
}
/**
* Register education preferences as true in EDUCATION_PREFERENCE SharedPreferences
*
* @param context The context to retrieve the key string in XML
* @param educationKeys Keys to save as boolean 'true'
*/
public static void saveEducationPreference(Context context, int... educationKeys) {
SharedPreferences sharedPreferences = PreferencesUtil.getEducationSharedPreferences(context);
SharedPreferences.Editor editor = sharedPreferences.edit();
for (int key : educationKeys) {
editor.putBoolean(context.getString(key), true);
}
editor.apply();
}
/**
* Determines whether the explanatory view of the database creation has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_create_db_key key
*/
public static boolean isEducationCreateDatabasePerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_create_db_key),
context.getResources().getBoolean(R.bool.education_create_db_default));
}
/**
* Determines whether the explanatory view of the database selection has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_select_db_key key
*/
public static boolean isEducationSelectDatabasePerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_select_db_key),
context.getResources().getBoolean(R.bool.education_select_db_default));
}
/**
* Determines whether the explanatory view of the database selection has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_select_db_key key
*/
public static boolean isEducationOpenLinkDatabasePerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_open_link_db_key),
context.getResources().getBoolean(R.bool.education_open_link_db_default));
}
/**
* Determines whether the explanatory view of the database unlock has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_unlock_key key
*/
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));
}
/**
* Determines whether the explanatory view of the database read-only has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_read_only_key key
*/
public static boolean isEducationReadOnlyPerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_read_only_key),
context.getResources().getBoolean(R.bool.education_read_only_default));
}
/**
* Determines whether the explanatory view of search has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_search_key key
*/
public static boolean isEducationSearchPerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_search_key),
context.getResources().getBoolean(R.bool.education_search_default));
}
/**
* Determines whether the explanatory view of add new node has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_new_node_key key
*/
public static boolean isEducationNewNodePerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_new_node_key),
context.getResources().getBoolean(R.bool.education_new_node_default));
}
/**
* Determines whether the explanatory view of the sort has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_sort_key key
*/
public static boolean isEducationSortPerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_sort_key),
context.getResources().getBoolean(R.bool.education_sort_default));
}
/**
* Determines whether the explanatory view of the database lock has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_lock_key key
*/
public static boolean isEducationLockPerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_lock_key),
context.getResources().getBoolean(R.bool.education_lock_default));
}
/**
* Determines whether the explanatory view of the username copy has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_copy_username_key key
*/
public static boolean isEducationCopyUsernamePerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_copy_username_key),
context.getResources().getBoolean(R.bool.education_copy_username_key));
}
/**
* Determines whether the explanatory view of the entry edition has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_entry_edit_key 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_edit_default));
}
/**
* Determines whether the explanatory view of the password generator has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_password_generator_key key
*/
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));
}
/**
* Determines whether the explanatory view of the new fields button in an entry has already been displayed.
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_entry_new_field_key key
*/
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));
}
/**
* Defines if the reset education preference has been reclicked
*
* @param context The context to open the SharedPreferences
* @return boolean value of education_screen_reclicked_key key
*/
public static boolean isEducationScreenReclickedPerformed(Context context) {
SharedPreferences prefs = getEducationSharedPreferences(context);
return prefs.getBoolean(context.getString(R.string.education_screen_reclicked_key),
context.getResources().getBoolean(R.bool.education_screen_reclicked_default));
}
}
@@ -181,6 +181,8 @@
<bool name="education_unlock_default" translatable="false">false</bool>
<string name="education_read_only_key" translatable="false">education_read_only_key</string>
<bool name="education_read_only_default" translatable="false">false</bool>
<string name="education_fingerprint_key" translatable="false">education_fingerprint_key</string>
<bool name="education_fingerprint_default" translatable="false">false</bool>
<string name="education_search_key" translatable="false">education_search_key</string>
<bool name="education_search_default" translatable="false">false</bool>
<string name="education_new_node_key" translatable="false">education_new_node_key</string>