Example #1
0
        public override void AfterUnlockDatabase(PasswordActivity act)
        {
            if (String.IsNullOrEmpty(UrlToSearchFor))
            {
                GroupActivity.Launch(act, new SelectEntryTask()
                {
                    ShowUserNotifications = ShowUserNotifications
                });
            }
            else
            {
                ShareUrlResults.Launch(act, this);
            }


            //removed. this causes an issue in the following workflow:
            //When the user wants to find an entry for a URL but has the wrong database open he needs
            //to switch to another database. But the Task is removed already the first time when going through PasswordActivity
            // (with the wrong db).
            //Then after switching to the right database, the task is gone.

            //A reason this code existed was the following workflow:
            //Using Chrome browser (with NEW_TASK flag for ActionSend): Share URL -> KP2A.
            //Now the AppTask was in PasswordActivity and didn't get out of it.
            //This is now solved by returning new tasks in ActivityResult.

            //RemoveTaskFromIntent(act);
            //act.AppTask = new NullTask();
        }
Example #2
0
            public override void Run()
            {
                if (Success)
                {
                    // Update the ongoing notification
                    App.Kp2a.UpdateOngoingNotification();

                    if (PreferenceManager.GetDefaultSharedPreferences(_activity).GetBoolean(_activity.GetString(Resource.String.RememberRecentFiles_key), _activity.Resources.GetBoolean(Resource.Boolean.RememberRecentFiles_default)))
                    {
                        // Add to recent files
                        FileDbHelper dbHelper = App.Kp2a.FileDbHelper;


                        //TODO: getFilename always returns "" -> bug?
                        dbHelper.CreateFile(_ioc, Filename);
                    }

                    GroupActivity.Launch(_activity, _activity._appTask);
                    _activity.Finish();
                }
                else
                {
                    DisplayMessage(_activity);
                    try
                    {
                        App.Kp2a.GetFileStorage(_ioc).Delete(_ioc);
                    }
                    catch (Exception e)
                    {
                        //not nice, but not a catastrophic failure if we can't delete the file:
                        Kp2aLog.Log("couldn't delete file after failure! " + e);
                    }
                }
            }
Example #3
0
        public override void StartInGroupActivity(GroupBaseActivity groupBaseActivity)
        {
            base.StartInGroupActivity(groupBaseActivity);

            if (GroupIsFound(groupBaseActivity))               // Group has been found: display toaster and stop here

            {
                if (ToastEnable)
                {
                    String toastMessage = groupBaseActivity.GetString(Resource.String.NavigationToGroupCompleted_message, new Java.Lang.Object[] { FullGroupName });

                    Toast.MakeText(groupBaseActivity, toastMessage, ToastLength.Long).Show();
                }

                groupBaseActivity.StartTask(TaskToBeLaunchedAfterNavigation);
                return;
            }
            else if ((groupBaseActivity.FullGroupId != null) && _fullGroupIds.Contains(groupBaseActivity.FullGroupId.FullId))                 // Need to down up in groups tree

            // Get next Group Uuid
            {
                var linkedListNode = _fullGroupIds.Find(groupBaseActivity.FullGroupId.FullId);
                if (linkedListNode != null)
                {
                    //Note: Resharper says there is a possible NullRefException.
                    //This is not the case because it was checked above if we're already there or not.
                    String nextGroupFullId = linkedListNode.Next.Value;

                    ElementAndDatabaseId fullId = new ElementAndDatabaseId(nextGroupFullId);

                    PwUuid nextGroupPwUuid = new PwUuid(MemUtil.HexStringToByteArray(fullId.ElementIdString));

                    // Create Group Activity
                    PwGroup nextGroup = App.Kp2a.GetDatabase(fullId.DatabaseId).GroupsById[nextGroupPwUuid];
                    GroupActivity.Launch(groupBaseActivity, nextGroup, this, new ActivityLaunchModeRequestCode(0));
                }
                return;
            }
            else                 // Need to go up in groups tree
            {
                ElementAndDatabaseId fullId = new ElementAndDatabaseId(_fullGroupIds.Last.Value);
                var targetDb = App.Kp2a.GetDatabase(fullId.DatabaseId);
                if (App.Kp2a.CurrentDb != targetDb)
                {
                    App.Kp2a.CurrentDb = targetDb;
                    GroupActivity.Launch(groupBaseActivity, targetDb.Root, this, new ActivityLaunchModeForward());
                }
                else
                {
                    SetActivityResult(groupBaseActivity, KeePass.ExitNormal);
                }
                groupBaseActivity.Finish();
            }
        }
Example #4
0
        public override void StartInGroupActivity(GroupBaseActivity groupBaseActivity)
        {
            base.StartInGroupActivity(groupBaseActivity);

            if (GroupIsFound(groupBaseActivity))               // Group has been found: display toaster and stop here

            {
                if (ToastEnable)
                {
                    String toastMessage = groupBaseActivity.GetString(Resource.String.NavigationToGroupCompleted_message, new Java.Lang.Object[] { FullGroupName });

                    Toast.MakeText(groupBaseActivity, toastMessage, ToastLength.Long).Show();
                }

                groupBaseActivity.StartTask(TaskToBeLaunchedAfterNavigation);
                return;
            }
            else if (_groupUuid.Contains(groupBaseActivity.UuidGroup))                 // Need to go up in groups tree

            // Get next Group Uuid
            {
                var linkedListNode = _groupUuid.Find(groupBaseActivity.UuidGroup);
                if (linkedListNode != null)
                {
                    //Note: Resharper says there is a possible NullRefException.
                    //This is not the case because it was checked above if we're already there or not.
                    String nextGroupUuid   = linkedListNode.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.ExitNormal);
                groupBaseActivity.Finish();
            }
        }
Example #5
0
 public virtual void AfterUnlockDatabase(PasswordActivity act)
 {
     GroupActivity.Launch(act, this);
 }
        private void Query(string url, bool autoReturnFromQuery)
        {
            try
            {
                //first: search for exact url
                Group = _db.SearchForExactUrl(url);
                if (!url.StartsWith("androidapp://"))
                {
                    //if no results, search for host (e.g. "accounts.google.com")
                    if (!Group.Entries.Any())
                    {
                        Group = _db.SearchForHost(url, false);
                    }
                    //if still no results, search for host, allowing subdomains ("www.google.com" in entry is ok for "accounts.google.com" in search (but not the other way around)
                    if (!Group.Entries.Any())
                    {
                        Group = _db.SearchForHost(url, true);
                    }
                }
                //if no results returned up to now, try to search through other fields as well:
                if (!Group.Entries.Any())
                {
                    Group = _db.SearchForText(url);
                }
                //search for host as text
                if (!Group.Entries.Any())
                {
                    Group = _db.SearchForText(UrlUtil.GetHost(url.Trim()));
                }
            } catch (Exception e)
            {
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                SetResult(Result.Canceled);
                Finish();
                return;
            }

            //if there is exactly one match: open the entry
            if ((Group.Entries.Count() == 1) && autoReturnFromQuery && PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(GetString(Resource.String.AutoReturnFromQuery_key), true))
            {
                LaunchActivityForEntry(Group.Entries.Single(), 0);
                return;
            }

            //show results:
            if (Group == null || (!Group.Entries.Any()))
            {
                SetContentView(Resource.Layout.searchurlresults_empty);
            }

            SetGroupTitle();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);

            View selectOtherEntry = FindViewById(Resource.Id.select_other_entry);

            var newTask = new SelectEntryForUrlTask(url);

            if (AppTask is SelectEntryTask currentSelectTask)
            {
                newTask.ShowUserNotifications = currentSelectTask.ShowUserNotifications;
            }

            selectOtherEntry.Click += (sender, e) => {
                GroupActivity.Launch(this, newTask);
            };


            View createUrlEntry = FindViewById(Resource.Id.add_url_entry);

            if (App.Kp2a.GetDb().CanWrite)
            {
                createUrlEntry.Visibility = ViewStates.Visible;
                createUrlEntry.Click     += (sender, e) =>
                {
                    GroupActivity.Launch(this, new CreateEntryThenCloseTask {
                        Url = url, ShowUserNotifications = (AppTask as SelectEntryTask)?.ShowUserNotifications ?? true
                    });
                    Toast.MakeText(this, GetString(Resource.String.select_group_then_add, new Java.Lang.Object[] { GetString(Resource.String.add_entry) }), ToastLength.Long).Show();
                };
            }
            else
            {
                createUrlEntry.Visibility = ViewStates.Gone;
            }

            Util.MoveBottomBarButtons(Resource.Id.select_other_entry, Resource.Id.add_url_entry, Resource.Id.bottom_bar, this);
        }
Example #7
0
 public virtual void LaunchFirstGroupActivity(Activity act)
 {
     GroupActivity.Launch(act, this, new ActivityLaunchModeRequestCode(0));
 }
        private void Query(string url, bool autoReturnFromQuery)
        {
            try
            {
                Group = GetSearchResultsForUrl(url);
            } catch (Exception e)
            {
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                SetResult(Result.Canceled);
                Finish();
                return;
            }

            //if there is exactly one match: open the entry
            if ((Group.Entries.Count() == 1) && autoReturnFromQuery && PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(GetString(Resource.String.AutoReturnFromQuery_key), true))
            {
                LaunchActivityForEntry(Group.Entries.Single(), 0);
                return;
            }

            //show results:
            if (Group == null || (!Group.Entries.Any()))
            {
                SetContentView(Resource.Layout.searchurlresults_empty);
            }

            SetGroupTitle();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);

            View selectOtherEntry = FindViewById(Resource.Id.select_other_entry);

            var newTask = new SearchUrlTask()
            {
                AutoReturnFromQuery = false, UrlToSearchFor = url
            };

            if (AppTask is SelectEntryTask currentSelectTask)
            {
                newTask.ShowUserNotifications = currentSelectTask.ShowUserNotifications;
            }

            selectOtherEntry.Click += (sender, e) => {
                GroupActivity.Launch(this, newTask, new ActivityLaunchModeRequestCode(0));
            };


            View createUrlEntry = FindViewById(Resource.Id.add_url_entry);

            if (App.Kp2a.OpenDatabases.Any(db => db.CanWrite))
            {
                createUrlEntry.Visibility = ViewStates.Visible;
                createUrlEntry.Click     += (sender, e) =>
                {
                    GroupActivity.Launch(this, new CreateEntryThenCloseTask {
                        Url = url, ShowUserNotifications = (AppTask as SelectEntryTask)?.ShowUserNotifications ?? ShowUserNotificationsMode.Always
                    }, new ActivityLaunchModeRequestCode(0));
                    Toast.MakeText(this, GetString(Resource.String.select_group_then_add, new Java.Lang.Object[] { GetString(Resource.String.add_entry) }), ToastLength.Long).Show();
                };
            }
            else
            {
                createUrlEntry.Visibility = ViewStates.Gone;
            }

            Util.MoveBottomBarButtons(Resource.Id.select_other_entry, Resource.Id.add_url_entry, Resource.Id.bottom_bar, this);
        }