private void CreateNewFromKpEntryTemplate(Database db, PwEntry templateEntry) { var entry = new PwEntry(true, true); KpEntryTemplatedEdit.InitializeEntry(entry, templateEntry); State.EntryInDatabase = entry; }
private void PopulateExtraStrings() { ViewGroup extraGroup = (ViewGroup)FindViewById(Resource.Id.extra_strings); bool hasExtras = false; IEditMode editMode = new DefaultEdit(); if (KpEntryTemplatedEdit.IsTemplated(App.Kp2a.GetDb(), this.Entry)) { editMode = new KpEntryTemplatedEdit(App.Kp2a.GetDb(), this.Entry); } foreach (var key in editMode.SortExtraFieldKeys(Entry.Strings.GetKeys().Where(key => !PwDefs.IsStandardField(key)))) { if (editMode.IsVisible(key)) { hasExtras = true; var value = Entry.Strings.Get(key); var stringView = CreateExtraSection(key, value.ReadString(), value.IsProtected); extraGroup.AddView(stringView.View); } } FindViewById(Resource.Id.extra_strings_container).Visibility = hasExtras ? ViewStates.Visible : ViewStates.Gone; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (LastNonConfigurationInstance != null) { //bug in Mono for Android or whatever: after config change the extra fields are wrong // -> reload: Reload(); return; } _appTask = AppTask.GetTaskInOnCreate(savedInstanceState, Intent); SetContentView(Resource.Layout.entry_edit); _closeForReload = false; // Likely the app has been killed exit the activity if (!App.Kp2a.DatabaseIsUnlocked) { Finish(); return; } if (Intent.GetBooleanExtra(IntentContinueWithEditing, false)) { //property "State" will return the state } else { Database db = App.Kp2a.GetDb(); App.Kp2a.EntryEditActivityState = new EntryEditActivityState(); ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this); State.ShowPassword = !prefs.GetBoolean(GetString(Resource.String.maskpass_key), Resources.GetBoolean(Resource.Boolean.maskpass_default)); Intent i = Intent; String uuidBytes = i.GetStringExtra(KeyEntry); PwUuid entryId = PwUuid.Zero; if (uuidBytes != null) { entryId = new PwUuid(MemUtil.HexStringToByteArray(uuidBytes)); } State.ParentGroup = null; if (entryId.Equals(PwUuid.Zero)) { //creating new entry String groupId = i.GetStringExtra(KeyParent); State.ParentGroup = db.KpDatabase.RootGroup.FindGroup(new PwUuid(MemUtil.HexStringToByteArray(groupId)), true); PwUuid templateId = new PwUuid(MemUtil.HexStringToByteArray(i.GetStringExtra(KeyTemplateUuid))); PwEntry templateEntry = null; if (!PwUuid.Zero.Equals(templateId)) { templateEntry = db.Entries[templateId]; } if (KpEntryTemplatedEdit.IsTemplate(templateEntry)) { CreateNewFromKpEntryTemplate(db, templateEntry); } else if (templateEntry != null) { CreateNewFromStandardTemplate(templateEntry); } else { CreateNewWithoutTemplate(db); } _appTask.PrepareNewEntry(State.EntryInDatabase); State.IsNew = true; State.EntryModified = true; } else { Debug.Assert(entryId != null); State.EntryInDatabase = db.Entries [entryId]; State.IsNew = false; } State.Entry = State.EntryInDatabase.CloneDeep(); if (KpEntryTemplatedEdit.IsTemplated(db, State.Entry)) { State.EditMode = new KpEntryTemplatedEdit(db, State.Entry); } else { State.EditMode = new DefaultEdit(); } } if (!State.EntryModified) { SetResult(KeePass.ExitNormal); } else { SetResult(KeePass.ExitRefreshTitle); } FillData(); View scrollView = FindViewById(Resource.Id.entry_scroll); scrollView.ScrollBarStyle = ScrollbarStyles.InsideInset; ImageButton iconButton = (ImageButton)FindViewById(Resource.Id.icon_button); if (State.SelectedIcon) { App.Kp2a.GetDb().DrawableFactory.AssignDrawableTo(iconButton, this, App.Kp2a.GetDb().KpDatabase, (PwIcon)State.SelectedIconId, State.SelectedCustomIconId, false); } iconButton.Click += (sender, evt) => { UpdateEntryFromUi(State.Entry); IconPickerActivity.Launch(this); }; // Generate password button FindViewById(Resource.Id.generate_button).Click += (sender, e) => { UpdateEntryFromUi(State.Entry); GeneratePasswordActivity.Launch(this); }; // Save button //SupportActionBar.SetCustomView(Resource.Layout.SaveButton); if (State.IsNew) { SupportActionBar.Title = GetString(Resource.String.add_entry); } else { SupportActionBar.Title = GetString(Resource.String.edit_entry); } SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); // Respect mask password setting MakePasswordVisibleOrHidden(); ImageButton btnTogglePassword = (ImageButton)FindViewById(Resource.Id.toggle_password); btnTogglePassword.Click += (sender, e) => { State.ShowPassword = !State.ShowPassword; MakePasswordVisibleOrHidden(); }; PorterDuff.Mode mMode = PorterDuff.Mode.SrcAtop; Color color = new Color(189, 189, 189); btnTogglePassword.SetColorFilter(color, mMode); Button addButton = (Button)FindViewById(Resource.Id.add_advanced); addButton.Visibility = ViewStates.Visible; addButton.Click += (sender, e) => { LinearLayout container = (LinearLayout)FindViewById(Resource.Id.advanced_container); KeyValuePair <string, ProtectedString> pair = new KeyValuePair <string, ProtectedString>("", new ProtectedString(true, "")); View ees = CreateExtraStringView(pair); container.AddView(ees); State.EntryModified = true; /*TextView keyView = (TextView) ees.FindViewById(Resource.Id.title); * keyView.RequestFocus();*/ EditAdvancedString(ees.FindViewById(Resource.Id.edit_extra)); }; SetAddExtraStringEnabled(); ((CheckBox)FindViewById(Resource.Id.entry_expires_checkbox)).CheckedChange += (sender, e) => { State.Entry.Expires = e.IsChecked; if (e.IsChecked) { if (State.Entry.ExpiryTime < DateTime.Now) { State.Entry.ExpiryTime = DateTime.Now; } } UpdateExpires(); State.EntryModified = true; }; }
public KeyOrderComparer(KpEntryTemplatedEdit kpEntryTemplatedEdit) { _kpEntryTemplatedEdit = kpEntryTemplatedEdit; }