Ejemplo n.º 1
0
        private void Query(SearchParameters searchParams)
        {
            Group = null;
            try {
                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    PwGroup resultsForThisDb = db.Search(searchParams, null);
                    if (Group == null)
                    {
                        Group = resultsForThisDb;
                    }
                    else
                    {
                        foreach (var entry in resultsForThisDb.Entries)
                        {
                            Group.AddEntry(entry, false);
                        }
                    }
                }
            } catch (Exception e) {
                Kp2aLog.LogUnexpectedError(e);
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                Finish();
                return;
            }

            if (Group == null || (!Group.Entries.Any()))
            {
                SetContentView(Resource.Layout.group_empty);
            }

            SetGroupTitle();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);
        }
Ejemplo n.º 2
0
        private void Query(SearchParameters searchParams)
        {
            //kind of an easter egg: if the user types this exact string into the search, it immediately allows to disable the donation options
            if (searchParams.SearchString == "allow disable donation")
            {
                ISharedPreferences       prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                ISharedPreferencesEditor edit  = prefs.Edit();
                edit.PutLong(GetString(Resource.String.UsageCount_key), 1000);
                edit.PutBoolean("DismissedDonateReminder", true);
                edit.Commit();
                Toast.MakeText(this, "Please go to Settings - App - Display to disable donation requests.", ToastLength.Long).Show();
            }


            Group = null;
            try {
                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    PwGroup resultsForThisDb = db.Search(searchParams, null);
                    if (Group == null)
                    {
                        Group = resultsForThisDb;
                    }
                    else
                    {
                        foreach (var entry in resultsForThisDb.Entries)
                        {
                            Group.AddEntry(entry, false);
                        }
                    }
                }
            } catch (Exception e) {
                Kp2aLog.LogUnexpectedError(e);
                Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                Finish();
                return;
            }

            if (Group == null || (!Group.Entries.Any()))
            {
                SetContentView(Resource.Layout.group_empty);
            }

            SetGroupTitle();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);
        }
Ejemplo n.º 3
0
        private void Query(string url, bool autoReturnFromQuery)
        {
            try
            {
                foreach (var db in App.Kp2a.OpenDatabases)
                {
                    PwGroup resultsForThisDb;
                    //first: search for exact url
                    resultsForThisDb = db.SearchForExactUrl(url);
                    if (!url.StartsWith("androidapp://"))
                    {
                        //if no results, search for host (e.g. "accounts.google.com")
                        if (!resultsForThisDb.Entries.Any())
                        {
                            resultsForThisDb = 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 (!resultsForThisDb.Entries.Any())
                        {
                            resultsForThisDb = db.SearchForHost(url, true);
                        }
                    }
                    //if no results returned up to now, try to search through other fields as well:
                    if (!resultsForThisDb.Entries.Any())
                    {
                        resultsForThisDb = db.SearchForText(url);
                    }
                    //search for host as text
                    if (!resultsForThisDb.Entries.Any())
                    {
                        resultsForThisDb = db.SearchForText(UrlUtil.GetHost(url.Trim()));
                    }

                    if (Group == null)
                    {
                        Group = resultsForThisDb;
                    }
                    else
                    {
                        foreach (var entry in resultsForThisDb.Entries)
                        {
                            Group.AddEntry(entry, false, false);
                        }
                    }
                }
            } 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, 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 ?? true
                    }, 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);
        }