From de18aefd7ba46017f090971d7682fc6fe295abca Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Wed, 4 Apr 2018 05:01:19 +0200 Subject: [PATCH] introduce vdots for file select list, prepare GUI for editing of storage locations --- src/Kp2aBusinessLogic/IKp2aApp.cs | 1 + .../Resources/layout/file_row.xml | 32 +++- .../Resources/values/strings.xml | 1 + src/keepass2android/app/App.cs | 6 +- .../fileselect/FileSelectActivity.cs | 143 +++++++++++------- 5 files changed, 119 insertions(+), 64 deletions(-) diff --git a/src/Kp2aBusinessLogic/IKp2aApp.cs b/src/Kp2aBusinessLogic/IKp2aApp.cs index de30aae6..c1f5dbeb 100644 --- a/src/Kp2aBusinessLogic/IKp2aApp.cs +++ b/src/Kp2aBusinessLogic/IKp2aApp.cs @@ -112,5 +112,6 @@ namespace keepass2android #if !NoNet ICertificateErrorHandler CertificateErrorHandler { get; } #endif + bool CanEditIoc(IOConnectionInfo ioc); } } \ No newline at end of file diff --git a/src/keepass2android/Resources/layout/file_row.xml b/src/keepass2android/Resources/layout/file_row.xml index 03188fa5..8c25e70c 100644 --- a/src/keepass2android/Resources/layout/file_row.xml +++ b/src/keepass2android/Resources/layout/file_row.xml @@ -17,10 +17,28 @@ You should have received a copy of the GNU General Public License along with Keepass2Android. If not, see . --> - \ No newline at end of file + + + + + diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index 2c3a00f3..938e5e96 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -218,6 +218,7 @@ Remembers the location of key files Save key file Remove + Edit Rijndael (AES) Root diff --git a/src/keepass2android/app/App.cs b/src/keepass2android/app/App.cs index 47067571..c21e3682 100644 --- a/src/keepass2android/app/App.cs +++ b/src/keepass2android/app/App.cs @@ -611,9 +611,13 @@ namespace keepass2android { get { return new CertificateErrorHandlerImpl(this); } } + public bool CanEditIoc(IOConnectionInfo ioc) + { + return false; + } - public class CertificateErrorHandlerImpl : Java.Lang.Object, Keepass2android.Javafilestorage.ICertificateErrorHandler + public class CertificateErrorHandlerImpl : Java.Lang.Object, Keepass2android.Javafilestorage.ICertificateErrorHandler { private readonly Kp2aApp _app; diff --git a/src/keepass2android/fileselect/FileSelectActivity.cs b/src/keepass2android/fileselect/FileSelectActivity.cs index a6b0a953..ab514b76 100644 --- a/src/keepass2android/fileselect/FileSelectActivity.cs +++ b/src/keepass2android/fileselect/FileSelectActivity.cs @@ -200,35 +200,89 @@ namespace keepass2android outState.PutBoolean(BundleKeyRecentMode, _recentMode); } - - - class MyViewBinder: Java.Lang.Object, SimpleCursorAdapter.IViewBinder - { - private readonly Kp2aApp _app; - public MyViewBinder(Kp2aApp app) - { - _app = app; - } + class MyCursorAdapter: CursorAdapter + { + private LayoutInflater cursorInflater; + private IKp2aApp _app; - public bool SetViewValue(View view, ICursor cursor, int columnIndex) - { - if (columnIndex == 1) - { - String path = cursor.GetString(columnIndex); - TextView textView = (TextView)view; - IOConnectionInfo ioc = new IOConnectionInfo {Path = path}; - var fileStorage = _app.GetFileStorage(ioc); - textView.Text = fileStorage.GetDisplayName(ioc); - textView.Tag = ioc.Path; - return true; - } + public MyCursorAdapter(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) + { + } - return false; - } - } - - private void FillData() + public MyCursorAdapter(Context context, ICursor c, IKp2aApp app) : base(context, c) + { + _app = app; + } + + public MyCursorAdapter(Context context, ICursor c, bool autoRequery) : base(context, c, autoRequery) + { + } + + public MyCursorAdapter(Context context, ICursor c, CursorAdapterFlags flags) : base(context, c, flags) + { + + } + + public override void BindView(View view, Context context, ICursor cursor) + { + String path = cursor.GetString(1); + + TextView textView = view.FindViewById(Resource.Id.file_filename); + IOConnectionInfo ioc = new IOConnectionInfo { Path = path }; + var fileStorage = _app.GetFileStorage(ioc); + textView.Text = fileStorage.GetDisplayName(ioc); + textView.Tag = ioc.Path; + + } + + public override View NewView(Context context, ICursor cursor, ViewGroup parent) + { + if (cursorInflater == null) + cursorInflater = (LayoutInflater)context.GetSystemService( Context.LayoutInflaterService); + View view = cursorInflater.Inflate(Resource.Layout.file_row, parent, false); + + view.FindViewById(Resource.Id.group_name_vdots).Click += (sender, args) => + { + Handler handler = new Handler(Looper.MainLooper); + handler.Post(() => + { + PopupMenu popupMenu = new PopupMenu(context, view.FindViewById(Resource.Id.group_name_vdots)); + + AccessManager.PreparePopup(popupMenu); + int remove = 0; + int edit = 1; + popupMenu.Menu.Add(0, remove, 0, context.GetString(Resource.String.remove_from_filelist)).SetIcon(Resource.Drawable.ic_menu_delete_grey); + + TextView textView = view.FindViewById(Resource.Id.file_filename); + + String filename = (string)textView.Tag; + IOConnectionInfo ioc = new IOConnectionInfo { Path = filename }; + if (_app.CanEditIoc(ioc)) + { + popupMenu.Menu.Add(0, edit, 0, context.GetString(Resource.String.edit)).SetIcon(Resource.Drawable.ic_menu_edit_grey); + } + + + popupMenu.MenuItemClick += delegate (object sender2, PopupMenu.MenuItemClickEventArgs args2) + { + if (args2.Item.ItemId == remove) + { + App.Kp2a.FileDbHelper.DeleteFile(filename); + + cursor.Requery(); + } + }; + popupMenu.Show(); + }); + }; + + return view; + } + } + + + private void FillData() { // Get all of the rows from the database and create the item list ICursor filesCursor = _dbHelper.FetchAllFiles(); @@ -241,15 +295,15 @@ namespace keepass2android // and an array of the fields we want to bind those fields to (in this // case just text1) int[] to = new[] { Resource.Id.file_filename }; - + /* // Now create a simple cursor adapter and set it to display SimpleCursorAdapter recentFilesAdapter = new SimpleCursorAdapter(this, Resource.Layout.file_row, filesCursor, from, to); recentFilesAdapter.ViewBinder = new MyViewBinder(App.Kp2a); - - FragmentManager.FindFragmentById(Resource.Id.recent_files).SetAdapter(recentFilesAdapter); + */ + FragmentManager.FindFragmentById(Resource.Id.recent_files).SetAdapter(new MyCursorAdapter(this, filesCursor,App.Kp2a)); } @@ -284,9 +338,9 @@ namespace keepass2android Finish(); } - public void OnListItemClick(ListView l, View v, int position, long id) { - - ICursor cursor = _dbHelper.FetchFile(id); + public void OnListItemClick(ListView l, View v, int position, long id) + { + ICursor cursor = _dbHelper.FetchFile(id); StartManagingCursor(cursor); IOConnectionInfo ioc = _dbHelper.CursorToIoc(cursor); @@ -462,30 +516,7 @@ namespace keepass2android cursor.Requery(); } - public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo) - { - base.OnCreateContextMenu(menu, v, menuInfo); - menu.Add(0, Menu.First, 0, Resource.String.remove_from_filelist); - } - - public override bool OnContextItemSelected(IMenuItem item) - { - if (item.ItemId == Menu.First) - { - AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo)item.MenuInfo; - - TextView tv = (TextView)acmi.TargetView; - String filename = (string)tv.Tag; - App.Kp2a.FileDbHelper.DeleteFile(filename); - - RefreshList(); - - - return true; - } - return base.OnContextItemSelected(item); - - } + } }