Groups can be edited

This commit is contained in:
Philipp Crocoll 2013-09-03 22:58:15 +02:00
parent 320f5e1fea
commit b9dce51afa
8 changed files with 785 additions and 628 deletions

View File

@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="database\CheckDatabaseForChanges.cs" />
<Compile Include="database\edit\EditGroup.cs" />
<Compile Include="database\edit\MoveElement.cs" />
<Compile Include="database\SynchronizeCachedDatabase.cs" />
<Compile Include="Io\BuiltInFileStorage.cs" />

View 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();
}
}
}
}

View File

@ -164,15 +164,6 @@ namespace keepass2android
{
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:
break;

View File

@ -71,6 +71,30 @@ namespace keepass2android
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)
{
AppTask.SetActivityResult(this, KeePass.ExitCloseAfterTaskComplete);
@ -491,6 +515,10 @@ namespace keepass2android
}
public void EditGroup(PwGroup pwGroup)
{
GroupEditActivity.Launch(this, pwGroup.ParentGroup, pwGroup);
}
}
}

View File

@ -21,6 +21,7 @@ using Android.Content;
using Android.OS;
using Android.Widget;
using KeePassLib;
using KeePassLib.Utility;
namespace keepass2android
{
@ -30,24 +31,38 @@ namespace keepass2android
public const String KeyParent = "parent";
public const String KeyName = "name";
public const String KeyIconId = "icon_id";
public const String KeyCustomIconId = "custom_icon_id";
public const string KeyGroupUuid = "group_uuid";
private int _selectedIconId;
private PwUuid _selectedCustomIconId = PwUuid.Zero;
private PwGroup _groupToEdit;
public static void Launch(Activity act, PwGroup pw)
public static void Launch(Activity act, PwGroup parentGroup)
{
Intent i = new Intent(act, typeof(GroupEditActivity));
PwGroup parent = pw;
PwGroup parent = parentGroup;
i.PutExtra(KeyParent, parent.Uuid.ToHexString());
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)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.group_edit);
SetTitle (Resource.String.add_group_title);
ImageButton iconButton = (ImageButton)FindViewById (Resource.Id.icon_button);
iconButton.Click += (sender, e) =>
@ -67,6 +82,10 @@ namespace keepass2android
intent.PutExtra (KeyName, name);
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);
Finish ();
@ -75,6 +94,23 @@ namespace keepass2android
}
};
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);
cancel.Click += (sender, e) => {
@ -91,6 +127,7 @@ namespace keepass2android
{
case EntryEditActivity.ResultOkIconPicker:
_selectedIconId = data.Extras.GetInt(IconPickerActivity.KeyIconId);
_selectedCustomIconId = PwUuid.Zero;
ImageButton currIconButton = (ImageButton) FindViewById(Resource.Id.icon_button);
currIconButton.SetImageResource(Icons.IconToResId((PwIcon)_selectedIconId));
break;

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@
<string name="add_url_entry">Create entry for URL</string>
<string name="add_group">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_colon">Algorithm</string>
<string name="app_name">Keepass2Android</string>

View File

@ -36,6 +36,7 @@ namespace keepass2android.view
private const int MenuOpen = Menu.First;
private const int MenuDelete = MenuOpen + 1;
private const int MenuMove = MenuDelete + 1;
private const int MenuEdit = MenuDelete + 2;
public static PwGroupView GetInstance(GroupBaseActivity act, PwGroup pw) {
@ -108,12 +109,12 @@ namespace keepass2android.view
menu.Add(0, MenuOpen, 0, Resource.String.menu_open);
menu.Add(0, MenuDelete, 0, Resource.String.menu_delete);
menu.Add(0, MenuMove, 0, Resource.String.menu_move);
menu.Add(0, MenuEdit, 0, Resource.String.menu_edit);
}
public override bool OnContextItemSelected(IMenuItem item)
{
switch ( item.ItemId ) {
case MenuOpen:
LaunchGroup();
return true;
@ -126,6 +127,9 @@ namespace keepass2android.view
case MenuMove:
_groupBaseActivity.StartTask(new MoveElementTask { Uuid = _pwGroup.Uuid });
return true;
case MenuEdit:
_groupBaseActivity.EditGroup(_pwGroup);
return true;
default:
return false;
}