protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            if (IsFinishing)
            {
                return;
            }

            SetResult(KeePass.ExitNormal);

            Log.Warn(Tag, "Creating group view");
            Intent intent = Intent;

            PwUuid id = RetrieveGroupId(intent);

            Database db = App.Kp2a.CurrentDb;

            if (id == null)
            {
                Group = db.Root;
            }
            else
            {
                Group = db.GroupsById[id];
            }

            Log.Warn(Tag, "Retrieved group");
            if (Group == null)
            {
                Log.Warn(Tag, "Group was null");
                return;
            }


            if (AddGroupEnabled)
            {
                // Add Group button
                View addGroup = FindViewById(Resource.Id.fabAddNewGroup);
                addGroup.Click += (sender, e) => {
                    GroupEditActivity.Launch(this, Group);
                };
            }


            if (AddEntryEnabled)
            {
                View addEntry = FindViewById(Resource.Id.fabAddNewEntry);
                addEntry.Click += (sender, e) =>
                {
                    if (App.Kp2a.CurrentDb.DatabaseFormat.SupportsTemplates &&
                        !AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb) &&
                        PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(Askaddtemplates, true))
                    {
                        App.Kp2a.AskYesNoCancel(UiStringKey.AskAddTemplatesTitle, UiStringKey.AskAddTemplatesMessage, UiStringKey.yes, UiStringKey.no,
                                                (o, args) =>
                        {
                            //yes
                            ProgressTask pt = new ProgressTask(App.Kp2a, this,
                                                               new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this,
                                                                                                                         (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry())));
                            pt.Run();
                        },
                                                (o, args) =>
                        {
                            var edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit();
                            edit.PutBoolean(Askaddtemplates, false);
                            edit.Commit();
                            //no
                            StartAddEntry();
                        }, null, this);
                    }
                    else
                    {
                        StartAddEntry();
                    }
                };
            }

            SetGroupTitle();
            SetGroupIcon();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);
            Log.Warn(Tag, "Finished creating group");

            var ioc = App.Kp2a.CurrentDb.Ioc;
            OptionalOut <UiStringKey> reason = new OptionalOut <UiStringKey>();

            if (App.Kp2a.GetFileStorage(ioc).IsReadOnly(ioc, reason))
            {
                bool hasShownReadOnlyReason =
                    PreferenceManager.GetDefaultSharedPreferences(this)
                    .GetBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", false);
                if (!hasShownReadOnlyReason)
                {
                    var b = new AlertDialog.Builder(this);
                    b.SetTitle(Resource.String.FileReadOnlyTitle);
                    b.SetMessage(GetString(Resource.String.FileReadOnlyMessagePre) + " " + App.Kp2a.GetResourceString(reason.Result));
                    b.SetPositiveButton(Android.Resource.String.Ok,
                                        (sender, args) =>
                    {
                        PreferenceManager.GetDefaultSharedPreferences(this).
                        Edit().PutBoolean(App.Kp2a.CurrentDb.IocAsHexString() + "_readonlyreason", true).Commit();
                    });
                    b.Show();
                }
            }
        }
Exemple #2
0
        public bool OnActionItemClicked(ActionMode mode, IMenuItem item)
        {
            var listView             = FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListView;
            var checkedItemPositions = listView.CheckedItemPositions;

            List <IStructureItem> checkedItems = new List <IStructureItem>();

            for (int i = 0; i < checkedItemPositions.Size(); i++)
            {
                if (checkedItemPositions.ValueAt(i))
                {
                    checkedItems.Add(((PwGroupListAdapter)ListAdapter).GetItemAtPosition(checkedItemPositions.KeyAt(i)));
                }
            }

            //shouldn't happen, just in case...
            if (!checkedItems.Any())
            {
                return(false);
            }
            Handler handler = new Handler();

            switch (item.ItemId)
            {
            case Resource.Id.menu_delete:

                DeleteMultipleItems task = new DeleteMultipleItems((GroupBaseActivity)Activity, App.Kp2a.GetDb(), checkedItems,
                                                                   new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)), App.Kp2a);
                task.Start();
                break;

            case Resource.Id.menu_move:
                var navMove = new NavigateToFolderAndLaunchMoveElementTask(checkedItems.First().ParentGroup, checkedItems.Select(i => i.Uuid).ToList(), ((GroupBaseActivity)Activity).IsSearchResult);
                ((GroupBaseActivity)Activity).StartTask(navMove);
                break;

            case Resource.Id.menu_copy:

                var copyTask = new CopyEntry((GroupBaseActivity)Activity, App.Kp2a, (PwEntry)checkedItems.First(),
                                             new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)));

                ProgressTask pt = new ProgressTask(App.Kp2a, Activity, copyTask);
                pt.Run();
                break;

            case Resource.Id.menu_navigate:
                NavigateToFolder navNavigate = new NavigateToFolder(checkedItems.First().ParentGroup, true);
                ((GroupBaseActivity)Activity).StartTask(navNavigate);
                break;

            case Resource.Id.menu_edit:
                GroupEditActivity.Launch(Activity, checkedItems.First().ParentGroup, (PwGroup)checkedItems.First());
                break;

            default:
                return(false);
            }
            listView.ClearChoices();
            ((BaseAdapter)ListAdapter).NotifyDataSetChanged();
            if (_mode != null)
            {
                mode.Finish();
            }

            return(true);
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            if (IsFinishing)
            {
                return;
            }

            SetResult(KeePass.ExitNormal);

            Log.Warn(Tag, "Creating group view");
            Intent intent = Intent;

            PwUuid id = RetrieveGroupId(intent);

            Database db = App.Kp2a.CurrentDb;

            if (db != null)
            {
                Group = id == null ? db.Root : db.GroupsById[id];
            }

            Log.Warn(Tag, "Retrieved group");
            if (Group == null)
            {
                Log.Warn(Tag, "Group was null");
                return;
            }


            if (AddGroupEnabled)
            {
                // Add Group button
                View addGroup = FindViewById(Resource.Id.fabAddNewGroup);
                addGroup.Click += (sender, e) => {
                    GroupEditActivity.Launch(this, Group);
                };
            }


            if (AddEntryEnabled)
            {
                View addEntry = FindViewById(Resource.Id.fabAddNewEntry);
                addEntry.Click += (sender, e) =>
                {
                    if (App.Kp2a.CurrentDb.DatabaseFormat.SupportsTemplates &&
                        !AddTemplateEntries.ContainsAllTemplates(App.Kp2a.CurrentDb) &&
                        PreferenceManager.GetDefaultSharedPreferences(this).GetBoolean(Askaddtemplates, true))
                    {
                        App.Kp2a.AskYesNoCancel(UiStringKey.AskAddTemplatesTitle, UiStringKey.AskAddTemplatesMessage, UiStringKey.yes, UiStringKey.no,
                                                (o, args) =>
                        {
                            //yes
                            ProgressTask pt = new ProgressTask(App.Kp2a, this,
                                                               new AddTemplateEntries(this, App.Kp2a, new ActionOnFinish(this,
                                                                                                                         (success, message, activity) => ((GroupActivity)activity)?.StartAddEntry())));
                            pt.Run();
                        },
                                                (o, args) =>
                        {
                            var edit = PreferenceManager.GetDefaultSharedPreferences(this).Edit();
                            edit.PutBoolean(Askaddtemplates, false);
                            edit.Commit();
                            //no
                            StartAddEntry();
                        }, null, this);
                    }
                    else
                    {
                        StartAddEntry();
                    }
                };
            }

            SetGroupTitle();
            SetGroupIcon();

            FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListAdapter = new PwGroupListAdapter(this, Group);
            Log.Warn(Tag, "Finished creating group");
        }
Exemple #4
0
 public void EditGroup(PwGroup pwGroup)
 {
     GroupEditActivity.Launch(this, pwGroup.ParentGroup, pwGroup);
 }