Add context menu to Search Result

This commit is contained in:
Jareth Lomson 2014-05-25 20:09:06 +02:00
parent 0c982e455e
commit 3eff8bfd90
8 changed files with 938 additions and 637 deletions

View File

@ -121,6 +121,17 @@ namespace keepass2android
internal AppTask AppTask; internal AppTask AppTask;
protected GroupView GroupView; protected GroupView GroupView;
private String strCachedGroupUuid = null;
public String UuidGroup {
get {
if (strCachedGroupUuid == null) {
strCachedGroupUuid = MemUtil.ByteArrayToHexString (Group.Uuid.UuidBytes);
}
return strCachedGroupUuid;
}
}
protected override void OnResume() { protected override void OnResume() {
base.OnResume(); base.OnResume();

View File

@ -84,6 +84,7 @@ namespace keepass2android
public const Result ExitClose = Result.FirstUser + 7; public const Result ExitClose = Result.FirstUser + 7;
public const Result ExitFileStorageSelectionOk = Result.FirstUser + 8; public const Result ExitFileStorageSelectionOk = Result.FirstUser + 8;
public const Result ResultOkPasswordGenerator = Result.FirstUser + 9; public const Result ResultOkPasswordGenerator = Result.FirstUser + 9;
public const Result ExitMoveEntry = Result.FirstUser + 10;
AppTask _appTask; AppTask _appTask;
private ActivityDesign _design; private ActivityDesign _design;

File diff suppressed because it is too large Load Diff

View File

@ -129,6 +129,7 @@
<string name="menu_db_settings">Database settings</string> <string name="menu_db_settings">Database settings</string>
<string name="menu_delete">Delete</string> <string name="menu_delete">Delete</string>
<string name="menu_move">Move to another group</string> <string name="menu_move">Move to another group</string>
<string name="menu_navigate">Navigate to this group</string>
<string name="menu_donate">Donate a beer...</string> <string name="menu_donate">Donate a beer...</string>
<string name="menu_edit">Edit</string> <string name="menu_edit">Edit</string>
<string name="menu_hide_password">Hide Password</string> <string name="menu_hide_password">Hide Password</string>

View File

@ -71,6 +71,53 @@ namespace keepass2android
#endregion #endregion
} }
/// <summary>
/// represents data stored in an intent or bundle as extra int
/// </summary>
public class IntExtra: IExtra
{
public string Key { get; set; }
public int Value{ get; set; }
#region IExtra implementation
public void ToBundle(Bundle b)
{
b.PutInt(Key, Value);
}
public void ToIntent(Intent i)
{
i.PutExtra(Key, Value);
}
#endregion
}
/// <summary>
/// represents data stored in an intent or bundle as extra string array
/// </summary>
public class StringArrayExtra : IExtra
{
public string Key { get; set; }
public string[] Value { get; set; }
#region IExtra implementation
public void ToBundle(Bundle b)
{
b.PutStringArray(Key, Value);
}
public void ToIntent(Intent i)
{
i.PutExtra(Key, Value);
}
#endregion
}
/// <summary> /// <summary>
/// base class for "tasks": these are things the user wants to do and which require several activities /// base class for "tasks": these are things the user wants to do and which require several activities
/// </summary> /// </summary>
@ -473,6 +520,7 @@ namespace keepass2android
} }
/// <summary> /// <summary>
/// User is about to move an entry or group to another group /// User is about to move an entry or group to another group
/// </summary> /// </summary>
@ -614,5 +662,183 @@ namespace keepass2android
base.CompleteOnCreateEntryActivity(activity); base.CompleteOnCreateEntryActivity(activity);
} }
} }
/// <summary>
/// Navigate to a folder and open a Task (appear in SearchResult)
/// </summary>
public abstract class NavigateAndLaunchTask: AppTask
{
// All group Uuid are stored in guuidKey + indice
// The last one is the destination group
public const String numberOfGroupsKey = "NumberOfGroups";
public const String gUuidKey = "gUuidKey";
#if INCLUDE_DEBUG_MOVE_GROUPNAME
public const String gNameKey = "gNameKey";
private LinkedList<string> groupName;
#endif
private LinkedList<string> groupUuid;
protected AppTask taskToBeLaunchAfterNavigation;
public NavigateAndLaunchTask() {
this.taskToBeLaunchAfterNavigation = new NullTask();
}
protected NavigateAndLaunchTask(PwGroup groups, AppTask taskToBeLaunchAfterNavigation) {
this.taskToBeLaunchAfterNavigation = taskToBeLaunchAfterNavigation;
populateGroupsUuid (groups);
}
public void populateGroupsUuid(PwGroup groups) {
groupUuid = new LinkedList<String>{};
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName = new LinkedList<String>{};
#endif
PwGroup readGroup = groups;
while (readGroup != null) {
groupUuid.AddFirst (MemUtil.ByteArrayToHexString (readGroup.Uuid.UuidBytes));
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName.AddFirst (readGroup.Name);
#endif
readGroup = readGroup.ParentGroup;
}
}
/// <summary>
/// Loads the parameters of the task from the given bundle. Embeded task is not setup from this bundle
/// </summary>
/// <param name="b">The bundle component.</param>
public override void Setup(Bundle b)
{
int numberOfGroups = b.GetInt(numberOfGroupsKey);
groupUuid = new LinkedList<String>{};
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName = new LinkedList<String>{};
#endif
int i = 0;
while (i < numberOfGroups) {
groupUuid.AddLast ( b.GetString (gUuidKey + i) ) ;
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName.AddLast ( b.GetString (gNameKey + i) );
#endif
i++;
}
}
public override IEnumerable<IExtra> Extras
{
get
{
// Return Navigate group Extras
IEnumerator<String> eGroupKeys = groupUuid.GetEnumerator ();
#if INCLUDE_DEBUG_MOVE_GROUPNAME
IEnumerator<String> eGroupName = groupName.GetEnumerator ();
#endif
int i = 0;
while (eGroupKeys.MoveNext()) {
yield return new StringExtra { Key = gUuidKey + i.ToString (), Value = eGroupKeys.Current };
#if INCLUDE_DEBUG_MOVE_GROUPNAME
eGroupName.MoveNext();
yield return new StringExtra { Key = gNameKey + i.ToString (), Value = eGroupName.Current };
#endif
i++;
}
yield return new IntExtra{ Key = numberOfGroupsKey, Value = i };
// Return afterTaskExtras
IEnumerator<IExtra> afterTaskExtras = taskToBeLaunchAfterNavigation.Extras.GetEnumerator();
while (afterTaskExtras.MoveNext ()) {
yield return afterTaskExtras.Current;
}
}
}
public override void StartInGroupActivity(GroupBaseActivity groupBaseActivity)
{
base.StartInGroupActivity(groupBaseActivity);
if (GroupIsFound(groupBaseActivity) ){ // Group has been found: stop here
groupBaseActivity.StartTask (taskToBeLaunchAfterNavigation);
return;
} else if (groupUuid.Contains(groupBaseActivity.UuidGroup)) { // Need to go up in groups tree
// Get next Group Uuid
String nextGroupUuid = groupUuid.Find (groupBaseActivity.UuidGroup).Next.Value;
PwUuid nextGroupPwUuid = new PwUuid (MemUtil.HexStringToByteArray (nextGroupUuid));
// Create Group Activity
PwGroup nextGroup = App.Kp2a.GetDb ().Groups [nextGroupPwUuid];
GroupActivity.Launch (groupBaseActivity, nextGroup, this);
return;
} else { // Need to go down in groups tree
SetActivityResult(groupBaseActivity, KeePass.ExitMoveEntry);
groupBaseActivity.Finish();
}
}
public override void SetupGroupBaseActivityButtons(GroupBaseActivity groupBaseActivity)
{
return;
}
public bool GroupIsFound(GroupBaseActivity groupBaseActivity)
{
return groupUuid.Last.Value.Equals (groupBaseActivity.UuidGroup);
}
}
public class NavigateToFolder: NavigateAndLaunchTask {
public NavigateToFolder():base() {
}
public NavigateToFolder(PwGroup groups): base(groups, new NullTask()) {
return;
}
}
public class NavigateToFolderAndLaunchMoveElementTask: NavigateAndLaunchTask {
public NavigateToFolderAndLaunchMoveElementTask():base(){
}
public NavigateToFolderAndLaunchMoveElementTask(PwGroup groups, PwUuid Uuid):
base(groups, new MoveElementTask() { Uuid = Uuid }) {
}
public override void Setup(Bundle b) {
base.Setup(b);
taskToBeLaunchAfterNavigation = new MoveElementTask ();
taskToBeLaunchAfterNavigation.Setup (b);
}
}
} }

View File

@ -28,7 +28,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;INCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE;EXCLUDE_KEYTRANSFORM</DefineConstants> <DefineConstants>DEBUG;EXCLUDE_TWOFISH;EXCLUDE_KEYBOARD;INCLUDE_FILECHOOSER;EXCLUDE_JAVAFILESTORAGE;EXCLUDE_KEYTRANSFORM;INCLUDE_DEBUG_MOVE_GROUPNAME</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
@ -270,6 +270,33 @@
<AndroidResource Include="Resources\layout\sftp_credentials.axml" /> <AndroidResource Include="Resources\layout\sftp_credentials.axml" />
<AndroidResource Include="Resources\layout\Kopie_von_donate.xml" /> <AndroidResource Include="Resources\layout\Kopie_von_donate.xml" />
<AndroidResource Include="Resources\xml\method.xml" /> <AndroidResource Include="Resources\xml\method.xml" />
<None Include="GroupBaseActivity.cs.bak">
<Visible>False</Visible>
</None>
<None Include="KeePass.cs.bak">
<Visible>False</Visible>
</None>
<None Include="app\AppTask.cs.bak">
<Visible>False</Visible>
</None>
<None Include="Resources\layout\entry_list_entry.xml.bak">
<Visible>False</Visible>
</None>
<None Include="Resources\values\config.xml.bak">
<Visible>False</Visible>
</None>
<None Include="Resources\values\strings.xml.bak">
<Visible>False</Visible>
</None>
<None Include="Resources\xml\preferences.xml.bak">
<Visible>False</Visible>
</None>
<None Include="search\SearchResults.cs.bak">
<Visible>False</Visible>
</None>
<None Include="views\PwEntryView.cs.bak">
<Visible>False</Visible>
</None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<AndroidResource Include="Resources\drawable\ic00.png" /> <AndroidResource Include="Resources\drawable\ic00.png" />

View File

@ -19,6 +19,7 @@ using System.Linq;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.OS; using Android.OS;
using Android.Views;
using Android.Widget; using Android.Widget;
using keepass2android.view; using keepass2android.view;
using KeePassLib; using KeePassLib;
@ -45,6 +46,7 @@ namespace keepass2android.search
SetResult(KeePass.ExitNormal); SetResult(KeePass.ExitNormal);
ProcessIntent(Intent); ProcessIntent(Intent);
RegisterForContextMenu(ListView);
} }
protected override void OnNewIntent(Intent intent) protected override void OnNewIntent(Intent intent)
@ -117,6 +119,24 @@ namespace keepass2android.search
} }
public override void OnCreateContextMenu(IContextMenu menu, View v,
IContextMenuContextMenuInfo menuInfo)
{
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
ClickView cv = (ClickView) acmi.TargetView;
cv.OnCreateMenu(menu, menuInfo);
}
public override bool OnContextItemSelected(IMenuItem item) {
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo)item.MenuInfo;
ClickView cv = (ClickView) acmi.TargetView;
bool result;
return cv.OnContextItemSelected(item);
}
public override bool OnSearchRequested() public override bool OnSearchRequested()
{ {

View File

@ -47,6 +47,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 MenuNavigate = MenuMove + 1;
public static PwEntryView GetInstance(GroupBaseActivity act, PwEntry pw, int pos) public static PwEntryView GetInstance(GroupBaseActivity act, PwEntry pw, int pos)
{ {
@ -189,6 +190,11 @@ namespace keepass2android.view
{ {
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);
if (_isSearchResult) {
menu.Add (0, MenuNavigate, 0, Resource.String.menu_navigate);
}
} }
} }
@ -206,7 +212,13 @@ namespace keepass2android.view
task.Start(); task.Start();
return true; return true;
case MenuMove: case MenuMove:
_groupActivity.StartTask(new MoveElementTask { Uuid = _entry.Uuid}); NavigateToFolderAndLaunchMoveElementTask navMove =
new NavigateToFolderAndLaunchMoveElementTask(_entry.ParentGroup, _entry.Uuid);
_groupActivity.StartTask (navMove);
return true;
case MenuNavigate:
NavigateToFolder navNavigate = new NavigateToFolder(_entry.ParentGroup);
_groupActivity.StartTask (navNavigate);
return true; return true;
default: default: