diff --git a/src/keepass2android/EntryActivity.cs b/src/keepass2android/EntryActivity.cs index cf195524..701cafdc 100644 --- a/src/keepass2android/EntryActivity.cs +++ b/src/keepass2android/EntryActivity.cs @@ -45,6 +45,7 @@ using KeePass.DataExchange; using KeePass.Util.Spr; using KeePassLib.Interfaces; using KeePassLib.Serialization; +using PluginTOTP; using File = Java.IO.File; using Uri = Android.Net.Uri; @@ -138,7 +139,7 @@ namespace keepass2android private PasswordFont _passwordFont = new PasswordFont(); - internal bool _showPassword; + internal Dictionary _showPassword = new Dictionary(); private int _pos; private AppTask _appTask; @@ -391,10 +392,12 @@ namespace keepass2android edit.PutLong(GetString(Resource.String.UsageCount_key), usageCount + 1); edit.Commit(); - _showPassword = + _showPasswordDefault = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default)); - - RequestWindowFeature(WindowFeatures.IndeterminateProgress); + _showTotpDefault = + !prefs.GetBoolean(GetString(Resource.String.masktotp_key), Resources.GetBoolean(Resource.Boolean.masktotp_default)); + + RequestWindowFeature(WindowFeatures.IndeterminateProgress); _activityDesign.ApplyTheme(); base.OnCreate(savedInstanceState); @@ -567,7 +570,7 @@ namespace keepass2android SetPasswordTypeface(valueViewVisible); if (isProtected) { - RegisterProtectedTextView(valueView, valueViewVisible); + RegisterProtectedTextView(key, valueView, valueViewVisible); } else @@ -700,8 +703,12 @@ namespace keepass2android - private void RegisterProtectedTextView(TextView protectedTextView, TextView visibleTextView) + private void RegisterProtectedTextView(string fieldKey, TextView protectedTextView, TextView visibleTextView) { + if (!_showPassword.ContainsKey(protectedTextView)) + { + _showPassword[protectedTextView] = fieldKey == UpdateTotpTimerTask.TotpKey ? _showTotpDefault : _showPasswordDefault; + } var protectedTextviewGroup = new ProtectedTextviewGroup { ProtectedField = protectedTextView, VisibleProtectedField = visibleTextView}; _protectedTextViews.Add(protectedTextviewGroup); SetPasswordStyle(protectedTextviewGroup); @@ -809,7 +816,7 @@ namespace keepass2android PopulateStandardText(Resource.Id.entry_url, Resource.Id.entryfield_container_url, PwDefs.UrlField); PopulateStandardText(new List { Resource.Id.entry_password, Resource.Id.entry_password_visible}, Resource.Id.entryfield_container_password, PwDefs.PasswordField); - RegisterProtectedTextView(FindViewById(Resource.Id.entry_password), FindViewById(Resource.Id.entry_password_visible)); + RegisterProtectedTextView(PwDefs.PasswordField, FindViewById(Resource.Id.entry_password), FindViewById(Resource.Id.entry_password_visible)); RegisterTextPopup(FindViewById (Resource.Id.groupname_container), FindViewById (Resource.Id.entry_group_name), KeyGroupFullPath); @@ -885,12 +892,16 @@ namespace keepass2android container, anchor); popupItems.Add(new CopyToClipboardPopupMenuIcon(this, _stringViews[fieldKey])); - if (isProtected) - popupItems.Add(new ToggleVisibilityPopupMenuItem(this)); + if (isProtected) + { + var valueView = container.FindViewById(fieldKey == PwDefs.PasswordField ? Resource.Id.entry_password : Resource.Id.entry_extra); + popupItems.Add(new ToggleVisibilityPopupMenuItem(this, valueView)); + } + if (fieldKey != PwDefs.UrlField //url already has a go-to-url menu - && (_stringViews[fieldKey].Text.StartsWith(KeePass.AndroidAppScheme) - || _stringViews[fieldKey].Text.StartsWith("http://") - || _stringViews[fieldKey].Text.StartsWith("https://"))) + && (_stringViews[fieldKey].Text.StartsWith(KeePass.AndroidAppScheme) + || _stringViews[fieldKey].Text.StartsWith("http://") + || _stringViews[fieldKey].Text.StartsWith("https://"))) { popupItems.Add(new GotoUrlMenuItem(this, fieldKey)); } @@ -1070,8 +1081,10 @@ namespace keepass2android } private ExportBinaryProcessManager _exportBinaryProcessManager; + private bool _showPasswordDefault; + private bool _showTotpDefault; - protected override void OnSaveInstanceState(Bundle outState) + protected override void OnSaveInstanceState(Bundle outState) { @@ -1114,7 +1127,7 @@ namespace keepass2android private void UpdateTogglePasswordMenu() { IMenuItem togglePassword = _menu.FindItem(Resource.Id.menu_toggle_pass); - if (_showPassword) + if (_showPassword.Values.All(x => x)) { togglePassword.SetTitle(Resource.String.menu_hide_password); } @@ -1134,8 +1147,9 @@ namespace keepass2android private void SetPasswordStyle(ProtectedTextviewGroup group) { - group.VisibleProtectedField.Visibility = _showPassword ? ViewStates.Visible : ViewStates.Gone; - group.ProtectedField.Visibility = !_showPassword ? ViewStates.Visible : ViewStates.Gone; + bool showPassword = _showPassword.GetValueOrDefault(group.ProtectedField, _showPasswordDefault); + group.VisibleProtectedField.Visibility = showPassword ? ViewStates.Visible : ViewStates.Gone; + group.ProtectedField.Visibility = !showPassword ? ViewStates.Visible : ViewStates.Gone; SetPasswordTypeface(group.VisibleProtectedField); @@ -1191,15 +1205,17 @@ namespace keepass2android task.Start(); break; case Resource.Id.menu_toggle_pass: - if (_showPassword) + if (_showPassword.Values.All(x => x)) { item.SetTitle(Resource.String.show_password); - _showPassword = false; + foreach (var k in _showPassword.Keys.ToList()) + _showPassword[k] = false; } else { item.SetTitle(Resource.String.menu_hide_password); - _showPassword = true; + foreach (var k in _showPassword.Keys.ToList()) + _showPassword[k] = true; } SetPasswordStyle(); @@ -1260,10 +1276,26 @@ namespace keepass2android ProgressTask pt = new ProgressTask(App.Kp2a, this, runnable); pt.Run(); - } - public void ToggleVisibility() + } + + public bool GetVisibilityForProtectedView(TextView protectedView) + { + if (protectedView == null) + { + return _showPasswordDefault; + } + if (_showPassword.ContainsKey(protectedView) == false) + { + _showPassword[protectedView] = _showPasswordDefault; + } + + return _showPassword[protectedView]; + } + + public void ToggleVisibility(TextView valueView) { - _showPassword = !_showPassword; + + _showPassword[valueView] = !GetVisibilityForProtectedView(valueView); SetPasswordStyle(); UpdateTogglePasswordMenu(); } diff --git a/src/keepass2android/EntryActivityClasses/ToggleVisibilityPopupMenuItem.cs b/src/keepass2android/EntryActivityClasses/ToggleVisibilityPopupMenuItem.cs index a4a77e23..ad4baf16 100644 --- a/src/keepass2android/EntryActivityClasses/ToggleVisibilityPopupMenuItem.cs +++ b/src/keepass2android/EntryActivityClasses/ToggleVisibilityPopupMenuItem.cs @@ -1,4 +1,5 @@ using Android.Graphics.Drawables; +using Android.Widget; namespace keepass2android { @@ -8,13 +9,14 @@ namespace keepass2android class ToggleVisibilityPopupMenuItem : IPopupMenuItem { private readonly EntryActivity _activity; - + private readonly TextView _valueView; - public ToggleVisibilityPopupMenuItem(EntryActivity activity) - { - _activity = activity; - - } + + public ToggleVisibilityPopupMenuItem(EntryActivity activity, TextView valueView) + { + _activity = activity; + _valueView = valueView; + } public Drawable Icon { @@ -30,7 +32,7 @@ namespace keepass2android get { return _activity.Resources.GetString( - _activity._showPassword ? + _activity.GetVisibilityForProtectedView(_valueView) ? Resource.String.menu_hide_password : Resource.String.show_password); } @@ -39,7 +41,7 @@ namespace keepass2android public void HandleClick() { - _activity.ToggleVisibility(); + _activity.ToggleVisibility(_valueView); } } } \ No newline at end of file diff --git a/src/keepass2android/Resources/values/config.xml b/src/keepass2android/Resources/values/config.xml index 88c3ade9..d60940d2 100644 --- a/src/keepass2android/Resources/values/config.xml +++ b/src/keepass2android/Resources/values/config.xml @@ -66,6 +66,7 @@ change_master_pwd keyfile maskpass + masktotp omitbackup list_size design_key @@ -82,6 +83,7 @@ /mnt/sdcard/keepass2android/binaries/ true + true true true true diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index 8461370a..6b657d15 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -186,6 +186,10 @@ ***** Mask password Hide passwords by default + + Mask TOTP field + Hide TOTP field by default + About Change Master Key Copy Password diff --git a/src/keepass2android/Resources/xml/preferences.xml b/src/keepass2android/Resources/xml/preferences.xml index 0a2d6d23..acdda907 100644 --- a/src/keepass2android/Resources/xml/preferences.xml +++ b/src/keepass2android/Resources/xml/preferences.xml @@ -243,6 +243,12 @@ android:summary="@string/maskpass_summary" android:defaultValue="@bool/maskpass_default"/> + +