Search in sources :

Example 1 with EntryEditNewField

use of com.keepassdroid.view.EntryEditNewField in project KeePassDX by Kunzisoft.

the class EntryEditActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.entry_edit);
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));
    setSupportActionBar(toolbar);
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    scrollView = findViewById(R.id.entry_scroll);
    scrollView.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
    entryTitleView = findViewById(R.id.entry_title);
    entryUserNameView = findViewById(R.id.entry_user_name);
    entryUrlView = findViewById(R.id.entry_url);
    entryPasswordView = findViewById(R.id.entry_password);
    entryConfirmationPasswordView = findViewById(R.id.entry_confpassword);
    entryCommentView = findViewById(R.id.entry_comment);
    entryExtraFieldsContainer = findViewById(R.id.advanced_container);
    // Likely the app has been killed exit the activity
    Database db = App.getDB();
    if (!db.Loaded()) {
        finish();
        return;
    }
    Intent intent = getIntent();
    byte[] uuidBytes = intent.getByteArrayExtra(KEY_ENTRY);
    PwDatabase pm = db.pm;
    if (uuidBytes == null) {
        PwGroupId parentId = (PwGroupId) intent.getSerializableExtra(KEY_PARENT);
        PwGroup parent = pm.groups.get(parentId);
        mEntry = PwEntry.getInstance(parent);
        mIsNew = true;
    } else {
        UUID uuid = Types.bytestoUUID(uuidBytes);
        mEntry = pm.entries.get(uuid);
        mIsNew = false;
        fillData();
    }
    View iconButton = findViewById(R.id.icon_button);
    iconButton.setOnClickListener(v -> IconPickerDialogFragment.launch(EntryEditActivity.this));
    // Generate password button
    View generatePassword = findViewById(R.id.generate_button);
    generatePassword.setOnClickListener(v -> {
        GeneratePasswordDialogFragment generatePasswordDialogFragment = new GeneratePasswordDialogFragment();
        generatePasswordDialogFragment.show(getSupportFragmentManager(), "PasswordGeneratorFragment");
    });
    // Save button
    View save = findViewById(R.id.entry_save);
    save.setOnClickListener(v -> {
        if (!validateBeforeSaving()) {
            return;
        }
        mCallbackNewEntry = populateNewEntry();
        OnFinish onFinish = new AfterSave();
        EntryEditActivity act = EntryEditActivity.this;
        RunnableOnFinish task;
        if (mIsNew) {
            task = new AddEntry(act, App.getDB(), mCallbackNewEntry, onFinish);
        } else {
            task = new UpdateEntry(act, App.getDB(), mEntry, mCallbackNewEntry, onFinish);
        }
        ProgressTask pt = new ProgressTask(act, task, R.string.saving_database);
        pt.run();
    });
    if (mEntry.allowExtraFields()) {
        View add = findViewById(R.id.add_new_field);
        add.setVisibility(View.VISIBLE);
        add.setOnClickListener(v -> {
            EntryEditNewField ees = new EntryEditNewField(EntryEditActivity.this);
            ees.setData("", new ProtectedString(false, ""));
            entryExtraFieldsContainer.addView(ees);
            // Scroll bottom
            scrollView.post(() -> scrollView.fullScroll(ScrollView.FOCUS_DOWN));
        });
    }
}
Also used : ProgressTask(com.keepassdroid.tasks.ProgressTask) UpdateEntry(com.keepassdroid.database.edit.UpdateEntry) PwDatabase(com.keepassdroid.database.PwDatabase) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) Intent(android.content.Intent) OnFinish(com.keepassdroid.database.edit.OnFinish) RunnableOnFinish(com.keepassdroid.database.edit.RunnableOnFinish) EntryEditNewField(com.keepassdroid.view.EntryEditNewField) View(android.view.View) ScrollView(android.widget.ScrollView) AddEntry(com.keepassdroid.database.edit.AddEntry) GeneratePasswordDialogFragment(com.keepassdroid.dialogs.GeneratePasswordDialogFragment) PwGroupId(com.keepassdroid.database.PwGroupId) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) ProtectedString(com.keepassdroid.database.security.ProtectedString) PwGroup(com.keepassdroid.database.PwGroup) UUID(java.util.UUID) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with EntryEditNewField

use of com.keepassdroid.view.EntryEditNewField in project KeePassDX by Kunzisoft.

the class EntryEditActivity method populateNewEntry.

protected PwEntry populateNewEntry() {
    PwDatabase db = App.getDB().pm;
    PwEntry newEntry = mEntry.clone();
    newEntry.startToDecodeReference(db);
    newEntry.createBackup(db);
    newEntry.setLastAccessTime(new PwDate());
    newEntry.setLastModificationTime(new PwDate());
    newEntry.setTitle(entryTitleView.getText().toString());
    if (mSelectedIconID != -1)
        // or TODO icon factory newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(mSelectedIconID));
        newEntry.setIcon(new PwIconStandard(mSelectedIconID));
    else {
        if (mIsNew) {
            newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(0));
        } else {
            //  Keep previous icon, if no new one was selected
            newEntry.setIcon(mEntry.getIconStandard());
        }
    }
    newEntry.setUrl(entryUrlView.getText().toString());
    newEntry.setUsername(entryUserNameView.getText().toString());
    newEntry.setNotes(entryCommentView.getText().toString());
    newEntry.setPassword(entryPasswordView.getText().toString());
    if (newEntry.allowExtraFields()) {
        // Delete all new standard strings
        newEntry.removeExtraFields();
        // Add extra fields from views
        for (int i = 0; i < entryExtraFieldsContainer.getChildCount(); i++) {
            EntryEditNewField view = (EntryEditNewField) entryExtraFieldsContainer.getChildAt(i);
            String key = view.getLabel();
            String value = view.getValue();
            boolean protect = view.isProtected();
            newEntry.addField(key, new ProtectedString(protect, value));
        }
    }
    newEntry.endToDecodeReference(db);
    return newEntry;
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwDate(com.keepassdroid.database.PwDate) PwEntry(com.keepassdroid.database.PwEntry) ProtectedString(com.keepassdroid.database.security.ProtectedString) PwIconStandard(com.keepassdroid.database.PwIconStandard) ProtectedString(com.keepassdroid.database.security.ProtectedString) EntryEditNewField(com.keepassdroid.view.EntryEditNewField)

Example 3 with EntryEditNewField

use of com.keepassdroid.view.EntryEditNewField in project KeePassDX by Kunzisoft.

the class EntryEditActivity method validateBeforeSaving.

protected boolean validateBeforeSaving() {
    // Require title
    String title = entryTitleView.getText().toString();
    if (title.length() == 0) {
        Toast.makeText(this, R.string.error_title_required, Toast.LENGTH_LONG).show();
        return false;
    }
    // Validate password
    String pass = entryPasswordView.getText().toString();
    String conf = entryConfirmationPasswordView.getText().toString();
    if (!pass.equals(conf)) {
        Toast.makeText(this, R.string.error_pass_match, Toast.LENGTH_LONG).show();
        return false;
    }
    // Validate extra fields
    if (mEntry.allowExtraFields()) {
        for (int i = 0; i < entryExtraFieldsContainer.getChildCount(); i++) {
            EntryEditNewField entryEditNewField = (EntryEditNewField) entryExtraFieldsContainer.getChildAt(i);
            String key = entryEditNewField.getLabel();
            if (key == null || key.length() == 0) {
                Toast.makeText(this, R.string.error_string_key, Toast.LENGTH_LONG).show();
                return false;
            }
        }
    }
    return true;
}
Also used : ProtectedString(com.keepassdroid.database.security.ProtectedString) EntryEditNewField(com.keepassdroid.view.EntryEditNewField)

Example 4 with EntryEditNewField

use of com.keepassdroid.view.EntryEditNewField in project KeePassDX by Kunzisoft.

the class EntryEditActivity method fillData.

protected void fillData() {
    ImageButton currIconButton = findViewById(R.id.icon_button);
    App.getDB().drawFactory.assignDrawableTo(currIconButton, getResources(), mEntry.getIcon());
    entryTitleView.setText(mEntry.getTitle());
    entryUserNameView.setText(mEntry.getUsername());
    entryUrlView.setText(mEntry.getUrl());
    String password = mEntry.getPassword();
    entryPasswordView.setText(password);
    entryConfirmationPasswordView.setText(password);
    entryCommentView.setText(mEntry.getNotes());
    boolean visibilityFontActivated = PreferencesUtil.fieldFontIsInVisibility(this);
    if (visibilityFontActivated) {
        Util.applyFontVisibilityTo(entryUserNameView);
        Util.applyFontVisibilityTo(entryPasswordView);
        Util.applyFontVisibilityTo(entryConfirmationPasswordView);
        Util.applyFontVisibilityTo(entryCommentView);
    }
    if (mEntry.allowExtraFields()) {
        LinearLayout container = findViewById(R.id.advanced_container);
        for (Map.Entry<String, ProtectedString> pair : mEntry.getExtraProtectedFields().entrySet()) {
            EntryEditNewField entryEditNewField = new EntryEditNewField(EntryEditActivity.this);
            entryEditNewField.setData(pair.getKey(), pair.getValue());
            entryEditNewField.setFontVisibility(visibilityFontActivated);
            container.addView(entryEditNewField);
        }
    }
}
Also used : ImageButton(android.widget.ImageButton) ProtectedString(com.keepassdroid.database.security.ProtectedString) ProtectedString(com.keepassdroid.database.security.ProtectedString) EntryEditNewField(com.keepassdroid.view.EntryEditNewField) Map(java.util.Map) LinearLayout(android.widget.LinearLayout)

Aggregations

ProtectedString (com.keepassdroid.database.security.ProtectedString)4 EntryEditNewField (com.keepassdroid.view.EntryEditNewField)4 PwDatabase (com.keepassdroid.database.PwDatabase)2 Intent (android.content.Intent)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 LinearLayout (android.widget.LinearLayout)1 ScrollView (android.widget.ScrollView)1 Database (com.keepassdroid.database.Database)1 PwDate (com.keepassdroid.database.PwDate)1 PwEntry (com.keepassdroid.database.PwEntry)1 PwGroup (com.keepassdroid.database.PwGroup)1 PwGroupId (com.keepassdroid.database.PwGroupId)1 PwIconStandard (com.keepassdroid.database.PwIconStandard)1 AddEntry (com.keepassdroid.database.edit.AddEntry)1 OnFinish (com.keepassdroid.database.edit.OnFinish)1 RunnableOnFinish (com.keepassdroid.database.edit.RunnableOnFinish)1 UpdateEntry (com.keepassdroid.database.edit.UpdateEntry)1 GeneratePasswordDialogFragment (com.keepassdroid.dialogs.GeneratePasswordDialogFragment)1