From 3218d2f90769c39028f1070fb2d0af6aac6cbbcf Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Fri, 12 Jul 2013 14:17:20 +0200 Subject: [PATCH] Improved editing of advanced fields, display and toggle protected fields like password --- src/keepass2android/EntryActivity.cs | 42 +- src/keepass2android/EntryEditActivity.cs | 72 +- .../Resources/Resource.designer.cs | 978 +++++++++--------- .../layout-v14/entry_edit_section.xml | 35 - .../Resources/layout/entry_edit_section.xml | 17 +- .../Resources/values/strings.xml | 9 +- src/keepass2android/keepass2android.csproj | 9 +- src/keepass2android/views/EntryEditSection.cs | 82 -- 8 files changed, 609 insertions(+), 635 deletions(-) delete mode 100644 src/keepass2android/Resources/layout-v14/entry_edit_section.xml delete mode 100644 src/keepass2android/views/EntryEditSection.cs diff --git a/src/keepass2android/EntryActivity.cs b/src/keepass2android/EntryActivity.cs index 41602145..fe7923ec 100644 --- a/src/keepass2android/EntryActivity.cs +++ b/src/keepass2android/EntryActivity.cs @@ -63,7 +63,8 @@ namespace keepass2android private int _pos; AppTask _appTask; - + private List _protectedTextViews; + protected void SetEntryView() { SetContentView(Resource.Layout.entry_view); @@ -180,16 +181,15 @@ namespace keepass2android } bool hasExtraFields = false; foreach (var view in from pair in Entry.Strings where !PwDefs.IsStandardField(pair.Key) orderby pair.Key - select CreateEditSection(pair.Key, pair.Value.ReadString())) + select CreateEditSection(pair.Key, pair.Value.ReadString(), pair.Value.IsProtected)) { - //View view = new EntrySection(this, null, key, pair.Value.ReadString()); extraGroup.AddView(view); hasExtraFields = true; } FindViewById(Resource.Id.entry_extra_strings_label).Visibility = hasExtraFields ? ViewStates.Visible : ViewStates.Gone; } - View CreateEditSection(string key, string value) + View CreateEditSection(string key, string value, bool isProtected) { LinearLayout layout = new LinearLayout(this, null) {Orientation = Orientation.Vertical}; LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent); @@ -199,19 +199,27 @@ namespace keepass2android TextView keyView = (TextView)viewInflated; if (key != null) keyView.Text = key; - + layout.AddView(keyView); TextView valueView = (TextView)LayoutInflater.Inflate(Resource.Layout.entry_extrastring_value, null); if (value != null) valueView.Text = value; valueView.Typeface = Typeface.Monospace; + if (isProtected) + RegisterProtectedTextView(valueView); + if ((int)Build.VERSION.SdkInt >= 11) valueView.SetTextIsSelectable(true); layout.AddView(valueView); return layout; } - + + private void RegisterProtectedTextView(TextView protectedTextView) + { + _protectedTextViews.Add(protectedTextView); + } + Android.Net.Uri WriteBinaryToFile(string key, bool writeToCacheDirectory) { ProtectedBinary pb = Entry.Binaries.Get(key); @@ -365,6 +373,7 @@ namespace keepass2android protected void FillData(bool trimList) { + _protectedTextViews = new List(); ImageView iv = (ImageView)FindViewById(Resource.Id.entry_icon); if (iv != null) { @@ -388,7 +397,7 @@ namespace keepass2android PopulateText(Resource.Id.entry_url, Resource.Id.entry_url_label, Entry.Strings.ReadSafe(PwDefs.UrlField)); PopulateText(Resource.Id.entry_password, Resource.Id.entry_password_label, Entry.Strings.ReadSafe(PwDefs.PasswordField)); - SetPasswordStyle(); + RegisterProtectedTextView(FindViewById(Resource.Id.entry_password)); PopulateText(Resource.Id.entry_created, Resource.Id.entry_created_label, getDateTime(Entry.CreationTime)); PopulateText(Resource.Id.entry_modified, Resource.Id.entry_modified_label, getDateTime(Entry.LastModificationTime)); @@ -411,7 +420,7 @@ namespace keepass2android PopulateBinaries(trimList); - + SetPasswordStyle(); } private void PopulateText(int viewId, int headerViewId,int resId) { @@ -498,12 +507,17 @@ namespace keepass2android } private void SetPasswordStyle() { - TextView password = (TextView) FindViewById(Resource.Id.entry_password); - - if ( _showPassword ) { - password.TransformationMethod = null; - } else { - password.TransformationMethod = PasswordTransformationMethod.Instance; + foreach (TextView password in _protectedTextViews) + { + + if (_showPassword) + { + password.TransformationMethod = null; + } + else + { + password.TransformationMethod = PasswordTransformationMethod.Instance; + } } } protected override void OnResume() diff --git a/src/keepass2android/EntryEditActivity.cs b/src/keepass2android/EntryEditActivity.cs index aeae3d8c..1acd7f8b 100644 --- a/src/keepass2android/EntryEditActivity.cs +++ b/src/keepass2android/EntryEditActivity.cs @@ -17,6 +17,7 @@ This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file using System; using System.Collections.Generic; +using System.Linq; using Android.App; using Android.Content; using Android.OS; @@ -444,12 +445,9 @@ namespace keepass2android TextView valueView = (TextView)view.FindViewById(Resource.Id.value); String value = valueView.Text; - - bool protect = true; - ProtectedString initialString = State.EntryInDatabase.Strings.Get(key); - if (initialString != null) - protect = initialString.IsProtected; + + bool protect = ((CheckBox) view.FindViewById(Resource.Id.protection)).Checked; entry.Strings.Set(key, new ProtectedString(protect, value)); } @@ -648,7 +646,7 @@ namespace keepass2android ViewGroup binariesGroup = (ViewGroup)FindViewById(Resource.Id.binaries); binariesGroup.RemoveAllViews(); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.WrapContent); - foreach (KeyValuePair pair in State.Entry.Binaries) + foreach (KeyValuePair pair in State.Entry.Binaries.OrderBy(p => p.Key) ) { String key = pair.Key; Button binaryButton = new Button(this) {Text = key}; @@ -790,10 +788,68 @@ namespace keepass2android ((TextView)ees.FindViewById(Resource.Id.title)).TextChanged += (sender, e) => State.EntryModified = true; ((TextView)ees.FindViewById(Resource.Id.value)).Text = pair.Value.ReadString(); ((TextView)ees.FindViewById(Resource.Id.value)).TextChanged += (sender, e) => State.EntryModified = true; - ees.FindViewById(Resource.Id.delete).Click += (sender, e) => DeleteAdvancedString((View)sender); + + ((CheckBox)ees.FindViewById(Resource.Id.protection)).Checked = pair.Value.IsProtected; + + //ees.FindViewById(Resource.Id.edit_extra).Click += (sender, e) => DeleteAdvancedString((View)sender); + ees.FindViewById(Resource.Id.edit_extra).Click += (sender, e) => EditAdvancedString((View)sender); return ees; } - + + private void EditAdvancedString(View sender) + { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + View dlgView = LayoutInflater.Inflate(Resource.Layout.edit_extra_string_dialog, null); + builder.SetView(dlgView); + builder.SetNegativeButton(Android.Resource.String.Cancel, (o, args) => { }); + builder.SetPositiveButton(Android.Resource.String.Ok, (o, args) => + { + CopyFieldFromExtraDialog(sender, o, Resource.Id.title); + CopyFieldFromExtraDialog(sender, o, Resource.Id.value); + CopyCheckboxFromExtraDialog(sender, o, Resource.Id.protection); + }); + Dialog dialog = builder.Create(); + + //setup delete button: + var deleteButton = dlgView.FindViewById