mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-12-22 23:18:48 -05:00
Groups can be edited
This commit is contained in:
parent
320f5e1fea
commit
b9dce51afa
@ -52,6 +52,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="database\CheckDatabaseForChanges.cs" />
|
<Compile Include="database\CheckDatabaseForChanges.cs" />
|
||||||
|
<Compile Include="database\edit\EditGroup.cs" />
|
||||||
<Compile Include="database\edit\MoveElement.cs" />
|
<Compile Include="database\edit\MoveElement.cs" />
|
||||||
<Compile Include="database\SynchronizeCachedDatabase.cs" />
|
<Compile Include="database\SynchronizeCachedDatabase.cs" />
|
||||||
<Compile Include="Io\BuiltInFileStorage.cs" />
|
<Compile Include="Io\BuiltInFileStorage.cs" />
|
||||||
|
92
src/Kp2aBusinessLogic/database/edit/EditGroup.cs
Normal file
92
src/Kp2aBusinessLogic/database/edit/EditGroup.cs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Keepass2Android, Copyright 2013 Philipp Crocoll. This file is based on Keepassdroid, Copyright Brian Pellin.
|
||||||
|
|
||||||
|
Keepass2Android is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Keepass2Android is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Keepass2Android. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using Android.Content;
|
||||||
|
using KeePassLib;
|
||||||
|
|
||||||
|
namespace keepass2android
|
||||||
|
{
|
||||||
|
|
||||||
|
public class EditGroup : RunnableOnFinish {
|
||||||
|
internal Database Db
|
||||||
|
{
|
||||||
|
get { return _app.GetDb(); }
|
||||||
|
}
|
||||||
|
private IKp2aApp _app;
|
||||||
|
private readonly String _name;
|
||||||
|
private readonly PwIcon _iconId;
|
||||||
|
private readonly PwUuid _customIconId;
|
||||||
|
internal PwGroup Group;
|
||||||
|
readonly Context _ctx;
|
||||||
|
|
||||||
|
public EditGroup(Context ctx, IKp2aApp app, String name, PwIcon iconid, PwUuid customIconId, PwGroup group, OnFinish finish)
|
||||||
|
: base(finish)
|
||||||
|
{
|
||||||
|
_ctx = ctx;
|
||||||
|
_name = name;
|
||||||
|
_iconId = iconid;
|
||||||
|
Group = group;
|
||||||
|
_customIconId = customIconId;
|
||||||
|
_app = app;
|
||||||
|
|
||||||
|
_onFinishToRun = new AfterEdit(this, OnFinishToRun);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void Run() {
|
||||||
|
// modify group:
|
||||||
|
Group.Name = _name;
|
||||||
|
Group.IconId = _iconId;
|
||||||
|
Group.CustomIconUuid = _customIconId;
|
||||||
|
|
||||||
|
// Commit to disk
|
||||||
|
SaveDb save = new SaveDb(_ctx, _app, OnFinishToRun);
|
||||||
|
save.SetStatusLogger(StatusLogger);
|
||||||
|
save.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AfterEdit : OnFinish {
|
||||||
|
readonly EditGroup _editGroup;
|
||||||
|
|
||||||
|
public AfterEdit(EditGroup editGroup, OnFinish finish)
|
||||||
|
: base(finish)
|
||||||
|
{
|
||||||
|
_editGroup = editGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void Run() {
|
||||||
|
|
||||||
|
if ( Success ) {
|
||||||
|
// Mark parent group dirty
|
||||||
|
_editGroup.Db.Dirty.Add(_editGroup.Group.ParentGroup);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
_editGroup._app.LockDatabase(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -164,21 +164,12 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
switch (resultCode)
|
switch (resultCode)
|
||||||
{
|
{
|
||||||
case Result.Ok:
|
|
||||||
String groupName = data.Extras.GetString(GroupEditActivity.KeyName);
|
|
||||||
int groupIconId = data.Extras.GetInt(GroupEditActivity.KeyIconId);
|
|
||||||
GroupBaseActivity act = this;
|
|
||||||
Handler handler = new Handler();
|
|
||||||
AddGroup task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, Group, new RefreshTask(handler, this), false);
|
|
||||||
ProgressTask pt = new ProgressTask(App.Kp2a, act, task);
|
|
||||||
pt.Run();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Result.Canceled:
|
case Result.Canceled:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
base.OnActivityResult(requestCode, resultCode, data);
|
base.OnActivityResult(requestCode, resultCode, data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,30 @@ namespace keepass2android
|
|||||||
|
|
||||||
AppTask.TryGetFromActivityResult(data, ref AppTask);
|
AppTask.TryGetFromActivityResult(data, ref AppTask);
|
||||||
|
|
||||||
|
if (resultCode == Result.Ok)
|
||||||
|
{
|
||||||
|
String groupName = data.Extras.GetString(GroupEditActivity.KeyName);
|
||||||
|
int groupIconId = data.Extras.GetInt(GroupEditActivity.KeyIconId);
|
||||||
|
PwUuid groupCustomIconId =
|
||||||
|
new PwUuid(MemUtil.HexStringToByteArray(data.Extras.GetString(GroupEditActivity.KeyCustomIconId)));
|
||||||
|
String strGroupUuid = data.Extras.GetString(GroupEditActivity.KeyGroupUuid);
|
||||||
|
GroupBaseActivity act = this;
|
||||||
|
Handler handler = new Handler();
|
||||||
|
RunnableOnFinish task;
|
||||||
|
if (strGroupUuid == null)
|
||||||
|
{
|
||||||
|
task = AddGroup.GetInstance(this, App.Kp2a, groupName, groupIconId, Group, new RefreshTask(handler, this), false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PwUuid groupUuid = new PwUuid(MemUtil.HexStringToByteArray(strGroupUuid));
|
||||||
|
task = new EditGroup(this, App.Kp2a, groupName, (PwIcon) groupIconId, groupCustomIconId, App.Kp2a.GetDb().Groups[groupUuid],
|
||||||
|
new RefreshTask(handler, this));
|
||||||
|
}
|
||||||
|
ProgressTask pt = new ProgressTask(App.Kp2a, act, task);
|
||||||
|
pt.Run();
|
||||||
|
}
|
||||||
|
|
||||||
if (resultCode == KeePass.ExitCloseAfterTaskComplete)
|
if (resultCode == KeePass.ExitCloseAfterTaskComplete)
|
||||||
{
|
{
|
||||||
AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete);
|
AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete);
|
||||||
@ -491,6 +515,10 @@ namespace keepass2android
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void EditGroup(PwGroup pwGroup)
|
||||||
|
{
|
||||||
|
GroupEditActivity.Launch(this, pwGroup.ParentGroup, pwGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ using Android.Content;
|
|||||||
using Android.OS;
|
using Android.OS;
|
||||||
using Android.Widget;
|
using Android.Widget;
|
||||||
using KeePassLib;
|
using KeePassLib;
|
||||||
|
using KeePassLib.Utility;
|
||||||
|
|
||||||
namespace keepass2android
|
namespace keepass2android
|
||||||
{
|
{
|
||||||
@ -30,25 +31,39 @@ namespace keepass2android
|
|||||||
public const String KeyParent = "parent";
|
public const String KeyParent = "parent";
|
||||||
public const String KeyName = "name";
|
public const String KeyName = "name";
|
||||||
public const String KeyIconId = "icon_id";
|
public const String KeyIconId = "icon_id";
|
||||||
|
public const String KeyCustomIconId = "custom_icon_id";
|
||||||
|
public const string KeyGroupUuid = "group_uuid";
|
||||||
|
|
||||||
private int _selectedIconId;
|
private int _selectedIconId;
|
||||||
|
private PwUuid _selectedCustomIconId = PwUuid.Zero;
|
||||||
public static void Launch(Activity act, PwGroup pw)
|
private PwGroup _groupToEdit;
|
||||||
|
|
||||||
|
public static void Launch(Activity act, PwGroup parentGroup)
|
||||||
{
|
{
|
||||||
Intent i = new Intent(act, typeof(GroupEditActivity));
|
Intent i = new Intent(act, typeof(GroupEditActivity));
|
||||||
|
|
||||||
PwGroup parent = pw;
|
PwGroup parent = parentGroup;
|
||||||
i.PutExtra(KeyParent, parent.Uuid.ToHexString());
|
i.PutExtra(KeyParent, parent.Uuid.ToHexString());
|
||||||
|
|
||||||
act.StartActivityForResult(i, 0);
|
act.StartActivityForResult(i, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Launch(Activity act, PwGroup parentGroup, PwGroup groupToEdit)
|
||||||
|
{
|
||||||
|
Intent i = new Intent(act, typeof(GroupEditActivity));
|
||||||
|
|
||||||
|
PwGroup parent = parentGroup;
|
||||||
|
i.PutExtra(KeyParent, parent.Uuid.ToHexString());
|
||||||
|
i.PutExtra(KeyGroupUuid, groupToEdit.Uuid.ToHexString());
|
||||||
|
|
||||||
|
act.StartActivityForResult(i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnCreate (Bundle savedInstanceState)
|
protected override void OnCreate (Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
base.OnCreate (savedInstanceState);
|
base.OnCreate (savedInstanceState);
|
||||||
SetContentView (Resource.Layout.group_edit);
|
SetContentView (Resource.Layout.group_edit);
|
||||||
SetTitle (Resource.String.add_group_title);
|
|
||||||
|
|
||||||
ImageButton iconButton = (ImageButton)FindViewById (Resource.Id.icon_button);
|
ImageButton iconButton = (ImageButton)FindViewById (Resource.Id.icon_button);
|
||||||
iconButton.Click += (sender, e) =>
|
iconButton.Click += (sender, e) =>
|
||||||
{
|
{
|
||||||
@ -67,6 +82,10 @@ namespace keepass2android
|
|||||||
|
|
||||||
intent.PutExtra (KeyName, name);
|
intent.PutExtra (KeyName, name);
|
||||||
intent.PutExtra (KeyIconId, _selectedIconId);
|
intent.PutExtra (KeyIconId, _selectedIconId);
|
||||||
|
intent.PutExtra(KeyCustomIconId, MemUtil.ByteArrayToHexString(_selectedCustomIconId.UuidBytes));
|
||||||
|
if (_groupToEdit != null)
|
||||||
|
intent.PutExtra(KeyGroupUuid, MemUtil.ByteArrayToHexString(_groupToEdit.Uuid.UuidBytes));
|
||||||
|
|
||||||
SetResult (Result.Ok, intent);
|
SetResult (Result.Ok, intent);
|
||||||
|
|
||||||
Finish ();
|
Finish ();
|
||||||
@ -74,6 +93,23 @@ namespace keepass2android
|
|||||||
Toast.MakeText (this, Resource.String.error_no_name, ToastLength.Long).Show ();
|
Toast.MakeText (this, Resource.String.error_no_name, ToastLength.Long).Show ();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (Intent.HasExtra(KeyGroupUuid))
|
||||||
|
{
|
||||||
|
string groupUuid = Intent.Extras.GetString(KeyGroupUuid);
|
||||||
|
_groupToEdit = App.Kp2a.GetDb().Groups[new PwUuid(MemUtil.HexStringToByteArray(groupUuid))];
|
||||||
|
_selectedIconId = (int) _groupToEdit.IconId;
|
||||||
|
_selectedCustomIconId = _groupToEdit.CustomIconUuid;
|
||||||
|
TextView nameField = (TextView)FindViewById(Resource.Id.group_name);
|
||||||
|
nameField.Text = _groupToEdit.Name;
|
||||||
|
App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iconButton, Resources, App.Kp2a.GetDb().KpDatabase, _groupToEdit.IconId, _groupToEdit.CustomIconUuid);
|
||||||
|
SetTitle(Resource.String.edit_group_title);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetTitle(Resource.String.add_group_title);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Button cancel = (Button)FindViewById (Resource.Id.cancel);
|
Button cancel = (Button)FindViewById (Resource.Id.cancel);
|
||||||
@ -89,11 +125,12 @@ namespace keepass2android
|
|||||||
{
|
{
|
||||||
switch ((int)resultCode)
|
switch ((int)resultCode)
|
||||||
{
|
{
|
||||||
case EntryEditActivity.ResultOkIconPicker:
|
case EntryEditActivity.ResultOkIconPicker:
|
||||||
_selectedIconId = data.Extras.GetInt(IconPickerActivity.KeyIconId);
|
_selectedIconId = data.Extras.GetInt(IconPickerActivity.KeyIconId);
|
||||||
ImageButton currIconButton = (ImageButton) FindViewById(Resource.Id.icon_button);
|
_selectedCustomIconId = PwUuid.Zero;
|
||||||
currIconButton.SetImageResource(Icons.IconToResId((PwIcon)_selectedIconId));
|
ImageButton currIconButton = (ImageButton) FindViewById(Resource.Id.icon_button);
|
||||||
break;
|
currIconButton.SetImageResource(Icons.IconToResId((PwIcon)_selectedIconId));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1183
src/keepass2android/Resources/Resource.designer.cs
generated
1183
src/keepass2android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,7 @@
|
|||||||
<string name="add_url_entry">Create entry for URL</string>
|
<string name="add_url_entry">Create entry for URL</string>
|
||||||
<string name="add_group">Add group</string>
|
<string name="add_group">Add group</string>
|
||||||
<string name="add_group_title">Add Group</string>
|
<string name="add_group_title">Add Group</string>
|
||||||
|
<string name="edit_group_title">Edit Group</string>
|
||||||
<string name="algorithm">Algorithm</string>
|
<string name="algorithm">Algorithm</string>
|
||||||
<string name="algorithm_colon">Algorithm</string>
|
<string name="algorithm_colon">Algorithm</string>
|
||||||
<string name="app_name">Keepass2Android</string>
|
<string name="app_name">Keepass2Android</string>
|
||||||
|
@ -36,6 +36,7 @@ namespace keepass2android.view
|
|||||||
private const int MenuOpen = Menu.First;
|
private const int MenuOpen = Menu.First;
|
||||||
private const int MenuDelete = MenuOpen + 1;
|
private const int MenuDelete = MenuOpen + 1;
|
||||||
private const int MenuMove = MenuDelete + 1;
|
private const int MenuMove = MenuDelete + 1;
|
||||||
|
private const int MenuEdit = MenuDelete + 2;
|
||||||
|
|
||||||
public static PwGroupView GetInstance(GroupBaseActivity act, PwGroup pw) {
|
public static PwGroupView GetInstance(GroupBaseActivity act, PwGroup pw) {
|
||||||
|
|
||||||
@ -108,26 +109,29 @@ namespace keepass2android.view
|
|||||||
menu.Add(0, MenuOpen, 0, Resource.String.menu_open);
|
menu.Add(0, MenuOpen, 0, Resource.String.menu_open);
|
||||||
menu.Add(0, MenuDelete, 0, Resource.String.menu_delete);
|
menu.Add(0, MenuDelete, 0, Resource.String.menu_delete);
|
||||||
menu.Add(0, MenuMove, 0, Resource.String.menu_move);
|
menu.Add(0, MenuMove, 0, Resource.String.menu_move);
|
||||||
|
menu.Add(0, MenuEdit, 0, Resource.String.menu_edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnContextItemSelected(IMenuItem item)
|
public override bool OnContextItemSelected(IMenuItem item)
|
||||||
{
|
{
|
||||||
switch ( item.ItemId ) {
|
switch ( item.ItemId ) {
|
||||||
|
case MenuOpen:
|
||||||
case MenuOpen:
|
LaunchGroup();
|
||||||
LaunchGroup();
|
return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
case MenuDelete:
|
case MenuDelete:
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
DeleteGroup task = new DeleteGroup(Context, App.Kp2a, _pwGroup, new GroupBaseActivity.AfterDeleteGroup(handler, _groupBaseActivity));
|
DeleteGroup task = new DeleteGroup(Context, App.Kp2a, _pwGroup, new GroupBaseActivity.AfterDeleteGroup(handler, _groupBaseActivity));
|
||||||
task.Start();
|
task.Start();
|
||||||
return true;
|
return true;
|
||||||
case MenuMove:
|
case MenuMove:
|
||||||
_groupBaseActivity.StartTask(new MoveElementTask { Uuid = _pwGroup.Uuid });
|
_groupBaseActivity.StartTask(new MoveElementTask { Uuid = _pwGroup.Uuid });
|
||||||
return true;
|
return true;
|
||||||
default:
|
case MenuEdit:
|
||||||
return false;
|
_groupBaseActivity.EditGroup(_pwGroup);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user