Add toaster after navigation to parent group

This commit is contained in:
Jareth Lomson 2014-05-25 23:00:30 +02:00
parent 8db8b27423
commit 5b6786d0a2
3 changed files with 927 additions and 895 deletions

File diff suppressed because it is too large Load Diff

View File

@ -28,6 +28,7 @@
<string name="application_settings">Application settings</string> <string name="application_settings">Application settings</string>
<string name="ShowGroupnameInSearchResult_title">Display groupname in search result</string> <string name="ShowGroupnameInSearchResult_title">Display groupname in search result</string>
<string name="ShowGroupnameInSearchResult_resume">Display groupname below entry titles. Usefull if several entries have the same name.</string> <string name="ShowGroupnameInSearchResult_resume">Display groupname below entry titles. Usefull if several entries have the same name.</string>
<string name="NavigationToGroupCompleted_message">Display group is now : %0</string>
<string name="security_prefs">Security</string> <string name="security_prefs">Security</string>
<string name="display_prefs">Display</string> <string name="display_prefs">Display</string>

View File

@ -2,6 +2,7 @@ using System;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.OS; using Android.OS;
using Android.Widget;
using System.Collections.Generic; using System.Collections.Generic;
using KeePassLib; using KeePassLib;
using KeePassLib.Security; using KeePassLib.Security;
@ -673,46 +674,61 @@ namespace keepass2android
// The last one is the destination group // The last one is the destination group
public const String numberOfGroupsKey = "NumberOfGroups"; public const String numberOfGroupsKey = "NumberOfGroups";
public const String gUuidKey = "gUuidKey"; public const String gUuidKey = "gUuidKey";
public const String fullGroupNameKey = "fullGroupNameKey";
#if INCLUDE_DEBUG_MOVE_GROUPNAME #if INCLUDE_DEBUG_MOVE_GROUPNAME
public const String gNameKey = "gNameKey"; public const String gNameKey = "gNameKey";
private LinkedList<string> groupName; private LinkedList<string> groupNameList;
#endif #endif
private LinkedList<string> groupUuid; private LinkedList<string> groupUuid;
protected AppTask taskToBeLaunchAfterNavigation; protected AppTask taskToBeLaunchAfterNavigation;
protected String fullGroupName {
get ;
set ;
}
public NavigateAndLaunchTask() { public NavigateAndLaunchTask() {
this.taskToBeLaunchAfterNavigation = new NullTask(); this.taskToBeLaunchAfterNavigation = new NullTask();
fullGroupName = "";
} }
protected NavigateAndLaunchTask(PwGroup groups, AppTask taskToBeLaunchAfterNavigation) { protected NavigateAndLaunchTask(PwGroup groups, AppTask taskToBeLaunchAfterNavigation) {
this.taskToBeLaunchAfterNavigation = taskToBeLaunchAfterNavigation; this.taskToBeLaunchAfterNavigation = taskToBeLaunchAfterNavigation;
populateGroupsUuid (groups); populateGroups (groups);
} }
public void populateGroupsUuid(PwGroup groups) { public void populateGroups(PwGroup groups) {
groupUuid = new LinkedList<String>{}; groupUuid = new LinkedList<String>{};
#if INCLUDE_DEBUG_MOVE_GROUPNAME #if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName = new LinkedList<String>{}; groupNameList = new LinkedList<String>{};
#endif #endif
fullGroupName = "";
PwGroup readGroup = groups; PwGroup readGroup = groups;
while (readGroup != null) { while (readGroup != null) {
if ( (readGroup.ParentGroup != null) ||
(readGroup.ParentGroup == null) && (readGroup == groups) ) {
fullGroupName = readGroup.Name + "." + fullGroupName;
}
groupUuid.AddFirst (MemUtil.ByteArrayToHexString (readGroup.Uuid.UuidBytes)); groupUuid.AddFirst (MemUtil.ByteArrayToHexString (readGroup.Uuid.UuidBytes));
#if INCLUDE_DEBUG_MOVE_GROUPNAME #if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName.AddFirst (readGroup.Name); groupNameList.AddFirst (readGroup.Name);
#endif #endif
readGroup = readGroup.ParentGroup; readGroup = readGroup.ParentGroup;
} }
} }
/// <summary> /// <summary>
/// Loads the parameters of the task from the given bundle. Embeded task is not setup from this bundle /// Loads the parameters of the task from the given bundle. Embeded task is not setup from this bundle
/// </summary> /// </summary>
@ -721,21 +737,25 @@ namespace keepass2android
{ {
int numberOfGroups = b.GetInt(numberOfGroupsKey); int numberOfGroups = b.GetInt(numberOfGroupsKey);
groupUuid = new LinkedList<String>{}; groupUuid = new LinkedList<String>{};
#if INCLUDE_DEBUG_MOVE_GROUPNAME #if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName = new LinkedList<String>{}; groupNameList = new LinkedList<String>{};
#endif #endif
int i = 0; int i = 0;
fullGroupName = "";
while (i < numberOfGroups) { while (i < numberOfGroups) {
groupUuid.AddLast ( b.GetString (gUuidKey + i) ) ; groupUuid.AddLast ( b.GetString (gUuidKey + i) ) ;
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupName.AddLast ( b.GetString (gNameKey + i) );
#endif
#if INCLUDE_DEBUG_MOVE_GROUPNAME
groupNameList.AddLast ( b.GetString (gNameKey + i);
#endif
i++; i++;
} }
this.fullGroupName = b.GetString (fullGroupNameKey);
} }
public override IEnumerable<IExtra> Extras public override IEnumerable<IExtra> Extras
@ -744,22 +764,25 @@ namespace keepass2android
{ {
// Return Navigate group Extras // Return Navigate group Extras
IEnumerator<String> eGroupKeys = groupUuid.GetEnumerator (); IEnumerator<String> eGroupKeys = groupUuid.GetEnumerator ();
#if INCLUDE_DEBUG_MOVE_GROUPNAME
IEnumerator<String> eGroupName = groupName.GetEnumerator (); #if INCLUDE_DEBUG_MOVE_GROUPNAME
#endif IEnumerator<String> eGroupName = groupNameList.GetEnumerator ();
#endif
int i = 0; int i = 0;
while (eGroupKeys.MoveNext()) { while (eGroupKeys.MoveNext()) {
yield return new StringExtra { Key = gUuidKey + i.ToString (), Value = eGroupKeys.Current }; yield return new StringExtra { Key = gUuidKey + i.ToString (), Value = eGroupKeys.Current };
#if INCLUDE_DEBUG_MOVE_GROUPNAME
#if INCLUDE_DEBUG_MOVE_GROUPNAME
eGroupName.MoveNext(); eGroupName.MoveNext();
yield return new StringExtra { Key = gNameKey + i.ToString (), Value = eGroupName.Current }; yield return new StringExtra { Key = gNameKey + i.ToString (), Value = eGroupName.Current };
#endif #endif
i++; i++;
} }
yield return new IntExtra{ Key = numberOfGroupsKey, Value = i }; yield return new IntExtra{ Key = numberOfGroupsKey, Value = i };
yield return new StringExtra{ Key = fullGroupNameKey, Value = fullGroupName };
// Return afterTaskExtras // Return afterTaskExtras
IEnumerator<IExtra> afterTaskExtras = taskToBeLaunchAfterNavigation.Extras.GetEnumerator(); IEnumerator<IExtra> afterTaskExtras = taskToBeLaunchAfterNavigation.Extras.GetEnumerator();
@ -774,7 +797,12 @@ namespace keepass2android
{ {
base.StartInGroupActivity(groupBaseActivity); base.StartInGroupActivity(groupBaseActivity);
if (GroupIsFound(groupBaseActivity) ){ // Group has been found: stop here if (GroupIsFound(groupBaseActivity) ){ // Group has been found: display toaster and stop here
String toastMessage = groupBaseActivity.GetString(Resource.String.NavigationToGroupCompleted_message);
toastMessage = toastMessage.Replace ("%0", this.fullGroupName);
Toast.MakeText (groupBaseActivity, toastMessage, ToastLength.Long).Show ();
groupBaseActivity.StartTask (taskToBeLaunchAfterNavigation); groupBaseActivity.StartTask (taskToBeLaunchAfterNavigation);
return; return;