コード例 #1
0
        void UpdateEntryFromUi(PwEntry entry)
        {
            Database          db  = App.Kp2a.GetDb();
            EntryEditActivity act = this;

            entry.Strings.Set(PwDefs.TitleField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectTitle,
                                                                     Util.GetEditText(act, Resource.Id.entry_title)));
            entry.Strings.Set(PwDefs.UserNameField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUserName,
                                                                        Util.GetEditText(act, Resource.Id.entry_user_name)));

            String pass = Util.GetEditText(act, Resource.Id.entry_password);

            byte[] password = StrUtil.Utf8.GetBytes(pass);
            entry.Strings.Set(PwDefs.PasswordField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectPassword,
                                                                        password));
            MemUtil.ZeroByteArray(password);

            entry.Strings.Set(PwDefs.UrlField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectUrl,
                                                                   Util.GetEditText(act, Resource.Id.entry_url)));
            entry.Strings.Set(PwDefs.NotesField, new ProtectedString(db.KpDatabase.MemoryProtection.ProtectNotes,
                                                                     Util.GetEditText(act, Resource.Id.entry_comment)));

            // Validate expiry date
            DateTime newExpiry = new DateTime();

            if ((State.Entry.Expires) && (!DateTime.TryParse(Util.GetEditText(this, Resource.Id.entry_expires), out newExpiry)))
            {
                //ignore here
            }
            else
            {
                State.Entry.ExpiryTime = newExpiry;
            }

            // Delete all non standard strings
            var keys = entry.Strings.GetKeys();

            foreach (String key in keys)
            {
                if (PwDefs.IsStandardField(key) == false)
                {
                    entry.Strings.Remove(key);
                }
            }

            LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container);

            for (int index = 0; index < container.ChildCount; index++)
            {
                View view = container.GetChildAt(index);

                TextView keyView = (TextView)view.FindViewById(Resource.Id.title);
                String   key     = keyView.Text;

                if (String.IsNullOrEmpty(key))
                {
                    continue;
                }

                TextView valueView = (TextView)view.FindViewById(Resource.Id.value);
                String   value     = valueView.Text;


                bool protect = ((CheckBox)view.FindViewById(Resource.Id.protection)).Checked;
                entry.Strings.Set(key, new ProtectedString(protect, value));
            }


            entry.OverrideUrl = Util.GetEditText(this, Resource.Id.entry_override_url);

            List <string> vNewTags = StrUtil.StringToTags(Util.GetEditText(this, Resource.Id.entry_tags));

            entry.Tags.Clear();
            foreach (string strTag in vNewTags)
            {
                entry.AddTag(strTag);
            }

            /*KPDesktop
             *
             *
             *      m_atConfig.Enabled = m_cbAutoTypeEnabled.Checked;
             *      m_atConfig.ObfuscationOptions = (m_cbAutoTypeObfuscation.Checked ?
             *                                       AutoTypeObfuscationOptions.UseClipboard :
             *                                       AutoTypeObfuscationOptions.None);
             *
             *      SaveDefaultSeq();
             *
             *      newEntry.AutoType = m_atConfig;
             */
        }
コード例 #2
0
        protected bool ValidateBeforeSaving()
        {
            // Require title
            String title = Util.GetEditText(this, Resource.Id.entry_title);

            if (title.Length == 0)
            {
                Toast.MakeText(this, Resource.String.error_title_required, ToastLength.Long).Show();
                return(false);
            }

            if (!State.ShowPassword)
            {
                // Validate password
                String pass = Util.GetEditText(this, Resource.Id.entry_password);
                String conf = Util.GetEditText(this, Resource.Id.entry_confpassword);
                if (!pass.Equals(conf))
                {
                    Toast.MakeText(this, Resource.String.error_pass_match, ToastLength.Long).Show();
                    return(false);
                }
            }


            // Validate expiry date
            DateTime newExpiry = new DateTime();

            if ((State.Entry.Expires) && (!DateTime.TryParse(Util.GetEditText(this, Resource.Id.entry_expires), out newExpiry)))
            {
                Toast.MakeText(this, Resource.String.error_invalid_expiry_date, ToastLength.Long).Show();
                return(false);
            }
            State.Entry.ExpiryTime = newExpiry;


            LinearLayout     container = (LinearLayout)FindViewById(Resource.Id.advanced_container);
            HashSet <string> allKeys   = new HashSet <string>();

            for (int i = 0; i < container.ChildCount; i++)
            {
                View ees = container.GetChildAt(i);

                TextView keyView = (TextView)ees.FindViewById(Resource.Id.title);
                string   key     = keyView.Text;

                if (String.IsNullOrEmpty(key))
                {
                    Toast.MakeText(this, Resource.String.error_string_key, ToastLength.Long).Show();
                    return(false);
                }

                if (allKeys.Contains(key))
                {
                    Toast.MakeText(this, GetString(Resource.String.error_string_duplicate_key, new Object[] { key }), ToastLength.Long).Show();
                    return(false);
                }

                allKeys.Add(key);
            }

            return(true);
        }